gpio.c 7.4 KB

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