laguna.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  1. /*
  2. * Gateworks Corporation Laguna Platform
  3. *
  4. * Copyright 2000 Deep Blue Solutions Ltd
  5. * Copyright 2008 ARM Limited
  6. * Copyright 2008 Cavium Networks
  7. * Scott Shu
  8. * Copyright 2010 MontaVista Software, LLC.
  9. * Anton Vorontsov <avorontsov@mvista.com>
  10. * Copyright 2011 Gateworks Corporation
  11. * Chris Lang <clang@gateworks.com>
  12. * Copyright 2012-2013 Gateworks Corporation
  13. * Tim Harvey <tharvey@gateworks.com>
  14. *
  15. * This file is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License, Version 2, as
  17. * published by the Free Software Foundation.
  18. */
  19. #include <linux/init.h>
  20. #include <linux/kernel.h>
  21. #include <linux/compiler.h>
  22. #include <linux/io.h>
  23. #include <linux/gpio.h>
  24. #include <linux/dma-mapping.h>
  25. #include <linux/serial_core.h>
  26. #include <linux/serial_8250.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/mtd/mtd.h>
  29. #include <linux/mtd/physmap.h>
  30. #include <linux/mtd/partitions.h>
  31. #include <linux/leds.h>
  32. #include <linux/i2c.h>
  33. #include <linux/platform_data/at24.h>
  34. #include <linux/platform_data/pca953x.h>
  35. #include <linux/spi/spi.h>
  36. #include <linux/spi/flash.h>
  37. #include <linux/if_ether.h>
  38. #include <linux/pps-gpio.h>
  39. #include <linux/usb/ehci_pdriver.h>
  40. #include <linux/usb/ohci_pdriver.h>
  41. #include <linux/clk-provider.h>
  42. #include <linux/clkdev.h>
  43. #include <linux/platform_data/cns3xxx.h>
  44. #include <asm/setup.h>
  45. #include <asm/mach-types.h>
  46. #include <asm/mach/arch.h>
  47. #include <asm/mach/map.h>
  48. #include <asm/mach/time.h>
  49. #include <mach/gpio.h>
  50. #include "core.h"
  51. #include "devices.h"
  52. #include "cns3xxx.h"
  53. #include "pm.h"
  54. #define ARRAY_AND_SIZE(x) (x), ARRAY_SIZE(x)
  55. // Config 1 Bitmap
  56. #define ETH0_LOAD BIT(0)
  57. #define ETH1_LOAD BIT(1)
  58. #define ETH2_LOAD BIT(2)
  59. #define SATA0_LOAD BIT(3)
  60. #define SATA1_LOAD BIT(4)
  61. #define PCM_LOAD BIT(5)
  62. #define I2S_LOAD BIT(6)
  63. #define SPI0_LOAD BIT(7)
  64. #define SPI1_LOAD BIT(8)
  65. #define PCIE0_LOAD BIT(9)
  66. #define PCIE1_LOAD BIT(10)
  67. #define USB0_LOAD BIT(11)
  68. #define USB1_LOAD BIT(12)
  69. #define USB1_ROUTE BIT(13)
  70. #define SD_LOAD BIT(14)
  71. #define UART0_LOAD BIT(15)
  72. #define UART1_LOAD BIT(16)
  73. #define UART2_LOAD BIT(17)
  74. #define MPCI0_LOAD BIT(18)
  75. #define MPCI1_LOAD BIT(19)
  76. #define MPCI2_LOAD BIT(20)
  77. #define MPCI3_LOAD BIT(21)
  78. #define FP_BUT_LOAD BIT(22)
  79. #define FP_BUT_HEADER_LOAD BIT(23)
  80. #define FP_LED_LOAD BIT(24)
  81. #define FP_LED_HEADER_LOAD BIT(25)
  82. #define FP_TAMPER_LOAD BIT(26)
  83. #define HEADER_33V_LOAD BIT(27)
  84. #define SATA_POWER_LOAD BIT(28)
  85. #define FP_POWER_LOAD BIT(29)
  86. #define GPIO_HEADER_LOAD BIT(30)
  87. #define GSP_BAT_LOAD BIT(31)
  88. // Config 2 Bitmap
  89. #define FAN_LOAD BIT(0)
  90. #define SPI_FLASH_LOAD BIT(1)
  91. #define NOR_FLASH_LOAD BIT(2)
  92. #define GPS_LOAD BIT(3)
  93. #define SUPPLY_5V_LOAD BIT(6)
  94. #define SUPPLY_33V_LOAD BIT(7)
  95. struct laguna_board_info {
  96. char model[16];
  97. u32 config_bitmap;
  98. u32 config2_bitmap;
  99. u8 nor_flash_size;
  100. u8 spi_flash_size;
  101. };
  102. static struct laguna_board_info laguna_info __initdata;
  103. /*
  104. * NOR Flash
  105. */
  106. static struct mtd_partition laguna_nor_partitions[] = {
  107. {
  108. .name = "uboot",
  109. .size = SZ_256K,
  110. .offset = 0,
  111. .mask_flags = MTD_WRITEABLE,
  112. }, {
  113. .name = "params",
  114. .size = SZ_128K,
  115. .offset = SZ_256K,
  116. }, {
  117. .name = "kernel",
  118. .size = SZ_2M,
  119. .offset = SZ_256K + SZ_128K,
  120. }, {
  121. .name = "rootfs",
  122. .size = SZ_16M - SZ_256K - SZ_128K - SZ_2M,
  123. .offset = SZ_256K + SZ_128K + SZ_2M,
  124. },
  125. };
  126. static struct physmap_flash_data laguna_nor_pdata = {
  127. .width = 2,
  128. .parts = laguna_nor_partitions,
  129. .nr_parts = ARRAY_SIZE(laguna_nor_partitions),
  130. };
  131. static struct resource laguna_nor_res = {
  132. .start = CNS3XXX_FLASH_BASE,
  133. .end = CNS3XXX_FLASH_BASE + SZ_128M - 1,
  134. .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
  135. };
  136. static struct platform_device laguna_nor_pdev = {
  137. .name = "physmap-flash",
  138. .id = 0,
  139. .resource = &laguna_nor_res,
  140. .num_resources = 1,
  141. .dev = {
  142. .platform_data = &laguna_nor_pdata,
  143. },
  144. };
  145. /*
  146. * SPI
  147. */
  148. static struct mtd_partition laguna_spi_partitions[] = {
  149. {
  150. .name = "uboot",
  151. .size = SZ_256K,
  152. .offset = 0,
  153. .mask_flags = MTD_WRITEABLE,
  154. }, {
  155. .name = "params",
  156. .size = SZ_256K,
  157. .offset = SZ_256K,
  158. }, {
  159. .name = "kernel",
  160. .size = SZ_1M + SZ_512K,
  161. .offset = SZ_512K,
  162. }, {
  163. .name = "rootfs",
  164. .size = SZ_16M - SZ_2M,
  165. .offset = SZ_2M,
  166. },
  167. };
  168. static struct flash_platform_data laguna_spi_pdata = {
  169. .parts = laguna_spi_partitions,
  170. .nr_parts = ARRAY_SIZE(laguna_spi_partitions),
  171. };
  172. static struct spi_board_info __initdata laguna_spi_devices[] = {
  173. {
  174. .modalias = "m25p80",
  175. .platform_data = &laguna_spi_pdata,
  176. .max_speed_hz = 50000000,
  177. .bus_num = 1,
  178. .chip_select = 0,
  179. },
  180. };
  181. static struct resource laguna_spi_resource = {
  182. .start = CNS3XXX_SSP_BASE + 0x40,
  183. .end = CNS3XXX_SSP_BASE + 0x6f,
  184. .flags = IORESOURCE_MEM,
  185. };
  186. static struct platform_device laguna_spi_controller = {
  187. .name = "cns3xxx_spi",
  188. .resource = &laguna_spi_resource,
  189. .num_resources = 1,
  190. };
  191. /*
  192. * LED's
  193. */
  194. static struct gpio_led laguna_gpio_leds[] = {
  195. {
  196. .name = "user1", /* Green Led */
  197. .gpio = 115,
  198. .active_low = 1,
  199. },{
  200. .name = "user2", /* Red Led */
  201. .gpio = 114,
  202. .active_low = 1,
  203. },{
  204. .name = "pwr1", /* Green Led */
  205. .gpio = 116,
  206. .active_low = 1,
  207. },{
  208. .name = "pwr2", /* Yellow Led */
  209. .gpio = 117,
  210. .active_low = 1,
  211. },{
  212. .name = "txd1", /* Green Led */
  213. .gpio = 118,
  214. .active_low = 1,
  215. },{
  216. .name = "txd2", /* Yellow Led */
  217. .gpio = 119,
  218. .active_low = 1,
  219. },{
  220. .name = "rxd1", /* Green Led */
  221. .gpio = 120,
  222. .active_low = 1,
  223. },{
  224. .name = "rxd2", /* Yellow Led */
  225. .gpio = 121,
  226. .active_low = 1,
  227. },{
  228. .name = "ser1", /* Green Led */
  229. .gpio = 122,
  230. .active_low = 1,
  231. },{
  232. .name = "ser2", /* Yellow Led */
  233. .gpio = 123,
  234. .active_low = 1,
  235. },{
  236. .name = "enet1", /* Green Led */
  237. .gpio = 124,
  238. .active_low = 1,
  239. },{
  240. .name = "enet2", /* Yellow Led */
  241. .gpio = 125,
  242. .active_low = 1,
  243. },{
  244. .name = "sig1_1", /* Green Led */
  245. .gpio = 126,
  246. .active_low = 1,
  247. },{
  248. .name = "sig1_2", /* Yellow Led */
  249. .gpio = 127,
  250. .active_low = 1,
  251. },{
  252. .name = "sig2_1", /* Green Led */
  253. .gpio = 128,
  254. .active_low = 1,
  255. },{
  256. .name = "sig2_2", /* Yellow Led */
  257. .gpio = 129,
  258. .active_low = 1,
  259. },{
  260. .name = "sig3_1", /* Green Led */
  261. .gpio = 130,
  262. .active_low = 1,
  263. },{
  264. .name = "sig3_2", /* Yellow Led */
  265. .gpio = 131,
  266. .active_low = 1,
  267. },{
  268. .name = "net1", /*Green Led */
  269. .gpio = 109,
  270. .active_low = 1,
  271. },{
  272. .name = "net2", /* Red Led */
  273. .gpio = 110,
  274. .active_low = 1,
  275. },{
  276. .name = "mod1", /* Green Led */
  277. .gpio = 111,
  278. .active_low = 1,
  279. },{
  280. .name = "mod2", /* Red Led */
  281. .gpio = 112,
  282. .active_low = 1,
  283. },
  284. };
  285. static struct gpio_led_platform_data laguna_gpio_leds_data = {
  286. .num_leds = 22,
  287. .leds = laguna_gpio_leds,
  288. };
  289. static struct platform_device laguna_gpio_leds_device = {
  290. .name = "leds-gpio",
  291. .id = -1,
  292. .dev.platform_data = &laguna_gpio_leds_data,
  293. };
  294. /*
  295. * Ethernet
  296. */
  297. static struct cns3xxx_plat_info laguna_net_data = {
  298. .ports = 0,
  299. .phy = {
  300. 0,
  301. 1,
  302. 2,
  303. },
  304. };
  305. static struct resource laguna_net_resource[] = {
  306. {
  307. .name = "eth0_mem",
  308. .start = CNS3XXX_SWITCH_BASE,
  309. .end = CNS3XXX_SWITCH_BASE + SZ_4K - 1,
  310. .flags = IORESOURCE_MEM
  311. }, {
  312. .name = "eth_rx",
  313. .start = IRQ_CNS3XXX_SW_R0RXC,
  314. .end = IRQ_CNS3XXX_SW_R0RXC,
  315. .flags = IORESOURCE_IRQ
  316. }, {
  317. .name = "eth_stat",
  318. .start = IRQ_CNS3XXX_SW_STATUS,
  319. .end = IRQ_CNS3XXX_SW_STATUS,
  320. .flags = IORESOURCE_IRQ
  321. }
  322. };
  323. static u64 laguna_net_dmamask = DMA_BIT_MASK(32);
  324. static struct platform_device laguna_net_device = {
  325. .name = "cns3xxx_eth",
  326. .id = 0,
  327. .resource = laguna_net_resource,
  328. .num_resources = ARRAY_SIZE(laguna_net_resource),
  329. .dev = {
  330. .dma_mask = &laguna_net_dmamask,
  331. .coherent_dma_mask = DMA_BIT_MASK(32),
  332. .platform_data = &laguna_net_data,
  333. }
  334. };
  335. /*
  336. * UART
  337. */
  338. static void __init laguna_early_serial_setup(void)
  339. {
  340. #ifdef CONFIG_SERIAL_8250_CONSOLE
  341. static struct uart_port laguna_serial_port = {
  342. .membase = (void __iomem *)CNS3XXX_UART0_BASE_VIRT,
  343. .mapbase = CNS3XXX_UART0_BASE,
  344. .irq = IRQ_CNS3XXX_UART0,
  345. .iotype = UPIO_MEM,
  346. .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
  347. .regshift = 2,
  348. .uartclk = 24000000,
  349. .line = 0,
  350. .type = PORT_16550A,
  351. .fifosize = 16,
  352. };
  353. early_serial_setup(&laguna_serial_port);
  354. #endif
  355. }
  356. static struct resource laguna_uart_resources[] = {
  357. {
  358. .start = CNS3XXX_UART0_BASE,
  359. .end = CNS3XXX_UART0_BASE + SZ_4K - 1,
  360. .flags = IORESOURCE_MEM
  361. },{
  362. .start = CNS3XXX_UART2_BASE,
  363. .end = CNS3XXX_UART2_BASE + SZ_4K - 1,
  364. .flags = IORESOURCE_MEM
  365. },{
  366. .start = CNS3XXX_UART2_BASE,
  367. .end = CNS3XXX_UART2_BASE + SZ_4K - 1,
  368. .flags = IORESOURCE_MEM
  369. },
  370. };
  371. static struct plat_serial8250_port laguna_uart_data[] = {
  372. {
  373. .mapbase = (CNS3XXX_UART0_BASE),
  374. .irq = IRQ_CNS3XXX_UART0,
  375. .iotype = UPIO_MEM,
  376. .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE | UPF_NO_TXEN_TEST | UPF_IOREMAP,
  377. .regshift = 2,
  378. .uartclk = 24000000,
  379. .type = PORT_16550A,
  380. },{
  381. .mapbase = (CNS3XXX_UART1_BASE),
  382. .irq = IRQ_CNS3XXX_UART1,
  383. .iotype = UPIO_MEM,
  384. .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE | UPF_NO_TXEN_TEST | UPF_IOREMAP,
  385. .regshift = 2,
  386. .uartclk = 24000000,
  387. .type = PORT_16550A,
  388. },{
  389. .mapbase = (CNS3XXX_UART2_BASE),
  390. .irq = IRQ_CNS3XXX_UART2,
  391. .iotype = UPIO_MEM,
  392. .flags = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE | UPF_NO_TXEN_TEST | UPF_IOREMAP,
  393. .regshift = 2,
  394. .uartclk = 24000000,
  395. .type = PORT_16550A,
  396. },
  397. { },
  398. };
  399. static struct platform_device laguna_uart = {
  400. .name = "serial8250",
  401. .id = PLAT8250_DEV_PLATFORM,
  402. .dev.platform_data = laguna_uart_data,
  403. .num_resources = 3,
  404. .resource = laguna_uart_resources
  405. };
  406. /*
  407. * USB
  408. */
  409. static struct resource cns3xxx_usb_ehci_resources[] = {
  410. [0] = {
  411. .start = CNS3XXX_USB_BASE,
  412. .end = CNS3XXX_USB_BASE + SZ_16M - 1,
  413. .flags = IORESOURCE_MEM,
  414. },
  415. [1] = {
  416. .start = IRQ_CNS3XXX_USB_EHCI,
  417. .flags = IORESOURCE_IRQ,
  418. },
  419. };
  420. static u64 cns3xxx_usb_ehci_dma_mask = DMA_BIT_MASK(32);
  421. static int csn3xxx_usb_power_on(struct platform_device *pdev)
  422. {
  423. /*
  424. * EHCI and OHCI share the same clock and power,
  425. * resetting twice would cause the 1st controller been reset.
  426. * Therefore only do power up at the first up device, and
  427. * power down at the last down device.
  428. *
  429. * Set USB AHB INCR length to 16
  430. */
  431. if (atomic_inc_return(&usb_pwr_ref) == 1) {
  432. cns3xxx_pwr_power_up(1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB);
  433. cns3xxx_pwr_clk_en(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST);
  434. cns3xxx_pwr_soft_rst(1 << PM_SOFT_RST_REG_OFFST_USB_HOST);
  435. __raw_writel((__raw_readl(MISC_CHIP_CONFIG_REG) | (0X2 << 24)),
  436. MISC_CHIP_CONFIG_REG);
  437. }
  438. return 0;
  439. }
  440. static void csn3xxx_usb_power_off(struct platform_device *pdev)
  441. {
  442. /*
  443. * EHCI and OHCI share the same clock and power,
  444. * resetting twice would cause the 1st controller been reset.
  445. * Therefore only do power up at the first up device, and
  446. * power down at the last down device.
  447. */
  448. if (atomic_dec_return(&usb_pwr_ref) == 0)
  449. cns3xxx_pwr_clk_dis(1 << PM_CLK_GATE_REG_OFFSET_USB_HOST);
  450. }
  451. static struct usb_ehci_pdata cns3xxx_usb_ehci_pdata = {
  452. .power_on = csn3xxx_usb_power_on,
  453. .power_off = csn3xxx_usb_power_off,
  454. };
  455. static struct platform_device cns3xxx_usb_ehci_device = {
  456. .name = "ehci-platform",
  457. .num_resources = ARRAY_SIZE(cns3xxx_usb_ehci_resources),
  458. .resource = cns3xxx_usb_ehci_resources,
  459. .dev = {
  460. .dma_mask = &cns3xxx_usb_ehci_dma_mask,
  461. .coherent_dma_mask = DMA_BIT_MASK(32),
  462. .platform_data = &cns3xxx_usb_ehci_pdata,
  463. },
  464. };
  465. static struct resource cns3xxx_usb_ohci_resources[] = {
  466. [0] = {
  467. .start = CNS3XXX_USB_OHCI_BASE,
  468. .end = CNS3XXX_USB_OHCI_BASE + SZ_16M - 1,
  469. .flags = IORESOURCE_MEM,
  470. },
  471. [1] = {
  472. .start = IRQ_CNS3XXX_USB_OHCI,
  473. .flags = IORESOURCE_IRQ,
  474. },
  475. };
  476. static u64 cns3xxx_usb_ohci_dma_mask = DMA_BIT_MASK(32);
  477. static struct usb_ohci_pdata cns3xxx_usb_ohci_pdata = {
  478. .num_ports = 1,
  479. .power_on = csn3xxx_usb_power_on,
  480. .power_off = csn3xxx_usb_power_off,
  481. };
  482. static struct platform_device cns3xxx_usb_ohci_device = {
  483. .name = "ohci-platform",
  484. .num_resources = ARRAY_SIZE(cns3xxx_usb_ohci_resources),
  485. .resource = cns3xxx_usb_ohci_resources,
  486. .dev = {
  487. .dma_mask = &cns3xxx_usb_ohci_dma_mask,
  488. .coherent_dma_mask = DMA_BIT_MASK(32),
  489. .platform_data = &cns3xxx_usb_ohci_pdata,
  490. },
  491. };
  492. static struct resource cns3xxx_usb_otg_resources[] = {
  493. [0] = {
  494. .start = CNS3XXX_USBOTG_BASE,
  495. .end = CNS3XXX_USBOTG_BASE + SZ_16M - 1,
  496. .flags = IORESOURCE_MEM,
  497. },
  498. [1] = {
  499. .start = IRQ_CNS3XXX_USB_OTG,
  500. .flags = IORESOURCE_IRQ,
  501. },
  502. };
  503. static u64 cns3xxx_usb_otg_dma_mask = DMA_BIT_MASK(32);
  504. static struct platform_device cns3xxx_usb_otg_device = {
  505. .name = "dwc2",
  506. .num_resources = ARRAY_SIZE(cns3xxx_usb_otg_resources),
  507. .resource = cns3xxx_usb_otg_resources,
  508. .dev = {
  509. .dma_mask = &cns3xxx_usb_otg_dma_mask,
  510. .coherent_dma_mask = DMA_BIT_MASK(32),
  511. },
  512. };
  513. /*
  514. * I2C
  515. */
  516. static struct resource laguna_i2c_resource[] = {
  517. {
  518. .start = CNS3XXX_SSP_BASE + 0x20,
  519. .end = CNS3XXX_SSP_BASE + 0x3f,
  520. .flags = IORESOURCE_MEM,
  521. },{
  522. .start = IRQ_CNS3XXX_I2C,
  523. .flags = IORESOURCE_IRQ,
  524. },
  525. };
  526. static struct platform_device laguna_i2c_controller = {
  527. .name = "cns3xxx-i2c",
  528. .num_resources = 2,
  529. .resource = laguna_i2c_resource,
  530. };
  531. static struct memory_accessor *at24_mem_acc;
  532. static void at24_setup(struct memory_accessor *mem_acc, void *context)
  533. {
  534. char buf[16];
  535. at24_mem_acc = mem_acc;
  536. /* Read MAC addresses */
  537. if (at24_mem_acc->read(at24_mem_acc, buf, 0x100, 6) == 6)
  538. memcpy(&laguna_net_data.hwaddr[0], buf, ETH_ALEN);
  539. if (at24_mem_acc->read(at24_mem_acc, buf, 0x106, 6) == 6)
  540. memcpy(&laguna_net_data.hwaddr[1], buf, ETH_ALEN);
  541. if (at24_mem_acc->read(at24_mem_acc, buf, 0x10C, 6) == 6)
  542. memcpy(&laguna_net_data.hwaddr[2], buf, ETH_ALEN);
  543. if (at24_mem_acc->read(at24_mem_acc, buf, 0x112, 6) == 6)
  544. memcpy(&laguna_net_data.hwaddr[3], buf, ETH_ALEN);
  545. /* Read out Model Information */
  546. if (at24_mem_acc->read(at24_mem_acc, buf, 0x130, 16) == 16)
  547. memcpy(&laguna_info.model, buf, 16);
  548. if (at24_mem_acc->read(at24_mem_acc, buf, 0x140, 1) == 1)
  549. memcpy(&laguna_info.nor_flash_size, buf, 1);
  550. if (at24_mem_acc->read(at24_mem_acc, buf, 0x141, 1) == 1)
  551. memcpy(&laguna_info.spi_flash_size, buf, 1);
  552. if (at24_mem_acc->read(at24_mem_acc, buf, 0x142, 4) == 4)
  553. memcpy(&laguna_info.config_bitmap, buf, 4);
  554. if (at24_mem_acc->read(at24_mem_acc, buf, 0x146, 4) == 4)
  555. memcpy(&laguna_info.config2_bitmap, buf, 4);
  556. };
  557. static struct at24_platform_data laguna_eeprom_info = {
  558. .byte_len = 1024,
  559. .page_size = 16,
  560. .flags = AT24_FLAG_READONLY,
  561. .setup = at24_setup,
  562. };
  563. static struct pca953x_platform_data laguna_pca_data = {
  564. .gpio_base = 100,
  565. .irq_base = -1,
  566. };
  567. static struct pca953x_platform_data laguna_pca2_data = {
  568. .gpio_base = 116,
  569. .irq_base = -1,
  570. };
  571. static struct i2c_board_info __initdata laguna_i2c_devices[] = {
  572. {
  573. I2C_BOARD_INFO("pca9555", 0x23),
  574. .platform_data = &laguna_pca_data,
  575. },{
  576. I2C_BOARD_INFO("pca9555", 0x27),
  577. .platform_data = &laguna_pca2_data,
  578. },{
  579. I2C_BOARD_INFO("gsp", 0x29),
  580. },{
  581. I2C_BOARD_INFO ("24c08",0x50),
  582. .platform_data = &laguna_eeprom_info,
  583. },{
  584. I2C_BOARD_INFO("ds1672", 0x68),
  585. },
  586. };
  587. /*
  588. * Watchdog
  589. */
  590. static struct resource laguna_watchdog_resources[] = {
  591. [0] = {
  592. .start = CNS3XXX_TC11MP_TWD_BASE + 0x100, // CPU0 watchdog
  593. .end = CNS3XXX_TC11MP_TWD_BASE + SZ_4K - 1,
  594. .flags = IORESOURCE_MEM,
  595. },
  596. };
  597. static struct platform_device laguna_watchdog = {
  598. .name = "mpcore_wdt",
  599. .id = -1,
  600. .num_resources = ARRAY_SIZE(laguna_watchdog_resources),
  601. .resource = laguna_watchdog_resources,
  602. };
  603. /*
  604. * GPS PPS
  605. */
  606. static struct pps_gpio_platform_data laguna_pps_data = {
  607. .gpio_pin = 0,
  608. .gpio_label = "GPS_PPS",
  609. .assert_falling_edge = 0,
  610. .capture_clear = 0,
  611. };
  612. static struct platform_device laguna_pps_device = {
  613. .name = "pps-gpio",
  614. .id = -1,
  615. .dev.platform_data = &laguna_pps_data,
  616. };
  617. /*
  618. * GPIO
  619. */
  620. static struct gpio laguna_gpio_gw2391[] = {
  621. { 0, GPIOF_IN , "*GPS_PPS" },
  622. { 1, GPIOF_IN , "*GSC_IRQ#" },
  623. { 2, GPIOF_IN , "*USB_FAULT#" },
  624. { 5, GPIOF_OUT_INIT_LOW , "*USB0_PCI_SEL" },
  625. { 6, GPIOF_OUT_INIT_HIGH, "*USB_VBUS_EN" },
  626. { 7, GPIOF_OUT_INIT_LOW , "*USB1_PCI_SEL" },
  627. { 8, GPIOF_OUT_INIT_HIGH, "*PERST#" },
  628. { 9, GPIOF_OUT_INIT_LOW , "*FP_SER_EN#" },
  629. { 100, GPIOF_IN , "*USER_PB#" },
  630. { 103, GPIOF_OUT_INIT_HIGH, "*V5_EN" },
  631. { 108, GPIOF_IN , "DIO0" },
  632. { 109, GPIOF_IN , "DIO1" },
  633. { 110, GPIOF_IN , "DIO2" },
  634. { 111, GPIOF_IN , "DIO3" },
  635. { 112, GPIOF_IN , "DIO4" },
  636. };
  637. static struct gpio laguna_gpio_gw2388[] = {
  638. { 0, GPIOF_IN , "*GPS_PPS" },
  639. { 1, GPIOF_IN , "*GSC_IRQ#" },
  640. { 3, GPIOF_IN , "*USB_FAULT#" },
  641. { 6, GPIOF_OUT_INIT_HIGH, "*USB_VBUS_EN" },
  642. { 7, GPIOF_OUT_INIT_LOW , "*GSM_SEL0" },
  643. { 8, GPIOF_OUT_INIT_LOW , "*GSM_SEL1" },
  644. { 9, GPIOF_OUT_INIT_LOW , "*FP_SER_EN" },
  645. { 100, GPIOF_OUT_INIT_HIGH, "*USER_PB#" },
  646. { 108, GPIOF_IN , "DIO0" },
  647. { 109, GPIOF_IN , "DIO1" },
  648. { 110, GPIOF_IN , "DIO2" },
  649. { 111, GPIOF_IN , "DIO3" },
  650. { 112, GPIOF_IN , "DIO4" },
  651. };
  652. static struct gpio laguna_gpio_gw2387[] = {
  653. { 0, GPIOF_IN , "*GPS_PPS" },
  654. { 1, GPIOF_IN , "*GSC_IRQ#" },
  655. { 2, GPIOF_IN , "*USB_FAULT#" },
  656. { 5, GPIOF_OUT_INIT_LOW , "*USB_PCI_SEL" },
  657. { 6, GPIOF_OUT_INIT_HIGH, "*USB_VBUS_EN" },
  658. { 7, GPIOF_OUT_INIT_LOW , "*GSM_SEL0" },
  659. { 8, GPIOF_OUT_INIT_LOW , "*GSM_SEL1" },
  660. { 9, GPIOF_OUT_INIT_LOW , "*FP_SER_EN" },
  661. { 100, GPIOF_IN , "*USER_PB#" },
  662. { 103, GPIOF_OUT_INIT_HIGH, "*V5_EN" },
  663. { 108, GPIOF_IN , "DIO0" },
  664. { 109, GPIOF_IN , "DIO1" },
  665. { 110, GPIOF_IN , "DIO2" },
  666. { 111, GPIOF_IN , "DIO3" },
  667. { 112, GPIOF_IN , "DIO4" },
  668. { 113, GPIOF_IN , "DIO5" },
  669. };
  670. static struct gpio laguna_gpio_gw2385[] = {
  671. { 0, GPIOF_IN , "*GSC_IRQ#" },
  672. { 1, GPIOF_OUT_INIT_HIGH, "*USB_HST_VBUS_EN" },
  673. { 2, GPIOF_IN , "*USB_HST_FAULT#" },
  674. { 5, GPIOF_IN , "*USB_OTG_FAULT#" },
  675. { 6, GPIOF_OUT_INIT_LOW , "*USB_HST_PCI_SEL" },
  676. { 7, GPIOF_OUT_INIT_LOW , "*GSM_SEL0" },
  677. { 8, GPIOF_OUT_INIT_LOW , "*GSM_SEL1" },
  678. { 9, GPIOF_OUT_INIT_LOW , "*SER_EN" },
  679. { 10, GPIOF_IN, "*USER_PB#" },
  680. { 11, GPIOF_OUT_INIT_HIGH, "*PERST#" },
  681. { 100, GPIOF_IN , "*USER_PB#" },
  682. { 103, GPIOF_OUT_INIT_HIGH, "V5_EN" },
  683. };
  684. static struct gpio laguna_gpio_gw2384[] = {
  685. { 0, GPIOF_IN , "*GSC_IRQ#" },
  686. { 1, GPIOF_OUT_INIT_HIGH, "*USB_HST_VBUS_EN" },
  687. { 2, GPIOF_IN , "*USB_HST_FAULT#" },
  688. { 5, GPIOF_IN , "*USB_OTG_FAULT#" },
  689. { 6, GPIOF_OUT_INIT_LOW , "*USB_HST_PCI_SEL" },
  690. { 7, GPIOF_OUT_INIT_LOW , "*GSM_SEL0" },
  691. { 8, GPIOF_OUT_INIT_LOW , "*GSM_SEL1" },
  692. { 9, GPIOF_OUT_INIT_LOW , "*FP_SER_EN" },
  693. { 12, GPIOF_OUT_INIT_LOW , "J10_DIOLED0" },
  694. { 13, GPIOF_OUT_INIT_HIGH, "*I2CMUX_RST#" },
  695. { 14, GPIOF_OUT_INIT_LOW , "J10_DIOLED1" },
  696. { 15, GPIOF_OUT_INIT_LOW , "J10_DIOLED2" },
  697. { 100, GPIOF_IN , "*USER_PB#" },
  698. { 103, GPIOF_OUT_INIT_HIGH, "V5_EN" },
  699. { 108, GPIOF_IN , "J9_DIOGSC0" },
  700. };
  701. static struct gpio laguna_gpio_gw2383[] = {
  702. { 0, GPIOF_IN , "*GPS_PPS" },
  703. { 1, GPIOF_IN , "*GSC_IRQ#" },
  704. { 2, GPIOF_OUT_INIT_HIGH, "*PCIE_RST#" },
  705. { 3, GPIOF_IN , "GPIO0" },
  706. { 8, GPIOF_IN , "GPIO1" },
  707. { 100, GPIOF_IN , "DIO0" },
  708. { 101, GPIOF_IN , "DIO1" },
  709. { 108, GPIOF_IN , "*USER_PB#" },
  710. };
  711. static struct gpio laguna_gpio_gw2382[] = {
  712. { 0, GPIOF_IN , "*GPS_PPS" },
  713. { 1, GPIOF_IN , "*GSC_IRQ#" },
  714. { 2, GPIOF_OUT_INIT_HIGH, "*PCIE_RST#" },
  715. { 3, GPIOF_IN , "GPIO0" },
  716. { 4, GPIOF_IN , "GPIO1" },
  717. { 9, GPIOF_OUT_INIT_HIGH, "*USB_VBUS_EN" },
  718. { 10, GPIOF_OUT_INIT_HIGH, "*USB_PCI_SEL#" },
  719. { 100, GPIOF_IN , "DIO0" },
  720. { 101, GPIOF_IN , "DIO1" },
  721. { 108, GPIOF_IN , "*USER_PB#" },
  722. };
  723. static struct gpio laguna_gpio_gw2380[] = {
  724. { 0, GPIOF_IN , "*GPS_PPS" },
  725. { 1, GPIOF_IN , "*GSC_IRQ#" },
  726. { 3, GPIOF_IN , "GPIO0" },
  727. { 8, GPIOF_IN , "GPIO1" },
  728. { 100, GPIOF_IN , "DIO0" },
  729. { 101, GPIOF_IN , "DIO1" },
  730. { 102, GPIOF_IN , "DIO2" },
  731. { 103, GPIOF_IN , "DIO3" },
  732. { 108, GPIOF_IN , "*USER_PB#" },
  733. };
  734. /*
  735. * Initialization
  736. */
  737. static void __init laguna_init(void)
  738. {
  739. struct clk *clk;
  740. u32 __iomem *reg;
  741. clk = clk_register_fixed_rate(NULL, "cpu", NULL,
  742. CLK_IS_ROOT | CLK_IGNORE_UNUSED,
  743. cns3xxx_cpu_clock() * (1000000 / 8));
  744. clk_register_clkdev(clk, "cpu", NULL);
  745. platform_device_register(&laguna_watchdog);
  746. platform_device_register(&laguna_i2c_controller);
  747. /* Set ext_int 0-3 drive strength to 21 mA */
  748. reg = MISC_IO_PAD_DRIVE_STRENGTH_CTRL_B;
  749. *reg |= 0x300;
  750. /* Enable SCL/SDA for I2C */
  751. reg = MISC_GPIOB_PIN_ENABLE_REG;
  752. *reg |= BIT(12) | BIT(13);
  753. /* Enable MMC/SD pins */
  754. *reg |= BIT(7) | BIT(8) | BIT(9) | BIT(10) | BIT(11);
  755. cns3xxx_pwr_clk_en(1 << PM_CLK_GATE_REG_OFFSET_SPI_PCM_I2C);
  756. cns3xxx_pwr_power_up(1 << PM_CLK_GATE_REG_OFFSET_SPI_PCM_I2C);
  757. cns3xxx_pwr_soft_rst(1 << PM_CLK_GATE_REG_OFFSET_SPI_PCM_I2C);
  758. cns3xxx_pwr_clk_en(CNS3XXX_PWR_CLK_EN(SPI_PCM_I2C));
  759. cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(SPI_PCM_I2C));
  760. i2c_register_board_info(0, ARRAY_AND_SIZE(laguna_i2c_devices));
  761. pm_power_off = cns3xxx_power_off;
  762. }
  763. static struct map_desc laguna_io_desc[] __initdata = {
  764. {
  765. .virtual = CNS3XXX_UART0_BASE_VIRT,
  766. .pfn = __phys_to_pfn(CNS3XXX_UART0_BASE),
  767. .length = SZ_4K,
  768. .type = MT_DEVICE,
  769. },
  770. };
  771. static void __init laguna_map_io(void)
  772. {
  773. cns3xxx_map_io();
  774. cns3xxx_pcie_iotable_init();
  775. iotable_init(ARRAY_AND_SIZE(laguna_io_desc));
  776. laguna_early_serial_setup();
  777. }
  778. static int laguna_register_gpio(struct gpio *array, size_t num)
  779. {
  780. int i, err, ret;
  781. ret = 0;
  782. for (i = 0; i < num; i++, array++) {
  783. const char *label = array->label;
  784. if (label[0] == '*')
  785. label++;
  786. err = gpio_request_one(array->gpio, array->flags, label);
  787. if (err)
  788. ret = err;
  789. else {
  790. err = gpio_export(array->gpio, array->label[0] != '*');
  791. }
  792. }
  793. return ret;
  794. }
  795. static int __init laguna_pcie_init(void)
  796. {
  797. if (!machine_is_gw2388())
  798. return 0;
  799. return cns3xxx_pcie_init();
  800. }
  801. subsys_initcall(laguna_pcie_init);
  802. static int __init laguna_model_setup(void)
  803. {
  804. u32 __iomem *mem;
  805. u32 reg;
  806. if (!machine_is_gw2388())
  807. return 0;
  808. printk("Running on Gateworks Laguna %s\n", laguna_info.model);
  809. cns3xxx_gpio_init( 0, 32, CNS3XXX_GPIOA_BASE_VIRT, IRQ_CNS3XXX_GPIOA,
  810. NR_IRQS_CNS3XXX);
  811. cns3xxx_gpio_init(32, 32, CNS3XXX_GPIOB_BASE_VIRT, IRQ_CNS3XXX_GPIOB,
  812. NR_IRQS_CNS3XXX + 32);
  813. if (strncmp(laguna_info.model, "GW", 2) == 0) {
  814. if (laguna_info.config_bitmap & ETH0_LOAD)
  815. laguna_net_data.ports |= BIT(0);
  816. if (laguna_info.config_bitmap & ETH1_LOAD)
  817. laguna_net_data.ports |= BIT(1);
  818. if (laguna_info.config_bitmap & ETH2_LOAD)
  819. laguna_net_data.ports |= BIT(2);
  820. if (laguna_net_data.ports)
  821. platform_device_register(&laguna_net_device);
  822. if ((laguna_info.config_bitmap & SATA0_LOAD) ||
  823. (laguna_info.config_bitmap & SATA1_LOAD))
  824. cns3xxx_ahci_init();
  825. if (laguna_info.config_bitmap & (USB0_LOAD)) {
  826. cns3xxx_pwr_power_up(1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB);
  827. /* DRVVBUS pins share with GPIOA */
  828. mem = (void __iomem *)(CNS3XXX_MISC_BASE_VIRT + 0x0014);
  829. reg = __raw_readl(mem);
  830. reg |= 0x8;
  831. __raw_writel(reg, mem);
  832. /* Enable OTG */
  833. mem = (void __iomem *)(CNS3XXX_MISC_BASE_VIRT + 0x0808);
  834. reg = __raw_readl(mem);
  835. reg &= ~(1 << 10);
  836. __raw_writel(reg, mem);
  837. platform_device_register(&cns3xxx_usb_otg_device);
  838. }
  839. if (laguna_info.config_bitmap & (USB1_LOAD)) {
  840. platform_device_register(&cns3xxx_usb_ehci_device);
  841. platform_device_register(&cns3xxx_usb_ohci_device);
  842. }
  843. if (laguna_info.config_bitmap & (SD_LOAD))
  844. cns3xxx_sdhci_init();
  845. if (laguna_info.config_bitmap & (UART0_LOAD))
  846. laguna_uart.num_resources = 1;
  847. if (laguna_info.config_bitmap & (UART1_LOAD))
  848. laguna_uart.num_resources = 2;
  849. if (laguna_info.config_bitmap & (UART2_LOAD))
  850. laguna_uart.num_resources = 3;
  851. platform_device_register(&laguna_uart);
  852. if (laguna_info.config2_bitmap & (NOR_FLASH_LOAD)) {
  853. switch (laguna_info.nor_flash_size) {
  854. case 1:
  855. laguna_nor_partitions[3].size = SZ_8M - SZ_256K - SZ_128K - SZ_2M;
  856. laguna_nor_res.end = CNS3XXX_FLASH_BASE + SZ_8M - 1;
  857. break;
  858. case 2:
  859. laguna_nor_partitions[3].size = SZ_16M - SZ_256K - SZ_128K - SZ_2M;
  860. laguna_nor_res.end = CNS3XXX_FLASH_BASE + SZ_16M - 1;
  861. break;
  862. case 3:
  863. laguna_nor_partitions[3].size = SZ_32M - SZ_256K - SZ_128K - SZ_2M;
  864. laguna_nor_res.end = CNS3XXX_FLASH_BASE + SZ_32M - 1;
  865. break;
  866. case 4:
  867. laguna_nor_partitions[3].size = SZ_64M - SZ_256K - SZ_128K - SZ_2M;
  868. laguna_nor_res.end = CNS3XXX_FLASH_BASE + SZ_64M - 1;
  869. break;
  870. case 5:
  871. laguna_nor_partitions[3].size = SZ_128M - SZ_256K - SZ_128K - SZ_2M;
  872. laguna_nor_res.end = CNS3XXX_FLASH_BASE + SZ_128M - 1;
  873. break;
  874. }
  875. platform_device_register(&laguna_nor_pdev);
  876. }
  877. if (laguna_info.config2_bitmap & (SPI_FLASH_LOAD)) {
  878. switch (laguna_info.spi_flash_size) {
  879. case 1:
  880. laguna_spi_partitions[3].size = SZ_4M - SZ_2M;
  881. break;
  882. case 2:
  883. laguna_spi_partitions[3].size = SZ_8M - SZ_2M;
  884. break;
  885. case 3:
  886. laguna_spi_partitions[3].size = SZ_16M - SZ_2M;
  887. break;
  888. case 4:
  889. laguna_spi_partitions[3].size = SZ_32M - SZ_2M;
  890. break;
  891. case 5:
  892. laguna_spi_partitions[3].size = SZ_64M - SZ_2M;
  893. break;
  894. }
  895. spi_register_board_info(ARRAY_AND_SIZE(laguna_spi_devices));
  896. }
  897. if ((laguna_info.config_bitmap & SPI0_LOAD) ||
  898. (laguna_info.config_bitmap & SPI1_LOAD))
  899. platform_device_register(&laguna_spi_controller);
  900. if (laguna_info.config2_bitmap & GPS_LOAD)
  901. platform_device_register(&laguna_pps_device);
  902. /*
  903. * Do any model specific setup not known by the bitmap by matching
  904. * the first 6 characters of the model name
  905. */
  906. if ( (strncmp(laguna_info.model, "GW2388", 6) == 0)
  907. || (strncmp(laguna_info.model, "GW2389", 6) == 0) )
  908. {
  909. // configure GPIO's
  910. laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2388));
  911. // configure LED's
  912. laguna_gpio_leds_data.num_leds = 2;
  913. } else if (strncmp(laguna_info.model, "GW2387", 6) == 0) {
  914. // configure GPIO's
  915. laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2387));
  916. // configure LED's
  917. laguna_gpio_leds_data.num_leds = 2;
  918. } else if (strncmp(laguna_info.model, "GW2385", 6) == 0) {
  919. // configure GPIO's
  920. laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2385));
  921. // configure LED's
  922. laguna_gpio_leds[0].gpio = 115;
  923. laguna_gpio_leds[1].gpio = 12;
  924. laguna_gpio_leds[1].name = "red";
  925. laguna_gpio_leds[1].active_low = 0,
  926. laguna_gpio_leds[2].gpio = 14;
  927. laguna_gpio_leds[2].name = "green";
  928. laguna_gpio_leds[2].active_low = 0,
  929. laguna_gpio_leds[3].gpio = 15;
  930. laguna_gpio_leds[3].name = "blue";
  931. laguna_gpio_leds[3].active_low = 0,
  932. laguna_gpio_leds_data.num_leds = 4;
  933. } else if (strncmp(laguna_info.model, "GW2384", 6) == 0) {
  934. // configure GPIO's
  935. laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2384));
  936. // configure LED's
  937. laguna_gpio_leds_data.num_leds = 1;
  938. } else if (strncmp(laguna_info.model, "GW2383", 6) == 0) {
  939. // configure GPIO's
  940. laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2383));
  941. // configure LED's
  942. laguna_gpio_leds[0].gpio = 107;
  943. laguna_gpio_leds_data.num_leds = 1;
  944. } else if (strncmp(laguna_info.model, "GW2382", 6) == 0) {
  945. // configure GPIO's
  946. laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2382));
  947. // configure LED's
  948. laguna_gpio_leds[0].gpio = 107;
  949. laguna_gpio_leds_data.num_leds = 1;
  950. } else if (strncmp(laguna_info.model, "GW2380", 6) == 0) {
  951. // configure GPIO's
  952. laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2380));
  953. // configure LED's
  954. laguna_gpio_leds[0].gpio = 107;
  955. laguna_gpio_leds[1].gpio = 106;
  956. laguna_gpio_leds_data.num_leds = 2;
  957. } else if (strncmp(laguna_info.model, "GW2391", 6) == 0) {
  958. // configure GPIO's
  959. laguna_register_gpio(ARRAY_AND_SIZE(laguna_gpio_gw2391));
  960. // configure LED's
  961. laguna_gpio_leds_data.num_leds = 2;
  962. }
  963. platform_device_register(&laguna_gpio_leds_device);
  964. } else {
  965. // Do some defaults here, not sure what yet
  966. }
  967. return 0;
  968. }
  969. late_initcall(laguna_model_setup);
  970. MACHINE_START(GW2388, "Gateworks Corporation Laguna Platform")
  971. .smp = smp_ops(cns3xxx_smp_ops),
  972. .atag_offset = 0x100,
  973. .map_io = laguna_map_io,
  974. .init_irq = cns3xxx_init_irq,
  975. .init_time = cns3xxx_timer_init,
  976. .init_machine = laguna_init,
  977. .restart = cns3xxx_restart,
  978. MACHINE_END