setup.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /*
  2. * arch/sh/boards/superh/microdev/setup.c
  3. *
  4. * Copyright (C) 2003 Sean McGoogan (Sean.McGoogan@superh.com)
  5. * Copyright (C) 2003, 2004 SuperH, Inc.
  6. * Copyright (C) 2004, 2005 Paul Mundt
  7. *
  8. * SuperH SH4-202 MicroDev board support.
  9. *
  10. * May be copied or modified under the terms of the GNU General Public
  11. * License. See linux/COPYING for more information.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/ioport.h>
  16. #include <video/s1d13xxxfb.h>
  17. #include <asm/microdev.h>
  18. #include <asm/io.h>
  19. #include <asm/machvec.h>
  20. extern void microdev_heartbeat(void);
  21. /*
  22. * The Machine Vector
  23. */
  24. struct sh_machine_vector mv_sh4202_microdev __initmv = {
  25. .mv_nr_irqs = 72, /* QQQ need to check this - use the MACRO */
  26. .mv_inb = microdev_inb,
  27. .mv_inw = microdev_inw,
  28. .mv_inl = microdev_inl,
  29. .mv_outb = microdev_outb,
  30. .mv_outw = microdev_outw,
  31. .mv_outl = microdev_outl,
  32. .mv_inb_p = microdev_inb_p,
  33. .mv_inw_p = microdev_inw_p,
  34. .mv_inl_p = microdev_inl_p,
  35. .mv_outb_p = microdev_outb_p,
  36. .mv_outw_p = microdev_outw_p,
  37. .mv_outl_p = microdev_outl_p,
  38. .mv_insb = microdev_insb,
  39. .mv_insw = microdev_insw,
  40. .mv_insl = microdev_insl,
  41. .mv_outsb = microdev_outsb,
  42. .mv_outsw = microdev_outsw,
  43. .mv_outsl = microdev_outsl,
  44. .mv_init_irq = init_microdev_irq,
  45. #ifdef CONFIG_HEARTBEAT
  46. .mv_heartbeat = microdev_heartbeat,
  47. #endif
  48. };
  49. ALIAS_MV(sh4202_microdev)
  50. /****************************************************************************/
  51. /*
  52. * Setup for the SMSC FDC37C93xAPM
  53. */
  54. #define SMSC_CONFIG_PORT_ADDR (0x3F0)
  55. #define SMSC_INDEX_PORT_ADDR SMSC_CONFIG_PORT_ADDR
  56. #define SMSC_DATA_PORT_ADDR (SMSC_INDEX_PORT_ADDR + 1)
  57. #define SMSC_ENTER_CONFIG_KEY 0x55
  58. #define SMSC_EXIT_CONFIG_KEY 0xaa
  59. #define SMCS_LOGICAL_DEV_INDEX 0x07 /* Logical Device Number */
  60. #define SMSC_DEVICE_ID_INDEX 0x20 /* Device ID */
  61. #define SMSC_DEVICE_REV_INDEX 0x21 /* Device Revision */
  62. #define SMSC_ACTIVATE_INDEX 0x30 /* Activate */
  63. #define SMSC_PRIMARY_BASE_INDEX 0x60 /* Primary Base Address */
  64. #define SMSC_SECONDARY_BASE_INDEX 0x62 /* Secondary Base Address */
  65. #define SMSC_PRIMARY_INT_INDEX 0x70 /* Primary Interrupt Select */
  66. #define SMSC_SECONDARY_INT_INDEX 0x72 /* Secondary Interrupt Select */
  67. #define SMSC_HDCS0_INDEX 0xf0 /* HDCS0 Address Decoder */
  68. #define SMSC_HDCS1_INDEX 0xf1 /* HDCS1 Address Decoder */
  69. #define SMSC_IDE1_DEVICE 1 /* IDE #1 logical device */
  70. #define SMSC_IDE2_DEVICE 2 /* IDE #2 logical device */
  71. #define SMSC_PARALLEL_DEVICE 3 /* Parallel Port logical device */
  72. #define SMSC_SERIAL1_DEVICE 4 /* Serial #1 logical device */
  73. #define SMSC_SERIAL2_DEVICE 5 /* Serial #2 logical device */
  74. #define SMSC_KEYBOARD_DEVICE 7 /* Keyboard logical device */
  75. #define SMSC_CONFIG_REGISTERS 8 /* Configuration Registers (Aux I/O) */
  76. #define SMSC_READ_INDEXED(index) ({ \
  77. outb((index), SMSC_INDEX_PORT_ADDR); \
  78. inb(SMSC_DATA_PORT_ADDR); })
  79. #define SMSC_WRITE_INDEXED(val, index) ({ \
  80. outb((index), SMSC_INDEX_PORT_ADDR); \
  81. outb((val), SMSC_DATA_PORT_ADDR); })
  82. #define IDE1_PRIMARY_BASE 0x01f0 /* Task File Registe base for IDE #1 */
  83. #define IDE1_SECONDARY_BASE 0x03f6 /* Miscellaneous AT registers for IDE #1 */
  84. #define IDE2_PRIMARY_BASE 0x0170 /* Task File Registe base for IDE #2 */
  85. #define IDE2_SECONDARY_BASE 0x0376 /* Miscellaneous AT registers for IDE #2 */
  86. #define SERIAL1_PRIMARY_BASE 0x03f8
  87. #define SERIAL2_PRIMARY_BASE 0x02f8
  88. #define MSB(x) ( (x) >> 8 )
  89. #define LSB(x) ( (x) & 0xff )
  90. /* General-Purpose base address on CPU-board FPGA */
  91. #define MICRODEV_FPGA_GP_BASE 0xa6100000ul
  92. /* assume a Keyboard Controller is present */
  93. int microdev_kbd_controller_present = 1;
  94. const char *get_system_type(void)
  95. {
  96. return "SH4-202 MicroDev";
  97. }
  98. static struct resource smc91x_resources[] = {
  99. [0] = {
  100. .start = 0x300,
  101. .end = 0x300 + 0x0001000 - 1,
  102. .flags = IORESOURCE_MEM,
  103. },
  104. [1] = {
  105. .start = MICRODEV_LINUX_IRQ_ETHERNET,
  106. .end = MICRODEV_LINUX_IRQ_ETHERNET,
  107. .flags = IORESOURCE_IRQ,
  108. },
  109. };
  110. static struct platform_device smc91x_device = {
  111. .name = "smc91x",
  112. .id = -1,
  113. .num_resources = ARRAY_SIZE(smc91x_resources),
  114. .resource = smc91x_resources,
  115. };
  116. #ifdef CONFIG_FB_S1D13XXX
  117. static struct s1d13xxxfb_regval s1d13806_initregs[] = {
  118. { S1DREG_MISC, 0x00 },
  119. { S1DREG_COM_DISP_MODE, 0x00 },
  120. { S1DREG_GPIO_CNF0, 0x00 },
  121. { S1DREG_GPIO_CNF1, 0x00 },
  122. { S1DREG_GPIO_CTL0, 0x00 },
  123. { S1DREG_GPIO_CTL1, 0x00 },
  124. { S1DREG_CLK_CNF, 0x02 },
  125. { S1DREG_LCD_CLK_CNF, 0x01 },
  126. { S1DREG_CRT_CLK_CNF, 0x03 },
  127. { S1DREG_MPLUG_CLK_CNF, 0x03 },
  128. { S1DREG_CPU2MEM_WST_SEL, 0x02 },
  129. { S1DREG_SDRAM_REF_RATE, 0x03 },
  130. { S1DREG_SDRAM_TC0, 0x00 },
  131. { S1DREG_SDRAM_TC1, 0x01 },
  132. { S1DREG_MEM_CNF, 0x80 },
  133. { S1DREG_PANEL_TYPE, 0x25 },
  134. { S1DREG_MOD_RATE, 0x00 },
  135. { S1DREG_LCD_DISP_HWIDTH, 0x63 },
  136. { S1DREG_LCD_NDISP_HPER, 0x1e },
  137. { S1DREG_TFT_FPLINE_START, 0x06 },
  138. { S1DREG_TFT_FPLINE_PWIDTH, 0x03 },
  139. { S1DREG_LCD_DISP_VHEIGHT0, 0x57 },
  140. { S1DREG_LCD_DISP_VHEIGHT1, 0x02 },
  141. { S1DREG_LCD_NDISP_VPER, 0x00 },
  142. { S1DREG_TFT_FPFRAME_START, 0x0a },
  143. { S1DREG_TFT_FPFRAME_PWIDTH, 0x81 },
  144. { S1DREG_LCD_DISP_MODE, 0x03 },
  145. { S1DREG_LCD_MISC, 0x00 },
  146. { S1DREG_LCD_DISP_START0, 0x00 },
  147. { S1DREG_LCD_DISP_START1, 0x00 },
  148. { S1DREG_LCD_DISP_START2, 0x00 },
  149. { S1DREG_LCD_MEM_OFF0, 0x90 },
  150. { S1DREG_LCD_MEM_OFF1, 0x01 },
  151. { S1DREG_LCD_PIX_PAN, 0x00 },
  152. { S1DREG_LCD_DISP_FIFO_HTC, 0x00 },
  153. { S1DREG_LCD_DISP_FIFO_LTC, 0x00 },
  154. { S1DREG_CRT_DISP_HWIDTH, 0x63 },
  155. { S1DREG_CRT_NDISP_HPER, 0x1f },
  156. { S1DREG_CRT_HRTC_START, 0x04 },
  157. { S1DREG_CRT_HRTC_PWIDTH, 0x8f },
  158. { S1DREG_CRT_DISP_VHEIGHT0, 0x57 },
  159. { S1DREG_CRT_DISP_VHEIGHT1, 0x02 },
  160. { S1DREG_CRT_NDISP_VPER, 0x1b },
  161. { S1DREG_CRT_VRTC_START, 0x00 },
  162. { S1DREG_CRT_VRTC_PWIDTH, 0x83 },
  163. { S1DREG_TV_OUT_CTL, 0x10 },
  164. { S1DREG_CRT_DISP_MODE, 0x05 },
  165. { S1DREG_CRT_DISP_START0, 0x00 },
  166. { S1DREG_CRT_DISP_START1, 0x00 },
  167. { S1DREG_CRT_DISP_START2, 0x00 },
  168. { S1DREG_CRT_MEM_OFF0, 0x20 },
  169. { S1DREG_CRT_MEM_OFF1, 0x03 },
  170. { S1DREG_CRT_PIX_PAN, 0x00 },
  171. { S1DREG_CRT_DISP_FIFO_HTC, 0x00 },
  172. { S1DREG_CRT_DISP_FIFO_LTC, 0x00 },
  173. { S1DREG_LCD_CUR_CTL, 0x00 },
  174. { S1DREG_LCD_CUR_START, 0x01 },
  175. { S1DREG_LCD_CUR_XPOS0, 0x00 },
  176. { S1DREG_LCD_CUR_XPOS1, 0x00 },
  177. { S1DREG_LCD_CUR_YPOS0, 0x00 },
  178. { S1DREG_LCD_CUR_YPOS1, 0x00 },
  179. { S1DREG_LCD_CUR_BCTL0, 0x00 },
  180. { S1DREG_LCD_CUR_GCTL0, 0x00 },
  181. { S1DREG_LCD_CUR_RCTL0, 0x00 },
  182. { S1DREG_LCD_CUR_BCTL1, 0x1f },
  183. { S1DREG_LCD_CUR_GCTL1, 0x3f },
  184. { S1DREG_LCD_CUR_RCTL1, 0x1f },
  185. { S1DREG_LCD_CUR_FIFO_HTC, 0x00 },
  186. { S1DREG_CRT_CUR_CTL, 0x00 },
  187. { S1DREG_CRT_CUR_START, 0x01 },
  188. { S1DREG_CRT_CUR_XPOS0, 0x00 },
  189. { S1DREG_CRT_CUR_XPOS1, 0x00 },
  190. { S1DREG_CRT_CUR_YPOS0, 0x00 },
  191. { S1DREG_CRT_CUR_YPOS1, 0x00 },
  192. { S1DREG_CRT_CUR_BCTL0, 0x00 },
  193. { S1DREG_CRT_CUR_GCTL0, 0x00 },
  194. { S1DREG_CRT_CUR_RCTL0, 0x00 },
  195. { S1DREG_CRT_CUR_BCTL1, 0x1f },
  196. { S1DREG_CRT_CUR_GCTL1, 0x3f },
  197. { S1DREG_CRT_CUR_RCTL1, 0x1f },
  198. { S1DREG_CRT_CUR_FIFO_HTC, 0x00 },
  199. { S1DREG_BBLT_CTL0, 0x00 },
  200. { S1DREG_BBLT_CTL1, 0x00 },
  201. { S1DREG_BBLT_CC_EXP, 0x00 },
  202. { S1DREG_BBLT_OP, 0x00 },
  203. { S1DREG_BBLT_SRC_START0, 0x00 },
  204. { S1DREG_BBLT_SRC_START1, 0x00 },
  205. { S1DREG_BBLT_SRC_START2, 0x00 },
  206. { S1DREG_BBLT_DST_START0, 0x00 },
  207. { S1DREG_BBLT_DST_START1, 0x00 },
  208. { S1DREG_BBLT_DST_START2, 0x00 },
  209. { S1DREG_BBLT_MEM_OFF0, 0x00 },
  210. { S1DREG_BBLT_MEM_OFF1, 0x00 },
  211. { S1DREG_BBLT_WIDTH0, 0x00 },
  212. { S1DREG_BBLT_WIDTH1, 0x00 },
  213. { S1DREG_BBLT_HEIGHT0, 0x00 },
  214. { S1DREG_BBLT_HEIGHT1, 0x00 },
  215. { S1DREG_BBLT_BGC0, 0x00 },
  216. { S1DREG_BBLT_BGC1, 0x00 },
  217. { S1DREG_BBLT_FGC0, 0x00 },
  218. { S1DREG_BBLT_FGC1, 0x00 },
  219. { S1DREG_LKUP_MODE, 0x00 },
  220. { S1DREG_LKUP_ADDR, 0x00 },
  221. { S1DREG_PS_CNF, 0x10 },
  222. { S1DREG_PS_STATUS, 0x00 },
  223. { S1DREG_CPU2MEM_WDOGT, 0x00 },
  224. { S1DREG_COM_DISP_MODE, 0x02 },
  225. };
  226. static struct s1d13xxxfb_pdata s1d13806_platform_data = {
  227. .initregs = s1d13806_initregs,
  228. .initregssize = ARRAY_SIZE(s1d13806_initregs),
  229. };
  230. static struct resource s1d13806_resources[] = {
  231. [0] = {
  232. .start = 0x07200000,
  233. .end = 0x07200000 + 0x00200000 - 1,
  234. .flags = IORESOURCE_MEM,
  235. },
  236. [1] = {
  237. .start = 0x07000000,
  238. .end = 0x07000000 + 0x00200000 - 1,
  239. .flags = IORESOURCE_MEM,
  240. },
  241. };
  242. static struct platform_device s1d13806_device = {
  243. .name = "s1d13806fb",
  244. .id = -1,
  245. .num_resources = ARRAY_SIZE(s1d13806_resources),
  246. .resource = s1d13806_resources,
  247. .dev = {
  248. .platform_data = &s1d13806_platform_data,
  249. },
  250. };
  251. #endif
  252. static struct platform_device *microdev_devices[] __initdata = {
  253. &smc91x_device,
  254. #ifdef CONFIG_FB_S1D13XXX
  255. &s1d13806_device,
  256. #endif
  257. };
  258. static int __init microdev_devices_setup(void)
  259. {
  260. return platform_add_devices(microdev_devices, ARRAY_SIZE(microdev_devices));
  261. }
  262. __initcall(microdev_devices_setup);
  263. void __init platform_setup(void)
  264. {
  265. int * const fpgaRevisionRegister = (int*)(MICRODEV_FPGA_GP_BASE + 0x8ul);
  266. const int fpgaRevision = *fpgaRevisionRegister;
  267. int * const CacheControlRegister = (int*)CCR;
  268. printk("SuperH %s board (FPGA rev: 0x%0x, CCR: 0x%0x)\n",
  269. get_system_type(), fpgaRevision, *CacheControlRegister);
  270. }
  271. /****************************************************************************/
  272. /*
  273. * Setup for the SMSC FDC37C93xAPM
  274. */
  275. static int __init smsc_superio_setup(void)
  276. {
  277. unsigned char devid, devrev;
  278. /* Initially the chip is in run state */
  279. /* Put it into configuration state */
  280. outb(SMSC_ENTER_CONFIG_KEY, SMSC_CONFIG_PORT_ADDR);
  281. /* Read device ID info */
  282. devid = SMSC_READ_INDEXED(SMSC_DEVICE_ID_INDEX);
  283. devrev = SMSC_READ_INDEXED(SMSC_DEVICE_REV_INDEX);
  284. if ( (devid==0x30) && (devrev==0x01) )
  285. {
  286. printk("SMSC FDC37C93xAPM SuperIO device detected\n");
  287. }
  288. else
  289. { /* not the device identity we expected */
  290. printk("Not detected a SMSC FDC37C93xAPM SuperIO device (devid=0x%02x, rev=0x%02x)\n",
  291. devid, devrev);
  292. /* inform the keyboard driver that we have no keyboard controller */
  293. microdev_kbd_controller_present = 0;
  294. /* little point in doing anything else in this functon */
  295. return 0;
  296. }
  297. /* Select the keyboard device */
  298. SMSC_WRITE_INDEXED(SMSC_KEYBOARD_DEVICE, SMCS_LOGICAL_DEV_INDEX);
  299. /* enable it */
  300. SMSC_WRITE_INDEXED(1, SMSC_ACTIVATE_INDEX);
  301. /* enable the interrupts */
  302. SMSC_WRITE_INDEXED(MICRODEV_FPGA_IRQ_KEYBOARD, SMSC_PRIMARY_INT_INDEX);
  303. SMSC_WRITE_INDEXED(MICRODEV_FPGA_IRQ_MOUSE, SMSC_SECONDARY_INT_INDEX);
  304. /* Select the Serial #1 device */
  305. SMSC_WRITE_INDEXED(SMSC_SERIAL1_DEVICE, SMCS_LOGICAL_DEV_INDEX);
  306. /* enable it */
  307. SMSC_WRITE_INDEXED(1, SMSC_ACTIVATE_INDEX);
  308. /* program with port addresses */
  309. SMSC_WRITE_INDEXED(MSB(SERIAL1_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+0);
  310. SMSC_WRITE_INDEXED(LSB(SERIAL1_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+1);
  311. SMSC_WRITE_INDEXED(0x00, SMSC_HDCS0_INDEX);
  312. /* enable the interrupts */
  313. SMSC_WRITE_INDEXED(MICRODEV_FPGA_IRQ_SERIAL1, SMSC_PRIMARY_INT_INDEX);
  314. /* Select the Serial #2 device */
  315. SMSC_WRITE_INDEXED(SMSC_SERIAL2_DEVICE, SMCS_LOGICAL_DEV_INDEX);
  316. /* enable it */
  317. SMSC_WRITE_INDEXED(1, SMSC_ACTIVATE_INDEX);
  318. /* program with port addresses */
  319. SMSC_WRITE_INDEXED(MSB(SERIAL2_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+0);
  320. SMSC_WRITE_INDEXED(LSB(SERIAL2_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+1);
  321. SMSC_WRITE_INDEXED(0x00, SMSC_HDCS0_INDEX);
  322. /* enable the interrupts */
  323. SMSC_WRITE_INDEXED(MICRODEV_FPGA_IRQ_SERIAL2, SMSC_PRIMARY_INT_INDEX);
  324. /* Select the IDE#1 device */
  325. SMSC_WRITE_INDEXED(SMSC_IDE1_DEVICE, SMCS_LOGICAL_DEV_INDEX);
  326. /* enable it */
  327. SMSC_WRITE_INDEXED(1, SMSC_ACTIVATE_INDEX);
  328. /* program with port addresses */
  329. SMSC_WRITE_INDEXED(MSB(IDE1_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+0);
  330. SMSC_WRITE_INDEXED(LSB(IDE1_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+1);
  331. SMSC_WRITE_INDEXED(MSB(IDE1_SECONDARY_BASE), SMSC_SECONDARY_BASE_INDEX+0);
  332. SMSC_WRITE_INDEXED(LSB(IDE1_SECONDARY_BASE), SMSC_SECONDARY_BASE_INDEX+1);
  333. SMSC_WRITE_INDEXED(0x0c, SMSC_HDCS0_INDEX);
  334. SMSC_WRITE_INDEXED(0x00, SMSC_HDCS1_INDEX);
  335. /* select the interrupt */
  336. SMSC_WRITE_INDEXED(MICRODEV_FPGA_IRQ_IDE1, SMSC_PRIMARY_INT_INDEX);
  337. /* Select the IDE#2 device */
  338. SMSC_WRITE_INDEXED(SMSC_IDE2_DEVICE, SMCS_LOGICAL_DEV_INDEX);
  339. /* enable it */
  340. SMSC_WRITE_INDEXED(1, SMSC_ACTIVATE_INDEX);
  341. /* program with port addresses */
  342. SMSC_WRITE_INDEXED(MSB(IDE2_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+0);
  343. SMSC_WRITE_INDEXED(LSB(IDE2_PRIMARY_BASE), SMSC_PRIMARY_BASE_INDEX+1);
  344. SMSC_WRITE_INDEXED(MSB(IDE2_SECONDARY_BASE), SMSC_SECONDARY_BASE_INDEX+0);
  345. SMSC_WRITE_INDEXED(LSB(IDE2_SECONDARY_BASE), SMSC_SECONDARY_BASE_INDEX+1);
  346. /* select the interrupt */
  347. SMSC_WRITE_INDEXED(MICRODEV_FPGA_IRQ_IDE2, SMSC_PRIMARY_INT_INDEX);
  348. /* Select the configuration registers */
  349. SMSC_WRITE_INDEXED(SMSC_CONFIG_REGISTERS, SMCS_LOGICAL_DEV_INDEX);
  350. /* enable the appropriate GPIO pins for IDE functionality:
  351. * bit[0] In/Out 1==input; 0==output
  352. * bit[1] Polarity 1==invert; 0==no invert
  353. * bit[2] Int Enb #1 1==Enable Combined IRQ #1; 0==disable
  354. * bit[3:4] Function Select 00==original; 01==Alternate Function #1
  355. */
  356. SMSC_WRITE_INDEXED(0x00, 0xc2); /* GP42 = nIDE1_OE */
  357. SMSC_WRITE_INDEXED(0x01, 0xc5); /* GP45 = IDE1_IRQ */
  358. SMSC_WRITE_INDEXED(0x00, 0xc6); /* GP46 = nIOROP */
  359. SMSC_WRITE_INDEXED(0x00, 0xc7); /* GP47 = nIOWOP */
  360. SMSC_WRITE_INDEXED(0x08, 0xe8); /* GP20 = nIDE2_OE */
  361. /* Exit the configuraton state */
  362. outb(SMSC_EXIT_CONFIG_KEY, SMSC_CONFIG_PORT_ADDR);
  363. return 0;
  364. }
  365. /* This is grotty, but, because kernel is always referenced on the link line
  366. * before any devices, this is safe.
  367. */
  368. __initcall(smsc_superio_setup);