board-mackerel.c 38 KB

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