board-mackerel.c 37 KB

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