board-bonito.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 <mach/common.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/mach/arch.h>
  31. #include <asm/mach/map.h>
  32. #include <asm/mach/time.h>
  33. #include <asm/hardware/cache-l2x0.h>
  34. #include <mach/r8a7740.h>
  35. #include <video/sh_mobile_lcdc.h>
  36. /*
  37. * CS Address device note
  38. *----------------------------------------------------------------
  39. * 0 0x0000_0000 NOR Flash (64MB) SW12 : bit3 = OFF
  40. * 2 0x0800_0000 ExtNOR (64MB) SW12 : bit3 = OFF
  41. * 4 -
  42. * 5A -
  43. * 5B 0x1600_0000 SRAM (8MB)
  44. * 6 0x1800_0000 FPGA (64K)
  45. * 0x1801_0000 Ether (4KB)
  46. * 0x1801_1000 USB (4KB)
  47. */
  48. /*
  49. * SW12
  50. *
  51. * bit1 bit2 bit3
  52. *----------------------------------------------------------------------------
  53. * ON NOR WriteProtect NAND WriteProtect CS0 ExtNOR / CS2 NOR
  54. * OFF NOR Not WriteProtect NAND Not WriteProtect CS0 NOR / CS2 ExtNOR
  55. */
  56. /*
  57. * SCIFA5 (CN42)
  58. *
  59. * S38.3 = ON
  60. * S39.6 = ON
  61. * S43.1 = ON
  62. */
  63. /*
  64. * LCDC0 (CN3/CN4/CN7)
  65. *
  66. * S38.1 = OFF
  67. * S38.2 = OFF
  68. */
  69. /*
  70. * FPGA
  71. */
  72. #define BUSSWMR1 0x0070
  73. #define BUSSWMR2 0x0072
  74. #define BUSSWMR3 0x0074
  75. #define BUSSWMR4 0x0076
  76. #define LCDCR 0x10B4
  77. #define A1MDSR 0x10E0
  78. #define BVERR 0x1100
  79. static u16 bonito_fpga_read(u32 offset)
  80. {
  81. return __raw_readw(0xf0003000 + offset);
  82. }
  83. static void bonito_fpga_write(u32 offset, u16 val)
  84. {
  85. __raw_writew(val, 0xf0003000 + offset);
  86. }
  87. /*
  88. * PMIC settings
  89. *
  90. * FIXME
  91. *
  92. * bonito board needs some settings by pmic which use i2c access.
  93. * pmic settings use device_initcall() here for use it.
  94. */
  95. static __u8 *pmic_settings = NULL;
  96. static __u8 pmic_do_2A[] = {
  97. 0x1C, 0x09,
  98. 0x1A, 0x80,
  99. 0xff, 0xff,
  100. };
  101. static int __init pmic_init(void)
  102. {
  103. struct i2c_adapter *a = i2c_get_adapter(0);
  104. struct i2c_msg msg;
  105. __u8 buf[2];
  106. int i, ret;
  107. if (!pmic_settings)
  108. return 0;
  109. if (!a)
  110. return 0;
  111. msg.addr = 0x46;
  112. msg.buf = buf;
  113. msg.len = 2;
  114. msg.flags = 0;
  115. for (i = 0; ; i += 2) {
  116. buf[0] = pmic_settings[i + 0];
  117. buf[1] = pmic_settings[i + 1];
  118. if ((0xff == buf[0]) && (0xff == buf[1]))
  119. break;
  120. ret = i2c_transfer(a, &msg, 1);
  121. if (ret < 0) {
  122. pr_err("i2c transfer fail\n");
  123. break;
  124. }
  125. }
  126. return 0;
  127. }
  128. device_initcall(pmic_init);
  129. /*
  130. * LCDC0
  131. */
  132. static const struct fb_videomode lcdc0_mode = {
  133. .name = "WVGA Panel",
  134. .xres = 800,
  135. .yres = 480,
  136. .left_margin = 88,
  137. .right_margin = 40,
  138. .hsync_len = 128,
  139. .upper_margin = 20,
  140. .lower_margin = 5,
  141. .vsync_len = 5,
  142. .sync = 0,
  143. };
  144. static struct sh_mobile_lcdc_info lcdc0_info = {
  145. .clock_source = LCDC_CLK_BUS,
  146. .ch[0] = {
  147. .chan = LCDC_CHAN_MAINLCD,
  148. .bpp = 16,
  149. .interface_type = RGB24,
  150. .clock_divider = 5,
  151. .flags = 0,
  152. .lcd_cfg = &lcdc0_mode,
  153. .num_cfg = 1,
  154. .lcd_size_cfg = {
  155. .width = 152,
  156. .height = 91,
  157. },
  158. },
  159. };
  160. static struct resource lcdc0_resources[] = {
  161. [0] = {
  162. .name = "LCDC0",
  163. .start = 0xfe940000,
  164. .end = 0xfe943fff,
  165. .flags = IORESOURCE_MEM,
  166. },
  167. [1] = {
  168. .start = intcs_evt2irq(0x0580),
  169. .flags = IORESOURCE_IRQ,
  170. },
  171. };
  172. static struct platform_device lcdc0_device = {
  173. .name = "sh_mobile_lcdc_fb",
  174. .id = 0,
  175. .resource = lcdc0_resources,
  176. .num_resources = ARRAY_SIZE(lcdc0_resources),
  177. .dev = {
  178. .platform_data = &lcdc0_info,
  179. .coherent_dma_mask = ~0,
  180. },
  181. };
  182. /*
  183. * core board devices
  184. */
  185. static struct platform_device *bonito_core_devices[] __initdata = {
  186. };
  187. /*
  188. * base board devices
  189. */
  190. static struct platform_device *bonito_base_devices[] __initdata = {
  191. &lcdc0_device,
  192. };
  193. /*
  194. * map I/O
  195. */
  196. static struct map_desc bonito_io_desc[] __initdata = {
  197. /*
  198. * for CPGA/INTC/PFC
  199. * 0xe6000000-0xefffffff -> 0xe6000000-0xefffffff
  200. */
  201. {
  202. .virtual = 0xe6000000,
  203. .pfn = __phys_to_pfn(0xe6000000),
  204. .length = 160 << 20,
  205. .type = MT_DEVICE_NONSHARED
  206. },
  207. #ifdef CONFIG_CACHE_L2X0
  208. /*
  209. * for l2x0_init()
  210. * 0xf0100000-0xf0101000 -> 0xf0002000-0xf0003000
  211. */
  212. {
  213. .virtual = 0xf0002000,
  214. .pfn = __phys_to_pfn(0xf0100000),
  215. .length = PAGE_SIZE,
  216. .type = MT_DEVICE_NONSHARED
  217. },
  218. #endif
  219. /*
  220. * for FPGA (0x1800000-0x19ffffff)
  221. * 0x18000000-0x18002000 -> 0xf0003000-0xf0005000
  222. */
  223. {
  224. .virtual = 0xf0003000,
  225. .pfn = __phys_to_pfn(0x18000000),
  226. .length = PAGE_SIZE * 2,
  227. .type = MT_DEVICE_NONSHARED
  228. }
  229. };
  230. static void __init bonito_map_io(void)
  231. {
  232. iotable_init(bonito_io_desc, ARRAY_SIZE(bonito_io_desc));
  233. /* setup early devices and console here as well */
  234. r8a7740_add_early_devices();
  235. shmobile_setup_console();
  236. }
  237. /*
  238. * board init
  239. */
  240. #define BIT_ON(sw, bit) (sw & (1 << bit))
  241. #define BIT_OFF(sw, bit) (!(sw & (1 << bit)))
  242. #define VCCQ1CR 0xE6058140
  243. #define VCCQ1LCDCR 0xE6058186
  244. static void __init bonito_init(void)
  245. {
  246. u16 val;
  247. r8a7740_pinmux_init();
  248. pmic_settings = pmic_do_2A;
  249. /*
  250. * core board settings
  251. */
  252. #ifdef CONFIG_CACHE_L2X0
  253. /* Early BRESP enable, Shared attribute override enable, 32K*8way */
  254. l2x0_init(__io(0xf0002000), 0x40440000, 0x82000fff);
  255. #endif
  256. r8a7740_add_standard_devices();
  257. platform_add_devices(bonito_core_devices,
  258. ARRAY_SIZE(bonito_core_devices));
  259. /*
  260. * base board settings
  261. */
  262. gpio_request(GPIO_PORT176, NULL);
  263. gpio_direction_input(GPIO_PORT176);
  264. if (!gpio_get_value(GPIO_PORT176)) {
  265. u16 bsw2;
  266. u16 bsw3;
  267. u16 bsw4;
  268. /*
  269. * FPGA
  270. */
  271. gpio_request(GPIO_FN_CS5B, NULL);
  272. gpio_request(GPIO_FN_CS6A, NULL);
  273. gpio_request(GPIO_FN_CS5A_PORT105, NULL);
  274. gpio_request(GPIO_FN_IRQ10, NULL);
  275. val = bonito_fpga_read(BVERR);
  276. pr_info("bonito version: cpu %02x, base %02x\n",
  277. ((val >> 8) & 0xFF),
  278. ((val >> 0) & 0xFF));
  279. bsw2 = bonito_fpga_read(BUSSWMR2);
  280. bsw3 = bonito_fpga_read(BUSSWMR3);
  281. bsw4 = bonito_fpga_read(BUSSWMR4);
  282. /*
  283. * SCIFA5 (CN42)
  284. */
  285. if (BIT_OFF(bsw2, 1) && /* S38.3 = ON */
  286. BIT_OFF(bsw3, 9) && /* S39.6 = ON */
  287. BIT_OFF(bsw4, 4)) { /* S43.1 = ON */
  288. gpio_request(GPIO_FN_SCIFA5_TXD_PORT91, NULL);
  289. gpio_request(GPIO_FN_SCIFA5_RXD_PORT92, NULL);
  290. }
  291. /*
  292. * LCDC0 (CN3)
  293. */
  294. if (BIT_ON(bsw2, 3) && /* S38.1 = OFF */
  295. BIT_ON(bsw2, 2)) { /* S38.2 = OFF */
  296. gpio_request(GPIO_FN_LCDC0_SELECT, NULL);
  297. gpio_request(GPIO_FN_LCD0_D0, NULL);
  298. gpio_request(GPIO_FN_LCD0_D1, NULL);
  299. gpio_request(GPIO_FN_LCD0_D2, NULL);
  300. gpio_request(GPIO_FN_LCD0_D3, NULL);
  301. gpio_request(GPIO_FN_LCD0_D4, NULL);
  302. gpio_request(GPIO_FN_LCD0_D5, NULL);
  303. gpio_request(GPIO_FN_LCD0_D6, NULL);
  304. gpio_request(GPIO_FN_LCD0_D7, NULL);
  305. gpio_request(GPIO_FN_LCD0_D8, NULL);
  306. gpio_request(GPIO_FN_LCD0_D9, NULL);
  307. gpio_request(GPIO_FN_LCD0_D10, NULL);
  308. gpio_request(GPIO_FN_LCD0_D11, NULL);
  309. gpio_request(GPIO_FN_LCD0_D12, NULL);
  310. gpio_request(GPIO_FN_LCD0_D13, NULL);
  311. gpio_request(GPIO_FN_LCD0_D14, NULL);
  312. gpio_request(GPIO_FN_LCD0_D15, NULL);
  313. gpio_request(GPIO_FN_LCD0_D16, NULL);
  314. gpio_request(GPIO_FN_LCD0_D17, NULL);
  315. gpio_request(GPIO_FN_LCD0_D18_PORT163, NULL);
  316. gpio_request(GPIO_FN_LCD0_D19_PORT162, NULL);
  317. gpio_request(GPIO_FN_LCD0_D20_PORT161, NULL);
  318. gpio_request(GPIO_FN_LCD0_D21_PORT158, NULL);
  319. gpio_request(GPIO_FN_LCD0_D22_PORT160, NULL);
  320. gpio_request(GPIO_FN_LCD0_D23_PORT159, NULL);
  321. gpio_request(GPIO_FN_LCD0_DCK, NULL);
  322. gpio_request(GPIO_FN_LCD0_VSYN, NULL);
  323. gpio_request(GPIO_FN_LCD0_HSYN, NULL);
  324. gpio_request(GPIO_FN_LCD0_DISP, NULL);
  325. gpio_request(GPIO_FN_LCD0_LCLK_PORT165, NULL);
  326. gpio_request(GPIO_PORT61, NULL); /* LCDDON */
  327. gpio_direction_output(GPIO_PORT61, 1);
  328. /* backlight on */
  329. bonito_fpga_write(LCDCR, 1);
  330. /* drivability Max */
  331. __raw_writew(0x00FF , VCCQ1LCDCR);
  332. __raw_writew(0xFFFF , VCCQ1CR);
  333. }
  334. platform_add_devices(bonito_base_devices,
  335. ARRAY_SIZE(bonito_base_devices));
  336. }
  337. }
  338. static void __init bonito_timer_init(void)
  339. {
  340. u16 val;
  341. u8 md_ck = 0;
  342. /* read MD_CK value */
  343. val = bonito_fpga_read(A1MDSR);
  344. if (val & (1 << 10))
  345. md_ck |= MD_CK2;
  346. if (val & (1 << 9))
  347. md_ck |= MD_CK1;
  348. if (val & (1 << 8))
  349. md_ck |= MD_CK0;
  350. r8a7740_clock_init(md_ck);
  351. shmobile_timer.init();
  352. }
  353. struct sys_timer bonito_timer = {
  354. .init = bonito_timer_init,
  355. };
  356. MACHINE_START(BONITO, "bonito")
  357. .map_io = bonito_map_io,
  358. .init_irq = r8a7740_init_irq,
  359. .handle_irq = shmobile_handle_irq_intc,
  360. .init_machine = bonito_init,
  361. .timer = &bonito_timer,
  362. MACHINE_END