core.c 22 KB

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