iopin_8xx.h 13 KB

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