gpio.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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 = "NQ",
  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 = "TA",
  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 = 8,
  47. .ngpio = 4,
  48. },
  49. .pddr = (void __iomem *)MCFGPTA_GPTDDR,
  50. .podr = (void __iomem *)MCFGPTA_GPTPORT,
  51. .ppdr = (void __iomem *)MCFGPTB_GPTPORT,
  52. },
  53. {
  54. .gpio_chip = {
  55. .label = "TB",
  56. .request = mcf_gpio_request,
  57. .free = mcf_gpio_free,
  58. .direction_input = mcf_gpio_direction_input,
  59. .direction_output = mcf_gpio_direction_output,
  60. .get = mcf_gpio_get_value,
  61. .set = mcf_gpio_set_value_fast,
  62. .base = 16,
  63. .ngpio = 4,
  64. },
  65. .pddr = (void __iomem *)MCFGPTB_GPTDDR,
  66. .podr = (void __iomem *)MCFGPTB_GPTPORT,
  67. .ppdr = (void __iomem *)MCFGPTB_GPTPORT,
  68. },
  69. {
  70. .gpio_chip = {
  71. .label = "QA",
  72. .request = mcf_gpio_request,
  73. .free = mcf_gpio_free,
  74. .direction_input = mcf_gpio_direction_input,
  75. .direction_output = mcf_gpio_direction_output,
  76. .get = mcf_gpio_get_value,
  77. .set = mcf_gpio_set_value_fast,
  78. .base = 24,
  79. .ngpio = 4,
  80. },
  81. .pddr = (void __iomem *)MCFQADC_DDRQA,
  82. .podr = (void __iomem *)MCFQADC_PORTQA,
  83. .ppdr = (void __iomem *)MCFQADC_PORTQA,
  84. },
  85. {
  86. .gpio_chip = {
  87. .label = "QB",
  88. .request = mcf_gpio_request,
  89. .free = mcf_gpio_free,
  90. .direction_input = mcf_gpio_direction_input,
  91. .direction_output = mcf_gpio_direction_output,
  92. .get = mcf_gpio_get_value,
  93. .set = mcf_gpio_set_value_fast,
  94. .base = 32,
  95. .ngpio = 4,
  96. },
  97. .pddr = (void __iomem *)MCFQADC_DDRQB,
  98. .podr = (void __iomem *)MCFQADC_PORTQB,
  99. .ppdr = (void __iomem *)MCFQADC_PORTQB,
  100. },
  101. {
  102. .gpio_chip = {
  103. .label = "A",
  104. .request = mcf_gpio_request,
  105. .free = mcf_gpio_free,
  106. .direction_input = mcf_gpio_direction_input,
  107. .direction_output = mcf_gpio_direction_output,
  108. .get = mcf_gpio_get_value,
  109. .set = mcf_gpio_set_value_fast,
  110. .base = 40,
  111. .ngpio = 8,
  112. },
  113. .pddr = (void __iomem *)MCFGPIO_DDRA,
  114. .podr = (void __iomem *)MCFGPIO_PORTA,
  115. .ppdr = (void __iomem *)MCFGPIO_PORTAP,
  116. .setr = (void __iomem *)MCFGPIO_SETA,
  117. .clrr = (void __iomem *)MCFGPIO_CLRA,
  118. },
  119. {
  120. .gpio_chip = {
  121. .label = "B",
  122. .request = mcf_gpio_request,
  123. .free = mcf_gpio_free,
  124. .direction_input = mcf_gpio_direction_input,
  125. .direction_output = mcf_gpio_direction_output,
  126. .get = mcf_gpio_get_value,
  127. .set = mcf_gpio_set_value_fast,
  128. .base = 48,
  129. .ngpio = 8,
  130. },
  131. .pddr = (void __iomem *)MCFGPIO_DDRB,
  132. .podr = (void __iomem *)MCFGPIO_PORTB,
  133. .ppdr = (void __iomem *)MCFGPIO_PORTBP,
  134. .setr = (void __iomem *)MCFGPIO_SETB,
  135. .clrr = (void __iomem *)MCFGPIO_CLRB,
  136. },
  137. {
  138. .gpio_chip = {
  139. .label = "C",
  140. .request = mcf_gpio_request,
  141. .free = mcf_gpio_free,
  142. .direction_input = mcf_gpio_direction_input,
  143. .direction_output = mcf_gpio_direction_output,
  144. .get = mcf_gpio_get_value,
  145. .set = mcf_gpio_set_value_fast,
  146. .base = 56,
  147. .ngpio = 8,
  148. },
  149. .pddr = (void __iomem *)MCFGPIO_DDRC,
  150. .podr = (void __iomem *)MCFGPIO_PORTC,
  151. .ppdr = (void __iomem *)MCFGPIO_PORTCP,
  152. .setr = (void __iomem *)MCFGPIO_SETC,
  153. .clrr = (void __iomem *)MCFGPIO_CLRC,
  154. },
  155. {
  156. .gpio_chip = {
  157. .label = "D",
  158. .request = mcf_gpio_request,
  159. .free = mcf_gpio_free,
  160. .direction_input = mcf_gpio_direction_input,
  161. .direction_output = mcf_gpio_direction_output,
  162. .get = mcf_gpio_get_value,
  163. .set = mcf_gpio_set_value_fast,
  164. .base = 64,
  165. .ngpio = 8,
  166. },
  167. .pddr = (void __iomem *)MCFGPIO_DDRD,
  168. .podr = (void __iomem *)MCFGPIO_PORTD,
  169. .ppdr = (void __iomem *)MCFGPIO_PORTDP,
  170. .setr = (void __iomem *)MCFGPIO_SETD,
  171. .clrr = (void __iomem *)MCFGPIO_CLRD,
  172. },
  173. {
  174. .gpio_chip = {
  175. .label = "E",
  176. .request = mcf_gpio_request,
  177. .free = mcf_gpio_free,
  178. .direction_input = mcf_gpio_direction_input,
  179. .direction_output = mcf_gpio_direction_output,
  180. .get = mcf_gpio_get_value,
  181. .set = mcf_gpio_set_value_fast,
  182. .base = 72,
  183. .ngpio = 8,
  184. },
  185. .pddr = (void __iomem *)MCFGPIO_DDRE,
  186. .podr = (void __iomem *)MCFGPIO_PORTE,
  187. .ppdr = (void __iomem *)MCFGPIO_PORTEP,
  188. .setr = (void __iomem *)MCFGPIO_SETE,
  189. .clrr = (void __iomem *)MCFGPIO_CLRE,
  190. },
  191. {
  192. .gpio_chip = {
  193. .label = "F",
  194. .request = mcf_gpio_request,
  195. .free = mcf_gpio_free,
  196. .direction_input = mcf_gpio_direction_input,
  197. .direction_output = mcf_gpio_direction_output,
  198. .get = mcf_gpio_get_value,
  199. .set = mcf_gpio_set_value_fast,
  200. .base = 80,
  201. .ngpio = 8,
  202. },
  203. .pddr = (void __iomem *)MCFGPIO_DDRF,
  204. .podr = (void __iomem *)MCFGPIO_PORTF,
  205. .ppdr = (void __iomem *)MCFGPIO_PORTFP,
  206. .setr = (void __iomem *)MCFGPIO_SETF,
  207. .clrr = (void __iomem *)MCFGPIO_CLRF,
  208. },
  209. {
  210. .gpio_chip = {
  211. .label = "G",
  212. .request = mcf_gpio_request,
  213. .free = mcf_gpio_free,
  214. .direction_input = mcf_gpio_direction_input,
  215. .direction_output = mcf_gpio_direction_output,
  216. .get = mcf_gpio_get_value,
  217. .set = mcf_gpio_set_value_fast,
  218. .base = 88,
  219. .ngpio = 8,
  220. },
  221. .pddr = (void __iomem *)MCFGPIO_DDRG,
  222. .podr = (void __iomem *)MCFGPIO_PORTG,
  223. .ppdr = (void __iomem *)MCFGPIO_PORTGP,
  224. .setr = (void __iomem *)MCFGPIO_SETG,
  225. .clrr = (void __iomem *)MCFGPIO_CLRG,
  226. },
  227. {
  228. .gpio_chip = {
  229. .label = "H",
  230. .request = mcf_gpio_request,
  231. .free = mcf_gpio_free,
  232. .direction_input = mcf_gpio_direction_input,
  233. .direction_output = mcf_gpio_direction_output,
  234. .get = mcf_gpio_get_value,
  235. .set = mcf_gpio_set_value_fast,
  236. .base = 96,
  237. .ngpio = 8,
  238. },
  239. .pddr = (void __iomem *)MCFGPIO_DDRH,
  240. .podr = (void __iomem *)MCFGPIO_PORTH,
  241. .ppdr = (void __iomem *)MCFGPIO_PORTHP,
  242. .setr = (void __iomem *)MCFGPIO_SETH,
  243. .clrr = (void __iomem *)MCFGPIO_CLRH,
  244. },
  245. {
  246. .gpio_chip = {
  247. .label = "J",
  248. .request = mcf_gpio_request,
  249. .free = mcf_gpio_free,
  250. .direction_input = mcf_gpio_direction_input,
  251. .direction_output = mcf_gpio_direction_output,
  252. .get = mcf_gpio_get_value,
  253. .set = mcf_gpio_set_value_fast,
  254. .base = 104,
  255. .ngpio = 8,
  256. },
  257. .pddr = (void __iomem *)MCFGPIO_DDRJ,
  258. .podr = (void __iomem *)MCFGPIO_PORTJ,
  259. .ppdr = (void __iomem *)MCFGPIO_PORTJP,
  260. .setr = (void __iomem *)MCFGPIO_SETJ,
  261. .clrr = (void __iomem *)MCFGPIO_CLRJ,
  262. },
  263. {
  264. .gpio_chip = {
  265. .label = "DD",
  266. .request = mcf_gpio_request,
  267. .free = mcf_gpio_free,
  268. .direction_input = mcf_gpio_direction_input,
  269. .direction_output = mcf_gpio_direction_output,
  270. .get = mcf_gpio_get_value,
  271. .set = mcf_gpio_set_value_fast,
  272. .base = 112,
  273. .ngpio = 8,
  274. },
  275. .pddr = (void __iomem *)MCFGPIO_DDRDD,
  276. .podr = (void __iomem *)MCFGPIO_PORTDD,
  277. .ppdr = (void __iomem *)MCFGPIO_PORTDDP,
  278. .setr = (void __iomem *)MCFGPIO_SETDD,
  279. .clrr = (void __iomem *)MCFGPIO_CLRDD,
  280. },
  281. {
  282. .gpio_chip = {
  283. .label = "EH",
  284. .request = mcf_gpio_request,
  285. .free = mcf_gpio_free,
  286. .direction_input = mcf_gpio_direction_input,
  287. .direction_output = mcf_gpio_direction_output,
  288. .get = mcf_gpio_get_value,
  289. .set = mcf_gpio_set_value_fast,
  290. .base = 120,
  291. .ngpio = 8,
  292. },
  293. .pddr = (void __iomem *)MCFGPIO_DDREH,
  294. .podr = (void __iomem *)MCFGPIO_PORTEH,
  295. .ppdr = (void __iomem *)MCFGPIO_PORTEHP,
  296. .setr = (void __iomem *)MCFGPIO_SETEH,
  297. .clrr = (void __iomem *)MCFGPIO_CLREH,
  298. },
  299. {
  300. .gpio_chip = {
  301. .label = "EL",
  302. .request = mcf_gpio_request,
  303. .free = mcf_gpio_free,
  304. .direction_input = mcf_gpio_direction_input,
  305. .direction_output = mcf_gpio_direction_output,
  306. .get = mcf_gpio_get_value,
  307. .set = mcf_gpio_set_value_fast,
  308. .base = 128,
  309. .ngpio = 8,
  310. },
  311. .pddr = (void __iomem *)MCFGPIO_DDREL,
  312. .podr = (void __iomem *)MCFGPIO_PORTEL,
  313. .ppdr = (void __iomem *)MCFGPIO_PORTELP,
  314. .setr = (void __iomem *)MCFGPIO_SETEL,
  315. .clrr = (void __iomem *)MCFGPIO_CLREL,
  316. },
  317. {
  318. .gpio_chip = {
  319. .label = "AS",
  320. .request = mcf_gpio_request,
  321. .free = mcf_gpio_free,
  322. .direction_input = mcf_gpio_direction_input,
  323. .direction_output = mcf_gpio_direction_output,
  324. .get = mcf_gpio_get_value,
  325. .set = mcf_gpio_set_value_fast,
  326. .base = 136,
  327. .ngpio = 6,
  328. },
  329. .pddr = (void __iomem *)MCFGPIO_DDRAS,
  330. .podr = (void __iomem *)MCFGPIO_PORTAS,
  331. .ppdr = (void __iomem *)MCFGPIO_PORTASP,
  332. .setr = (void __iomem *)MCFGPIO_SETAS,
  333. .clrr = (void __iomem *)MCFGPIO_CLRAS,
  334. },
  335. {
  336. .gpio_chip = {
  337. .label = "QS",
  338. .request = mcf_gpio_request,
  339. .free = mcf_gpio_free,
  340. .direction_input = mcf_gpio_direction_input,
  341. .direction_output = mcf_gpio_direction_output,
  342. .get = mcf_gpio_get_value,
  343. .set = mcf_gpio_set_value_fast,
  344. .base = 144,
  345. .ngpio = 7,
  346. },
  347. .pddr = (void __iomem *)MCFGPIO_DDRQS,
  348. .podr = (void __iomem *)MCFGPIO_PORTQS,
  349. .ppdr = (void __iomem *)MCFGPIO_PORTQSP,
  350. .setr = (void __iomem *)MCFGPIO_SETQS,
  351. .clrr = (void __iomem *)MCFGPIO_CLRQS,
  352. },
  353. {
  354. .gpio_chip = {
  355. .label = "SD",
  356. .request = mcf_gpio_request,
  357. .free = mcf_gpio_free,
  358. .direction_input = mcf_gpio_direction_input,
  359. .direction_output = mcf_gpio_direction_output,
  360. .get = mcf_gpio_get_value,
  361. .set = mcf_gpio_set_value_fast,
  362. .base = 152,
  363. .ngpio = 6,
  364. },
  365. .pddr = (void __iomem *)MCFGPIO_DDRSD,
  366. .podr = (void __iomem *)MCFGPIO_PORTSD,
  367. .ppdr = (void __iomem *)MCFGPIO_PORTSDP,
  368. .setr = (void __iomem *)MCFGPIO_SETSD,
  369. .clrr = (void __iomem *)MCFGPIO_CLRSD,
  370. },
  371. {
  372. .gpio_chip = {
  373. .label = "TC",
  374. .request = mcf_gpio_request,
  375. .free = mcf_gpio_free,
  376. .direction_input = mcf_gpio_direction_input,
  377. .direction_output = mcf_gpio_direction_output,
  378. .get = mcf_gpio_get_value,
  379. .set = mcf_gpio_set_value_fast,
  380. .base = 160,
  381. .ngpio = 4,
  382. },
  383. .pddr = (void __iomem *)MCFGPIO_DDRTC,
  384. .podr = (void __iomem *)MCFGPIO_PORTTC,
  385. .ppdr = (void __iomem *)MCFGPIO_PORTTCP,
  386. .setr = (void __iomem *)MCFGPIO_SETTC,
  387. .clrr = (void __iomem *)MCFGPIO_CLRTC,
  388. },
  389. {
  390. .gpio_chip = {
  391. .label = "TD",
  392. .request = mcf_gpio_request,
  393. .free = mcf_gpio_free,
  394. .direction_input = mcf_gpio_direction_input,
  395. .direction_output = mcf_gpio_direction_output,
  396. .get = mcf_gpio_get_value,
  397. .set = mcf_gpio_set_value_fast,
  398. .base = 168,
  399. .ngpio = 4,
  400. },
  401. .pddr = (void __iomem *)MCFGPIO_DDRTD,
  402. .podr = (void __iomem *)MCFGPIO_PORTTD,
  403. .ppdr = (void __iomem *)MCFGPIO_PORTTDP,
  404. .setr = (void __iomem *)MCFGPIO_SETTD,
  405. .clrr = (void __iomem *)MCFGPIO_CLRTD,
  406. },
  407. {
  408. .gpio_chip = {
  409. .label = "UA",
  410. .request = mcf_gpio_request,
  411. .free = mcf_gpio_free,
  412. .direction_input = mcf_gpio_direction_input,
  413. .direction_output = mcf_gpio_direction_output,
  414. .get = mcf_gpio_get_value,
  415. .set = mcf_gpio_set_value_fast,
  416. .base = 176,
  417. .ngpio = 4,
  418. },
  419. .pddr = (void __iomem *)MCFGPIO_DDRUA,
  420. .podr = (void __iomem *)MCFGPIO_PORTUA,
  421. .ppdr = (void __iomem *)MCFGPIO_PORTUAP,
  422. .setr = (void __iomem *)MCFGPIO_SETUA,
  423. .clrr = (void __iomem *)MCFGPIO_CLRUA,
  424. },
  425. };
  426. static int __init mcf_gpio_init(void)
  427. {
  428. unsigned i = 0;
  429. while (i < ARRAY_SIZE(mcf_gpio_chips))
  430. (void)gpiochip_add((struct gpio_chip *)&mcf_gpio_chips[i++]);
  431. return 0;
  432. }
  433. core_initcall(mcf_gpio_init);