pcf50633-gpio.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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/module.h>
  18. #include <linux/mfd/pcf50633/core.h>
  19. #include <linux/mfd/pcf50633/gpio.h>
  20. enum pcf50633_regulator_id {
  21. PCF50633_REGULATOR_AUTO,
  22. PCF50633_REGULATOR_DOWN1,
  23. PCF50633_REGULATOR_DOWN2,
  24. PCF50633_REGULATOR_LDO1,
  25. PCF50633_REGULATOR_LDO2,
  26. PCF50633_REGULATOR_LDO3,
  27. PCF50633_REGULATOR_LDO4,
  28. PCF50633_REGULATOR_LDO5,
  29. PCF50633_REGULATOR_LDO6,
  30. PCF50633_REGULATOR_HCLDO,
  31. PCF50633_REGULATOR_MEMLDO,
  32. };
  33. #define PCF50633_REG_AUTOOUT 0x1a
  34. #define PCF50633_REG_DOWN1OUT 0x1e
  35. #define PCF50633_REG_DOWN2OUT 0x22
  36. #define PCF50633_REG_MEMLDOOUT 0x26
  37. #define PCF50633_REG_LDO1OUT 0x2d
  38. #define PCF50633_REG_LDO2OUT 0x2f
  39. #define PCF50633_REG_LDO3OUT 0x31
  40. #define PCF50633_REG_LDO4OUT 0x33
  41. #define PCF50633_REG_LDO5OUT 0x35
  42. #define PCF50633_REG_LDO6OUT 0x37
  43. #define PCF50633_REG_HCLDOOUT 0x39
  44. static const u8 pcf50633_regulator_registers[PCF50633_NUM_REGULATORS] = {
  45. [PCF50633_REGULATOR_AUTO] = PCF50633_REG_AUTOOUT,
  46. [PCF50633_REGULATOR_DOWN1] = PCF50633_REG_DOWN1OUT,
  47. [PCF50633_REGULATOR_DOWN2] = PCF50633_REG_DOWN2OUT,
  48. [PCF50633_REGULATOR_MEMLDO] = PCF50633_REG_MEMLDOOUT,
  49. [PCF50633_REGULATOR_LDO1] = PCF50633_REG_LDO1OUT,
  50. [PCF50633_REGULATOR_LDO2] = PCF50633_REG_LDO2OUT,
  51. [PCF50633_REGULATOR_LDO3] = PCF50633_REG_LDO3OUT,
  52. [PCF50633_REGULATOR_LDO4] = PCF50633_REG_LDO4OUT,
  53. [PCF50633_REGULATOR_LDO5] = PCF50633_REG_LDO5OUT,
  54. [PCF50633_REGULATOR_LDO6] = PCF50633_REG_LDO6OUT,
  55. [PCF50633_REGULATOR_HCLDO] = PCF50633_REG_HCLDOOUT,
  56. };
  57. int pcf50633_gpio_set(struct pcf50633 *pcf, int gpio, u8 val)
  58. {
  59. u8 reg;
  60. reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
  61. return pcf50633_reg_set_bit_mask(pcf, reg, 0x07, val);
  62. }
  63. EXPORT_SYMBOL_GPL(pcf50633_gpio_set);
  64. u8 pcf50633_gpio_get(struct pcf50633 *pcf, int gpio)
  65. {
  66. u8 reg, val;
  67. reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
  68. val = pcf50633_reg_read(pcf, reg) & 0x07;
  69. return val;
  70. }
  71. EXPORT_SYMBOL_GPL(pcf50633_gpio_get);
  72. int pcf50633_gpio_invert_set(struct pcf50633 *pcf, int gpio, int invert)
  73. {
  74. u8 val, reg;
  75. reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
  76. val = !!invert << 3;
  77. return pcf50633_reg_set_bit_mask(pcf, reg, 1 << 3, val);
  78. }
  79. EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_set);
  80. int pcf50633_gpio_invert_get(struct pcf50633 *pcf, int gpio)
  81. {
  82. u8 reg, val;
  83. reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
  84. val = pcf50633_reg_read(pcf, reg);
  85. return val & (1 << 3);
  86. }
  87. EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_get);
  88. int pcf50633_gpio_power_supply_set(struct pcf50633 *pcf,
  89. int gpio, int regulator, int on)
  90. {
  91. u8 reg, val, mask;
  92. /* the *ENA register is always one after the *OUT register */
  93. reg = pcf50633_regulator_registers[regulator] + 1;
  94. val = !!on << (gpio - PCF50633_GPIO1);
  95. mask = 1 << (gpio - PCF50633_GPIO1);
  96. return pcf50633_reg_set_bit_mask(pcf, reg, mask, val);
  97. }
  98. EXPORT_SYMBOL_GPL(pcf50633_gpio_power_supply_set);
  99. MODULE_LICENSE("GPL");