board-mackerel.c 37 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/mtd/sh_flctl.h>
  43. #include <linux/pinctrl/machine.h>
  44. #include <linux/platform_data/gpio_backlight.h>
  45. #include <linux/pm_clock.h>
  46. #include <linux/regulator/fixed.h>
  47. #include <linux/regulator/machine.h>
  48. #include <linux/smsc911x.h>
  49. #include <linux/sh_intc.h>
  50. #include <linux/tca6416_keypad.h>
  51. #include <linux/usb/renesas_usbhs.h>
  52. #include <linux/dma-mapping.h>
  53. #include <video/sh_mobile_hdmi.h>
  54. #include <video/sh_mobile_lcdc.h>
  55. #include <media/sh_mobile_ceu.h>
  56. #include <media/soc_camera.h>
  57. #include <media/soc_camera_platform.h>
  58. #include <sound/sh_fsi.h>
  59. #include <sound/simple_card.h>
  60. #include <mach/common.h>
  61. #include <mach/irqs.h>
  62. #include <mach/sh7372.h>
  63. #include <asm/mach/arch.h>
  64. #include <asm/mach-types.h>
  65. #include "sh-gpio.h"
  66. /*
  67. * Address Interface BusWidth note
  68. * ------------------------------------------------------------------
  69. * 0x0000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = ON
  70. * 0x0800_0000 user area -
  71. * 0x1000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = OFF
  72. * 0x1400_0000 Ether (LAN9220) 16bit
  73. * 0x1600_0000 user area - cannot use with NAND
  74. * 0x1800_0000 user area -
  75. * 0x1A00_0000 -
  76. * 0x4000_0000 LPDDR2-SDRAM (POP) 32bit
  77. */
  78. /*
  79. * CPU mode
  80. *
  81. * SW4 | Boot Area| Master | Remarks
  82. * 1 | 2 | 3 | 4 | 5 | 6 | 8 | | Processor|
  83. * ----+-----+-----+-----+-----+-----+-----+----------+----------+--------------
  84. * ON | ON | OFF | ON | ON | OFF | OFF | External | System | External ROM
  85. * ON | ON | ON | ON | ON | OFF | OFF | External | System | ROM Debug
  86. * ON | ON | X | ON | OFF | OFF | OFF | Built-in | System | ROM Debug
  87. * X | OFF | X | X | X | X | OFF | Built-in | System | MaskROM
  88. * OFF | X | X | X | X | X | OFF | Built-in | System | MaskROM
  89. * X | X | X | OFF | X | X | OFF | Built-in | System | MaskROM
  90. * OFF | ON | OFF | X | X | OFF | ON | External | System | Standalone
  91. * ON | OFF | OFF | X | X | OFF | ON | External | Realtime | Standalone
  92. */
  93. /*
  94. * NOR Flash ROM
  95. *
  96. * SW1 | SW2 | SW7 | NOR Flash ROM
  97. * bit1 | bit1 bit2 | bit1 | Memory allocation
  98. * ------+------------+------+------------------
  99. * OFF | ON OFF | ON | Area 0
  100. * OFF | ON OFF | OFF | Area 4
  101. */
  102. /*
  103. * SMSC 9220
  104. *
  105. * SW1 SMSC 9220
  106. * -----------------------
  107. * ON access disable
  108. * OFF access enable
  109. */
  110. /*
  111. * NAND Flash ROM
  112. *
  113. * SW1 | SW2 | SW7 | NAND Flash ROM
  114. * bit1 | bit1 bit2 | bit2 | Memory allocation
  115. * ------+------------+------+------------------
  116. * OFF | ON OFF | ON | FCE 0
  117. * OFF | ON OFF | OFF | FCE 1
  118. */
  119. /*
  120. * External interrupt pin settings
  121. *
  122. * IRQX | pin setting | device | level
  123. * ------+--------------------+--------------------+-------
  124. * IRQ0 | ICR1A.IRQ0SA=0010 | SDHI2 card detect | Low
  125. * IRQ6 | ICR1A.IRQ6SA=0011 | Ether(LAN9220) | High
  126. * IRQ7 | ICR1A.IRQ7SA=0010 | LCD Touch Panel | Low
  127. * IRQ8 | ICR2A.IRQ8SA=0010 | MMC/SD card detect | Low
  128. * IRQ9 | ICR2A.IRQ9SA=0010 | KEY(TCA6408) | Low
  129. * IRQ21 | ICR4A.IRQ21SA=0011 | Sensor(ADXL345) | High
  130. * IRQ22 | ICR4A.IRQ22SA=0011 | Sensor(AK8975) | High
  131. */
  132. /*
  133. * USB
  134. *
  135. * USB0 : CN22 : Function
  136. * USB1 : CN31 : Function/Host *1
  137. *
  138. * J30 (for CN31) *1
  139. * ----------+---------------+-------------
  140. * 1-2 short | VBUS 5V | Host
  141. * open | external VBUS | 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. /*
  156. * SDHI0 (CN12)
  157. *
  158. * SW56 : OFF
  159. *
  160. */
  161. /* MMC /SDHI1 (CN7)
  162. *
  163. * I/O voltage : 1.8v
  164. *
  165. * Power voltage : 1.8v or 3.3v
  166. * J22 : select power voltage *1
  167. * 1-2 pin : 1.8v
  168. * 2-3 pin : 3.3v
  169. *
  170. * *1
  171. * Please change J22 depends the card to be used.
  172. * MMC's OCR field set to support either voltage for the card inserted.
  173. *
  174. * SW1 | SW33
  175. * | bit1 | bit2 | bit3 | bit4
  176. * -------------+------+------+------+-------
  177. * MMC0 OFF | OFF | X | ON | X (Use MMCIF)
  178. * SDHI1 OFF | ON | X | OFF | X (Use MFD_SH_MOBILE_SDHI)
  179. *
  180. */
  181. /*
  182. * SDHI2 (CN23)
  183. *
  184. * microSD card sloct
  185. *
  186. */
  187. /*
  188. * FSI - AK4642
  189. *
  190. * it needs amixer settings for playing
  191. *
  192. * amixer set "Headphone Enable" on
  193. */
  194. /* Fixed 3.3V and 1.8V regulators to be used by multiple devices */
  195. static struct regulator_consumer_supply fixed1v8_power_consumers[] =
  196. {
  197. /*
  198. * J22 on mackerel switches mmcif.0 and sdhi.1 between 1.8V and 3.3V
  199. * Since we cannot support both voltages, we support the default 1.8V
  200. */
  201. REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.1"),
  202. REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.1"),
  203. REGULATOR_SUPPLY("vmmc", "sh_mmcif.0"),
  204. REGULATOR_SUPPLY("vqmmc", "sh_mmcif.0"),
  205. };
  206. static struct regulator_consumer_supply fixed3v3_power_consumers[] =
  207. {
  208. REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
  209. REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
  210. REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.2"),
  211. REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.2"),
  212. };
  213. /* Dummy supplies, where voltage doesn't matter */
  214. static struct regulator_consumer_supply dummy_supplies[] = {
  215. REGULATOR_SUPPLY("vddvario", "smsc911x"),
  216. REGULATOR_SUPPLY("vdd33a", "smsc911x"),
  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 = "regs",
  301. .start = 0xe8000000,
  302. .end = 0xe807ffff,
  303. .flags = IORESOURCE_MEM,
  304. },
  305. [1] = {
  306. .name = "meram",
  307. .start = 0xe8080000,
  308. .end = 0xe81fffff,
  309. .flags = IORESOURCE_MEM,
  310. },
  311. };
  312. static struct platform_device meram_device = {
  313. .name = "sh_mobile_meram",
  314. .id = 0,
  315. .num_resources = ARRAY_SIZE(meram_resources),
  316. .resource = meram_resources,
  317. .dev = {
  318. .platform_data = &mackerel_meram_info,
  319. },
  320. };
  321. /* LCDC and backlight */
  322. static struct fb_videomode mackerel_lcdc_modes[] = {
  323. {
  324. .name = "WVGA Panel",
  325. .xres = 800,
  326. .yres = 480,
  327. .left_margin = 220,
  328. .right_margin = 110,
  329. .hsync_len = 70,
  330. .upper_margin = 20,
  331. .lower_margin = 5,
  332. .vsync_len = 5,
  333. .sync = 0,
  334. },
  335. };
  336. static const struct sh_mobile_meram_cfg lcd_meram_cfg = {
  337. .icb[0] = {
  338. .meram_size = 0x40,
  339. },
  340. .icb[1] = {
  341. .meram_size = 0x40,
  342. },
  343. };
  344. static struct sh_mobile_lcdc_info lcdc_info = {
  345. .meram_dev = &mackerel_meram_info,
  346. .clock_source = LCDC_CLK_BUS,
  347. .ch[0] = {
  348. .chan = LCDC_CHAN_MAINLCD,
  349. .fourcc = V4L2_PIX_FMT_RGB565,
  350. .lcd_modes = mackerel_lcdc_modes,
  351. .num_modes = ARRAY_SIZE(mackerel_lcdc_modes),
  352. .interface_type = RGB24,
  353. .clock_divider = 3,
  354. .flags = 0,
  355. .panel_cfg = {
  356. .width = 152,
  357. .height = 91,
  358. },
  359. .meram_cfg = &lcd_meram_cfg,
  360. }
  361. };
  362. static struct resource lcdc_resources[] = {
  363. [0] = {
  364. .name = "LCDC",
  365. .start = 0xfe940000,
  366. .end = 0xfe943fff,
  367. .flags = IORESOURCE_MEM,
  368. },
  369. [1] = {
  370. .start = intcs_evt2irq(0x580),
  371. .flags = IORESOURCE_IRQ,
  372. },
  373. };
  374. static struct platform_device lcdc_device = {
  375. .name = "sh_mobile_lcdc_fb",
  376. .num_resources = ARRAY_SIZE(lcdc_resources),
  377. .resource = lcdc_resources,
  378. .dev = {
  379. .platform_data = &lcdc_info,
  380. .coherent_dma_mask = ~0,
  381. },
  382. };
  383. static struct gpio_backlight_platform_data gpio_backlight_data = {
  384. .fbdev = &lcdc_device.dev,
  385. .gpio = 31,
  386. .def_value = 1,
  387. .name = "backlight",
  388. };
  389. static struct platform_device gpio_backlight_device = {
  390. .name = "gpio-backlight",
  391. .dev = {
  392. .platform_data = &gpio_backlight_data,
  393. },
  394. };
  395. /* HDMI */
  396. static struct sh_mobile_hdmi_info hdmi_info = {
  397. .flags = HDMI_SND_SRC_SPDIF,
  398. };
  399. static struct resource hdmi_resources[] = {
  400. [0] = {
  401. .name = "HDMI",
  402. .start = 0xe6be0000,
  403. .end = 0xe6be00ff,
  404. .flags = IORESOURCE_MEM,
  405. },
  406. [1] = {
  407. /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
  408. .start = evt2irq(0x17e0),
  409. .flags = IORESOURCE_IRQ,
  410. },
  411. };
  412. static struct platform_device hdmi_device = {
  413. .name = "sh-mobile-hdmi",
  414. .num_resources = ARRAY_SIZE(hdmi_resources),
  415. .resource = hdmi_resources,
  416. .id = -1,
  417. .dev = {
  418. .platform_data = &hdmi_info,
  419. },
  420. };
  421. static const struct sh_mobile_meram_cfg hdmi_meram_cfg = {
  422. .icb[0] = {
  423. .meram_size = 0x100,
  424. },
  425. .icb[1] = {
  426. .meram_size = 0x100,
  427. },
  428. };
  429. static struct sh_mobile_lcdc_info hdmi_lcdc_info = {
  430. .meram_dev = &mackerel_meram_info,
  431. .clock_source = LCDC_CLK_EXTERNAL,
  432. .ch[0] = {
  433. .chan = LCDC_CHAN_MAINLCD,
  434. .fourcc = V4L2_PIX_FMT_RGB565,
  435. .interface_type = RGB24,
  436. .clock_divider = 1,
  437. .flags = LCDC_FLAGS_DWPOL,
  438. .meram_cfg = &hdmi_meram_cfg,
  439. .tx_dev = &hdmi_device,
  440. }
  441. };
  442. static struct resource hdmi_lcdc_resources[] = {
  443. [0] = {
  444. .name = "LCDC1",
  445. .start = 0xfe944000,
  446. .end = 0xfe947fff,
  447. .flags = IORESOURCE_MEM,
  448. },
  449. [1] = {
  450. .start = intcs_evt2irq(0x1780),
  451. .flags = IORESOURCE_IRQ,
  452. },
  453. };
  454. static struct platform_device hdmi_lcdc_device = {
  455. .name = "sh_mobile_lcdc_fb",
  456. .num_resources = ARRAY_SIZE(hdmi_lcdc_resources),
  457. .resource = hdmi_lcdc_resources,
  458. .id = 1,
  459. .dev = {
  460. .platform_data = &hdmi_lcdc_info,
  461. .coherent_dma_mask = ~0,
  462. },
  463. };
  464. static struct asoc_simple_card_info fsi2_hdmi_info = {
  465. .name = "HDMI",
  466. .card = "FSI2B-HDMI",
  467. .codec = "sh-mobile-hdmi",
  468. .platform = "sh_fsi2",
  469. .cpu_dai = {
  470. .name = "fsib-dai",
  471. .fmt = SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF,
  472. },
  473. .codec_dai = {
  474. .name = "sh_mobile_hdmi-hifi",
  475. },
  476. };
  477. static struct platform_device fsi_hdmi_device = {
  478. .name = "asoc-simple-card",
  479. .id = 1,
  480. .dev = {
  481. .platform_data = &fsi2_hdmi_info,
  482. },
  483. };
  484. static void __init hdmi_init_pm_clock(void)
  485. {
  486. struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
  487. int ret;
  488. long rate;
  489. if (IS_ERR(hdmi_ick)) {
  490. ret = PTR_ERR(hdmi_ick);
  491. pr_err("Cannot get HDMI ICK: %d\n", ret);
  492. goto out;
  493. }
  494. ret = clk_set_parent(&sh7372_pllc2_clk, &sh7372_dv_clki_div2_clk);
  495. if (ret < 0) {
  496. pr_err("Cannot set PLLC2 parent: %d, %d users\n",
  497. ret, sh7372_pllc2_clk.usecount);
  498. goto out;
  499. }
  500. pr_debug("PLLC2 initial frequency %lu\n",
  501. clk_get_rate(&sh7372_pllc2_clk));
  502. rate = clk_round_rate(&sh7372_pllc2_clk, 594000000);
  503. if (rate < 0) {
  504. pr_err("Cannot get suitable rate: %ld\n", rate);
  505. ret = rate;
  506. goto out;
  507. }
  508. ret = clk_set_rate(&sh7372_pllc2_clk, rate);
  509. if (ret < 0) {
  510. pr_err("Cannot set rate %ld: %d\n", rate, ret);
  511. goto out;
  512. }
  513. pr_debug("PLLC2 set frequency %lu\n", rate);
  514. ret = clk_set_parent(hdmi_ick, &sh7372_pllc2_clk);
  515. if (ret < 0)
  516. pr_err("Cannot set HDMI parent: %d\n", ret);
  517. out:
  518. if (!IS_ERR(hdmi_ick))
  519. clk_put(hdmi_ick);
  520. }
  521. /* USBHS0 is connected to CN22 which takes a USB Mini-B plug
  522. *
  523. * The sh7372 SoC has IRQ7 set aside for USBHS0 hotplug,
  524. * but on this particular board IRQ7 is already used by
  525. * the touch screen. This leaves us with software polling.
  526. */
  527. #define USBHS0_POLL_INTERVAL (HZ * 5)
  528. struct usbhs_private {
  529. void __iomem *usbphyaddr;
  530. void __iomem *usbcrcaddr;
  531. struct renesas_usbhs_platform_info info;
  532. struct delayed_work work;
  533. struct platform_device *pdev;
  534. };
  535. #define usbhs_get_priv(pdev) \
  536. container_of(renesas_usbhs_get_info(pdev), \
  537. struct usbhs_private, info)
  538. #define usbhs_is_connected(priv) \
  539. (!((1 << 7) & __raw_readw(priv->usbcrcaddr)))
  540. static int usbhs_get_vbus(struct platform_device *pdev)
  541. {
  542. return usbhs_is_connected(usbhs_get_priv(pdev));
  543. }
  544. static int usbhs_phy_reset(struct platform_device *pdev)
  545. {
  546. struct usbhs_private *priv = usbhs_get_priv(pdev);
  547. /* init phy */
  548. __raw_writew(0x8a0a, priv->usbcrcaddr);
  549. return 0;
  550. }
  551. static int usbhs0_get_id(struct platform_device *pdev)
  552. {
  553. return USBHS_GADGET;
  554. }
  555. static void usbhs0_work_function(struct work_struct *work)
  556. {
  557. struct usbhs_private *priv = container_of(work, struct usbhs_private,
  558. work.work);
  559. renesas_usbhs_call_notify_hotplug(priv->pdev);
  560. schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
  561. }
  562. static int usbhs0_hardware_init(struct platform_device *pdev)
  563. {
  564. struct usbhs_private *priv = usbhs_get_priv(pdev);
  565. priv->pdev = pdev;
  566. INIT_DELAYED_WORK(&priv->work, usbhs0_work_function);
  567. schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
  568. return 0;
  569. }
  570. static int usbhs0_hardware_exit(struct platform_device *pdev)
  571. {
  572. struct usbhs_private *priv = usbhs_get_priv(pdev);
  573. cancel_delayed_work_sync(&priv->work);
  574. return 0;
  575. }
  576. static struct usbhs_private usbhs0_private = {
  577. .usbcrcaddr = IOMEM(0xe605810c), /* USBCR2 */
  578. .info = {
  579. .platform_callback = {
  580. .hardware_init = usbhs0_hardware_init,
  581. .hardware_exit = usbhs0_hardware_exit,
  582. .phy_reset = usbhs_phy_reset,
  583. .get_id = usbhs0_get_id,
  584. .get_vbus = usbhs_get_vbus,
  585. },
  586. .driver_param = {
  587. .buswait_bwait = 4,
  588. .d0_tx_id = SHDMA_SLAVE_USB0_TX,
  589. .d1_rx_id = SHDMA_SLAVE_USB0_RX,
  590. },
  591. },
  592. };
  593. static struct resource usbhs0_resources[] = {
  594. [0] = {
  595. .name = "USBHS0",
  596. .start = 0xe6890000,
  597. .end = 0xe68900e6 - 1,
  598. .flags = IORESOURCE_MEM,
  599. },
  600. [1] = {
  601. .start = evt2irq(0x1ca0) /* USB0_USB0I0 */,
  602. .flags = IORESOURCE_IRQ,
  603. },
  604. };
  605. static struct platform_device usbhs0_device = {
  606. .name = "renesas_usbhs",
  607. .id = 0,
  608. .dev = {
  609. .platform_data = &usbhs0_private.info,
  610. },
  611. .num_resources = ARRAY_SIZE(usbhs0_resources),
  612. .resource = usbhs0_resources,
  613. };
  614. /* USBHS1 is connected to CN31 which takes a USB Mini-AB plug
  615. *
  616. * Use J30 to select between Host and Function. This setting
  617. * can however not be detected by software. Hotplug of USBHS1
  618. * is provided via IRQ8.
  619. *
  620. * Current USB1 works as "USB Host".
  621. * - set J30 "short"
  622. *
  623. * If you want to use it as "USB gadget",
  624. * - J30 "open"
  625. * - modify usbhs1_get_id() USBHS_HOST -> USBHS_GADGET
  626. * - add .get_vbus = usbhs_get_vbus in usbhs1_private
  627. * - check usbhs0_device(pio)/usbhs1_device(irq) order in mackerel_devices.
  628. */
  629. #define IRQ8 evt2irq(0x0300)
  630. #define USB_PHY_MODE (1 << 4)
  631. #define USB_PHY_INT_EN ((1 << 3) | (1 << 2))
  632. #define USB_PHY_ON (1 << 1)
  633. #define USB_PHY_OFF (1 << 0)
  634. #define USB_PHY_INT_CLR (USB_PHY_ON | USB_PHY_OFF)
  635. static irqreturn_t usbhs1_interrupt(int irq, void *data)
  636. {
  637. struct platform_device *pdev = data;
  638. struct usbhs_private *priv = usbhs_get_priv(pdev);
  639. dev_dbg(&pdev->dev, "%s\n", __func__);
  640. renesas_usbhs_call_notify_hotplug(pdev);
  641. /* clear status */
  642. __raw_writew(__raw_readw(priv->usbphyaddr) | USB_PHY_INT_CLR,
  643. priv->usbphyaddr);
  644. return IRQ_HANDLED;
  645. }
  646. static int usbhs1_hardware_init(struct platform_device *pdev)
  647. {
  648. struct usbhs_private *priv = usbhs_get_priv(pdev);
  649. int ret;
  650. /* clear interrupt status */
  651. __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
  652. ret = request_irq(IRQ8, usbhs1_interrupt, IRQF_TRIGGER_HIGH,
  653. dev_name(&pdev->dev), pdev);
  654. if (ret) {
  655. dev_err(&pdev->dev, "request_irq err\n");
  656. return ret;
  657. }
  658. /* enable USB phy interrupt */
  659. __raw_writew(USB_PHY_MODE | USB_PHY_INT_EN, priv->usbphyaddr);
  660. return 0;
  661. }
  662. static int usbhs1_hardware_exit(struct platform_device *pdev)
  663. {
  664. struct usbhs_private *priv = usbhs_get_priv(pdev);
  665. /* clear interrupt status */
  666. __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
  667. free_irq(IRQ8, pdev);
  668. return 0;
  669. }
  670. static int usbhs1_get_id(struct platform_device *pdev)
  671. {
  672. return USBHS_HOST;
  673. }
  674. static u32 usbhs1_pipe_cfg[] = {
  675. USB_ENDPOINT_XFER_CONTROL,
  676. USB_ENDPOINT_XFER_ISOC,
  677. USB_ENDPOINT_XFER_ISOC,
  678. USB_ENDPOINT_XFER_BULK,
  679. USB_ENDPOINT_XFER_BULK,
  680. USB_ENDPOINT_XFER_BULK,
  681. USB_ENDPOINT_XFER_INT,
  682. USB_ENDPOINT_XFER_INT,
  683. USB_ENDPOINT_XFER_INT,
  684. USB_ENDPOINT_XFER_BULK,
  685. USB_ENDPOINT_XFER_BULK,
  686. USB_ENDPOINT_XFER_BULK,
  687. USB_ENDPOINT_XFER_BULK,
  688. USB_ENDPOINT_XFER_BULK,
  689. USB_ENDPOINT_XFER_BULK,
  690. USB_ENDPOINT_XFER_BULK,
  691. };
  692. static struct usbhs_private usbhs1_private = {
  693. .usbphyaddr = IOMEM(0xe60581e2), /* USBPHY1INTAP */
  694. .usbcrcaddr = IOMEM(0xe6058130), /* USBCR4 */
  695. .info = {
  696. .platform_callback = {
  697. .hardware_init = usbhs1_hardware_init,
  698. .hardware_exit = usbhs1_hardware_exit,
  699. .get_id = usbhs1_get_id,
  700. .phy_reset = usbhs_phy_reset,
  701. },
  702. .driver_param = {
  703. .buswait_bwait = 4,
  704. .has_otg = 1,
  705. .pipe_type = usbhs1_pipe_cfg,
  706. .pipe_size = ARRAY_SIZE(usbhs1_pipe_cfg),
  707. .d0_tx_id = SHDMA_SLAVE_USB1_TX,
  708. .d1_rx_id = SHDMA_SLAVE_USB1_RX,
  709. },
  710. },
  711. };
  712. static struct resource usbhs1_resources[] = {
  713. [0] = {
  714. .name = "USBHS1",
  715. .start = 0xe68b0000,
  716. .end = 0xe68b00e6 - 1,
  717. .flags = IORESOURCE_MEM,
  718. },
  719. [1] = {
  720. .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
  721. .flags = IORESOURCE_IRQ,
  722. },
  723. };
  724. static struct platform_device usbhs1_device = {
  725. .name = "renesas_usbhs",
  726. .id = 1,
  727. .dev = {
  728. .platform_data = &usbhs1_private.info,
  729. .dma_mask = &usbhs1_device.dev.coherent_dma_mask,
  730. .coherent_dma_mask = DMA_BIT_MASK(32),
  731. },
  732. .num_resources = ARRAY_SIZE(usbhs1_resources),
  733. .resource = usbhs1_resources,
  734. };
  735. /* LED */
  736. static struct gpio_led mackerel_leds[] = {
  737. {
  738. .name = "led0",
  739. .gpio = 0,
  740. .default_state = LEDS_GPIO_DEFSTATE_ON,
  741. },
  742. {
  743. .name = "led1",
  744. .gpio = 1,
  745. .default_state = LEDS_GPIO_DEFSTATE_ON,
  746. },
  747. {
  748. .name = "led2",
  749. .gpio = 2,
  750. .default_state = LEDS_GPIO_DEFSTATE_ON,
  751. },
  752. {
  753. .name = "led3",
  754. .gpio = 159,
  755. .default_state = LEDS_GPIO_DEFSTATE_ON,
  756. }
  757. };
  758. static struct gpio_led_platform_data mackerel_leds_pdata = {
  759. .leds = mackerel_leds,
  760. .num_leds = ARRAY_SIZE(mackerel_leds),
  761. };
  762. static struct platform_device leds_device = {
  763. .name = "leds-gpio",
  764. .id = 0,
  765. .dev = {
  766. .platform_data = &mackerel_leds_pdata,
  767. },
  768. };
  769. /* FSI */
  770. #define IRQ_FSI evt2irq(0x1840)
  771. static struct sh_fsi_platform_info fsi_info = {
  772. .port_a = {
  773. .tx_id = SHDMA_SLAVE_FSIA_TX,
  774. .rx_id = SHDMA_SLAVE_FSIA_RX,
  775. },
  776. .port_b = {
  777. .flags = SH_FSI_CLK_CPG |
  778. SH_FSI_FMT_SPDIF,
  779. }
  780. };
  781. static struct resource fsi_resources[] = {
  782. [0] = {
  783. /* we need 0xFE1F0000 to access DMA
  784. * instead of 0xFE3C0000 */
  785. .name = "FSI",
  786. .start = 0xFE1F0000,
  787. .end = 0xFE1F0400 - 1,
  788. .flags = IORESOURCE_MEM,
  789. },
  790. [1] = {
  791. .start = IRQ_FSI,
  792. .flags = IORESOURCE_IRQ,
  793. },
  794. };
  795. static struct platform_device fsi_device = {
  796. .name = "sh_fsi2",
  797. .id = -1,
  798. .num_resources = ARRAY_SIZE(fsi_resources),
  799. .resource = fsi_resources,
  800. .dev = {
  801. .platform_data = &fsi_info,
  802. },
  803. };
  804. static struct asoc_simple_card_info fsi2_ak4643_info = {
  805. .name = "AK4643",
  806. .card = "FSI2A-AK4643",
  807. .codec = "ak4642-codec.0-0013",
  808. .platform = "sh_fsi2",
  809. .daifmt = SND_SOC_DAIFMT_LEFT_J,
  810. .cpu_dai = {
  811. .name = "fsia-dai",
  812. .fmt = SND_SOC_DAIFMT_CBS_CFS,
  813. },
  814. .codec_dai = {
  815. .name = "ak4642-hifi",
  816. .fmt = SND_SOC_DAIFMT_CBM_CFM,
  817. .sysclk = 11289600,
  818. },
  819. };
  820. static struct platform_device fsi_ak4643_device = {
  821. .name = "asoc-simple-card",
  822. .dev = {
  823. .platform_data = &fsi2_ak4643_info,
  824. },
  825. };
  826. /* FLCTL */
  827. static struct mtd_partition nand_partition_info[] = {
  828. {
  829. .name = "system",
  830. .offset = 0,
  831. .size = 128 * 1024 * 1024,
  832. },
  833. {
  834. .name = "userdata",
  835. .offset = MTDPART_OFS_APPEND,
  836. .size = 256 * 1024 * 1024,
  837. },
  838. {
  839. .name = "cache",
  840. .offset = MTDPART_OFS_APPEND,
  841. .size = 128 * 1024 * 1024,
  842. },
  843. };
  844. static struct resource nand_flash_resources[] = {
  845. [0] = {
  846. .start = 0xe6a30000,
  847. .end = 0xe6a3009b,
  848. .flags = IORESOURCE_MEM,
  849. },
  850. [1] = {
  851. .start = evt2irq(0x0d80), /* flstei: status error irq */
  852. .flags = IORESOURCE_IRQ,
  853. },
  854. };
  855. static struct sh_flctl_platform_data nand_flash_data = {
  856. .parts = nand_partition_info,
  857. .nr_parts = ARRAY_SIZE(nand_partition_info),
  858. .flcmncr_val = CLK_16B_12L_4H | TYPESEL_SET
  859. | SHBUSSEL | SEL_16BIT | SNAND_E,
  860. .use_holden = 1,
  861. };
  862. static struct platform_device nand_flash_device = {
  863. .name = "sh_flctl",
  864. .resource = nand_flash_resources,
  865. .num_resources = ARRAY_SIZE(nand_flash_resources),
  866. .dev = {
  867. .platform_data = &nand_flash_data,
  868. },
  869. };
  870. /* SDHI0 */
  871. static struct sh_mobile_sdhi_info sdhi0_info = {
  872. .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
  873. .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
  874. .tmio_flags = TMIO_MMC_USE_GPIO_CD,
  875. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
  876. .cd_gpio = 172,
  877. };
  878. static struct resource sdhi0_resources[] = {
  879. {
  880. .name = "SDHI0",
  881. .start = 0xe6850000,
  882. .end = 0xe68500ff,
  883. .flags = IORESOURCE_MEM,
  884. }, {
  885. .name = SH_MOBILE_SDHI_IRQ_SDCARD,
  886. .start = evt2irq(0x0e20) /* SDHI0_SDHI0I1 */,
  887. .flags = IORESOURCE_IRQ,
  888. }, {
  889. .name = SH_MOBILE_SDHI_IRQ_SDIO,
  890. .start = evt2irq(0x0e40) /* SDHI0_SDHI0I2 */,
  891. .flags = IORESOURCE_IRQ,
  892. },
  893. };
  894. static struct platform_device sdhi0_device = {
  895. .name = "sh_mobile_sdhi",
  896. .num_resources = ARRAY_SIZE(sdhi0_resources),
  897. .resource = sdhi0_resources,
  898. .id = 0,
  899. .dev = {
  900. .platform_data = &sdhi0_info,
  901. },
  902. };
  903. #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
  904. /* SDHI1 */
  905. /* GPIO 41 can trigger IRQ8, but it is used by USBHS1, we have to poll */
  906. static struct sh_mobile_sdhi_info sdhi1_info = {
  907. .dma_slave_tx = SHDMA_SLAVE_SDHI1_TX,
  908. .dma_slave_rx = SHDMA_SLAVE_SDHI1_RX,
  909. .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_USE_GPIO_CD,
  910. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
  911. MMC_CAP_NEEDS_POLL,
  912. .cd_gpio = 41,
  913. };
  914. static struct resource sdhi1_resources[] = {
  915. {
  916. .name = "SDHI1",
  917. .start = 0xe6860000,
  918. .end = 0xe68600ff,
  919. .flags = IORESOURCE_MEM,
  920. }, {
  921. .name = SH_MOBILE_SDHI_IRQ_SDCARD,
  922. .start = evt2irq(0x0ea0), /* SDHI1_SDHI1I1 */
  923. .flags = IORESOURCE_IRQ,
  924. }, {
  925. .name = SH_MOBILE_SDHI_IRQ_SDIO,
  926. .start = evt2irq(0x0ec0), /* SDHI1_SDHI1I2 */
  927. .flags = IORESOURCE_IRQ,
  928. },
  929. };
  930. static struct platform_device sdhi1_device = {
  931. .name = "sh_mobile_sdhi",
  932. .num_resources = ARRAY_SIZE(sdhi1_resources),
  933. .resource = sdhi1_resources,
  934. .id = 1,
  935. .dev = {
  936. .platform_data = &sdhi1_info,
  937. },
  938. };
  939. #endif
  940. /* SDHI2 */
  941. /*
  942. * The card detect pin of the top SD/MMC slot (CN23) is active low and is
  943. * connected to GPIO SCIFB_SCK of SH7372 (GPIO 162).
  944. */
  945. static struct sh_mobile_sdhi_info sdhi2_info = {
  946. .dma_slave_tx = SHDMA_SLAVE_SDHI2_TX,
  947. .dma_slave_rx = SHDMA_SLAVE_SDHI2_RX,
  948. .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_USE_GPIO_CD,
  949. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
  950. MMC_CAP_NEEDS_POLL,
  951. .cd_gpio = 162,
  952. };
  953. static struct resource sdhi2_resources[] = {
  954. {
  955. .name = "SDHI2",
  956. .start = 0xe6870000,
  957. .end = 0xe68700ff,
  958. .flags = IORESOURCE_MEM,
  959. }, {
  960. .name = SH_MOBILE_SDHI_IRQ_SDCARD,
  961. .start = evt2irq(0x1220), /* SDHI2_SDHI2I1 */
  962. .flags = IORESOURCE_IRQ,
  963. }, {
  964. .name = SH_MOBILE_SDHI_IRQ_SDIO,
  965. .start = evt2irq(0x1240), /* SDHI2_SDHI2I2 */
  966. .flags = IORESOURCE_IRQ,
  967. },
  968. };
  969. static struct platform_device sdhi2_device = {
  970. .name = "sh_mobile_sdhi",
  971. .num_resources = ARRAY_SIZE(sdhi2_resources),
  972. .resource = sdhi2_resources,
  973. .id = 2,
  974. .dev = {
  975. .platform_data = &sdhi2_info,
  976. },
  977. };
  978. /* SH_MMCIF */
  979. #if IS_ENABLED(CONFIG_MMC_SH_MMCIF)
  980. static struct resource sh_mmcif_resources[] = {
  981. [0] = {
  982. .name = "MMCIF",
  983. .start = 0xE6BD0000,
  984. .end = 0xE6BD00FF,
  985. .flags = IORESOURCE_MEM,
  986. },
  987. [1] = {
  988. /* MMC ERR */
  989. .start = evt2irq(0x1ac0),
  990. .flags = IORESOURCE_IRQ,
  991. },
  992. [2] = {
  993. /* MMC NOR */
  994. .start = evt2irq(0x1ae0),
  995. .flags = IORESOURCE_IRQ,
  996. },
  997. };
  998. static struct sh_mmcif_plat_data sh_mmcif_plat = {
  999. .sup_pclk = 0,
  1000. .caps = MMC_CAP_4_BIT_DATA |
  1001. MMC_CAP_8_BIT_DATA |
  1002. MMC_CAP_NEEDS_POLL,
  1003. .use_cd_gpio = true,
  1004. /* card detect pin for SD/MMC slot (CN7) */
  1005. .cd_gpio = 41,
  1006. .slave_id_tx = SHDMA_SLAVE_MMCIF_TX,
  1007. .slave_id_rx = SHDMA_SLAVE_MMCIF_RX,
  1008. };
  1009. static struct platform_device sh_mmcif_device = {
  1010. .name = "sh_mmcif",
  1011. .id = 0,
  1012. .dev = {
  1013. .dma_mask = NULL,
  1014. .coherent_dma_mask = 0xffffffff,
  1015. .platform_data = &sh_mmcif_plat,
  1016. },
  1017. .num_resources = ARRAY_SIZE(sh_mmcif_resources),
  1018. .resource = sh_mmcif_resources,
  1019. };
  1020. #endif
  1021. static int mackerel_camera_add(struct soc_camera_device *icd);
  1022. static void mackerel_camera_del(struct soc_camera_device *icd);
  1023. static int camera_set_capture(struct soc_camera_platform_info *info,
  1024. int enable)
  1025. {
  1026. return 0; /* camera sensor always enabled */
  1027. }
  1028. static struct soc_camera_platform_info camera_info = {
  1029. .format_name = "UYVY",
  1030. .format_depth = 16,
  1031. .format = {
  1032. .code = V4L2_MBUS_FMT_UYVY8_2X8,
  1033. .colorspace = V4L2_COLORSPACE_SMPTE170M,
  1034. .field = V4L2_FIELD_NONE,
  1035. .width = 640,
  1036. .height = 480,
  1037. },
  1038. .mbus_param = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
  1039. V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
  1040. V4L2_MBUS_DATA_ACTIVE_HIGH,
  1041. .mbus_type = V4L2_MBUS_PARALLEL,
  1042. .set_capture = camera_set_capture,
  1043. };
  1044. static struct soc_camera_link camera_link = {
  1045. .bus_id = 0,
  1046. .add_device = mackerel_camera_add,
  1047. .del_device = mackerel_camera_del,
  1048. .module_name = "soc_camera_platform",
  1049. .priv = &camera_info,
  1050. };
  1051. static struct platform_device *camera_device;
  1052. static void mackerel_camera_release(struct device *dev)
  1053. {
  1054. soc_camera_platform_release(&camera_device);
  1055. }
  1056. static int mackerel_camera_add(struct soc_camera_device *icd)
  1057. {
  1058. return soc_camera_platform_add(icd, &camera_device, &camera_link,
  1059. mackerel_camera_release, 0);
  1060. }
  1061. static void mackerel_camera_del(struct soc_camera_device *icd)
  1062. {
  1063. soc_camera_platform_del(icd, camera_device, &camera_link);
  1064. }
  1065. static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
  1066. .flags = SH_CEU_FLAG_USE_8BIT_BUS,
  1067. .max_width = 8188,
  1068. .max_height = 8188,
  1069. };
  1070. static struct resource ceu_resources[] = {
  1071. [0] = {
  1072. .name = "CEU",
  1073. .start = 0xfe910000,
  1074. .end = 0xfe91009f,
  1075. .flags = IORESOURCE_MEM,
  1076. },
  1077. [1] = {
  1078. .start = intcs_evt2irq(0x880),
  1079. .flags = IORESOURCE_IRQ,
  1080. },
  1081. [2] = {
  1082. /* place holder for contiguous memory */
  1083. },
  1084. };
  1085. static struct platform_device ceu_device = {
  1086. .name = "sh_mobile_ceu",
  1087. .id = 0, /* "ceu0" clock */
  1088. .num_resources = ARRAY_SIZE(ceu_resources),
  1089. .resource = ceu_resources,
  1090. .dev = {
  1091. .platform_data = &sh_mobile_ceu_info,
  1092. .coherent_dma_mask = 0xffffffff,
  1093. },
  1094. };
  1095. static struct platform_device mackerel_camera = {
  1096. .name = "soc-camera-pdrv",
  1097. .id = 0,
  1098. .dev = {
  1099. .platform_data = &camera_link,
  1100. },
  1101. };
  1102. static struct platform_device *mackerel_devices[] __initdata = {
  1103. &nor_flash_device,
  1104. &smc911x_device,
  1105. &lcdc_device,
  1106. &gpio_backlight_device,
  1107. &usbhs0_device,
  1108. &usbhs1_device,
  1109. &leds_device,
  1110. &fsi_device,
  1111. &fsi_ak4643_device,
  1112. &fsi_hdmi_device,
  1113. &nand_flash_device,
  1114. &sdhi0_device,
  1115. #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
  1116. &sdhi1_device,
  1117. #else
  1118. &sh_mmcif_device,
  1119. #endif
  1120. &sdhi2_device,
  1121. &ceu_device,
  1122. &mackerel_camera,
  1123. &hdmi_device,
  1124. &hdmi_lcdc_device,
  1125. &meram_device,
  1126. };
  1127. /* Keypad Initialization */
  1128. #define KEYPAD_BUTTON(ev_type, ev_code, act_low) \
  1129. { \
  1130. .type = ev_type, \
  1131. .code = ev_code, \
  1132. .active_low = act_low, \
  1133. }
  1134. #define KEYPAD_BUTTON_LOW(event_code) KEYPAD_BUTTON(EV_KEY, event_code, 1)
  1135. static struct tca6416_button mackerel_gpio_keys[] = {
  1136. KEYPAD_BUTTON_LOW(KEY_HOME),
  1137. KEYPAD_BUTTON_LOW(KEY_MENU),
  1138. KEYPAD_BUTTON_LOW(KEY_BACK),
  1139. KEYPAD_BUTTON_LOW(KEY_POWER),
  1140. };
  1141. static struct tca6416_keys_platform_data mackerel_tca6416_keys_info = {
  1142. .buttons = mackerel_gpio_keys,
  1143. .nbuttons = ARRAY_SIZE(mackerel_gpio_keys),
  1144. .rep = 1,
  1145. .use_polling = 0,
  1146. .pinmask = 0x000F,
  1147. };
  1148. /* I2C */
  1149. #define IRQ7 evt2irq(0x02e0)
  1150. #define IRQ9 evt2irq(0x0320)
  1151. static struct i2c_board_info i2c0_devices[] = {
  1152. {
  1153. I2C_BOARD_INFO("ak4643", 0x13),
  1154. },
  1155. /* Keypad */
  1156. {
  1157. I2C_BOARD_INFO("tca6408-keys", 0x20),
  1158. .platform_data = &mackerel_tca6416_keys_info,
  1159. .irq = IRQ9,
  1160. },
  1161. /* Touchscreen */
  1162. {
  1163. I2C_BOARD_INFO("st1232-ts", 0x55),
  1164. .irq = IRQ7,
  1165. },
  1166. };
  1167. #define IRQ21 evt2irq(0x32a0)
  1168. static struct i2c_board_info i2c1_devices[] = {
  1169. /* Accelerometer */
  1170. {
  1171. I2C_BOARD_INFO("adxl34x", 0x53),
  1172. .irq = IRQ21,
  1173. },
  1174. };
  1175. static const struct pinctrl_map mackerel_pinctrl_map[] = {
  1176. /* ADXL34X */
  1177. PIN_MAP_MUX_GROUP_DEFAULT("1-0053", "pfc-sh7372",
  1178. "intc_irq21", "intc"),
  1179. /* CEU */
  1180. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
  1181. "ceu_data_0_7", "ceu"),
  1182. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
  1183. "ceu_clk_0", "ceu"),
  1184. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
  1185. "ceu_sync", "ceu"),
  1186. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
  1187. "ceu_field", "ceu"),
  1188. /* FLCTL */
  1189. PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
  1190. "flctl_data", "flctl"),
  1191. PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
  1192. "flctl_ce0", "flctl"),
  1193. PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
  1194. "flctl_ctrl", "flctl"),
  1195. /* FSIA (AK4643) */
  1196. PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
  1197. "fsia_sclk_in", "fsia"),
  1198. PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
  1199. "fsia_data_in", "fsia"),
  1200. PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
  1201. "fsia_data_out", "fsia"),
  1202. /* FSIB (HDMI) */
  1203. PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.1", "pfc-sh7372",
  1204. "fsib_mclk_in", "fsib"),
  1205. /* HDMI */
  1206. PIN_MAP_MUX_GROUP_DEFAULT("sh-mobile-hdmi", "pfc-sh7372",
  1207. "hdmi", "hdmi"),
  1208. /* LCDC */
  1209. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-sh7372",
  1210. "lcd_data24", "lcd"),
  1211. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-sh7372",
  1212. "lcd_sync", "lcd"),
  1213. /* SCIFA0 */
  1214. PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.0", "pfc-sh7372",
  1215. "scifa0_data", "scifa0"),
  1216. /* SCIFA2 (GT-720F GPS module) */
  1217. PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.2", "pfc-sh7372",
  1218. "scifa2_data", "scifa2"),
  1219. /* SDHI0 */
  1220. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
  1221. "sdhi0_data4", "sdhi0"),
  1222. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
  1223. "sdhi0_ctrl", "sdhi0"),
  1224. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
  1225. "sdhi0_wp", "sdhi0"),
  1226. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
  1227. "intc_irq26_1", "intc"),
  1228. /* SDHI1 */
  1229. #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
  1230. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-sh7372",
  1231. "sdhi1_data4", "sdhi1"),
  1232. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-sh7372",
  1233. "sdhi1_ctrl", "sdhi1"),
  1234. #else
  1235. /* MMCIF */
  1236. PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh7372",
  1237. "mmc0_data8_0", "mmc0"),
  1238. PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh7372",
  1239. "mmc0_ctrl_0", "mmc0"),
  1240. #endif
  1241. /* SDHI2 */
  1242. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-sh7372",
  1243. "sdhi2_data4", "sdhi2"),
  1244. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-sh7372",
  1245. "sdhi2_ctrl", "sdhi2"),
  1246. /* SMSC911X */
  1247. PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-sh7372",
  1248. "bsc_cs5a", "bsc"),
  1249. PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-sh7372",
  1250. "intc_irq6_0", "intc"),
  1251. /* ST1232 */
  1252. PIN_MAP_MUX_GROUP_DEFAULT("0-0055", "pfc-sh7372",
  1253. "intc_irq7_0", "intc"),
  1254. /* TCA6416 */
  1255. PIN_MAP_MUX_GROUP_DEFAULT("0-0020", "pfc-sh7372",
  1256. "intc_irq9_0", "intc"),
  1257. /* USBHS0 */
  1258. PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.0", "pfc-sh7372",
  1259. "usb0_vbus", "usb0"),
  1260. /* USBHS1 */
  1261. PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
  1262. "usb1_vbus", "usb1"),
  1263. PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
  1264. "usb1_otg_id_0", "usb1"),
  1265. };
  1266. #define GPIO_PORT9CR IOMEM(0xE6051009)
  1267. #define GPIO_PORT10CR IOMEM(0xE605100A)
  1268. #define GPIO_PORT167CR IOMEM(0xE60520A7)
  1269. #define GPIO_PORT168CR IOMEM(0xE60520A8)
  1270. #define SRCR4 IOMEM(0xe61580bc)
  1271. #define USCCR1 IOMEM(0xE6058144)
  1272. static void __init mackerel_init(void)
  1273. {
  1274. struct pm_domain_device domain_devices[] = {
  1275. { "A4LC", &lcdc_device, },
  1276. { "A4LC", &hdmi_lcdc_device, },
  1277. { "A4LC", &meram_device, },
  1278. { "A4MP", &fsi_device, },
  1279. { "A3SP", &usbhs0_device, },
  1280. { "A3SP", &usbhs1_device, },
  1281. { "A3SP", &nand_flash_device, },
  1282. { "A3SP", &sdhi0_device, },
  1283. #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
  1284. { "A3SP", &sdhi1_device, },
  1285. #else
  1286. { "A3SP", &sh_mmcif_device, },
  1287. #endif
  1288. { "A3SP", &sdhi2_device, },
  1289. { "A4R", &ceu_device, },
  1290. };
  1291. u32 srcr4;
  1292. struct clk *clk;
  1293. regulator_register_always_on(0, "fixed-1.8V", fixed1v8_power_consumers,
  1294. ARRAY_SIZE(fixed1v8_power_consumers), 1800000);
  1295. regulator_register_always_on(1, "fixed-3.3V", fixed3v3_power_consumers,
  1296. ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
  1297. regulator_register_fixed(2, dummy_supplies, ARRAY_SIZE(dummy_supplies));
  1298. /* External clock source */
  1299. clk_set_rate(&sh7372_dv_clki_clk, 27000000);
  1300. pinctrl_register_mappings(mackerel_pinctrl_map,
  1301. ARRAY_SIZE(mackerel_pinctrl_map));
  1302. sh7372_pinmux_init();
  1303. gpio_request_one(151, GPIOF_OUT_INIT_HIGH, NULL); /* LCDDON */
  1304. /* USBHS0 */
  1305. gpio_request_pulldown(GPIO_PORT168CR); /* VBUS0_0 pull down */
  1306. /* USBHS1 */
  1307. gpio_request_pulldown(GPIO_PORT167CR); /* VBUS0_1 pull down */
  1308. /* FSI2 port A (ak4643) */
  1309. gpio_request_one(161, GPIOF_OUT_INIT_LOW, NULL); /* slave */
  1310. gpio_request(9, NULL);
  1311. gpio_request(10, NULL);
  1312. gpio_direction_none(GPIO_PORT9CR); /* FSIAOBT needs no direction */
  1313. gpio_direction_none(GPIO_PORT10CR); /* FSIAOLR needs no direction */
  1314. intc_set_priority(IRQ_FSI, 3); /* irq priority FSI(3) > SMSC911X(2) */
  1315. /* FSI2 port B (HDMI) */
  1316. __raw_writew(__raw_readw(USCCR1) & ~(1 << 6), USCCR1); /* use SPDIF */
  1317. /* set SPU2 clock to 119.6 MHz */
  1318. clk = clk_get(NULL, "spu_clk");
  1319. if (!IS_ERR(clk)) {
  1320. clk_set_rate(clk, clk_round_rate(clk, 119600000));
  1321. clk_put(clk);
  1322. }
  1323. /* Keypad */
  1324. irq_set_irq_type(IRQ9, IRQ_TYPE_LEVEL_HIGH);
  1325. /* Touchscreen */
  1326. irq_set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
  1327. /* Accelerometer */
  1328. irq_set_irq_type(IRQ21, IRQ_TYPE_LEVEL_HIGH);
  1329. /* Reset HDMI, must be held at least one EXTALR (32768Hz) period */
  1330. srcr4 = __raw_readl(SRCR4);
  1331. __raw_writel(srcr4 | (1 << 13), SRCR4);
  1332. udelay(50);
  1333. __raw_writel(srcr4 & ~(1 << 13), SRCR4);
  1334. i2c_register_board_info(0, i2c0_devices,
  1335. ARRAY_SIZE(i2c0_devices));
  1336. i2c_register_board_info(1, i2c1_devices,
  1337. ARRAY_SIZE(i2c1_devices));
  1338. sh7372_add_standard_devices();
  1339. platform_add_devices(mackerel_devices, ARRAY_SIZE(mackerel_devices));
  1340. rmobile_add_devices_to_domains(domain_devices,
  1341. ARRAY_SIZE(domain_devices));
  1342. hdmi_init_pm_clock();
  1343. sh7372_pm_init();
  1344. pm_clk_add(&fsi_device.dev, "spu2");
  1345. pm_clk_add(&hdmi_lcdc_device.dev, "hdmi");
  1346. }
  1347. static const char *mackerel_boards_compat_dt[] __initdata = {
  1348. "renesas,mackerel",
  1349. NULL,
  1350. };
  1351. DT_MACHINE_START(MACKEREL_DT, "mackerel")
  1352. .map_io = sh7372_map_io,
  1353. .init_early = sh7372_add_early_devices,
  1354. .init_irq = sh7372_init_irq,
  1355. .handle_irq = shmobile_handle_irq_intc,
  1356. .init_machine = mackerel_init,
  1357. .init_late = sh7372_pm_init_late,
  1358. .init_time = sh7372_earlytimer_init,
  1359. .dt_compat = mackerel_boards_compat_dt,
  1360. MACHINE_END