board-mackerel.c 37 KB

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