board-mackerel.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593
  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/pm_clock.h>
  43. #include <linux/smsc911x.h>
  44. #include <linux/sh_intc.h>
  45. #include <linux/tca6416_keypad.h>
  46. #include <linux/usb/renesas_usbhs.h>
  47. #include <linux/dma-mapping.h>
  48. #include <video/sh_mobile_hdmi.h>
  49. #include <video/sh_mobile_lcdc.h>
  50. #include <media/sh_mobile_ceu.h>
  51. #include <media/soc_camera.h>
  52. #include <media/soc_camera_platform.h>
  53. #include <sound/sh_fsi.h>
  54. #include <mach/common.h>
  55. #include <mach/sh7372.h>
  56. #include <asm/mach/arch.h>
  57. #include <asm/mach/time.h>
  58. #include <asm/mach/map.h>
  59. #include <asm/mach-types.h>
  60. /*
  61. * Address Interface BusWidth note
  62. * ------------------------------------------------------------------
  63. * 0x0000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = ON
  64. * 0x0800_0000 user area -
  65. * 0x1000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = OFF
  66. * 0x1400_0000 Ether (LAN9220) 16bit
  67. * 0x1600_0000 user area - cannot use with NAND
  68. * 0x1800_0000 user area -
  69. * 0x1A00_0000 -
  70. * 0x4000_0000 LPDDR2-SDRAM (POP) 32bit
  71. */
  72. /*
  73. * CPU mode
  74. *
  75. * SW4 | Boot Area| Master | Remarks
  76. * 1 | 2 | 3 | 4 | 5 | 6 | 8 | | Processor|
  77. * ----+-----+-----+-----+-----+-----+-----+----------+----------+--------------
  78. * ON | ON | OFF | ON | ON | OFF | OFF | External | System | External ROM
  79. * ON | ON | ON | ON | ON | OFF | OFF | External | System | ROM Debug
  80. * ON | ON | X | ON | OFF | OFF | OFF | Built-in | System | ROM Debug
  81. * X | OFF | X | X | X | X | OFF | Built-in | System | MaskROM
  82. * OFF | X | X | X | X | X | OFF | Built-in | System | MaskROM
  83. * X | X | X | OFF | X | X | OFF | Built-in | System | MaskROM
  84. * OFF | ON | OFF | X | X | OFF | ON | External | System | Standalone
  85. * ON | OFF | OFF | X | X | OFF | ON | External | Realtime | Standalone
  86. */
  87. /*
  88. * NOR Flash ROM
  89. *
  90. * SW1 | SW2 | SW7 | NOR Flash ROM
  91. * bit1 | bit1 bit2 | bit1 | Memory allocation
  92. * ------+------------+------+------------------
  93. * OFF | ON OFF | ON | Area 0
  94. * OFF | ON OFF | OFF | Area 4
  95. */
  96. /*
  97. * SMSC 9220
  98. *
  99. * SW1 SMSC 9220
  100. * -----------------------
  101. * ON access disable
  102. * OFF access enable
  103. */
  104. /*
  105. * NAND Flash ROM
  106. *
  107. * SW1 | SW2 | SW7 | NAND Flash ROM
  108. * bit1 | bit1 bit2 | bit2 | Memory allocation
  109. * ------+------------+------+------------------
  110. * OFF | ON OFF | ON | FCE 0
  111. * OFF | ON OFF | OFF | FCE 1
  112. */
  113. /*
  114. * External interrupt pin settings
  115. *
  116. * IRQX | pin setting | device | level
  117. * ------+--------------------+--------------------+-------
  118. * IRQ0 | ICR1A.IRQ0SA=0010 | SDHI2 card detect | Low
  119. * IRQ6 | ICR1A.IRQ6SA=0011 | Ether(LAN9220) | High
  120. * IRQ7 | ICR1A.IRQ7SA=0010 | LCD Touch Panel | Low
  121. * IRQ8 | ICR2A.IRQ8SA=0010 | MMC/SD card detect | Low
  122. * IRQ9 | ICR2A.IRQ9SA=0010 | KEY(TCA6408) | Low
  123. * IRQ21 | ICR4A.IRQ21SA=0011 | Sensor(ADXL345) | High
  124. * IRQ22 | ICR4A.IRQ22SA=0011 | Sensor(AK8975) | High
  125. */
  126. /*
  127. * USB
  128. *
  129. * USB0 : CN22 : Function
  130. * USB1 : CN31 : Function/Host *1
  131. *
  132. * J30 (for CN31) *1
  133. * ----------+---------------+-------------
  134. * 1-2 short | VBUS 5V | Host
  135. * open | external VBUS | Function
  136. *
  137. * CAUTION
  138. *
  139. * renesas_usbhs driver can use external interrupt mode
  140. * (which come from USB-PHY) or autonomy mode (it use own interrupt)
  141. * for detecting connection/disconnection when Function.
  142. * USB will be power OFF while it has been disconnecting
  143. * if external interrupt mode, and it is always power ON if autonomy mode,
  144. *
  145. * mackerel can not use external interrupt (IRQ7-PORT167) mode on "USB0",
  146. * because Touchscreen is using IRQ7-PORT40.
  147. * It is impossible to use IRQ7 demux on this board.
  148. */
  149. /*
  150. * SDHI0 (CN12)
  151. *
  152. * SW56 : OFF
  153. *
  154. */
  155. /* MMC /SDHI1 (CN7)
  156. *
  157. * I/O voltage : 1.8v
  158. *
  159. * Power voltage : 1.8v or 3.3v
  160. * J22 : select power voltage *1
  161. * 1-2 pin : 1.8v
  162. * 2-3 pin : 3.3v
  163. *
  164. * *1
  165. * Please change J22 depends the card to be used.
  166. * MMC's OCR field set to support either voltage for the card inserted.
  167. *
  168. * SW1 | SW33
  169. * | bit1 | bit2 | bit3 | bit4
  170. * -------------+------+------+------+-------
  171. * MMC0 OFF | OFF | X | ON | X (Use MMCIF)
  172. * SDHI1 OFF | ON | X | OFF | X (Use MFD_SH_MOBILE_SDHI)
  173. *
  174. */
  175. /*
  176. * SDHI2 (CN23)
  177. *
  178. * microSD card sloct
  179. *
  180. */
  181. /*
  182. * FSI - AK4642
  183. *
  184. * it needs amixer settings for playing
  185. *
  186. * amixer set "Headphone" on
  187. * amixer set "HPOUTL Mixer DACH" on
  188. * amixer set "HPOUTR Mixer DACH" on
  189. */
  190. /*
  191. * FIXME !!
  192. *
  193. * gpio_no_direction
  194. * gpio_pull_down
  195. * are quick_hack.
  196. *
  197. * current gpio frame work doesn't have
  198. * the method to control only pull up/down/free.
  199. * this function should be replaced by correct gpio function
  200. */
  201. static void __init gpio_no_direction(u32 addr)
  202. {
  203. __raw_writeb(0x00, addr);
  204. }
  205. static void __init gpio_pull_down(u32 addr)
  206. {
  207. u8 data = __raw_readb(addr);
  208. data &= 0x0F;
  209. data |= 0xA0;
  210. __raw_writeb(data, addr);
  211. }
  212. /* MTD */
  213. static struct mtd_partition nor_flash_partitions[] = {
  214. {
  215. .name = "loader",
  216. .offset = 0x00000000,
  217. .size = 512 * 1024,
  218. .mask_flags = MTD_WRITEABLE,
  219. },
  220. {
  221. .name = "bootenv",
  222. .offset = MTDPART_OFS_APPEND,
  223. .size = 512 * 1024,
  224. .mask_flags = MTD_WRITEABLE,
  225. },
  226. {
  227. .name = "kernel_ro",
  228. .offset = MTDPART_OFS_APPEND,
  229. .size = 8 * 1024 * 1024,
  230. .mask_flags = MTD_WRITEABLE,
  231. },
  232. {
  233. .name = "kernel",
  234. .offset = MTDPART_OFS_APPEND,
  235. .size = 8 * 1024 * 1024,
  236. },
  237. {
  238. .name = "data",
  239. .offset = MTDPART_OFS_APPEND,
  240. .size = MTDPART_SIZ_FULL,
  241. },
  242. };
  243. static struct physmap_flash_data nor_flash_data = {
  244. .width = 2,
  245. .parts = nor_flash_partitions,
  246. .nr_parts = ARRAY_SIZE(nor_flash_partitions),
  247. };
  248. static struct resource nor_flash_resources[] = {
  249. [0] = {
  250. .start = 0x20000000, /* CS0 shadow instead of regular CS0 */
  251. .end = 0x28000000 - 1, /* needed by USB MASK ROM boot */
  252. .flags = IORESOURCE_MEM,
  253. }
  254. };
  255. static struct platform_device nor_flash_device = {
  256. .name = "physmap-flash",
  257. .dev = {
  258. .platform_data = &nor_flash_data,
  259. },
  260. .num_resources = ARRAY_SIZE(nor_flash_resources),
  261. .resource = nor_flash_resources,
  262. };
  263. /* SMSC */
  264. static struct resource smc911x_resources[] = {
  265. {
  266. .start = 0x14000000,
  267. .end = 0x16000000 - 1,
  268. .flags = IORESOURCE_MEM,
  269. }, {
  270. .start = evt2irq(0x02c0) /* IRQ6A */,
  271. .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
  272. },
  273. };
  274. static struct smsc911x_platform_config smsc911x_info = {
  275. .flags = SMSC911X_USE_16BIT | SMSC911X_SAVE_MAC_ADDRESS,
  276. .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
  277. .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
  278. };
  279. static struct platform_device smc911x_device = {
  280. .name = "smsc911x",
  281. .id = -1,
  282. .num_resources = ARRAY_SIZE(smc911x_resources),
  283. .resource = smc911x_resources,
  284. .dev = {
  285. .platform_data = &smsc911x_info,
  286. },
  287. };
  288. /* MERAM */
  289. static struct sh_mobile_meram_info mackerel_meram_info = {
  290. .addr_mode = SH_MOBILE_MERAM_MODE1,
  291. };
  292. static struct resource meram_resources[] = {
  293. [0] = {
  294. .name = "MERAM",
  295. .start = 0xe8000000,
  296. .end = 0xe81fffff,
  297. .flags = IORESOURCE_MEM,
  298. },
  299. };
  300. static struct platform_device meram_device = {
  301. .name = "sh_mobile_meram",
  302. .id = 0,
  303. .num_resources = ARRAY_SIZE(meram_resources),
  304. .resource = meram_resources,
  305. .dev = {
  306. .platform_data = &mackerel_meram_info,
  307. },
  308. };
  309. /* LCDC */
  310. static struct fb_videomode mackerel_lcdc_modes[] = {
  311. {
  312. .name = "WVGA Panel",
  313. .xres = 800,
  314. .yres = 480,
  315. .left_margin = 220,
  316. .right_margin = 110,
  317. .hsync_len = 70,
  318. .upper_margin = 20,
  319. .lower_margin = 5,
  320. .vsync_len = 5,
  321. .sync = 0,
  322. },
  323. };
  324. static int mackerel_set_brightness(int brightness)
  325. {
  326. gpio_set_value(GPIO_PORT31, brightness);
  327. return 0;
  328. }
  329. static int mackerel_get_brightness(void)
  330. {
  331. return gpio_get_value(GPIO_PORT31);
  332. }
  333. static struct sh_mobile_meram_cfg lcd_meram_cfg = {
  334. .icb[0] = {
  335. .marker_icb = 28,
  336. .cache_icb = 24,
  337. .meram_offset = 0x0,
  338. .meram_size = 0x40,
  339. },
  340. .icb[1] = {
  341. .marker_icb = 29,
  342. .cache_icb = 25,
  343. .meram_offset = 0x40,
  344. .meram_size = 0x40,
  345. },
  346. };
  347. static struct sh_mobile_lcdc_info lcdc_info = {
  348. .meram_dev = &mackerel_meram_info,
  349. .clock_source = LCDC_CLK_BUS,
  350. .ch[0] = {
  351. .chan = LCDC_CHAN_MAINLCD,
  352. .fourcc = V4L2_PIX_FMT_RGB565,
  353. .lcd_cfg = mackerel_lcdc_modes,
  354. .num_cfg = ARRAY_SIZE(mackerel_lcdc_modes),
  355. .interface_type = RGB24,
  356. .clock_divider = 3,
  357. .flags = 0,
  358. .lcd_size_cfg.width = 152,
  359. .lcd_size_cfg.height = 91,
  360. .bl_info = {
  361. .name = "sh_mobile_lcdc_bl",
  362. .max_brightness = 1,
  363. .set_brightness = mackerel_set_brightness,
  364. .get_brightness = mackerel_get_brightness,
  365. },
  366. .meram_cfg = &lcd_meram_cfg,
  367. }
  368. };
  369. static struct resource lcdc_resources[] = {
  370. [0] = {
  371. .name = "LCDC",
  372. .start = 0xfe940000,
  373. .end = 0xfe943fff,
  374. .flags = IORESOURCE_MEM,
  375. },
  376. [1] = {
  377. .start = intcs_evt2irq(0x580),
  378. .flags = IORESOURCE_IRQ,
  379. },
  380. };
  381. static struct platform_device lcdc_device = {
  382. .name = "sh_mobile_lcdc_fb",
  383. .num_resources = ARRAY_SIZE(lcdc_resources),
  384. .resource = lcdc_resources,
  385. .dev = {
  386. .platform_data = &lcdc_info,
  387. .coherent_dma_mask = ~0,
  388. },
  389. };
  390. /* HDMI */
  391. static struct sh_mobile_hdmi_info hdmi_info = {
  392. .flags = HDMI_SND_SRC_SPDIF,
  393. };
  394. static struct resource hdmi_resources[] = {
  395. [0] = {
  396. .name = "HDMI",
  397. .start = 0xe6be0000,
  398. .end = 0xe6be00ff,
  399. .flags = IORESOURCE_MEM,
  400. },
  401. [1] = {
  402. /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
  403. .start = evt2irq(0x17e0),
  404. .flags = IORESOURCE_IRQ,
  405. },
  406. };
  407. static struct platform_device hdmi_device = {
  408. .name = "sh-mobile-hdmi",
  409. .num_resources = ARRAY_SIZE(hdmi_resources),
  410. .resource = hdmi_resources,
  411. .id = -1,
  412. .dev = {
  413. .platform_data = &hdmi_info,
  414. },
  415. };
  416. static struct sh_mobile_meram_cfg hdmi_meram_cfg = {
  417. .icb[0] = {
  418. .marker_icb = 30,
  419. .cache_icb = 26,
  420. .meram_offset = 0x80,
  421. .meram_size = 0x100,
  422. },
  423. .icb[1] = {
  424. .marker_icb = 31,
  425. .cache_icb = 27,
  426. .meram_offset = 0x180,
  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 = ~0,
  463. },
  464. };
  465. static struct platform_device fsi_hdmi_device = {
  466. .name = "sh_fsi2_b_hdmi",
  467. };
  468. static void __init hdmi_init_pm_clock(void)
  469. {
  470. struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
  471. int ret;
  472. long rate;
  473. if (IS_ERR(hdmi_ick)) {
  474. ret = PTR_ERR(hdmi_ick);
  475. pr_err("Cannot get HDMI ICK: %d\n", ret);
  476. goto out;
  477. }
  478. ret = clk_set_parent(&sh7372_pllc2_clk, &sh7372_dv_clki_div2_clk);
  479. if (ret < 0) {
  480. pr_err("Cannot set PLLC2 parent: %d, %d users\n",
  481. ret, sh7372_pllc2_clk.usecount);
  482. goto out;
  483. }
  484. pr_debug("PLLC2 initial frequency %lu\n",
  485. clk_get_rate(&sh7372_pllc2_clk));
  486. rate = clk_round_rate(&sh7372_pllc2_clk, 594000000);
  487. if (rate < 0) {
  488. pr_err("Cannot get suitable rate: %ld\n", rate);
  489. ret = rate;
  490. goto out;
  491. }
  492. ret = clk_set_rate(&sh7372_pllc2_clk, rate);
  493. if (ret < 0) {
  494. pr_err("Cannot set rate %ld: %d\n", rate, ret);
  495. goto out;
  496. }
  497. pr_debug("PLLC2 set frequency %lu\n", rate);
  498. ret = clk_set_parent(hdmi_ick, &sh7372_pllc2_clk);
  499. if (ret < 0)
  500. pr_err("Cannot set HDMI parent: %d\n", ret);
  501. out:
  502. if (!IS_ERR(hdmi_ick))
  503. clk_put(hdmi_ick);
  504. }
  505. /* USBHS0 is connected to CN22 which takes a USB Mini-B plug
  506. *
  507. * The sh7372 SoC has IRQ7 set aside for USBHS0 hotplug,
  508. * but on this particular board IRQ7 is already used by
  509. * the touch screen. This leaves us with software polling.
  510. */
  511. #define USBHS0_POLL_INTERVAL (HZ * 5)
  512. struct usbhs_private {
  513. unsigned int usbphyaddr;
  514. unsigned int usbcrcaddr;
  515. struct renesas_usbhs_platform_info info;
  516. struct delayed_work work;
  517. struct platform_device *pdev;
  518. };
  519. #define usbhs_get_priv(pdev) \
  520. container_of(renesas_usbhs_get_info(pdev), \
  521. struct usbhs_private, info)
  522. #define usbhs_is_connected(priv) \
  523. (!((1 << 7) & __raw_readw(priv->usbcrcaddr)))
  524. static int usbhs_get_vbus(struct platform_device *pdev)
  525. {
  526. return usbhs_is_connected(usbhs_get_priv(pdev));
  527. }
  528. static void usbhs_phy_reset(struct platform_device *pdev)
  529. {
  530. struct usbhs_private *priv = usbhs_get_priv(pdev);
  531. /* init phy */
  532. __raw_writew(0x8a0a, priv->usbcrcaddr);
  533. }
  534. static int usbhs0_get_id(struct platform_device *pdev)
  535. {
  536. return USBHS_GADGET;
  537. }
  538. static void usbhs0_work_function(struct work_struct *work)
  539. {
  540. struct usbhs_private *priv = container_of(work, struct usbhs_private,
  541. work.work);
  542. renesas_usbhs_call_notify_hotplug(priv->pdev);
  543. schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
  544. }
  545. static int usbhs0_hardware_init(struct platform_device *pdev)
  546. {
  547. struct usbhs_private *priv = usbhs_get_priv(pdev);
  548. priv->pdev = pdev;
  549. INIT_DELAYED_WORK(&priv->work, usbhs0_work_function);
  550. schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
  551. return 0;
  552. }
  553. static void usbhs0_hardware_exit(struct platform_device *pdev)
  554. {
  555. struct usbhs_private *priv = usbhs_get_priv(pdev);
  556. cancel_delayed_work_sync(&priv->work);
  557. }
  558. static struct usbhs_private usbhs0_private = {
  559. .usbcrcaddr = 0xe605810c, /* USBCR2 */
  560. .info = {
  561. .platform_callback = {
  562. .hardware_init = usbhs0_hardware_init,
  563. .hardware_exit = usbhs0_hardware_exit,
  564. .phy_reset = usbhs_phy_reset,
  565. .get_id = usbhs0_get_id,
  566. .get_vbus = usbhs_get_vbus,
  567. },
  568. .driver_param = {
  569. .buswait_bwait = 4,
  570. .d0_tx_id = SHDMA_SLAVE_USB0_TX,
  571. .d1_rx_id = SHDMA_SLAVE_USB0_RX,
  572. },
  573. },
  574. };
  575. static struct resource usbhs0_resources[] = {
  576. [0] = {
  577. .name = "USBHS0",
  578. .start = 0xe6890000,
  579. .end = 0xe68900e6 - 1,
  580. .flags = IORESOURCE_MEM,
  581. },
  582. [1] = {
  583. .start = evt2irq(0x1ca0) /* USB0_USB0I0 */,
  584. .flags = IORESOURCE_IRQ,
  585. },
  586. };
  587. static struct platform_device usbhs0_device = {
  588. .name = "renesas_usbhs",
  589. .id = 0,
  590. .dev = {
  591. .platform_data = &usbhs0_private.info,
  592. },
  593. .num_resources = ARRAY_SIZE(usbhs0_resources),
  594. .resource = usbhs0_resources,
  595. };
  596. /* USBHS1 is connected to CN31 which takes a USB Mini-AB plug
  597. *
  598. * Use J30 to select between Host and Function. This setting
  599. * can however not be detected by software. Hotplug of USBHS1
  600. * is provided via IRQ8.
  601. *
  602. * Current USB1 works as "USB Host".
  603. * - set J30 "short"
  604. *
  605. * If you want to use it as "USB gadget",
  606. * - J30 "open"
  607. * - modify usbhs1_get_id() USBHS_HOST -> USBHS_GADGET
  608. * - add .get_vbus = usbhs_get_vbus in usbhs1_private
  609. */
  610. #define IRQ8 evt2irq(0x0300)
  611. #define USB_PHY_MODE (1 << 4)
  612. #define USB_PHY_INT_EN ((1 << 3) | (1 << 2))
  613. #define USB_PHY_ON (1 << 1)
  614. #define USB_PHY_OFF (1 << 0)
  615. #define USB_PHY_INT_CLR (USB_PHY_ON | USB_PHY_OFF)
  616. static irqreturn_t usbhs1_interrupt(int irq, void *data)
  617. {
  618. struct platform_device *pdev = data;
  619. struct usbhs_private *priv = usbhs_get_priv(pdev);
  620. dev_dbg(&pdev->dev, "%s\n", __func__);
  621. renesas_usbhs_call_notify_hotplug(pdev);
  622. /* clear status */
  623. __raw_writew(__raw_readw(priv->usbphyaddr) | USB_PHY_INT_CLR,
  624. priv->usbphyaddr);
  625. return IRQ_HANDLED;
  626. }
  627. static int usbhs1_hardware_init(struct platform_device *pdev)
  628. {
  629. struct usbhs_private *priv = usbhs_get_priv(pdev);
  630. int ret;
  631. /* clear interrupt status */
  632. __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
  633. ret = request_irq(IRQ8, usbhs1_interrupt, IRQF_TRIGGER_HIGH,
  634. dev_name(&pdev->dev), pdev);
  635. if (ret) {
  636. dev_err(&pdev->dev, "request_irq err\n");
  637. return ret;
  638. }
  639. /* enable USB phy interrupt */
  640. __raw_writew(USB_PHY_MODE | USB_PHY_INT_EN, priv->usbphyaddr);
  641. return 0;
  642. }
  643. static void usbhs1_hardware_exit(struct platform_device *pdev)
  644. {
  645. struct usbhs_private *priv = usbhs_get_priv(pdev);
  646. /* clear interrupt status */
  647. __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
  648. free_irq(IRQ8, pdev);
  649. }
  650. static int usbhs1_get_id(struct platform_device *pdev)
  651. {
  652. return USBHS_HOST;
  653. }
  654. static u32 usbhs1_pipe_cfg[] = {
  655. USB_ENDPOINT_XFER_CONTROL,
  656. USB_ENDPOINT_XFER_ISOC,
  657. USB_ENDPOINT_XFER_ISOC,
  658. USB_ENDPOINT_XFER_BULK,
  659. USB_ENDPOINT_XFER_BULK,
  660. USB_ENDPOINT_XFER_BULK,
  661. USB_ENDPOINT_XFER_INT,
  662. USB_ENDPOINT_XFER_INT,
  663. USB_ENDPOINT_XFER_INT,
  664. USB_ENDPOINT_XFER_BULK,
  665. USB_ENDPOINT_XFER_BULK,
  666. USB_ENDPOINT_XFER_BULK,
  667. USB_ENDPOINT_XFER_BULK,
  668. USB_ENDPOINT_XFER_BULK,
  669. USB_ENDPOINT_XFER_BULK,
  670. USB_ENDPOINT_XFER_BULK,
  671. };
  672. static struct usbhs_private usbhs1_private = {
  673. .usbphyaddr = 0xe60581e2, /* USBPHY1INTAP */
  674. .usbcrcaddr = 0xe6058130, /* USBCR4 */
  675. .info = {
  676. .platform_callback = {
  677. .hardware_init = usbhs1_hardware_init,
  678. .hardware_exit = usbhs1_hardware_exit,
  679. .get_id = usbhs1_get_id,
  680. .phy_reset = usbhs_phy_reset,
  681. },
  682. .driver_param = {
  683. .buswait_bwait = 4,
  684. .has_otg = 1,
  685. .pipe_type = usbhs1_pipe_cfg,
  686. .pipe_size = ARRAY_SIZE(usbhs1_pipe_cfg),
  687. .d0_tx_id = SHDMA_SLAVE_USB1_TX,
  688. .d1_rx_id = SHDMA_SLAVE_USB1_RX,
  689. },
  690. },
  691. };
  692. static struct resource usbhs1_resources[] = {
  693. [0] = {
  694. .name = "USBHS1",
  695. .start = 0xe68b0000,
  696. .end = 0xe68b00e6 - 1,
  697. .flags = IORESOURCE_MEM,
  698. },
  699. [1] = {
  700. .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
  701. .flags = IORESOURCE_IRQ,
  702. },
  703. };
  704. static struct platform_device usbhs1_device = {
  705. .name = "renesas_usbhs",
  706. .id = 1,
  707. .dev = {
  708. .platform_data = &usbhs1_private.info,
  709. },
  710. .num_resources = ARRAY_SIZE(usbhs1_resources),
  711. .resource = usbhs1_resources,
  712. };
  713. /* LED */
  714. static struct gpio_led mackerel_leds[] = {
  715. {
  716. .name = "led0",
  717. .gpio = GPIO_PORT0,
  718. .default_state = LEDS_GPIO_DEFSTATE_ON,
  719. },
  720. {
  721. .name = "led1",
  722. .gpio = GPIO_PORT1,
  723. .default_state = LEDS_GPIO_DEFSTATE_ON,
  724. },
  725. {
  726. .name = "led2",
  727. .gpio = GPIO_PORT2,
  728. .default_state = LEDS_GPIO_DEFSTATE_ON,
  729. },
  730. {
  731. .name = "led3",
  732. .gpio = GPIO_PORT159,
  733. .default_state = LEDS_GPIO_DEFSTATE_ON,
  734. }
  735. };
  736. static struct gpio_led_platform_data mackerel_leds_pdata = {
  737. .leds = mackerel_leds,
  738. .num_leds = ARRAY_SIZE(mackerel_leds),
  739. };
  740. static struct platform_device leds_device = {
  741. .name = "leds-gpio",
  742. .id = 0,
  743. .dev = {
  744. .platform_data = &mackerel_leds_pdata,
  745. },
  746. };
  747. /* FSI */
  748. #define IRQ_FSI evt2irq(0x1840)
  749. static int __fsi_set_round_rate(struct clk *clk, long rate, int enable)
  750. {
  751. int ret;
  752. if (rate <= 0)
  753. return 0;
  754. if (!enable) {
  755. clk_disable(clk);
  756. return 0;
  757. }
  758. ret = clk_set_rate(clk, clk_round_rate(clk, rate));
  759. if (ret < 0)
  760. return ret;
  761. return clk_enable(clk);
  762. }
  763. static int fsi_set_rate(struct device *dev, int is_porta, int rate, int enable)
  764. {
  765. struct clk *fsib_clk;
  766. struct clk *fdiv_clk = &sh7372_fsidivb_clk;
  767. long fsib_rate = 0;
  768. long fdiv_rate = 0;
  769. int ackmd_bpfmd;
  770. int ret;
  771. /* FSIA is slave mode. nothing to do here */
  772. if (is_porta)
  773. return 0;
  774. /* clock start */
  775. switch (rate) {
  776. case 44100:
  777. fsib_rate = rate * 256;
  778. ackmd_bpfmd = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
  779. break;
  780. case 48000:
  781. fsib_rate = 85428000; /* around 48kHz x 256 x 7 */
  782. fdiv_rate = rate * 256;
  783. ackmd_bpfmd = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
  784. break;
  785. default:
  786. pr_err("unsupported rate in FSI2 port B\n");
  787. return -EINVAL;
  788. }
  789. /* FSI B setting */
  790. fsib_clk = clk_get(dev, "ickb");
  791. if (IS_ERR(fsib_clk))
  792. return -EIO;
  793. /* fsib */
  794. ret = __fsi_set_round_rate(fsib_clk, fsib_rate, enable);
  795. if (ret < 0)
  796. goto fsi_set_rate_end;
  797. /* FSI DIV */
  798. ret = __fsi_set_round_rate(fdiv_clk, fdiv_rate, enable);
  799. if (ret < 0) {
  800. /* disable FSI B */
  801. if (enable)
  802. __fsi_set_round_rate(fsib_clk, fsib_rate, 0);
  803. goto fsi_set_rate_end;
  804. }
  805. ret = ackmd_bpfmd;
  806. fsi_set_rate_end:
  807. clk_put(fsib_clk);
  808. return ret;
  809. }
  810. static struct sh_fsi_platform_info fsi_info = {
  811. .porta_flags = SH_FSI_BRS_INV,
  812. .portb_flags = SH_FSI_BRS_INV |
  813. SH_FSI_BRM_INV |
  814. SH_FSI_LRS_INV |
  815. SH_FSI_FMT_SPDIF,
  816. .set_rate = fsi_set_rate,
  817. };
  818. static struct resource fsi_resources[] = {
  819. [0] = {
  820. .name = "FSI",
  821. .start = 0xFE3C0000,
  822. .end = 0xFE3C0400 - 1,
  823. .flags = IORESOURCE_MEM,
  824. },
  825. [1] = {
  826. .start = IRQ_FSI,
  827. .flags = IORESOURCE_IRQ,
  828. },
  829. };
  830. static struct platform_device fsi_device = {
  831. .name = "sh_fsi2",
  832. .id = -1,
  833. .num_resources = ARRAY_SIZE(fsi_resources),
  834. .resource = fsi_resources,
  835. .dev = {
  836. .platform_data = &fsi_info,
  837. },
  838. };
  839. static struct fsi_ak4642_info fsi2_ak4643_info = {
  840. .name = "AK4643",
  841. .card = "FSI2A-AK4643",
  842. .cpu_dai = "fsia-dai",
  843. .codec = "ak4642-codec.0-0013",
  844. .platform = "sh_fsi2",
  845. .id = FSI_PORT_A,
  846. };
  847. static struct platform_device fsi_ak4643_device = {
  848. .name = "fsi-ak4642-audio",
  849. .dev = {
  850. .platform_data = &fsi2_ak4643_info,
  851. },
  852. };
  853. /*
  854. * The card detect pin of the top SD/MMC slot (CN7) is active low and is
  855. * connected to GPIO A22 of SH7372 (GPIO_PORT41).
  856. */
  857. static int slot_cn7_get_cd(struct platform_device *pdev)
  858. {
  859. return !gpio_get_value(GPIO_PORT41);
  860. }
  861. /* SDHI0 */
  862. static irqreturn_t mackerel_sdhi0_gpio_cd(int irq, void *arg)
  863. {
  864. struct device *dev = arg;
  865. struct sh_mobile_sdhi_info *info = dev->platform_data;
  866. struct tmio_mmc_data *pdata = info->pdata;
  867. tmio_mmc_cd_wakeup(pdata);
  868. return IRQ_HANDLED;
  869. }
  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_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
  874. };
  875. static struct resource sdhi0_resources[] = {
  876. [0] = {
  877. .name = "SDHI0",
  878. .start = 0xe6850000,
  879. .end = 0xe68500ff,
  880. .flags = IORESOURCE_MEM,
  881. },
  882. [1] = {
  883. .start = evt2irq(0x0e00) /* SDHI0_SDHI0I0 */,
  884. .flags = IORESOURCE_IRQ,
  885. },
  886. [2] = {
  887. .start = evt2irq(0x0e20) /* SDHI0_SDHI0I1 */,
  888. .flags = IORESOURCE_IRQ,
  889. },
  890. [3] = {
  891. .start = evt2irq(0x0e40) /* SDHI0_SDHI0I2 */,
  892. .flags = IORESOURCE_IRQ,
  893. },
  894. };
  895. static struct platform_device sdhi0_device = {
  896. .name = "sh_mobile_sdhi",
  897. .num_resources = ARRAY_SIZE(sdhi0_resources),
  898. .resource = sdhi0_resources,
  899. .id = 0,
  900. .dev = {
  901. .platform_data = &sdhi0_info,
  902. },
  903. };
  904. #if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE)
  905. /* SDHI1 */
  906. static struct sh_mobile_sdhi_info sdhi1_info = {
  907. .dma_slave_tx = SHDMA_SLAVE_SDHI1_TX,
  908. .dma_slave_rx = SHDMA_SLAVE_SDHI1_RX,
  909. .tmio_ocr_mask = MMC_VDD_165_195,
  910. .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE,
  911. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
  912. MMC_CAP_NEEDS_POLL,
  913. .get_cd = slot_cn7_get_cd,
  914. };
  915. static struct resource sdhi1_resources[] = {
  916. [0] = {
  917. .name = "SDHI1",
  918. .start = 0xe6860000,
  919. .end = 0xe68600ff,
  920. .flags = IORESOURCE_MEM,
  921. },
  922. [1] = {
  923. .name = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
  924. .start = evt2irq(0x0e80), /* SDHI1_SDHI1I0 */
  925. .flags = IORESOURCE_IRQ,
  926. },
  927. [2] = {
  928. .name = SH_MOBILE_SDHI_IRQ_SDCARD,
  929. .start = evt2irq(0x0ea0), /* SDHI1_SDHI1I1 */
  930. .flags = IORESOURCE_IRQ,
  931. },
  932. [3] = {
  933. .name = SH_MOBILE_SDHI_IRQ_SDIO,
  934. .start = evt2irq(0x0ec0), /* SDHI1_SDHI1I2 */
  935. .flags = IORESOURCE_IRQ,
  936. },
  937. };
  938. static struct platform_device sdhi1_device = {
  939. .name = "sh_mobile_sdhi",
  940. .num_resources = ARRAY_SIZE(sdhi1_resources),
  941. .resource = sdhi1_resources,
  942. .id = 1,
  943. .dev = {
  944. .platform_data = &sdhi1_info,
  945. },
  946. };
  947. #endif
  948. /*
  949. * The card detect pin of the top SD/MMC slot (CN23) is active low and is
  950. * connected to GPIO SCIFB_SCK of SH7372 (GPIO_PORT162).
  951. */
  952. static int slot_cn23_get_cd(struct platform_device *pdev)
  953. {
  954. return !gpio_get_value(GPIO_PORT162);
  955. }
  956. /* SDHI2 */
  957. static struct sh_mobile_sdhi_info sdhi2_info = {
  958. .dma_slave_tx = SHDMA_SLAVE_SDHI2_TX,
  959. .dma_slave_rx = SHDMA_SLAVE_SDHI2_RX,
  960. .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE,
  961. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
  962. MMC_CAP_NEEDS_POLL,
  963. .get_cd = slot_cn23_get_cd,
  964. };
  965. static struct resource sdhi2_resources[] = {
  966. [0] = {
  967. .name = "SDHI2",
  968. .start = 0xe6870000,
  969. .end = 0xe68700ff,
  970. .flags = IORESOURCE_MEM,
  971. },
  972. [1] = {
  973. .name = SH_MOBILE_SDHI_IRQ_CARD_DETECT,
  974. .start = evt2irq(0x1200), /* SDHI2_SDHI2I0 */
  975. .flags = IORESOURCE_IRQ,
  976. },
  977. [2] = {
  978. .name = SH_MOBILE_SDHI_IRQ_SDCARD,
  979. .start = evt2irq(0x1220), /* SDHI2_SDHI2I1 */
  980. .flags = IORESOURCE_IRQ,
  981. },
  982. [3] = {
  983. .name = SH_MOBILE_SDHI_IRQ_SDIO,
  984. .start = evt2irq(0x1240), /* SDHI2_SDHI2I2 */
  985. .flags = IORESOURCE_IRQ,
  986. },
  987. };
  988. static struct platform_device sdhi2_device = {
  989. .name = "sh_mobile_sdhi",
  990. .num_resources = ARRAY_SIZE(sdhi2_resources),
  991. .resource = sdhi2_resources,
  992. .id = 2,
  993. .dev = {
  994. .platform_data = &sdhi2_info,
  995. },
  996. };
  997. /* SH_MMCIF */
  998. static struct resource sh_mmcif_resources[] = {
  999. [0] = {
  1000. .name = "MMCIF",
  1001. .start = 0xE6BD0000,
  1002. .end = 0xE6BD00FF,
  1003. .flags = IORESOURCE_MEM,
  1004. },
  1005. [1] = {
  1006. /* MMC ERR */
  1007. .start = evt2irq(0x1ac0),
  1008. .flags = IORESOURCE_IRQ,
  1009. },
  1010. [2] = {
  1011. /* MMC NOR */
  1012. .start = evt2irq(0x1ae0),
  1013. .flags = IORESOURCE_IRQ,
  1014. },
  1015. };
  1016. static struct sh_mmcif_plat_data sh_mmcif_plat = {
  1017. .sup_pclk = 0,
  1018. .ocr = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
  1019. .caps = MMC_CAP_4_BIT_DATA |
  1020. MMC_CAP_8_BIT_DATA |
  1021. MMC_CAP_NEEDS_POLL,
  1022. .get_cd = slot_cn7_get_cd,
  1023. .slave_id_tx = SHDMA_SLAVE_MMCIF_TX,
  1024. .slave_id_rx = SHDMA_SLAVE_MMCIF_RX,
  1025. };
  1026. static struct platform_device sh_mmcif_device = {
  1027. .name = "sh_mmcif",
  1028. .id = 0,
  1029. .dev = {
  1030. .dma_mask = NULL,
  1031. .coherent_dma_mask = 0xffffffff,
  1032. .platform_data = &sh_mmcif_plat,
  1033. },
  1034. .num_resources = ARRAY_SIZE(sh_mmcif_resources),
  1035. .resource = sh_mmcif_resources,
  1036. };
  1037. static int mackerel_camera_add(struct soc_camera_device *icd);
  1038. static void mackerel_camera_del(struct soc_camera_device *icd);
  1039. static int camera_set_capture(struct soc_camera_platform_info *info,
  1040. int enable)
  1041. {
  1042. return 0; /* camera sensor always enabled */
  1043. }
  1044. static struct soc_camera_platform_info camera_info = {
  1045. .format_name = "UYVY",
  1046. .format_depth = 16,
  1047. .format = {
  1048. .code = V4L2_MBUS_FMT_UYVY8_2X8,
  1049. .colorspace = V4L2_COLORSPACE_SMPTE170M,
  1050. .field = V4L2_FIELD_NONE,
  1051. .width = 640,
  1052. .height = 480,
  1053. },
  1054. .mbus_param = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
  1055. V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
  1056. V4L2_MBUS_DATA_ACTIVE_HIGH,
  1057. .mbus_type = V4L2_MBUS_PARALLEL,
  1058. .set_capture = camera_set_capture,
  1059. };
  1060. static struct soc_camera_link camera_link = {
  1061. .bus_id = 0,
  1062. .add_device = mackerel_camera_add,
  1063. .del_device = mackerel_camera_del,
  1064. .module_name = "soc_camera_platform",
  1065. .priv = &camera_info,
  1066. };
  1067. static struct platform_device *camera_device;
  1068. static void mackerel_camera_release(struct device *dev)
  1069. {
  1070. soc_camera_platform_release(&camera_device);
  1071. }
  1072. static int mackerel_camera_add(struct soc_camera_device *icd)
  1073. {
  1074. return soc_camera_platform_add(icd, &camera_device, &camera_link,
  1075. mackerel_camera_release, 0);
  1076. }
  1077. static void mackerel_camera_del(struct soc_camera_device *icd)
  1078. {
  1079. soc_camera_platform_del(icd, camera_device, &camera_link);
  1080. }
  1081. static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
  1082. .flags = SH_CEU_FLAG_USE_8BIT_BUS,
  1083. };
  1084. static struct resource ceu_resources[] = {
  1085. [0] = {
  1086. .name = "CEU",
  1087. .start = 0xfe910000,
  1088. .end = 0xfe91009f,
  1089. .flags = IORESOURCE_MEM,
  1090. },
  1091. [1] = {
  1092. .start = intcs_evt2irq(0x880),
  1093. .flags = IORESOURCE_IRQ,
  1094. },
  1095. [2] = {
  1096. /* place holder for contiguous memory */
  1097. },
  1098. };
  1099. static struct platform_device ceu_device = {
  1100. .name = "sh_mobile_ceu",
  1101. .id = 0, /* "ceu0" clock */
  1102. .num_resources = ARRAY_SIZE(ceu_resources),
  1103. .resource = ceu_resources,
  1104. .dev = {
  1105. .platform_data = &sh_mobile_ceu_info,
  1106. .coherent_dma_mask = 0xffffffff,
  1107. },
  1108. };
  1109. static struct platform_device mackerel_camera = {
  1110. .name = "soc-camera-pdrv",
  1111. .id = 0,
  1112. .dev = {
  1113. .platform_data = &camera_link,
  1114. },
  1115. };
  1116. static struct platform_device *mackerel_devices[] __initdata = {
  1117. &nor_flash_device,
  1118. &smc911x_device,
  1119. &lcdc_device,
  1120. &usbhs1_device,
  1121. &usbhs0_device,
  1122. &leds_device,
  1123. &fsi_device,
  1124. &fsi_ak4643_device,
  1125. &fsi_hdmi_device,
  1126. &sdhi0_device,
  1127. #if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE)
  1128. &sdhi1_device,
  1129. #endif
  1130. &sdhi2_device,
  1131. &sh_mmcif_device,
  1132. &ceu_device,
  1133. &mackerel_camera,
  1134. &hdmi_device,
  1135. &hdmi_lcdc_device,
  1136. &meram_device,
  1137. };
  1138. /* Keypad Initialization */
  1139. #define KEYPAD_BUTTON(ev_type, ev_code, act_low) \
  1140. { \
  1141. .type = ev_type, \
  1142. .code = ev_code, \
  1143. .active_low = act_low, \
  1144. }
  1145. #define KEYPAD_BUTTON_LOW(event_code) KEYPAD_BUTTON(EV_KEY, event_code, 1)
  1146. static struct tca6416_button mackerel_gpio_keys[] = {
  1147. KEYPAD_BUTTON_LOW(KEY_HOME),
  1148. KEYPAD_BUTTON_LOW(KEY_MENU),
  1149. KEYPAD_BUTTON_LOW(KEY_BACK),
  1150. KEYPAD_BUTTON_LOW(KEY_POWER),
  1151. };
  1152. static struct tca6416_keys_platform_data mackerel_tca6416_keys_info = {
  1153. .buttons = mackerel_gpio_keys,
  1154. .nbuttons = ARRAY_SIZE(mackerel_gpio_keys),
  1155. .rep = 1,
  1156. .use_polling = 0,
  1157. .pinmask = 0x000F,
  1158. };
  1159. /* I2C */
  1160. #define IRQ7 evt2irq(0x02e0)
  1161. #define IRQ9 evt2irq(0x0320)
  1162. static struct i2c_board_info i2c0_devices[] = {
  1163. {
  1164. I2C_BOARD_INFO("ak4643", 0x13),
  1165. },
  1166. /* Keypad */
  1167. {
  1168. I2C_BOARD_INFO("tca6408-keys", 0x20),
  1169. .platform_data = &mackerel_tca6416_keys_info,
  1170. .irq = IRQ9,
  1171. },
  1172. /* Touchscreen */
  1173. {
  1174. I2C_BOARD_INFO("st1232-ts", 0x55),
  1175. .irq = IRQ7,
  1176. },
  1177. };
  1178. #define IRQ21 evt2irq(0x32a0)
  1179. static struct i2c_board_info i2c1_devices[] = {
  1180. /* Accelerometer */
  1181. {
  1182. I2C_BOARD_INFO("adxl34x", 0x53),
  1183. .irq = IRQ21,
  1184. },
  1185. };
  1186. static struct map_desc mackerel_io_desc[] __initdata = {
  1187. /* create a 1:1 entity map for 0xe6xxxxxx
  1188. * used by CPGA, INTC and PFC.
  1189. */
  1190. {
  1191. .virtual = 0xe6000000,
  1192. .pfn = __phys_to_pfn(0xe6000000),
  1193. .length = 256 << 20,
  1194. .type = MT_DEVICE_NONSHARED
  1195. },
  1196. };
  1197. static void __init mackerel_map_io(void)
  1198. {
  1199. iotable_init(mackerel_io_desc, ARRAY_SIZE(mackerel_io_desc));
  1200. /* setup early devices and console here as well */
  1201. sh7372_add_early_devices();
  1202. shmobile_setup_console();
  1203. }
  1204. #define GPIO_PORT9CR 0xE6051009
  1205. #define GPIO_PORT10CR 0xE605100A
  1206. #define GPIO_PORT167CR 0xE60520A7
  1207. #define GPIO_PORT168CR 0xE60520A8
  1208. #define SRCR4 0xe61580bc
  1209. #define USCCR1 0xE6058144
  1210. static void __init mackerel_init(void)
  1211. {
  1212. u32 srcr4;
  1213. struct clk *clk;
  1214. int ret;
  1215. sh7372_pinmux_init();
  1216. /* enable SCIFA0 */
  1217. gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
  1218. gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
  1219. /* enable SMSC911X */
  1220. gpio_request(GPIO_FN_CS5A, NULL);
  1221. gpio_request(GPIO_FN_IRQ6_39, NULL);
  1222. /* LCDC */
  1223. gpio_request(GPIO_FN_LCDD23, NULL);
  1224. gpio_request(GPIO_FN_LCDD22, NULL);
  1225. gpio_request(GPIO_FN_LCDD21, NULL);
  1226. gpio_request(GPIO_FN_LCDD20, NULL);
  1227. gpio_request(GPIO_FN_LCDD19, NULL);
  1228. gpio_request(GPIO_FN_LCDD18, NULL);
  1229. gpio_request(GPIO_FN_LCDD17, NULL);
  1230. gpio_request(GPIO_FN_LCDD16, NULL);
  1231. gpio_request(GPIO_FN_LCDD15, NULL);
  1232. gpio_request(GPIO_FN_LCDD14, NULL);
  1233. gpio_request(GPIO_FN_LCDD13, NULL);
  1234. gpio_request(GPIO_FN_LCDD12, NULL);
  1235. gpio_request(GPIO_FN_LCDD11, NULL);
  1236. gpio_request(GPIO_FN_LCDD10, NULL);
  1237. gpio_request(GPIO_FN_LCDD9, NULL);
  1238. gpio_request(GPIO_FN_LCDD8, NULL);
  1239. gpio_request(GPIO_FN_LCDD7, NULL);
  1240. gpio_request(GPIO_FN_LCDD6, NULL);
  1241. gpio_request(GPIO_FN_LCDD5, NULL);
  1242. gpio_request(GPIO_FN_LCDD4, NULL);
  1243. gpio_request(GPIO_FN_LCDD3, NULL);
  1244. gpio_request(GPIO_FN_LCDD2, NULL);
  1245. gpio_request(GPIO_FN_LCDD1, NULL);
  1246. gpio_request(GPIO_FN_LCDD0, NULL);
  1247. gpio_request(GPIO_FN_LCDDISP, NULL);
  1248. gpio_request(GPIO_FN_LCDDCK, NULL);
  1249. gpio_request(GPIO_PORT31, NULL); /* backlight */
  1250. gpio_direction_output(GPIO_PORT31, 0); /* off by default */
  1251. gpio_request(GPIO_PORT151, NULL); /* LCDDON */
  1252. gpio_direction_output(GPIO_PORT151, 1);
  1253. /* USBHS0 */
  1254. gpio_request(GPIO_FN_VBUS0_0, NULL);
  1255. gpio_pull_down(GPIO_PORT168CR); /* VBUS0_0 pull down */
  1256. /* USBHS1 */
  1257. gpio_request(GPIO_FN_VBUS0_1, NULL);
  1258. gpio_pull_down(GPIO_PORT167CR); /* VBUS0_1 pull down */
  1259. gpio_request(GPIO_FN_IDIN_1_113, NULL);
  1260. /* enable FSI2 port A (ak4643) */
  1261. gpio_request(GPIO_FN_FSIAIBT, NULL);
  1262. gpio_request(GPIO_FN_FSIAILR, NULL);
  1263. gpio_request(GPIO_FN_FSIAISLD, NULL);
  1264. gpio_request(GPIO_FN_FSIAOSLD, NULL);
  1265. gpio_request(GPIO_PORT161, NULL);
  1266. gpio_direction_output(GPIO_PORT161, 0); /* slave */
  1267. gpio_request(GPIO_PORT9, NULL);
  1268. gpio_request(GPIO_PORT10, NULL);
  1269. gpio_no_direction(GPIO_PORT9CR); /* FSIAOBT needs no direction */
  1270. gpio_no_direction(GPIO_PORT10CR); /* FSIAOLR needs no direction */
  1271. intc_set_priority(IRQ_FSI, 3); /* irq priority FSI(3) > SMSC911X(2) */
  1272. /* setup FSI2 port B (HDMI) */
  1273. gpio_request(GPIO_FN_FSIBCK, NULL);
  1274. __raw_writew(__raw_readw(USCCR1) & ~(1 << 6), USCCR1); /* use SPDIF */
  1275. /* set SPU2 clock to 119.6 MHz */
  1276. clk = clk_get(NULL, "spu_clk");
  1277. if (!IS_ERR(clk)) {
  1278. clk_set_rate(clk, clk_round_rate(clk, 119600000));
  1279. clk_put(clk);
  1280. }
  1281. /* enable Keypad */
  1282. gpio_request(GPIO_FN_IRQ9_42, NULL);
  1283. irq_set_irq_type(IRQ9, IRQ_TYPE_LEVEL_HIGH);
  1284. /* enable Touchscreen */
  1285. gpio_request(GPIO_FN_IRQ7_40, NULL);
  1286. irq_set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
  1287. /* enable Accelerometer */
  1288. gpio_request(GPIO_FN_IRQ21, NULL);
  1289. irq_set_irq_type(IRQ21, IRQ_TYPE_LEVEL_HIGH);
  1290. /* enable SDHI0 */
  1291. gpio_request(GPIO_FN_SDHICD0, NULL);
  1292. gpio_request(GPIO_FN_SDHIWP0, NULL);
  1293. gpio_request(GPIO_FN_SDHICMD0, NULL);
  1294. gpio_request(GPIO_FN_SDHICLK0, NULL);
  1295. gpio_request(GPIO_FN_SDHID0_3, NULL);
  1296. gpio_request(GPIO_FN_SDHID0_2, NULL);
  1297. gpio_request(GPIO_FN_SDHID0_1, NULL);
  1298. gpio_request(GPIO_FN_SDHID0_0, NULL);
  1299. ret = request_irq(evt2irq(0x3340), mackerel_sdhi0_gpio_cd,
  1300. IRQF_TRIGGER_FALLING, "sdhi0 cd", &sdhi0_device.dev);
  1301. if (!ret)
  1302. sdhi0_info.tmio_flags |= TMIO_MMC_HAS_COLD_CD;
  1303. else
  1304. pr_err("Cannot get IRQ #%d: %d\n", evt2irq(0x3340), ret);
  1305. #if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE)
  1306. /* enable SDHI1 */
  1307. gpio_request(GPIO_FN_SDHICMD1, NULL);
  1308. gpio_request(GPIO_FN_SDHICLK1, NULL);
  1309. gpio_request(GPIO_FN_SDHID1_3, NULL);
  1310. gpio_request(GPIO_FN_SDHID1_2, NULL);
  1311. gpio_request(GPIO_FN_SDHID1_1, NULL);
  1312. gpio_request(GPIO_FN_SDHID1_0, NULL);
  1313. #endif
  1314. /* card detect pin for MMC slot (CN7) */
  1315. gpio_request(GPIO_PORT41, NULL);
  1316. gpio_direction_input(GPIO_PORT41);
  1317. /* enable SDHI2 */
  1318. gpio_request(GPIO_FN_SDHICMD2, NULL);
  1319. gpio_request(GPIO_FN_SDHICLK2, NULL);
  1320. gpio_request(GPIO_FN_SDHID2_3, NULL);
  1321. gpio_request(GPIO_FN_SDHID2_2, NULL);
  1322. gpio_request(GPIO_FN_SDHID2_1, NULL);
  1323. gpio_request(GPIO_FN_SDHID2_0, NULL);
  1324. /* card detect pin for microSD slot (CN23) */
  1325. gpio_request(GPIO_PORT162, NULL);
  1326. gpio_direction_input(GPIO_PORT162);
  1327. /* MMCIF */
  1328. gpio_request(GPIO_FN_MMCD0_0, NULL);
  1329. gpio_request(GPIO_FN_MMCD0_1, NULL);
  1330. gpio_request(GPIO_FN_MMCD0_2, NULL);
  1331. gpio_request(GPIO_FN_MMCD0_3, NULL);
  1332. gpio_request(GPIO_FN_MMCD0_4, NULL);
  1333. gpio_request(GPIO_FN_MMCD0_5, NULL);
  1334. gpio_request(GPIO_FN_MMCD0_6, NULL);
  1335. gpio_request(GPIO_FN_MMCD0_7, NULL);
  1336. gpio_request(GPIO_FN_MMCCMD0, NULL);
  1337. gpio_request(GPIO_FN_MMCCLK0, NULL);
  1338. /* enable GPS module (GT-720F) */
  1339. gpio_request(GPIO_FN_SCIFA2_TXD1, NULL);
  1340. gpio_request(GPIO_FN_SCIFA2_RXD1, NULL);
  1341. /* CEU */
  1342. gpio_request(GPIO_FN_VIO_CLK, NULL);
  1343. gpio_request(GPIO_FN_VIO_VD, NULL);
  1344. gpio_request(GPIO_FN_VIO_HD, NULL);
  1345. gpio_request(GPIO_FN_VIO_FIELD, NULL);
  1346. gpio_request(GPIO_FN_VIO_CKO, NULL);
  1347. gpio_request(GPIO_FN_VIO_D7, NULL);
  1348. gpio_request(GPIO_FN_VIO_D6, NULL);
  1349. gpio_request(GPIO_FN_VIO_D5, NULL);
  1350. gpio_request(GPIO_FN_VIO_D4, NULL);
  1351. gpio_request(GPIO_FN_VIO_D3, NULL);
  1352. gpio_request(GPIO_FN_VIO_D2, NULL);
  1353. gpio_request(GPIO_FN_VIO_D1, NULL);
  1354. gpio_request(GPIO_FN_VIO_D0, NULL);
  1355. /* HDMI */
  1356. gpio_request(GPIO_FN_HDMI_HPD, NULL);
  1357. gpio_request(GPIO_FN_HDMI_CEC, NULL);
  1358. /* Reset HDMI, must be held at least one EXTALR (32768Hz) period */
  1359. srcr4 = __raw_readl(SRCR4);
  1360. __raw_writel(srcr4 | (1 << 13), SRCR4);
  1361. udelay(50);
  1362. __raw_writel(srcr4 & ~(1 << 13), SRCR4);
  1363. i2c_register_board_info(0, i2c0_devices,
  1364. ARRAY_SIZE(i2c0_devices));
  1365. i2c_register_board_info(1, i2c1_devices,
  1366. ARRAY_SIZE(i2c1_devices));
  1367. sh7372_add_standard_devices();
  1368. platform_add_devices(mackerel_devices, ARRAY_SIZE(mackerel_devices));
  1369. sh7372_add_device_to_domain(&sh7372_a4lc, &lcdc_device);
  1370. sh7372_add_device_to_domain(&sh7372_a4lc, &hdmi_lcdc_device);
  1371. sh7372_add_device_to_domain(&sh7372_a4lc, &meram_device);
  1372. sh7372_add_device_to_domain(&sh7372_a4mp, &fsi_device);
  1373. sh7372_add_device_to_domain(&sh7372_a3sp, &usbhs0_device);
  1374. sh7372_add_device_to_domain(&sh7372_a3sp, &usbhs1_device);
  1375. sh7372_add_device_to_domain(&sh7372_a3sp, &sh_mmcif_device);
  1376. sh7372_add_device_to_domain(&sh7372_a3sp, &sdhi0_device);
  1377. #if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE)
  1378. sh7372_add_device_to_domain(&sh7372_a3sp, &sdhi1_device);
  1379. #endif
  1380. sh7372_add_device_to_domain(&sh7372_a3sp, &sdhi2_device);
  1381. sh7372_add_device_to_domain(&sh7372_a4r, &ceu_device);
  1382. hdmi_init_pm_clock();
  1383. sh7372_pm_init();
  1384. pm_clk_add(&fsi_device.dev, "spu2");
  1385. pm_clk_add(&hdmi_lcdc_device.dev, "hdmi");
  1386. }
  1387. static void __init mackerel_timer_init(void)
  1388. {
  1389. sh7372_clock_init();
  1390. shmobile_timer.init();
  1391. /* External clock source */
  1392. clk_set_rate(&sh7372_dv_clki_clk, 27000000);
  1393. }
  1394. static struct sys_timer mackerel_timer = {
  1395. .init = mackerel_timer_init,
  1396. };
  1397. MACHINE_START(MACKEREL, "mackerel")
  1398. .map_io = mackerel_map_io,
  1399. .init_irq = sh7372_init_irq,
  1400. .handle_irq = shmobile_handle_irq_intc,
  1401. .init_machine = mackerel_init,
  1402. .timer = &mackerel_timer,
  1403. MACHINE_END