setup_opsput.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. /*
  2. * linux/arch/m32r/kernel/setup_opsput.c
  3. *
  4. * Setup routines for Renesas OPSPUT Board
  5. *
  6. * Copyright (c) 2002-2004
  7. * Hiroyuki Kondo, Hirokazu Takata,
  8. * Hitoshi Yamamoto, Takeo Takahashi, Mamoru Sakugawa
  9. *
  10. * This file is subject to the terms and conditions of the GNU General
  11. * Public License. See the file "COPYING" in the main directory of this
  12. * archive for more details.
  13. */
  14. #include <linux/config.h>
  15. #include <linux/irq.h>
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/device.h>
  19. #include <asm/system.h>
  20. #include <asm/m32r.h>
  21. #include <asm/io.h>
  22. /*
  23. * OPSP Interrupt Control Unit (Level 1)
  24. */
  25. #define irq2port(x) (M32R_ICU_CR1_PORTL + ((x - 1) * sizeof(unsigned long)))
  26. #ifndef CONFIG_SMP
  27. typedef struct {
  28. unsigned long icucr; /* ICU Control Register */
  29. } icu_data_t;
  30. #endif /* CONFIG_SMP */
  31. static icu_data_t icu_data[OPSPUT_NUM_CPU_IRQ];
  32. static void disable_opsput_irq(unsigned int irq)
  33. {
  34. unsigned long port, data;
  35. port = irq2port(irq);
  36. data = icu_data[irq].icucr|M32R_ICUCR_ILEVEL7;
  37. outl(data, port);
  38. }
  39. static void enable_opsput_irq(unsigned int irq)
  40. {
  41. unsigned long port, data;
  42. port = irq2port(irq);
  43. data = icu_data[irq].icucr|M32R_ICUCR_IEN|M32R_ICUCR_ILEVEL6;
  44. outl(data, port);
  45. }
  46. static void mask_and_ack_opsput(unsigned int irq)
  47. {
  48. disable_opsput_irq(irq);
  49. }
  50. static void end_opsput_irq(unsigned int irq)
  51. {
  52. enable_opsput_irq(irq);
  53. }
  54. static unsigned int startup_opsput_irq(unsigned int irq)
  55. {
  56. enable_opsput_irq(irq);
  57. return (0);
  58. }
  59. static void shutdown_opsput_irq(unsigned int irq)
  60. {
  61. unsigned long port;
  62. port = irq2port(irq);
  63. outl(M32R_ICUCR_ILEVEL7, port);
  64. }
  65. static struct hw_interrupt_type opsput_irq_type =
  66. {
  67. .typename = "OPSPUT-IRQ",
  68. .startup = startup_opsput_irq,
  69. .shutdown = shutdown_opsput_irq,
  70. .enable = enable_opsput_irq,
  71. .disable = disable_opsput_irq,
  72. .ack = mask_and_ack_opsput,
  73. .end = end_opsput_irq
  74. };
  75. /*
  76. * Interrupt Control Unit of PLD on OPSPUT (Level 2)
  77. */
  78. #define irq2pldirq(x) ((x) - OPSPUT_PLD_IRQ_BASE)
  79. #define pldirq2port(x) (unsigned long)((int)PLD_ICUCR1 + \
  80. (((x) - 1) * sizeof(unsigned short)))
  81. typedef struct {
  82. unsigned short icucr; /* ICU Control Register */
  83. } pld_icu_data_t;
  84. static pld_icu_data_t pld_icu_data[OPSPUT_NUM_PLD_IRQ];
  85. static void disable_opsput_pld_irq(unsigned int irq)
  86. {
  87. unsigned long port, data;
  88. unsigned int pldirq;
  89. pldirq = irq2pldirq(irq);
  90. // disable_opsput_irq(M32R_IRQ_INT1);
  91. port = pldirq2port(pldirq);
  92. data = pld_icu_data[pldirq].icucr|PLD_ICUCR_ILEVEL7;
  93. outw(data, port);
  94. }
  95. static void enable_opsput_pld_irq(unsigned int irq)
  96. {
  97. unsigned long port, data;
  98. unsigned int pldirq;
  99. pldirq = irq2pldirq(irq);
  100. // enable_opsput_irq(M32R_IRQ_INT1);
  101. port = pldirq2port(pldirq);
  102. data = pld_icu_data[pldirq].icucr|PLD_ICUCR_IEN|PLD_ICUCR_ILEVEL6;
  103. outw(data, port);
  104. }
  105. static void mask_and_ack_opsput_pld(unsigned int irq)
  106. {
  107. disable_opsput_pld_irq(irq);
  108. // mask_and_ack_opsput(M32R_IRQ_INT1);
  109. }
  110. static void end_opsput_pld_irq(unsigned int irq)
  111. {
  112. enable_opsput_pld_irq(irq);
  113. end_opsput_irq(M32R_IRQ_INT1);
  114. }
  115. static unsigned int startup_opsput_pld_irq(unsigned int irq)
  116. {
  117. enable_opsput_pld_irq(irq);
  118. return (0);
  119. }
  120. static void shutdown_opsput_pld_irq(unsigned int irq)
  121. {
  122. unsigned long port;
  123. unsigned int pldirq;
  124. pldirq = irq2pldirq(irq);
  125. // shutdown_opsput_irq(M32R_IRQ_INT1);
  126. port = pldirq2port(pldirq);
  127. outw(PLD_ICUCR_ILEVEL7, port);
  128. }
  129. static struct hw_interrupt_type opsput_pld_irq_type =
  130. {
  131. .typename = "OPSPUT-PLD-IRQ",
  132. .startup = startup_opsput_pld_irq,
  133. .shutdown = shutdown_opsput_pld_irq,
  134. .enable = enable_opsput_pld_irq,
  135. .disable = disable_opsput_pld_irq,
  136. .ack = mask_and_ack_opsput_pld,
  137. .end = end_opsput_pld_irq
  138. };
  139. /*
  140. * Interrupt Control Unit of PLD on OPSPUT-LAN (Level 2)
  141. */
  142. #define irq2lanpldirq(x) ((x) - OPSPUT_LAN_PLD_IRQ_BASE)
  143. #define lanpldirq2port(x) (unsigned long)((int)OPSPUT_LAN_ICUCR1 + \
  144. (((x) - 1) * sizeof(unsigned short)))
  145. static pld_icu_data_t lanpld_icu_data[OPSPUT_NUM_LAN_PLD_IRQ];
  146. static void disable_opsput_lanpld_irq(unsigned int irq)
  147. {
  148. unsigned long port, data;
  149. unsigned int pldirq;
  150. pldirq = irq2lanpldirq(irq);
  151. port = lanpldirq2port(pldirq);
  152. data = lanpld_icu_data[pldirq].icucr|PLD_ICUCR_ILEVEL7;
  153. outw(data, port);
  154. }
  155. static void enable_opsput_lanpld_irq(unsigned int irq)
  156. {
  157. unsigned long port, data;
  158. unsigned int pldirq;
  159. pldirq = irq2lanpldirq(irq);
  160. port = lanpldirq2port(pldirq);
  161. data = lanpld_icu_data[pldirq].icucr|PLD_ICUCR_IEN|PLD_ICUCR_ILEVEL6;
  162. outw(data, port);
  163. }
  164. static void mask_and_ack_opsput_lanpld(unsigned int irq)
  165. {
  166. disable_opsput_lanpld_irq(irq);
  167. }
  168. static void end_opsput_lanpld_irq(unsigned int irq)
  169. {
  170. enable_opsput_lanpld_irq(irq);
  171. end_opsput_irq(M32R_IRQ_INT0);
  172. }
  173. static unsigned int startup_opsput_lanpld_irq(unsigned int irq)
  174. {
  175. enable_opsput_lanpld_irq(irq);
  176. return (0);
  177. }
  178. static void shutdown_opsput_lanpld_irq(unsigned int irq)
  179. {
  180. unsigned long port;
  181. unsigned int pldirq;
  182. pldirq = irq2lanpldirq(irq);
  183. port = lanpldirq2port(pldirq);
  184. outw(PLD_ICUCR_ILEVEL7, port);
  185. }
  186. static struct hw_interrupt_type opsput_lanpld_irq_type =
  187. {
  188. "OPSPUT-PLD-LAN-IRQ",
  189. startup_opsput_lanpld_irq,
  190. shutdown_opsput_lanpld_irq,
  191. enable_opsput_lanpld_irq,
  192. disable_opsput_lanpld_irq,
  193. mask_and_ack_opsput_lanpld,
  194. end_opsput_lanpld_irq
  195. };
  196. /*
  197. * Interrupt Control Unit of PLD on OPSPUT-LCD (Level 2)
  198. */
  199. #define irq2lcdpldirq(x) ((x) - OPSPUT_LCD_PLD_IRQ_BASE)
  200. #define lcdpldirq2port(x) (unsigned long)((int)OPSPUT_LCD_ICUCR1 + \
  201. (((x) - 1) * sizeof(unsigned short)))
  202. static pld_icu_data_t lcdpld_icu_data[OPSPUT_NUM_LCD_PLD_IRQ];
  203. static void disable_opsput_lcdpld_irq(unsigned int irq)
  204. {
  205. unsigned long port, data;
  206. unsigned int pldirq;
  207. pldirq = irq2lcdpldirq(irq);
  208. port = lcdpldirq2port(pldirq);
  209. data = lcdpld_icu_data[pldirq].icucr|PLD_ICUCR_ILEVEL7;
  210. outw(data, port);
  211. }
  212. static void enable_opsput_lcdpld_irq(unsigned int irq)
  213. {
  214. unsigned long port, data;
  215. unsigned int pldirq;
  216. pldirq = irq2lcdpldirq(irq);
  217. port = lcdpldirq2port(pldirq);
  218. data = lcdpld_icu_data[pldirq].icucr|PLD_ICUCR_IEN|PLD_ICUCR_ILEVEL6;
  219. outw(data, port);
  220. }
  221. static void mask_and_ack_opsput_lcdpld(unsigned int irq)
  222. {
  223. disable_opsput_lcdpld_irq(irq);
  224. }
  225. static void end_opsput_lcdpld_irq(unsigned int irq)
  226. {
  227. enable_opsput_lcdpld_irq(irq);
  228. end_opsput_irq(M32R_IRQ_INT2);
  229. }
  230. static unsigned int startup_opsput_lcdpld_irq(unsigned int irq)
  231. {
  232. enable_opsput_lcdpld_irq(irq);
  233. return (0);
  234. }
  235. static void shutdown_opsput_lcdpld_irq(unsigned int irq)
  236. {
  237. unsigned long port;
  238. unsigned int pldirq;
  239. pldirq = irq2lcdpldirq(irq);
  240. port = lcdpldirq2port(pldirq);
  241. outw(PLD_ICUCR_ILEVEL7, port);
  242. }
  243. static struct hw_interrupt_type opsput_lcdpld_irq_type =
  244. {
  245. "OPSPUT-PLD-LCD-IRQ",
  246. startup_opsput_lcdpld_irq,
  247. shutdown_opsput_lcdpld_irq,
  248. enable_opsput_lcdpld_irq,
  249. disable_opsput_lcdpld_irq,
  250. mask_and_ack_opsput_lcdpld,
  251. end_opsput_lcdpld_irq
  252. };
  253. void __init init_IRQ(void)
  254. {
  255. #if defined(CONFIG_SMC91X)
  256. /* INT#0: LAN controller on OPSPUT-LAN (SMC91C111)*/
  257. irq_desc[OPSPUT_LAN_IRQ_LAN].status = IRQ_DISABLED;
  258. irq_desc[OPSPUT_LAN_IRQ_LAN].handler = &opsput_lanpld_irq_type;
  259. irq_desc[OPSPUT_LAN_IRQ_LAN].action = 0;
  260. irq_desc[OPSPUT_LAN_IRQ_LAN].depth = 1; /* disable nested irq */
  261. lanpld_icu_data[irq2lanpldirq(OPSPUT_LAN_IRQ_LAN)].icucr = PLD_ICUCR_IEN|PLD_ICUCR_ISMOD02; /* "H" edge sense */
  262. disable_opsput_lanpld_irq(OPSPUT_LAN_IRQ_LAN);
  263. #endif /* CONFIG_SMC91X */
  264. /* MFT2 : system timer */
  265. irq_desc[M32R_IRQ_MFT2].status = IRQ_DISABLED;
  266. irq_desc[M32R_IRQ_MFT2].handler = &opsput_irq_type;
  267. irq_desc[M32R_IRQ_MFT2].action = 0;
  268. irq_desc[M32R_IRQ_MFT2].depth = 1;
  269. icu_data[M32R_IRQ_MFT2].icucr = M32R_ICUCR_IEN;
  270. disable_opsput_irq(M32R_IRQ_MFT2);
  271. /* SIO0 : receive */
  272. irq_desc[M32R_IRQ_SIO0_R].status = IRQ_DISABLED;
  273. irq_desc[M32R_IRQ_SIO0_R].handler = &opsput_irq_type;
  274. irq_desc[M32R_IRQ_SIO0_R].action = 0;
  275. irq_desc[M32R_IRQ_SIO0_R].depth = 1;
  276. icu_data[M32R_IRQ_SIO0_R].icucr = 0;
  277. disable_opsput_irq(M32R_IRQ_SIO0_R);
  278. /* SIO0 : send */
  279. irq_desc[M32R_IRQ_SIO0_S].status = IRQ_DISABLED;
  280. irq_desc[M32R_IRQ_SIO0_S].handler = &opsput_irq_type;
  281. irq_desc[M32R_IRQ_SIO0_S].action = 0;
  282. irq_desc[M32R_IRQ_SIO0_S].depth = 1;
  283. icu_data[M32R_IRQ_SIO0_S].icucr = 0;
  284. disable_opsput_irq(M32R_IRQ_SIO0_S);
  285. /* SIO1 : receive */
  286. irq_desc[M32R_IRQ_SIO1_R].status = IRQ_DISABLED;
  287. irq_desc[M32R_IRQ_SIO1_R].handler = &opsput_irq_type;
  288. irq_desc[M32R_IRQ_SIO1_R].action = 0;
  289. irq_desc[M32R_IRQ_SIO1_R].depth = 1;
  290. icu_data[M32R_IRQ_SIO1_R].icucr = 0;
  291. disable_opsput_irq(M32R_IRQ_SIO1_R);
  292. /* SIO1 : send */
  293. irq_desc[M32R_IRQ_SIO1_S].status = IRQ_DISABLED;
  294. irq_desc[M32R_IRQ_SIO1_S].handler = &opsput_irq_type;
  295. irq_desc[M32R_IRQ_SIO1_S].action = 0;
  296. irq_desc[M32R_IRQ_SIO1_S].depth = 1;
  297. icu_data[M32R_IRQ_SIO1_S].icucr = 0;
  298. disable_opsput_irq(M32R_IRQ_SIO1_S);
  299. /* DMA1 : */
  300. irq_desc[M32R_IRQ_DMA1].status = IRQ_DISABLED;
  301. irq_desc[M32R_IRQ_DMA1].handler = &opsput_irq_type;
  302. irq_desc[M32R_IRQ_DMA1].action = 0;
  303. irq_desc[M32R_IRQ_DMA1].depth = 1;
  304. icu_data[M32R_IRQ_DMA1].icucr = 0;
  305. disable_opsput_irq(M32R_IRQ_DMA1);
  306. #ifdef CONFIG_SERIAL_M32R_PLDSIO
  307. /* INT#1: SIO0 Receive on PLD */
  308. irq_desc[PLD_IRQ_SIO0_RCV].status = IRQ_DISABLED;
  309. irq_desc[PLD_IRQ_SIO0_RCV].handler = &opsput_pld_irq_type;
  310. irq_desc[PLD_IRQ_SIO0_RCV].action = 0;
  311. irq_desc[PLD_IRQ_SIO0_RCV].depth = 1; /* disable nested irq */
  312. pld_icu_data[irq2pldirq(PLD_IRQ_SIO0_RCV)].icucr = PLD_ICUCR_IEN|PLD_ICUCR_ISMOD03;
  313. disable_opsput_pld_irq(PLD_IRQ_SIO0_RCV);
  314. /* INT#1: SIO0 Send on PLD */
  315. irq_desc[PLD_IRQ_SIO0_SND].status = IRQ_DISABLED;
  316. irq_desc[PLD_IRQ_SIO0_SND].handler = &opsput_pld_irq_type;
  317. irq_desc[PLD_IRQ_SIO0_SND].action = 0;
  318. irq_desc[PLD_IRQ_SIO0_SND].depth = 1; /* disable nested irq */
  319. pld_icu_data[irq2pldirq(PLD_IRQ_SIO0_SND)].icucr = PLD_ICUCR_IEN|PLD_ICUCR_ISMOD03;
  320. disable_opsput_pld_irq(PLD_IRQ_SIO0_SND);
  321. #endif /* CONFIG_SERIAL_M32R_PLDSIO */
  322. #if defined(CONFIG_M32R_CFC)
  323. /* INT#1: CFC IREQ on PLD */
  324. irq_desc[PLD_IRQ_CFIREQ].status = IRQ_DISABLED;
  325. irq_desc[PLD_IRQ_CFIREQ].handler = &opsput_pld_irq_type;
  326. irq_desc[PLD_IRQ_CFIREQ].action = 0;
  327. irq_desc[PLD_IRQ_CFIREQ].depth = 1; /* disable nested irq */
  328. pld_icu_data[irq2pldirq(PLD_IRQ_CFIREQ)].icucr = PLD_ICUCR_IEN|PLD_ICUCR_ISMOD01; /* 'L' level sense */
  329. disable_opsput_pld_irq(PLD_IRQ_CFIREQ);
  330. /* INT#1: CFC Insert on PLD */
  331. irq_desc[PLD_IRQ_CFC_INSERT].status = IRQ_DISABLED;
  332. irq_desc[PLD_IRQ_CFC_INSERT].handler = &opsput_pld_irq_type;
  333. irq_desc[PLD_IRQ_CFC_INSERT].action = 0;
  334. irq_desc[PLD_IRQ_CFC_INSERT].depth = 1; /* disable nested irq */
  335. pld_icu_data[irq2pldirq(PLD_IRQ_CFC_INSERT)].icucr = PLD_ICUCR_IEN|PLD_ICUCR_ISMOD00; /* 'L' edge sense */
  336. disable_opsput_pld_irq(PLD_IRQ_CFC_INSERT);
  337. /* INT#1: CFC Eject on PLD */
  338. irq_desc[PLD_IRQ_CFC_EJECT].status = IRQ_DISABLED;
  339. irq_desc[PLD_IRQ_CFC_EJECT].handler = &opsput_pld_irq_type;
  340. irq_desc[PLD_IRQ_CFC_EJECT].action = 0;
  341. irq_desc[PLD_IRQ_CFC_EJECT].depth = 1; /* disable nested irq */
  342. pld_icu_data[irq2pldirq(PLD_IRQ_CFC_EJECT)].icucr = PLD_ICUCR_IEN|PLD_ICUCR_ISMOD02; /* 'H' edge sense */
  343. disable_opsput_pld_irq(PLD_IRQ_CFC_EJECT);
  344. #endif /* CONFIG_M32R_CFC */
  345. /*
  346. * INT0# is used for LAN, DIO
  347. * We enable it here.
  348. */
  349. icu_data[M32R_IRQ_INT0].icucr = M32R_ICUCR_IEN|M32R_ICUCR_ISMOD11;
  350. enable_opsput_irq(M32R_IRQ_INT0);
  351. /*
  352. * INT1# is used for UART, MMC, CF Controller in FPGA.
  353. * We enable it here.
  354. */
  355. icu_data[M32R_IRQ_INT1].icucr = M32R_ICUCR_IEN|M32R_ICUCR_ISMOD11;
  356. enable_opsput_irq(M32R_IRQ_INT1);
  357. #if defined(CONFIG_USB)
  358. outw(USBCR_OTGS, USBCR); /* USBCR: non-OTG */
  359. irq_desc[OPSPUT_LCD_IRQ_USB_INT1].status = IRQ_DISABLED;
  360. irq_desc[OPSPUT_LCD_IRQ_USB_INT1].handler = &opsput_lcdpld_irq_type;
  361. irq_desc[OPSPUT_LCD_IRQ_USB_INT1].action = 0;
  362. irq_desc[OPSPUT_LCD_IRQ_USB_INT1].depth = 1;
  363. lcdpld_icu_data[irq2lcdpldirq(OPSPUT_LCD_IRQ_USB_INT1)].icucr = PLD_ICUCR_IEN|PLD_ICUCR_ISMOD01; /* "L" level sense */
  364. disable_opsput_lcdpld_irq(OPSPUT_LCD_IRQ_USB_INT1);
  365. #endif
  366. /*
  367. * INT2# is used for BAT, USB, AUDIO
  368. * We enable it here.
  369. */
  370. icu_data[M32R_IRQ_INT2].icucr = M32R_ICUCR_IEN|M32R_ICUCR_ISMOD01;
  371. enable_opsput_irq(M32R_IRQ_INT2);
  372. //#if defined(CONFIG_VIDEO_M32R_AR)
  373. /*
  374. * INT3# is used for AR
  375. */
  376. irq_desc[M32R_IRQ_INT3].status = IRQ_DISABLED;
  377. irq_desc[M32R_IRQ_INT3].handler = &opsput_irq_type;
  378. irq_desc[M32R_IRQ_INT3].action = 0;
  379. irq_desc[M32R_IRQ_INT3].depth = 1;
  380. icu_data[M32R_IRQ_INT3].icucr = M32R_ICUCR_IEN|M32R_ICUCR_ISMOD10;
  381. disable_opsput_irq(M32R_IRQ_INT3);
  382. //#endif /* CONFIG_VIDEO_M32R_AR */
  383. }
  384. #define LAN_IOSTART 0x300
  385. #define LAN_IOEND 0x320
  386. static struct resource smc91x_resources[] = {
  387. [0] = {
  388. .start = (LAN_IOSTART),
  389. .end = (LAN_IOEND),
  390. .flags = IORESOURCE_MEM,
  391. },
  392. [1] = {
  393. .start = OPSPUT_LAN_IRQ_LAN,
  394. .end = OPSPUT_LAN_IRQ_LAN,
  395. .flags = IORESOURCE_IRQ,
  396. }
  397. };
  398. static struct platform_device smc91x_device = {
  399. .name = "smc91x",
  400. .id = 0,
  401. .num_resources = ARRAY_SIZE(smc91x_resources),
  402. .resource = smc91x_resources,
  403. };
  404. static int __init platform_init(void)
  405. {
  406. platform_device_register(&smc91x_device);
  407. return 0;
  408. }
  409. arch_initcall(platform_init);