board-bonito.c 11 KB

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