power_fsl.c 1.3 KB

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