/kern_2.6.32/arch/arm/mach-ixp4xx/common.c

http://omnia2droid.googlecode.com/ · C · 493 lines · 348 code · 77 blank · 68 comment · 26 complexity · 499ee2d7eb9bad58b4ee24daf4fccc8b MD5 · raw file

  1. /*
  2. * arch/arm/mach-ixp4xx/common.c
  3. *
  4. * Generic code shared across all IXP4XX platforms
  5. *
  6. * Maintainer: Deepak Saxena <dsaxena@plexity.net>
  7. *
  8. * Copyright 2002 (c) Intel Corporation
  9. * Copyright 2003-2004 (c) MontaVista, Software, Inc.
  10. *
  11. * This file is licensed under the terms of the GNU General Public
  12. * License version 2. This program is licensed "as is" without any
  13. * warranty of any kind, whether express or implied.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/mm.h>
  17. #include <linux/init.h>
  18. #include <linux/serial.h>
  19. #include <linux/sched.h>
  20. #include <linux/tty.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/serial_core.h>
  23. #include <linux/bootmem.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/bitops.h>
  26. #include <linux/time.h>
  27. #include <linux/timex.h>
  28. #include <linux/clocksource.h>
  29. #include <linux/clockchips.h>
  30. #include <linux/io.h>
  31. #include <mach/udc.h>
  32. #include <mach/hardware.h>
  33. #include <asm/uaccess.h>
  34. #include <asm/pgtable.h>
  35. #include <asm/page.h>
  36. #include <asm/irq.h>
  37. #include <asm/mach/map.h>
  38. #include <asm/mach/irq.h>
  39. #include <asm/mach/time.h>
  40. static void __init ixp4xx_clocksource_init(void);
  41. static void __init ixp4xx_clockevent_init(void);
  42. static struct clock_event_device clockevent_ixp4xx;
  43. /*************************************************************************
  44. * IXP4xx chipset I/O mapping
  45. *************************************************************************/
  46. static struct map_desc ixp4xx_io_desc[] __initdata = {
  47. { /* UART, Interrupt ctrl, GPIO, timers, NPEs, MACs, USB .... */
  48. .virtual = IXP4XX_PERIPHERAL_BASE_VIRT,
  49. .pfn = __phys_to_pfn(IXP4XX_PERIPHERAL_BASE_PHYS),
  50. .length = IXP4XX_PERIPHERAL_REGION_SIZE,
  51. .type = MT_DEVICE
  52. }, { /* Expansion Bus Config Registers */
  53. .virtual = IXP4XX_EXP_CFG_BASE_VIRT,
  54. .pfn = __phys_to_pfn(IXP4XX_EXP_CFG_BASE_PHYS),
  55. .length = IXP4XX_EXP_CFG_REGION_SIZE,
  56. .type = MT_DEVICE
  57. }, { /* PCI Registers */
  58. .virtual = IXP4XX_PCI_CFG_BASE_VIRT,
  59. .pfn = __phys_to_pfn(IXP4XX_PCI_CFG_BASE_PHYS),
  60. .length = IXP4XX_PCI_CFG_REGION_SIZE,
  61. .type = MT_DEVICE
  62. },
  63. #ifdef CONFIG_DEBUG_LL
  64. { /* Debug UART mapping */
  65. .virtual = IXP4XX_DEBUG_UART_BASE_VIRT,
  66. .pfn = __phys_to_pfn(IXP4XX_DEBUG_UART_BASE_PHYS),
  67. .length = IXP4XX_DEBUG_UART_REGION_SIZE,
  68. .type = MT_DEVICE
  69. }
  70. #endif
  71. };
  72. void __init ixp4xx_map_io(void)
  73. {
  74. iotable_init(ixp4xx_io_desc, ARRAY_SIZE(ixp4xx_io_desc));
  75. }
  76. /*************************************************************************
  77. * IXP4xx chipset IRQ handling
  78. *
  79. * TODO: GPIO IRQs should be marked invalid until the user of the IRQ
  80. * (be it PCI or something else) configures that GPIO line
  81. * as an IRQ.
  82. **************************************************************************/
  83. enum ixp4xx_irq_type {
  84. IXP4XX_IRQ_LEVEL, IXP4XX_IRQ_EDGE
  85. };
  86. /* Each bit represents an IRQ: 1: edge-triggered, 0: level triggered */
  87. static unsigned long long ixp4xx_irq_edge = 0;
  88. /*
  89. * IRQ -> GPIO mapping table
  90. */
  91. static signed char irq2gpio[32] = {
  92. -1, -1, -1, -1, -1, -1, 0, 1,
  93. -1, -1, -1, -1, -1, -1, -1, -1,
  94. -1, -1, -1, 2, 3, 4, 5, 6,
  95. 7, 8, 9, 10, 11, 12, -1, -1,
  96. };
  97. int gpio_to_irq(int gpio)
  98. {
  99. int irq;
  100. for (irq = 0; irq < 32; irq++) {
  101. if (irq2gpio[irq] == gpio)
  102. return irq;
  103. }
  104. return -EINVAL;
  105. }
  106. EXPORT_SYMBOL(gpio_to_irq);
  107. int irq_to_gpio(int irq)
  108. {
  109. int gpio = (irq < 32) ? irq2gpio[irq] : -EINVAL;
  110. if (gpio == -1)
  111. return -EINVAL;
  112. return gpio;
  113. }
  114. EXPORT_SYMBOL(irq_to_gpio);
  115. static int ixp4xx_set_irq_type(unsigned int irq, unsigned int type)
  116. {
  117. int line = irq2gpio[irq];
  118. u32 int_style;
  119. enum ixp4xx_irq_type irq_type;
  120. volatile u32 *int_reg;
  121. /*
  122. * Only for GPIO IRQs
  123. */
  124. if (line < 0)
  125. return -EINVAL;
  126. switch (type){
  127. case IRQ_TYPE_EDGE_BOTH:
  128. int_style = IXP4XX_GPIO_STYLE_TRANSITIONAL;
  129. irq_type = IXP4XX_IRQ_EDGE;
  130. break;
  131. case IRQ_TYPE_EDGE_RISING:
  132. int_style = IXP4XX_GPIO_STYLE_RISING_EDGE;
  133. irq_type = IXP4XX_IRQ_EDGE;
  134. break;
  135. case IRQ_TYPE_EDGE_FALLING:
  136. int_style = IXP4XX_GPIO_STYLE_FALLING_EDGE;
  137. irq_type = IXP4XX_IRQ_EDGE;
  138. break;
  139. case IRQ_TYPE_LEVEL_HIGH:
  140. int_style = IXP4XX_GPIO_STYLE_ACTIVE_HIGH;
  141. irq_type = IXP4XX_IRQ_LEVEL;
  142. break;
  143. case IRQ_TYPE_LEVEL_LOW:
  144. int_style = IXP4XX_GPIO_STYLE_ACTIVE_LOW;
  145. irq_type = IXP4XX_IRQ_LEVEL;
  146. break;
  147. default:
  148. return -EINVAL;
  149. }
  150. if (irq_type == IXP4XX_IRQ_EDGE)
  151. ixp4xx_irq_edge |= (1 << irq);
  152. else
  153. ixp4xx_irq_edge &= ~(1 << irq);
  154. if (line >= 8) { /* pins 8-15 */
  155. line -= 8;
  156. int_reg = IXP4XX_GPIO_GPIT2R;
  157. } else { /* pins 0-7 */
  158. int_reg = IXP4XX_GPIO_GPIT1R;
  159. }
  160. /* Clear the style for the appropriate pin */
  161. *int_reg &= ~(IXP4XX_GPIO_STYLE_CLEAR <<
  162. (line * IXP4XX_GPIO_STYLE_SIZE));
  163. *IXP4XX_GPIO_GPISR = (1 << line);
  164. /* Set the new style */
  165. *int_reg |= (int_style << (line * IXP4XX_GPIO_STYLE_SIZE));
  166. /* Configure the line as an input */
  167. gpio_line_config(irq2gpio[irq], IXP4XX_GPIO_IN);
  168. return 0;
  169. }
  170. static void ixp4xx_irq_mask(unsigned int irq)
  171. {
  172. if ((cpu_is_ixp46x() || cpu_is_ixp43x()) && irq >= 32)
  173. *IXP4XX_ICMR2 &= ~(1 << (irq - 32));
  174. else
  175. *IXP4XX_ICMR &= ~(1 << irq);
  176. }
  177. static void ixp4xx_irq_ack(unsigned int irq)
  178. {
  179. int line = (irq < 32) ? irq2gpio[irq] : -1;
  180. if (line >= 0)
  181. *IXP4XX_GPIO_GPISR = (1 << line);
  182. }
  183. /*
  184. * Level triggered interrupts on GPIO lines can only be cleared when the
  185. * interrupt condition disappears.
  186. */
  187. static void ixp4xx_irq_unmask(unsigned int irq)
  188. {
  189. if (!(ixp4xx_irq_edge & (1 << irq)))
  190. ixp4xx_irq_ack(irq);
  191. if ((cpu_is_ixp46x() || cpu_is_ixp43x()) && irq >= 32)
  192. *IXP4XX_ICMR2 |= (1 << (irq - 32));
  193. else
  194. *IXP4XX_ICMR |= (1 << irq);
  195. }
  196. static struct irq_chip ixp4xx_irq_chip = {
  197. .name = "IXP4xx",
  198. .ack = ixp4xx_irq_ack,
  199. .mask = ixp4xx_irq_mask,
  200. .unmask = ixp4xx_irq_unmask,
  201. .set_type = ixp4xx_set_irq_type,
  202. };
  203. void __init ixp4xx_init_irq(void)
  204. {
  205. int i = 0;
  206. /* Route all sources to IRQ instead of FIQ */
  207. *IXP4XX_ICLR = 0x0;
  208. /* Disable all interrupt */
  209. *IXP4XX_ICMR = 0x0;
  210. if (cpu_is_ixp46x() || cpu_is_ixp43x()) {
  211. /* Route upper 32 sources to IRQ instead of FIQ */
  212. *IXP4XX_ICLR2 = 0x00;
  213. /* Disable upper 32 interrupts */
  214. *IXP4XX_ICMR2 = 0x00;
  215. }
  216. /* Default to all level triggered */
  217. for(i = 0; i < NR_IRQS; i++) {
  218. set_irq_chip(i, &ixp4xx_irq_chip);
  219. set_irq_handler(i, handle_level_irq);
  220. set_irq_flags(i, IRQF_VALID);
  221. }
  222. }
  223. /*************************************************************************
  224. * IXP4xx timer tick
  225. * We use OS timer1 on the CPU for the timer tick and the timestamp
  226. * counter as a source of real clock ticks to account for missed jiffies.
  227. *************************************************************************/
  228. static irqreturn_t ixp4xx_timer_interrupt(int irq, void *dev_id)
  229. {
  230. struct clock_event_device *evt = dev_id;
  231. /* Clear Pending Interrupt by writing '1' to it */
  232. *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
  233. evt->event_handler(evt);
  234. return IRQ_HANDLED;
  235. }
  236. static struct irqaction ixp4xx_timer_irq = {
  237. .name = "timer1",
  238. .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  239. .handler = ixp4xx_timer_interrupt,
  240. .dev_id = &clockevent_ixp4xx,
  241. };
  242. void __init ixp4xx_timer_init(void)
  243. {
  244. /* Reset/disable counter */
  245. *IXP4XX_OSRT1 = 0;
  246. /* Clear Pending Interrupt by writing '1' to it */
  247. *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
  248. /* Reset time-stamp counter */
  249. *IXP4XX_OSTS = 0;
  250. /* Connect the interrupt handler and enable the interrupt */
  251. setup_irq(IRQ_IXP4XX_TIMER1, &ixp4xx_timer_irq);
  252. ixp4xx_clocksource_init();
  253. ixp4xx_clockevent_init();
  254. }
  255. struct sys_timer ixp4xx_timer = {
  256. .init = ixp4xx_timer_init,
  257. };
  258. static struct pxa2xx_udc_mach_info ixp4xx_udc_info;
  259. void __init ixp4xx_set_udc_info(struct pxa2xx_udc_mach_info *info)
  260. {
  261. memcpy(&ixp4xx_udc_info, info, sizeof *info);
  262. }
  263. static struct resource ixp4xx_udc_resources[] = {
  264. [0] = {
  265. .start = 0xc800b000,
  266. .end = 0xc800bfff,
  267. .flags = IORESOURCE_MEM,
  268. },
  269. [1] = {
  270. .start = IRQ_IXP4XX_USB,
  271. .end = IRQ_IXP4XX_USB,
  272. .flags = IORESOURCE_IRQ,
  273. },
  274. };
  275. /*
  276. * USB device controller. The IXP4xx uses the same controller as PXA25X,
  277. * so we just use the same device.
  278. */
  279. static struct platform_device ixp4xx_udc_device = {
  280. .name = "pxa25x-udc",
  281. .id = -1,
  282. .num_resources = 2,
  283. .resource = ixp4xx_udc_resources,
  284. .dev = {
  285. .platform_data = &ixp4xx_udc_info,
  286. },
  287. };
  288. static struct platform_device *ixp4xx_devices[] __initdata = {
  289. &ixp4xx_udc_device,
  290. };
  291. static struct resource ixp46x_i2c_resources[] = {
  292. [0] = {
  293. .start = 0xc8011000,
  294. .end = 0xc801101c,
  295. .flags = IORESOURCE_MEM,
  296. },
  297. [1] = {
  298. .start = IRQ_IXP4XX_I2C,
  299. .end = IRQ_IXP4XX_I2C,
  300. .flags = IORESOURCE_IRQ
  301. }
  302. };
  303. /*
  304. * I2C controller. The IXP46x uses the same block as the IOP3xx, so
  305. * we just use the same device name.
  306. */
  307. static struct platform_device ixp46x_i2c_controller = {
  308. .name = "IOP3xx-I2C",
  309. .id = 0,
  310. .num_resources = 2,
  311. .resource = ixp46x_i2c_resources
  312. };
  313. static struct platform_device *ixp46x_devices[] __initdata = {
  314. &ixp46x_i2c_controller
  315. };
  316. unsigned long ixp4xx_exp_bus_size;
  317. EXPORT_SYMBOL(ixp4xx_exp_bus_size);
  318. void __init ixp4xx_sys_init(void)
  319. {
  320. ixp4xx_exp_bus_size = SZ_16M;
  321. platform_add_devices(ixp4xx_devices, ARRAY_SIZE(ixp4xx_devices));
  322. if (cpu_is_ixp46x()) {
  323. int region;
  324. platform_add_devices(ixp46x_devices,
  325. ARRAY_SIZE(ixp46x_devices));
  326. for (region = 0; region < 7; region++) {
  327. if((*(IXP4XX_EXP_REG(0x4 * region)) & 0x200)) {
  328. ixp4xx_exp_bus_size = SZ_32M;
  329. break;
  330. }
  331. }
  332. }
  333. printk("IXP4xx: Using %luMiB expansion bus window size\n",
  334. ixp4xx_exp_bus_size >> 20);
  335. }
  336. /*
  337. * clocksource
  338. */
  339. static cycle_t ixp4xx_get_cycles(struct clocksource *cs)
  340. {
  341. return *IXP4XX_OSTS;
  342. }
  343. static struct clocksource clocksource_ixp4xx = {
  344. .name = "OSTS",
  345. .rating = 200,
  346. .read = ixp4xx_get_cycles,
  347. .mask = CLOCKSOURCE_MASK(32),
  348. .shift = 20,
  349. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  350. };
  351. unsigned long ixp4xx_timer_freq = FREQ;
  352. EXPORT_SYMBOL(ixp4xx_timer_freq);
  353. static void __init ixp4xx_clocksource_init(void)
  354. {
  355. clocksource_ixp4xx.mult =
  356. clocksource_hz2mult(ixp4xx_timer_freq,
  357. clocksource_ixp4xx.shift);
  358. clocksource_register(&clocksource_ixp4xx);
  359. }
  360. /*
  361. * clockevents
  362. */
  363. static int ixp4xx_set_next_event(unsigned long evt,
  364. struct clock_event_device *unused)
  365. {
  366. unsigned long opts = *IXP4XX_OSRT1 & IXP4XX_OST_RELOAD_MASK;
  367. *IXP4XX_OSRT1 = (evt & ~IXP4XX_OST_RELOAD_MASK) | opts;
  368. return 0;
  369. }
  370. static void ixp4xx_set_mode(enum clock_event_mode mode,
  371. struct clock_event_device *evt)
  372. {
  373. unsigned long opts = *IXP4XX_OSRT1 & IXP4XX_OST_RELOAD_MASK;
  374. unsigned long osrt = *IXP4XX_OSRT1 & ~IXP4XX_OST_RELOAD_MASK;
  375. switch (mode) {
  376. case CLOCK_EVT_MODE_PERIODIC:
  377. osrt = LATCH & ~IXP4XX_OST_RELOAD_MASK;
  378. opts = IXP4XX_OST_ENABLE;
  379. break;
  380. case CLOCK_EVT_MODE_ONESHOT:
  381. /* period set by 'set next_event' */
  382. osrt = 0;
  383. opts = IXP4XX_OST_ENABLE | IXP4XX_OST_ONE_SHOT;
  384. break;
  385. case CLOCK_EVT_MODE_SHUTDOWN:
  386. opts &= ~IXP4XX_OST_ENABLE;
  387. break;
  388. case CLOCK_EVT_MODE_RESUME:
  389. opts |= IXP4XX_OST_ENABLE;
  390. break;
  391. case CLOCK_EVT_MODE_UNUSED:
  392. default:
  393. osrt = opts = 0;
  394. break;
  395. }
  396. *IXP4XX_OSRT1 = osrt | opts;
  397. }
  398. static struct clock_event_device clockevent_ixp4xx = {
  399. .name = "ixp4xx timer1",
  400. .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
  401. .rating = 200,
  402. .shift = 24,
  403. .set_mode = ixp4xx_set_mode,
  404. .set_next_event = ixp4xx_set_next_event,
  405. };
  406. static void __init ixp4xx_clockevent_init(void)
  407. {
  408. clockevent_ixp4xx.mult = div_sc(FREQ, NSEC_PER_SEC,
  409. clockevent_ixp4xx.shift);
  410. clockevent_ixp4xx.max_delta_ns =
  411. clockevent_delta2ns(0xfffffffe, &clockevent_ixp4xx);
  412. clockevent_ixp4xx.min_delta_ns =
  413. clockevent_delta2ns(0xf, &clockevent_ixp4xx);
  414. clockevent_ixp4xx.cpumask = cpumask_of(0);
  415. clockevents_register_device(&clockevent_ixp4xx);
  416. }