setup.c 13 KB

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