pcf50633-gpio.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* NXP PCF50633 GPIO Driver
  2. *
  3. * (C) 2006-2008 by Openmoko, Inc.
  4. * Author: Balaji Rao <balajirrao@openmoko.org>
  5. * All rights reserved.
  6. *
  7. * Broken down from monstrous PCF50633 driver mainly by
  8. * Harald Welte, Andy Green and Werner Almesberger
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/mfd/pcf50633/core.h>
  18. #include <linux/mfd/pcf50633/gpio.h>
  19. enum pcf50633_regulator_id {
  20. PCF50633_REGULATOR_AUTO,
  21. PCF50633_REGULATOR_DOWN1,
  22. PCF50633_REGULATOR_DOWN2,
  23. PCF50633_REGULATOR_LDO1,
  24. PCF50633_REGULATOR_LDO2,
  25. PCF50633_REGULATOR_LDO3,
  26. PCF50633_REGULATOR_LDO4,
  27. PCF50633_REGULATOR_LDO5,
  28. PCF50633_REGULATOR_LDO6,
  29. PCF50633_REGULATOR_HCLDO,
  30. PCF50633_REGULATOR_MEMLDO,
  31. };
  32. #define PCF50633_REG_AUTOOUT 0x1a
  33. #define PCF50633_REG_DOWN1OUT 0x1e
  34. #define PCF50633_REG_DOWN2OUT 0x22
  35. #define PCF50633_REG_MEMLDOOUT 0x26
  36. #define PCF50633_REG_LDO1OUT 0x2d
  37. #define PCF50633_REG_LDO2OUT 0x2f
  38. #define PCF50633_REG_LDO3OUT 0x31
  39. #define PCF50633_REG_LDO4OUT 0x33
  40. #define PCF50633_REG_LDO5OUT 0x35
  41. #define PCF50633_REG_LDO6OUT 0x37
  42. #define PCF50633_REG_HCLDOOUT 0x39
  43. static const u8 pcf50633_regulator_registers[PCF50633_NUM_REGULATORS] = {
  44. [PCF50633_REGULATOR_AUTO] = PCF50633_REG_AUTOOUT,
  45. [PCF50633_REGULATOR_DOWN1] = PCF50633_REG_DOWN1OUT,
  46. [PCF50633_REGULATOR_DOWN2] = PCF50633_REG_DOWN2OUT,
  47. [PCF50633_REGULATOR_MEMLDO] = PCF50633_REG_MEMLDOOUT,
  48. [PCF50633_REGULATOR_LDO1] = PCF50633_REG_LDO1OUT,
  49. [PCF50633_REGULATOR_LDO2] = PCF50633_REG_LDO2OUT,
  50. [PCF50633_REGULATOR_LDO3] = PCF50633_REG_LDO3OUT,
  51. [PCF50633_REGULATOR_LDO4] = PCF50633_REG_LDO4OUT,
  52. [PCF50633_REGULATOR_LDO5] = PCF50633_REG_LDO5OUT,
  53. [PCF50633_REGULATOR_LDO6] = PCF50633_REG_LDO6OUT,
  54. [PCF50633_REGULATOR_HCLDO] = PCF50633_REG_HCLDOOUT,
  55. };
  56. int pcf50633_gpio_set(struct pcf50633 *pcf, int gpio, u8 val)
  57. {
  58. u8 reg;
  59. reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
  60. return pcf50633_reg_set_bit_mask(pcf, reg, 0x07, val);
  61. }
  62. EXPORT_SYMBOL_GPL(pcf50633_gpio_set);
  63. u8 pcf50633_gpio_get(struct pcf50633 *pcf, int gpio)
  64. {
  65. u8 reg, val;
  66. reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
  67. val = pcf50633_reg_read(pcf, reg) & 0x07;
  68. return val;
  69. }
  70. EXPORT_SYMBOL_GPL(pcf50633_gpio_get);
  71. int pcf50633_gpio_invert_set(struct pcf50633 *pcf, int gpio, int invert)
  72. {
  73. u8 val, reg;
  74. reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
  75. val = !!invert << 3;
  76. return pcf50633_reg_set_bit_mask(pcf, reg, 1 << 3, val);
  77. }
  78. EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_set);
  79. int pcf50633_gpio_invert_get(struct pcf50633 *pcf, int gpio)
  80. {
  81. u8 reg, val;
  82. reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
  83. val = pcf50633_reg_read(pcf, reg);
  84. return val & (1 << 3);
  85. }
  86. EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_get);
  87. int pcf50633_gpio_power_supply_set(struct pcf50633 *pcf,
  88. int gpio, int regulator, int on)
  89. {
  90. u8 reg, val, mask;
  91. /* the *ENA register is always one after the *OUT register */
  92. reg = pcf50633_regulator_registers[regulator] + 1;
  93. val = !!on << (gpio - PCF50633_GPIO1);
  94. mask = 1 << (gpio - PCF50633_GPIO1);
  95. return pcf50633_reg_set_bit_mask(pcf, reg, mask, val);
  96. }
  97. EXPORT_SYMBOL_GPL(pcf50633_gpio_power_supply_set);