power_fsl.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics
  3. * Lukasz Majewski <l.majewski@samsung.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <spi.h>
  9. #include <power/pmic.h>
  10. #include <fsl_pmic.h>
  11. #include <errno.h>
  12. #if defined(CONFIG_POWER_FSL_MC13892)
  13. #define FSL_PMIC_I2C_LENGTH 3
  14. #elif defined(CONFIG_POWER_FSL_MC34704)
  15. #define FSL_PMIC_I2C_LENGTH 1
  16. #endif
  17. #if defined(CONFIG_POWER_SPI)
  18. static u32 pmic_spi_prepare_tx(u32 reg, u32 *val, u32 write)
  19. {
  20. return (write << 31) | (reg << 25) | (*val & 0x00FFFFFF);
  21. }
  22. #endif
  23. int pmic_init(unsigned char bus)
  24. {
  25. static const char name[] = "FSL_PMIC";
  26. struct pmic *p = pmic_alloc();
  27. if (!p) {
  28. printf("%s: POWER allocation error!\n", __func__);
  29. return -ENOMEM;
  30. }
  31. p->name = name;
  32. p->number_of_regs = PMIC_NUM_OF_REGS;
  33. p->bus = bus;
  34. #if defined(CONFIG_POWER_SPI)
  35. p->interface = PMIC_SPI;
  36. p->hw.spi.cs = CONFIG_FSL_PMIC_CS;
  37. p->hw.spi.clk = CONFIG_FSL_PMIC_CLK;
  38. p->hw.spi.mode = CONFIG_FSL_PMIC_MODE;
  39. p->hw.spi.bitlen = CONFIG_FSL_PMIC_BITLEN;
  40. p->hw.spi.flags = SPI_XFER_BEGIN | SPI_XFER_END;
  41. p->hw.spi.prepare_tx = pmic_spi_prepare_tx;
  42. #elif defined(CONFIG_POWER_I2C)
  43. p->interface = PMIC_I2C;
  44. p->hw.i2c.addr = CONFIG_SYS_FSL_PMIC_I2C_ADDR;
  45. p->hw.i2c.tx_num = FSL_PMIC_I2C_LENGTH;
  46. #else
  47. #error "You must select CONFIG_POWER_SPI or CONFIG_POWER_I2C"
  48. #endif
  49. return 0;
  50. }