pcf50633-gpio.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #include <linux/mfd/pcf50633/pmic.h>
  21. static const u8 pcf50633_regulator_registers[PCF50633_NUM_REGULATORS] = {
  22. [PCF50633_REGULATOR_AUTO] = PCF50633_REG_AUTOOUT,
  23. [PCF50633_REGULATOR_DOWN1] = PCF50633_REG_DOWN1OUT,
  24. [PCF50633_REGULATOR_DOWN2] = PCF50633_REG_DOWN2OUT,
  25. [PCF50633_REGULATOR_MEMLDO] = PCF50633_REG_MEMLDOOUT,
  26. [PCF50633_REGULATOR_LDO1] = PCF50633_REG_LDO1OUT,
  27. [PCF50633_REGULATOR_LDO2] = PCF50633_REG_LDO2OUT,
  28. [PCF50633_REGULATOR_LDO3] = PCF50633_REG_LDO3OUT,
  29. [PCF50633_REGULATOR_LDO4] = PCF50633_REG_LDO4OUT,
  30. [PCF50633_REGULATOR_LDO5] = PCF50633_REG_LDO5OUT,
  31. [PCF50633_REGULATOR_LDO6] = PCF50633_REG_LDO6OUT,
  32. [PCF50633_REGULATOR_HCLDO] = PCF50633_REG_HCLDOOUT,
  33. };
  34. int pcf50633_gpio_set(struct pcf50633 *pcf, int gpio, u8 val)
  35. {
  36. u8 reg;
  37. reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
  38. return pcf50633_reg_set_bit_mask(pcf, reg, 0x07, val);
  39. }
  40. EXPORT_SYMBOL_GPL(pcf50633_gpio_set);
  41. u8 pcf50633_gpio_get(struct pcf50633 *pcf, int gpio)
  42. {
  43. u8 reg, val;
  44. reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
  45. val = pcf50633_reg_read(pcf, reg) & 0x07;
  46. return val;
  47. }
  48. EXPORT_SYMBOL_GPL(pcf50633_gpio_get);
  49. int pcf50633_gpio_invert_set(struct pcf50633 *pcf, int gpio, int invert)
  50. {
  51. u8 val, reg;
  52. reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
  53. val = !!invert << 3;
  54. return pcf50633_reg_set_bit_mask(pcf, reg, 1 << 3, val);
  55. }
  56. EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_set);
  57. int pcf50633_gpio_invert_get(struct pcf50633 *pcf, int gpio)
  58. {
  59. u8 reg, val;
  60. reg = gpio - PCF50633_GPIO1 + PCF50633_REG_GPIO1CFG;
  61. val = pcf50633_reg_read(pcf, reg);
  62. return val & (1 << 3);
  63. }
  64. EXPORT_SYMBOL_GPL(pcf50633_gpio_invert_get);
  65. int pcf50633_gpio_power_supply_set(struct pcf50633 *pcf,
  66. int gpio, int regulator, int on)
  67. {
  68. u8 reg, val, mask;
  69. /* the *ENA register is always one after the *OUT register */
  70. reg = pcf50633_regulator_registers[regulator] + 1;
  71. val = !!on << (gpio - PCF50633_GPIO1);
  72. mask = 1 << (gpio - PCF50633_GPIO1);
  73. return pcf50633_reg_set_bit_mask(pcf, reg, mask, val);
  74. }
  75. EXPORT_SYMBOL_GPL(pcf50633_gpio_power_supply_set);
  76. MODULE_LICENSE("GPL");