hiddenDangerAnalysis.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  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/pm_clock.h>
  44. #include <linux/regulator/fixed.h>
  45. #include <linux/regulator/machine.h>
  46. #include <linux/smsc911x.h>
  47. #include <linux/sh_intc.h>
  48. #include <linux/tca6416_keypad.h>
  49. #include <linux/usb/renesas_usbhs.h>
  50. #include <linux/dma-mapping.h>
  51. #include <video/sh_mobile_hdmi.h>
  52. #include <video/sh_mobile_lcdc.h>
  53. #include <media/sh_mobile_ceu.h>
  54. #include <media/soc_camera.h>
  55. #include <media/soc_camera_platform.h>
  56. #include <sound/sh_fsi.h>
  57. #include <sound/simple_card.h>
  58. #include <mach/common.h>
  59. #include <mach/irqs.h>
  60. #include <mach/sh7372.h>
  61. #include <asm/mach/arch.h>
  62. #include <asm/mach-types.h>
  63. #include "sh-gpio.h"
  64. /*
  65. * Address Interface BusWidth note
  66. * ------------------------------------------------------------------
  67. * 0x0000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = ON
  68. * 0x0800_0000 user area -
  69. * 0x1000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = OFF
  70. * 0x1400_0000 Ether (LAN9220) 16bit
  71. * 0x1600_0000 user area - cannot use with NAND
  72. * 0x1800_0000 user area -
  73. * 0x1A00_0000 -
  74. * 0x4000_0000 LPDDR2-SDRAM (POP) 32bit
  75. */
  76. /*
  77. * CPU mode
  78. *
  79. * SW4 | Boot Area| Master | Remarks
  80. * 1 | 2 | 3 | 4 | 5 | 6 | 8 | | Processor|
  81. * ----+-----+-----+-----+-----+-----+-----+----------+----------+--------------
  82. * ON | ON | OFF | ON | ON | OFF | OFF | External | System | External ROM
  83. * ON | ON | ON | ON | ON | OFF | OFF | External | System | ROM Debug
  84. * ON | ON | X | ON | OFF | OFF | OFF | Built-in | System | ROM Debug
  85. * X | OFF | X | X | X | X | OFF | Built-in | System | MaskROM
  86. * OFF | X | X | X | X | X | OFF | Built-in | System | MaskROM
  87. * X | X | X | OFF | X | X | OFF | Built-in | System | MaskROM
  88. * OFF | ON | OFF | X | X | OFF | ON | External | System | Standalone
  89. * ON | OFF | OFF | X | X | OFF | ON | External | Realtime | Standalone
  90. */
  91. /*
  92. * NOR Flash ROM
  93. *
  94. * SW1 | SW2 | SW7 | NOR Flash ROM
  95. * bit1 | bit1 bit2 | bit1 | Memory allocation
  96. * ------+------------+------+------------------
  97. * OFF | ON OFF | ON | Area 0
  98. * OFF | ON OFF | OFF | Area 4
  99. */
  100. /*
  101. * SMSC 9220
  102. *
  103. * SW1 SMSC 9220
  104. * -----------------------
  105. * ON access disable
  106. * OFF access enable
  107. */
  108. /*
  109. * NAND Flash ROM
  110. *
  111. * SW1 | SW2 | SW7 | NAND Flash ROM
  112. * bit1 | bit1 bit2 | bit2 | Memory allocation
  113. * ------+------------+------+------------------
  114. * OFF | ON OFF | ON | FCE 0
  115. * OFF | ON OFF | OFF | FCE 1
  116. */
  117. /*
  118. * External interrupt pin settings
  119. *
  120. * IRQX | pin setting | device | level
  121. * ------+--------------------+--------------------+-------
  122. * IRQ0 | ICR1A.IRQ0SA=0010 | SDHI2 card detect | Low
  123. * IRQ6 | ICR1A.IRQ6SA=0011 | Ether(LAN9220) | High
  124. * IRQ7 | ICR1A.IRQ7SA=0010 | LCD Touch Panel | Low
  125. * IRQ8 | ICR2A.IRQ8SA=0010 | MMC/SD card detect | Low
  126. * IRQ9 | ICR2A.IRQ9SA=0010 | KEY(TCA6408) | Low
  127. * IRQ21 | ICR4A.IRQ21SA=0011 | Sensor(ADXL345) | High
  128. * IRQ22 | ICR4A.IRQ22SA=0011 | Sensor(AK8975) | High
  129. */
  130. /*
  131. * USB
  132. *
  133. * USB0 : CN22 : Function
  134. * USB1 : CN31 : Function/Host *1
  135. *
  136. * J30 (for CN31) *1
  137. * ----------+---------------+-------------
  138. * 1-2 short | VBUS 5V | Host
  139. * open | external VBUS | Function
  140. *
  141. * CAUTION
  142. *
  143. * renesas_usbhs driver can use external interrupt mode
  144. * (which come from USB-PHY) or autonomy mode (it use own interrupt)
  145. * for detecting connection/disconnection when Function.
  146. * USB will be power OFF while it has been disconnecting
  147. * if external interrupt mode, and it is always power ON if autonomy mode,
  148. *
  149. * mackerel can not use external interrupt (IRQ7-PORT167) mode on "USB0",
  150. * because Touchscreen is using IRQ7-PORT40.
  151. * It is impossible to use IRQ7 demux on this board.
  152. */
  153. /*
  154. * SDHI0 (CN12)
  155. *
  156. * SW56 : OFF
  157. *
  158. */
  159. /* MMC /SDHI1 (CN7)
  160. *
  161. * I/O voltage : 1.8v
  162. *
  163. * Power voltage : 1.8v or 3.3v
  164. * J22 : select power voltage *1
  165. * 1-2 pin : 1.8v
  166. * 2-3 pin : 3.3v
  167. *
  168. * *1
  169. * Please change J22 depends the card to be used.
  170. * MMC's OCR field set to support either voltage for the card inserted.
  171. *
  172. * SW1 | SW33
  173. * | bit1 | bit2 | bit3 | bit4
  174. * -------------+------+------+------+-------
  175. * MMC0 OFF | OFF | X | ON | X (Use MMCIF)
  176. * SDHI1 OFF | ON | X | OFF | X (Use MFD_SH_MOBILE_SDHI)
  177. *
  178. */
  179. /*
  180. * SDHI2 (CN23)
  181. *
  182. * microSD card sloct
  183. *
  184. */
  185. /*
  186. * FSI - AK4642
  187. *
  188. * it needs amixer settings for playing
  189. *
  190. * amixer set "Headphone" on
  191. * amixer set "HPOUTL Mixer DACH" on
  192. * amixer set "HPOUTR Mixer DACH" on
  193. */
  194. /* Fixed 3.3V and 1.8V regulators to be used by multiple devices */
  195. static struct regulator_consumer_supply fixed1v8_power_consumers[] =
  196. {
  197. /*
  198. * J22 on mackerel switches mmcif.0 and sdhi.1 between 1.8V and 3.3V
  199. * Since we cannot support both voltages, we support the default 1.8V
  200. */
  201. REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.1"),
  202. REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.1"),
  203. REGULATOR_SUPPLY("vmmc", "sh_mmcif.0"),
  204. REGULATOR_SUPPLY("vqmmc", "sh_mmcif.0"),
  205. };
  206. static struct regulator_consumer_supply fixed3v3_power_consumers[] =
  207. {
  208. REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
  209. REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
  210. REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.2"),
  211. REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.2"),
  212. };
  213. /* Dummy supplies, where voltage doesn't matter */
  214. static struct regulator_consumer_supply dummy_supplies[] = {
  215. REGULATOR_SUPPLY("vddvario", "smsc911x"),
  216. REGULATOR_SUPPLY("vdd33a", "smsc911x"),
  217. };
  218. /* MTD */
  219. static struct mtd_partition nor_flash_partitions[] = {
  220. {
  221. .name = "loader",
  222. .offset = 0x00000000,
  223. .size = 512 * 1024,
  224. .mask_flags = MTD_WRITEABLE,
  225. },
  226. {
  227. .name = "bootenv",
  228. .offset = MTDPART_OFS_APPEND,
  229. .size = 512 * 1024,
  230. .mask_flags = MTD_WRITEABLE,
  231. },
  232. {
  233. .name = "kernel_ro",
  234. .offset = MTDPART_OFS_APPEND,
  235. .size = 8 * 1024 * 1024,
  236. .mask_flags = MTD_WRITEABLE,
  237. },
  238. {
  239. .name = "kernel",
  240. .offset = MTDPART_OFS_APPEND,
  241. .size = 8 * 1024 * 1024,
  242. },
  243. {
  244. .name = "data",
  245. .offset = MTDPART_OFS_APPEND,
  246. .size = MTDPART_SIZ_FULL,
  247. },
  248. };
  249. static struct physmap_flash_data nor_flash_data = {
  250. .width = 2,
  251. .parts = nor_flash_partitions,
  252. .nr_parts = ARRAY_SIZE(nor_flash_partitions),
  253. };
  254. static struct resource nor_flash_resources[] = {
  255. [0] = {
  256. .start = 0x20000000, /* CS0 shadow instead of regular CS0 */
  257. .end = 0x28000000 - 1, /* needed by USB MASK ROM boot */
  258. .flags = IORESOURCE_MEM,
  259. }
  260. };
  261. static struct platform_device nor_flash_device = {
  262. .name = "physmap-flash",
  263. .dev = {
  264. .platform_data = &nor_flash_data,
  265. },
  266. .num_resources = ARRAY_SIZE(nor_flash_resources),
  267. .resource = nor_flash_resources,
  268. };
  269. /* SMSC */
  270. static struct resource smc911x_resources[] = {
  271. {
  272. .start = 0x14000000,
  273. .end = 0x16000000 - 1,
  274. .flags = IORESOURCE_MEM,
  275. }, {
  276. .start = evt2irq(0x02c0) /* IRQ6A */,
  277. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  278. },
  279. };
  280. static struct smsc911x_platform_config smsc911x_info = {
  281. .flags = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
  282. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  283. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  284. };
  285. static struct platform_device smc911x_device = {
  286. .name = "smsc911x",
  287. .id = -1,
  288. .num_resources = ARRAY_SIZE(smc911x_resources),
  289. .resource = smc911x_resources,
  290. .dev = {
  291. .platform_data = &smsc911x_info,
  292. },
  293. };
  294. /* MERAM */
  295. static struct sh_mobile_meram_info mackerel_meram_info = {
  296. .addr_mode = SH_MOBILE_MERAM_MODE1,
  297. };
  298. static struct resource meram_resources[] = {
  299. [0] = {
  300. .name = "regs",
  301. .start = 0xe8000000,
  302. .end = 0xe807ffff,
  303. .flags = IORESOURCE_MEM,
  304. },
  305. [1] = {
  306. .name = "meram",
  307. .start = 0xe8080000,
  308. .end = 0xe81fffff,
  309. .flags = IORESOURCE_MEM,
  310. },
  311. };
  312. static struct platform_device meram_device = {
  313. .name = "sh_mobile_meram",
  314. .id = 0,
  315. .num_resources = ARRAY_SIZE(meram_resources),
  316. .resource = meram_resources,
  317. .dev = {
  318. .platform_data = &mackerel_meram_info,
  319. },
  320. };
  321. /* LCDC */
  322. static struct fb_videomode mackerel_lcdc_modes[] = {
  323. {
  324. .name = "WVGA Panel",
  325. .xres = 800,
  326. .yres = 480,
  327. .left_margin = 220,
  328. .right_margin = 110,
  329. .hsync_len = 70,
  330. .upper_margin = 20,
  331. .lower_margin = 5,
  332. .vsync_len = 5,
  333. .sync = 0,
  334. },
  335. };
  336. static int mackerel_set_brightness(int brightness)
  337. {
  338. gpio_set_value(GPIO_PORT31, brightness);
  339. return 0;
  340. }
  341. static const struct sh_mobile_meram_cfg lcd_meram_cfg = {
  342. .icb[0] = {
  343. .meram_size = 0x40,
  344. },
  345. .icb[1] = {
  346. .meram_size = 0x40,
  347. },
  348. };
  349. static struct sh_mobile_lcdc_info lcdc_info = {
  350. .meram_dev = &mackerel_meram_info,
  351. .clock_source = LCDC_CLK_BUS,
  352. .ch[0] = {
  353. .chan = LCDC_CHAN_MAINLCD,
  354. .fourcc = V4L2_PIX_FMT_RGB565,
  355. .lcd_modes = mackerel_lcdc_modes,
  356. .num_modes = ARRAY_SIZE(mackerel_lcdc_modes),
  357. .interface_type = RGB24,
  358. .clock_divider = 3,
  359. .flags = 0,
  360. .panel_cfg = {
  361. .width = 152,
  362. .height = 91,
  363. },
  364. .bl_info = {
  365. .name = "sh_mobile_lcdc_bl",
  366. .max_brightness = 1,
  367. .set_brightness = mackerel_set_brightness,
  368. },
  369. .meram_cfg = &lcd_meram_cfg,
  370. }
  371. };
  372. static struct resource lcdc_resources[] = {
  373. [0] = {
  374. .name = "LCDC",
  375. .start = 0xfe940000,
  376. .end = 0xfe943fff,
  377. .flags = IORESOURCE_MEM,
  378. },
  379. [1] = {
  380. .start = intcs_evt2irq(0x580),
  381. .flags = IORESOURCE_IRQ,
  382. },
  383. };
  384. static struct platform_device lcdc_device = {
  385. .name = "sh_mobile_lcdc_fb",
  386. .num_resources = ARRAY_SIZE(lcdc_resources),
  387. .resource = lcdc_resources,
  388. .dev = {
  389. .platform_data = &lcdc_info,
  390. .coherent_dma_mask = ~0,
  391. },
  392. };
  393. /* HDMI */
  394. static struct sh_mobile_hdmi_info hdmi_info = {
  395. .flags = HDMI_SND_SRC_SPDIF,
  396. };
  397. static struct resource hdmi_resources[] = {
  398. [0] = {
  399. .name = "HDMI",
  400. .start = 0xe6be0000,
  401. .end = 0xe6be00ff,
  402. .flags = IORESOURCE_MEM,
  403. },
  404. [1] = {
  405. /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
  406. .start = evt2irq(0x17e0),
  407. .flags = IORESOURCE_IRQ,
  408. },
  409. };
  410. static struct platform_device hdmi_device = {
  411. .name = "sh-mobile-hdmi",
  412. .num_resources = ARRAY_SIZE(hdmi_resources),
  413. .resource = hdmi_resources,
  414. .id = -1,
  415. .dev = {
  416. .platform_data = &hdmi_info,
  417. },
  418. };
  419. static const struct sh_mobile_meram_cfg hdmi_meram_cfg = {
  420. .icb[0] = {
  421. .meram_size = 0x100,
  422. },
  423. .icb[1] = {
  424. .meram_size = 0x100,
  425. },
  426. };
  427. static struct sh_mobile_lcdc_info hdmi_lcdc_info = {
  428. .meram_dev = &mackerel_meram_info,
  429. .clock_source = LCDC_CLK_EXTERNAL,
  430. .ch[0] = {
  431. .chan = LCDC_CHAN_MAINLCD,
  432. .fourcc = V4L2_PIX_FMT_RGB565,
  433. .interface_type = RGB24,
  434. .clock_divider = 1,
  435. .flags = LCDC_FLAGS_DWPOL,
  436. .meram_cfg = &hdmi_meram_cfg,
  437. .tx_dev = &hdmi_device,
  438. }
  439. };
  440. static struct resource hdmi_lcdc_resources[] = {
  441. [0] = {
  442. .name = "LCDC1",
  443. .start = 0xfe944000,
  444. .end = 0xfe947fff,
  445. .flags = IORESOURCE_MEM,
  446. },
  447. [1] = {
  448. .start = intcs_evt2irq(0x1780),
  449. .flags = IORESOURCE_IRQ,
  450. },
  451. };
  452. static struct platform_device hdmi_lcdc_device = {
  453. .name = "sh_mobile_lcdc_fb",
  454. .num_resources = ARRAY_SIZE(hdmi_lcdc_resources),
  455. .resource = hdmi_lcdc_resources,
  456. .id = 1,
  457. .dev = {
  458. .platform_data = &hdmi_lcdc_info,
  459. .coherent_dma_mask = ~0,
  460. },
  461. };
  462. static struct asoc_simple_dai_init_info fsi2_hdmi_init_info = {
  463. .cpu_daifmt = SND_SOC_DAIFMT_CBM_CFM,
  464. };
  465. static struct asoc_simple_card_info fsi2_hdmi_info = {
  466. .name = "HDMI",
  467. .card = "FSI2B-HDMI",
  468. .cpu_dai = "fsib-dai",
  469. .codec = "sh-mobile-hdmi",
  470. .platform = "sh_fsi2",
  471. .codec_dai = "sh_mobile_hdmi-hifi",
  472. .init = &fsi2_hdmi_init_info,
  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 void 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. }
  547. static int usbhs0_get_id(struct platform_device *pdev)
  548. {
  549. return USBHS_GADGET;
  550. }
  551. static void usbhs0_work_function(struct work_struct *work)
  552. {
  553. struct usbhs_private *priv = container_of(work, struct usbhs_private,
  554. work.work);
  555. renesas_usbhs_call_notify_hotplug(priv->pdev);
  556. schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
  557. }
  558. static int usbhs0_hardware_init(struct platform_device *pdev)
  559. {
  560. struct usbhs_private *priv = usbhs_get_priv(pdev);
  561. priv->pdev = pdev;
  562. INIT_DELAYED_WORK(&priv->work, usbhs0_work_function);
  563. schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
  564. return 0;
  565. }
  566. static void usbhs0_hardware_exit(struct platform_device *pdev)
  567. {
  568. struct usbhs_private *priv = usbhs_get_priv(pdev);
  569. cancel_delayed_work_sync(&priv->work);
  570. }
  571. static struct usbhs_private usbhs0_private = {
  572. .usbcrcaddr = IOMEM(0xe605810c), /* USBCR2 */
  573. .info = {
  574. .platform_callback = {
  575. .hardware_init = usbhs0_hardware_init,
  576. .hardware_exit = usbhs0_hardware_exit,
  577. .phy_reset = usbhs_phy_reset,
  578. .get_id = usbhs0_get_id,
  579. .get_vbus = usbhs_get_vbus,
  580. },
  581. .driver_param = {
  582. .buswait_bwait = 4,
  583. .d0_tx_id = SHDMA_SLAVE_USB0_TX,
  584. .d1_rx_id = SHDMA_SLAVE_USB0_RX,
  585. },
  586. },
  587. };
  588. static struct resource usbhs0_resources[] = {
  589. [0] = {
  590. .name = "USBHS0",
  591. .start = 0xe6890000,
  592. .end = 0xe68900e6 - 1,
  593. .flags = IORESOURCE_MEM,
  594. },
  595. [1] = {
  596. .start = evt2irq(0x1ca0) /* USB0_USB0I0 */,
  597. .flags = IORESOURCE_IRQ,
  598. },
  599. };
  600. static struct platform_device usbhs0_device = {
  601. .name = "renesas_usbhs",
  602. .id = 0,
  603. .dev = {
  604. .platform_data = &usbhs0_private.info,
  605. },
  606. .num_resources = ARRAY_SIZE(usbhs0_resources),
  607. .resource = usbhs0_resources,
  608. };
  609. /* USBHS1 is connected to CN31 which takes a USB Mini-AB plug
  610. *
  611. * Use J30 to select between Host and Function. This setting
  612. * can however not be detected by software. Hotplug of USBHS1
  613. * is provided via IRQ8.
  614. *
  615. * Current USB1 works as "USB Host".
  616. * - set J30 "short"
  617. *
  618. * If you want to use it as "USB gadget",
  619. * - J30 "open"
  620. * - modify usbhs1_get_id() USBHS_HOST -> USBHS_GADGET
  621. * - add .get_vbus = usbhs_get_vbus in usbhs1_private
  622. * - check usbhs0_device(pio)/usbhs1_device(irq) order in mackerel_devices.
  623. */
  624. #define IRQ8 evt2irq(0x0300)
  625. #define USB_PHY_MODE (1 << 4)
  626. #define USB_PHY_INT_EN ((1 << 3) | (1 << 2))
  627. #define USB_PHY_ON (1 << 1)
  628. #define USB_PHY_OFF (1 << 0)
  629. #define USB_PHY_INT_CLR (USB_PHY_ON | USB_PHY_OFF)
  630. static irqreturn_t usbhs1_interrupt(int irq, void *data)
  631. {
  632. struct platform_device *pdev = data;
  633. struct usbhs_private *priv = usbhs_get_priv(pdev);
  634. dev_dbg(&pdev->dev, "%s\n", __func__);
  635. renesas_usbhs_call_notify_hotplug(pdev);
  636. /* clear status */
  637. __raw_writew(__raw_readw(priv->usbphyaddr) | USB_PHY_INT_CLR,
  638. priv->usbphyaddr);
  639. return IRQ_HANDLED;
  640. }
  641. static int usbhs1_hardware_init(struct platform_device *pdev)
  642. {
  643. struct usbhs_private *priv = usbhs_get_priv(pdev);
  644. int ret;
  645. /* clear interrupt status */
  646. __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
  647. ret = request_irq(IRQ8, usbhs1_interrupt, IRQF_TRIGGER_HIGH,
  648. dev_name(&pdev->dev), pdev);
  649. if (ret) {
  650. dev_err(&pdev->dev, "request_irq err\n");
  651. return ret;
  652. }
  653. /* enable USB phy interrupt */
  654. __raw_writew(USB_PHY_MODE | USB_PHY_INT_EN, priv->usbphyaddr);
  655. return 0;
  656. }
  657. static void usbhs1_hardware_exit(struct platform_device *pdev)
  658. {
  659. struct usbhs_private *priv = usbhs_get_priv(pdev);
  660. /* clear interrupt status */
  661. __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
  662. free_irq(IRQ8, pdev);
  663. }
  664. static int usbhs1_get_id(struct platform_device *pdev)
  665. {
  666. return USBHS_HOST;
  667. }
  668. static u32 usbhs1_pipe_cfg[] = {
  669. USB_ENDPOINT_XFER_CONTROL,
  670. USB_ENDPOINT_XFER_ISOC,
  671. USB_ENDPOINT_XFER_ISOC,
  672. USB_ENDPOINT_XFER_BULK,
  673. USB_ENDPOINT_XFER_BULK,
  674. USB_ENDPOINT_XFER_BULK,
  675. USB_ENDPOINT_XFER_INT,
  676. USB_ENDPOINT_XFER_INT,
  677. USB_ENDPOINT_XFER_INT,
  678. USB_ENDPOINT_XFER_BULK,
  679. USB_ENDPOINT_XFER_BULK,
  680. USB_ENDPOINT_XFER_BULK,
  681. USB_ENDPOINT_XFER_BULK,
  682. USB_ENDPOINT_XFER_BULK,
  683. USB_ENDPOINT_XFER_BULK,
  684. USB_ENDPOINT_XFER_BULK,
  685. };
  686. static struct usbhs_private usbhs1_private = {
  687. .usbphyaddr = IOMEM(0xe60581e2), /* USBPHY1INTAP */
  688. .usbcrcaddr = IOMEM(0xe6058130), /* USBCR4 */
  689. .info = {
  690. .platform_callback = {
  691. .hardware_init = usbhs1_hardware_init,
  692. .hardware_exit = usbhs1_hardware_exit,
  693. .get_id = usbhs1_get_id,
  694. .phy_reset = usbhs_phy_reset,
  695. },
  696. .driver_param = {
  697. .buswait_bwait = 4,
  698. .has_otg = 1,
  699. .pipe_type = usbhs1_pipe_cfg,
  700. .pipe_size = ARRAY_SIZE(usbhs1_pipe_cfg),
  701. .d0_tx_id = SHDMA_SLAVE_USB1_TX,
  702. .d1_rx_id = SHDMA_SLAVE_USB1_RX,
  703. },
  704. },
  705. };
  706. static struct resource usbhs1_resources[] = {
  707. [0] = {
  708. .name = "USBHS1",
  709. .start = 0xe68b0000,
  710. .end = 0xe68b00e6 - 1,
  711. .flags = IORESOURCE_MEM,
  712. },
  713. [1] = {
  714. .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
  715. .flags = IORESOURCE_IRQ,
  716. },
  717. };
  718. static struct platform_device usbhs1_device = {
  719. .name = "renesas_usbhs",
  720. .id = 1,
  721. .dev = {
  722. .platform_data = &usbhs1_private.info,
  723. .dma_mask = &usbhs1_device.dev.coherent_dma_mask,
  724. .coherent_dma_mask = DMA_BIT_MASK(32),
  725. },
  726. .num_resources = ARRAY_SIZE(usbhs1_resources),
  727. .resource = usbhs1_resources,
  728. };
  729. /* LED */
  730. static struct gpio_led mackerel_leds[] = {
  731. {
  732. .name = "led0",
  733. .gpio = GPIO_PORT0,
  734. .default_state = LEDS_GPIO_DEFSTATE_ON,
  735. },
  736. {
  737. .name = "led1",
  738. .gpio = GPIO_PORT1,
  739. .default_state = LEDS_GPIO_DEFSTATE_ON,
  740. },
  741. {
  742. .name = "led2",
  743. .gpio = GPIO_PORT2,