board-bonito.c 11 KB

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