board-bonito.c 11 KB

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