board-mackerel.c 37 KB

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