core.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/dma-mapping.h>
  21. #include <linux/timex.h>
  22. #include <linux/io.h>
  23. #include <linux/gpio.h>
  24. #include <linux/leds.h>
  25. #include <linux/termios.h>
  26. #include <linux/amba/bus.h>
  27. #include <linux/amba/serial.h>
  28. #include <linux/i2c.h>
  29. #include <linux/i2c-gpio.h>
  30. #include <mach/hardware.h>
  31. #include <mach/fb.h>
  32. #include <asm/mach/map.h>
  33. #include <asm/mach/time.h>
  34. #include <asm/mach/irq.h>
  35. #include <asm/hardware/vic.h>
  36. /*************************************************************************
  37. * Static I/O mappings that are needed for all EP93xx platforms
  38. *************************************************************************/
  39. static struct map_desc ep93xx_io_desc[] __initdata = {
  40. {
  41. .virtual = EP93XX_AHB_VIRT_BASE,
  42. .pfn = __phys_to_pfn(EP93XX_AHB_PHYS_BASE),
  43. .length = EP93XX_AHB_SIZE,
  44. .type = MT_DEVICE,
  45. }, {
  46. .virtual = EP93XX_APB_VIRT_BASE,
  47. .pfn = __phys_to_pfn(EP93XX_APB_PHYS_BASE),
  48. .length = EP93XX_APB_SIZE,
  49. .type = MT_DEVICE,
  50. },
  51. };
  52. void __init ep93xx_map_io(void)
  53. {
  54. iotable_init(ep93xx_io_desc, ARRAY_SIZE(ep93xx_io_desc));
  55. }
  56. /*************************************************************************
  57. * Timer handling for EP93xx
  58. *************************************************************************
  59. * The ep93xx has four internal timers. Timers 1, 2 (both 16 bit) and
  60. * 3 (32 bit) count down at 508 kHz, are self-reloading, and can generate
  61. * an interrupt on underflow. Timer 4 (40 bit) counts down at 983.04 kHz,
  62. * is free-running, and can't generate interrupts.
  63. *
  64. * The 508 kHz timers are ideal for use for the timer interrupt, as the
  65. * most common values of HZ divide 508 kHz nicely. We pick one of the 16
  66. * bit timers (timer 1) since we don't need more than 16 bits of reload
  67. * value as long as HZ >= 8.
  68. *
  69. * The higher clock rate of timer 4 makes it a better choice than the
  70. * other timers for use in gettimeoffset(), while the fact that it can't
  71. * generate interrupts means we don't have to worry about not being able
  72. * to use this timer for something else. We also use timer 4 for keeping
  73. * track of lost jiffies.
  74. */
  75. static unsigned int last_jiffy_time;
  76. #define TIMER4_TICKS_PER_JIFFY DIV_ROUND_CLOSEST(CLOCK_TICK_RATE, HZ)
  77. static irqreturn_t ep93xx_timer_interrupt(int irq, void *dev_id)
  78. {
  79. __raw_writel(1, EP93XX_TIMER1_CLEAR);
  80. while ((signed long)
  81. (__raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time)
  82. >= TIMER4_TICKS_PER_JIFFY) {
  83. last_jiffy_time += TIMER4_TICKS_PER_JIFFY;
  84. timer_tick();
  85. }
  86. return IRQ_HANDLED;
  87. }
  88. static struct irqaction ep93xx_timer_irq = {
  89. .name = "ep93xx timer",
  90. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  91. .handler = ep93xx_timer_interrupt,
  92. };
  93. static void __init ep93xx_timer_init(void)
  94. {
  95. /* Enable periodic HZ timer. */
  96. __raw_writel(0x48, EP93XX_TIMER1_CONTROL);
  97. __raw_writel((508469 / HZ) - 1, EP93XX_TIMER1_LOAD);
  98. __raw_writel(0xc8, EP93XX_TIMER1_CONTROL);
  99. /* Enable lost jiffy timer. */
  100. __raw_writel(0x100, EP93XX_TIMER4_VALUE_HIGH);
  101. setup_irq(IRQ_EP93XX_TIMER1, &ep93xx_timer_irq);
  102. }
  103. static unsigned long ep93xx_gettimeoffset(void)
  104. {
  105. int offset;
  106. offset = __raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time;
  107. /* Calculate (1000000 / 983040) * offset. */
  108. return offset + (53 * offset / 3072);
  109. }
  110. struct sys_timer ep93xx_timer = {
  111. .init = ep93xx_timer_init,
  112. .offset = ep93xx_gettimeoffset,
  113. };
  114. /*************************************************************************
  115. * GPIO handling for EP93xx
  116. *************************************************************************/
  117. static unsigned char gpio_int_unmasked[3];
  118. static unsigned char gpio_int_enabled[3];
  119. static unsigned char gpio_int_type1[3];
  120. static unsigned char gpio_int_type2[3];
  121. static unsigned char gpio_int_debounce[3];
  122. /* Port ordering is: A B F */
  123. static const u8 int_type1_register_offset[3] = { 0x90, 0xac, 0x4c };
  124. static const u8 int_type2_register_offset[3] = { 0x94, 0xb0, 0x50 };
  125. static const u8 eoi_register_offset[3] = { 0x98, 0xb4, 0x54 };
  126. static const u8 int_en_register_offset[3] = { 0x9c, 0xb8, 0x58 };
  127. static const u8 int_debounce_register_offset[3] = { 0xa8, 0xc4, 0x64 };
  128. void ep93xx_gpio_update_int_params(unsigned port)
  129. {
  130. BUG_ON(port > 2);
  131. __raw_writeb(0, EP93XX_GPIO_REG(int_en_register_offset[port]));
  132. __raw_writeb(gpio_int_type2[port],
  133. EP93XX_GPIO_REG(int_type2_register_offset[port]));
  134. __raw_writeb(gpio_int_type1[port],
  135. EP93XX_GPIO_REG(int_type1_register_offset[port]));
  136. __raw_writeb(gpio_int_unmasked[port] & gpio_int_enabled[port],
  137. EP93XX_GPIO_REG(int_en_register_offset[port]));
  138. }
  139. void ep93xx_gpio_int_mask(unsigned line)
  140. {
  141. gpio_int_unmasked[line >> 3] &= ~(1 << (line & 7));
  142. }
  143. void ep93xx_gpio_int_debounce(unsigned int irq, int enable)
  144. {
  145. int line = irq_to_gpio(irq);
  146. int port = line >> 3;
  147. int port_mask = 1 << (line & 7);
  148. if (enable)
  149. gpio_int_debounce[port] |= port_mask;
  150. else
  151. gpio_int_debounce[port] &= ~port_mask;
  152. __raw_writeb(gpio_int_debounce[port],
  153. EP93XX_GPIO_REG(int_debounce_register_offset[port]));
  154. }
  155. EXPORT_SYMBOL(ep93xx_gpio_int_debounce);
  156. /*************************************************************************
  157. * EP93xx IRQ handling
  158. *************************************************************************/
  159. static void ep93xx_gpio_ab_irq_handler(unsigned int irq, struct irq_desc *desc)
  160. {
  161. unsigned char status;
  162. int i;
  163. status = __raw_readb(EP93XX_GPIO_A_INT_STATUS);
  164. for (i = 0; i < 8; i++) {
  165. if (status & (1 << i)) {
  166. int gpio_irq = gpio_to_irq(EP93XX_GPIO_LINE_A(0)) + i;
  167. generic_handle_irq(gpio_irq);
  168. }
  169. }
  170. status = __raw_readb(EP93XX_GPIO_B_INT_STATUS);
  171. for (i = 0; i < 8; i++) {
  172. if (status & (1 << i)) {
  173. int gpio_irq = gpio_to_irq(EP93XX_GPIO_LINE_B(0)) + i;
  174. generic_handle_irq(gpio_irq);
  175. }
  176. }
  177. }
  178. static void ep93xx_gpio_f_irq_handler(unsigned int irq, struct irq_desc *desc)
  179. {
  180. /*
  181. * map discontiguous hw irq range to continous sw irq range:
  182. *
  183. * IRQ_EP93XX_GPIO{0..7}MUX -> gpio_to_irq(EP93XX_GPIO_LINE_F({0..7})
  184. */
  185. int port_f_idx = ((irq + 1) & 7) ^ 4; /* {19..22,47..50} -> {0..7} */
  186. int gpio_irq = gpio_to_irq(EP93XX_GPIO_LINE_F(0)) + port_f_idx;
  187. generic_handle_irq(gpio_irq);
  188. }
  189. static void ep93xx_gpio_irq_ack(unsigned int irq)
  190. {
  191. int line = irq_to_gpio(irq);
  192. int port = line >> 3;
  193. int port_mask = 1 << (line & 7);
  194. if ((irq_desc[irq].status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
  195. gpio_int_type2[port] ^= port_mask; /* switch edge direction */
  196. ep93xx_gpio_update_int_params(port);
  197. }
  198. __raw_writeb(port_mask, EP93XX_GPIO_REG(eoi_register_offset[port]));
  199. }
  200. static void ep93xx_gpio_irq_mask_ack(unsigned int irq)
  201. {
  202. int line = irq_to_gpio(irq);
  203. int port = line >> 3;
  204. int port_mask = 1 << (line & 7);
  205. if ((irq_desc[irq].status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH)
  206. gpio_int_type2[port] ^= port_mask; /* switch edge direction */
  207. gpio_int_unmasked[port] &= ~port_mask;
  208. ep93xx_gpio_update_int_params(port);
  209. __raw_writeb(port_mask, EP93XX_GPIO_REG(eoi_register_offset[port]));
  210. }
  211. static void ep93xx_gpio_irq_mask(unsigned int irq)
  212. {
  213. int line = irq_to_gpio(irq);
  214. int port = line >> 3;
  215. gpio_int_unmasked[port] &= ~(1 << (line & 7));
  216. ep93xx_gpio_update_int_params(port);
  217. }
  218. static void ep93xx_gpio_irq_unmask(unsigned int irq)
  219. {
  220. int line = irq_to_gpio(irq);
  221. int port = line >> 3;
  222. gpio_int_unmasked[port] |= 1 << (line & 7);
  223. ep93xx_gpio_update_int_params(port);
  224. }
  225. /*
  226. * gpio_int_type1 controls whether the interrupt is level (0) or
  227. * edge (1) triggered, while gpio_int_type2 controls whether it
  228. * triggers on low/falling (0) or high/rising (1).
  229. */
  230. static int ep93xx_gpio_irq_type(unsigned int irq, unsigned int type)
  231. {
  232. struct irq_desc *desc = irq_desc + irq;
  233. const int gpio = irq_to_gpio(irq);
  234. const int port = gpio >> 3;
  235. const int port_mask = 1 << (gpio & 7);
  236. gpio_direction_input(gpio);
  237. switch (type) {
  238. case IRQ_TYPE_EDGE_RISING:
  239. gpio_int_type1[port] |= port_mask;
  240. gpio_int_type2[port] |= port_mask;
  241. desc->handle_irq = handle_edge_irq;
  242. break;
  243. case IRQ_TYPE_EDGE_FALLING:
  244. gpio_int_type1[port] |= port_mask;
  245. gpio_int_type2[port] &= ~port_mask;
  246. desc->handle_irq = handle_edge_irq;
  247. break;
  248. case IRQ_TYPE_LEVEL_HIGH:
  249. gpio_int_type1[port] &= ~port_mask;
  250. gpio_int_type2[port] |= port_mask;
  251. desc->handle_irq = handle_level_irq;
  252. break;
  253. case IRQ_TYPE_LEVEL_LOW:
  254. gpio_int_type1[port] &= ~port_mask;
  255. gpio_int_type2[port] &= ~port_mask;
  256. desc->handle_irq = handle_level_irq;
  257. break;
  258. case IRQ_TYPE_EDGE_BOTH:
  259. gpio_int_type1[port] |= port_mask;
  260. /* set initial polarity based on current input level */
  261. if (gpio_get_value(gpio))
  262. gpio_int_type2[port] &= ~port_mask; /* falling */
  263. else
  264. gpio_int_type2[port] |= port_mask; /* rising */
  265. desc->handle_irq = handle_edge_irq;
  266. break;
  267. default:
  268. pr_err("ep93xx: failed to set irq type %d for gpio %d\n",
  269. type, gpio);
  270. return -EINVAL;
  271. }
  272. gpio_int_enabled[port] |= port_mask;
  273. desc->status &= ~IRQ_TYPE_SENSE_MASK;
  274. desc->status |= type & IRQ_TYPE_SENSE_MASK;
  275. ep93xx_gpio_update_int_params(port);
  276. return 0;
  277. }
  278. static struct irq_chip ep93xx_gpio_irq_chip = {
  279. .name = "GPIO",
  280. .ack = ep93xx_gpio_irq_ack,
  281. .mask_ack = ep93xx_gpio_irq_mask_ack,
  282. .mask = ep93xx_gpio_irq_mask,
  283. .unmask = ep93xx_gpio_irq_unmask,
  284. .set_type = ep93xx_gpio_irq_type,
  285. };
  286. void __init ep93xx_init_irq(void)
  287. {
  288. int gpio_irq;
  289. vic_init(EP93XX_VIC1_BASE, 0, EP93XX_VIC1_VALID_IRQ_MASK, 0);
  290. vic_init(EP93XX_VIC2_BASE, 32, EP93XX_VIC2_VALID_IRQ_MASK, 0);
  291. for (gpio_irq = gpio_to_irq(0);
  292. gpio_irq <= gpio_to_irq(EP93XX_GPIO_LINE_MAX_IRQ); ++gpio_irq) {
  293. set_irq_chip(gpio_irq, &ep93xx_gpio_irq_chip);
  294. set_irq_handler(gpio_irq, handle_level_irq);
  295. set_irq_flags(gpio_irq, IRQF_VALID);
  296. }
  297. set_irq_chained_handler(IRQ_EP93XX_GPIO_AB, ep93xx_gpio_ab_irq_handler);
  298. set_irq_chained_handler(IRQ_EP93XX_GPIO0MUX, ep93xx_gpio_f_irq_handler);
  299. set_irq_chained_handler(IRQ_EP93XX_GPIO1MUX, ep93xx_gpio_f_irq_handler);
  300. set_irq_chained_handler(IRQ_EP93XX_GPIO2MUX, ep93xx_gpio_f_irq_handler);
  301. set_irq_chained_handler(IRQ_EP93XX_GPIO3MUX, ep93xx_gpio_f_irq_handler);
  302. set_irq_chained_handler(IRQ_EP93XX_GPIO4MUX, ep93xx_gpio_f_irq_handler);
  303. set_irq_chained_handler(IRQ_EP93XX_GPIO5MUX, ep93xx_gpio_f_irq_handler);
  304. set_irq_chained_handler(IRQ_EP93XX_GPIO6MUX, ep93xx_gpio_f_irq_handler);
  305. set_irq_chained_handler(IRQ_EP93XX_GPIO7MUX, ep93xx_gpio_f_irq_handler);
  306. }
  307. /*************************************************************************
  308. * EP93xx System Controller Software Locked register handling
  309. *************************************************************************/
  310. /*
  311. * syscon_swlock prevents anything else from writing to the syscon
  312. * block while a software locked register is being written.
  313. */
  314. static DEFINE_SPINLOCK(syscon_swlock);
  315. void ep93xx_syscon_swlocked_write(unsigned int val, void __iomem *reg)
  316. {
  317. unsigned long flags;
  318. spin_lock_irqsave(&syscon_swlock, flags);
  319. __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
  320. __raw_writel(val, reg);
  321. spin_unlock_irqrestore(&syscon_swlock, flags);
  322. }
  323. EXPORT_SYMBOL(ep93xx_syscon_swlocked_write);
  324. void ep93xx_devcfg_set_clear(unsigned int set_bits, unsigned int clear_bits)
  325. {
  326. unsigned long flags;
  327. unsigned int val;
  328. spin_lock_irqsave(&syscon_swlock, flags);
  329. val = __raw_readl(EP93XX_SYSCON_DEVCFG);
  330. val |= set_bits;
  331. val &= ~clear_bits;
  332. __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
  333. __raw_writel(val, EP93XX_SYSCON_DEVCFG);
  334. spin_unlock_irqrestore(&syscon_swlock, flags);
  335. }
  336. EXPORT_SYMBOL(ep93xx_devcfg_set_clear);
  337. /*************************************************************************
  338. * EP93xx peripheral handling
  339. *************************************************************************/
  340. #define EP93XX_UART_MCR_OFFSET (0x0100)
  341. static void ep93xx_uart_set_mctrl(struct amba_device *dev,
  342. void __iomem *base, unsigned int mctrl)
  343. {
  344. unsigned int mcr;
  345. mcr = 0;
  346. if (!(mctrl & TIOCM_RTS))
  347. mcr |= 2;
  348. if (!(mctrl & TIOCM_DTR))
  349. mcr |= 1;
  350. __raw_writel(mcr, base + EP93XX_UART_MCR_OFFSET);
  351. }
  352. static struct amba_pl010_data ep93xx_uart_data = {
  353. .set_mctrl = ep93xx_uart_set_mctrl,
  354. };
  355. static struct amba_device uart1_device = {
  356. .dev = {
  357. .init_name = "apb:uart1",
  358. .platform_data = &ep93xx_uart_data,
  359. },
  360. .res = {
  361. .start = EP93XX_UART1_PHYS_BASE,
  362. .end = EP93XX_UART1_PHYS_BASE + 0x0fff,
  363. .flags = IORESOURCE_MEM,
  364. },
  365. .irq = { IRQ_EP93XX_UART1, NO_IRQ },
  366. .periphid = 0x00041010,
  367. };
  368. static struct amba_device uart2_device = {
  369. .dev = {
  370. .init_name = "apb:uart2",
  371. .platform_data = &ep93xx_uart_data,
  372. },
  373. .res = {
  374. .start = EP93XX_UART2_PHYS_BASE,
  375. .end = EP93XX_UART2_PHYS_BASE + 0x0fff,
  376. .flags = IORESOURCE_MEM,
  377. },
  378. .irq = { IRQ_EP93XX_UART2, NO_IRQ },
  379. .periphid = 0x00041010,
  380. };
  381. static struct amba_device uart3_device = {
  382. .dev = {
  383. .init_name = "apb:uart3",
  384. .platform_data = &ep93xx_uart_data,
  385. },
  386. .res = {
  387. .start = EP93XX_UART3_PHYS_BASE,
  388. .end = EP93XX_UART3_PHYS_BASE + 0x0fff,
  389. .flags = IORESOURCE_MEM,
  390. },
  391. .irq = { IRQ_EP93XX_UART3, NO_IRQ },
  392. .periphid = 0x00041010,
  393. };
  394. static struct resource ep93xx_rtc_resource[] = {
  395. {
  396. .start = EP93XX_RTC_PHYS_BASE,
  397. .end = EP93XX_RTC_PHYS_BASE + 0x10c - 1,
  398. .flags = IORESOURCE_MEM,
  399. },
  400. };
  401. static struct platform_device ep93xx_rtc_device = {
  402. .name = "ep93xx-rtc",
  403. .id = -1,
  404. .num_resources = ARRAY_SIZE(ep93xx_rtc_resource),
  405. .resource = ep93xx_rtc_resource,
  406. };
  407. static struct resource ep93xx_ohci_resources[] = {
  408. [0] = {
  409. .start = EP93XX_USB_PHYS_BASE,
  410. .end = EP93XX_USB_PHYS_BASE + 0x0fff,
  411. .flags = IORESOURCE_MEM,
  412. },
  413. [1] = {
  414. .start = IRQ_EP93XX_USB,
  415. .end = IRQ_EP93XX_USB,
  416. .flags = IORESOURCE_IRQ,
  417. },
  418. };
  419. static struct platform_device ep93xx_ohci_device = {
  420. .name = "ep93xx-ohci",
  421. .id = -1,
  422. .dev = {
  423. .dma_mask = &ep93xx_ohci_device.dev.coherent_dma_mask,
  424. .coherent_dma_mask = DMA_BIT_MASK(32),
  425. },
  426. .num_resources = ARRAY_SIZE(ep93xx_ohci_resources),
  427. .resource = ep93xx_ohci_resources,
  428. };
  429. static struct ep93xx_eth_data ep93xx_eth_data;
  430. static struct resource ep93xx_eth_resource[] = {
  431. {
  432. .start = EP93XX_ETHERNET_PHYS_BASE,
  433. .end = EP93XX_ETHERNET_PHYS_BASE + 0xffff,
  434. .flags = IORESOURCE_MEM,
  435. }, {
  436. .start = IRQ_EP93XX_ETHERNET,
  437. .end = IRQ_EP93XX_ETHERNET,
  438. .flags = IORESOURCE_IRQ,
  439. }
  440. };
  441. static struct platform_device ep93xx_eth_device = {
  442. .name = "ep93xx-eth",
  443. .id = -1,
  444. .dev = {
  445. .platform_data = &ep93xx_eth_data,
  446. },
  447. .num_resources = ARRAY_SIZE(ep93xx_eth_resource),
  448. .resource = ep93xx_eth_resource,
  449. };
  450. void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
  451. {
  452. if (copy_addr)
  453. memcpy_fromio(data->dev_addr, EP93XX_ETHERNET_BASE + 0x50, 6);
  454. ep93xx_eth_data = *data;
  455. platform_device_register(&ep93xx_eth_device);
  456. }
  457. /*************************************************************************
  458. * EP93xx i2c peripheral handling
  459. *************************************************************************/
  460. static struct i2c_gpio_platform_data ep93xx_i2c_data;
  461. static struct platform_device ep93xx_i2c_device = {
  462. .name = "i2c-gpio",
  463. .id = 0,
  464. .dev.platform_data = &ep93xx_i2c_data,
  465. };
  466. void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data,
  467. struct i2c_board_info *devices, int num)
  468. {
  469. /*
  470. * Set the EEPROM interface pin drive type control.
  471. * Defines the driver type for the EECLK and EEDAT pins as either
  472. * open drain, which will require an external pull-up, or a normal
  473. * CMOS driver.
  474. */
  475. if (data->sda_is_open_drain && data->sda_pin != EP93XX_GPIO_LINE_EEDAT)
  476. pr_warning("ep93xx: sda != EEDAT, open drain has no effect\n");
  477. if (data->scl_is_open_drain && data->scl_pin != EP93XX_GPIO_LINE_EECLK)
  478. pr_warning("ep93xx: scl != EECLK, open drain has no effect\n");
  479. __raw_writel((data->sda_is_open_drain << 1) |
  480. (data->scl_is_open_drain << 0),
  481. EP93XX_GPIO_EEDRIVE);
  482. ep93xx_i2c_data = *data;
  483. i2c_register_board_info(0, devices, num);
  484. platform_device_register(&ep93xx_i2c_device);
  485. }
  486. /*************************************************************************
  487. * EP93xx LEDs
  488. *************************************************************************/
  489. static struct gpio_led ep93xx_led_pins[] = {
  490. {
  491. .name = "platform:grled",
  492. .gpio = EP93XX_GPIO_LINE_GRLED,
  493. }, {
  494. .name = "platform:rdled",
  495. .gpio = EP93XX_GPIO_LINE_RDLED,
  496. },
  497. };
  498. static struct gpio_led_platform_data ep93xx_led_data = {
  499. .num_leds = ARRAY_SIZE(ep93xx_led_pins),
  500. .leds = ep93xx_led_pins,
  501. };
  502. static struct platform_device ep93xx_leds = {
  503. .name = "leds-gpio",
  504. .id = -1,
  505. .dev = {
  506. .platform_data = &ep93xx_led_data,
  507. },
  508. };
  509. /*************************************************************************
  510. * EP93xx pwm peripheral handling
  511. *************************************************************************/
  512. static struct resource ep93xx_pwm0_resource[] = {
  513. {
  514. .start = EP93XX_PWM_PHYS_BASE,
  515. .end = EP93XX_PWM_PHYS_BASE + 0x10 - 1,
  516. .flags = IORESOURCE_MEM,
  517. },
  518. };
  519. static struct platform_device ep93xx_pwm0_device = {
  520. .name = "ep93xx-pwm",
  521. .id = 0,
  522. .num_resources = ARRAY_SIZE(ep93xx_pwm0_resource),
  523. .resource = ep93xx_pwm0_resource,
  524. };
  525. static struct resource ep93xx_pwm1_resource[] = {
  526. {
  527. .start = EP93XX_PWM_PHYS_BASE + 0x20,
  528. .end = EP93XX_PWM_PHYS_BASE + 0x30 - 1,
  529. .flags = IORESOURCE_MEM,
  530. },
  531. };
  532. static struct platform_device ep93xx_pwm1_device = {
  533. .name = "ep93xx-pwm",
  534. .id = 1,
  535. .num_resources = ARRAY_SIZE(ep93xx_pwm1_resource),
  536. .resource = ep93xx_pwm1_resource,
  537. };
  538. void __init ep93xx_register_pwm(int pwm0, int pwm1)
  539. {
  540. if (pwm0)
  541. platform_device_register(&ep93xx_pwm0_device);
  542. /* NOTE: EP9307 does not have PWMOUT1 (pin EGPIO14) */
  543. if (pwm1)
  544. platform_device_register(&ep93xx_pwm1_device);
  545. }
  546. int ep93xx_pwm_acquire_gpio(struct platform_device *pdev)
  547. {
  548. int err;
  549. if (pdev->id == 0) {
  550. err = 0;
  551. } else if (pdev->id == 1) {
  552. err = gpio_request(EP93XX_GPIO_LINE_EGPIO14,
  553. dev_name(&pdev->dev));
  554. if (err)
  555. return err;
  556. err = gpio_direction_output(EP93XX_GPIO_LINE_EGPIO14, 0);
  557. if (err)
  558. goto fail;
  559. /* PWM 1 output on EGPIO[14] */
  560. ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_PONG);
  561. } else {
  562. err = -ENODEV;
  563. }
  564. return err;
  565. fail:
  566. gpio_free(EP93XX_GPIO_LINE_EGPIO14);
  567. return err;
  568. }
  569. EXPORT_SYMBOL(ep93xx_pwm_acquire_gpio);
  570. void ep93xx_pwm_release_gpio(struct platform_device *pdev)
  571. {
  572. if (pdev->id == 1) {
  573. gpio_direction_input(EP93XX_GPIO_LINE_EGPIO14);
  574. gpio_free(EP93XX_GPIO_LINE_EGPIO14);
  575. /* EGPIO[14] used for GPIO */
  576. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_PONG);
  577. }
  578. }
  579. EXPORT_SYMBOL(ep93xx_pwm_release_gpio);
  580. /*************************************************************************
  581. * EP93xx video peripheral handling
  582. *************************************************************************/
  583. static struct ep93xxfb_mach_info ep93xxfb_data;
  584. static struct resource ep93xx_fb_resource[] = {
  585. {
  586. .start = EP93XX_RASTER_PHYS_BASE,
  587. .end = EP93XX_RASTER_PHYS_BASE + 0x800 - 1,
  588. .flags = IORESOURCE_MEM,
  589. },
  590. };
  591. static struct platform_device ep93xx_fb_device = {
  592. .name = "ep93xx-fb",
  593. .id = -1,
  594. .dev = {
  595. .platform_data = &ep93xxfb_data,
  596. .coherent_dma_mask = DMA_BIT_MASK(32),
  597. .dma_mask = &ep93xx_fb_device.dev.coherent_dma_mask,
  598. },
  599. .num_resources = ARRAY_SIZE(ep93xx_fb_resource),
  600. .resource = ep93xx_fb_resource,
  601. };
  602. void __init ep93xx_register_fb(struct ep93xxfb_mach_info *data)
  603. {
  604. ep93xxfb_data = *data;
  605. platform_device_register(&ep93xx_fb_device);
  606. }
  607. extern void ep93xx_gpio_init(void);
  608. void __init ep93xx_init_devices(void)
  609. {
  610. /* Disallow access to MaverickCrunch initially */
  611. ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_CPENA);
  612. ep93xx_gpio_init();
  613. amba_device_register(&uart1_device, &iomem_resource);
  614. amba_device_register(&uart2_device, &iomem_resource);
  615. amba_device_register(&uart3_device, &iomem_resource);
  616. platform_device_register(&ep93xx_rtc_device);
  617. platform_device_register(&ep93xx_ohci_device);
  618. platform_device_register(&ep93xx_leds);
  619. }