iopin_8xx.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /*
  2. * SPDX-License-Identifier: GPL-2.0+
  3. */
  4. /*
  5. * MPC8xx I/O port pin manipulation functions
  6. * Roughly based on iopin_8260.h
  7. */
  8. #ifndef _ASM_IOPIN_8XX_H_
  9. #define _ASM_IOPIN_8XX_H_
  10. #include <linux/types.h>
  11. #include <asm/8xx_immap.h>
  12. #ifdef __KERNEL__
  13. typedef struct {
  14. u_char port:2; /* port number (A=0, B=1, C=2, D=3) */
  15. u_char pin:5; /* port pin (0-31) */
  16. u_char flag:1; /* for whatever */
  17. } iopin_t;
  18. #define IOPIN_PORTA 0
  19. #define IOPIN_PORTB 1
  20. #define IOPIN_PORTC 2
  21. #define IOPIN_PORTD 3
  22. static __inline__ void
  23. iopin_set_high(iopin_t *iopin)
  24. {
  25. if (iopin->port == IOPIN_PORTA) {
  26. volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padat;
  27. *datp |= (1 << (15 - iopin->pin));
  28. } else if (iopin->port == IOPIN_PORTB) {
  29. volatile uint *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdat;
  30. *datp |= (1 << (31 - iopin->pin));
  31. } else if (iopin->port == IOPIN_PORTC) {
  32. volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat;
  33. *datp |= (1 << (15 - iopin->pin));
  34. } else if (iopin->port == IOPIN_PORTD) {
  35. volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddat;
  36. *datp |= (1 << (15 - iopin->pin));
  37. }
  38. }
  39. static __inline__ void
  40. iopin_set_low(iopin_t *iopin)
  41. {
  42. if (iopin->port == IOPIN_PORTA) {
  43. volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padat;
  44. *datp &= ~(1 << (15 - iopin->pin));
  45. } else if (iopin->port == IOPIN_PORTB) {
  46. volatile uint *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdat;
  47. *datp &= ~(1 << (31 - iopin->pin));
  48. } else if (iopin->port == IOPIN_PORTC) {
  49. volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat;
  50. *datp &= ~(1 << (15 - iopin->pin));
  51. } else if (iopin->port == IOPIN_PORTD) {
  52. volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddat;
  53. *datp &= ~(1 << (15 - iopin->pin));
  54. }
  55. }
  56. static __inline__ uint
  57. iopin_is_high(iopin_t *iopin)
  58. {
  59. if (iopin->port == IOPIN_PORTA) {
  60. volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padat;
  61. return (*datp >> (15 - iopin->pin)) & 1;
  62. } else if (iopin->port == IOPIN_PORTB) {
  63. volatile uint *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdat;
  64. return (*datp >> (31 - iopin->pin)) & 1;
  65. } else if (iopin->port == IOPIN_PORTC) {
  66. volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat;
  67. return (*datp >> (15 - iopin->pin)) & 1;
  68. } else if (iopin->port == IOPIN_PORTD) {
  69. volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddat;
  70. return (*datp >> (15 - iopin->pin)) & 1;
  71. }
  72. return 0;
  73. }
  74. static __inline__ uint
  75. iopin_is_low(iopin_t *iopin)
  76. {
  77. if (iopin->port == IOPIN_PORTA) {
  78. volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padat;
  79. return ((*datp >> (15 - iopin->pin)) & 1) ^ 1;
  80. } else if (iopin->port == IOPIN_PORTB) {
  81. volatile uint *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdat;
  82. return ((*datp >> (31 - iopin->pin)) & 1) ^ 1;
  83. } else if (iopin->port == IOPIN_PORTC) {
  84. volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat;
  85. return ((*datp >> (15 - iopin->pin)) & 1) ^ 1;
  86. } else if (iopin->port == IOPIN_PORTD) {
  87. volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddat;
  88. return ((*datp >> (15 - iopin->pin)) & 1) ^ 1;
  89. }
  90. return 0;
  91. }
  92. static __inline__ void
  93. iopin_set_out(iopin_t *iopin)
  94. {
  95. if (iopin->port == IOPIN_PORTA) {
  96. volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padir;
  97. *dirp |= (1 << (15 - iopin->pin));
  98. } else if (iopin->port == IOPIN_PORTB) {
  99. volatile uint *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdir;
  100. *dirp |= (1 << (31 - iopin->pin));
  101. } else if (iopin->port == IOPIN_PORTC) {
  102. volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdir;
  103. *dirp |= (1 << (15 - iopin->pin));
  104. } else if (iopin->port == IOPIN_PORTD) {
  105. volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddir;
  106. *dirp |= (1 << (15 - iopin->pin));
  107. }
  108. }
  109. static __inline__ void
  110. iopin_set_in(iopin_t *iopin)
  111. {
  112. if (iopin->port == IOPIN_PORTA) {
  113. volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padir;
  114. *dirp &= ~(1 << (15 - iopin->pin));
  115. } else if (iopin->port == IOPIN_PORTB) {
  116. volatile uint *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdir;
  117. *dirp &= ~(1 << (31 - iopin->pin));
  118. } else if (iopin->port == IOPIN_PORTC) {
  119. volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdir;
  120. *dirp &= ~(1 << (15 - iopin->pin));
  121. } else if (iopin->port == IOPIN_PORTD) {
  122. volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddir;
  123. *dirp &= ~(1 << (15 - iopin->pin));
  124. }
  125. }
  126. static __inline__ uint
  127. iopin_is_out(iopin_t *iopin)
  128. {
  129. if (iopin->port == IOPIN_PORTA) {
  130. volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padir;
  131. return (*dirp >> (15 - iopin->pin)) & 1;
  132. } else if (iopin->port == IOPIN_PORTB) {
  133. volatile uint *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdir;
  134. return (*dirp >> (31 - iopin->pin)) & 1;
  135. } else if (iopin->port == IOPIN_PORTC) {
  136. volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdir;
  137. return (*dirp >> (15 - iopin->pin)) & 1;
  138. } else if (iopin->port == IOPIN_PORTD) {
  139. volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddir;
  140. return (*dirp >> (15 - iopin->pin)) & 1;
  141. }
  142. return 0;
  143. }
  144. static __inline__ uint
  145. iopin_is_in(iopin_t *iopin)
  146. {
  147. if (iopin->port == IOPIN_PORTA) {
  148. volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padir;
  149. return ((*dirp >> (15 - iopin->pin)) & 1) ^ 1;
  150. } else if (iopin->port == IOPIN_PORTB) {
  151. volatile uint *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdir;
  152. return ((*dirp >> (31 - iopin->pin)) & 1) ^ 1;
  153. } else if (iopin->port == IOPIN_PORTC) {
  154. volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdir;
  155. return ((*dirp >> (15 - iopin->pin)) & 1) ^ 1;
  156. } else if (iopin->port == IOPIN_PORTD) {
  157. volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddir;
  158. return ((*dirp >> (15 - iopin->pin)) & 1) ^ 1;
  159. }
  160. return 0;
  161. }
  162. static __inline__ void
  163. iopin_set_odr(iopin_t *iopin)
  164. {
  165. if (iopin->port == IOPIN_PORTA) {
  166. volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_paodr;
  167. *odrp |= (1 << (15 - iopin->pin));
  168. } else if (iopin->port == IOPIN_PORTB) {
  169. volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbodr;
  170. *odrp |= (1 << (31 - iopin->pin));
  171. }
  172. }
  173. static __inline__ void
  174. iopin_set_act(iopin_t *iopin)
  175. {
  176. if (iopin->port == IOPIN_PORTA) {
  177. volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_paodr;
  178. *odrp &= ~(1 << (15 - iopin->pin));
  179. } else if (iopin->port == IOPIN_PORTB) {
  180. volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbodr;
  181. *odrp &= ~(1 << (31 - iopin->pin));
  182. }
  183. }
  184. static __inline__ uint
  185. iopin_is_odr(iopin_t *iopin)
  186. {
  187. if (iopin->port == IOPIN_PORTA) {
  188. volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_paodr;
  189. return (*odrp >> (15 - iopin->pin)) & 1;
  190. } else if (iopin->port == IOPIN_PORTB) {
  191. volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbodr;
  192. return (*odrp >> (31 - iopin->pin)) & 1;
  193. }
  194. return 0;
  195. }
  196. static __inline__ uint
  197. iopin_is_act(iopin_t *iopin)
  198. {
  199. if (iopin->port == IOPIN_PORTA) {
  200. volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_paodr;
  201. return ((*odrp >> (15 - iopin->pin)) & 1) ^ 1;
  202. } else if (iopin->port == IOPIN_PORTB) {
  203. volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbodr;
  204. return ((*odrp >> (31 - iopin->pin)) & 1) ^ 1;
  205. }
  206. return 0;
  207. }
  208. static __inline__ void
  209. iopin_set_ded(iopin_t *iopin)
  210. {
  211. if (iopin->port == IOPIN_PORTA) {
  212. volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_papar;
  213. *parp |= (1 << (15 - iopin->pin));
  214. } else if (iopin->port == IOPIN_PORTB) {
  215. volatile uint *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbpar;
  216. *parp |= (1 << (31 - iopin->pin));
  217. } else if (iopin->port == IOPIN_PORTC) {
  218. volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcpar;
  219. *parp |= (1 << (15 - iopin->pin));
  220. } else if (iopin->port == IOPIN_PORTD) {
  221. volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pdpar;
  222. *parp |= (1 << (15 - iopin->pin));
  223. }
  224. }
  225. static __inline__ void
  226. iopin_set_gen(iopin_t *iopin)
  227. {
  228. if (iopin->port == IOPIN_PORTA) {
  229. volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_papar;
  230. *parp &= ~(1 << (15 - iopin->pin));
  231. } else if (iopin->port == IOPIN_PORTB) {
  232. volatile uint *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbpar;
  233. *parp &= ~(1 << (31 - iopin->pin));
  234. } else if (iopin->port == IOPIN_PORTC) {
  235. volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcpar;
  236. *parp &= ~(1 << (15 - iopin->pin));
  237. } else if (iopin->port == IOPIN_PORTD) {
  238. volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pdpar;
  239. *parp &= ~(1 << (15 - iopin->pin));
  240. }
  241. }
  242. static __inline__ uint
  243. iopin_is_ded(iopin_t *iopin)
  244. {
  245. if (iopin->port == IOPIN_PORTA) {
  246. volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_papar;
  247. return (*parp >> (15 - iopin->pin)) & 1;
  248. } else if (iopin->port == IOPIN_PORTB) {
  249. volatile uint *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbpar;
  250. return (*parp >> (31 - iopin->pin)) & 1;
  251. } else if (iopin->port == IOPIN_PORTC) {
  252. volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcpar;
  253. return (*parp >> (15 - iopin->pin)) & 1;
  254. } else if (iopin->port == IOPIN_PORTD) {
  255. volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pdpar;
  256. return (*parp >> (15 - iopin->pin)) & 1;
  257. }
  258. return 0;
  259. }
  260. static __inline__ uint
  261. iopin_is_gen(iopin_t *iopin)
  262. {
  263. if (iopin->port == IOPIN_PORTA) {
  264. volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_papar;
  265. return ((*parp >> (15 - iopin->pin)) & 1) ^ 1;
  266. } else if (iopin->port == IOPIN_PORTB) {
  267. volatile uint *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbpar;
  268. return ((*parp >> (31 - iopin->pin)) & 1) ^ 1;
  269. } else if (iopin->port == IOPIN_PORTC) {
  270. volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcpar;
  271. return ((*parp >> (15 - iopin->pin)) & 1) ^ 1;
  272. } else if (iopin->port == IOPIN_PORTD) {
  273. volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pdpar;
  274. return ((*parp >> (15 - iopin->pin)) & 1) ^ 1;
  275. }
  276. return 0;
  277. }
  278. static __inline__ void
  279. iopin_set_opt2(iopin_t *iopin)
  280. {
  281. if (iopin->port == IOPIN_PORTC) {
  282. volatile ushort *sorp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcso;
  283. *sorp |= (1 << (15 - iopin->pin));
  284. }
  285. }
  286. static __inline__ void
  287. iopin_set_opt1(iopin_t *iopin)
  288. {
  289. if (iopin->port == IOPIN_PORTC) {
  290. volatile ushort *sorp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcso;
  291. *sorp &= ~(1 << (15 - iopin->pin));
  292. }
  293. }
  294. static __inline__ uint
  295. iopin_is_opt2(iopin_t *iopin)
  296. {
  297. if (iopin->port == IOPIN_PORTC) {
  298. volatile ushort *sorp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcso;
  299. return (*sorp >> (15 - iopin->pin)) & 1;
  300. }
  301. return 0;
  302. }
  303. static __inline__ uint
  304. iopin_is_opt1(iopin_t *iopin)
  305. {
  306. if (iopin->port == IOPIN_PORTC) {
  307. volatile ushort *sorp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcso;
  308. return ((*sorp >> (15 - iopin->pin)) & 1) ^ 1;
  309. }
  310. return 0;
  311. }
  312. static __inline__ void
  313. iopin_set_falledge(iopin_t *iopin)
  314. {
  315. if (iopin->port == IOPIN_PORTC) {
  316. volatile ushort *intp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcint;
  317. *intp |= (1 << (15 - iopin->pin));
  318. }
  319. }
  320. static __inline__ void
  321. iopin_set_anyedge(iopin_t *iopin)
  322. {
  323. if (iopin->port == IOPIN_PORTC) {
  324. volatile ushort *intp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcint;
  325. *intp &= ~(1 << (15 - iopin->pin));
  326. }
  327. }
  328. static __inline__ uint
  329. iopin_is_falledge(iopin_t *iopin)
  330. {
  331. if (iopin->port == IOPIN_PORTC) {
  332. volatile ushort *intp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcint;
  333. return (*intp >> (15 - iopin->pin)) & 1;
  334. }
  335. return 0;
  336. }
  337. static __inline__ uint
  338. iopin_is_anyedge(iopin_t *iopin)
  339. {
  340. if (iopin->port == IOPIN_PORTC) {
  341. volatile ushort *intp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcint;
  342. return ((*intp >> (15 - iopin->pin)) & 1) ^ 1;
  343. }
  344. return 0;
  345. }
  346. #endif /* __KERNEL__ */
  347. #endif /* _ASM_IOPIN_8XX_H_ */