board-mackerel.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608
  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_runtime.h>
  43. #include <linux/smsc911x.h>
  44. #include <linux/sh_intc.h>
  45. #include <linux/tca6416_keypad.h>
  46. #include <linux/usb/r8a66597.h>
  47. #include <linux/usb/renesas_usbhs.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. * *1
  138. * CN31 is used as
  139. * CONFIG_USB_R8A66597_HCD Host
  140. * CONFIG_USB_RENESAS_USBHS 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. * We can use external interrupt mode USB-Function on "USB1".
  155. * USB1 can become Host by r8a66597, and become Function by renesas_usbhs.
  156. * But don't select both drivers in same time.
  157. * These uses same IRQ number for request_irq(), and aren't supporting
  158. * IRQF_SHARED / IORESOURCE_IRQ_SHAREABLE.
  159. *
  160. * Actually these are old/new version of USB driver.
  161. * This mean its register will be broken if it supports shared IRQ,
  162. */
  163. /*
  164. * SDHI0 (CN12)
  165. *
  166. * SW56 : OFF
  167. *
  168. */
  169. /* MMC /SDHI1 (CN7)
  170. *
  171. * I/O voltage : 1.8v
  172. *
  173. * Power voltage : 1.8v or 3.3v
  174. * J22 : select power voltage *1
  175. * 1-2 pin : 1.8v
  176. * 2-3 pin : 3.3v
  177. *
  178. * *1
  179. * Please change J22 depends the card to be used.
  180. * MMC's OCR field set to support either voltage for the card inserted.
  181. *
  182. * SW1 | SW33
  183. * | bit1 | bit2 | bit3 | bit4
  184. * -------------+------+------+------+-------
  185. * MMC0 OFF | OFF | X | ON | X (Use MMCIF)
  186. * SDHI1 OFF | ON | X | OFF | X (Use MFD_SH_MOBILE_SDHI)
  187. *
  188. */
  189. /*
  190. * SDHI2 (CN23)
  191. *
  192. * microSD card sloct
  193. *
  194. */
  195. /*
  196. * FIXME !!
  197. *
  198. * gpio_no_direction
  199. * gpio_pull_down
  200. * are quick_hack.
  201. *
  202. * current gpio frame work doesn't have
  203. * the method to control only pull up/down/free.
  204. * this function should be replaced by correct gpio function
  205. */
  206. static void __init gpio_no_direction(u32 addr)
  207. {
  208. __raw_writeb(0x00, addr);
  209. }
  210. static void __init gpio_pull_down(u32 addr)
  211. {
  212. u8 data = __raw_readb(addr);
  213. data &= 0x0F;
  214. data |= 0xA0;
  215. __raw_writeb(data, addr);
  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 = 0x00000000,
  256. .end = 0x08000000 - 1,
  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 = "MERAM",
  300. .start = 0xe8000000,
  301. .end = 0xe81fffff,
  302. .flags = IORESOURCE_MEM,
  303. },
  304. };
  305. static struct platform_device meram_device = {
  306. .name = "sh_mobile_meram",
  307. .id = 0,
  308. .num_resources = ARRAY_SIZE(meram_resources),
  309. .resource = meram_resources,
  310. .dev = {
  311. .platform_data = &mackerel_meram_info,
  312. },
  313. };
  314. /* LCDC */
  315. static struct fb_videomode mackerel_lcdc_modes[] = {
  316. {
  317. .name = "WVGA Panel",
  318. .xres = 800,
  319. .yres = 480,
  320. .left_margin = 220,
  321. .right_margin = 110,
  322. .hsync_len = 70,
  323. .upper_margin = 20,
  324. .lower_margin = 5,
  325. .vsync_len = 5,
  326. .sync = 0,
  327. },
  328. };
  329. static int mackerel_set_brightness(void *board_data, int brightness)
  330. {
  331. gpio_set_value(GPIO_PORT31, brightness);
  332. return 0;
  333. }
  334. static int mackerel_get_brightness(void *board_data)
  335. {
  336. return gpio_get_value(GPIO_PORT31);
  337. }
  338. static struct sh_mobile_meram_cfg lcd_meram_cfg = {
  339. .icb[0] = {
  340. .marker_icb = 28,
  341. .cache_icb = 24,
  342. .meram_offset = 0x0,
  343. .meram_size = 0x40,
  344. },
  345. .icb[1] = {
  346. .marker_icb = 29,
  347. .cache_icb = 25,
  348. .meram_offset = 0x40,
  349. .meram_size = 0x40,
  350. },
  351. };
  352. static struct sh_mobile_lcdc_info lcdc_info = {
  353. .meram_dev = &mackerel_meram_info,
  354. .clock_source = LCDC_CLK_BUS,
  355. .ch[0] = {
  356. .chan = LCDC_CHAN_MAINLCD,
  357. .bpp = 16,
  358. .lcd_cfg = mackerel_lcdc_modes,
  359. .num_cfg = ARRAY_SIZE(mackerel_lcdc_modes),
  360. .interface_type = RGB24,
  361. .clock_divider = 3,
  362. .flags = 0,
  363. .lcd_size_cfg.width = 152,
  364. .lcd_size_cfg.height = 91,
  365. .board_cfg = {
  366. .set_brightness = mackerel_set_brightness,
  367. .get_brightness = mackerel_get_brightness,
  368. },
  369. .bl_info = {
  370. .name = "sh_mobile_lcdc_bl",
  371. .max_brightness = 1,
  372. },
  373. .meram_cfg = &lcd_meram_cfg,
  374. }
  375. };
  376. static struct resource lcdc_resources[] = {
  377. [0] = {
  378. .name = "LCDC",
  379. .start = 0xfe940000,
  380. .end = 0xfe943fff,
  381. .flags = IORESOURCE_MEM,
  382. },
  383. [1] = {
  384. .start = intcs_evt2irq(0x580),
  385. .flags = IORESOURCE_IRQ,
  386. },
  387. };
  388. static struct platform_device lcdc_device = {
  389. .name = "sh_mobile_lcdc_fb",
  390. .num_resources = ARRAY_SIZE(lcdc_resources),
  391. .resource = lcdc_resources,
  392. .dev = {
  393. .platform_data = &lcdc_info,
  394. .coherent_dma_mask = ~0,
  395. },
  396. };
  397. static struct sh_mobile_meram_cfg hdmi_meram_cfg = {
  398. .icb[0] = {
  399. .marker_icb = 30,
  400. .cache_icb = 26,
  401. .meram_offset = 0x80,
  402. .meram_size = 0x100,
  403. },
  404. .icb[1] = {
  405. .marker_icb = 31,
  406. .cache_icb = 27,
  407. .meram_offset = 0x180,
  408. .meram_size = 0x100,
  409. },
  410. };
  411. /* HDMI */
  412. static struct sh_mobile_lcdc_info hdmi_lcdc_info = {
  413. .meram_dev = &mackerel_meram_info,
  414. .clock_source = LCDC_CLK_EXTERNAL,
  415. .ch[0] = {
  416. .chan = LCDC_CHAN_MAINLCD,
  417. .bpp = 16,
  418. .interface_type = RGB24,
  419. .clock_divider = 1,
  420. .flags = LCDC_FLAGS_DWPOL,
  421. .meram_cfg = &hdmi_meram_cfg,
  422. }
  423. };
  424. static struct resource hdmi_lcdc_resources[] = {
  425. [0] = {
  426. .name = "LCDC1",
  427. .start = 0xfe944000,
  428. .end = 0xfe947fff,
  429. .flags = IORESOURCE_MEM,
  430. },
  431. [1] = {
  432. .start = intcs_evt2irq(0x1780),
  433. .flags = IORESOURCE_IRQ,
  434. },
  435. };
  436. static struct platform_device hdmi_lcdc_device = {
  437. .name = "sh_mobile_lcdc_fb",
  438. .num_resources = ARRAY_SIZE(hdmi_lcdc_resources),
  439. .resource = hdmi_lcdc_resources,
  440. .id = 1,
  441. .dev = {
  442. .platform_data = &hdmi_lcdc_info,
  443. .coherent_dma_mask = ~0,
  444. },
  445. };
  446. static struct sh_mobile_hdmi_info hdmi_info = {
  447. .lcd_chan = &hdmi_lcdc_info.ch[0],
  448. .lcd_dev = &hdmi_lcdc_device.dev,
  449. .flags = HDMI_SND_SRC_SPDIF,
  450. };
  451. static struct resource hdmi_resources[] = {
  452. [0] = {
  453. .name = "HDMI",
  454. .start = 0xe6be0000,
  455. .end = 0xe6be00ff,
  456. .flags = IORESOURCE_MEM,
  457. },
  458. [1] = {
  459. /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
  460. .start = evt2irq(0x17e0),
  461. .flags = IORESOURCE_IRQ,
  462. },
  463. };
  464. static struct platform_device hdmi_device = {
  465. .name = "sh-mobile-hdmi",
  466. .num_resources = ARRAY_SIZE(hdmi_resources),
  467. .resource = hdmi_resources,
  468. .id = -1,
  469. .dev = {
  470. .platform_data = &hdmi_info,
  471. },
  472. };
  473. static struct platform_device fsi_hdmi_device = {
  474. .name = "sh_fsi2_b_hdmi",
  475. };
  476. static void __init hdmi_init_pm_clock(void)
  477. {
  478. struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
  479. int ret;
  480. long rate;
  481. if (IS_ERR(hdmi_ick)) {
  482. ret = PTR_ERR(hdmi_ick);
  483. pr_err("Cannot get HDMI ICK: %d\n", ret);
  484. goto out;
  485. }
  486. ret = clk_set_parent(&sh7372_pllc2_clk, &sh7372_dv_clki_div2_clk);
  487. if (ret < 0) {
  488. pr_err("Cannot set PLLC2 parent: %d, %d users\n",
  489. ret, sh7372_pllc2_clk.usecount);
  490. goto out;
  491. }
  492. pr_debug("PLLC2 initial frequency %lu\n",
  493. clk_get_rate(&sh7372_pllc2_clk));
  494. rate = clk_round_rate(&sh7372_pllc2_clk, 594000000);
  495. if (rate < 0) {
  496. pr_err("Cannot get suitable rate: %ld\n", rate);
  497. ret = rate;
  498. goto out;
  499. }
  500. ret = clk_set_rate(&sh7372_pllc2_clk, rate);
  501. if (ret < 0) {
  502. pr_err("Cannot set rate %ld: %d\n", rate, ret);
  503. goto out;
  504. }
  505. pr_debug("PLLC2 set frequency %lu\n", rate);
  506. ret = clk_set_parent(hdmi_ick, &sh7372_pllc2_clk);
  507. if (ret < 0)
  508. pr_err("Cannot set HDMI parent: %d\n", ret);
  509. out:
  510. if (!IS_ERR(hdmi_ick))
  511. clk_put(hdmi_ick);
  512. }
  513. /* USBHS0 is connected to CN22 which takes a USB Mini-B plug
  514. *
  515. * The sh7372 SoC has IRQ7 set aside for USBHS0 hotplug,
  516. * but on this particular board IRQ7 is already used by
  517. * the touch screen. This leaves us with software polling.
  518. */
  519. #define USBHS0_POLL_INTERVAL (HZ * 5)
  520. struct usbhs_private {
  521. unsigned int usbphyaddr;
  522. unsigned int usbcrcaddr;
  523. struct renesas_usbhs_platform_info info;
  524. struct delayed_work work;
  525. struct platform_device *pdev;
  526. };
  527. #define usbhs_get_priv(pdev) \
  528. container_of(renesas_usbhs_get_info(pdev), \
  529. struct usbhs_private, info)
  530. #define usbhs_is_connected(priv) \
  531. (!((1 << 7) & __raw_readw(priv->usbcrcaddr)))
  532. static int usbhs_get_vbus(struct platform_device *pdev)
  533. {
  534. return usbhs_is_connected(usbhs_get_priv(pdev));
  535. }
  536. static void usbhs_phy_reset(struct platform_device *pdev)
  537. {
  538. struct usbhs_private *priv = usbhs_get_priv(pdev);
  539. /* init phy */
  540. __raw_writew(0x8a0a, priv->usbcrcaddr);
  541. }
  542. static int usbhs0_get_id(struct platform_device *pdev)
  543. {
  544. return USBHS_GADGET;
  545. }
  546. static void usbhs0_work_function(struct work_struct *work)
  547. {
  548. struct usbhs_private *priv = container_of(work, struct usbhs_private,
  549. work.work);
  550. renesas_usbhs_call_notify_hotplug(priv->pdev);
  551. schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
  552. }
  553. static int usbhs0_hardware_init(struct platform_device *pdev)
  554. {
  555. struct usbhs_private *priv = usbhs_get_priv(pdev);
  556. priv->pdev = pdev;
  557. INIT_DELAYED_WORK(&priv->work, usbhs0_work_function);
  558. schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
  559. return 0;
  560. }
  561. static void usbhs0_hardware_exit(struct platform_device *pdev)
  562. {
  563. struct usbhs_private *priv = usbhs_get_priv(pdev);
  564. cancel_delayed_work_sync(&priv->work);
  565. }
  566. static struct usbhs_private usbhs0_private = {
  567. .usbcrcaddr = 0xe605810c, /* USBCR2 */
  568. .info = {
  569. .platform_callback = {
  570. .hardware_init = usbhs0_hardware_init,
  571. .hardware_exit = usbhs0_hardware_exit,
  572. .phy_reset = usbhs_phy_reset,
  573. .get_id = usbhs0_get_id,
  574. .get_vbus = usbhs_get_vbus,
  575. },
  576. .driver_param = {
  577. .buswait_bwait = 4,
  578. },
  579. },
  580. };
  581. static struct resource usbhs0_resources[] = {
  582. [0] = {
  583. .name = "USBHS0",
  584. .start = 0xe6890000,
  585. .end = 0xe68900e6 - 1,
  586. .flags = IORESOURCE_MEM,
  587. },
  588. [1] = {
  589. .start = evt2irq(0x1ca0) /* USB0_USB0I0 */,
  590. .flags = IORESOURCE_IRQ,
  591. },
  592. };
  593. static struct platform_device usbhs0_device = {
  594. .name = "renesas_usbhs",
  595. .id = 0,
  596. .dev = {
  597. .platform_data = &usbhs0_private.info,
  598. },
  599. .num_resources = ARRAY_SIZE(usbhs0_resources),
  600. .resource = usbhs0_resources,
  601. };
  602. /* USBHS1 is connected to CN31 which takes a USB Mini-AB plug
  603. *
  604. * Use J30 to select between Host and Function. This setting
  605. * can however not be detected by software. Hotplug of USBHS1
  606. * is provided via IRQ8.
  607. */
  608. #define IRQ8 evt2irq(0x0300)
  609. /* USBHS1 USB Host support via r8a66597_hcd */
  610. static void usb1_host_port_power(int port, int power)
  611. {
  612. if (!power) /* only power-on is supported for now */
  613. return;
  614. /* set VBOUT/PWEN and EXTLP1 in DVSTCTR */
  615. __raw_writew(__raw_readw(0xE68B0008) | 0x600, 0xE68B0008);
  616. }
  617. static struct r8a66597_platdata usb1_host_data = {
  618. .on_chip = 1,
  619. .port_power = usb1_host_port_power,
  620. };
  621. static struct resource usb1_host_resources[] = {
  622. [0] = {
  623. .name = "USBHS1",
  624. .start = 0xe68b0000,
  625. .end = 0xe68b00e6 - 1,
  626. .flags = IORESOURCE_MEM,
  627. },
  628. [1] = {
  629. .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
  630. .flags = IORESOURCE_IRQ,
  631. },
  632. };
  633. static struct platform_device usb1_host_device = {
  634. .name = "r8a66597_hcd",
  635. .id = 1,
  636. .dev = {
  637. .dma_mask = NULL, /* not use dma */
  638. .coherent_dma_mask = 0xffffffff,
  639. .platform_data = &usb1_host_data,
  640. },
  641. .num_resources = ARRAY_SIZE(usb1_host_resources),
  642. .resource = usb1_host_resources,
  643. };
  644. /* USBHS1 USB Function support via renesas_usbhs */
  645. #define USB_PHY_MODE (1 << 4)
  646. #define USB_PHY_INT_EN ((1 << 3) | (1 << 2))
  647. #define USB_PHY_ON (1 << 1)
  648. #define USB_PHY_OFF (1 << 0)
  649. #define USB_PHY_INT_CLR (USB_PHY_ON | USB_PHY_OFF)
  650. static irqreturn_t usbhs1_interrupt(int irq, void *data)
  651. {
  652. struct platform_device *pdev = data;
  653. struct usbhs_private *priv = usbhs_get_priv(pdev);
  654. dev_dbg(&pdev->dev, "%s\n", __func__);
  655. renesas_usbhs_call_notify_hotplug(pdev);
  656. /* clear status */
  657. __raw_writew(__raw_readw(priv->usbphyaddr) | USB_PHY_INT_CLR,
  658. priv->usbphyaddr);
  659. return IRQ_HANDLED;
  660. }
  661. static int usbhs1_hardware_init(struct platform_device *pdev)
  662. {
  663. struct usbhs_private *priv = usbhs_get_priv(pdev);
  664. int ret;
  665. /* clear interrupt status */
  666. __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
  667. ret = request_irq(IRQ8, usbhs1_interrupt, IRQF_TRIGGER_HIGH,
  668. dev_name(&pdev->dev), pdev);
  669. if (ret) {
  670. dev_err(&pdev->dev, "request_irq err\n");
  671. return ret;
  672. }
  673. /* enable USB phy interrupt */
  674. __raw_writew(USB_PHY_MODE | USB_PHY_INT_EN, priv->usbphyaddr);
  675. return 0;
  676. }
  677. static void usbhs1_hardware_exit(struct platform_device *pdev)
  678. {
  679. struct usbhs_private *priv = usbhs_get_priv(pdev);
  680. /* clear interrupt status */
  681. __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
  682. free_irq(IRQ8, pdev);
  683. }
  684. static int usbhs1_get_id(struct platform_device *pdev)
  685. {
  686. return USBHS_GADGET;
  687. }
  688. static u32 usbhs1_pipe_cfg[] = {
  689. USB_ENDPOINT_XFER_CONTROL,
  690. USB_ENDPOINT_XFER_ISOC,
  691. USB_ENDPOINT_XFER_ISOC,
  692. USB_ENDPOINT_XFER_BULK,
  693. USB_ENDPOINT_XFER_BULK,
  694. USB_ENDPOINT_XFER_BULK,
  695. USB_ENDPOINT_XFER_INT,
  696. USB_ENDPOINT_XFER_INT,
  697. USB_ENDPOINT_XFER_INT,
  698. USB_ENDPOINT_XFER_BULK,
  699. USB_ENDPOINT_XFER_BULK,
  700. USB_ENDPOINT_XFER_BULK,
  701. USB_ENDPOINT_XFER_BULK,
  702. USB_ENDPOINT_XFER_BULK,
  703. USB_ENDPOINT_XFER_BULK,
  704. USB_ENDPOINT_XFER_BULK,
  705. };
  706. static struct usbhs_private usbhs1_private = {
  707. .usbphyaddr = 0xe60581e2, /* USBPHY1INTAP */
  708. .usbcrcaddr = 0xe6058130, /* USBCR4 */
  709. .info = {
  710. .platform_callback = {
  711. .hardware_init = usbhs1_hardware_init,
  712. .hardware_exit = usbhs1_hardware_exit,
  713. .get_id = usbhs1_get_id,
  714. .phy_reset = usbhs_phy_reset,
  715. .get_vbus = usbhs_get_vbus,
  716. },
  717. .driver_param = {
  718. .buswait_bwait = 4,
  719. .pipe_type = usbhs1_pipe_cfg,
  720. .pipe_size = ARRAY_SIZE(usbhs1_pipe_cfg),
  721. },
  722. },
  723. };
  724. static struct resource usbhs1_resources[] = {
  725. [0] = {
  726. .name = "USBHS1",
  727. .start = 0xe68b0000,
  728. .end = 0xe68b00e6 - 1,
  729. .flags = IORESOURCE_MEM,
  730. },
  731. [1] = {
  732. .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
  733. .flags = IORESOURCE_IRQ,
  734. },
  735. };
  736. static struct platform_device usbhs1_device = {
  737. .name = "renesas_usbhs",
  738. .id = 1,
  739. .dev = {
  740. .platform_data = &usbhs1_private.info,
  741. },
  742. .num_resources = ARRAY_SIZE(usbhs1_resources),
  743. .resource = usbhs1_resources,
  744. };
  745. /* LED */
  746. static struct gpio_led mackerel_leds[] = {
  747. {
  748. .name = "led0",
  749. .gpio = GPIO_PORT0,
  750. .default_state = LEDS_GPIO_DEFSTATE_ON,
  751. },
  752. {
  753. .name = "led1",
  754. .gpio = GPIO_PORT1,
  755. .default_state = LEDS_GPIO_DEFSTATE_ON,
  756. },
  757. {
  758. .name = "led2",
  759. .gpio = GPIO_PORT2,
  760. .default_state = LEDS_GPIO_DEFSTATE_ON,
  761. },
  762. {
  763. .name = "led3",
  764. .gpio = GPIO_PORT159,
  765. .default_state = LEDS_GPIO_DEFSTATE_ON,
  766. }
  767. };
  768. static struct gpio_led_platform_data mackerel_leds_pdata = {
  769. .leds = mackerel_leds,
  770. .num_leds = ARRAY_SIZE(mackerel_leds),
  771. };
  772. static struct platform_device leds_device = {
  773. .name = "leds-gpio",
  774. .id = 0,
  775. .dev = {
  776. .platform_data = &mackerel_leds_pdata,
  777. },
  778. };
  779. /* FSI */
  780. #define IRQ_FSI evt2irq(0x1840)
  781. static int __fsi_set_round_rate(struct clk *clk, long rate, int enable)
  782. {
  783. int ret;
  784. if (rate <= 0)
  785. return 0;
  786. if (!enable) {
  787. clk_disable(clk);
  788. return 0;
  789. }
  790. ret = clk_set_rate(clk, clk_round_rate(clk, rate));
  791. if (ret < 0)
  792. return ret;
  793. return clk_enable(clk);
  794. }
  795. static int fsi_set_rate(struct device *dev, int is_porta, int rate, int enable)
  796. {
  797. struct clk *fsib_clk;
  798. struct clk *fdiv_clk = &sh7372_fsidivb_clk;
  799. long fsib_rate = 0;
  800. long fdiv_rate = 0;
  801. int ackmd_bpfmd;
  802. int ret;
  803. /* FSIA is slave mode. nothing to do here */
  804. if (is_porta)
  805. return 0;
  806. /* clock start */
  807. switch (rate) {
  808. case 44100:
  809. fsib_rate = rate * 256;
  810. ackmd_bpfmd = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
  811. break;
  812. case 48000:
  813. fsib_rate = 85428000; /* around 48kHz x 256 x 7 */
  814. fdiv_rate = rate * 256;
  815. ackmd_bpfmd = SH_FSI_ACKMD_256 | SH_FSI_BPFMD_64;
  816. break;
  817. default:
  818. pr_err("unsupported rate in FSI2 port B\n");
  819. return -EINVAL;
  820. }
  821. /* FSI B setting */
  822. fsib_clk = clk_get(dev, "ickb");
  823. if (IS_ERR(fsib_clk))
  824. return -EIO;
  825. /* fsib */
  826. ret = __fsi_set_round_rate(fsib_clk, fsib_rate, enable);
  827. if (ret < 0)
  828. goto fsi_set_rate_end;
  829. /* FSI DIV */
  830. ret = __fsi_set_round_rate(fdiv_clk, fdiv_rate, enable);
  831. if (ret < 0) {
  832. /* disable FSI B */
  833. if (enable)
  834. __fsi_set_round_rate(fsib_clk, fsib_rate, 0);
  835. goto fsi_set_rate_end;
  836. }
  837. ret = ackmd_bpfmd;
  838. fsi_set_rate_end:
  839. clk_put(fsib_clk);
  840. return ret;
  841. }
  842. static struct sh_fsi_platform_info fsi_info = {
  843. .porta_flags = SH_FSI_BRS_INV,
  844. .portb_flags = SH_FSI_BRS_INV |
  845. SH_FSI_BRM_INV |
  846. SH_FSI_LRS_INV |
  847. SH_FSI_FMT_SPDIF,
  848. .set_rate = fsi_set_rate,
  849. };
  850. static struct resource fsi_resources[] = {
  851. [0] = {
  852. .name = "FSI",
  853. .start = 0xFE3C0000,
  854. .end = 0xFE3C0400 - 1,
  855. .flags = IORESOURCE_MEM,
  856. },
  857. [1] = {
  858. .start = IRQ_FSI,
  859. .flags = IORESOURCE_IRQ,
  860. },
  861. };
  862. static struct platform_device fsi_device = {
  863. .name = "sh_fsi2",
  864. .id = -1,
  865. .num_resources = ARRAY_SIZE(fsi_resources),
  866. .resource = fsi_resources,
  867. .dev = {
  868. .platform_data = &fsi_info,
  869. },
  870. };
  871. static struct platform_device fsi_ak4643_device = {
  872. .name = "sh_fsi2_a_ak4643",
  873. };
  874. /*
  875. * The card detect pin of the top SD/MMC slot (CN7) is active low and is
  876. * connected to GPIO A22 of SH7372 (GPIO_PORT41).
  877. */
  878. static int slot_cn7_get_cd(struct platform_device *pdev)
  879. {
  880. return !gpio_get_value(GPIO_PORT41);
  881. }
  882. /* SDHI0 */
  883. static irqreturn_t mackerel_sdhi0_gpio_cd(int irq, void *arg)
  884. {
  885. struct device *dev = arg;
  886. struct sh_mobile_sdhi_info *info = dev->platform_data;
  887. struct tmio_mmc_data *pdata = info->pdata;
  888. tmio_mmc_cd_wakeup(pdata);
  889. return IRQ_HANDLED;
  890. }
  891. static struct sh_mobile_sdhi_info sdhi0_info = {
  892. .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
  893. .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
  894. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
  895. };
  896. static struct resource sdhi0_resources[] = {
  897. [0] = {
  898. .name = "SDHI0",
  899. .start = 0xe6850000,
  900. .end = 0xe68500ff,
  901. .flags = IORESOURCE_MEM,
  902. },
  903. [1] = {
  904. .start = evt2irq(0x0e00) /* SDHI0_SDHI0I0 */,
  905. .flags = IORESOURCE_IRQ,
  906. },
  907. [2] = {
  908. .start = evt2irq(0x0e20) /* SDHI0_SDHI0I1 */,
  909. .flags = IORESOURCE_IRQ,
  910. },
  911. [3] = {
  912. .start = evt2irq(0x0e40) /* SDHI0_SDHI0I2 */,
  913. .flags = IORESOURCE_IRQ,
  914. },
  915. };
  916. static struct platform_device sdhi0_device = {
  917. .name = "sh_mobile_sdhi",
  918. .num_resources = ARRAY_SIZE(sdhi0_resources),
  919. .resource = sdhi0_resources,
  920. .id = 0,
  921. .dev = {
  922. .platform_data = &sdhi0_info,
  923. },
  924. };
  925. #if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE)
  926. /* SDHI1 */
  927. static struct sh_mobile_sdhi_info sdhi1_info = {
  928. .dma_slave_tx = SHDMA_SLAVE_SDHI1_TX,
  929. .dma_slave_rx = SHDMA_SLAVE_SDHI1_RX,
  930. .tmio_ocr_mask = MMC_VDD_165_195,
  931. .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE,
  932. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
  933. MMC_CAP_NEEDS_POLL,
  934. .get_cd = slot_cn7_get_cd,
  935. };
  936. static struct resource sdhi1_resources[] = {
  937. [0] = {
  938. .name = "SDHI1",
  939. .start = 0xe6860000,
  940. .end = 0xe68600ff,
  941. .flags = IORESOURCE_MEM,
  942. },
  943. [1] = {
  944. .start = evt2irq(0x0e80), /* SDHI1_SDHI1I0 */
  945. .flags = IORESOURCE_IRQ,
  946. },
  947. [2] = {
  948. .start = evt2irq(0x0ea0), /* SDHI1_SDHI1I1 */
  949. .flags = IORESOURCE_IRQ,
  950. },
  951. [3] = {
  952. .start = evt2irq(0x0ec0), /* SDHI1_SDHI1I2 */
  953. .flags = IORESOURCE_IRQ,
  954. },
  955. };
  956. static struct platform_device sdhi1_device = {
  957. .name = "sh_mobile_sdhi",
  958. .num_resources = ARRAY_SIZE(sdhi1_resources),
  959. .resource = sdhi1_resources,
  960. .id = 1,
  961. .dev = {
  962. .platform_data = &sdhi1_info,
  963. },
  964. };
  965. #endif
  966. /*
  967. * The card detect pin of the top SD/MMC slot (CN23) is active low and is
  968. * connected to GPIO SCIFB_SCK of SH7372 (GPIO_PORT162).
  969. */
  970. static int slot_cn23_get_cd(struct platform_device *pdev)
  971. {
  972. return !gpio_get_value(GPIO_PORT162);
  973. }
  974. /* SDHI2 */
  975. static struct sh_mobile_sdhi_info sdhi2_info = {
  976. .dma_slave_tx = SHDMA_SLAVE_SDHI2_TX,
  977. .dma_slave_rx = SHDMA_SLAVE_SDHI2_RX,
  978. .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE,
  979. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
  980. MMC_CAP_NEEDS_POLL,
  981. .get_cd = slot_cn23_get_cd,
  982. };
  983. static struct resource sdhi2_resources[] = {
  984. [0] = {
  985. .name = "SDHI2",
  986. .start = 0xe6870000,
  987. .end = 0xe68700ff,
  988. .flags = IORESOURCE_MEM,
  989. },
  990. [1] = {
  991. .start = evt2irq(0x1200), /* SDHI2_SDHI2I0 */
  992. .flags = IORESOURCE_IRQ,
  993. },
  994. [2] = {
  995. .start = evt2irq(0x1220), /* SDHI2_SDHI2I1 */
  996. .flags = IORESOURCE_IRQ,
  997. },
  998. [3] = {
  999. .start = evt2irq(0x1240), /* SDHI2_SDHI2I2 */
  1000. .flags = IORESOURCE_IRQ,
  1001. },
  1002. };
  1003. static struct platform_device sdhi2_device = {
  1004. .name = "sh_mobile_sdhi",
  1005. .num_resources = ARRAY_SIZE(sdhi2_resources),
  1006. .resource = sdhi2_resources,
  1007. .id = 2,
  1008. .dev = {
  1009. .platform_data = &sdhi2_info,
  1010. },
  1011. };
  1012. /* SH_MMCIF */
  1013. static struct resource sh_mmcif_resources[] = {
  1014. [0] = {
  1015. .name = "MMCIF",
  1016. .start = 0xE6BD0000,
  1017. .end = 0xE6BD00FF,
  1018. .flags = IORESOURCE_MEM,
  1019. },
  1020. [1] = {
  1021. /* MMC ERR */
  1022. .start = evt2irq(0x1ac0),
  1023. .flags = IORESOURCE_IRQ,
  1024. },
  1025. [2] = {
  1026. /* MMC NOR */
  1027. .start = evt2irq(0x1ae0),
  1028. .flags = IORESOURCE_IRQ,
  1029. },
  1030. };
  1031. static struct sh_mmcif_dma sh_mmcif_dma = {
  1032. .chan_priv_rx = {
  1033. .slave_id = SHDMA_SLAVE_MMCIF_RX,
  1034. },
  1035. .chan_priv_tx = {
  1036. .slave_id = SHDMA_SLAVE_MMCIF_TX,
  1037. },
  1038. };
  1039. static struct sh_mmcif_plat_data sh_mmcif_plat = {
  1040. .sup_pclk = 0,
  1041. .ocr = MMC_VDD_165_195 | MMC_VDD_32_33 | MMC_VDD_33_34,
  1042. .caps = MMC_CAP_4_BIT_DATA |
  1043. MMC_CAP_8_BIT_DATA |
  1044. MMC_CAP_NEEDS_POLL,
  1045. .get_cd = slot_cn7_get_cd,
  1046. .dma = &sh_mmcif_dma,
  1047. };
  1048. static struct platform_device sh_mmcif_device = {
  1049. .name = "sh_mmcif",
  1050. .id = 0,
  1051. .dev = {
  1052. .dma_mask = NULL,
  1053. .coherent_dma_mask = 0xffffffff,
  1054. .platform_data = &sh_mmcif_plat,
  1055. },
  1056. .num_resources = ARRAY_SIZE(sh_mmcif_resources),
  1057. .resource = sh_mmcif_resources,
  1058. };
  1059. static int mackerel_camera_add(struct soc_camera_link *icl, struct device *dev);
  1060. static void mackerel_camera_del(struct soc_camera_link *icl);
  1061. static int camera_set_capture(struct soc_camera_platform_info *info,
  1062. int enable)
  1063. {
  1064. return 0; /* camera sensor always enabled */
  1065. }
  1066. static struct soc_camera_platform_info camera_info = {
  1067. .format_name = "UYVY",
  1068. .format_depth = 16,
  1069. .format = {
  1070. .code = V4L2_MBUS_FMT_UYVY8_2X8,
  1071. .colorspace = V4L2_COLORSPACE_SMPTE170M,
  1072. .field = V4L2_FIELD_NONE,
  1073. .width = 640,
  1074. .height = 480,
  1075. },
  1076. .bus_param = SOCAM_PCLK_SAMPLE_RISING | SOCAM_HSYNC_ACTIVE_HIGH |
  1077. SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_MASTER | SOCAM_DATAWIDTH_8 |
  1078. SOCAM_DATA_ACTIVE_HIGH,
  1079. .set_capture = camera_set_capture,
  1080. };
  1081. static struct soc_camera_link camera_link = {
  1082. .bus_id = 0,
  1083. .add_device = mackerel_camera_add,
  1084. .del_device = mackerel_camera_del,
  1085. .module_name = "soc_camera_platform",
  1086. .priv = &camera_info,
  1087. };
  1088. static struct platform_device *camera_device;
  1089. static void mackerel_camera_release(struct device *dev)
  1090. {
  1091. soc_camera_platform_release(&camera_device);
  1092. }
  1093. static int mackerel_camera_add(struct soc_camera_link *icl,
  1094. struct device *dev)
  1095. {
  1096. return soc_camera_platform_add(icl, dev, &camera_device, &camera_link,
  1097. mackerel_camera_release, 0);
  1098. }
  1099. static void mackerel_camera_del(struct soc_camera_link *icl)
  1100. {
  1101. soc_camera_platform_del(icl, camera_device, &camera_link);
  1102. }
  1103. static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
  1104. .flags = SH_CEU_FLAG_USE_8BIT_BUS,
  1105. };
  1106. static struct resource ceu_resources[] = {
  1107. [0] = {
  1108. .name = "CEU",
  1109. .start = 0xfe910000,
  1110. .end = 0xfe91009f,
  1111. .flags = IORESOURCE_MEM,
  1112. },
  1113. [1] = {
  1114. .start = intcs_evt2irq(0x880),
  1115. .flags = IORESOURCE_IRQ,
  1116. },
  1117. [2] = {
  1118. /* place holder for contiguous memory */
  1119. },
  1120. };
  1121. static struct platform_device ceu_device = {
  1122. .name = "sh_mobile_ceu",
  1123. .id = 0, /* "ceu0" clock */
  1124. .num_resources = ARRAY_SIZE(ceu_resources),
  1125. .resource = ceu_resources,
  1126. .dev = {
  1127. .platform_data = &sh_mobile_ceu_info,
  1128. .coherent_dma_mask = 0xffffffff,
  1129. },
  1130. };
  1131. static struct platform_device mackerel_camera = {
  1132. .name = "soc-camera-pdrv",
  1133. .id = 0,
  1134. .dev = {
  1135. .platform_data = &camera_link,
  1136. },
  1137. };
  1138. static struct platform_device *mackerel_devices[] __initdata = {
  1139. &nor_flash_device,
  1140. &smc911x_device,
  1141. &lcdc_device,
  1142. &usb1_host_device,
  1143. &usbhs1_device,
  1144. &usbhs0_device,
  1145. &leds_device,
  1146. &fsi_device,
  1147. &fsi_ak4643_device,
  1148. &fsi_hdmi_device,
  1149. &sdhi0_device,
  1150. #if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE)
  1151. &sdhi1_device,
  1152. #endif
  1153. &sdhi2_device,
  1154. &sh_mmcif_device,
  1155. &ceu_device,
  1156. &mackerel_camera,
  1157. &hdmi_lcdc_device,
  1158. &hdmi_device,
  1159. &meram_device,
  1160. };
  1161. /* Keypad Initialization */
  1162. #define KEYPAD_BUTTON(ev_type, ev_code, act_low) \
  1163. { \
  1164. .type = ev_type, \
  1165. .code = ev_code, \
  1166. .active_low = act_low, \
  1167. }
  1168. #define KEYPAD_BUTTON_LOW(event_code) KEYPAD_BUTTON(EV_KEY, event_code, 1)
  1169. static struct tca6416_button mackerel_gpio_keys[] = {
  1170. KEYPAD_BUTTON_LOW(KEY_HOME),
  1171. KEYPAD_BUTTON_LOW(KEY_MENU),
  1172. KEYPAD_BUTTON_LOW(KEY_BACK),
  1173. KEYPAD_BUTTON_LOW(KEY_POWER),
  1174. };
  1175. static struct tca6416_keys_platform_data mackerel_tca6416_keys_info = {
  1176. .buttons = mackerel_gpio_keys,
  1177. .nbuttons = ARRAY_SIZE(mackerel_gpio_keys),
  1178. .rep = 1,
  1179. .use_polling = 0,
  1180. .pinmask = 0x000F,
  1181. };
  1182. /* I2C */
  1183. #define IRQ7 evt2irq(0x02e0)
  1184. #define IRQ9 evt2irq(0x0320)
  1185. static struct i2c_board_info i2c0_devices[] = {
  1186. {
  1187. I2C_BOARD_INFO("ak4643", 0x13),
  1188. },
  1189. /* Keypad */
  1190. {
  1191. I2C_BOARD_INFO("tca6408-keys", 0x20),
  1192. .platform_data = &mackerel_tca6416_keys_info,
  1193. .irq = IRQ9,
  1194. },
  1195. /* Touchscreen */
  1196. {
  1197. I2C_BOARD_INFO("st1232-ts", 0x55),
  1198. .irq = IRQ7,
  1199. },
  1200. };
  1201. #define IRQ21 evt2irq(0x32a0)
  1202. static struct i2c_board_info i2c1_devices[] = {
  1203. /* Accelerometer */
  1204. {
  1205. I2C_BOARD_INFO("adxl34x", 0x53),
  1206. .irq = IRQ21,
  1207. },
  1208. };
  1209. static struct map_desc mackerel_io_desc[] __initdata = {
  1210. /* create a 1:1 entity map for 0xe6xxxxxx
  1211. * used by CPGA, INTC and PFC.
  1212. */
  1213. {
  1214. .virtual = 0xe6000000,
  1215. .pfn = __phys_to_pfn(0xe6000000),
  1216. .length = 256 << 20,
  1217. .type = MT_DEVICE_NONSHARED
  1218. },
  1219. };
  1220. static void __init mackerel_map_io(void)
  1221. {
  1222. iotable_init(mackerel_io_desc, ARRAY_SIZE(mackerel_io_desc));
  1223. /* setup early devices and console here as well */
  1224. sh7372_add_early_devices();
  1225. shmobile_setup_console();
  1226. }
  1227. #define GPIO_PORT9CR 0xE6051009
  1228. #define GPIO_PORT10CR 0xE605100A
  1229. #define GPIO_PORT167CR 0xE60520A7
  1230. #define GPIO_PORT168CR 0xE60520A8
  1231. #define SRCR4 0xe61580bc
  1232. #define USCCR1 0xE6058144
  1233. static void __init mackerel_init(void)
  1234. {
  1235. u32 srcr4;
  1236. struct clk *clk;
  1237. int ret;
  1238. sh7372_pinmux_init();
  1239. /* enable SCIFA0 */
  1240. gpio_request(GPIO_FN_SCIFA0_TXD, NULL);
  1241. gpio_request(GPIO_FN_SCIFA0_RXD, NULL);
  1242. /* enable SMSC911X */
  1243. gpio_request(GPIO_FN_CS5A, NULL);
  1244. gpio_request(GPIO_FN_IRQ6_39, NULL);
  1245. /* LCDC */
  1246. gpio_request(GPIO_FN_LCDD23, NULL);
  1247. gpio_request(GPIO_FN_LCDD22, NULL);
  1248. gpio_request(GPIO_FN_LCDD21, NULL);
  1249. gpio_request(GPIO_FN_LCDD20, NULL);
  1250. gpio_request(GPIO_FN_LCDD19, NULL);
  1251. gpio_request(GPIO_FN_LCDD18, NULL);
  1252. gpio_request(GPIO_FN_LCDD17, NULL);
  1253. gpio_request(GPIO_FN_LCDD16, NULL);
  1254. gpio_request(GPIO_FN_LCDD15, NULL);
  1255. gpio_request(GPIO_FN_LCDD14, NULL);
  1256. gpio_request(GPIO_FN_LCDD13, NULL);
  1257. gpio_request(GPIO_FN_LCDD12, NULL);
  1258. gpio_request(GPIO_FN_LCDD11, NULL);
  1259. gpio_request(GPIO_FN_LCDD10, NULL);
  1260. gpio_request(GPIO_FN_LCDD9, NULL);
  1261. gpio_request(GPIO_FN_LCDD8, NULL);
  1262. gpio_request(GPIO_FN_LCDD7, NULL);
  1263. gpio_request(GPIO_FN_LCDD6, NULL);
  1264. gpio_request(GPIO_FN_LCDD5, NULL);
  1265. gpio_request(GPIO_FN_LCDD4, NULL);
  1266. gpio_request(GPIO_FN_LCDD3, NULL);
  1267. gpio_request(GPIO_FN_LCDD2, NULL);
  1268. gpio_request(GPIO_FN_LCDD1, NULL);
  1269. gpio_request(GPIO_FN_LCDD0, NULL);
  1270. gpio_request(GPIO_FN_LCDDISP, NULL);
  1271. gpio_request(GPIO_FN_LCDDCK, NULL);
  1272. gpio_request(GPIO_PORT31, NULL); /* backlight */
  1273. gpio_direction_output(GPIO_PORT31, 0); /* off by default */
  1274. gpio_request(GPIO_PORT151, NULL); /* LCDDON */
  1275. gpio_direction_output(GPIO_PORT151, 1);
  1276. /* USBHS0 */
  1277. gpio_request(GPIO_FN_VBUS0_0, NULL);
  1278. gpio_pull_down(GPIO_PORT168CR); /* VBUS0_0 pull down */
  1279. /* USBHS1 */
  1280. gpio_request(GPIO_FN_VBUS0_1, NULL);
  1281. gpio_pull_down(GPIO_PORT167CR); /* VBUS0_1 pull down */
  1282. gpio_request(GPIO_FN_IDIN_1_113, NULL);
  1283. /* USB phy tweak to make the r8a66597_hcd host driver work */
  1284. __raw_writew(0x8a0a, 0xe6058130); /* USBCR4 */
  1285. /* enable FSI2 port A (ak4643) */
  1286. gpio_request(GPIO_FN_FSIAIBT, NULL);
  1287. gpio_request(GPIO_FN_FSIAILR, NULL);
  1288. gpio_request(GPIO_FN_FSIAISLD, NULL);
  1289. gpio_request(GPIO_FN_FSIAOSLD, NULL);
  1290. gpio_request(GPIO_PORT161, NULL);
  1291. gpio_direction_output(GPIO_PORT161, 0); /* slave */
  1292. gpio_request(GPIO_PORT9, NULL);
  1293. gpio_request(GPIO_PORT10, NULL);
  1294. gpio_no_direction(GPIO_PORT9CR); /* FSIAOBT needs no direction */
  1295. gpio_no_direction(GPIO_PORT10CR); /* FSIAOLR needs no direction */
  1296. intc_set_priority(IRQ_FSI, 3); /* irq priority FSI(3) > SMSC911X(2) */
  1297. /* setup FSI2 port B (HDMI) */
  1298. gpio_request(GPIO_FN_FSIBCK, NULL);
  1299. __raw_writew(__raw_readw(USCCR1) & ~(1 << 6), USCCR1); /* use SPDIF */
  1300. /* set SPU2 clock to 119.6 MHz */
  1301. clk = clk_get(NULL, "spu_clk");
  1302. if (!IS_ERR(clk)) {
  1303. clk_set_rate(clk, clk_round_rate(clk, 119600000));
  1304. clk_put(clk);
  1305. }
  1306. /* enable Keypad */
  1307. gpio_request(GPIO_FN_IRQ9_42, NULL);
  1308. irq_set_irq_type(IRQ9, IRQ_TYPE_LEVEL_HIGH);
  1309. /* enable Touchscreen */
  1310. gpio_request(GPIO_FN_IRQ7_40, NULL);
  1311. irq_set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
  1312. /* enable Accelerometer */
  1313. gpio_request(GPIO_FN_IRQ21, NULL);
  1314. irq_set_irq_type(IRQ21, IRQ_TYPE_LEVEL_HIGH);
  1315. /* enable SDHI0 */
  1316. gpio_request(GPIO_FN_SDHICD0, NULL);
  1317. gpio_request(GPIO_FN_SDHIWP0, NULL);
  1318. gpio_request(GPIO_FN_SDHICMD0, NULL);
  1319. gpio_request(GPIO_FN_SDHICLK0, NULL);
  1320. gpio_request(GPIO_FN_SDHID0_3, NULL);
  1321. gpio_request(GPIO_FN_SDHID0_2, NULL);
  1322. gpio_request(GPIO_FN_SDHID0_1, NULL);
  1323. gpio_request(GPIO_FN_SDHID0_0, NULL);
  1324. ret = request_irq(evt2irq(0x3340), mackerel_sdhi0_gpio_cd,
  1325. IRQF_TRIGGER_FALLING, "sdhi0 cd", &sdhi0_device.dev);
  1326. if (!ret)
  1327. sdhi0_info.tmio_flags |= TMIO_MMC_HAS_COLD_CD;
  1328. else
  1329. pr_err("Cannot get IRQ #%d: %d\n", evt2irq(0x3340), ret);
  1330. #if !defined(CONFIG_MMC_SH_MMCIF) && !defined(CONFIG_MMC_SH_MMCIF_MODULE)
  1331. /* enable SDHI1 */
  1332. gpio_request(GPIO_FN_SDHICMD1, NULL);
  1333. gpio_request(GPIO_FN_SDHICLK1, NULL);
  1334. gpio_request(GPIO_FN_SDHID1_3, NULL);
  1335. gpio_request(GPIO_FN_SDHID1_2, NULL);
  1336. gpio_request(GPIO_FN_SDHID1_1, NULL);
  1337. gpio_request(GPIO_FN_SDHID1_0, NULL);
  1338. #endif
  1339. /* card detect pin for MMC slot (CN7) */
  1340. gpio_request(GPIO_PORT41, NULL);
  1341. gpio_direction_input(GPIO_PORT41);
  1342. /* enable SDHI2 */
  1343. gpio_request(GPIO_FN_SDHICMD2, NULL);
  1344. gpio_request(GPIO_FN_SDHICLK2, NULL);
  1345. gpio_request(GPIO_FN_SDHID2_3, NULL);
  1346. gpio_request(GPIO_FN_SDHID2_2, NULL);
  1347. gpio_request(GPIO_FN_SDHID2_1, NULL);
  1348. gpio_request(GPIO_FN_SDHID2_0, NULL);
  1349. /* card detect pin for microSD slot (CN23) */
  1350. gpio_request(GPIO_PORT162, NULL);
  1351. gpio_direction_input(GPIO_PORT162);
  1352. /* MMCIF */
  1353. gpio_request(GPIO_FN_MMCD0_0, NULL);
  1354. gpio_request(GPIO_FN_MMCD0_1, NULL);
  1355. gpio_request(GPIO_FN_MMCD0_2, NULL);
  1356. gpio_request(GPIO_FN_MMCD0_3, NULL);
  1357. gpio_request(GPIO_FN_MMCD0_4, NULL);
  1358. gpio_request(GPIO_FN_MMCD0_5, NULL);
  1359. gpio_request(GPIO_FN_MMCD0_6, NULL);
  1360. gpio_request(GPIO_FN_MMCD0_7, NULL);
  1361. gpio_request(GPIO_FN_MMCCMD0, NULL);
  1362. gpio_request(GPIO_FN_MMCCLK0, NULL);
  1363. /* enable GPS module (GT-720F) */
  1364. gpio_request(GPIO_FN_SCIFA2_TXD1, NULL);
  1365. gpio_request(GPIO_FN_SCIFA2_RXD1, NULL);
  1366. /* CEU */
  1367. gpio_request(GPIO_FN_VIO_CLK, NULL);
  1368. gpio_request(GPIO_FN_VIO_VD, NULL);
  1369. gpio_request(GPIO_FN_VIO_HD, NULL);
  1370. gpio_request(GPIO_FN_VIO_FIELD, NULL);
  1371. gpio_request(GPIO_FN_VIO_CKO, NULL);
  1372. gpio_request(GPIO_FN_VIO_D7, NULL);
  1373. gpio_request(GPIO_FN_VIO_D6, NULL);
  1374. gpio_request(GPIO_FN_VIO_D5, NULL);
  1375. gpio_request(GPIO_FN_VIO_D4, NULL);
  1376. gpio_request(GPIO_FN_VIO_D3, NULL);
  1377. gpio_request(GPIO_FN_VIO_D2, NULL);
  1378. gpio_request(GPIO_FN_VIO_D1, NULL);
  1379. gpio_request(GPIO_FN_VIO_D0, NULL);
  1380. /* HDMI */
  1381. gpio_request(GPIO_FN_HDMI_HPD, NULL);
  1382. gpio_request(GPIO_FN_HDMI_CEC, NULL);
  1383. /* Reset HDMI, must be held at least one EXTALR (32768Hz) period */
  1384. srcr4 = __raw_readl(SRCR4);
  1385. __raw_writel(srcr4 | (1 << 13), SRCR4);
  1386. udelay(50);
  1387. __raw_writel(srcr4 & ~(1 << 13), SRCR4);
  1388. i2c_register_board_info(0, i2c0_devices,
  1389. ARRAY_SIZE(i2c0_devices));
  1390. i2c_register_board_info(1, i2c1_devices,
  1391. ARRAY_SIZE(i2c1_devices));
  1392. sh7372_add_standard_devices();
  1393. platform_add_devices(mackerel_devices, ARRAY_SIZE(mackerel_devices));
  1394. hdmi_init_pm_clock();
  1395. sh7372_pm_init();
  1396. }
  1397. static void __init mackerel_timer_init(void)
  1398. {
  1399. sh7372_clock_init();
  1400. shmobile_timer.init();
  1401. /* External clock source */
  1402. clk_set_rate(&sh7372_dv_clki_clk, 27000000);
  1403. }
  1404. static struct sys_timer mackerel_timer = {
  1405. .init = mackerel_timer_init,
  1406. };
  1407. MACHINE_START(MACKEREL, "mackerel")
  1408. .map_io = mackerel_map_io,
  1409. .init_irq = sh7372_init_irq,
  1410. .handle_irq = shmobile_handle_irq_intc,
  1411. .init_machine = mackerel_init,
  1412. .timer = &mackerel_timer,
  1413. MACHINE_END