core.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  1. /*
  2. * arch/arm/mach-ep93xx/core.c
  3. * Core routines for Cirrus EP93xx chips.
  4. *
  5. * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org>
  6. * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org>
  7. *
  8. * Thanks go to Michael Burian and Ray Lehtiniemi for their key
  9. * role in the ep93xx linux community.
  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; either version 2 of the License, or (at
  14. * your option) any later version.
  15. */
  16. #define pr_fmt(fmt) "ep93xx " KBUILD_MODNAME ": " fmt
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/dma-mapping.h>
  22. #include <linux/sys_soc.h>
  23. #include <linux/timex.h>
  24. #include <linux/irq.h>
  25. #include <linux/io.h>
  26. #include <linux/gpio.h>
  27. #include <linux/leds.h>
  28. #include <linux/termios.h>
  29. #include <linux/amba/bus.h>
  30. #include <linux/amba/serial.h>
  31. #include <linux/mtd/physmap.h>
  32. #include <linux/i2c.h>
  33. #include <linux/i2c-gpio.h>
  34. #include <linux/spi/spi.h>
  35. #include <linux/export.h>
  36. #include <linux/irqchip/arm-vic.h>
  37. #include <linux/reboot.h>
  38. #include <linux/usb/ohci_pdriver.h>
  39. #include <mach/hardware.h>
  40. #include <linux/platform_data/video-ep93xx.h>
  41. #include <linux/platform_data/keypad-ep93xx.h>
  42. #include <linux/platform_data/spi-ep93xx.h>
  43. #include <mach/gpio-ep93xx.h>
  44. #include <asm/mach/arch.h>
  45. #include <asm/mach/map.h>
  46. #include <asm/mach/time.h>
  47. #include "soc.h"
  48. /*************************************************************************
  49. * Static I/O mappings that are needed for all EP93xx platforms
  50. *************************************************************************/
  51. static struct map_desc ep93xx_io_desc[] __initdata = {
  52. {
  53. .virtual = EP93XX_AHB_VIRT_BASE,
  54. .pfn = __phys_to_pfn(EP93XX_AHB_PHYS_BASE),
  55. .length = EP93XX_AHB_SIZE,
  56. .type = MT_DEVICE,
  57. }, {
  58. .virtual = EP93XX_APB_VIRT_BASE,
  59. .pfn = __phys_to_pfn(EP93XX_APB_PHYS_BASE),
  60. .length = EP93XX_APB_SIZE,
  61. .type = MT_DEVICE,
  62. },
  63. };
  64. void __init ep93xx_map_io(void)
  65. {
  66. iotable_init(ep93xx_io_desc, ARRAY_SIZE(ep93xx_io_desc));
  67. }
  68. /*************************************************************************
  69. * Timer handling for EP93xx
  70. *************************************************************************
  71. * The ep93xx has four internal timers. Timers 1, 2 (both 16 bit) and
  72. * 3 (32 bit) count down at 508 kHz, are self-reloading, and can generate
  73. * an interrupt on underflow. Timer 4 (40 bit) counts down at 983.04 kHz,
  74. * is free-running, and can't generate interrupts.
  75. *
  76. * The 508 kHz timers are ideal for use for the timer interrupt, as the
  77. * most common values of HZ divide 508 kHz nicely. We pick one of the 16
  78. * bit timers (timer 1) since we don't need more than 16 bits of reload
  79. * value as long as HZ >= 8.
  80. *
  81. * The higher clock rate of timer 4 makes it a better choice than the
  82. * other timers for use in gettimeoffset(), while the fact that it can't
  83. * generate interrupts means we don't have to worry about not being able
  84. * to use this timer for something else. We also use timer 4 for keeping
  85. * track of lost jiffies.
  86. */
  87. #define EP93XX_TIMER_REG(x) (EP93XX_TIMER_BASE + (x))
  88. #define EP93XX_TIMER1_LOAD EP93XX_TIMER_REG(0x00)
  89. #define EP93XX_TIMER1_VALUE EP93XX_TIMER_REG(0x04)
  90. #define EP93XX_TIMER1_CONTROL EP93XX_TIMER_REG(0x08)
  91. #define EP93XX_TIMER123_CONTROL_ENABLE (1 << 7)
  92. #define EP93XX_TIMER123_CONTROL_MODE (1 << 6)
  93. #define EP93XX_TIMER123_CONTROL_CLKSEL (1 << 3)
  94. #define EP93XX_TIMER1_CLEAR EP93XX_TIMER_REG(0x0c)
  95. #define EP93XX_TIMER2_LOAD EP93XX_TIMER_REG(0x20)
  96. #define EP93XX_TIMER2_VALUE EP93XX_TIMER_REG(0x24)
  97. #define EP93XX_TIMER2_CONTROL EP93XX_TIMER_REG(0x28)
  98. #define EP93XX_TIMER2_CLEAR EP93XX_TIMER_REG(0x2c)
  99. #define EP93XX_TIMER4_VALUE_LOW EP93XX_TIMER_REG(0x60)
  100. #define EP93XX_TIMER4_VALUE_HIGH EP93XX_TIMER_REG(0x64)
  101. #define EP93XX_TIMER4_VALUE_HIGH_ENABLE (1 << 8)
  102. #define EP93XX_TIMER3_LOAD EP93XX_TIMER_REG(0x80)
  103. #define EP93XX_TIMER3_VALUE EP93XX_TIMER_REG(0x84)
  104. #define EP93XX_TIMER3_CONTROL EP93XX_TIMER_REG(0x88)
  105. #define EP93XX_TIMER3_CLEAR EP93XX_TIMER_REG(0x8c)
  106. #define EP93XX_TIMER123_CLOCK 508469
  107. #define EP93XX_TIMER4_CLOCK 983040
  108. #define TIMER1_RELOAD ((EP93XX_TIMER123_CLOCK / HZ) - 1)
  109. #define TIMER4_TICKS_PER_JIFFY DIV_ROUND_CLOSEST(EP93XX_TIMER4_CLOCK, HZ)
  110. static unsigned int last_jiffy_time;
  111. static irqreturn_t ep93xx_timer_interrupt(int irq, void *dev_id)
  112. {
  113. /* Writing any value clears the timer interrupt */
  114. __raw_writel(1, EP93XX_TIMER1_CLEAR);
  115. /* Recover lost jiffies */
  116. while ((signed long)
  117. (__raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time)
  118. >= TIMER4_TICKS_PER_JIFFY) {
  119. last_jiffy_time += TIMER4_TICKS_PER_JIFFY;
  120. timer_tick();
  121. }
  122. return IRQ_HANDLED;
  123. }
  124. static struct irqaction ep93xx_timer_irq = {
  125. .name = "ep93xx timer",
  126. .flags = IRQF_TIMER | IRQF_IRQPOLL,
  127. .handler = ep93xx_timer_interrupt,
  128. };
  129. static u32 ep93xx_gettimeoffset(void)
  130. {
  131. int offset;
  132. offset = __raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time;
  133. /*
  134. * Timer 4 is based on a 983.04 kHz reference clock,
  135. * so dividing by 983040 gives the fraction of a second,
  136. * so dividing by 0.983040 converts to uS.
  137. * Refactor the calculation to avoid overflow.
  138. * Finally, multiply by 1000 to give nS.
  139. */
  140. return (offset + (53 * offset / 3072)) * 1000;
  141. }
  142. void __init ep93xx_timer_init(void)
  143. {
  144. u32 tmode = EP93XX_TIMER123_CONTROL_MODE |
  145. EP93XX_TIMER123_CONTROL_CLKSEL;
  146. arch_gettimeoffset = ep93xx_gettimeoffset;
  147. /* Enable periodic HZ timer. */
  148. __raw_writel(tmode, EP93XX_TIMER1_CONTROL);
  149. __raw_writel(TIMER1_RELOAD, EP93XX_TIMER1_LOAD);
  150. __raw_writel(tmode | EP93XX_TIMER123_CONTROL_ENABLE,
  151. EP93XX_TIMER1_CONTROL);
  152. /* Enable lost jiffy timer. */
  153. __raw_writel(EP93XX_TIMER4_VALUE_HIGH_ENABLE,
  154. EP93XX_TIMER4_VALUE_HIGH);
  155. setup_irq(IRQ_EP93XX_TIMER1, &ep93xx_timer_irq);
  156. }
  157. /*************************************************************************
  158. * EP93xx IRQ handling
  159. *************************************************************************/
  160. void __init ep93xx_init_irq(void)
  161. {
  162. vic_init(EP93XX_VIC1_BASE, 0, EP93XX_VIC1_VALID_IRQ_MASK, 0);
  163. vic_init(EP93XX_VIC2_BASE, 32, EP93XX_VIC2_VALID_IRQ_MASK, 0);
  164. }
  165. /*************************************************************************
  166. * EP93xx System Controller Software Locked register handling
  167. *************************************************************************/
  168. /*
  169. * syscon_swlock prevents anything else from writing to the syscon
  170. * block while a software locked register is being written.
  171. */
  172. static DEFINE_SPINLOCK(syscon_swlock);
  173. void ep93xx_syscon_swlocked_write(unsigned int val, void __iomem *reg)
  174. {
  175. unsigned long flags;
  176. spin_lock_irqsave(&syscon_swlock, flags);
  177. __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
  178. __raw_writel(val, reg);
  179. spin_unlock_irqrestore(&syscon_swlock, flags);
  180. }
  181. void ep93xx_devcfg_set_clear(unsigned int set_bits, unsigned int clear_bits)
  182. {
  183. unsigned long flags;
  184. unsigned int val;
  185. spin_lock_irqsave(&syscon_swlock, flags);
  186. val = __raw_readl(EP93XX_SYSCON_DEVCFG);
  187. val &= ~clear_bits;
  188. val |= set_bits;
  189. __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
  190. __raw_writel(val, EP93XX_SYSCON_DEVCFG);
  191. spin_unlock_irqrestore(&syscon_swlock, flags);
  192. }
  193. /**
  194. * ep93xx_chip_revision() - returns the EP93xx chip revision
  195. *
  196. * See <mach/platform.h> for more information.
  197. */
  198. unsigned int ep93xx_chip_revision(void)
  199. {
  200. unsigned int v;
  201. v = __raw_readl(EP93XX_SYSCON_SYSCFG);
  202. v &= EP93XX_SYSCON_SYSCFG_REV_MASK;
  203. v >>= EP93XX_SYSCON_SYSCFG_REV_SHIFT;
  204. return v;
  205. }
  206. EXPORT_SYMBOL_GPL(ep93xx_chip_revision);
  207. /*************************************************************************
  208. * EP93xx GPIO
  209. *************************************************************************/
  210. static struct resource ep93xx_gpio_resource[] = {
  211. DEFINE_RES_MEM(EP93XX_GPIO_PHYS_BASE, 0xcc),
  212. };
  213. static struct platform_device ep93xx_gpio_device = {
  214. .name = "gpio-ep93xx",
  215. .id = -1,
  216. .num_resources = ARRAY_SIZE(ep93xx_gpio_resource),
  217. .resource = ep93xx_gpio_resource,
  218. };
  219. /*************************************************************************
  220. * EP93xx peripheral handling
  221. *************************************************************************/
  222. #define EP93XX_UART_MCR_OFFSET (0x0100)
  223. static void ep93xx_uart_set_mctrl(struct amba_device *dev,
  224. void __iomem *base, unsigned int mctrl)
  225. {
  226. unsigned int mcr;
  227. mcr = 0;
  228. if (mctrl & TIOCM_RTS)
  229. mcr |= 2;
  230. if (mctrl & TIOCM_DTR)
  231. mcr |= 1;
  232. __raw_writel(mcr, base + EP93XX_UART_MCR_OFFSET);
  233. }
  234. static struct amba_pl010_data ep93xx_uart_data = {
  235. .set_mctrl = ep93xx_uart_set_mctrl,
  236. };
  237. static AMBA_APB_DEVICE(uart1, "apb:uart1", 0x00041010, EP93XX_UART1_PHYS_BASE,
  238. { IRQ_EP93XX_UART1 }, &ep93xx_uart_data);
  239. static AMBA_APB_DEVICE(uart2, "apb:uart2", 0x00041010, EP93XX_UART2_PHYS_BASE,
  240. { IRQ_EP93XX_UART2 }, NULL);
  241. static AMBA_APB_DEVICE(uart3, "apb:uart3", 0x00041010, EP93XX_UART3_PHYS_BASE,
  242. { IRQ_EP93XX_UART3 }, &ep93xx_uart_data);
  243. static struct resource ep93xx_rtc_resource[] = {
  244. DEFINE_RES_MEM(EP93XX_RTC_PHYS_BASE, 0x10c),
  245. };
  246. static struct platform_device ep93xx_rtc_device = {
  247. .name = "ep93xx-rtc",
  248. .id = -1,
  249. .num_resources = ARRAY_SIZE(ep93xx_rtc_resource),
  250. .resource = ep93xx_rtc_resource,
  251. };
  252. /*************************************************************************
  253. * EP93xx OHCI USB Host
  254. *************************************************************************/
  255. static struct clk *ep93xx_ohci_host_clock;
  256. static int ep93xx_ohci_power_on(struct platform_device *pdev)
  257. {
  258. if (!ep93xx_ohci_host_clock) {
  259. ep93xx_ohci_host_clock = devm_clk_get(&pdev->dev, NULL);
  260. if (IS_ERR(ep93xx_ohci_host_clock))
  261. return PTR_ERR(ep93xx_ohci_host_clock);
  262. }
  263. return clk_enable(ep93xx_ohci_host_clock);
  264. }
  265. static void ep93xx_ohci_power_off(struct platform_device *pdev)
  266. {
  267. clk_disable(ep93xx_ohci_host_clock);
  268. }
  269. static struct usb_ohci_pdata ep93xx_ohci_pdata = {
  270. .power_on = ep93xx_ohci_power_on,
  271. .power_off = ep93xx_ohci_power_off,
  272. .power_suspend = ep93xx_ohci_power_off,
  273. };
  274. static struct resource ep93xx_ohci_resources[] = {
  275. DEFINE_RES_MEM(EP93XX_USB_PHYS_BASE, 0x1000),
  276. DEFINE_RES_IRQ(IRQ_EP93XX_USB),
  277. };
  278. static u64 ep93xx_ohci_dma_mask = DMA_BIT_MASK(32);
  279. static struct platform_device ep93xx_ohci_device = {
  280. .name = "ohci-platform",
  281. .id = -1,
  282. .num_resources = ARRAY_SIZE(ep93xx_ohci_resources),
  283. .resource = ep93xx_ohci_resources,
  284. .dev = {
  285. .dma_mask = &ep93xx_ohci_dma_mask,
  286. .coherent_dma_mask = DMA_BIT_MASK(32),
  287. .platform_data = &ep93xx_ohci_pdata,
  288. },
  289. };
  290. /*************************************************************************
  291. * EP93xx physmap'ed flash
  292. *************************************************************************/
  293. static struct physmap_flash_data ep93xx_flash_data;
  294. static struct resource ep93xx_flash_resource = {
  295. .flags = IORESOURCE_MEM,
  296. };
  297. static struct platform_device ep93xx_flash = {
  298. .name = "physmap-flash",
  299. .id = 0,
  300. .dev = {
  301. .platform_data = &ep93xx_flash_data,
  302. },
  303. .num_resources = 1,
  304. .resource = &ep93xx_flash_resource,
  305. };
  306. /**
  307. * ep93xx_register_flash() - Register the external flash device.
  308. * @width: bank width in octets
  309. * @start: resource start address
  310. * @size: resource size
  311. */
  312. void __init ep93xx_register_flash(unsigned int width,
  313. resource_size_t start, resource_size_t size)
  314. {
  315. ep93xx_flash_data.width = width;
  316. ep93xx_flash_resource.start = start;
  317. ep93xx_flash_resource.end = start + size - 1;
  318. platform_device_register(&ep93xx_flash);
  319. }
  320. /*************************************************************************
  321. * EP93xx ethernet peripheral handling
  322. *************************************************************************/
  323. static struct ep93xx_eth_data ep93xx_eth_data;
  324. static struct resource ep93xx_eth_resource[] = {
  325. DEFINE_RES_MEM(EP93XX_ETHERNET_PHYS_BASE, 0x10000),
  326. DEFINE_RES_IRQ(IRQ_EP93XX_ETHERNET),
  327. };
  328. static u64 ep93xx_eth_dma_mask = DMA_BIT_MASK(32);
  329. static struct platform_device ep93xx_eth_device = {
  330. .name = "ep93xx-eth",
  331. .id = -1,
  332. .dev = {
  333. .platform_data = &ep93xx_eth_data,
  334. .coherent_dma_mask = DMA_BIT_MASK(32),
  335. .dma_mask = &ep93xx_eth_dma_mask,
  336. },
  337. .num_resources = ARRAY_SIZE(ep93xx_eth_resource),
  338. .resource = ep93xx_eth_resource,
  339. };
  340. /**
  341. * ep93xx_register_eth - Register the built-in ethernet platform device.
  342. * @data: platform specific ethernet configuration (__initdata)
  343. * @copy_addr: flag indicating that the MAC address should be copied
  344. * from the IndAd registers (as programmed by the bootloader)
  345. */
  346. void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
  347. {
  348. if (copy_addr)
  349. memcpy_fromio(data->dev_addr, EP93XX_ETHERNET_BASE + 0x50, 6);
  350. ep93xx_eth_data = *data;
  351. platform_device_register(&ep93xx_eth_device);
  352. }
  353. /*************************************************************************
  354. * EP93xx i2c peripheral handling
  355. *************************************************************************/
  356. static struct i2c_gpio_platform_data ep93xx_i2c_data;
  357. static struct platform_device ep93xx_i2c_device = {
  358. .name = "i2c-gpio",
  359. .id = 0,
  360. .dev = {
  361. .platform_data = &ep93xx_i2c_data,
  362. },
  363. };
  364. /**
  365. * ep93xx_register_i2c - Register the i2c platform device.
  366. * @data: platform specific i2c-gpio configuration (__initdata)
  367. * @devices: platform specific i2c bus device information (__initdata)
  368. * @num: the number of devices on the i2c bus
  369. */
  370. void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data,
  371. struct i2c_board_info *devices, int num)
  372. {
  373. /*
  374. * Set the EEPROM interface pin drive type control.
  375. * Defines the driver type for the EECLK and EEDAT pins as either
  376. * open drain, which will require an external pull-up, or a normal
  377. * CMOS driver.
  378. */
  379. if (data->sda_is_open_drain && data->sda_pin != EP93XX_GPIO_LINE_EEDAT)
  380. pr_warning("sda != EEDAT, open drain has no effect\n");
  381. if (data->scl_is_open_drain && data->scl_pin != EP93XX_GPIO_LINE_EECLK)
  382. pr_warning("scl != EECLK, open drain has no effect\n");
  383. __raw_writel((data->sda_is_open_drain << 1) |
  384. (data->scl_is_open_drain << 0),
  385. EP93XX_GPIO_EEDRIVE);
  386. ep93xx_i2c_data = *data;
  387. i2c_register_board_info(0, devices, num);
  388. platform_device_register(&ep93xx_i2c_device);
  389. }
  390. /*************************************************************************
  391. * EP93xx SPI peripheral handling
  392. *************************************************************************/
  393. static struct ep93xx_spi_info ep93xx_spi_master_data;
  394. static struct resource ep93xx_spi_resources[] = {
  395. DEFINE_RES_MEM(EP93XX_SPI_PHYS_BASE, 0x18),
  396. DEFINE_RES_IRQ(IRQ_EP93XX_SSP),
  397. };
  398. static u64 ep93xx_spi_dma_mask = DMA_BIT_MASK(32);
  399. static struct platform_device ep93xx_spi_device = {
  400. .name = "ep93xx-spi",
  401. .id = 0,
  402. .dev = {
  403. .platform_data = &ep93xx_spi_master_data,
  404. .coherent_dma_mask = DMA_BIT_MASK(32),
  405. .dma_mask = &ep93xx_spi_dma_mask,
  406. },
  407. .num_resources = ARRAY_SIZE(ep93xx_spi_resources),
  408. .resource = ep93xx_spi_resources,
  409. };
  410. /**
  411. * ep93xx_register_spi() - registers spi platform device
  412. * @info: ep93xx board specific spi master info (__initdata)
  413. * @devices: SPI devices to register (__initdata)
  414. * @num: number of SPI devices to register
  415. *
  416. * This function registers platform device for the EP93xx SPI controller and
  417. * also makes sure that SPI pins are muxed so that I2S is not using those pins.
  418. */
  419. void __init ep93xx_register_spi(struct ep93xx_spi_info *info,
  420. struct spi_board_info *devices, int num)
  421. {
  422. /*
  423. * When SPI is used, we need to make sure that I2S is muxed off from
  424. * SPI pins.
  425. */
  426. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONSSP);
  427. ep93xx_spi_master_data = *info;
  428. spi_register_board_info(devices, num);
  429. platform_device_register(&ep93xx_spi_device);
  430. }
  431. /*************************************************************************
  432. * EP93xx LEDs
  433. *************************************************************************/
  434. static const struct gpio_led ep93xx_led_pins[] __initconst = {
  435. {
  436. .name = "platform:grled",
  437. .gpio = EP93XX_GPIO_LINE_GRLED,
  438. }, {
  439. .name = "platform:rdled",
  440. .gpio = EP93XX_GPIO_LINE_RDLED,
  441. },
  442. };
  443. static const struct gpio_led_platform_data ep93xx_led_data __initconst = {
  444. .num_leds = ARRAY_SIZE(ep93xx_led_pins),
  445. .leds = ep93xx_led_pins,
  446. };
  447. /*************************************************************************
  448. * EP93xx pwm peripheral handling
  449. *************************************************************************/
  450. static struct resource ep93xx_pwm0_resource[] = {
  451. DEFINE_RES_MEM(EP93XX_PWM_PHYS_BASE, 0x10),
  452. };
  453. static struct platform_device ep93xx_pwm0_device = {
  454. .name = "ep93xx-pwm",
  455. .id = 0,
  456. .num_resources = ARRAY_SIZE(ep93xx_pwm0_resource),
  457. .resource = ep93xx_pwm0_resource,
  458. };
  459. static struct resource ep93xx_pwm1_resource[] = {
  460. DEFINE_RES_MEM(EP93XX_PWM_PHYS_BASE + 0x20, 0x10),
  461. };
  462. static struct platform_device ep93xx_pwm1_device = {
  463. .name = "ep93xx-pwm",
  464. .id = 1,
  465. .num_resources = ARRAY_SIZE(ep93xx_pwm1_resource),
  466. .resource = ep93xx_pwm1_resource,
  467. };
  468. void __init ep93xx_register_pwm(int pwm0, int pwm1)
  469. {
  470. if (pwm0)
  471. platform_device_register(&ep93xx_pwm0_device);
  472. /* NOTE: EP9307 does not have PWMOUT1 (pin EGPIO14) */
  473. if (pwm1)
  474. platform_device_register(&ep93xx_pwm1_device);
  475. }
  476. int ep93xx_pwm_acquire_gpio(struct platform_device *pdev)
  477. {
  478. int err;
  479. if (pdev->id == 0) {
  480. err = 0;
  481. } else if (pdev->id == 1) {
  482. err = gpio_request(EP93XX_GPIO_LINE_EGPIO14,
  483. dev_name(&pdev->dev));
  484. if (err)
  485. return err;
  486. err = gpio_direction_output(EP93XX_GPIO_LINE_EGPIO14, 0);
  487. if (err)
  488. goto fail;
  489. /* PWM 1 output on EGPIO[14] */
  490. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_PONG);
  491. } else {
  492. err = -ENODEV;
  493. }
  494. return err;
  495. fail:
  496. gpio_free(EP93XX_GPIO_LINE_EGPIO14);
  497. return err;
  498. }
  499. EXPORT_SYMBOL(ep93xx_pwm_acquire_gpio);
  500. void ep93xx_pwm_release_gpio(struct platform_device *pdev)
  501. {
  502. if (pdev->id == 1) {
  503. gpio_direction_input(EP93XX_GPIO_LINE_EGPIO14);
  504. gpio_free(EP93XX_GPIO_LINE_EGPIO14);
  505. /* EGPIO[14] used for GPIO */
  506. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_PONG);
  507. }
  508. }
  509. EXPORT_SYMBOL(ep93xx_pwm_release_gpio);
  510. /*************************************************************************
  511. * EP93xx video peripheral handling
  512. *************************************************************************/
  513. static struct ep93xxfb_mach_info ep93xxfb_data;
  514. static struct resource ep93xx_fb_resource[] = {
  515. DEFINE_RES_MEM(EP93XX_RASTER_PHYS_BASE, 0x800),
  516. };
  517. static struct platform_device ep93xx_fb_device = {
  518. .name = "ep93xx-fb",
  519. .id = -1,
  520. .dev = {
  521. .platform_data = &ep93xxfb_data,
  522. .coherent_dma_mask = DMA_BIT_MASK(32),
  523. .dma_mask = &ep93xx_fb_device.dev.coherent_dma_mask,
  524. },
  525. .num_resources = ARRAY_SIZE(ep93xx_fb_resource),
  526. .resource = ep93xx_fb_resource,
  527. };
  528. /* The backlight use a single register in the framebuffer's register space */
  529. #define EP93XX_RASTER_REG_BRIGHTNESS 0x20
  530. static struct resource ep93xx_bl_resources[] = {
  531. DEFINE_RES_MEM(EP93XX_RASTER_PHYS_BASE +
  532. EP93XX_RASTER_REG_BRIGHTNESS, 0x04),
  533. };
  534. static struct platform_device ep93xx_bl_device = {
  535. .name = "ep93xx-bl",
  536. .id = -1,
  537. .num_resources = ARRAY_SIZE(ep93xx_bl_resources),
  538. .resource = ep93xx_bl_resources,
  539. };
  540. /**
  541. * ep93xx_register_fb - Register the framebuffer platform device.
  542. * @data: platform specific framebuffer configuration (__initdata)
  543. */
  544. void __init ep93xx_register_fb(struct ep93xxfb_mach_info *data)
  545. {
  546. ep93xxfb_data = *data;
  547. platform_device_register(&ep93xx_fb_device);
  548. platform_device_register(&ep93xx_bl_device);
  549. }
  550. /*************************************************************************
  551. * EP93xx matrix keypad peripheral handling
  552. *************************************************************************/
  553. static struct ep93xx_keypad_platform_data ep93xx_keypad_data;
  554. static struct resource ep93xx_keypad_resource[] = {
  555. DEFINE_RES_MEM(EP93XX_KEY_MATRIX_PHYS_BASE, 0x0c),
  556. DEFINE_RES_IRQ(IRQ_EP93XX_KEY),
  557. };
  558. static struct platform_device ep93xx_keypad_device = {
  559. .name = "ep93xx-keypad",
  560. .id = -1,
  561. .dev = {
  562. .platform_data = &ep93xx_keypad_data,
  563. },
  564. .num_resources = ARRAY_SIZE(ep93xx_keypad_resource),
  565. .resource = ep93xx_keypad_resource,
  566. };
  567. /**
  568. * ep93xx_register_keypad - Register the keypad platform device.
  569. * @data: platform specific keypad configuration (__initdata)
  570. */
  571. void __init ep93xx_register_keypad(struct ep93xx_keypad_platform_data *data)
  572. {
  573. ep93xx_keypad_data = *data;
  574. platform_device_register(&ep93xx_keypad_device);
  575. }
  576. int ep93xx_keypad_acquire_gpio(struct platform_device *pdev)
  577. {
  578. int err;
  579. int i;
  580. for (i = 0; i < 8; i++) {
  581. err = gpio_request(EP93XX_GPIO_LINE_C(i), dev_name(&pdev->dev));
  582. if (err)
  583. goto fail_gpio_c;
  584. err = gpio_request(EP93XX_GPIO_LINE_D(i), dev_name(&pdev->dev));
  585. if (err)
  586. goto fail_gpio_d;
  587. }
  588. /* Enable the keypad controller; GPIO ports C and D used for keypad */
  589. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_KEYS |
  590. EP93XX_SYSCON_DEVCFG_GONK);
  591. return 0;
  592. fail_gpio_d:
  593. gpio_free(EP93XX_GPIO_LINE_C(i));
  594. fail_gpio_c:
  595. for (--i; i >= 0; --i) {
  596. gpio_free(EP93XX_GPIO_LINE_C(i));
  597. gpio_free(EP93XX_GPIO_LINE_D(i));
  598. }
  599. return err;
  600. }
  601. EXPORT_SYMBOL(ep93xx_keypad_acquire_gpio);
  602. void ep93xx_keypad_release_gpio(struct platform_device *pdev)
  603. {
  604. int i;
  605. for (i = 0; i < 8; i++) {
  606. gpio_free(EP93XX_GPIO_LINE_C(i));
  607. gpio_free(EP93XX_GPIO_LINE_D(i));
  608. }
  609. /* Disable the keypad controller; GPIO ports C and D used for GPIO */
  610. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS |
  611. EP93XX_SYSCON_DEVCFG_GONK);
  612. }
  613. EXPORT_SYMBOL(ep93xx_keypad_release_gpio);
  614. /*************************************************************************
  615. * EP93xx I2S audio peripheral handling
  616. *************************************************************************/
  617. static struct resource ep93xx_i2s_resource[] = {
  618. DEFINE_RES_MEM(EP93XX_I2S_PHYS_BASE, 0x100),
  619. };
  620. static struct platform_device ep93xx_i2s_device = {
  621. .name = "ep93xx-i2s",
  622. .id = -1,
  623. .num_resources = ARRAY_SIZE(ep93xx_i2s_resource),
  624. .resource = ep93xx_i2s_resource,
  625. };
  626. static struct platform_device ep93xx_pcm_device = {
  627. .name = "ep93xx-pcm-audio",
  628. .id = -1,
  629. };
  630. void __init ep93xx_register_i2s(void)
  631. {
  632. platform_device_register(&ep93xx_i2s_device);
  633. platform_device_register(&ep93xx_pcm_device);
  634. }
  635. #define EP93XX_SYSCON_DEVCFG_I2S_MASK (EP93XX_SYSCON_DEVCFG_I2SONSSP | \
  636. EP93XX_SYSCON_DEVCFG_I2SONAC97)
  637. #define EP93XX_I2SCLKDIV_MASK (EP93XX_SYSCON_I2SCLKDIV_ORIDE | \
  638. EP93XX_SYSCON_I2SCLKDIV_SPOL)
  639. int ep93xx_i2s_acquire(void)
  640. {
  641. unsigned val;
  642. ep93xx_devcfg_set_clear(EP93XX_SYSCON_DEVCFG_I2SONAC97,
  643. EP93XX_SYSCON_DEVCFG_I2S_MASK);
  644. /*
  645. * This is potentially racy with the clock api for i2s_mclk, sclk and
  646. * lrclk. Since the i2s driver is the only user of those clocks we
  647. * rely on it to prevent parallel use of this function and the
  648. * clock api for the i2s clocks.
  649. */
  650. val = __raw_readl(EP93XX_SYSCON_I2SCLKDIV);
  651. val &= ~EP93XX_I2SCLKDIV_MASK;
  652. val |= EP93XX_SYSCON_I2SCLKDIV_ORIDE | EP93XX_SYSCON_I2SCLKDIV_SPOL;
  653. ep93xx_syscon_swlocked_write(val, EP93XX_SYSCON_I2SCLKDIV);
  654. return 0;
  655. }
  656. EXPORT_SYMBOL(ep93xx_i2s_acquire);
  657. void ep93xx_i2s_release(void)
  658. {
  659. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2S_MASK);
  660. }
  661. EXPORT_SYMBOL(ep93xx_i2s_release);
  662. /*************************************************************************
  663. * EP93xx AC97 audio peripheral handling
  664. *************************************************************************/
  665. static struct resource ep93xx_ac97_resources[] = {
  666. DEFINE_RES_MEM(EP93XX_AAC_PHYS_BASE, 0xac),
  667. DEFINE_RES_IRQ(IRQ_EP93XX_AACINTR),
  668. };
  669. static struct platform_device ep93xx_ac97_device = {
  670. .name = "ep93xx-ac97",
  671. .id = -1,
  672. .num_resources = ARRAY_SIZE(ep93xx_ac97_resources),
  673. .resource = ep93xx_ac97_resources,
  674. };
  675. void __init ep93xx_register_ac97(void)
  676. {
  677. /*
  678. * Make sure that the AC97 pins are not used by I2S.
  679. */
  680. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONAC97);
  681. platform_device_register(&ep93xx_ac97_device);
  682. platform_device_register(&ep93xx_pcm_device);
  683. }
  684. /*************************************************************************
  685. * EP93xx Watchdog
  686. *************************************************************************/
  687. static struct resource ep93xx_wdt_resources[] = {
  688. DEFINE_RES_MEM(EP93XX_WATCHDOG_PHYS_BASE, 0x08),
  689. };
  690. static struct platform_device ep93xx_wdt_device = {
  691. .name = "ep93xx-wdt",
  692. .id = -1,
  693. .num_resources = ARRAY_SIZE(ep93xx_wdt_resources),
  694. .resource = ep93xx_wdt_resources,
  695. };
  696. /*************************************************************************
  697. * EP93xx IDE
  698. *************************************************************************/
  699. static struct resource ep93xx_ide_resources[] = {
  700. DEFINE_RES_MEM(EP93XX_IDE_PHYS_BASE, 0x38),
  701. DEFINE_RES_IRQ(IRQ_EP93XX_EXT3),
  702. };
  703. static struct platform_device ep93xx_ide_device = {
  704. .name = "ep93xx-ide",
  705. .id = -1,
  706. .dev = {
  707. .dma_mask = &ep93xx_ide_device.dev.coherent_dma_mask,
  708. .coherent_dma_mask = DMA_BIT_MASK(32),
  709. },
  710. .num_resources = ARRAY_SIZE(ep93xx_ide_resources),
  711. .resource = ep93xx_ide_resources,
  712. };
  713. void __init ep93xx_register_ide(void)
  714. {
  715. platform_device_register(&ep93xx_ide_device);
  716. }
  717. int ep93xx_ide_acquire_gpio(struct platform_device *pdev)
  718. {
  719. int err;
  720. int i;
  721. err = gpio_request(EP93XX_GPIO_LINE_EGPIO2, dev_name(&pdev->dev));
  722. if (err)
  723. return err;
  724. err = gpio_request(EP93XX_GPIO_LINE_EGPIO15, dev_name(&pdev->dev));
  725. if (err)
  726. goto fail_egpio15;
  727. for (i = 2; i < 8; i++) {
  728. err = gpio_request(EP93XX_GPIO_LINE_E(i), dev_name(&pdev->dev));
  729. if (err)
  730. goto fail_gpio_e;
  731. }
  732. for (i = 4; i < 8; i++) {
  733. err = gpio_request(EP93XX_GPIO_LINE_G(i), dev_name(&pdev->dev));
  734. if (err)
  735. goto fail_gpio_g;
  736. }
  737. for (i = 0; i < 8; i++) {
  738. err = gpio_request(EP93XX_GPIO_LINE_H(i), dev_name(&pdev->dev));
  739. if (err)
  740. goto fail_gpio_h;
  741. }
  742. /* GPIO ports E[7:2], G[7:4] and H used by IDE */
  743. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_EONIDE |
  744. EP93XX_SYSCON_DEVCFG_GONIDE |
  745. EP93XX_SYSCON_DEVCFG_HONIDE);
  746. return 0;
  747. fail_gpio_h:
  748. for (--i; i >= 0; --i)
  749. gpio_free(EP93XX_GPIO_LINE_H(i));
  750. i = 8;
  751. fail_gpio_g:
  752. for (--i; i >= 4; --i)
  753. gpio_free(EP93XX_GPIO_LINE_G(i));
  754. i = 8;
  755. fail_gpio_e:
  756. for (--i; i >= 2; --i)
  757. gpio_free(EP93XX_GPIO_LINE_E(i));
  758. gpio_free(EP93XX_GPIO_LINE_EGPIO15);
  759. fail_egpio15:
  760. gpio_free(EP93XX_GPIO_LINE_EGPIO2);
  761. return err;
  762. }
  763. EXPORT_SYMBOL(ep93xx_ide_acquire_gpio);
  764. void ep93xx_ide_release_gpio(struct platform_device *pdev)
  765. {
  766. int i;
  767. for (i = 2; i < 8; i++)
  768. gpio_free(EP93XX_GPIO_LINE_E(i));
  769. for (i = 4; i < 8; i++)
  770. gpio_free(EP93XX_GPIO_LINE_G(i));
  771. for (i = 0; i < 8; i++)
  772. gpio_free(EP93XX_GPIO_LINE_H(i));
  773. gpio_free(EP93XX_GPIO_LINE_EGPIO15);
  774. gpio_free(EP93XX_GPIO_LINE_EGPIO2);
  775. /* GPIO ports E[7:2], G[7:4] and H used by GPIO */
  776. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_EONIDE |
  777. EP93XX_SYSCON_DEVCFG_GONIDE |
  778. EP93XX_SYSCON_DEVCFG_HONIDE);
  779. }
  780. EXPORT_SYMBOL(ep93xx_ide_release_gpio);
  781. /*************************************************************************
  782. * EP93xx Security peripheral
  783. *************************************************************************/
  784. /*
  785. * The Maverick Key is 256 bits of micro fuses blown at the factory during
  786. * manufacturing to uniquely identify a part.
  787. *
  788. * See: http://arm.cirrus.com/forum/viewtopic.php?t=486&highlight=maverick+key
  789. */
  790. #define EP93XX_SECURITY_REG(x) (EP93XX_SECURITY_BASE + (x))
  791. #define EP93XX_SECURITY_SECFLG EP93XX_SECURITY_REG(0x2400)
  792. #define EP93XX_SECURITY_FUSEFLG EP93XX_SECURITY_REG(0x2410)
  793. #define EP93XX_SECURITY_UNIQID EP93XX_SECURITY_REG(0x2440)
  794. #define EP93XX_SECURITY_UNIQCHK EP93XX_SECURITY_REG(0x2450)
  795. #define EP93XX_SECURITY_UNIQVAL EP93XX_SECURITY_REG(0x2460)
  796. #define EP93XX_SECURITY_SECID1 EP93XX_SECURITY_REG(0x2500)
  797. #define EP93XX_SECURITY_SECID2 EP93XX_SECURITY_REG(0x2504)
  798. #define EP93XX_SECURITY_SECCHK1 EP93XX_SECURITY_REG(0x2520)
  799. #define EP93XX_SECURITY_SECCHK2 EP93XX_SECURITY_REG(0x2524)
  800. #define EP93XX_SECURITY_UNIQID2 EP93XX_SECURITY_REG(0x2700)
  801. #define EP93XX_SECURITY_UNIQID3 EP93XX_SECURITY_REG(0x2704)
  802. #define EP93XX_SECURITY_UNIQID4 EP93XX_SECURITY_REG(0x2708)
  803. #define EP93XX_SECURITY_UNIQID5 EP93XX_SECURITY_REG(0x270c)
  804. static char ep93xx_soc_id[33];
  805. static const char __init *ep93xx_get_soc_id(void)
  806. {
  807. unsigned int id, id2, id3, id4, id5;
  808. if (__raw_readl(EP93XX_SECURITY_UNIQVAL) != 1)
  809. return "bad Hamming code";
  810. id = __raw_readl(EP93XX_SECURITY_UNIQID);
  811. id2 = __raw_readl(EP93XX_SECURITY_UNIQID2);
  812. id3 = __raw_readl(EP93XX_SECURITY_UNIQID3);
  813. id4 = __raw_readl(EP93XX_SECURITY_UNIQID4);
  814. id5 = __raw_readl(EP93XX_SECURITY_UNIQID5);
  815. if (id != id2)
  816. return "invalid";
  817. snprintf(ep93xx_soc_id, sizeof(ep93xx_soc_id),
  818. "%08x%08x%08x%08x", id2, id3, id4, id5);
  819. return ep93xx_soc_id;
  820. }
  821. static const char __init *ep93xx_get_soc_rev(void)
  822. {
  823. int rev = ep93xx_chip_revision();
  824. switch (rev) {
  825. case EP93XX_CHIP_REV_D0:
  826. return "D0";
  827. case EP93XX_CHIP_REV_D1:
  828. return "D1";
  829. case EP93XX_CHIP_REV_E0:
  830. return "E0";
  831. case EP93XX_CHIP_REV_E1:
  832. return "E1";
  833. case EP93XX_CHIP_REV_E2:
  834. return "E2";
  835. default:
  836. return "unknown";
  837. }
  838. }
  839. static const char __init *ep93xx_get_machine_name(void)
  840. {
  841. return kasprintf(GFP_KERNEL,"%s", machine_desc->name);
  842. }
  843. static struct device __init *ep93xx_init_soc(void)
  844. {
  845. struct soc_device_attribute *soc_dev_attr;
  846. struct soc_device *soc_dev;
  847. soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
  848. if (!soc_dev_attr)
  849. return NULL;
  850. soc_dev_attr->machine = ep93xx_get_machine_name();
  851. soc_dev_attr->family = "Cirrus Logic EP93xx";
  852. soc_dev_attr->revision = ep93xx_get_soc_rev();
  853. soc_dev_attr->soc_id = ep93xx_get_soc_id();
  854. soc_dev = soc_device_register(soc_dev_attr);
  855. if (IS_ERR(soc_dev)) {
  856. kfree(soc_dev_attr->machine);
  857. kfree(soc_dev_attr);
  858. return NULL;
  859. }
  860. return soc_device_to_device(soc_dev);
  861. }
  862. struct device __init *ep93xx_init_devices(void)
  863. {
  864. struct device *parent;
  865. /* Disallow access to MaverickCrunch initially */
  866. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_CPENA);
  867. /* Default all ports to GPIO */
  868. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS |
  869. EP93XX_SYSCON_DEVCFG_GONK |
  870. EP93XX_SYSCON_DEVCFG_EONIDE |
  871. EP93XX_SYSCON_DEVCFG_GONIDE |
  872. EP93XX_SYSCON_DEVCFG_HONIDE);
  873. parent = ep93xx_init_soc();
  874. /* Get the GPIO working early, other devices need it */
  875. platform_device_register(&ep93xx_gpio_device);
  876. amba_device_register(&uart1_device, &iomem_resource);
  877. amba_device_register(&uart2_device, &iomem_resource);
  878. amba_device_register(&uart3_device, &iomem_resource);
  879. platform_device_register(&ep93xx_rtc_device);
  880. platform_device_register(&ep93xx_ohci_device);
  881. platform_device_register(&ep93xx_wdt_device);
  882. gpio_led_register_device(-1, &ep93xx_led_data);
  883. return parent;
  884. }
  885. void ep93xx_restart(enum reboot_mode mode, const char *cmd)
  886. {
  887. /*
  888. * Set then clear the SWRST bit to initiate a software reset
  889. */
  890. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_SWRST);
  891. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_SWRST);
  892. while (1)
  893. ;
  894. }
  895. void __init ep93xx_init_late(void)
  896. {
  897. crunch_init();
  898. }