board-bonito.c 12 KB

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