gpio.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <asm/coldfire.h>
  18. #include <asm/mcfsim.h>
  19. #include <asm/mcfgpio.h>
  20. static struct mcf_gpio_chip mcf_gpio_chips[] = {
  21. {
  22. .gpio_chip = {
  23. .label = "PIRQ",
  24. .request = mcf_gpio_request,
  25. .free = mcf_gpio_free,
  26. .direction_input = mcf_gpio_direction_input,
  27. .direction_output = mcf_gpio_direction_output,
  28. .get = mcf_gpio_get_value,
  29. .set = mcf_gpio_set_value,
  30. .base = 1,
  31. .ngpio = 7,
  32. },
  33. .pddr = (void __iomem *) MCFEPORT_EPDDR,
  34. .podr = (void __iomem *) MCFEPORT_EPDR,
  35. .ppdr = (void __iomem *) MCFEPORT_EPPDR,
  36. },
  37. {
  38. .gpio_chip = {
  39. .label = "ADDR",
  40. .request = mcf_gpio_request,
  41. .free = mcf_gpio_free,
  42. .direction_input = mcf_gpio_direction_input,
  43. .direction_output = mcf_gpio_direction_output,
  44. .get = mcf_gpio_get_value,
  45. .set = mcf_gpio_set_value_fast,
  46. .base = 13,
  47. .ngpio = 3,
  48. },
  49. .pddr = (void __iomem *) MCFGPIO_PDDR_ADDR,
  50. .podr = (void __iomem *) MCFGPIO_PODR_ADDR,
  51. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_ADDR,
  52. .setr = (void __iomem *) MCFGPIO_PPDSDR_ADDR,
  53. .clrr = (void __iomem *) MCFGPIO_PCLRR_ADDR,
  54. },
  55. {
  56. .gpio_chip = {
  57. .label = "DATAH",
  58. .request = mcf_gpio_request,
  59. .free = mcf_gpio_free,
  60. .direction_input = mcf_gpio_direction_input,
  61. .direction_output = mcf_gpio_direction_output,
  62. .get = mcf_gpio_get_value,
  63. .set = mcf_gpio_set_value_fast,
  64. .base = 16,
  65. .ngpio = 8,
  66. },
  67. .pddr = (void __iomem *) MCFGPIO_PDDR_DATAH,
  68. .podr = (void __iomem *) MCFGPIO_PODR_DATAH,
  69. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_DATAH,
  70. .setr = (void __iomem *) MCFGPIO_PPDSDR_DATAH,
  71. .clrr = (void __iomem *) MCFGPIO_PCLRR_DATAH,
  72. },
  73. {
  74. .gpio_chip = {
  75. .label = "DATAL",
  76. .request = mcf_gpio_request,
  77. .free = mcf_gpio_free,
  78. .direction_input = mcf_gpio_direction_input,
  79. .direction_output = mcf_gpio_direction_output,
  80. .get = mcf_gpio_get_value,
  81. .set = mcf_gpio_set_value_fast,
  82. .base = 24,
  83. .ngpio = 8,
  84. },
  85. .pddr = (void __iomem *) MCFGPIO_PDDR_DATAL,
  86. .podr = (void __iomem *) MCFGPIO_PODR_DATAL,
  87. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_DATAL,
  88. .setr = (void __iomem *) MCFGPIO_PPDSDR_DATAL,
  89. .clrr = (void __iomem *) MCFGPIO_PCLRR_DATAL,
  90. },
  91. {
  92. .gpio_chip = {
  93. .label = "BUSCTL",
  94. .request = mcf_gpio_request,
  95. .free = mcf_gpio_free,
  96. .direction_input = mcf_gpio_direction_input,
  97. .direction_output = mcf_gpio_direction_output,
  98. .get = mcf_gpio_get_value,
  99. .set = mcf_gpio_set_value_fast,
  100. .base = 32,
  101. .ngpio = 8,
  102. },
  103. .pddr = (void __iomem *) MCFGPIO_PDDR_BUSCTL,
  104. .podr = (void __iomem *) MCFGPIO_PODR_BUSCTL,
  105. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_BUSCTL,
  106. .setr = (void __iomem *) MCFGPIO_PPDSDR_BUSCTL,
  107. .clrr = (void __iomem *) MCFGPIO_PCLRR_BUSCTL,
  108. },
  109. {
  110. .gpio_chip = {
  111. .label = "BS",
  112. .request = mcf_gpio_request,
  113. .free = mcf_gpio_free,
  114. .direction_input = mcf_gpio_direction_input,
  115. .direction_output = mcf_gpio_direction_output,
  116. .get = mcf_gpio_get_value,
  117. .set = mcf_gpio_set_value_fast,
  118. .base = 40,
  119. .ngpio = 4,
  120. },
  121. .pddr = (void __iomem *) MCFGPIO_PDDR_BS,
  122. .podr = (void __iomem *) MCFGPIO_PODR_BS,
  123. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_BS,
  124. .setr = (void __iomem *) MCFGPIO_PPDSDR_BS,
  125. .clrr = (void __iomem *) MCFGPIO_PCLRR_BS,
  126. },
  127. {
  128. .gpio_chip = {
  129. .label = "CS",
  130. .request = mcf_gpio_request,
  131. .free = mcf_gpio_free,
  132. .direction_input = mcf_gpio_direction_input,
  133. .direction_output = mcf_gpio_direction_output,
  134. .get = mcf_gpio_get_value,
  135. .set = mcf_gpio_set_value_fast,
  136. .base = 49,
  137. .ngpio = 7,
  138. },
  139. .pddr = (void __iomem *) MCFGPIO_PDDR_CS,
  140. .podr = (void __iomem *) MCFGPIO_PODR_CS,
  141. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_CS,
  142. .setr = (void __iomem *) MCFGPIO_PPDSDR_CS,
  143. .clrr = (void __iomem *) MCFGPIO_PCLRR_CS,
  144. },
  145. {
  146. .gpio_chip = {
  147. .label = "SDRAM",
  148. .request = mcf_gpio_request,
  149. .free = mcf_gpio_free,
  150. .direction_input = mcf_gpio_direction_input,
  151. .direction_output = mcf_gpio_direction_output,
  152. .get = mcf_gpio_get_value,
  153. .set = mcf_gpio_set_value_fast,
  154. .base = 56,
  155. .ngpio = 6,
  156. },
  157. .pddr = (void __iomem *) MCFGPIO_PDDR_SDRAM,
  158. .podr = (void __iomem *) MCFGPIO_PODR_SDRAM,
  159. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_SDRAM,
  160. .setr = (void __iomem *) MCFGPIO_PPDSDR_SDRAM,
  161. .clrr = (void __iomem *) MCFGPIO_PCLRR_SDRAM,
  162. },
  163. {
  164. .gpio_chip = {
  165. .label = "FECI2C",
  166. .request = mcf_gpio_request,
  167. .free = mcf_gpio_free,
  168. .direction_input = mcf_gpio_direction_input,
  169. .direction_output = mcf_gpio_direction_output,
  170. .get = mcf_gpio_get_value,
  171. .set = mcf_gpio_set_value_fast,
  172. .base = 64,
  173. .ngpio = 4,
  174. },
  175. .pddr = (void __iomem *) MCFGPIO_PDDR_FECI2C,
  176. .podr = (void __iomem *) MCFGPIO_PODR_FECI2C,
  177. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_FECI2C,
  178. .setr = (void __iomem *) MCFGPIO_PPDSDR_FECI2C,
  179. .clrr = (void __iomem *) MCFGPIO_PCLRR_FECI2C,
  180. },
  181. {
  182. .gpio_chip = {
  183. .label = "UARTH",
  184. .request = mcf_gpio_request,
  185. .free = mcf_gpio_free,
  186. .direction_input = mcf_gpio_direction_input,
  187. .direction_output = mcf_gpio_direction_output,
  188. .get = mcf_gpio_get_value,
  189. .set = mcf_gpio_set_value_fast,
  190. .base = 72,
  191. .ngpio = 2,
  192. },
  193. .pddr = (void __iomem *) MCFGPIO_PDDR_UARTH,
  194. .podr = (void __iomem *) MCFGPIO_PODR_UARTH,
  195. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_UARTH,
  196. .setr = (void __iomem *) MCFGPIO_PPDSDR_UARTH,
  197. .clrr = (void __iomem *) MCFGPIO_PCLRR_UARTH,
  198. },
  199. {
  200. .gpio_chip = {
  201. .label = "UARTL",
  202. .request = mcf_gpio_request,
  203. .free = mcf_gpio_free,
  204. .direction_input = mcf_gpio_direction_input,
  205. .direction_output = mcf_gpio_direction_output,
  206. .get = mcf_gpio_get_value,
  207. .set = mcf_gpio_set_value_fast,
  208. .base = 80,
  209. .ngpio = 8,
  210. },
  211. .pddr = (void __iomem *) MCFGPIO_PDDR_UARTL,
  212. .podr = (void __iomem *) MCFGPIO_PODR_UARTL,
  213. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_UARTL,
  214. .setr = (void __iomem *) MCFGPIO_PPDSDR_UARTL,
  215. .clrr = (void __iomem *) MCFGPIO_PCLRR_UARTL,
  216. },
  217. {
  218. .gpio_chip = {
  219. .label = "QSPI",
  220. .request = mcf_gpio_request,
  221. .free = mcf_gpio_free,
  222. .direction_input = mcf_gpio_direction_input,
  223. .direction_output = mcf_gpio_direction_output,
  224. .get = mcf_gpio_get_value,
  225. .set = mcf_gpio_set_value_fast,
  226. .base = 88,
  227. .ngpio = 5,
  228. },
  229. .pddr = (void __iomem *) MCFGPIO_PDDR_QSPI,
  230. .podr = (void __iomem *) MCFGPIO_PODR_QSPI,
  231. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_QSPI,
  232. .setr = (void __iomem *) MCFGPIO_PPDSDR_QSPI,
  233. .clrr = (void __iomem *) MCFGPIO_PCLRR_QSPI,
  234. },
  235. {
  236. .gpio_chip = {
  237. .label = "TIMER",
  238. .request = mcf_gpio_request,
  239. .free = mcf_gpio_free,
  240. .direction_input = mcf_gpio_direction_input,
  241. .direction_output = mcf_gpio_direction_output,
  242. .get = mcf_gpio_get_value,
  243. .set = mcf_gpio_set_value_fast,
  244. .base = 96,
  245. .ngpio = 8,
  246. },
  247. .pddr = (void __iomem *) MCFGPIO_PDDR_TIMER,
  248. .podr = (void __iomem *) MCFGPIO_PODR_TIMER,
  249. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_TIMER,
  250. .setr = (void __iomem *) MCFGPIO_PPDSDR_TIMER,
  251. .clrr = (void __iomem *) MCFGPIO_PCLRR_TIMER,
  252. },
  253. {
  254. .gpio_chip = {
  255. .label = "ETPU",
  256. .request = mcf_gpio_request,
  257. .free = mcf_gpio_free,
  258. .direction_input = mcf_gpio_direction_input,
  259. .direction_output = mcf_gpio_direction_output,
  260. .get = mcf_gpio_get_value,
  261. .set = mcf_gpio_set_value_fast,
  262. .base = 104,
  263. .ngpio = 3,
  264. },
  265. .pddr = (void __iomem *) MCFGPIO_PDDR_ETPU,
  266. .podr = (void __iomem *) MCFGPIO_PODR_ETPU,
  267. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_ETPU,
  268. .setr = (void __iomem *) MCFGPIO_PPDSDR_ETPU,
  269. .clrr = (void __iomem *) MCFGPIO_PCLRR_ETPU,
  270. },
  271. };
  272. static int __init mcf_gpio_init(void)
  273. {
  274. unsigned i = 0;
  275. while (i < ARRAY_SIZE(mcf_gpio_chips))
  276. (void)gpiochip_add((struct gpio_chip *)&mcf_gpio_chips[i++]);
  277. return 0;
  278. }
  279. core_initcall(mcf_gpio_init);