gpio.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 = (void __iomem *) MCFEPORT_EPDDR,
  33. .podr = (void __iomem *) MCFEPORT_EPDR,
  34. .ppdr = (void __iomem *) MCFEPORT_EPPDR,
  35. },
  36. {
  37. .gpio_chip = {
  38. .label = "FECH",
  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 = 8,
  46. .ngpio = 8,
  47. },
  48. .pddr = (void __iomem *) MCFGPIO_PDDR_FECH,
  49. .podr = (void __iomem *) MCFGPIO_PODR_FECH,
  50. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_FECH,
  51. .setr = (void __iomem *) MCFGPIO_PPDSDR_FECH,
  52. .clrr = (void __iomem *) MCFGPIO_PCLRR_FECH,
  53. },
  54. {
  55. .gpio_chip = {
  56. .label = "FECL",
  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 = (void __iomem *) MCFGPIO_PDDR_FECL,
  67. .podr = (void __iomem *) MCFGPIO_PODR_FECL,
  68. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_FECL,
  69. .setr = (void __iomem *) MCFGPIO_PPDSDR_FECL,
  70. .clrr = (void __iomem *) MCFGPIO_PCLRR_FECL,
  71. },
  72. {
  73. .gpio_chip = {
  74. .label = "SSI",
  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 = 5,
  83. },
  84. .pddr = (void __iomem *) MCFGPIO_PDDR_SSI,
  85. .podr = (void __iomem *) MCFGPIO_PODR_SSI,
  86. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_SSI,
  87. .setr = (void __iomem *) MCFGPIO_PPDSDR_SSI,
  88. .clrr = (void __iomem *) MCFGPIO_PCLRR_SSI,
  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 = 4,
  101. },
  102. .pddr = (void __iomem *) MCFGPIO_PDDR_BUSCTL,
  103. .podr = (void __iomem *) MCFGPIO_PODR_BUSCTL,
  104. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_BUSCTL,
  105. .setr = (void __iomem *) MCFGPIO_PPDSDR_BUSCTL,
  106. .clrr = (void __iomem *) MCFGPIO_PCLRR_BUSCTL,
  107. },
  108. {
  109. .gpio_chip = {
  110. .label = "BE",
  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 = (void __iomem *) MCFGPIO_PDDR_BE,
  121. .podr = (void __iomem *) MCFGPIO_PODR_BE,
  122. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_BE,
  123. .setr = (void __iomem *) MCFGPIO_PPDSDR_BE,
  124. .clrr = (void __iomem *) MCFGPIO_PCLRR_BE,
  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 = 5,
  137. },
  138. .pddr = (void __iomem *) MCFGPIO_PDDR_CS,
  139. .podr = (void __iomem *) MCFGPIO_PODR_CS,
  140. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_CS,
  141. .setr = (void __iomem *) MCFGPIO_PPDSDR_CS,
  142. .clrr = (void __iomem *) MCFGPIO_PCLRR_CS,
  143. },
  144. {
  145. .gpio_chip = {
  146. .label = "PWM",
  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 = 58,
  154. .ngpio = 4,
  155. },
  156. .pddr = (void __iomem *) MCFGPIO_PDDR_PWM,
  157. .podr = (void __iomem *) MCFGPIO_PODR_PWM,
  158. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_PWM,
  159. .setr = (void __iomem *) MCFGPIO_PPDSDR_PWM,
  160. .clrr = (void __iomem *) MCFGPIO_PCLRR_PWM,
  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 = (void __iomem *) MCFGPIO_PDDR_FECI2C,
  175. .podr = (void __iomem *) MCFGPIO_PODR_FECI2C,
  176. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_FECI2C,
  177. .setr = (void __iomem *) MCFGPIO_PPDSDR_FECI2C,
  178. .clrr = (void __iomem *) MCFGPIO_PCLRR_FECI2C,
  179. },
  180. {
  181. .gpio_chip = {
  182. .label = "UART",
  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 = 8,
  191. },
  192. .pddr = (void __iomem *) MCFGPIO_PDDR_UART,
  193. .podr = (void __iomem *) MCFGPIO_PODR_UART,
  194. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_UART,
  195. .setr = (void __iomem *) MCFGPIO_PPDSDR_UART,
  196. .clrr = (void __iomem *) MCFGPIO_PCLRR_UART,
  197. },
  198. {
  199. .gpio_chip = {
  200. .label = "QSPI",
  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 = 6,
  209. },
  210. .pddr = (void __iomem *) MCFGPIO_PDDR_QSPI,
  211. .podr = (void __iomem *) MCFGPIO_PODR_QSPI,
  212. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_QSPI,
  213. .setr = (void __iomem *) MCFGPIO_PPDSDR_QSPI,
  214. .clrr = (void __iomem *) MCFGPIO_PCLRR_QSPI,
  215. },
  216. {
  217. .gpio_chip = {
  218. .label = "TIMER",
  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 = 4,
  227. },
  228. .pddr = (void __iomem *) MCFGPIO_PDDR_TIMER,
  229. .podr = (void __iomem *) MCFGPIO_PODR_TIMER,
  230. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_TIMER,
  231. .setr = (void __iomem *) MCFGPIO_PPDSDR_TIMER,
  232. .clrr = (void __iomem *) MCFGPIO_PCLRR_TIMER,
  233. },
  234. {
  235. .gpio_chip = {
  236. .label = "LCDDATAH",
  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 = 2,
  245. },
  246. .pddr = (void __iomem *) MCFGPIO_PDDR_LCDDATAH,
  247. .podr = (void __iomem *) MCFGPIO_PODR_LCDDATAH,
  248. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_LCDDATAH,
  249. .setr = (void __iomem *) MCFGPIO_PPDSDR_LCDDATAH,
  250. .clrr = (void __iomem *) MCFGPIO_PCLRR_LCDDATAH,
  251. },
  252. {
  253. .gpio_chip = {
  254. .label = "LCDDATAM",
  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 = 8,
  263. },
  264. .pddr = (void __iomem *) MCFGPIO_PDDR_LCDDATAM,
  265. .podr = (void __iomem *) MCFGPIO_PODR_LCDDATAM,
  266. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_LCDDATAM,
  267. .setr = (void __iomem *) MCFGPIO_PPDSDR_LCDDATAM,
  268. .clrr = (void __iomem *) MCFGPIO_PCLRR_LCDDATAM,
  269. },
  270. {
  271. .gpio_chip = {
  272. .label = "LCDDATAL",
  273. .request = mcf_gpio_request,
  274. .free = mcf_gpio_free,
  275. .direction_input = mcf_gpio_direction_input,
  276. .direction_output = mcf_gpio_direction_output,
  277. .get = mcf_gpio_get_value,
  278. .set = mcf_gpio_set_value_fast,
  279. .base = 112,
  280. .ngpio = 8,
  281. },
  282. .pddr = (void __iomem *) MCFGPIO_PDDR_LCDDATAL,
  283. .podr = (void __iomem *) MCFGPIO_PODR_LCDDATAL,
  284. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_LCDDATAL,
  285. .setr = (void __iomem *) MCFGPIO_PPDSDR_LCDDATAL,
  286. .clrr = (void __iomem *) MCFGPIO_PCLRR_LCDDATAL,
  287. },
  288. {
  289. .gpio_chip = {
  290. .label = "LCDCTLH",
  291. .request = mcf_gpio_request,
  292. .free = mcf_gpio_free,
  293. .direction_input = mcf_gpio_direction_input,
  294. .direction_output = mcf_gpio_direction_output,
  295. .get = mcf_gpio_get_value,
  296. .set = mcf_gpio_set_value_fast,
  297. .base = 120,
  298. .ngpio = 1,
  299. },
  300. .pddr = (void __iomem *) MCFGPIO_PDDR_LCDCTLH,
  301. .podr = (void __iomem *) MCFGPIO_PODR_LCDCTLH,
  302. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_LCDCTLH,
  303. .setr = (void __iomem *) MCFGPIO_PPDSDR_LCDCTLH,
  304. .clrr = (void __iomem *) MCFGPIO_PCLRR_LCDCTLH,
  305. },
  306. {
  307. .gpio_chip = {
  308. .label = "LCDCTLL",
  309. .request = mcf_gpio_request,
  310. .free = mcf_gpio_free,
  311. .direction_input = mcf_gpio_direction_input,
  312. .direction_output = mcf_gpio_direction_output,
  313. .get = mcf_gpio_get_value,
  314. .set = mcf_gpio_set_value_fast,
  315. .base = 128,
  316. .ngpio = 8,
  317. },
  318. .pddr = (void __iomem *) MCFGPIO_PDDR_LCDCTLL,
  319. .podr = (void __iomem *) MCFGPIO_PODR_LCDCTLL,
  320. .ppdr = (void __iomem *) MCFGPIO_PPDSDR_LCDCTLL,
  321. .setr = (void __iomem *) MCFGPIO_PPDSDR_LCDCTLL,
  322. .clrr = (void __iomem *) MCFGPIO_PCLRR_LCDCTLL,
  323. },
  324. };
  325. static int __init mcf_gpio_init(void)
  326. {
  327. unsigned i = 0;
  328. while (i < ARRAY_SIZE(mcf_gpio_chips))
  329. (void)gpiochip_add((struct gpio_chip *)&mcf_gpio_chips[i++]);
  330. return 0;
  331. }
  332. core_initcall(mcf_gpio_init);