board-bonito.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. /*
  2. * bonito board support
  3. *
  4. * Copyright (C) 2011 Renesas Solutions Corp.
  5. * Copyright (C) 2011 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/i2c.h>
  23. #include <linux/init.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/irq.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/gpio.h>
  28. #include <linux/smsc911x.h>
  29. #include <mach/common.h>
  30. #include <asm/mach-types.h>
  31. #include <asm/mach/arch.h>
  32. #include <asm/mach/map.h>
  33. #include <asm/mach/time.h>
  34. #include <asm/hardware/cache-l2x0.h>
  35. #include <mach/r8a7740.h>
  36. #include <video/sh_mobile_lcdc.h>
  37. /*
  38. * CS Address device note
  39. *----------------------------------------------------------------
  40. * 0 0x0000_0000 NOR Flash (64MB) SW12 : bit3 = OFF
  41. * 2 0x0800_0000 ExtNOR (64MB) SW12 : bit3 = OFF
  42. * 4 -
  43. * 5A -
  44. * 5B 0x1600_0000 SRAM (8MB)
  45. * 6 0x1800_0000 FPGA (64K)
  46. * 0x1801_0000 Ether (4KB)
  47. * 0x1801_1000 USB (4KB)
  48. */
  49. /*
  50. * SW12
  51. *
  52. * bit1 bit2 bit3
  53. *----------------------------------------------------------------------------
  54. * ON NOR WriteProtect NAND WriteProtect CS0 ExtNOR / CS2 NOR
  55. * OFF NOR Not WriteProtect NAND Not WriteProtect CS0 NOR / CS2 ExtNOR
  56. */
  57. /*
  58. * SCIFA5 (CN42)
  59. *
  60. * S38.3 = ON
  61. * S39.6 = ON
  62. * S43.1 = ON
  63. */
  64. /*
  65. * LCDC0 (CN3/CN4/CN7)
  66. *
  67. * S38.1 = OFF
  68. * S38.2 = OFF
  69. */
  70. /*
  71. * FPGA
  72. */
  73. #define IRQSR0 0x0020
  74. #define IRQSR1 0x0022
  75. #define IRQMR0 0x0030
  76. #define IRQMR1 0x0032
  77. #define BUSSWMR1 0x0070
  78. #define BUSSWMR2 0x0072
  79. #define BUSSWMR3 0x0074
  80. #define BUSSWMR4 0x0076
  81. #define LCDCR 0x10B4
  82. #define DEVRSTCR1 0x10D0
  83. #define DEVRSTCR2 0x10D2
  84. #define A1MDSR 0x10E0
  85. #define BVERR 0x1100
  86. /* FPGA IRQ */
  87. #define FPGA_IRQ_BASE (512)
  88. #define FPGA_IRQ0 (FPGA_IRQ_BASE)
  89. #define FPGA_IRQ1 (FPGA_IRQ_BASE + 16)
  90. #define FPGA_ETH_IRQ (FPGA_IRQ0 + 15)
  91. static u16 bonito_fpga_read(u32 offset)
  92. {
  93. return __raw_readw(0xf0003000 + offset);
  94. }
  95. static void bonito_fpga_write(u32 offset, u16 val)
  96. {
  97. __raw_writew(val, 0xf0003000 + offset);
  98. }
  99. static void bonito_fpga_irq_disable(struct irq_data *data)
  100. {
  101. unsigned int irq = data->irq;
  102. u32 addr = (irq < 1016) ? IRQMR0 : IRQMR1;
  103. int shift = irq % 16;
  104. bonito_fpga_write(addr, bonito_fpga_read(addr) | (1 << shift));
  105. }
  106. static void bonito_fpga_irq_enable(struct irq_data *data)
  107. {
  108. unsigned int irq = data->irq;
  109. u32 addr = (irq < 1016) ? IRQMR0 : IRQMR1;
  110. int shift = irq % 16;
  111. bonito_fpga_write(addr, bonito_fpga_read(addr) & ~(1 << shift));
  112. }
  113. static struct irq_chip bonito_fpga_irq_chip __read_mostly = {
  114. .name = "bonito FPGA",
  115. .irq_mask = bonito_fpga_irq_disable,
  116. .irq_unmask = bonito_fpga_irq_enable,
  117. };
  118. static void bonito_fpga_irq_demux(unsigned int irq, struct irq_desc *desc)
  119. {
  120. u32 val = bonito_fpga_read(IRQSR1) << 16 |
  121. bonito_fpga_read(IRQSR0);
  122. u32 mask = bonito_fpga_read(IRQMR1) << 16 |
  123. bonito_fpga_read(IRQMR0);
  124. int i;
  125. val &= ~mask;
  126. for (i = 0; i < 32; i++) {
  127. if (!(val & (1 << i)))
  128. continue;
  129. generic_handle_irq(FPGA_IRQ_BASE + i);
  130. }
  131. }
  132. static void bonito_fpga_init(void)
  133. {
  134. int i;
  135. bonito_fpga_write(IRQMR0, 0xffff); /* mask all */
  136. bonito_fpga_write(IRQMR1, 0xffff); /* mask all */
  137. /* Device reset */
  138. bonito_fpga_write(DEVRSTCR1,
  139. (1 << 2)); /* Eth */
  140. /* FPGA irq require special handling */
  141. for (i = FPGA_IRQ_BASE; i < FPGA_IRQ_BASE + 32; i++) {
  142. irq_set_chip_and_handler_name(i, &bonito_fpga_irq_chip,
  143. handle_level_irq, "level");
  144. set_irq_flags(i, IRQF_VALID); /* yuck */
  145. }
  146. irq_set_chained_handler(evt2irq(0x0340), bonito_fpga_irq_demux);
  147. irq_set_irq_type(evt2irq(0x0340), IRQ_TYPE_LEVEL_LOW);
  148. }
  149. /*
  150. * PMIC settings
  151. *
  152. * FIXME
  153. *
  154. * bonito board needs some settings by pmic which use i2c access.
  155. * pmic settings use device_initcall() here for use it.
  156. */
  157. static __u8 *pmic_settings = NULL;
  158. static __u8 pmic_do_2A[] = {
  159. 0x1C, 0x09,
  160. 0x1A, 0x80,
  161. 0xff, 0xff,
  162. };
  163. static int __init pmic_init(void)
  164. {
  165. struct i2c_adapter *a = i2c_get_adapter(0);
  166. struct i2c_msg msg;
  167. __u8 buf[2];
  168. int i, ret;
  169. if (!pmic_settings)
  170. return 0;
  171. if (!a)
  172. return 0;
  173. msg.addr = 0x46;
  174. msg.buf = buf;
  175. msg.len = 2;
  176. msg.flags = 0;
  177. for (i = 0; ; i += 2) {
  178. buf[0] = pmic_settings[i + 0];
  179. buf[1] = pmic_settings[i + 1];
  180. if ((0xff == buf[0]) && (0xff == buf[1]))
  181. break;
  182. ret = i2c_transfer(a, &msg, 1);
  183. if (ret < 0) {
  184. pr_err("i2c transfer fail\n");
  185. break;
  186. }
  187. }
  188. return 0;
  189. }
  190. device_initcall(pmic_init);
  191. /*
  192. * LCDC0
  193. */
  194. static const struct fb_videomode lcdc0_mode = {
  195. .name = "WVGA Panel",
  196. .xres = 800,
  197. .yres = 480,
  198. .left_margin = 88,
  199. .right_margin = 40,
  200. .hsync_len = 128,
  201. .upper_margin = 20,
  202. .lower_margin = 5,
  203. .vsync_len = 5,
  204. .sync = 0,
  205. };
  206. static struct sh_mobile_lcdc_info lcdc0_info = {
  207. .clock_source = LCDC_CLK_BUS,
  208. .ch[0] = {
  209. .chan = LCDC_CHAN_MAINLCD,
  210. .bpp = 16,
  211. .interface_type = RGB24,
  212. .clock_divider = 5,
  213. .flags = 0,
  214. .lcd_cfg = &lcdc0_mode,
  215. .num_cfg = 1,
  216. .lcd_size_cfg = {
  217. .width = 152,
  218. .height = 91,
  219. },
  220. },
  221. };
  222. static struct resource lcdc0_resources[] = {
  223. [0] = {
  224. .name = "LCDC0",
  225. .start = 0xfe940000,
  226. .end = 0xfe943fff,
  227. .flags = IORESOURCE_MEM,
  228. },
  229. [1] = {
  230. .start = intcs_evt2irq(0x0580),
  231. .flags = IORESOURCE_IRQ,
  232. },
  233. };
  234. static struct platform_device lcdc0_device = {
  235. .name = "sh_mobile_lcdc_fb",
  236. .id = 0,
  237. .resource = lcdc0_resources,
  238. .num_resources = ARRAY_SIZE(lcdc0_resources),
  239. .dev = {
  240. .platform_data = &lcdc0_info,
  241. .coherent_dma_mask = ~0,
  242. },
  243. };
  244. /*
  245. * SMSC 9221
  246. */
  247. static struct resource smsc_resources[] = {
  248. [0] = {
  249. .start = 0x18010000,
  250. .end = 0x18011000 - 1,
  251. .flags = IORESOURCE_MEM,
  252. },
  253. [1] = {
  254. .start = FPGA_ETH_IRQ,
  255. .flags = IORESOURCE_IRQ,
  256. },
  257. };
  258. static struct smsc911x_platform_config smsc_platdata = {
  259. .flags = SMSC911X_USE_16BIT,
  260. .phy_interface = PHY_INTERFACE_MODE_MII,
  261. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  262. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  263. };
  264. static struct platform_device smsc_device = {
  265. .name = "smsc911x",
  266. .dev = {
  267. .platform_data = &smsc_platdata,
  268. },
  269. .resource = smsc_resources,
  270. .num_resources = ARRAY_SIZE(smsc_resources),
  271. };
  272. /*
  273. * core board devices
  274. */
  275. static struct platform_device *bonito_core_devices[] __initdata = {
  276. };
  277. /*
  278. * base board devices
  279. */
  280. static struct platform_device *bonito_base_devices[] __initdata = {
  281. &lcdc0_device,
  282. &smsc_device,
  283. };
  284. /*
  285. * map I/O
  286. */
  287. static struct map_desc bonito_io_desc[] __initdata = {
  288. /*
  289. * for CPGA/INTC/PFC
  290. * 0xe6000000-0xefffffff -> 0xe6000000-0xefffffff
  291. */
  292. {
  293. .virtual = 0xe6000000,
  294. .pfn = __phys_to_pfn(0xe6000000),
  295. .length = 160 << 20,
  296. .type = MT_DEVICE_NONSHARED
  297. },
  298. #ifdef CONFIG_CACHE_L2X0
  299. /*
  300. * for l2x0_init()
  301. * 0xf0100000-0xf0101000 -> 0xf0002000-0xf0003000
  302. */
  303. {
  304. .virtual = 0xf0002000,
  305. .pfn = __phys_to_pfn(0xf0100000),
  306. .length = PAGE_SIZE,
  307. .type = MT_DEVICE_NONSHARED
  308. },
  309. #endif
  310. /*
  311. * for FPGA (0x1800000-0x19ffffff)
  312. * 0x18000000-0x18002000 -> 0xf0003000-0xf0005000
  313. */
  314. {
  315. .virtual = 0xf0003000,
  316. .pfn = __phys_to_pfn(0x18000000),
  317. .length = PAGE_SIZE * 2,
  318. .type = MT_DEVICE_NONSHARED
  319. }
  320. };
  321. static void __init bonito_map_io(void)
  322. {
  323. iotable_init(bonito_io_desc, ARRAY_SIZE(bonito_io_desc));
  324. /* setup early devices and console here as well */
  325. r8a7740_add_early_devices();
  326. shmobile_setup_console();
  327. }
  328. /*
  329. * board init
  330. */
  331. #define BIT_ON(sw, bit) (sw & (1 << bit))
  332. #define BIT_OFF(sw, bit) (!(sw & (1 << bit)))
  333. #define VCCQ1CR 0xE6058140
  334. #define VCCQ1LCDCR 0xE6058186
  335. static void __init bonito_init(void)
  336. {
  337. u16 val;
  338. r8a7740_pinmux_init();
  339. bonito_fpga_init();
  340. pmic_settings = pmic_do_2A;
  341. /*
  342. * core board settings
  343. */
  344. #ifdef CONFIG_CACHE_L2X0
  345. /* Early BRESP enable, Shared attribute override enable, 32K*8way */
  346. l2x0_init(__io(0xf0002000), 0x40440000, 0x82000fff);
  347. #endif
  348. r8a7740_add_standard_devices();
  349. platform_add_devices(bonito_core_devices,
  350. ARRAY_SIZE(bonito_core_devices));
  351. /*
  352. * base board settings
  353. */
  354. gpio_request(GPIO_PORT176, NULL);
  355. gpio_direction_input(GPIO_PORT176);
  356. if (!gpio_get_value(GPIO_PORT176)) {
  357. u16 bsw2;
  358. u16 bsw3;
  359. u16 bsw4;
  360. /*
  361. * FPGA
  362. */
  363. gpio_request(GPIO_FN_CS5B, NULL);
  364. gpio_request(GPIO_FN_CS6A, NULL);
  365. gpio_request(GPIO_FN_CS5A_PORT105, NULL);
  366. gpio_request(GPIO_FN_IRQ10, NULL);
  367. val = bonito_fpga_read(BVERR);
  368. pr_info("bonito version: cpu %02x, base %02x\n",
  369. ((val >> 8) & 0xFF),
  370. ((val >> 0) & 0xFF));
  371. bsw2 = bonito_fpga_read(BUSSWMR2);
  372. bsw3 = bonito_fpga_read(BUSSWMR3);
  373. bsw4 = bonito_fpga_read(BUSSWMR4);
  374. /*
  375. * SCIFA5 (CN42)
  376. */
  377. if (BIT_OFF(bsw2, 1) && /* S38.3 = ON */
  378. BIT_OFF(bsw3, 9) && /* S39.6 = ON */
  379. BIT_OFF(bsw4, 4)) { /* S43.1 = ON */
  380. gpio_request(GPIO_FN_SCIFA5_TXD_PORT91, NULL);
  381. gpio_request(GPIO_FN_SCIFA5_RXD_PORT92, NULL);
  382. }
  383. /*
  384. * LCDC0 (CN3)
  385. */
  386. if (BIT_ON(bsw2, 3) && /* S38.1 = OFF */
  387. BIT_ON(bsw2, 2)) { /* S38.2 = OFF */
  388. gpio_request(GPIO_FN_LCDC0_SELECT, NULL);
  389. gpio_request(GPIO_FN_LCD0_D0, NULL);
  390. gpio_request(GPIO_FN_LCD0_D1, NULL);
  391. gpio_request(GPIO_FN_LCD0_D2, NULL);
  392. gpio_request(GPIO_FN_LCD0_D3, NULL);
  393. gpio_request(GPIO_FN_LCD0_D4, NULL);
  394. gpio_request(GPIO_FN_LCD0_D5, NULL);
  395. gpio_request(GPIO_FN_LCD0_D6, NULL);
  396. gpio_request(GPIO_FN_LCD0_D7, NULL);
  397. gpio_request(GPIO_FN_LCD0_D8, NULL);
  398. gpio_request(GPIO_FN_LCD0_D9, NULL);
  399. gpio_request(GPIO_FN_LCD0_D10, NULL);
  400. gpio_request(GPIO_FN_LCD0_D11, NULL);
  401. gpio_request(GPIO_FN_LCD0_D12, NULL);
  402. gpio_request(GPIO_FN_LCD0_D13, NULL);
  403. gpio_request(GPIO_FN_LCD0_D14, NULL);
  404. gpio_request(GPIO_FN_LCD0_D15, NULL);
  405. gpio_request(GPIO_FN_LCD0_D16, NULL);
  406. gpio_request(GPIO_FN_LCD0_D17, NULL);
  407. gpio_request(GPIO_FN_LCD0_D18_PORT163, NULL);
  408. gpio_request(GPIO_FN_LCD0_D19_PORT162, NULL);
  409. gpio_request(GPIO_FN_LCD0_D20_PORT161, NULL);
  410. gpio_request(GPIO_FN_LCD0_D21_PORT158, NULL);
  411. gpio_request(GPIO_FN_LCD0_D22_PORT160, NULL);
  412. gpio_request(GPIO_FN_LCD0_D23_PORT159, NULL);
  413. gpio_request(GPIO_FN_LCD0_DCK, NULL);
  414. gpio_request(GPIO_FN_LCD0_VSYN, NULL);
  415. gpio_request(GPIO_FN_LCD0_HSYN, NULL);
  416. gpio_request(GPIO_FN_LCD0_DISP, NULL);
  417. gpio_request(GPIO_FN_LCD0_LCLK_PORT165, NULL);
  418. gpio_request(GPIO_PORT61, NULL); /* LCDDON */
  419. gpio_direction_output(GPIO_PORT61, 1);
  420. /* backlight on */
  421. bonito_fpga_write(LCDCR, 1);
  422. /* drivability Max */
  423. __raw_writew(0x00FF , VCCQ1LCDCR);
  424. __raw_writew(0xFFFF , VCCQ1CR);
  425. }
  426. platform_add_devices(bonito_base_devices,
  427. ARRAY_SIZE(bonito_base_devices));
  428. }
  429. }
  430. static void __init bonito_timer_init(void)
  431. {
  432. u16 val;
  433. u8 md_ck = 0;
  434. /* read MD_CK value */
  435. val = bonito_fpga_read(A1MDSR);
  436. if (val & (1 << 10))
  437. md_ck |= MD_CK2;
  438. if (val & (1 << 9))
  439. md_ck |= MD_CK1;
  440. if (val & (1 << 8))
  441. md_ck |= MD_CK0;
  442. r8a7740_clock_init(md_ck);
  443. shmobile_timer.init();
  444. }
  445. struct sys_timer bonito_timer = {
  446. .init = bonito_timer_init,
  447. };
  448. MACHINE_START(BONITO, "bonito")
  449. .map_io = bonito_map_io,
  450. .init_irq = r8a7740_init_irq,
  451. .handle_irq = shmobile_handle_irq_intc,
  452. .init_machine = bonito_init,
  453. .timer = &bonito_timer,
  454. MACHINE_END