board-mackerel.c 39 KB

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