board-mackerel.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  1. /*
  2. * mackerel board support
  3. *
  4. * Copyright (C) 2010 Renesas Solutions Corp.
  5. * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  7. * based on ap4evb
  8. * Copyright (C) 2010 Magnus Damm
  9. * Copyright (C) 2008 Yoshihiro Shimoda
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; version 2 of the License.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #include <linux/delay.h>
  25. #include <linux/kernel.h>
  26. #include <linux/init.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/irq.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/gpio.h>
  31. #include <linux/input.h>
  32. #include <linux/io.h>
  33. #include <linux/i2c.h>
  34. #include <linux/leds.h>
  35. #include <linux/mfd/tmio.h>
  36. #include <linux/mmc/host.h>
  37. #include <linux/mmc/sh_mmcif.h>
  38. #include <linux/mmc/sh_mobile_sdhi.h>
  39. #include <linux/mtd/mtd.h>
  40. #include <linux/mtd/partitions.h>
  41. #include <linux/mtd/physmap.h>
  42. #include <linux/mtd/sh_flctl.h>
  43. #include <linux/pinctrl/machine.h>
  44. #include <linux/pinctrl/pinconf-generic.h>
  45. #include <linux/platform_data/gpio_backlight.h>
  46. #include <linux/pm_clock.h>
  47. #include <linux/regulator/fixed.h>
  48. #include <linux/regulator/machine.h>
  49. #include <linux/smsc911x.h>
  50. #include <linux/sh_intc.h>
  51. #include <linux/tca6416_keypad.h>
  52. #include <linux/usb/renesas_usbhs.h>
  53. #include <linux/dma-mapping.h>
  54. #include <video/sh_mobile_hdmi.h>
  55. #include <video/sh_mobile_lcdc.h>
  56. #include <media/sh_mobile_ceu.h>
  57. #include <media/soc_camera.h>
  58. #include <media/soc_camera_platform.h>
  59. #include <sound/sh_fsi.h>
  60. #include <sound/simple_card.h>
  61. #include <mach/common.h>
  62. #include <mach/irqs.h>
  63. #include <mach/sh7372.h>
  64. #include <asm/mach/arch.h>
  65. #include <asm/mach-types.h>
  66. #include "sh-gpio.h"
  67. /*
  68. * Address Interface BusWidth note
  69. * ------------------------------------------------------------------
  70. * 0x0000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = ON
  71. * 0x0800_0000 user area -
  72. * 0x1000_0000 NOR Flash ROM (MCP) 16bit SW7 : bit1 = OFF
  73. * 0x1400_0000 Ether (LAN9220) 16bit
  74. * 0x1600_0000 user area - cannot use with NAND
  75. * 0x1800_0000 user area -
  76. * 0x1A00_0000 -
  77. * 0x4000_0000 LPDDR2-SDRAM (POP) 32bit
  78. */
  79. /*
  80. * CPU mode
  81. *
  82. * SW4 | Boot Area| Master | Remarks
  83. * 1 | 2 | 3 | 4 | 5 | 6 | 8 | | Processor|
  84. * ----+-----+-----+-----+-----+-----+-----+----------+----------+--------------
  85. * ON | ON | OFF | ON | ON | OFF | OFF | External | System | External ROM
  86. * ON | ON | ON | ON | ON | OFF | OFF | External | System | ROM Debug
  87. * ON | ON | X | ON | OFF | OFF | OFF | Built-in | System | ROM Debug
  88. * X | OFF | X | X | X | X | OFF | Built-in | System | MaskROM
  89. * OFF | X | X | X | X | X | OFF | Built-in | System | MaskROM
  90. * X | X | X | OFF | X | X | OFF | Built-in | System | MaskROM
  91. * OFF | ON | OFF | X | X | OFF | ON | External | System | Standalone
  92. * ON | OFF | OFF | X | X | OFF | ON | External | Realtime | Standalone
  93. */
  94. /*
  95. * NOR Flash ROM
  96. *
  97. * SW1 | SW2 | SW7 | NOR Flash ROM
  98. * bit1 | bit1 bit2 | bit1 | Memory allocation
  99. * ------+------------+------+------------------
  100. * OFF | ON OFF | ON | Area 0
  101. * OFF | ON OFF | OFF | Area 4
  102. */
  103. /*
  104. * SMSC 9220
  105. *
  106. * SW1 SMSC 9220
  107. * -----------------------
  108. * ON access disable
  109. * OFF access enable
  110. */
  111. /*
  112. * NAND Flash ROM
  113. *
  114. * SW1 | SW2 | SW7 | NAND Flash ROM
  115. * bit1 | bit1 bit2 | bit2 | Memory allocation
  116. * ------+------------+------+------------------
  117. * OFF | ON OFF | ON | FCE 0
  118. * OFF | ON OFF | OFF | FCE 1
  119. */
  120. /*
  121. * External interrupt pin settings
  122. *
  123. * IRQX | pin setting | device | level
  124. * ------+--------------------+--------------------+-------
  125. * IRQ0 | ICR1A.IRQ0SA=0010 | SDHI2 card detect | Low
  126. * IRQ6 | ICR1A.IRQ6SA=0011 | Ether(LAN9220) | High
  127. * IRQ7 | ICR1A.IRQ7SA=0010 | LCD Touch Panel | Low
  128. * IRQ8 | ICR2A.IRQ8SA=0010 | MMC/SD card detect | Low
  129. * IRQ9 | ICR2A.IRQ9SA=0010 | KEY(TCA6408) | Low
  130. * IRQ21 | ICR4A.IRQ21SA=0011 | Sensor(ADXL345) | High
  131. * IRQ22 | ICR4A.IRQ22SA=0011 | Sensor(AK8975) | High
  132. */
  133. /*
  134. * USB
  135. *
  136. * USB0 : CN22 : Function
  137. * USB1 : CN31 : Function/Host *1
  138. *
  139. * J30 (for CN31) *1
  140. * ----------+---------------+-------------
  141. * 1-2 short | VBUS 5V | Host
  142. * open | external VBUS | 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. /*
  157. * SDHI0 (CN12)
  158. *
  159. * SW56 : OFF
  160. *
  161. */
  162. /* MMC /SDHI1 (CN7)
  163. *
  164. * I/O voltage : 1.8v
  165. *
  166. * Power voltage : 1.8v or 3.3v
  167. * J22 : select power voltage *1
  168. * 1-2 pin : 1.8v
  169. * 2-3 pin : 3.3v
  170. *
  171. * *1
  172. * Please change J22 depends the card to be used.
  173. * MMC's OCR field set to support either voltage for the card inserted.
  174. *
  175. * SW1 | SW33
  176. * | bit1 | bit2 | bit3 | bit4
  177. * -------------+------+------+------+-------
  178. * MMC0 OFF | OFF | X | ON | X (Use MMCIF)
  179. * SDHI1 OFF | ON | X | OFF | X (Use MFD_SH_MOBILE_SDHI)
  180. *
  181. */
  182. /*
  183. * SDHI2 (CN23)
  184. *
  185. * microSD card sloct
  186. *
  187. */
  188. /*
  189. * FSI - AK4642
  190. *
  191. * it needs amixer settings for playing
  192. *
  193. * amixer set "Headphone Enable" on
  194. */
  195. /* Fixed 3.3V and 1.8V regulators to be used by multiple devices */
  196. static struct regulator_consumer_supply fixed1v8_power_consumers[] =
  197. {
  198. /*
  199. * J22 on mackerel switches mmcif.0 and sdhi.1 between 1.8V and 3.3V
  200. * Since we cannot support both voltages, we support the default 1.8V
  201. */
  202. REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.1"),
  203. REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.1"),
  204. REGULATOR_SUPPLY("vmmc", "sh_mmcif.0"),
  205. REGULATOR_SUPPLY("vqmmc", "sh_mmcif.0"),
  206. };
  207. static struct regulator_consumer_supply fixed3v3_power_consumers[] =
  208. {
  209. REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.0"),
  210. REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.0"),
  211. REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi.2"),
  212. REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi.2"),
  213. };
  214. /* Dummy supplies, where voltage doesn't matter */
  215. static struct regulator_consumer_supply dummy_supplies[] = {
  216. REGULATOR_SUPPLY("vddvario", "smsc911x"),
  217. REGULATOR_SUPPLY("vdd33a", "smsc911x"),
  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 = "regs",
  302. .start = 0xe8000000,
  303. .end = 0xe807ffff,
  304. .flags = IORESOURCE_MEM,
  305. },
  306. [1] = {
  307. .name = "meram",
  308. .start = 0xe8080000,
  309. .end = 0xe81fffff,
  310. .flags = IORESOURCE_MEM,
  311. },
  312. };
  313. static struct platform_device meram_device = {
  314. .name = "sh_mobile_meram",
  315. .id = 0,
  316. .num_resources = ARRAY_SIZE(meram_resources),
  317. .resource = meram_resources,
  318. .dev = {
  319. .platform_data = &mackerel_meram_info,
  320. },
  321. };
  322. /* LCDC and backlight */
  323. static struct fb_videomode mackerel_lcdc_modes[] = {
  324. {
  325. .name = "WVGA Panel",
  326. .xres = 800,
  327. .yres = 480,
  328. .left_margin = 220,
  329. .right_margin = 110,
  330. .hsync_len = 70,
  331. .upper_margin = 20,
  332. .lower_margin = 5,
  333. .vsync_len = 5,
  334. .sync = 0,
  335. },
  336. };
  337. static const struct sh_mobile_meram_cfg lcd_meram_cfg = {
  338. .icb[0] = {
  339. .meram_size = 0x40,
  340. },
  341. .icb[1] = {
  342. .meram_size = 0x40,
  343. },
  344. };
  345. static struct sh_mobile_lcdc_info lcdc_info = {
  346. .meram_dev = &mackerel_meram_info,
  347. .clock_source = LCDC_CLK_BUS,
  348. .ch[0] = {
  349. .chan = LCDC_CHAN_MAINLCD,
  350. .fourcc = V4L2_PIX_FMT_RGB565,
  351. .lcd_modes = mackerel_lcdc_modes,
  352. .num_modes = ARRAY_SIZE(mackerel_lcdc_modes),
  353. .interface_type = RGB24,
  354. .clock_divider = 3,
  355. .flags = 0,
  356. .panel_cfg = {
  357. .width = 152,
  358. .height = 91,
  359. },
  360. .meram_cfg = &lcd_meram_cfg,
  361. }
  362. };
  363. static struct resource lcdc_resources[] = {
  364. [0] = {
  365. .name = "LCDC",
  366. .start = 0xfe940000,
  367. .end = 0xfe943fff,
  368. .flags = IORESOURCE_MEM,
  369. },
  370. [1] = {
  371. .start = intcs_evt2irq(0x580),
  372. .flags = IORESOURCE_IRQ,
  373. },
  374. };
  375. static struct platform_device lcdc_device = {
  376. .name = "sh_mobile_lcdc_fb",
  377. .num_resources = ARRAY_SIZE(lcdc_resources),
  378. .resource = lcdc_resources,
  379. .dev = {
  380. .platform_data = &lcdc_info,
  381. .coherent_dma_mask = DMA_BIT_MASK(32),
  382. },
  383. };
  384. static struct gpio_backlight_platform_data gpio_backlight_data = {
  385. .fbdev = &lcdc_device.dev,
  386. .gpio = 31,
  387. .def_value = 1,
  388. .name = "backlight",
  389. };
  390. static struct platform_device gpio_backlight_device = {
  391. .name = "gpio-backlight",
  392. .dev = {
  393. .platform_data = &gpio_backlight_data,
  394. },
  395. };
  396. /* HDMI */
  397. static struct sh_mobile_hdmi_info hdmi_info = {
  398. .flags = HDMI_SND_SRC_SPDIF,
  399. };
  400. static struct resource hdmi_resources[] = {
  401. [0] = {
  402. .name = "HDMI",
  403. .start = 0xe6be0000,
  404. .end = 0xe6be00ff,
  405. .flags = IORESOURCE_MEM,
  406. },
  407. [1] = {
  408. /* There's also an HDMI interrupt on INTCS @ 0x18e0 */
  409. .start = evt2irq(0x17e0),
  410. .flags = IORESOURCE_IRQ,
  411. },
  412. };
  413. static struct platform_device hdmi_device = {
  414. .name = "sh-mobile-hdmi",
  415. .num_resources = ARRAY_SIZE(hdmi_resources),
  416. .resource = hdmi_resources,
  417. .id = -1,
  418. .dev = {
  419. .platform_data = &hdmi_info,
  420. },
  421. };
  422. static const struct sh_mobile_meram_cfg hdmi_meram_cfg = {
  423. .icb[0] = {
  424. .meram_size = 0x100,
  425. },
  426. .icb[1] = {
  427. .meram_size = 0x100,
  428. },
  429. };
  430. static struct sh_mobile_lcdc_info hdmi_lcdc_info = {
  431. .meram_dev = &mackerel_meram_info,
  432. .clock_source = LCDC_CLK_EXTERNAL,
  433. .ch[0] = {
  434. .chan = LCDC_CHAN_MAINLCD,
  435. .fourcc = V4L2_PIX_FMT_RGB565,
  436. .interface_type = RGB24,
  437. .clock_divider = 1,
  438. .flags = LCDC_FLAGS_DWPOL,
  439. .meram_cfg = &hdmi_meram_cfg,
  440. .tx_dev = &hdmi_device,
  441. }
  442. };
  443. static struct resource hdmi_lcdc_resources[] = {
  444. [0] = {
  445. .name = "LCDC1",
  446. .start = 0xfe944000,
  447. .end = 0xfe947fff,
  448. .flags = IORESOURCE_MEM,
  449. },
  450. [1] = {
  451. .start = intcs_evt2irq(0x1780),
  452. .flags = IORESOURCE_IRQ,
  453. },
  454. };
  455. static struct platform_device hdmi_lcdc_device = {
  456. .name = "sh_mobile_lcdc_fb",
  457. .num_resources = ARRAY_SIZE(hdmi_lcdc_resources),
  458. .resource = hdmi_lcdc_resources,
  459. .id = 1,
  460. .dev = {
  461. .platform_data = &hdmi_lcdc_info,
  462. .coherent_dma_mask = DMA_BIT_MASK(32),
  463. },
  464. };
  465. static struct asoc_simple_card_info fsi2_hdmi_info = {
  466. .name = "HDMI",
  467. .card = "FSI2B-HDMI",
  468. .codec = "sh-mobile-hdmi",
  469. .platform = "sh_fsi2",
  470. .cpu_dai = {
  471. .name = "fsib-dai",
  472. .fmt = SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF,
  473. },
  474. .codec_dai = {
  475. .name = "sh_mobile_hdmi-hifi",
  476. },
  477. };
  478. static struct platform_device fsi_hdmi_device = {
  479. .name = "asoc-simple-card",
  480. .id = 1,
  481. .dev = {
  482. .platform_data = &fsi2_hdmi_info,
  483. },
  484. };
  485. static void __init hdmi_init_pm_clock(void)
  486. {
  487. struct clk *hdmi_ick = clk_get(&hdmi_device.dev, "ick");
  488. int ret;
  489. long rate;
  490. if (IS_ERR(hdmi_ick)) {
  491. ret = PTR_ERR(hdmi_ick);
  492. pr_err("Cannot get HDMI ICK: %d\n", ret);
  493. goto out;
  494. }
  495. ret = clk_set_parent(&sh7372_pllc2_clk, &sh7372_dv_clki_div2_clk);
  496. if (ret < 0) {
  497. pr_err("Cannot set PLLC2 parent: %d, %d users\n",
  498. ret, sh7372_pllc2_clk.usecount);
  499. goto out;
  500. }
  501. pr_debug("PLLC2 initial frequency %lu\n",
  502. clk_get_rate(&sh7372_pllc2_clk));
  503. rate = clk_round_rate(&sh7372_pllc2_clk, 594000000);
  504. if (rate <= 0) {
  505. pr_err("Cannot get suitable rate: %ld\n", rate);
  506. ret = -EINVAL;
  507. goto out;
  508. }
  509. ret = clk_set_rate(&sh7372_pllc2_clk, rate);
  510. if (ret < 0) {
  511. pr_err("Cannot set rate %ld: %d\n", rate, ret);
  512. goto out;
  513. }
  514. pr_debug("PLLC2 set frequency %lu\n", rate);
  515. ret = clk_set_parent(hdmi_ick, &sh7372_pllc2_clk);
  516. if (ret < 0)
  517. pr_err("Cannot set HDMI parent: %d\n", ret);
  518. out:
  519. if (!IS_ERR(hdmi_ick))
  520. clk_put(hdmi_ick);
  521. }
  522. /* USBHS0 is connected to CN22 which takes a USB Mini-B plug
  523. *
  524. * The sh7372 SoC has IRQ7 set aside for USBHS0 hotplug,
  525. * but on this particular board IRQ7 is already used by
  526. * the touch screen. This leaves us with software polling.
  527. */
  528. #define USBHS0_POLL_INTERVAL (HZ * 5)
  529. struct usbhs_private {
  530. void __iomem *usbphyaddr;
  531. void __iomem *usbcrcaddr;
  532. struct renesas_usbhs_platform_info info;
  533. struct delayed_work work;
  534. struct platform_device *pdev;
  535. };
  536. #define usbhs_get_priv(pdev) \
  537. container_of(renesas_usbhs_get_info(pdev), \
  538. struct usbhs_private, info)
  539. #define usbhs_is_connected(priv) \
  540. (!((1 << 7) & __raw_readw(priv->usbcrcaddr)))
  541. static int usbhs_get_vbus(struct platform_device *pdev)
  542. {
  543. return usbhs_is_connected(usbhs_get_priv(pdev));
  544. }
  545. static int usbhs_phy_reset(struct platform_device *pdev)
  546. {
  547. struct usbhs_private *priv = usbhs_get_priv(pdev);
  548. /* init phy */
  549. __raw_writew(0x8a0a, priv->usbcrcaddr);
  550. return 0;
  551. }
  552. static int usbhs0_get_id(struct platform_device *pdev)
  553. {
  554. return USBHS_GADGET;
  555. }
  556. static void usbhs0_work_function(struct work_struct *work)
  557. {
  558. struct usbhs_private *priv = container_of(work, struct usbhs_private,
  559. work.work);
  560. renesas_usbhs_call_notify_hotplug(priv->pdev);
  561. schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
  562. }
  563. static int usbhs0_hardware_init(struct platform_device *pdev)
  564. {
  565. struct usbhs_private *priv = usbhs_get_priv(pdev);
  566. priv->pdev = pdev;
  567. INIT_DELAYED_WORK(&priv->work, usbhs0_work_function);
  568. schedule_delayed_work(&priv->work, USBHS0_POLL_INTERVAL);
  569. return 0;
  570. }
  571. static int usbhs0_hardware_exit(struct platform_device *pdev)
  572. {
  573. struct usbhs_private *priv = usbhs_get_priv(pdev);
  574. cancel_delayed_work_sync(&priv->work);
  575. return 0;
  576. }
  577. static struct usbhs_private usbhs0_private = {
  578. .usbcrcaddr = IOMEM(0xe605810c), /* USBCR2 */
  579. .info = {
  580. .platform_callback = {
  581. .hardware_init = usbhs0_hardware_init,
  582. .hardware_exit = usbhs0_hardware_exit,
  583. .phy_reset = usbhs_phy_reset,
  584. .get_id = usbhs0_get_id,
  585. .get_vbus = usbhs_get_vbus,
  586. },
  587. .driver_param = {
  588. .buswait_bwait = 4,
  589. .d0_tx_id = SHDMA_SLAVE_USB0_TX,
  590. .d1_rx_id = SHDMA_SLAVE_USB0_RX,
  591. },
  592. },
  593. };
  594. static struct resource usbhs0_resources[] = {
  595. [0] = {
  596. .name = "USBHS0",
  597. .start = 0xe6890000,
  598. .end = 0xe68900e6 - 1,
  599. .flags = IORESOURCE_MEM,
  600. },
  601. [1] = {
  602. .start = evt2irq(0x1ca0) /* USB0_USB0I0 */,
  603. .flags = IORESOURCE_IRQ,
  604. },
  605. };
  606. static struct platform_device usbhs0_device = {
  607. .name = "renesas_usbhs",
  608. .id = 0,
  609. .dev = {
  610. .platform_data = &usbhs0_private.info,
  611. },
  612. .num_resources = ARRAY_SIZE(usbhs0_resources),
  613. .resource = usbhs0_resources,
  614. };
  615. /* USBHS1 is connected to CN31 which takes a USB Mini-AB plug
  616. *
  617. * Use J30 to select between Host and Function. This setting
  618. * can however not be detected by software. Hotplug of USBHS1
  619. * is provided via IRQ8.
  620. *
  621. * Current USB1 works as "USB Host".
  622. * - set J30 "short"
  623. *
  624. * If you want to use it as "USB gadget",
  625. * - J30 "open"
  626. * - modify usbhs1_get_id() USBHS_HOST -> USBHS_GADGET
  627. * - add .get_vbus = usbhs_get_vbus in usbhs1_private
  628. * - check usbhs0_device(pio)/usbhs1_device(irq) order in mackerel_devices.
  629. */
  630. #define IRQ8 evt2irq(0x0300)
  631. #define USB_PHY_MODE (1 << 4)
  632. #define USB_PHY_INT_EN ((1 << 3) | (1 << 2))
  633. #define USB_PHY_ON (1 << 1)
  634. #define USB_PHY_OFF (1 << 0)
  635. #define USB_PHY_INT_CLR (USB_PHY_ON | USB_PHY_OFF)
  636. static irqreturn_t usbhs1_interrupt(int irq, void *data)
  637. {
  638. struct platform_device *pdev = data;
  639. struct usbhs_private *priv = usbhs_get_priv(pdev);
  640. dev_dbg(&pdev->dev, "%s\n", __func__);
  641. renesas_usbhs_call_notify_hotplug(pdev);
  642. /* clear status */
  643. __raw_writew(__raw_readw(priv->usbphyaddr) | USB_PHY_INT_CLR,
  644. priv->usbphyaddr);
  645. return IRQ_HANDLED;
  646. }
  647. static int usbhs1_hardware_init(struct platform_device *pdev)
  648. {
  649. struct usbhs_private *priv = usbhs_get_priv(pdev);
  650. int ret;
  651. /* clear interrupt status */
  652. __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
  653. ret = request_irq(IRQ8, usbhs1_interrupt, IRQF_TRIGGER_HIGH,
  654. dev_name(&pdev->dev), pdev);
  655. if (ret) {
  656. dev_err(&pdev->dev, "request_irq err\n");
  657. return ret;
  658. }
  659. /* enable USB phy interrupt */
  660. __raw_writew(USB_PHY_MODE | USB_PHY_INT_EN, priv->usbphyaddr);
  661. return 0;
  662. }
  663. static int usbhs1_hardware_exit(struct platform_device *pdev)
  664. {
  665. struct usbhs_private *priv = usbhs_get_priv(pdev);
  666. /* clear interrupt status */
  667. __raw_writew(USB_PHY_MODE | USB_PHY_INT_CLR, priv->usbphyaddr);
  668. free_irq(IRQ8, pdev);
  669. return 0;
  670. }
  671. static int usbhs1_get_id(struct platform_device *pdev)
  672. {
  673. return USBHS_HOST;
  674. }
  675. static u32 usbhs1_pipe_cfg[] = {
  676. USB_ENDPOINT_XFER_CONTROL,
  677. USB_ENDPOINT_XFER_ISOC,
  678. USB_ENDPOINT_XFER_ISOC,
  679. USB_ENDPOINT_XFER_BULK,
  680. USB_ENDPOINT_XFER_BULK,
  681. USB_ENDPOINT_XFER_BULK,
  682. USB_ENDPOINT_XFER_INT,
  683. USB_ENDPOINT_XFER_INT,
  684. USB_ENDPOINT_XFER_INT,
  685. USB_ENDPOINT_XFER_BULK,
  686. USB_ENDPOINT_XFER_BULK,
  687. USB_ENDPOINT_XFER_BULK,
  688. USB_ENDPOINT_XFER_BULK,
  689. USB_ENDPOINT_XFER_BULK,
  690. USB_ENDPOINT_XFER_BULK,
  691. USB_ENDPOINT_XFER_BULK,
  692. };
  693. static struct usbhs_private usbhs1_private = {
  694. .usbphyaddr = IOMEM(0xe60581e2), /* USBPHY1INTAP */
  695. .usbcrcaddr = IOMEM(0xe6058130), /* USBCR4 */
  696. .info = {
  697. .platform_callback = {
  698. .hardware_init = usbhs1_hardware_init,
  699. .hardware_exit = usbhs1_hardware_exit,
  700. .get_id = usbhs1_get_id,
  701. .phy_reset = usbhs_phy_reset,
  702. },
  703. .driver_param = {
  704. .buswait_bwait = 4,
  705. .has_otg = 1,
  706. .pipe_type = usbhs1_pipe_cfg,
  707. .pipe_size = ARRAY_SIZE(usbhs1_pipe_cfg),
  708. .d0_tx_id = SHDMA_SLAVE_USB1_TX,
  709. .d1_rx_id = SHDMA_SLAVE_USB1_RX,
  710. },
  711. },
  712. };
  713. static struct resource usbhs1_resources[] = {
  714. [0] = {
  715. .name = "USBHS1",
  716. .start = 0xe68b0000,
  717. .end = 0xe68b00e6 - 1,
  718. .flags = IORESOURCE_MEM,
  719. },
  720. [1] = {
  721. .start = evt2irq(0x1ce0) /* USB1_USB1I0 */,
  722. .flags = IORESOURCE_IRQ,
  723. },
  724. };
  725. static struct platform_device usbhs1_device = {
  726. .name = "renesas_usbhs",
  727. .id = 1,
  728. .dev = {
  729. .platform_data = &usbhs1_private.info,
  730. .dma_mask = &usbhs1_device.dev.coherent_dma_mask,
  731. .coherent_dma_mask = DMA_BIT_MASK(32),
  732. },
  733. .num_resources = ARRAY_SIZE(usbhs1_resources),
  734. .resource = usbhs1_resources,
  735. };
  736. /* LED */
  737. static struct gpio_led mackerel_leds[] = {
  738. {
  739. .name = "led0",
  740. .gpio = 0,
  741. .default_state = LEDS_GPIO_DEFSTATE_ON,
  742. },
  743. {
  744. .name = "led1",
  745. .gpio = 1,
  746. .default_state = LEDS_GPIO_DEFSTATE_ON,
  747. },
  748. {
  749. .name = "led2",
  750. .gpio = 2,
  751. .default_state = LEDS_GPIO_DEFSTATE_ON,
  752. },
  753. {
  754. .name = "led3",
  755. .gpio = 159,
  756. .default_state = LEDS_GPIO_DEFSTATE_ON,
  757. }
  758. };
  759. static struct gpio_led_platform_data mackerel_leds_pdata = {
  760. .leds = mackerel_leds,
  761. .num_leds = ARRAY_SIZE(mackerel_leds),
  762. };
  763. static struct platform_device leds_device = {
  764. .name = "leds-gpio",
  765. .id = 0,
  766. .dev = {
  767. .platform_data = &mackerel_leds_pdata,
  768. },
  769. };
  770. /* FSI */
  771. #define IRQ_FSI evt2irq(0x1840)
  772. static struct sh_fsi_platform_info fsi_info = {
  773. .port_a = {
  774. .tx_id = SHDMA_SLAVE_FSIA_TX,
  775. .rx_id = SHDMA_SLAVE_FSIA_RX,
  776. },
  777. .port_b = {
  778. .flags = SH_FSI_CLK_CPG |
  779. SH_FSI_FMT_SPDIF,
  780. }
  781. };
  782. static struct resource fsi_resources[] = {
  783. [0] = {
  784. /* we need 0xFE1F0000 to access DMA
  785. * instead of 0xFE3C0000 */
  786. .name = "FSI",
  787. .start = 0xFE1F0000,
  788. .end = 0xFE1F0400 - 1,
  789. .flags = IORESOURCE_MEM,
  790. },
  791. [1] = {
  792. .start = IRQ_FSI,
  793. .flags = IORESOURCE_IRQ,
  794. },
  795. };
  796. static struct platform_device fsi_device = {
  797. .name = "sh_fsi2",
  798. .id = -1,
  799. .num_resources = ARRAY_SIZE(fsi_resources),
  800. .resource = fsi_resources,
  801. .dev = {
  802. .platform_data = &fsi_info,
  803. },
  804. };
  805. static struct asoc_simple_card_info fsi2_ak4643_info = {
  806. .name = "AK4643",
  807. .card = "FSI2A-AK4643",
  808. .codec = "ak4642-codec.0-0013",
  809. .platform = "sh_fsi2",
  810. .daifmt = SND_SOC_DAIFMT_LEFT_J,
  811. .cpu_dai = {
  812. .name = "fsia-dai",
  813. .fmt = SND_SOC_DAIFMT_CBS_CFS,
  814. },
  815. .codec_dai = {
  816. .name = "ak4642-hifi",
  817. .fmt = SND_SOC_DAIFMT_CBM_CFM,
  818. .sysclk = 11289600,
  819. },
  820. };
  821. static struct platform_device fsi_ak4643_device = {
  822. .name = "asoc-simple-card",
  823. .dev = {
  824. .platform_data = &fsi2_ak4643_info,
  825. },
  826. };
  827. /* FLCTL */
  828. static struct mtd_partition nand_partition_info[] = {
  829. {
  830. .name = "system",
  831. .offset = 0,
  832. .size = 128 * 1024 * 1024,
  833. },
  834. {
  835. .name = "userdata",
  836. .offset = MTDPART_OFS_APPEND,
  837. .size = 256 * 1024 * 1024,
  838. },
  839. {
  840. .name = "cache",
  841. .offset = MTDPART_OFS_APPEND,
  842. .size = 128 * 1024 * 1024,
  843. },
  844. };
  845. static struct resource nand_flash_resources[] = {
  846. [0] = {
  847. .start = 0xe6a30000,
  848. .end = 0xe6a3009b,
  849. .flags = IORESOURCE_MEM,
  850. },
  851. [1] = {
  852. .start = evt2irq(0x0d80), /* flstei: status error irq */
  853. .flags = IORESOURCE_IRQ,
  854. },
  855. };
  856. static struct sh_flctl_platform_data nand_flash_data = {
  857. .parts = nand_partition_info,
  858. .nr_parts = ARRAY_SIZE(nand_partition_info),
  859. .flcmncr_val = CLK_16B_12L_4H | TYPESEL_SET
  860. | SHBUSSEL | SEL_16BIT | SNAND_E,
  861. .use_holden = 1,
  862. };
  863. static struct platform_device nand_flash_device = {
  864. .name = "sh_flctl",
  865. .resource = nand_flash_resources,
  866. .num_resources = ARRAY_SIZE(nand_flash_resources),
  867. .dev = {
  868. .platform_data = &nand_flash_data,
  869. },
  870. };
  871. /* SDHI0 */
  872. static struct sh_mobile_sdhi_info sdhi0_info = {
  873. .dma_slave_tx = SHDMA_SLAVE_SDHI0_TX,
  874. .dma_slave_rx = SHDMA_SLAVE_SDHI0_RX,
  875. .tmio_flags = TMIO_MMC_USE_GPIO_CD,
  876. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ,
  877. .cd_gpio = 172,
  878. };
  879. static struct resource sdhi0_resources[] = {
  880. {
  881. .name = "SDHI0",
  882. .start = 0xe6850000,
  883. .end = 0xe68500ff,
  884. .flags = IORESOURCE_MEM,
  885. }, {
  886. .name = SH_MOBILE_SDHI_IRQ_SDCARD,
  887. .start = evt2irq(0x0e20) /* SDHI0_SDHI0I1 */,
  888. .flags = IORESOURCE_IRQ,
  889. }, {
  890. .name = SH_MOBILE_SDHI_IRQ_SDIO,
  891. .start = evt2irq(0x0e40) /* SDHI0_SDHI0I2 */,
  892. .flags = IORESOURCE_IRQ,
  893. },
  894. };
  895. static struct platform_device sdhi0_device = {
  896. .name = "sh_mobile_sdhi",
  897. .num_resources = ARRAY_SIZE(sdhi0_resources),
  898. .resource = sdhi0_resources,
  899. .id = 0,
  900. .dev = {
  901. .platform_data = &sdhi0_info,
  902. },
  903. };
  904. #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
  905. /* SDHI1 */
  906. /* GPIO 41 can trigger IRQ8, but it is used by USBHS1, we have to poll */
  907. static struct sh_mobile_sdhi_info sdhi1_info = {
  908. .dma_slave_tx = SHDMA_SLAVE_SDHI1_TX,
  909. .dma_slave_rx = SHDMA_SLAVE_SDHI1_RX,
  910. .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_USE_GPIO_CD,
  911. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
  912. MMC_CAP_NEEDS_POLL,
  913. .cd_gpio = 41,
  914. };
  915. static struct resource sdhi1_resources[] = {
  916. {
  917. .name = "SDHI1",
  918. .start = 0xe6860000,
  919. .end = 0xe68600ff,
  920. .flags = IORESOURCE_MEM,
  921. }, {
  922. .name = SH_MOBILE_SDHI_IRQ_SDCARD,
  923. .start = evt2irq(0x0ea0), /* SDHI1_SDHI1I1 */
  924. .flags = IORESOURCE_IRQ,
  925. }, {
  926. .name = SH_MOBILE_SDHI_IRQ_SDIO,
  927. .start = evt2irq(0x0ec0), /* SDHI1_SDHI1I2 */
  928. .flags = IORESOURCE_IRQ,
  929. },
  930. };
  931. static struct platform_device sdhi1_device = {
  932. .name = "sh_mobile_sdhi",
  933. .num_resources = ARRAY_SIZE(sdhi1_resources),
  934. .resource = sdhi1_resources,
  935. .id = 1,
  936. .dev = {
  937. .platform_data = &sdhi1_info,
  938. },
  939. };
  940. #endif
  941. /* SDHI2 */
  942. /*
  943. * The card detect pin of the top SD/MMC slot (CN23) is active low and is
  944. * connected to GPIO SCIFB_SCK of SH7372 (GPIO 162).
  945. */
  946. static struct sh_mobile_sdhi_info sdhi2_info = {
  947. .dma_slave_tx = SHDMA_SLAVE_SDHI2_TX,
  948. .dma_slave_rx = SHDMA_SLAVE_SDHI2_RX,
  949. .tmio_flags = TMIO_MMC_WRPROTECT_DISABLE | TMIO_MMC_USE_GPIO_CD,
  950. .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
  951. MMC_CAP_NEEDS_POLL,
  952. .cd_gpio = 162,
  953. };
  954. static struct resource sdhi2_resources[] = {
  955. {
  956. .name = "SDHI2",
  957. .start = 0xe6870000,
  958. .end = 0xe68700ff,
  959. .flags = IORESOURCE_MEM,
  960. }, {
  961. .name = SH_MOBILE_SDHI_IRQ_SDCARD,
  962. .start = evt2irq(0x1220), /* SDHI2_SDHI2I1 */
  963. .flags = IORESOURCE_IRQ,
  964. }, {
  965. .name = SH_MOBILE_SDHI_IRQ_SDIO,
  966. .start = evt2irq(0x1240), /* SDHI2_SDHI2I2 */
  967. .flags = IORESOURCE_IRQ,
  968. },
  969. };
  970. static struct platform_device sdhi2_device = {
  971. .name = "sh_mobile_sdhi",
  972. .num_resources = ARRAY_SIZE(sdhi2_resources),
  973. .resource = sdhi2_resources,
  974. .id = 2,
  975. .dev = {
  976. .platform_data = &sdhi2_info,
  977. },
  978. };
  979. /* SH_MMCIF */
  980. #if IS_ENABLED(CONFIG_MMC_SH_MMCIF)
  981. static struct resource sh_mmcif_resources[] = {
  982. [0] = {
  983. .name = "MMCIF",
  984. .start = 0xE6BD0000,
  985. .end = 0xE6BD00FF,
  986. .flags = IORESOURCE_MEM,
  987. },
  988. [1] = {
  989. /* MMC ERR */
  990. .start = evt2irq(0x1ac0),
  991. .flags = IORESOURCE_IRQ,
  992. },
  993. [2] = {
  994. /* MMC NOR */
  995. .start = evt2irq(0x1ae0),
  996. .flags = IORESOURCE_IRQ,
  997. },
  998. };
  999. static struct sh_mmcif_plat_data sh_mmcif_plat = {
  1000. .sup_pclk = 0,
  1001. .caps = MMC_CAP_4_BIT_DATA |
  1002. MMC_CAP_8_BIT_DATA |
  1003. MMC_CAP_NEEDS_POLL,
  1004. .use_cd_gpio = true,
  1005. /* card detect pin for SD/MMC slot (CN7) */
  1006. .cd_gpio = 41,
  1007. .slave_id_tx = SHDMA_SLAVE_MMCIF_TX,
  1008. .slave_id_rx = SHDMA_SLAVE_MMCIF_RX,
  1009. };
  1010. static struct platform_device sh_mmcif_device = {
  1011. .name = "sh_mmcif",
  1012. .id = 0,
  1013. .dev = {
  1014. .dma_mask = NULL,
  1015. .coherent_dma_mask = 0xffffffff,
  1016. .platform_data = &sh_mmcif_plat,
  1017. },
  1018. .num_resources = ARRAY_SIZE(sh_mmcif_resources),
  1019. .resource = sh_mmcif_resources,
  1020. };
  1021. #endif
  1022. static int mackerel_camera_add(struct soc_camera_device *icd);
  1023. static void mackerel_camera_del(struct soc_camera_device *icd);
  1024. static int camera_set_capture(struct soc_camera_platform_info *info,
  1025. int enable)
  1026. {
  1027. return 0; /* camera sensor always enabled */
  1028. }
  1029. static struct soc_camera_platform_info camera_info = {
  1030. .format_name = "UYVY",
  1031. .format_depth = 16,
  1032. .format = {
  1033. .code = V4L2_MBUS_FMT_UYVY8_2X8,
  1034. .colorspace = V4L2_COLORSPACE_SMPTE170M,
  1035. .field = V4L2_FIELD_NONE,
  1036. .width = 640,
  1037. .height = 480,
  1038. },
  1039. .mbus_param = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
  1040. V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
  1041. V4L2_MBUS_DATA_ACTIVE_HIGH,
  1042. .mbus_type = V4L2_MBUS_PARALLEL,
  1043. .set_capture = camera_set_capture,
  1044. };
  1045. static struct soc_camera_link camera_link = {
  1046. .bus_id = 0,
  1047. .add_device = mackerel_camera_add,
  1048. .del_device = mackerel_camera_del,
  1049. .module_name = "soc_camera_platform",
  1050. .priv = &camera_info,
  1051. };
  1052. static struct platform_device *camera_device;
  1053. static void mackerel_camera_release(struct device *dev)
  1054. {
  1055. soc_camera_platform_release(&camera_device);
  1056. }
  1057. static int mackerel_camera_add(struct soc_camera_device *icd)
  1058. {
  1059. return soc_camera_platform_add(icd, &camera_device, &camera_link,
  1060. mackerel_camera_release, 0);
  1061. }
  1062. static void mackerel_camera_del(struct soc_camera_device *icd)
  1063. {
  1064. soc_camera_platform_del(icd, camera_device, &camera_link);
  1065. }
  1066. static struct sh_mobile_ceu_info sh_mobile_ceu_info = {
  1067. .flags = SH_CEU_FLAG_USE_8BIT_BUS,
  1068. .max_width = 8188,
  1069. .max_height = 8188,
  1070. };
  1071. static struct resource ceu_resources[] = {
  1072. [0] = {
  1073. .name = "CEU",
  1074. .start = 0xfe910000,
  1075. .end = 0xfe91009f,
  1076. .flags = IORESOURCE_MEM,
  1077. },
  1078. [1] = {
  1079. .start = intcs_evt2irq(0x880),
  1080. .flags = IORESOURCE_IRQ,
  1081. },
  1082. [2] = {
  1083. /* place holder for contiguous memory */
  1084. },
  1085. };
  1086. static struct platform_device ceu_device = {
  1087. .name = "sh_mobile_ceu",
  1088. .id = 0, /* "ceu0" clock */
  1089. .num_resources = ARRAY_SIZE(ceu_resources),
  1090. .resource = ceu_resources,
  1091. .dev = {
  1092. .platform_data = &sh_mobile_ceu_info,
  1093. .coherent_dma_mask = 0xffffffff,
  1094. },
  1095. };
  1096. static struct platform_device mackerel_camera = {
  1097. .name = "soc-camera-pdrv",
  1098. .id = 0,
  1099. .dev = {
  1100. .platform_data = &camera_link,
  1101. },
  1102. };
  1103. static struct platform_device *mackerel_devices[] __initdata = {
  1104. &nor_flash_device,
  1105. &smc911x_device,
  1106. &lcdc_device,
  1107. &gpio_backlight_device,
  1108. &usbhs0_device,
  1109. &usbhs1_device,
  1110. &leds_device,
  1111. &fsi_device,
  1112. &fsi_ak4643_device,
  1113. &fsi_hdmi_device,
  1114. &nand_flash_device,
  1115. &sdhi0_device,
  1116. #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
  1117. &sdhi1_device,
  1118. #else
  1119. &sh_mmcif_device,
  1120. #endif
  1121. &sdhi2_device,
  1122. &ceu_device,
  1123. &mackerel_camera,
  1124. &hdmi_device,
  1125. &hdmi_lcdc_device,
  1126. &meram_device,
  1127. };
  1128. /* Keypad Initialization */
  1129. #define KEYPAD_BUTTON(ev_type, ev_code, act_low) \
  1130. { \
  1131. .type = ev_type, \
  1132. .code = ev_code, \
  1133. .active_low = act_low, \
  1134. }
  1135. #define KEYPAD_BUTTON_LOW(event_code) KEYPAD_BUTTON(EV_KEY, event_code, 1)
  1136. static struct tca6416_button mackerel_gpio_keys[] = {
  1137. KEYPAD_BUTTON_LOW(KEY_HOME),
  1138. KEYPAD_BUTTON_LOW(KEY_MENU),
  1139. KEYPAD_BUTTON_LOW(KEY_BACK),
  1140. KEYPAD_BUTTON_LOW(KEY_POWER),
  1141. };
  1142. static struct tca6416_keys_platform_data mackerel_tca6416_keys_info = {
  1143. .buttons = mackerel_gpio_keys,
  1144. .nbuttons = ARRAY_SIZE(mackerel_gpio_keys),
  1145. .rep = 1,
  1146. .use_polling = 0,
  1147. .pinmask = 0x000F,
  1148. };
  1149. /* I2C */
  1150. #define IRQ7 evt2irq(0x02e0)
  1151. #define IRQ9 evt2irq(0x0320)
  1152. static struct i2c_board_info i2c0_devices[] = {
  1153. {
  1154. I2C_BOARD_INFO("ak4643", 0x13),
  1155. },
  1156. /* Keypad */
  1157. {
  1158. I2C_BOARD_INFO("tca6408-keys", 0x20),
  1159. .platform_data = &mackerel_tca6416_keys_info,
  1160. .irq = IRQ9,
  1161. },
  1162. /* Touchscreen */
  1163. {
  1164. I2C_BOARD_INFO("st1232-ts", 0x55),
  1165. .irq = IRQ7,
  1166. },
  1167. };
  1168. #define IRQ21 evt2irq(0x32a0)
  1169. static struct i2c_board_info i2c1_devices[] = {
  1170. /* Accelerometer */
  1171. {
  1172. I2C_BOARD_INFO("adxl34x", 0x53),
  1173. .irq = IRQ21,
  1174. },
  1175. };
  1176. static unsigned long pin_pulldown_conf[] = {
  1177. PIN_CONF_PACKED(PIN_CONFIG_BIAS_PULL_DOWN, 0),
  1178. };
  1179. static const struct pinctrl_map mackerel_pinctrl_map[] = {
  1180. /* ADXL34X */
  1181. PIN_MAP_MUX_GROUP_DEFAULT("1-0053", "pfc-sh7372",
  1182. "intc_irq21", "intc"),
  1183. /* CEU */
  1184. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
  1185. "ceu_data_0_7", "ceu"),
  1186. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
  1187. "ceu_clk_0", "ceu"),
  1188. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
  1189. "ceu_sync", "ceu"),
  1190. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_ceu.0", "pfc-sh7372",
  1191. "ceu_field", "ceu"),
  1192. /* FLCTL */
  1193. PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
  1194. "flctl_data", "flctl"),
  1195. PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
  1196. "flctl_ce0", "flctl"),
  1197. PIN_MAP_MUX_GROUP_DEFAULT("sh_flctl.0", "pfc-sh7372",
  1198. "flctl_ctrl", "flctl"),
  1199. /* FSIA (AK4643) */
  1200. PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
  1201. "fsia_sclk_in", "fsia"),
  1202. PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
  1203. "fsia_data_in", "fsia"),
  1204. PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.0", "pfc-sh7372",
  1205. "fsia_data_out", "fsia"),
  1206. /* FSIB (HDMI) */
  1207. PIN_MAP_MUX_GROUP_DEFAULT("asoc-simple-card.1", "pfc-sh7372",
  1208. "fsib_mclk_in", "fsib"),
  1209. /* HDMI */
  1210. PIN_MAP_MUX_GROUP_DEFAULT("sh-mobile-hdmi", "pfc-sh7372",
  1211. "hdmi", "hdmi"),
  1212. /* LCDC */
  1213. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-sh7372",
  1214. "lcd_data24", "lcd"),
  1215. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_lcdc_fb.0", "pfc-sh7372",
  1216. "lcd_sync", "lcd"),
  1217. /* SCIFA0 */
  1218. PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.0", "pfc-sh7372",
  1219. "scifa0_data", "scifa0"),
  1220. /* SCIFA2 (GT-720F GPS module) */
  1221. PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.2", "pfc-sh7372",
  1222. "scifa2_data", "scifa2"),
  1223. /* SDHI0 */
  1224. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
  1225. "sdhi0_data4", "sdhi0"),
  1226. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
  1227. "sdhi0_ctrl", "sdhi0"),
  1228. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
  1229. "sdhi0_wp", "sdhi0"),
  1230. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-sh7372",
  1231. "intc_irq26_1", "intc"),
  1232. /* SDHI1 */
  1233. #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
  1234. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-sh7372",
  1235. "sdhi1_data4", "sdhi1"),
  1236. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-sh7372",
  1237. "sdhi1_ctrl", "sdhi1"),
  1238. #else
  1239. /* MMCIF */
  1240. PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh7372",
  1241. "mmc0_data8_0", "mmc0"),
  1242. PIN_MAP_MUX_GROUP_DEFAULT("sh_mmcif.0", "pfc-sh7372",
  1243. "mmc0_ctrl_0", "mmc0"),
  1244. #endif
  1245. /* SDHI2 */
  1246. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-sh7372",
  1247. "sdhi2_data4", "sdhi2"),
  1248. PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-sh7372",
  1249. "sdhi2_ctrl", "sdhi2"),
  1250. /* SMSC911X */
  1251. PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-sh7372",
  1252. "bsc_cs5a", "bsc"),
  1253. PIN_MAP_MUX_GROUP_DEFAULT("smsc911x", "pfc-sh7372",
  1254. "intc_irq6_0", "intc"),
  1255. /* ST1232 */
  1256. PIN_MAP_MUX_GROUP_DEFAULT("0-0055", "pfc-sh7372",
  1257. "intc_irq7_0", "intc"),
  1258. /* TCA6416 */
  1259. PIN_MAP_MUX_GROUP_DEFAULT("0-0020", "pfc-sh7372",
  1260. "intc_irq9_0", "intc"),
  1261. /* USBHS0 */
  1262. PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.0", "pfc-sh7372",
  1263. "usb0_vbus", "usb0"),
  1264. PIN_MAP_CONFIGS_GROUP_DEFAULT("renesas_usbhs.0", "pfc-sh7372",
  1265. "usb0_vbus", pin_pulldown_conf),
  1266. /* USBHS1 */
  1267. PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
  1268. "usb1_vbus", "usb1"),
  1269. PIN_MAP_CONFIGS_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
  1270. "usb1_vbus", pin_pulldown_conf),
  1271. PIN_MAP_MUX_GROUP_DEFAULT("renesas_usbhs.1", "pfc-sh7372",
  1272. "usb1_otg_id_0", "usb1"),
  1273. };
  1274. #define GPIO_PORT9CR IOMEM(0xE6051009)
  1275. #define GPIO_PORT10CR IOMEM(0xE605100A)
  1276. #define SRCR4 IOMEM(0xe61580bc)
  1277. #define USCCR1 IOMEM(0xE6058144)
  1278. static void __init mackerel_init(void)
  1279. {
  1280. struct pm_domain_device domain_devices[] = {
  1281. { "A4LC", &lcdc_device, },
  1282. { "A4LC", &hdmi_lcdc_device, },
  1283. { "A4LC", &meram_device, },
  1284. { "A4MP", &fsi_device, },
  1285. { "A3SP", &usbhs0_device, },
  1286. { "A3SP", &usbhs1_device, },
  1287. { "A3SP", &nand_flash_device, },
  1288. { "A3SP", &sdhi0_device, },
  1289. #if !IS_ENABLED(CONFIG_MMC_SH_MMCIF)
  1290. { "A3SP", &sdhi1_device, },
  1291. #else
  1292. { "A3SP", &sh_mmcif_device, },
  1293. #endif
  1294. { "A3SP", &sdhi2_device, },
  1295. { "A4R", &ceu_device, },
  1296. };
  1297. u32 srcr4;
  1298. struct clk *clk;
  1299. regulator_register_always_on(0, "fixed-1.8V", fixed1v8_power_consumers,
  1300. ARRAY_SIZE(fixed1v8_power_consumers), 1800000);
  1301. regulator_register_always_on(1, "fixed-3.3V", fixed3v3_power_consumers,
  1302. ARRAY_SIZE(fixed3v3_power_consumers), 3300000);
  1303. regulator_register_fixed(2, dummy_supplies, ARRAY_SIZE(dummy_supplies));
  1304. /* External clock source */
  1305. clk_set_rate(&sh7372_dv_clki_clk, 27000000);
  1306. pinctrl_register_mappings(mackerel_pinctrl_map,
  1307. ARRAY_SIZE(mackerel_pinctrl_map));
  1308. sh7372_pinmux_init();
  1309. gpio_request_one(151, GPIOF_OUT_INIT_HIGH, NULL); /* LCDDON */
  1310. /* FSI2 port A (ak4643) */
  1311. gpio_request_one(161, GPIOF_OUT_INIT_LOW, NULL); /* slave */
  1312. gpio_request(9, NULL);
  1313. gpio_request(10, NULL);
  1314. gpio_direction_none(GPIO_PORT9CR); /* FSIAOBT needs no direction */
  1315. gpio_direction_none(GPIO_PORT10CR); /* FSIAOLR needs no direction */
  1316. intc_set_priority(IRQ_FSI, 3); /* irq priority FSI(3) > SMSC911X(2) */
  1317. /* FSI2 port B (HDMI) */
  1318. __raw_writew(__raw_readw(USCCR1) & ~(1 << 6), USCCR1); /* use SPDIF */
  1319. /* set SPU2 clock to 119.6 MHz */
  1320. clk = clk_get(NULL, "spu_clk");
  1321. if (!IS_ERR(clk)) {
  1322. clk_set_rate(clk, clk_round_rate(clk, 119600000));
  1323. clk_put(clk);
  1324. }
  1325. /* Keypad */
  1326. irq_set_irq_type(IRQ9, IRQ_TYPE_LEVEL_HIGH);
  1327. /* Touchscreen */
  1328. irq_set_irq_type(IRQ7, IRQ_TYPE_LEVEL_LOW);
  1329. /* Accelerometer */
  1330. irq_set_irq_type(IRQ21, IRQ_TYPE_LEVEL_HIGH);
  1331. /* Reset HDMI, must be held at least one EXTALR (32768Hz) period */
  1332. srcr4 = __raw_readl(SRCR4);
  1333. __raw_writel(srcr4 | (1 << 13), SRCR4);
  1334. udelay(50);
  1335. __raw_writel(srcr4 & ~(1 << 13), SRCR4);
  1336. i2c_register_board_info(0, i2c0_devices,
  1337. ARRAY_SIZE(i2c0_devices));
  1338. i2c_register_board_info(1, i2c1_devices,
  1339. ARRAY_SIZE(i2c1_devices));
  1340. sh7372_add_standard_devices();
  1341. platform_add_devices(mackerel_devices, ARRAY_SIZE(mackerel_devices));
  1342. rmobile_add_devices_to_domains(domain_devices,
  1343. ARRAY_SIZE(domain_devices));
  1344. hdmi_init_pm_clock();
  1345. sh7372_pm_init();
  1346. pm_clk_add(&fsi_device.dev, "spu2");
  1347. pm_clk_add(&hdmi_lcdc_device.dev, "hdmi");
  1348. }
  1349. static const char *mackerel_boards_compat_dt[] __initdata = {
  1350. "renesas,mackerel",
  1351. NULL,
  1352. };
  1353. DT_MACHINE_START(MACKEREL_DT, "mackerel")
  1354. .map_io = sh7372_map_io,
  1355. .init_early = sh7372_add_early_devices,
  1356. .init_irq = sh7372_init_irq,
  1357. .handle_irq = shmobile_handle_irq_intc,
  1358. .init_machine = mackerel_init,
  1359. .init_late = sh7372_pm_init_late,
  1360. .init_time = sh7372_earlytimer_init,
  1361. .dt_compat = mackerel_boards_compat_dt,
  1362. MACHINE_END