board-magicpanelr2.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/sh/boards/magicpanel/setup.c
  4. *
  5. * Copyright (C) 2007 Markus Brunner, Mark Jonas
  6. *
  7. * Magic Panel Release 2 board setup
  8. */
  9. #include <linux/init.h>
  10. #include <linux/irq.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/delay.h>
  13. #include <linux/gpio.h>
  14. #include <linux/regulator/fixed.h>
  15. #include <linux/regulator/machine.h>
  16. #include <linux/smsc911x.h>
  17. #include <linux/mtd/mtd.h>
  18. #include <linux/mtd/partitions.h>
  19. #include <linux/mtd/physmap.h>
  20. #include <linux/mtd/map.h>
  21. #include <linux/sh_intc.h>
  22. #include <mach/magicpanelr2.h>
  23. #include <asm/heartbeat.h>
  24. #include <cpu/sh7720.h>
  25. /* Dummy supplies, where voltage doesn't matter */
  26. static struct regulator_consumer_supply dummy_supplies[] = {
  27. REGULATOR_SUPPLY("vddvario", "smsc911x"),
  28. REGULATOR_SUPPLY("vdd33a", "smsc911x"),
  29. };
  30. #define LAN9115_READY (__raw_readl(0xA8000084UL) & 0x00000001UL)
  31. /* Wait until reset finished. Timeout is 100ms. */
  32. static int __init ethernet_reset_finished(void)
  33. {
  34. int i;
  35. if (LAN9115_READY)
  36. return 1;
  37. for (i = 0; i < 10; ++i) {
  38. mdelay(10);
  39. if (LAN9115_READY)
  40. return 1;
  41. }
  42. return 0;
  43. }
  44. static void __init reset_ethernet(void)
  45. {
  46. /* PMDR: LAN_RESET=on */
  47. CLRBITS_OUTB(0x10, PORT_PMDR);
  48. udelay(200);
  49. /* PMDR: LAN_RESET=off */
  50. SETBITS_OUTB(0x10, PORT_PMDR);
  51. }
  52. static void __init setup_chip_select(void)
  53. {
  54. /* CS2: LAN (0x08000000 - 0x0bffffff) */
  55. /* no idle cycles, normal space, 8 bit data bus */
  56. __raw_writel(0x36db0400, CS2BCR);
  57. /* (SW:1.5 WR:3 HW:1.5), ext. wait */
  58. __raw_writel(0x000003c0, CS2WCR);
  59. /* CS4: CAN1 (0xb0000000 - 0xb3ffffff) */
  60. /* no idle cycles, normal space, 8 bit data bus */
  61. __raw_writel(0x00000200, CS4BCR);
  62. /* (SW:1.5 WR:3 HW:1.5), ext. wait */
  63. __raw_writel(0x00100981, CS4WCR);
  64. /* CS5a: CAN2 (0xb4000000 - 0xb5ffffff) */
  65. /* no idle cycles, normal space, 8 bit data bus */
  66. __raw_writel(0x00000200, CS5ABCR);
  67. /* (SW:1.5 WR:3 HW:1.5), ext. wait */
  68. __raw_writel(0x00100981, CS5AWCR);
  69. /* CS5b: CAN3 (0xb6000000 - 0xb7ffffff) */
  70. /* no idle cycles, normal space, 8 bit data bus */
  71. __raw_writel(0x00000200, CS5BBCR);
  72. /* (SW:1.5 WR:3 HW:1.5), ext. wait */
  73. __raw_writel(0x00100981, CS5BWCR);
  74. /* CS6a: Rotary (0xb8000000 - 0xb9ffffff) */
  75. /* no idle cycles, normal space, 8 bit data bus */
  76. __raw_writel(0x00000200, CS6ABCR);
  77. /* (SW:1.5 WR:3 HW:1.5), no ext. wait */
  78. __raw_writel(0x001009C1, CS6AWCR);
  79. }
  80. static void __init setup_port_multiplexing(void)
  81. {
  82. /* A7 GPO(LED8); A6 GPO(LED7); A5 GPO(LED6); A4 GPO(LED5);
  83. * A3 GPO(LED4); A2 GPO(LED3); A1 GPO(LED2); A0 GPO(LED1);
  84. */
  85. __raw_writew(0x5555, PORT_PACR); /* 01 01 01 01 01 01 01 01 */
  86. /* B7 GPO(RST4); B6 GPO(RST3); B5 GPO(RST2); B4 GPO(RST1);
  87. * B3 GPO(PB3); B2 GPO(PB2); B1 GPO(PB1); B0 GPO(PB0);
  88. */
  89. __raw_writew(0x5555, PORT_PBCR); /* 01 01 01 01 01 01 01 01 */
  90. /* C7 GPO(PC7); C6 GPO(PC6); C5 GPO(PC5); C4 GPO(PC4);
  91. * C3 LCD_DATA3; C2 LCD_DATA2; C1 LCD_DATA1; C0 LCD_DATA0;
  92. */
  93. __raw_writew(0x5500, PORT_PCCR); /* 01 01 01 01 00 00 00 00 */
  94. /* D7 GPO(PD7); D6 GPO(PD6); D5 GPO(PD5); D4 GPO(PD4);
  95. * D3 GPO(PD3); D2 GPO(PD2); D1 GPO(PD1); D0 GPO(PD0);
  96. */
  97. __raw_writew(0x5555, PORT_PDCR); /* 01 01 01 01 01 01 01 01 */
  98. /* E7 (x); E6 GPI(nu); E5 GPI(nu); E4 LCD_M_DISP;
  99. * E3 LCD_CL1; E2 LCD_CL2; E1 LCD_DON; E0 LCD_FLM;
  100. */
  101. __raw_writew(0x3C00, PORT_PECR); /* 00 11 11 00 00 00 00 00 */
  102. /* F7 (x); F6 DA1(VLCD); F5 DA0(nc); F4 AN3;
  103. * F3 AN2(MID_AD); F2 AN1(EARTH_AD); F1 AN0(TEMP); F0 GPI+(nc);
  104. */
  105. __raw_writew(0x0002, PORT_PFCR); /* 00 00 00 00 00 00 00 10 */
  106. /* G7 (x); G6 IRQ5(TOUCH_BUSY); G5 IRQ4(TOUCH_IRQ); G4 GPI(KEY2);
  107. * G3 GPI(KEY1); G2 GPO(LED11); G1 GPO(LED10); G0 GPO(LED9);
  108. */
  109. __raw_writew(0x03D5, PORT_PGCR); /* 00 00 00 11 11 01 01 01 */
  110. /* H7 (x); H6 /RAS(BRAS); H5 /CAS(BCAS); H4 CKE(BCKE);
  111. * H3 GPO(EARTH_OFF); H2 GPO(EARTH_TEST); H1 USB2_PWR; H0 USB1_PWR;
  112. */
  113. __raw_writew(0x0050, PORT_PHCR); /* 00 00 00 00 01 01 00 00 */
  114. /* J7 (x); J6 AUDCK; J5 ASEBRKAK; J4 AUDATA3;
  115. * J3 AUDATA2; J2 AUDATA1; J1 AUDATA0; J0 AUDSYNC;
  116. */
  117. __raw_writew(0x0000, PORT_PJCR); /* 00 00 00 00 00 00 00 00 */
  118. /* K7 (x); K6 (x); K5 (x); K4 (x);
  119. * K3 PINT7(/PWR2); K2 PINT6(/PWR1); K1 PINT5(nu); K0 PINT4(FLASH_READY)
  120. */
  121. __raw_writew(0x00FF, PORT_PKCR); /* 00 00 00 00 11 11 11 11 */
  122. /* L7 TRST; L6 TMS; L5 TDO; L4 TDI;
  123. * L3 TCK; L2 (x); L1 (x); L0 (x);
  124. */
  125. __raw_writew(0x0000, PORT_PLCR); /* 00 00 00 00 00 00 00 00 */
  126. /* M7 GPO(CURRENT_SINK); M6 GPO(PWR_SWITCH); M5 GPO(LAN_SPEED);
  127. * M4 GPO(LAN_RESET); M3 GPO(BUZZER); M2 GPO(LCD_BL);
  128. * M1 CS5B(CAN3_CS); M0 GPI+(nc);
  129. */
  130. __raw_writew(0x5552, PORT_PMCR); /* 01 01 01 01 01 01 00 10 */
  131. /* CURRENT_SINK=off, PWR_SWITCH=off, LAN_SPEED=100MBit,
  132. * LAN_RESET=off, BUZZER=off, LCD_BL=off
  133. */
  134. #if CONFIG_SH_MAGIC_PANEL_R2_VERSION == 2
  135. __raw_writeb(0x30, PORT_PMDR);
  136. #elif CONFIG_SH_MAGIC_PANEL_R2_VERSION == 3
  137. __raw_writeb(0xF0, PORT_PMDR);
  138. #else
  139. #error Unknown revision of PLATFORM_MP_R2
  140. #endif
  141. /* P7 (x); P6 (x); P5 (x);
  142. * P4 GPO(nu); P3 IRQ3(LAN_IRQ); P2 IRQ2(CAN3_IRQ);
  143. * P1 IRQ1(CAN2_IRQ); P0 IRQ0(CAN1_IRQ)
  144. */
  145. __raw_writew(0x0100, PORT_PPCR); /* 00 00 00 01 00 00 00 00 */
  146. __raw_writeb(0x10, PORT_PPDR);
  147. /* R7 A25; R6 A24; R5 A23; R4 A22;
  148. * R3 A21; R2 A20; R1 A19; R0 A0;
  149. */
  150. gpio_request(GPIO_FN_A25, NULL);
  151. gpio_request(GPIO_FN_A24, NULL);
  152. gpio_request(GPIO_FN_A23, NULL);
  153. gpio_request(GPIO_FN_A22, NULL);
  154. gpio_request(GPIO_FN_A21, NULL);
  155. gpio_request(GPIO_FN_A20, NULL);
  156. gpio_request(GPIO_FN_A19, NULL);
  157. gpio_request(GPIO_FN_A0, NULL);
  158. /* S7 (x); S6 (x); S5 (x); S4 GPO(EEPROM_CS2);
  159. * S3 GPO(EEPROM_CS1); S2 SIOF0_TXD; S1 SIOF0_RXD; S0 SIOF0_SCK;
  160. */
  161. __raw_writew(0x0140, PORT_PSCR); /* 00 00 00 01 01 00 00 00 */
  162. /* T7 (x); T6 (x); T5 (x); T4 COM1_CTS;
  163. * T3 COM1_RTS; T2 COM1_TXD; T1 COM1_RXD; T0 GPO(WDOG)
  164. */
  165. __raw_writew(0x0001, PORT_PTCR); /* 00 00 00 00 00 00 00 01 */
  166. /* U7 (x); U6 (x); U5 (x); U4 GPI+(/AC_FAULT);
  167. * U3 GPO(TOUCH_CS); U2 TOUCH_TXD; U1 TOUCH_RXD; U0 TOUCH_SCK;
  168. */
  169. __raw_writew(0x0240, PORT_PUCR); /* 00 00 00 10 01 00 00 00 */
  170. /* V7 (x); V6 (x); V5 (x); V4 GPO(MID2);
  171. * V3 GPO(MID1); V2 CARD_TxD; V1 CARD_RxD; V0 GPI+(/BAT_FAULT);
  172. */
  173. __raw_writew(0x0142, PORT_PVCR); /* 00 00 00 01 01 00 00 10 */
  174. }
  175. static void __init mpr2_setup(char **cmdline_p)
  176. {
  177. /* set Pin Select Register A:
  178. * /PCC_CD1, /PCC_CD2, PCC_BVD1, PCC_BVD2,
  179. * /IOIS16, IRQ4, IRQ5, USB1d_SUSPEND
  180. */
  181. __raw_writew(0xAABC, PORT_PSELA);
  182. /* set Pin Select Register B:
  183. * /SCIF0_RTS, /SCIF0_CTS, LCD_VCPWC,
  184. * LCD_VEPWC, IIC_SDA, IIC_SCL, Reserved
  185. */
  186. __raw_writew(0x3C00, PORT_PSELB);
  187. /* set Pin Select Register C:
  188. * SIOF1_SCK, SIOF1_RxD, SCIF1_RxD, SCIF1_TxD, Reserved
  189. */
  190. __raw_writew(0x0000, PORT_PSELC);
  191. /* set Pin Select Register D: Reserved, SIOF1_TxD, Reserved, SIOF1_MCLK,
  192. * Reserved, SIOF1_SYNC, Reserved, SCIF1_SCK, Reserved
  193. */
  194. __raw_writew(0x0000, PORT_PSELD);
  195. /* set USB TxRx Control: Reserved, DRV, Reserved, USB_TRANS, USB_SEL */
  196. __raw_writew(0x0101, PORT_UTRCTL);
  197. /* set USB Clock Control: USSCS, USSTB, Reserved (HighByte always A5) */
  198. __raw_writew(0xA5C0, PORT_UCLKCR_W);
  199. setup_chip_select();
  200. setup_port_multiplexing();
  201. reset_ethernet();
  202. printk(KERN_INFO "Magic Panel Release 2 A.%i\n",
  203. CONFIG_SH_MAGIC_PANEL_R2_VERSION);
  204. if (ethernet_reset_finished() == 0)
  205. printk(KERN_WARNING "Ethernet not ready\n");
  206. }
  207. static struct resource smsc911x_resources[] = {
  208. [0] = {
  209. .start = 0xa8000000,
  210. .end = 0xabffffff,
  211. .flags = IORESOURCE_MEM,
  212. },
  213. [1] = {
  214. .start = evt2irq(0x660),
  215. .end = evt2irq(0x660),
  216. .flags = IORESOURCE_IRQ,
  217. },
  218. };
  219. static struct smsc911x_platform_config smsc911x_config = {
  220. .phy_interface = PHY_INTERFACE_MODE_MII,
  221. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  222. .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
  223. .flags = SMSC911X_USE_32BIT,
  224. };
  225. static struct platform_device smsc911x_device = {
  226. .name = "smsc911x",
  227. .id = -1,
  228. .num_resources = ARRAY_SIZE(smsc911x_resources),
  229. .resource = smsc911x_resources,
  230. .dev = {
  231. .platform_data = &smsc911x_config,
  232. },
  233. };
  234. static struct resource heartbeat_resources[] = {
  235. [0] = {
  236. .start = PA_LED,
  237. .end = PA_LED,
  238. .flags = IORESOURCE_MEM,
  239. },
  240. };
  241. static struct heartbeat_data heartbeat_data = {
  242. .flags = HEARTBEAT_INVERTED,
  243. };
  244. static struct platform_device heartbeat_device = {
  245. .name = "heartbeat",
  246. .id = -1,
  247. .dev = {
  248. .platform_data = &heartbeat_data,
  249. },
  250. .num_resources = ARRAY_SIZE(heartbeat_resources),
  251. .resource = heartbeat_resources,
  252. };
  253. static struct mtd_partition mpr2_partitions[] = {
  254. /* Reserved for bootloader, read-only */
  255. {
  256. .name = "Bootloader",
  257. .offset = 0x00000000UL,
  258. .size = MPR2_MTD_BOOTLOADER_SIZE,
  259. .mask_flags = MTD_WRITEABLE,
  260. },
  261. /* Reserved for kernel image */
  262. {
  263. .name = "Kernel",
  264. .offset = MTDPART_OFS_NXTBLK,
  265. .size = MPR2_MTD_KERNEL_SIZE,
  266. },
  267. /* Rest is used for Flash FS */
  268. {
  269. .name = "Flash_FS",
  270. .offset = MTDPART_OFS_NXTBLK,
  271. .size = MTDPART_SIZ_FULL,
  272. }
  273. };
  274. static struct physmap_flash_data flash_data = {
  275. .parts = mpr2_partitions,
  276. .nr_parts = ARRAY_SIZE(mpr2_partitions),
  277. .width = 2,
  278. };
  279. static struct resource flash_resource = {
  280. .start = 0x00000000,
  281. .end = 0x2000000UL,
  282. .flags = IORESOURCE_MEM,
  283. };
  284. static struct platform_device flash_device = {
  285. .name = "physmap-flash",
  286. .id = -1,
  287. .resource = &flash_resource,
  288. .num_resources = 1,
  289. .dev = {
  290. .platform_data = &flash_data,
  291. },
  292. };
  293. /*
  294. * Add all resources to the platform_device
  295. */
  296. static struct platform_device *mpr2_devices[] __initdata = {
  297. &heartbeat_device,
  298. &smsc911x_device,
  299. &flash_device,
  300. };
  301. static int __init mpr2_devices_setup(void)
  302. {
  303. regulator_register_fixed(0, dummy_supplies, ARRAY_SIZE(dummy_supplies));
  304. return platform_add_devices(mpr2_devices, ARRAY_SIZE(mpr2_devices));
  305. }
  306. device_initcall(mpr2_devices_setup);
  307. /*
  308. * Initialize IRQ setting
  309. */
  310. static void __init init_mpr2_IRQ(void)
  311. {
  312. plat_irq_setup_pins(IRQ_MODE_IRQ); /* install handlers for IRQ0-5 */
  313. irq_set_irq_type(evt2irq(0x600), IRQ_TYPE_LEVEL_LOW); /* IRQ0 CAN1 */
  314. irq_set_irq_type(evt2irq(0x620), IRQ_TYPE_LEVEL_LOW); /* IRQ1 CAN2 */
  315. irq_set_irq_type(evt2irq(0x640), IRQ_TYPE_LEVEL_LOW); /* IRQ2 CAN3 */
  316. irq_set_irq_type(evt2irq(0x660), IRQ_TYPE_LEVEL_LOW); /* IRQ3 SMSC9115 */
  317. irq_set_irq_type(evt2irq(0x680), IRQ_TYPE_EDGE_RISING); /* IRQ4 touchscreen */
  318. irq_set_irq_type(evt2irq(0x6a0), IRQ_TYPE_EDGE_FALLING); /* IRQ5 touchscreen */
  319. intc_set_priority(evt2irq(0x600), 13); /* IRQ0 CAN1 */
  320. intc_set_priority(evt2irq(0x620), 13); /* IRQ0 CAN2 */
  321. intc_set_priority(evt2irq(0x640), 13); /* IRQ0 CAN3 */
  322. intc_set_priority(evt2irq(0x660), 6); /* IRQ3 SMSC9115 */
  323. }
  324. /*
  325. * The Machine Vector
  326. */
  327. static struct sh_machine_vector mv_mpr2 __initmv = {
  328. .mv_name = "mpr2",
  329. .mv_setup = mpr2_setup,
  330. .mv_init_irq = init_mpr2_IRQ,
  331. };