board-mackerel.c 39 KB

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