board-mackerel.c 37 KB

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