common.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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 <asm/arch/udc.h>
  30. #include <asm/hardware.h>
  31. #include <asm/uaccess.h>
  32. #include <asm/io.h>
  33. #include <asm/pgtable.h>
  34. #include <asm/page.h>
  35. #include <asm/irq.h>
  36. #include <asm/mach/map.h>
  37. #include <asm/mach/irq.h>
  38. #include <asm/mach/time.h>
  39. static int __init ixp4xx_clocksource_init(void);
  40. /*************************************************************************
  41. * IXP4xx chipset I/O mapping
  42. *************************************************************************/
  43. static struct map_desc ixp4xx_io_desc[] __initdata = {
  44. { /* UART, Interrupt ctrl, GPIO, timers, NPEs, MACs, USB .... */
  45. .virtual = IXP4XX_PERIPHERAL_BASE_VIRT,
  46. .pfn = __phys_to_pfn(IXP4XX_PERIPHERAL_BASE_PHYS),
  47. .length = IXP4XX_PERIPHERAL_REGION_SIZE,
  48. .type = MT_DEVICE
  49. }, { /* Expansion Bus Config Registers */
  50. .virtual = IXP4XX_EXP_CFG_BASE_VIRT,
  51. .pfn = __phys_to_pfn(IXP4XX_EXP_CFG_BASE_PHYS),
  52. .length = IXP4XX_EXP_CFG_REGION_SIZE,
  53. .type = MT_DEVICE
  54. }, { /* PCI Registers */
  55. .virtual = IXP4XX_PCI_CFG_BASE_VIRT,
  56. .pfn = __phys_to_pfn(IXP4XX_PCI_CFG_BASE_PHYS),
  57. .length = IXP4XX_PCI_CFG_REGION_SIZE,
  58. .type = MT_DEVICE
  59. },
  60. #ifdef CONFIG_DEBUG_LL
  61. { /* Debug UART mapping */
  62. .virtual = IXP4XX_DEBUG_UART_BASE_VIRT,
  63. .pfn = __phys_to_pfn(IXP4XX_DEBUG_UART_BASE_PHYS),
  64. .length = IXP4XX_DEBUG_UART_REGION_SIZE,
  65. .type = MT_DEVICE
  66. }
  67. #endif
  68. };
  69. void __init ixp4xx_map_io(void)
  70. {
  71. iotable_init(ixp4xx_io_desc, ARRAY_SIZE(ixp4xx_io_desc));
  72. }
  73. /*************************************************************************
  74. * IXP4xx chipset IRQ handling
  75. *
  76. * TODO: GPIO IRQs should be marked invalid until the user of the IRQ
  77. * (be it PCI or something else) configures that GPIO line
  78. * as an IRQ.
  79. **************************************************************************/
  80. enum ixp4xx_irq_type {
  81. IXP4XX_IRQ_LEVEL, IXP4XX_IRQ_EDGE
  82. };
  83. /* Each bit represents an IRQ: 1: edge-triggered, 0: level triggered */
  84. static unsigned long long ixp4xx_irq_edge = 0;
  85. /*
  86. * IRQ -> GPIO mapping table
  87. */
  88. static signed char irq2gpio[32] = {
  89. -1, -1, -1, -1, -1, -1, 0, 1,
  90. -1, -1, -1, -1, -1, -1, -1, -1,
  91. -1, -1, -1, 2, 3, 4, 5, 6,
  92. 7, 8, 9, 10, 11, 12, -1, -1,
  93. };
  94. int gpio_to_irq(int gpio)
  95. {
  96. int irq;
  97. for (irq = 0; irq < 32; irq++) {
  98. if (irq2gpio[irq] == gpio)
  99. return irq;
  100. }
  101. return -EINVAL;
  102. }
  103. EXPORT_SYMBOL(gpio_to_irq);
  104. int irq_to_gpio(int irq)
  105. {
  106. int gpio = (irq < 32) ? irq2gpio[irq] : -EINVAL;
  107. if (gpio == -1)
  108. return -EINVAL;
  109. return gpio;
  110. }
  111. EXPORT_SYMBOL(irq_to_gpio);
  112. static int ixp4xx_set_irq_type(unsigned int irq, unsigned int type)
  113. {
  114. int line = irq2gpio[irq];
  115. u32 int_style;
  116. enum ixp4xx_irq_type irq_type;
  117. volatile u32 *int_reg;
  118. /*
  119. * Only for GPIO IRQs
  120. */
  121. if (line < 0)
  122. return -EINVAL;
  123. switch (type){
  124. case IRQT_BOTHEDGE:
  125. int_style = IXP4XX_GPIO_STYLE_TRANSITIONAL;
  126. irq_type = IXP4XX_IRQ_EDGE;
  127. break;
  128. case IRQT_RISING:
  129. int_style = IXP4XX_GPIO_STYLE_RISING_EDGE;
  130. irq_type = IXP4XX_IRQ_EDGE;
  131. break;
  132. case IRQT_FALLING:
  133. int_style = IXP4XX_GPIO_STYLE_FALLING_EDGE;
  134. irq_type = IXP4XX_IRQ_EDGE;
  135. break;
  136. case IRQT_HIGH:
  137. int_style = IXP4XX_GPIO_STYLE_ACTIVE_HIGH;
  138. irq_type = IXP4XX_IRQ_LEVEL;
  139. break;
  140. case IRQT_LOW:
  141. int_style = IXP4XX_GPIO_STYLE_ACTIVE_LOW;
  142. irq_type = IXP4XX_IRQ_LEVEL;
  143. break;
  144. default:
  145. return -EINVAL;
  146. }
  147. if (irq_type == IXP4XX_IRQ_EDGE)
  148. ixp4xx_irq_edge |= (1 << irq);
  149. else
  150. ixp4xx_irq_edge &= ~(1 << irq);
  151. if (line >= 8) { /* pins 8-15 */
  152. line -= 8;
  153. int_reg = IXP4XX_GPIO_GPIT2R;
  154. } else { /* pins 0-7 */
  155. int_reg = IXP4XX_GPIO_GPIT1R;
  156. }
  157. /* Clear the style for the appropriate pin */
  158. *int_reg &= ~(IXP4XX_GPIO_STYLE_CLEAR <<
  159. (line * IXP4XX_GPIO_STYLE_SIZE));
  160. *IXP4XX_GPIO_GPISR = (1 << line);
  161. /* Set the new style */
  162. *int_reg |= (int_style << (line * IXP4XX_GPIO_STYLE_SIZE));
  163. /* Configure the line as an input */
  164. gpio_line_config(line, IXP4XX_GPIO_IN);
  165. return 0;
  166. }
  167. static void ixp4xx_irq_mask(unsigned int irq)
  168. {
  169. if (cpu_is_ixp46x() && irq >= 32)
  170. *IXP4XX_ICMR2 &= ~(1 << (irq - 32));
  171. else
  172. *IXP4XX_ICMR &= ~(1 << irq);
  173. }
  174. static void ixp4xx_irq_ack(unsigned int irq)
  175. {
  176. int line = (irq < 32) ? irq2gpio[irq] : -1;
  177. if (line >= 0)
  178. *IXP4XX_GPIO_GPISR = (1 << line);
  179. }
  180. /*
  181. * Level triggered interrupts on GPIO lines can only be cleared when the
  182. * interrupt condition disappears.
  183. */
  184. static void ixp4xx_irq_unmask(unsigned int irq)
  185. {
  186. if (!(ixp4xx_irq_edge & (1 << irq)))
  187. ixp4xx_irq_ack(irq);
  188. if (cpu_is_ixp46x() && irq >= 32)
  189. *IXP4XX_ICMR2 |= (1 << (irq - 32));
  190. else
  191. *IXP4XX_ICMR |= (1 << irq);
  192. }
  193. static struct irq_chip ixp4xx_irq_chip = {
  194. .name = "IXP4xx",
  195. .ack = ixp4xx_irq_ack,
  196. .mask = ixp4xx_irq_mask,
  197. .unmask = ixp4xx_irq_unmask,
  198. .set_type = ixp4xx_set_irq_type,
  199. };
  200. void __init ixp4xx_init_irq(void)
  201. {
  202. int i = 0;
  203. /* Route all sources to IRQ instead of FIQ */
  204. *IXP4XX_ICLR = 0x0;
  205. /* Disable all interrupt */
  206. *IXP4XX_ICMR = 0x0;
  207. if (cpu_is_ixp46x()) {
  208. /* Route upper 32 sources to IRQ instead of FIQ */
  209. *IXP4XX_ICLR2 = 0x00;
  210. /* Disable upper 32 interrupts */
  211. *IXP4XX_ICMR2 = 0x00;
  212. }
  213. /* Default to all level triggered */
  214. for(i = 0; i < NR_IRQS; i++) {
  215. set_irq_chip(i, &ixp4xx_irq_chip);
  216. set_irq_handler(i, handle_level_irq);
  217. set_irq_flags(i, IRQF_VALID);
  218. }
  219. }
  220. /*************************************************************************
  221. * IXP4xx timer tick
  222. * We use OS timer1 on the CPU for the timer tick and the timestamp
  223. * counter as a source of real clock ticks to account for missed jiffies.
  224. *************************************************************************/
  225. static unsigned volatile last_jiffy_time;
  226. #define CLOCK_TICKS_PER_USEC ((CLOCK_TICK_RATE + USEC_PER_SEC/2) / USEC_PER_SEC)
  227. static irqreturn_t ixp4xx_timer_interrupt(int irq, void *dev_id)
  228. {
  229. write_seqlock(&xtime_lock);
  230. /* Clear Pending Interrupt by writing '1' to it */
  231. *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
  232. /*
  233. * Catch up with the real idea of time
  234. */
  235. while ((signed long)(*IXP4XX_OSTS - last_jiffy_time) >= LATCH) {
  236. timer_tick();
  237. last_jiffy_time += LATCH;
  238. }
  239. write_sequnlock(&xtime_lock);
  240. return IRQ_HANDLED;
  241. }
  242. static struct irqaction ixp4xx_timer_irq = {
  243. .name = "IXP4xx Timer Tick",
  244. .flags = IRQF_DISABLED | IRQF_TIMER,
  245. .handler = ixp4xx_timer_interrupt,
  246. };
  247. static void __init ixp4xx_timer_init(void)
  248. {
  249. /* Clear Pending Interrupt by writing '1' to it */
  250. *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
  251. /* Setup the Timer counter value */
  252. *IXP4XX_OSRT1 = (LATCH & ~IXP4XX_OST_RELOAD_MASK) | IXP4XX_OST_ENABLE;
  253. /* Reset time-stamp counter */
  254. *IXP4XX_OSTS = 0;
  255. last_jiffy_time = 0;
  256. /* Connect the interrupt handler and enable the interrupt */
  257. setup_irq(IRQ_IXP4XX_TIMER1, &ixp4xx_timer_irq);
  258. ixp4xx_clocksource_init();
  259. }
  260. struct sys_timer ixp4xx_timer = {
  261. .init = ixp4xx_timer_init,
  262. };
  263. static struct pxa2xx_udc_mach_info ixp4xx_udc_info;
  264. void __init ixp4xx_set_udc_info(struct pxa2xx_udc_mach_info *info)
  265. {
  266. memcpy(&ixp4xx_udc_info, info, sizeof *info);
  267. }
  268. static struct resource ixp4xx_udc_resources[] = {
  269. [0] = {
  270. .start = 0xc800b000,
  271. .end = 0xc800bfff,
  272. .flags = IORESOURCE_MEM,
  273. },
  274. [1] = {
  275. .start = IRQ_IXP4XX_USB,
  276. .end = IRQ_IXP4XX_USB,
  277. .flags = IORESOURCE_IRQ,
  278. },
  279. };
  280. /*
  281. * USB device controller. The IXP4xx uses the same controller as PXA2XX,
  282. * so we just use the same device.
  283. */
  284. static struct platform_device ixp4xx_udc_device = {
  285. .name = "pxa2xx-udc",
  286. .id = -1,
  287. .num_resources = 2,
  288. .resource = ixp4xx_udc_resources,
  289. .dev = {
  290. .platform_data = &ixp4xx_udc_info,
  291. },
  292. };
  293. static struct platform_device *ixp4xx_devices[] __initdata = {
  294. &ixp4xx_udc_device,
  295. };
  296. static struct resource ixp46x_i2c_resources[] = {
  297. [0] = {
  298. .start = 0xc8011000,
  299. .end = 0xc801101c,
  300. .flags = IORESOURCE_MEM,
  301. },
  302. [1] = {
  303. .start = IRQ_IXP4XX_I2C,
  304. .end = IRQ_IXP4XX_I2C,
  305. .flags = IORESOURCE_IRQ
  306. }
  307. };
  308. /*
  309. * I2C controller. The IXP46x uses the same block as the IOP3xx, so
  310. * we just use the same device name.
  311. */
  312. static struct platform_device ixp46x_i2c_controller = {
  313. .name = "IOP3xx-I2C",
  314. .id = 0,
  315. .num_resources = 2,
  316. .resource = ixp46x_i2c_resources
  317. };
  318. static struct platform_device *ixp46x_devices[] __initdata = {
  319. &ixp46x_i2c_controller
  320. };
  321. unsigned long ixp4xx_exp_bus_size;
  322. EXPORT_SYMBOL(ixp4xx_exp_bus_size);
  323. void __init ixp4xx_sys_init(void)
  324. {
  325. ixp4xx_exp_bus_size = SZ_16M;
  326. platform_add_devices(ixp4xx_devices, ARRAY_SIZE(ixp4xx_devices));
  327. if (cpu_is_ixp46x()) {
  328. int region;
  329. platform_add_devices(ixp46x_devices,
  330. ARRAY_SIZE(ixp46x_devices));
  331. for (region = 0; region < 7; region++) {
  332. if((*(IXP4XX_EXP_REG(0x4 * region)) & 0x200)) {
  333. ixp4xx_exp_bus_size = SZ_32M;
  334. break;
  335. }
  336. }
  337. }
  338. printk("IXP4xx: Using %luMiB expansion bus window size\n",
  339. ixp4xx_exp_bus_size >> 20);
  340. }
  341. cycle_t ixp4xx_get_cycles(void)
  342. {
  343. return *IXP4XX_OSTS;
  344. }
  345. static struct clocksource clocksource_ixp4xx = {
  346. .name = "OSTS",
  347. .rating = 200,
  348. .read = ixp4xx_get_cycles,
  349. .mask = CLOCKSOURCE_MASK(32),
  350. .shift = 20,
  351. .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  352. };
  353. unsigned long ixp4xx_timer_freq = FREQ;
  354. static int __init ixp4xx_clocksource_init(void)
  355. {
  356. clocksource_ixp4xx.mult =
  357. clocksource_hz2mult(ixp4xx_timer_freq,
  358. clocksource_ixp4xx.shift);
  359. clocksource_register(&clocksource_ixp4xx);
  360. return 0;
  361. }