mcfgpio.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Coldfire generic GPIO support.
  3. *
  4. * (C) Copyright 2009, Steven King <sfking@fdwdc.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #ifndef mcfgpio_h
  16. #define mcfgpio_h
  17. #include <linux/io.h>
  18. #include <asm-generic/gpio.h>
  19. struct mcf_gpio_chip {
  20. struct gpio_chip gpio_chip;
  21. void __iomem *pddr;
  22. void __iomem *podr;
  23. void __iomem *ppdr;
  24. void __iomem *setr;
  25. void __iomem *clrr;
  26. const u8 *gpio_to_pinmux;
  27. };
  28. extern struct mcf_gpio_chip mcf_gpio_chips[];
  29. extern unsigned int mcf_gpio_chips_size;
  30. int mcf_gpio_direction_input(struct gpio_chip *, unsigned);
  31. int mcf_gpio_get_value(struct gpio_chip *, unsigned);
  32. int mcf_gpio_direction_output(struct gpio_chip *, unsigned, int);
  33. void mcf_gpio_set_value(struct gpio_chip *, unsigned, int);
  34. void mcf_gpio_set_value_fast(struct gpio_chip *, unsigned, int);
  35. int mcf_gpio_request(struct gpio_chip *, unsigned);
  36. void mcf_gpio_free(struct gpio_chip *, unsigned);
  37. /*
  38. * Define macros to ease the pain of setting up the GPIO tables. There
  39. * are two cases we need to deal with here, they cover all currently
  40. * available ColdFire GPIO hardware. There are of course minor differences
  41. * in the layout and number of bits in each ColdFire part, but the macros
  42. * take all that in.
  43. *
  44. * Firstly is the conventional GPIO registers where we toggle individual
  45. * bits in a register, preserving the other bits in the register. For
  46. * lack of a better term I have called this the slow method.
  47. */
  48. #define MCFGPS(mlabel, mbase, mngpio, mpddr, mpodr, mppdr) \
  49. { \
  50. .gpio_chip = { \
  51. .label = #mlabel, \
  52. .request = mcf_gpio_request, \
  53. .free = mcf_gpio_free, \
  54. .direction_input = mcf_gpio_direction_input, \
  55. .direction_output = mcf_gpio_direction_output,\
  56. .get = mcf_gpio_get_value, \
  57. .set = mcf_gpio_set_value, \
  58. .base = mbase, \
  59. .ngpio = mngpio, \
  60. }, \
  61. .pddr = (void __iomem *) mpddr, \
  62. .podr = (void __iomem *) mpodr, \
  63. .ppdr = (void __iomem *) mppdr, \
  64. }
  65. /*
  66. * Secondly is the faster case, where we have set and clear registers
  67. * that allow us to set or clear a bit with a single write, not having
  68. * to worry about preserving other bits.
  69. */
  70. #define MCFGPF(mlabel, mbase, mngpio) \
  71. { \
  72. .gpio_chip = { \
  73. .label = #mlabel, \
  74. .request = mcf_gpio_request, \
  75. .free = mcf_gpio_free, \
  76. .direction_input = mcf_gpio_direction_input, \
  77. .direction_output = mcf_gpio_direction_output,\
  78. .get = mcf_gpio_get_value, \
  79. .set = mcf_gpio_set_value_fast, \
  80. .base = mbase, \
  81. .ngpio = mngpio, \
  82. }, \
  83. .pddr = (void __iomem *) MCFGPIO_PDDR_##mlabel, \
  84. .podr = (void __iomem *) MCFGPIO_PODR_##mlabel, \
  85. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_##mlabel, \
  86. .setr = (void __iomem *) MCFGPIO_PPDSDR_##mlabel, \
  87. .clrr = (void __iomem *) MCFGPIO_PCLRR_##mlabel, \
  88. }
  89. #endif