board-mackerel.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522
  1. /*
  2. * mackerel board support
  3. *
  4. * Copyright (C) 2010 Renesas Solutions Corp.
  5. * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  7. * based on ap4evb
  8. * Copyright (C) 2010 Magnus Damm
  9. * Copyright (C) 2008 Yoshihiro Shimoda
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; version 2 of the License.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #include <linux/delay.h>
  25. #include <linux/kernel.h>
  26. #include <linux/init.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/irq.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/gpio.h>
  31. #include <linux/input.h>
  32. #include <linux/io.h>
  33. #include <linux/i2c.h>
  34. #include <linux/leds.h>
  35. #include <linux/mfd/tmio.h>
  36. #include <linux/mmc/host.h>
  37. #include <linux/mmc/sh_mmcif.h>
  38. #include <linux/mmc/sh_mobile_sdhi.h>
  39. #include <linux/mtd/mtd.h>
  40. #include <linux/mtd/partitions.h>
  41. #include <linux/mtd/physmap.h>
  42. #include <linux/pm_runtime.h>
  43. #include <linux/smsc911x.h>
  44. #include <linux/sh_intc.h>
  45. #include <linux/tca6416_keypad.h>
  46. #include <linux/usb/r8a66597.h>
  47. #include <linux/usb/renesas_usbhs.h>
  48. #include <video/sh_mobile_hdmi.h>
  49. #include <video/sh_mobile_lcdc.h>
  50. #include <media/sh_mobile_ceu.h>
  51. #include <media/soc_camera.h>
  52. #include <media/soc_camera_platform.h>
  53. #include <sound/sh_fsi.h>
  54. #include <mach/common.h>
  55. #include <mach/sh7372.h>
  56. #include <asm/mach/arch.h>
  57. #include <asm/mach/time.h>
  58. #include <asm/mach/map.h>
  59. #include <asm/mach-types.h>
  60. /*
  61. * Address Interface BusWidth note
  62. * ------------------------------------------------------------------
  63. * 0x0000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = ON
  64. * 0x0800_0000 user area -
  65. * 0x1000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = OFF
  66. * 0x1400_0000 Ether (LAN9220) 16bit
  67. * 0x1600_0000 user area - cannot use with NAND
  68. * 0x1800_0000 user area -
  69. * 0x1A00_0000 -
  70. * 0x4000_0000 LPDDR2-SDRAM (POP) 32bit
  71. */
  72. /*
  73. * CPU mode
  74. *
  75. * SW4 | Boot Area| Master | Remarks
  76. * 1 | 2 | 3 | 4 | 5 | 6 | 8 | | Processor|
  77. * ----+-----+-----+-----+-----+-----+-----+----------+----------+--------------
  78. * ON | ON | OFF | ON | ON | OFF | OFF | External | System | External ROM
  79. * ON | ON | ON | ON | ON | OFF | OFF | External | System | ROM Debug
  80. * ON | ON | X | ON | OFF | OFF | OFF | Built-in | System | ROM Debug
  81. * X | OFF | X | X | X | X | OFF | Built-in | System | MaskROM
  82. * OFF | X | X | X | X | X | OFF | Built-in | System | MaskROM
  83. * X | X | X | OFF | X | X | OFF | Built-in | System | MaskROM
  84. * OFF | ON | OFF | X | X | OFF | ON | External | System | Standalone
  85. * ON | OFF | OFF | X | X | OFF | ON | External | Realtime | Standalone
  86. */
  87. /*
  88. * NOR Flash ROM
  89. *
  90. * SW1 | SW2 | SW7 | NOR Flash ROM
  91. * bit1 | bit1 bit2 | bit1 | Memory allocation
  92. * ------+------------+------+------------------
  93. * OFF | ON OFF | ON | Area 0
  94. * OFF | ON OFF | OFF | Area 4
  95. */
  96. /*
  97. * SMSC 9220
  98. *
  99. * SW1 SMSC 9220
  100. * -----------------------
  101. * ON access disable
  102. * OFF access enable
  103. */
  104. /*
  105. * NAND Flash ROM
  106. *
  107. * SW1 | SW2 | SW7 | NAND Flash ROM
  108. * bit1 | bit1 bit2 | bit2 | Memory allocation
  109. * ------+------------+------+------------------
  110. * OFF | ON OFF | ON | FCE 0
  111. * OFF | ON OFF | OFF | FCE 1
  112. */
  113. /*
  114. * External interrupt pin settings
  115. *
  116. * IRQX | pin setting | device | level
  117. * ------+--------------------+--------------------+-------
  118. * IRQ0 | ICR1A.IRQ0SA=0010 | SDHI2 card detect | Low
  119. * IRQ6 | ICR1A.IRQ6SA=0011 | Ether(LAN9220) | High
  120. * IRQ7 | ICR1A.IRQ7SA=0010 | LCD Tuch Panel | Low
  121. * IRQ8 | ICR2A.IRQ8SA=0010 | MMC/SD card detect | Low
  122. * IRQ9 | ICR2A.IRQ9SA=0010 | KEY(TCA6408) | Low
  123. * IRQ21 | ICR4A.IRQ21SA=0011 | Sensor(ADXL345) | High
  124. * IRQ22 | ICR4A.IRQ22SA=0011 | Sensor(AK8975) | High
  125. */
  126. /*
  127. * USB
  128. *
  129. * USB0 : CN22 : Function
  130. * USB1 : CN31 : Function/Host *1
  131. *
  132. * J30 (for CN31) *1
  133. * ----------+---------------+-------------
  134. * 1-2 short | VBUS 5V | Host
  135. * open | external VBUS | Function
  136. *
  137. * *1
  138. * CN31 is used as
  139. * CONFIG_USB_R8A66597_HCD Host
  140. * CONFIG_USB_RENESAS_USBHS Function
  141. *
  142. * CAUTION
  143. *
  144. * renesas_usbhs driver can use external interrupt mode
  145. * (which come from USB-PHY) or autonomy mode (it use own interrupt)
  146. * for detecting connection/disconnection when Function.
  147. * USB will be power OFF while it has been disconnecting
  148. * if external interrupt mode, and it is always power ON if autonomy mode,
  149. *
  150. * mackerel can not use external interrupt (IRQ7-PORT167) mode on "USB0",
  151. * because Touchscreen is using IRQ7-PORT40.
  152. * It is impossible to use IRQ7 demux on this board.
  153. *
  154. * We can use external interrupt mode USB-Function on "USB1".
  155. * USB1 can become Host by r8a66597, and become Function by renesas_usbhs.
  156. * But don't select both drivers in same time.
  157. * These uses same IRQ number for request_irq(), and aren't supporting
  158. * IRQF_SHARD / IORESOURCE_IRQ_SHAREABLE.
  159. *
  160. * Actually these are old/new version of USB driver.
  161. * This mean its register will be broken if it supports SHARD IRQ,
  162. */
  163. /*
  164. * SDHI0 (CN12)
  165. *
  166. * SW56 : OFF
  167. *
  168. */
  169. /* MMC /SDHI1 (CN7)
  170. *
  171. * I/O voltage : 1.8v
  172. *
  173. * Power voltage : 1.8v or 3.3v
  174. * J22 : select power voltage *1
  175. * 1-2 pin : 1.8v
  176. * 2-3 pin : 3.3v
  177. *
  178. * *1
  179. * Please change J22 depends the card to be used.
  180. * MMC's OCR field set to support either voltage for the card inserted.
  181. *
  182. * SW1 | SW33
  183. * | bit1 | bit2 | bit3 | bit4
  184. * -------------+------+------+------+-------
  185. * MMC0 OFF | OFF | X | ON | X (Use MMCIF)
  186. * SDHI1 OFF | ON | X | OFF | X (Use MFD_SH_MOBILE_SDHI)
  187. *
  188. */
  189. /*
  190. * SDHI2 (CN23)
  191. *
  192. * microSD card sloct
  193. *
  194. */
  195. /*
  196. * FIXME !!
  197. *
  198. * gpio_no_direction
  199. * gpio_pull_down
  200. * are quick_hack.
  201. *
  202. * current gpio frame work doesn't have
  203. * the method to control only pull up/down/free.
  204. * this function should be replaced by correct gpio function
  205. */
  206. static void __init gpio_no_direction(u32 addr)
  207. {
  208. __raw_writeb(0x00, addr);
  209. }
  210. static void __init gpio_pull_down(u32 addr)
  211. {
  212. u8 data = __raw_readb(addr);
  213. data &= 0x0F;
  214. data |= 0xA0;
  215. __raw_writeb(data, addr);
  216. }
  217. /* MTD */
  218. static struct mtd_partition nor_flash_partitions[] = {
  219. {
  220. .name = "loader",
  221. .offset = 0x00000000,
  222. .size = 512 * 1024,
  223. .mask_flags = MTD_WRITEABLE,
  224. },
  225. {
  226. .name = "bootenv",
  227. .offset = MTDPART_OFS_APPEND,
  228. .size = 512 * 1024,
  229. .mask_flags = MTD_WRITEABLE,
  230. },
  231. {
  232. .name = "kernel_ro",
  233. .offset = MTDPART_OFS_APPEND,
  234. .size = 8 * 1024 * 1024,
  235. .mask_flags = MTD_WRITEABLE,
  236. },
  237. {
  238. .name = "kernel",
  239. .offset = MTDPART_OFS_APPEND,
  240. .size = 8 * 1024 * 1024,
  241. },
  242. {
  243. .name = "data",
  244. .offset = MTDPART_OFS_APPEND,
  245. .size = MTDPART_SIZ_FULL,
  246. },
  247. };
  248. static struct physmap_flash_data nor_flash_data = {
  249. .width = 2,
  250. .parts = nor_flash_partitions,
  251. .nr_parts = ARRAY_SIZE(nor_flash_partitions),
  252. };
  253. static struct resource nor_flash_resources[] = {
  254. [0] = {
  255. .start = 0x00000000,
  256. .end = 0x08000000 - 1,
  257. .flags = IORESOURCE_MEM,
  258. }
  259. };
  260. static struct platform_device nor_flash_device = {
  261. .name = "physmap-flash",
  262. .dev = {
  263. .platform_data = &nor_flash_data,
  264. },
  265. .num_resources = ARRAY_SIZE(nor_flash_resources),
  266. .resource = nor_flash_resources,
  267. };
  268. /* SMSC */
  269. static struct resource smc911x_resources[] = {
  270. {
  271. .start = 0x14000000,
  272. .end = 0x16000000 - 1,
  273. .flags = IORESOURCE_MEM,
  274. }, {
  275. .start = evt2irq(0x02c0) /* IRQ6A */,
  276. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  277. },
  278. };
  279. static struct smsc911x_platform_config smsc911x_info = {
  280. .flags = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
  281. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  282. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  283. };
  284. static struct platform_device smc911x_device = {
  285. .name = "smsc911x",
  286. .id = -1,
  287. .num_resources = ARRAY_SIZE(smc911x_resources),
  288. .resource = smc911x_resources,
  289. .dev = {
  290. .platform_data = &smsc911x_info,
  291. },
  292. };
  293. /* MERAM */
  294. static struct sh_mobile_meram_info mackerel_meram_info = {
  295. .addr_mode = SH_MOBILE_MERAM_MODE1,
  296. };
  297. static struct resource meram_resources[] = {
  298. [0] = {
  299. .name = "MERAM",
  300. .start = 0xe8000000,
  301. .end = 0xe81fffff,
  302. .flags = IORESOURCE_MEM,
  303. },
  304. };
  305. static struct platform_device meram_device = {
  306. .name = "sh_mobile_meram",
  307. .id = 0,
  308. .num_resources = ARRAY_SIZE(meram_resources),
  309. .resource = meram_resources,
  310. .dev = {
  311. .platform_data = &mackerel_meram_info,
  312. },
  313. };
  314. /* LCDC */
  315. static struct fb_videomode mackerel_lcdc_modes[] = {
  316. {
  317. .name = "WVGA Panel",
  318. .xres = 800,
  319. .yres = 480,
  320. .left_margin = 220,
  321. .right_margin = 110,
  322. .hsync_len = 70,
  323. .upper_margin = 20,
  324. .lower_margin = 5,
  325. .vsync_len = 5,
  326. .sync = 0,
  327. },
  328. };
  329. static int mackerel_set_brightness(void *board_data, int brightness)
  330. {
  331. gpio_set_value(GPIO_PORT31, brightness);
  332. return 0;
  333. }
  334. static int mackerel_get_brightness(void *board_data)
  335. {
  336. return gpio_get_value(GPIO_PORT31);
  337. }
  338. static struct sh_mobile_meram_cfg lcd_meram_cfg = {
  339. .icb[0] = {
  340. .marker_icb = 28,
  341. .cache_icb = 24,
  342. .meram_offset = 0x0,
  343. .meram_size = 0x40,
  344. },
  345. .icb[1] = {
  346. .marker_icb = 29,
  347. .cache_icb = 25,
  348. .meram_offset = 0x40,
  349. .meram_size = 0x40,
  350. },
  351. };
  352. static struct sh_mobile_lcdc_info lcdc_info = {
  353. .meram_dev = &mackerel_meram_info,
  354. .clock_source = LCDC_CLK_BUS,
  355. .ch[0] = {
  356. .chan = LCDC_CHAN_MAINLCD,
  357. .bpp = 16,
  358. .lcd_cfg = mackerel_lcdc_modes,
  359. .num_cfg = ARRAY_SIZE(mackerel_lcdc_modes),
  360. .interface_type = RGB24,
  361. .clock_divider = 3,
  362. .flags = 0,
  363. .lcd_size_cfg.width = 152,
  364. .lcd_size_cfg.height = 91,
  365. .board_cfg = {
  366. .set_brightness = mackerel_set_brightness,
  367. .get_brightness = mackerel_get_brightness,
  368. },
  369. .bl_info = {
  370. .name = "sh_mobile_lcdc_bl",
  371. .max_brightness = 1,
  372. },
  373. .meram_cfg = &lcd_meram_cfg,
  374. }
  375. };
  376. static struct resource lcdc_resources[] = {
  377. [0] = {
  378. .name = "LCDC",
  379. .start = 0xfe940000,
  380. .end = 0xfe943fff,
  381. .flags = IORESOURCE_MEM,
  382. },
  383. [1] = {
  384. .start = intcs_evt2irq(0x580),
  385. .flags = IORESOURCE_IRQ,
  386. },
  387. };
  388. static struct platform_device lcdc_device = {
  389. .name = "sh_mobile_lcdc_fb",
  390. .num_resources = ARRAY_SIZE(lcdc_resources),
  391. .resource = lcdc_resources,
  392. .dev = {
  393. .platform_data = &lcdc_info,
  394. .coherent_dma_mask = ~0,
  395. },
  396. };
  397. static struct sh_mobile_meram_cfg hdmi_meram_cfg = {
  398. .icb[0] = {
  399. .marker_icb = 30,
  400. .cache_icb = 26,
  401. .meram_offset = 0x80,
  402. .meram_size = 0x100,
  403. },
  404. .icb[1] = {
  405. .marker_icb = 31,
  406. .cache_icb = 27,
  407. .meram_offset = 0x180,
  408. .meram_size = 0x100,
  409. },
  410. };
  411. /* HDMI */
  412. static struct sh_mobile_lcdc_info hdmi_lcdc_info = {
  413. .meram_dev = &mackerel_meram_info,
  414. .clock_source = LCDC_CLK_EXTERNAL,
  415. .ch[0] = {
  416. .chan = LCDC_CHAN_MAINLCD,
  417. .bpp = 16,
  418. .interface_type = RGB24,
  419. .clock_divider = 1,
  420. .flags = LCDC_FLAGS_DWPOL,
  421. .meram_cfg = &hdmi_meram_cfg,
  422. }
  423. };
  424. static struct resource hdmi_lcdc_resources[] = {
  425. [0] = {
  426. .name = "LCDC1",
  427. .start = 0xfe944000,
  428. .end = 0xfe947fff,
  429. .flags = IORESOURCE_MEM,
  430. },
  431. [1] = {
  432. .start = intcs_evt2irq(0x1780),
  433. .flags = IORESOURCE_IRQ,
  434. },
  435. };
  436. static struct platform_device hdmi_lcdc_device = {
  437. .name = "sh_mobile_lcdc_fb",
  438. .num_resources = ARRAY_SIZE(hdmi_lcdc_resources),
  439. .resource = hdmi_lcdc_resources,
  440. .id = 1,
  441. .dev = {
  442. .platform_data = &hdmi_lcdc_info,
  443. .coherent_dma_mask = ~0,
  444. },
  445. };
  446. static struct sh_mobile_hdmi_info hdmi_info = {
  447. .lcd_chan = &hdmi_lcdc_info.ch[0],
  448. .lcd_dev = &hdmi_lcdc_device.dev,
  449. .flags = HDMI_SND_SRC_SPDIF,
  450. };
  451. static struct resource hdmi_resources[] = {
  452. [0] = {
  453. .name = "HDMI",
  454. .start = 0xe6be0000,
  455. .end = 0xe6be00ff,
  456. .flags = IORESOURCE_MEM,
  457. },
  458. [1] = {
  459. /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
  460. .start = evt2irq(0x17e0),
  461. .flags = IORESOURCE_IRQ,
  462. },
  463. };
  464. static struct platform_device hdmi_device = {
  465. .name = "sh-mobile-hdmi",
  466. .num_resources = ARRAY_SIZE(hdmi_resources),
  467. .resource = hdmi_resources,
  468. .id = -1,
  469. .dev = {
  470. .platform_data = &hdmi_info,
  471. },
  472. };
  473. static struct platform_device fsi_hdmi_device = {
  474. .name = "sh_fsi2_b_hdmi",
  475. };
  476. static void __init hdmi_init_pm_clock(void)
  477. {
  478. struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
  479. int ret;
  480. long rate;
  481. if (IS_ERR(hdmi_ick)) {
  482. ret = PTR_ERR(hdmi_ick);
  483. pr_err("Cannot get HDMI ICK: %d\n", ret);
  484. goto out;
  485. }
  486. ret = clk_set_parent(&sh7372_pllc2_clk, &sh7372_dv_clki_div2_clk);
  487. if (ret < 0) {
  488. pr_err("Cannot set PLLC2 parent: %d, %d users\n",
  489. ret, sh7372_pllc2_clk.usecount);
  490. goto out;
  491. }
  492. pr_debug("PLLC2 initial frequency %lu\n",
  493. clk_get_rate(&sh7372_pllc2_clk));
  494. rate = clk_round_rate(&sh7372_pllc2_clk, 594000000);
  495. if (rate < 0) {
  496. pr_err("Cannot get suitable rate: %ld\n", rate);
  497. ret = rate;
  498. goto out;
  499. }
  500. ret = clk_set_rate(&sh7372_pllc2_clk, rate);
  501. if (ret < 0) {
  502. pr_err("Cannot set rate %ld: %d\n", rate, ret);
  503. goto out;
  504. }
  505. pr_debug("PLLC2 set frequency %lu\n", rate);
  506. ret = clk_set_parent(hdmi_ick, &sh7372_pllc2_clk);
  507. if (ret < 0)
  508. pr_err("Cannot set HDMI parent: %d\n", ret);
  509. out:
  510. if (!IS_ERR(hdmi_ick))
  511. clk_put(hdmi_ick);
  512. }
  513. /* USB1 (Host) */
  514. static void usb1_host_port_power(int port, int power)
  515. {
  516. if (!power) /* only power-on is supported for now */
  517. return;
  518. /* set VBOUT/PWEN and EXTLP1 in DVSTCTR */
  519. __raw_writew(__raw_readw(0xE68B0008) | 0x600, 0xE68B0008);
  520. }
  521. static struct r8a66597_platdata usb1_host_data = {
  522. .on_chip = 1,
  523. .port_power = usb1_host_port_power,
  524. };
  525. static struct resource usb1_host_resources[] = {
  526. [0] = {
  527. .name = "USBHS",
  528. .start = 0xE68B0000,
  529. .end = 0xE68B00E6 - 1,
  530. .flags = IORESOURCE_MEM,
  531. },
  532. [1] = {
  533. .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
  534. .flags = IORESOURCE_IRQ,
  535. },
  536. };
  537. static struct platform_device usb1_host_device = {
  538. .name = "r8a66597_hcd",
  539. .id = 1,
  540. .dev = {
  541. .dma_mask = NULL, /* not use dma */
  542. .coherent_dma_mask = 0xffffffff,
  543. .platform_data = &usb1_host_data,
  544. },
  545. .num_resources = ARRAY_SIZE(usb1_host_resources),
  546. .resource = usb1_host_resources,
  547. };
  548. /* USB1 (Function) */
  549. #define USB_PHY_MODE (1 << 4)
  550. #define USB_PHY_INT_EN ((1 << 3) | (1 << 2))
  551. #define USB_PHY_ON (1 << 1)
  552. #define USB_PHY_OFF (1 << 0)
  553. #define USB_PHY_INT_CLR (USB_PHY_ON | USB_PHY_OFF)
  554. struct usbhs_private {
  555. unsigned int irq;
  556. unsigned int usbphyaddr;
  557. unsigned int usbcrcaddr;
  558. struct renesas_usbhs_platform_info info;
  559. };
  560. #define usbhs_get_priv(pdev) \
  561. container_of(renesas_usbhs_get_info(pdev), \
  562. struct usbhs_private, info)
  563. #define usbhs_is_connected(priv) \
  564. (!((1 << 7) & __raw_readw(priv->usbcrcaddr)))
  565. static int usbhs1_get_id(struct platform_device *pdev)
  566. {
  567. return USBHS_GADGET;
  568. }
  569. static int usbhs1_get_vbus(struct platform_device *pdev)
  570. {
  571. return usbhs_is_connected(usbhs_get_priv(pdev));
  572. }
  573. static irqreturn_t usbhs1_interrupt(int irq, void *data)
  574. {
  575. struct platform_device *pdev = data;
  576. struct usbhs_private *priv = usbhs_get_priv(pdev);
  577. dev_dbg(&pdev->dev, "%s\n", __func__);
  578. renesas_usbhs_call_notify_hotplug(pdev);
  579. /* clear status */
  580. __raw_writew(__raw_readw(priv->usbphyaddr) | USB_PHY_INT_CLR,
  581. priv->usbphyaddr);
  582. return IRQ_HANDLED;
  583. }
  584. static int usbhs1_hardware_init(struct platform_device *pdev)
  585. {
  586. struct usbhs_private *priv = usbhs_get_priv(pdev);
  587. int ret;
  588. irq_set_irq_type(priv->irq, IRQ_TYPE_LEVEL_HIGH);
  589. /* clear interrupt status */
  590. __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
  591. ret = request_irq(priv->irq, usbhs1_interrupt, 0,
  592. dev_name(&pdev->dev), pdev);
  593. if (ret) {
  594. dev_err(&pdev->dev, "request_irq err\n");
  595. return ret;
  596. }
  597. /* enable USB phy interrupt */
  598. __raw_writew(USB_PHY_MODE | USB_PHY_INT_EN, priv->usbphyaddr);
  599. return 0;
  600. }
  601. static void usbhs1_hardware_exit(struct platform_device *pdev)
  602. {
  603. struct usbhs_private *priv = usbhs_get_priv(pdev);
  604. /* clear interrupt status */
  605. __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
  606. free_irq(priv->irq, pdev);
  607. }
  608. static void usbhs1_phy_reset(struct platform_device *pdev)
  609. {
  610. struct usbhs_private *priv = usbhs_get_priv(pdev);
  611. /* init phy */
  612. __raw_writew(0x8a0a, priv->usbcrcaddr);
  613. }
  614. static u32 usbhs1_pipe_cfg[] = {
  615. USB_ENDPOINT_XFER_CONTROL,
  616. USB_ENDPOINT_XFER_ISOC,
  617. USB_ENDPOINT_XFER_ISOC,
  618. USB_ENDPOINT_XFER_BULK,
  619. USB_ENDPOINT_XFER_BULK,
  620. USB_ENDPOINT_XFER_BULK,
  621. USB_ENDPOINT_XFER_INT,
  622. USB_ENDPOINT_XFER_INT,
  623. USB_ENDPOINT_XFER_INT,
  624. USB_ENDPOINT_XFER_BULK,
  625. USB_ENDPOINT_XFER_BULK,
  626. USB_ENDPOINT_XFER_BULK,
  627. USB_ENDPOINT_XFER_BULK,
  628. USB_ENDPOINT_XFER_BULK,
  629. USB_ENDPOINT_XFER_BULK,
  630. USB_ENDPOINT_XFER_BULK,
  631. };
  632. static struct usbhs_private usbhs1_private = {
  633. .irq = evt2irq(0x0300), /* IRQ8 */
  634. .usbphyaddr = 0xE60581E2, /* USBPHY1INTAP */
  635. .usbcrcaddr = 0xE6058130, /* USBCR4 */
  636. .info = {
  637. .platform_callback = {
  638. .hardware_init = usbhs1_hardware_init,
  639. .hardware_exit = usbhs1_hardware_exit,
  640. .phy_reset = usbhs1_phy_reset,
  641. .get_id = usbhs1_get_id,
  642. .get_vbus = usbhs1_get_vbus,
  643. },
  644. .driver_param = {
  645. .buswait_bwait = 4,
  646. .pipe_type = usbhs1_pipe_cfg,
  647. .pipe_size = ARRAY_SIZE(usbhs1_pipe_cfg),
  648. },
  649. },
  650. };
  651. static struct resource usbhs1_resources[] = {
  652. [0] = {
  653. .name = "USBHS",
  654. .start = 0xE68B0000,
  655. .end = 0xE68B00E6 - 1,
  656. .flags = IORESOURCE_MEM,
  657. },
  658. [1] = {
  659. .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
  660. .flags = IORESOURCE_IRQ,
  661. },
  662. };
  663. static struct platform_device usbhs1_device = {
  664. .name = "renesas_usbhs",
  665. .id = 1,
  666. .dev = {
  667. .platform_data = &usbhs1_private.info,
  668. },
  669. .num_resources = ARRAY_SIZE(usbhs1_resources),
  670. .resource = usbhs1_resources,
  671. };
  672. /* LED */
  673. static struct gpio_led mackerel_leds[] = {
  674. {
  675. .name = "led0",
  676. .gpio = GPIO_PORT0,
  677. .default_state = LEDS_GPIO_DEFSTATE_ON,
  678. },
  679. {
  680. .name = "led1",
  681. .gpio = GPIO_PORT1,
  682. .default_state = LEDS_GPIO_DEFSTATE_ON,
  683. },
  684. {
  685. .name = "led2",
  686. .gpio = GPIO_PORT2,
  687. .default_state = LEDS_GPIO_DEFSTATE_ON,
  688. },
  689. {
  690. .name = "led3",
  691. .gpio = GPIO_PORT159,
  692. .default_state = LEDS_GPIO_DEFSTATE_ON,
  693. }
  694. };
  695. static struct gpio_led_platform_data mackerel_leds_pdata = {
  696. .leds = mackerel_leds,
  697. .num_leds = ARRAY_SIZE(mackerel_leds),
  698. };
  699. static struct platform_device leds_device = {
  700. .name = "leds-gpio",
  701. .id = 0,
  702. .dev = {
  703. .platform_data = &mackerel_leds_pdata,
  704. },
  705. };
  706. /* FSI */
  707. #define IRQ_FSI evt2irq(0x1840)
  708. static int __fsi_set_round_rate(struct clk *clk, long rate, int enable)
  709. {
  710. int ret;
  711. if (rate <= 0)
  712. return 0;
  713. if (!enable) {
  714. clk_disable(clk);
  715. return 0;
  716. }
  717. ret = clk_set_rate(clk, clk_round_rate(clk, rate));
  718. if (ret < 0)
  719. return ret;
  720. return clk_enable(clk);
  721. }
  722. static int fsi_set_rate(struct device *dev, int is_porta, int rate, int enable)
  723. {
  724. struct clk *fsib_clk;
  725. struct clk *fdiv_clk = &sh7372_fsidivb_clk;
  726. long fsib_rate = 0;
  727. long fdiv_rate = 0;
  728. int ackmd_bpfmd;
  729. int ret;
  730. /* FSIA is slave mode. nothing to do here */
  731. if (is_porta)
  732. return 0;
  733. /* clock start */
  734. switch (rate) {
  735. case 44100:
  736. fsib_rate = rate * 256;
  737. ackmd_bpfmd = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
  738. break;
  739. case 48000:
  740. fsib_rate = 85428000; /* around 48kHz x 256 x 7 */
  741. fdiv_rate = rate * 256;
  742. ackmd_bpfmd = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
  743. break;
  744. default:
  745. pr_err("unsupported rate in FSI2 port B\n");
  746. return -EINVAL;
  747. }
  748. /* FSI B setting */
  749. fsib_clk = clk_get(dev, "ickb");
  750. if (IS_ERR(fsib_clk))
  751. return -EIO;
  752. /* fsib */
  753. ret = __fsi_set_round_rate(fsib_clk, fsib_rate, enable);
  754. if (ret < 0)
  755. goto fsi_set_rate_end;
  756. /* FSI DIV */
  757. ret = __fsi_set_round_rate(fdiv_clk, fdiv_rate, enable);
  758. if (ret < 0) {
  759. /* disable FSI B */
  760. if (enable)
  761. __fsi_set_round_rate(fsib_clk, fsib_rate, 0);
  762. goto fsi_set_rate_end;
  763. }
  764. ret = ackmd_bpfmd;
  765. fsi_set_rate_end:
  766. clk_put(fsib_clk);
  767. return ret;
  768. }
  769. static struct sh_fsi_platform_info fsi_info = {
  770. .porta_flags = SH_FSI_BRS_INV,
  771. .portb_flags = SH_FSI_BRS_INV |
  772. SH_FSI_BRM_INV |
  773. SH_FSI_LRS_INV |
  774. SH_FSI_FMT_SPDIF,
  775. .set_rate = fsi_set_rate,
  776. };
  777. static struct resource fsi_resources[] = {
  778. [0] = {
  779. .name = "FSI",
  780. .start = 0xFE3C0000,
  781. .end = 0xFE3C0400 - 1,
  782. .flags = IORESOURCE_MEM,
  783. },
  784. [1] = {
  785. .start = IRQ_FSI,
  786. .flags = IORESOURCE_IRQ,
  787. },
  788. };
  789. static struct platform_device fsi_device = {
  790. .name = "sh_fsi2",
  791. .id = -1,
  792. .num_resources = ARRAY_SIZE(fsi_resources),
  793. .resource = fsi_resources,
  794. .dev = {
  795. .platform_data = &fsi_info,
  796. },
  797. };
  798. static struct platform_device fsi_ak4643_device = {
  799. .name = "sh_fsi2_a_ak4643",
  800. };
  801. /*
  802. * The card detect pin of the top SD/MMC slot (CN7) is active low and is
  803. * connected to GPIO A22 of SH7372 (GPIO_PORT41).
  804. */
  805. static int slot_cn7_get_cd(struct platform_device *pdev)
  806. {
  807. return !gpio_get_value(GPIO_PORT41);
  808. }
  809. /* SDHI0 */
  810. static irqreturn_t mackerel_sdhi0_gpio_cd(int irq, void *arg)
  811. {
  812. struct device *dev = arg;
  813. struct sh_mobile_sdhi_info *info = dev->platform_data;
  814. struct tmio_mmc_data *pdata = info->pdata;
  815. tmio_mmc_cd_wakeup(pdata);
  816. return IRQ_HANDLED;
  817. }
  818. static struct sh_mobile_sdhi_info sdhi0_info = {
  819. .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
  820. .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
  821. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
  822. };
  823. static struct resource sdhi0_resources[] = {
  824. [0] = {
  825. .name = "SDHI0",
  826. .start = 0xe6850000,
  827. .end = 0xe68500ff,
  828. .flags = IORESOURCE_MEM,
  829. },
  830. [1] = {
  831. .start = evt2irq(0x0e00) /* SDHI0_SDHI0I0 */,
  832. .flags = IORESOURCE_IRQ,
  833. },
  834. [2] = {
  835. .start = evt2irq(0x0e20) /* SDHI0_SDHI0I1 */,
  836. .flags = IORESOURCE_IRQ,
  837. },
  838. [3] = {
  839. .start = evt2irq(0x0e40) /* SDHI0_SDHI0I2 */,
  840. .flags = IORESOURCE_IRQ,
  841. },
  842. };
  843. static struct platform_device sdhi0_device = {
  844. .name = "sh_mobile_sdhi",
  845. .num_resources = ARRAY_SIZE(sdhi0_resources),
  846. .resource = sdhi0_resources,
  847. .id = 0,
  848. .dev = {
  849. .platform_data = &sdhi0_info,
  850. },
  851. };
  852. #if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE)
  853. /* SDHI1 */
  854. static struct sh_mobile_sdhi_info sdhi1_info = {
  855. .dma_slave_tx = SHDMA_SLAVE_SDHI1_TX,
  856. .dma_slave_rx = SHDMA_SLAVE_SDHI1_RX,
  857. .tmio_ocr_mask = MMC_VDD_165_195,
  858. .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE,
  859. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
  860. MMC_CAP_NEEDS_POLL,
  861. .get_cd = slot_cn7_get_cd,
  862. };
  863. static struct resource sdhi1_resources[] = {
  864. [0] = {
  865. .name = "SDHI1",
  866. .start = 0xe6860000,
  867. .end = 0xe68600ff,
  868. .flags = IORESOURCE_MEM,
  869. },
  870. [1] = {
  871. .start = evt2irq(0x0e80), /* SDHI1_SDHI1I0 */
  872. .flags = IORESOURCE_IRQ,
  873. },
  874. [2] = {
  875. .start = evt2irq(0x0ea0), /* SDHI1_SDHI1I1 */
  876. .flags = IORESOURCE_IRQ,
  877. },
  878. [3] = {
  879. .start = evt2irq(0x0ec0), /* SDHI1_SDHI1I2 */
  880. .flags = IORESOURCE_IRQ,
  881. },
  882. };
  883. static struct platform_device sdhi1_device = {
  884. .name = "sh_mobile_sdhi",
  885. .num_resources = ARRAY_SIZE(sdhi1_resources),
  886. .resource = sdhi1_resources,
  887. .id = 1,
  888. .dev = {
  889. .platform_data = &sdhi1_info,
  890. },
  891. };
  892. #endif
  893. /*
  894. * The card detect pin of the top SD/MMC slot (CN23) is active low and is
  895. * connected to GPIO SCIFB_SCK of SH7372 (GPIO_PORT162).
  896. */
  897. static int slot_cn23_get_cd(struct platform_device *pdev)
  898. {
  899. return !gpio_get_value(GPIO_PORT162);
  900. }
  901. /* SDHI2 */
  902. static struct sh_mobile_sdhi_info sdhi2_info = {
  903. .dma_slave_tx = SHDMA_SLAVE_SDHI2_TX,
  904. .dma_slave_rx = SHDMA_SLAVE_SDHI2_RX,
  905. .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE,
  906. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
  907. MMC_CAP_NEEDS_POLL,
  908. .get_cd = slot_cn23_get_cd,
  909. };
  910. static struct resource sdhi2_resources[] = {
  911. [0] = {
  912. .name = "SDHI2",
  913. .start = 0xe6870000,
  914. .end = 0xe68700ff,
  915. .flags = IORESOURCE_MEM,
  916. },
  917. [1] = {
  918. .start = evt2irq(0x1200), /* SDHI2_SDHI2I0 */
  919. .flags = IORESOURCE_IRQ,
  920. },
  921. [2] = {
  922. .start = evt2irq(0x1220), /* SDHI2_SDHI2I1 */
  923. .flags = IORESOURCE_IRQ,
  924. },
  925. [3] = {
  926. .start = evt2irq(0x1240), /* SDHI2_SDHI2I2 */
  927. .flags = IORESOURCE_IRQ,
  928. },
  929. };
  930. static struct platform_device sdhi2_device = {
  931. .name = "sh_mobile_sdhi",
  932. .num_resources = ARRAY_SIZE(sdhi2_resources),
  933. .resource = sdhi2_resources,
  934. .id = 2,
  935. .dev = {
  936. .platform_data = &sdhi2_info,
  937. },
  938. };
  939. /* SH_MMCIF */
  940. static struct resource sh_mmcif_resources[] = {
  941. [0] = {
  942. .name = "MMCIF",
  943. .start = 0xE6BD0000,
  944. .end = 0xE6BD00FF,
  945. .flags = IORESOURCE_MEM,
  946. },
  947. [1] = {
  948. /* MMC ERR */
  949. .start = evt2irq(0x1ac0),
  950. .flags = IORESOURCE_IRQ,
  951. },
  952. [2] = {
  953. /* MMC NOR */
  954. .start = evt2irq(0x1ae0),
  955. .flags = IORESOURCE_IRQ,
  956. },
  957. };
  958. static struct sh_mmcif_dma sh_mmcif_dma = {
  959. .chan_priv_rx = {
  960. .slave_id = SHDMA_SLAVE_MMCIF_RX,
  961. },
  962. .chan_priv_tx = {
  963. .slave_id = SHDMA_SLAVE_MMCIF_TX,
  964. },
  965. };
  966. static struct sh_mmcif_plat_data sh_mmcif_plat = {
  967. .sup_pclk = 0,
  968. .ocr = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
  969. .caps = MMC_CAP_4_BIT_DATA |
  970. MMC_CAP_8_BIT_DATA |
  971. MMC_CAP_NEEDS_POLL,
  972. .get_cd = slot_cn7_get_cd,
  973. .dma = &sh_mmcif_dma,
  974. };
  975. static struct platform_device sh_mmcif_device = {
  976. .name = "sh_mmcif",
  977. .id = 0,
  978. .dev = {
  979. .dma_mask = NULL,
  980. .coherent_dma_mask = 0xffffffff,
  981. .platform_data = &sh_mmcif_plat,
  982. },
  983. .num_resources = ARRAY_SIZE(sh_mmcif_resources),
  984. .resource = sh_mmcif_resources,
  985. };
  986. static int mackerel_camera_add(struct soc_camera_link *icl, struct device *dev);
  987. static void mackerel_camera_del(struct soc_camera_link *icl);
  988. static int camera_set_capture(struct soc_camera_platform_info *info,
  989. int enable)
  990. {
  991. return 0; /* camera sensor always enabled */
  992. }
  993. static struct soc_camera_platform_info camera_info = {
  994. .format_name = "UYVY",
  995. .format_depth = 16,
  996. .format = {
  997. .code = V4L2_MBUS_FMT_UYVY8_2X8,
  998. .colorspace = V4L2_COLORSPACE_SMPTE170M,
  999. .field = V4L2_FIELD_NONE,
  1000. .width = 640,
  1001. .height = 480,
  1002. },
  1003. .bus_param = SOCAM_PCLK_SAMPLE_RISING | SOCAM_HSYNC_ACTIVE_HIGH |
  1004. SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_DATAWIDTH_8 |
  1005. SOCAM_DATA_ACTIVE_HIGH,
  1006. .set_capture = camera_set_capture,
  1007. };
  1008. static struct soc_camera_link camera_link = {
  1009. .bus_id = 0,
  1010. .add_device = mackerel_camera_add,
  1011. .del_device = mackerel_camera_del,
  1012. .module_name = "soc_camera_platform",
  1013. .priv = &camera_info,
  1014. };
  1015. static struct platform_device *camera_device;
  1016. static void mackerel_camera_release(struct device *dev)
  1017. {
  1018. soc_camera_platform_release(&camera_device);
  1019. }
  1020. static int mackerel_camera_add(struct soc_camera_link *icl,
  1021. struct device *dev)
  1022. {
  1023. return soc_camera_platform_add(icl, dev, &camera_device, &camera_link,
  1024. mackerel_camera_release, 0);
  1025. }
  1026. static void mackerel_camera_del(struct soc_camera_link *icl)
  1027. {
  1028. soc_camera_platform_del(icl, camera_device, &camera_link);
  1029. }
  1030. static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
  1031. .flags = SH_CEU_FLAG_USE_8BIT_BUS,
  1032. };
  1033. static struct resource ceu_resources[] = {
  1034. [0] = {
  1035. .name = "CEU",
  1036. .start = 0xfe910000,
  1037. .end = 0xfe91009f,
  1038. .flags = IORESOURCE_MEM,
  1039. },
  1040. [1] = {
  1041. .start = intcs_evt2irq(0x880),
  1042. .flags = IORESOURCE_IRQ,
  1043. },
  1044. [2] = {
  1045. /* place holder for contiguous memory */
  1046. },
  1047. };
  1048. static struct platform_device ceu_device = {
  1049. .name = "sh_mobile_ceu",
  1050. .id = 0, /* "ceu0" clock */
  1051. .num_resources = ARRAY_SIZE(ceu_resources),
  1052. .resource = ceu_resources,
  1053. .dev = {
  1054. .platform_data = &sh_mobile_ceu_info,
  1055. .coherent_dma_mask = 0xffffffff,
  1056. },
  1057. };
  1058. static struct platform_device mackerel_camera = {
  1059. .name = "soc-camera-pdrv",
  1060. .id = 0,
  1061. .dev = {
  1062. .platform_data = &camera_link,
  1063. },
  1064. };
  1065. static struct platform_device *mackerel_devices[] __initdata = {
  1066. &nor_flash_device,
  1067. &smc911x_device,
  1068. &lcdc_device,
  1069. &usb1_host_device,
  1070. &usbhs1_device,
  1071. &leds_device,
  1072. &fsi_device,
  1073. &fsi_ak4643_device,
  1074. &fsi_hdmi_device,
  1075. &sdhi0_device,
  1076. #if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE)
  1077. &sdhi1_device,
  1078. #endif
  1079. &sdhi2_device,
  1080. &sh_mmcif_device,
  1081. &ceu_device,
  1082. &mackerel_camera,
  1083. &hdmi_lcdc_device,
  1084. &hdmi_device,
  1085. &meram_device,
  1086. };
  1087. /* Keypad Initialization */
  1088. #define KEYPAD_BUTTON(ev_type, ev_code, act_low) \
  1089. { \
  1090. .type = ev_type, \
  1091. .code = ev_code, \
  1092. .active_low = act_low, \
  1093. }
  1094. #define KEYPAD_BUTTON_LOW(event_code) KEYPAD_BUTTON(EV_KEY, event_code, 1)
  1095. static struct tca6416_button mackerel_gpio_keys[] = {
  1096. KEYPAD_BUTTON_LOW(KEY_HOME),
  1097. KEYPAD_BUTTON_LOW(KEY_MENU),
  1098. KEYPAD_BUTTON_LOW(KEY_BACK),
  1099. KEYPAD_BUTTON_LOW(KEY_POWER),
  1100. };
  1101. static struct tca6416_keys_platform_data mackerel_tca6416_keys_info = {
  1102. .buttons = mackerel_gpio_keys,
  1103. .nbuttons = ARRAY_SIZE(mackerel_gpio_keys),
  1104. .rep = 1,
  1105. .use_polling = 0,
  1106. .pinmask = 0x000F,
  1107. };
  1108. /* I2C */
  1109. #define IRQ7 evt2irq(0x02e0)
  1110. #define IRQ9 evt2irq(0x0320)
  1111. static struct i2c_board_info i2c0_devices[] = {
  1112. {
  1113. I2C_BOARD_INFO("ak4643", 0x13),
  1114. },
  1115. /* Keypad */
  1116. {
  1117. I2C_BOARD_INFO("tca6408-keys", 0x20),
  1118. .platform_data = &mackerel_tca6416_keys_info,
  1119. .irq = IRQ9,
  1120. },
  1121. /* Touchscreen */
  1122. {
  1123. I2C_BOARD_INFO("st1232-ts", 0x55),
  1124. .irq = IRQ7,
  1125. },
  1126. };
  1127. #define IRQ21 evt2irq(0x32a0)
  1128. static struct i2c_board_info i2c1_devices[] = {
  1129. /* Accelerometer */
  1130. {
  1131. I2C_BOARD_INFO("adxl34x", 0x53),
  1132. .irq = IRQ21,
  1133. },
  1134. };
  1135. static struct map_desc mackerel_io_desc[] __initdata = {
  1136. /* create a 1:1 entity map for 0xe6xxxxxx
  1137. * used by CPGA, INTC and PFC.
  1138. */
  1139. {
  1140. .virtual = 0xe6000000,
  1141. .pfn = __phys_to_pfn(0xe6000000),
  1142. .length = 256 << 20,
  1143. .type = MT_DEVICE_NONSHARED
  1144. },
  1145. };
  1146. static void __init mackerel_map_io(void)
  1147. {
  1148. iotable_init(mackerel_io_desc, ARRAY_SIZE(mackerel_io_desc));
  1149. /* setup early devices and console here as well */
  1150. sh7372_add_early_devices();
  1151. shmobile_setup_console();
  1152. }
  1153. #define GPIO_PORT9CR 0xE6051009
  1154. #define GPIO_PORT10CR 0xE605100A
  1155. #define GPIO_PORT168CR 0xE60520A8
  1156. #define SRCR4 0xe61580bc
  1157. #define USCCR1 0xE6058144
  1158. static void __init mackerel_init(void)
  1159. {
  1160. u32 srcr4;
  1161. struct clk *clk;
  1162. int ret;
  1163. sh7372_pinmux_init();
  1164. /* enable SCIFA0 */
  1165. gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
  1166. gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
  1167. /* enable SMSC911X */
  1168. gpio_request(GPIO_FN_CS5A, NULL);
  1169. gpio_request(GPIO_FN_IRQ6_39, NULL);
  1170. /* LCDC */
  1171. gpio_request(GPIO_FN_LCDD23, NULL);
  1172. gpio_request(GPIO_FN_LCDD22, NULL);
  1173. gpio_request(GPIO_FN_LCDD21, NULL);
  1174. gpio_request(GPIO_FN_LCDD20, NULL);
  1175. gpio_request(GPIO_FN_LCDD19, NULL);
  1176. gpio_request(GPIO_FN_LCDD18, NULL);
  1177. gpio_request(GPIO_FN_LCDD17, NULL);
  1178. gpio_request(GPIO_FN_LCDD16, NULL);
  1179. gpio_request(GPIO_FN_LCDD15, NULL);
  1180. gpio_request(GPIO_FN_LCDD14, NULL);
  1181. gpio_request(GPIO_FN_LCDD13, NULL);
  1182. gpio_request(GPIO_FN_LCDD12, NULL);
  1183. gpio_request(GPIO_FN_LCDD11, NULL);
  1184. gpio_request(GPIO_FN_LCDD10, NULL);
  1185. gpio_request(GPIO_FN_LCDD9, NULL);
  1186. gpio_request(GPIO_FN_LCDD8, NULL);
  1187. gpio_request(GPIO_FN_LCDD7, NULL);
  1188. gpio_request(GPIO_FN_LCDD6, NULL);
  1189. gpio_request(GPIO_FN_LCDD5, NULL);
  1190. gpio_request(GPIO_FN_LCDD4, NULL);
  1191. gpio_request(GPIO_FN_LCDD3, NULL);
  1192. gpio_request(GPIO_FN_LCDD2, NULL);
  1193. gpio_request(GPIO_FN_LCDD1, NULL);
  1194. gpio_request(GPIO_FN_LCDD0, NULL);
  1195. gpio_request(GPIO_FN_LCDDISP, NULL);
  1196. gpio_request(GPIO_FN_LCDDCK, NULL);
  1197. gpio_request(GPIO_PORT31, NULL); /* backlight */
  1198. gpio_direction_output(GPIO_PORT31, 0); /* off by default */
  1199. gpio_request(GPIO_PORT151, NULL); /* LCDDON */
  1200. gpio_direction_output(GPIO_PORT151, 1);
  1201. /* USB enable */
  1202. gpio_request(GPIO_FN_VBUS0_1, NULL);
  1203. gpio_request(GPIO_FN_IDIN_1_18, NULL);
  1204. gpio_request(GPIO_FN_PWEN_1_115, NULL);
  1205. gpio_request(GPIO_FN_OVCN_1_114, NULL);
  1206. gpio_request(GPIO_FN_EXTLP_1, NULL);
  1207. gpio_request(GPIO_FN_OVCN2_1, NULL);
  1208. gpio_pull_down(GPIO_PORT168CR);
  1209. /* setup USB phy */
  1210. __raw_writew(0x8a0a, 0xE6058130); /* USBCR4 */
  1211. /* enable FSI2 port A (ak4643) */
  1212. gpio_request(GPIO_FN_FSIAIBT, NULL);
  1213. gpio_request(GPIO_FN_FSIAILR, NULL);
  1214. gpio_request(GPIO_FN_FSIAISLD, NULL);
  1215. gpio_request(GPIO_FN_FSIAOSLD, NULL);
  1216. gpio_request(GPIO_PORT161, NULL);
  1217. gpio_direction_output(GPIO_PORT161, 0); /* slave */
  1218. gpio_request(GPIO_PORT9, NULL);
  1219. gpio_request(GPIO_PORT10, NULL);
  1220. gpio_no_direction(GPIO_PORT9CR); /* FSIAOBT needs no direction */
  1221. gpio_no_direction(GPIO_PORT10CR); /* FSIAOLR needs no direction */
  1222. intc_set_priority(IRQ_FSI, 3); /* irq priority FSI(3) > SMSC911X(2) */
  1223. /* setup FSI2 port B (HDMI) */
  1224. gpio_request(GPIO_FN_FSIBCK, NULL);
  1225. __raw_writew(__raw_readw(USCCR1) & ~(1 << 6), USCCR1); /* use SPDIF */
  1226. /* set SPU2 clock to 119.6 MHz */
  1227. clk = clk_get(NULL, "spu_clk");
  1228. if (!IS_ERR(clk)) {
  1229. clk_set_rate(clk, clk_round_rate(clk, 119600000));
  1230. clk_put(clk);
  1231. }
  1232. /* enable Keypad */
  1233. gpio_request(GPIO_FN_IRQ9_42, NULL);
  1234. irq_set_irq_type(IRQ9, IRQ_TYPE_LEVEL_HIGH);
  1235. /* enable Touchscreen */
  1236. gpio_request(GPIO_FN_IRQ7_40, NULL);
  1237. irq_set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
  1238. /* enable Accelerometer */
  1239. gpio_request(GPIO_FN_IRQ21, NULL);
  1240. irq_set_irq_type(IRQ21, IRQ_TYPE_LEVEL_HIGH);
  1241. /* enable SDHI0 */
  1242. gpio_request(GPIO_FN_SDHICD0, NULL);
  1243. gpio_request(GPIO_FN_SDHIWP0, NULL);
  1244. gpio_request(GPIO_FN_SDHICMD0, NULL);
  1245. gpio_request(GPIO_FN_SDHICLK0, NULL);
  1246. gpio_request(GPIO_FN_SDHID0_3, NULL);
  1247. gpio_request(GPIO_FN_SDHID0_2, NULL);
  1248. gpio_request(GPIO_FN_SDHID0_1, NULL);
  1249. gpio_request(GPIO_FN_SDHID0_0, NULL);
  1250. ret = request_irq(evt2irq(0x3340), mackerel_sdhi0_gpio_cd,
  1251. IRQF_TRIGGER_FALLING, "sdhi0 cd", &sdhi0_device.dev);
  1252. if (!ret)
  1253. sdhi0_info.tmio_flags |= TMIO_MMC_HAS_COLD_CD;
  1254. else
  1255. pr_err("Cannot get IRQ #%d: %d\n", evt2irq(0x3340), ret);
  1256. #if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE)
  1257. /* enable SDHI1 */
  1258. gpio_request(GPIO_FN_SDHICMD1, NULL);
  1259. gpio_request(GPIO_FN_SDHICLK1, NULL);
  1260. gpio_request(GPIO_FN_SDHID1_3, NULL);
  1261. gpio_request(GPIO_FN_SDHID1_2, NULL);
  1262. gpio_request(GPIO_FN_SDHID1_1, NULL);
  1263. gpio_request(GPIO_FN_SDHID1_0, NULL);
  1264. #endif
  1265. /* card detect pin for MMC slot (CN7) */
  1266. gpio_request(GPIO_PORT41, NULL);
  1267. gpio_direction_input(GPIO_PORT41);
  1268. /* enable SDHI2 */
  1269. gpio_request(GPIO_FN_SDHICMD2, NULL);
  1270. gpio_request(GPIO_FN_SDHICLK2, NULL);
  1271. gpio_request(GPIO_FN_SDHID2_3, NULL);
  1272. gpio_request(GPIO_FN_SDHID2_2, NULL);
  1273. gpio_request(GPIO_FN_SDHID2_1, NULL);
  1274. gpio_request(GPIO_FN_SDHID2_0, NULL);
  1275. /* card detect pin for microSD slot (CN23) */
  1276. gpio_request(GPIO_PORT162, NULL);
  1277. gpio_direction_input(GPIO_PORT162);
  1278. /* MMCIF */
  1279. gpio_request(GPIO_FN_MMCD0_0, NULL);
  1280. gpio_request(GPIO_FN_MMCD0_1, NULL);
  1281. gpio_request(GPIO_FN_MMCD0_2, NULL);
  1282. gpio_request(GPIO_FN_MMCD0_3, NULL);
  1283. gpio_request(GPIO_FN_MMCD0_4, NULL);
  1284. gpio_request(GPIO_FN_MMCD0_5, NULL);
  1285. gpio_request(GPIO_FN_MMCD0_6, NULL);
  1286. gpio_request(GPIO_FN_MMCD0_7, NULL);
  1287. gpio_request(GPIO_FN_MMCCMD0, NULL);
  1288. gpio_request(GPIO_FN_MMCCLK0, NULL);
  1289. /* enable GPS module (GT-720F) */
  1290. gpio_request(GPIO_FN_SCIFA2_TXD1, NULL);
  1291. gpio_request(GPIO_FN_SCIFA2_RXD1, NULL);
  1292. /* CEU */
  1293. gpio_request(GPIO_FN_VIO_CLK, NULL);
  1294. gpio_request(GPIO_FN_VIO_VD, NULL);
  1295. gpio_request(GPIO_FN_VIO_HD, NULL);
  1296. gpio_request(GPIO_FN_VIO_FIELD, NULL);
  1297. gpio_request(GPIO_FN_VIO_CKO, NULL);
  1298. gpio_request(GPIO_FN_VIO_D7, NULL);
  1299. gpio_request(GPIO_FN_VIO_D6, NULL);
  1300. gpio_request(GPIO_FN_VIO_D5, NULL);
  1301. gpio_request(GPIO_FN_VIO_D4, NULL);
  1302. gpio_request(GPIO_FN_VIO_D3, NULL);
  1303. gpio_request(GPIO_FN_VIO_D2, NULL);
  1304. gpio_request(GPIO_FN_VIO_D1, NULL);
  1305. gpio_request(GPIO_FN_VIO_D0, NULL);
  1306. /* HDMI */
  1307. gpio_request(GPIO_FN_HDMI_HPD, NULL);
  1308. gpio_request(GPIO_FN_HDMI_CEC, NULL);
  1309. /* Reset HDMI, must be held at least one EXTALR (32768Hz) period */
  1310. srcr4 = __raw_readl(SRCR4);
  1311. __raw_writel(srcr4 | (1 << 13), SRCR4);
  1312. udelay(50);
  1313. __raw_writel(srcr4 & ~(1 << 13), SRCR4);
  1314. i2c_register_board_info(0, i2c0_devices,
  1315. ARRAY_SIZE(i2c0_devices));
  1316. i2c_register_board_info(1, i2c1_devices,
  1317. ARRAY_SIZE(i2c1_devices));
  1318. sh7372_add_standard_devices();
  1319. platform_add_devices(mackerel_devices, ARRAY_SIZE(mackerel_devices));
  1320. hdmi_init_pm_clock();
  1321. sh7372_pm_init();
  1322. }
  1323. static void __init mackerel_timer_init(void)
  1324. {
  1325. sh7372_clock_init();
  1326. shmobile_timer.init();
  1327. /* External clock source */
  1328. clk_set_rate(&sh7372_dv_clki_clk, 27000000);
  1329. }
  1330. static struct sys_timer mackerel_timer = {
  1331. .init = mackerel_timer_init,
  1332. };
  1333. MACHINE_START(MACKEREL, "mackerel")
  1334. .map_io = mackerel_map_io,
  1335. .init_irq = sh7372_init_irq,
  1336. .handle_irq = shmobile_handle_irq_intc,
  1337. .init_machine = mackerel_init,
  1338. .timer = &mackerel_timer,
  1339. MACHINE_END