common.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  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/tty.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/serial_core.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/bitops.h>
  24. #include <linux/time.h>
  25. #include <linux/clocksource.h>
  26. #include <linux/clockchips.h>
  27. #include <linux/io.h>
  28. #include <linux/export.h>
  29. #include <linux/gpio/driver.h>
  30. #include <linux/cpu.h>
  31. #include <linux/pci.h>
  32. #include <linux/sched_clock.h>
  33. #include <mach/udc.h>
  34. #include <mach/hardware.h>
  35. #include <mach/io.h>
  36. #include <asm/uaccess.h>
  37. #include <asm/pgtable.h>
  38. #include <asm/page.h>
  39. #include <asm/irq.h>
  40. #include <asm/system_misc.h>
  41. #include <asm/mach/map.h>
  42. #include <asm/mach/irq.h>
  43. #include <asm/mach/time.h>
  44. #define IXP4XX_TIMER_FREQ 66666000
  45. /*
  46. * The timer register doesn't allow to specify the two least significant bits of
  47. * the timeout value and assumes them being zero. So make sure IXP4XX_LATCH is
  48. * the best value with the two least significant bits unset.
  49. */
  50. #define IXP4XX_LATCH DIV_ROUND_CLOSEST(IXP4XX_TIMER_FREQ, \
  51. (IXP4XX_OST_RELOAD_MASK + 1) * HZ) * \
  52. (IXP4XX_OST_RELOAD_MASK + 1)
  53. static void __init ixp4xx_clocksource_init(void);
  54. static void __init ixp4xx_clockevent_init(void);
  55. static struct clock_event_device clockevent_ixp4xx;
  56. /*************************************************************************
  57. * IXP4xx chipset I/O mapping
  58. *************************************************************************/
  59. static struct map_desc ixp4xx_io_desc[] __initdata = {
  60. { /* UART, Interrupt ctrl, GPIO, timers, NPEs, MACs, USB .... */
  61. .virtual = (unsigned long)IXP4XX_PERIPHERAL_BASE_VIRT,
  62. .pfn = __phys_to_pfn(IXP4XX_PERIPHERAL_BASE_PHYS),
  63. .length = IXP4XX_PERIPHERAL_REGION_SIZE,
  64. .type = MT_DEVICE
  65. }, { /* Expansion Bus Config Registers */
  66. .virtual = (unsigned long)IXP4XX_EXP_CFG_BASE_VIRT,
  67. .pfn = __phys_to_pfn(IXP4XX_EXP_CFG_BASE_PHYS),
  68. .length = IXP4XX_EXP_CFG_REGION_SIZE,
  69. .type = MT_DEVICE
  70. }, { /* PCI Registers */
  71. .virtual = (unsigned long)IXP4XX_PCI_CFG_BASE_VIRT,
  72. .pfn = __phys_to_pfn(IXP4XX_PCI_CFG_BASE_PHYS),
  73. .length = IXP4XX_PCI_CFG_REGION_SIZE,
  74. .type = MT_DEVICE
  75. }, { /* Queue Manager */
  76. .virtual = (unsigned long)IXP4XX_QMGR_BASE_VIRT,
  77. .pfn = __phys_to_pfn(IXP4XX_QMGR_BASE_PHYS),
  78. .length = IXP4XX_QMGR_REGION_SIZE,
  79. .type = MT_DEVICE
  80. },
  81. };
  82. void __init ixp4xx_map_io(void)
  83. {
  84. iotable_init(ixp4xx_io_desc, ARRAY_SIZE(ixp4xx_io_desc));
  85. }
  86. /*
  87. * GPIO-functions
  88. */
  89. /*
  90. * The following converted to the real HW bits the gpio_line_config
  91. */
  92. /* GPIO pin types */
  93. #define IXP4XX_GPIO_OUT 0x1
  94. #define IXP4XX_GPIO_IN 0x2
  95. /* GPIO signal types */
  96. #define IXP4XX_GPIO_LOW 0
  97. #define IXP4XX_GPIO_HIGH 1
  98. /* GPIO Clocks */
  99. #define IXP4XX_GPIO_CLK_0 14
  100. #define IXP4XX_GPIO_CLK_1 15
  101. static void gpio_line_config(u8 line, u32 direction)
  102. {
  103. if (direction == IXP4XX_GPIO_IN)
  104. *IXP4XX_GPIO_GPOER |= (1 << line);
  105. else
  106. *IXP4XX_GPIO_GPOER &= ~(1 << line);
  107. }
  108. static void gpio_line_get(u8 line, int *value)
  109. {
  110. *value = (*IXP4XX_GPIO_GPINR >> line) & 0x1;
  111. }
  112. static void gpio_line_set(u8 line, int value)
  113. {
  114. if (value == IXP4XX_GPIO_HIGH)
  115. *IXP4XX_GPIO_GPOUTR |= (1 << line);
  116. else if (value == IXP4XX_GPIO_LOW)
  117. *IXP4XX_GPIO_GPOUTR &= ~(1 << line);
  118. }
  119. /*************************************************************************
  120. * IXP4xx chipset IRQ handling
  121. *
  122. * TODO: GPIO IRQs should be marked invalid until the user of the IRQ
  123. * (be it PCI or something else) configures that GPIO line
  124. * as an IRQ.
  125. **************************************************************************/
  126. enum ixp4xx_irq_type {
  127. IXP4XX_IRQ_LEVEL, IXP4XX_IRQ_EDGE
  128. };
  129. /* Each bit represents an IRQ: 1: edge-triggered, 0: level triggered */
  130. static unsigned long long ixp4xx_irq_edge = 0;
  131. /*
  132. * IRQ -> GPIO mapping table
  133. */
  134. static signed char irq2gpio[32] = {
  135. -1, -1, -1, -1, -1, -1, 0, 1,
  136. -1, -1, -1, -1, -1, -1, -1, -1,
  137. -1, -1, -1, 2, 3, 4, 5, 6,
  138. 7, 8, 9, 10, 11, 12, -1, -1,
  139. };
  140. static int ixp4xx_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  141. {
  142. int irq;
  143. for (irq = 0; irq < 32; irq++) {
  144. if (irq2gpio[irq] == gpio)
  145. return irq;
  146. }
  147. return -EINVAL;
  148. }
  149. static int ixp4xx_set_irq_type(struct irq_data *d, unsigned int type)
  150. {
  151. int line = irq2gpio[d->irq];
  152. u32 int_style;
  153. enum ixp4xx_irq_type irq_type;
  154. volatile u32 *int_reg;
  155. /*
  156. * Only for GPIO IRQs
  157. */
  158. if (line < 0)
  159. return -EINVAL;
  160. switch (type){
  161. case IRQ_TYPE_EDGE_BOTH:
  162. int_style = IXP4XX_GPIO_STYLE_TRANSITIONAL;
  163. irq_type = IXP4XX_IRQ_EDGE;
  164. break;
  165. case IRQ_TYPE_EDGE_RISING:
  166. int_style = IXP4XX_GPIO_STYLE_RISING_EDGE;
  167. irq_type = IXP4XX_IRQ_EDGE;
  168. break;
  169. case IRQ_TYPE_EDGE_FALLING:
  170. int_style = IXP4XX_GPIO_STYLE_FALLING_EDGE;
  171. irq_type = IXP4XX_IRQ_EDGE;
  172. break;
  173. case IRQ_TYPE_LEVEL_HIGH:
  174. int_style = IXP4XX_GPIO_STYLE_ACTIVE_HIGH;
  175. irq_type = IXP4XX_IRQ_LEVEL;
  176. break;
  177. case IRQ_TYPE_LEVEL_LOW:
  178. int_style = IXP4XX_GPIO_STYLE_ACTIVE_LOW;
  179. irq_type = IXP4XX_IRQ_LEVEL;
  180. break;
  181. default:
  182. return -EINVAL;
  183. }
  184. if (irq_type == IXP4XX_IRQ_EDGE)
  185. ixp4xx_irq_edge |= (1 << d->irq);
  186. else
  187. ixp4xx_irq_edge &= ~(1 << d->irq);
  188. if (line >= 8) { /* pins 8-15 */
  189. line -= 8;
  190. int_reg = IXP4XX_GPIO_GPIT2R;
  191. } else { /* pins 0-7 */
  192. int_reg = IXP4XX_GPIO_GPIT1R;
  193. }
  194. /* Clear the style for the appropriate pin */
  195. *int_reg &= ~(IXP4XX_GPIO_STYLE_CLEAR <<
  196. (line * IXP4XX_GPIO_STYLE_SIZE));
  197. *IXP4XX_GPIO_GPISR = (1 << line);
  198. /* Set the new style */
  199. *int_reg |= (int_style << (line * IXP4XX_GPIO_STYLE_SIZE));
  200. /* Configure the line as an input */
  201. gpio_line_config(irq2gpio[d->irq], IXP4XX_GPIO_IN);
  202. return 0;
  203. }
  204. static void ixp4xx_irq_mask(struct irq_data *d)
  205. {
  206. if ((cpu_is_ixp46x() || cpu_is_ixp43x()) && d->irq >= 32)
  207. *IXP4XX_ICMR2 &= ~(1 << (d->irq - 32));
  208. else
  209. *IXP4XX_ICMR &= ~(1 << d->irq);
  210. }
  211. static void ixp4xx_irq_ack(struct irq_data *d)
  212. {
  213. int line = (d->irq < 32) ? irq2gpio[d->irq] : -1;
  214. if (line >= 0)
  215. *IXP4XX_GPIO_GPISR = (1 << line);
  216. }
  217. /*
  218. * Level triggered interrupts on GPIO lines can only be cleared when the
  219. * interrupt condition disappears.
  220. */
  221. static void ixp4xx_irq_unmask(struct irq_data *d)
  222. {
  223. if (!(ixp4xx_irq_edge & (1 << d->irq)))
  224. ixp4xx_irq_ack(d);
  225. if ((cpu_is_ixp46x() || cpu_is_ixp43x()) && d->irq >= 32)
  226. *IXP4XX_ICMR2 |= (1 << (d->irq - 32));
  227. else
  228. *IXP4XX_ICMR |= (1 << d->irq);
  229. }
  230. static struct irq_chip ixp4xx_irq_chip = {
  231. .name = "IXP4xx",
  232. .irq_ack = ixp4xx_irq_ack,
  233. .irq_mask = ixp4xx_irq_mask,
  234. .irq_unmask = ixp4xx_irq_unmask,
  235. .irq_set_type = ixp4xx_set_irq_type,
  236. };
  237. void __init ixp4xx_init_irq(void)
  238. {
  239. int i = 0;
  240. /*
  241. * ixp4xx does not implement the XScale PWRMODE register
  242. * so it must not call cpu_do_idle().
  243. */
  244. cpu_idle_poll_ctrl(true);
  245. /* Route all sources to IRQ instead of FIQ */
  246. *IXP4XX_ICLR = 0x0;
  247. /* Disable all interrupt */
  248. *IXP4XX_ICMR = 0x0;
  249. if (cpu_is_ixp46x() || cpu_is_ixp43x()) {
  250. /* Route upper 32 sources to IRQ instead of FIQ */
  251. *IXP4XX_ICLR2 = 0x00;
  252. /* Disable upper 32 interrupts */
  253. *IXP4XX_ICMR2 = 0x00;
  254. }
  255. /* Default to all level triggered */
  256. for(i = 0; i < NR_IRQS; i++) {
  257. irq_set_chip_and_handler(i, &ixp4xx_irq_chip,
  258. handle_level_irq);
  259. irq_clear_status_flags(i, IRQ_NOREQUEST);
  260. }
  261. }
  262. /*************************************************************************
  263. * IXP4xx timer tick
  264. * We use OS timer1 on the CPU for the timer tick and the timestamp
  265. * counter as a source of real clock ticks to account for missed jiffies.
  266. *************************************************************************/
  267. static irqreturn_t ixp4xx_timer_interrupt(int irq, void *dev_id)
  268. {
  269. struct clock_event_device *evt = dev_id;
  270. /* Clear Pending Interrupt by writing '1' to it */
  271. *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
  272. evt->event_handler(evt);
  273. return IRQ_HANDLED;
  274. }
  275. static struct irqaction ixp4xx_timer_irq = {
  276. .name = "timer1",
  277. .flags = IRQF_TIMER | IRQF_IRQPOLL,
  278. .handler = ixp4xx_timer_interrupt,
  279. .dev_id = &clockevent_ixp4xx,
  280. };
  281. void __init ixp4xx_timer_init(void)
  282. {
  283. /* Reset/disable counter */
  284. *IXP4XX_OSRT1 = 0;
  285. /* Clear Pending Interrupt by writing '1' to it */
  286. *IXP4XX_OSST = IXP4XX_OSST_TIMER_1_PEND;
  287. /* Reset time-stamp counter */
  288. *IXP4XX_OSTS = 0;
  289. /* Connect the interrupt handler and enable the interrupt */
  290. setup_irq(IRQ_IXP4XX_TIMER1, &ixp4xx_timer_irq);
  291. ixp4xx_clocksource_init();
  292. ixp4xx_clockevent_init();
  293. }
  294. static struct pxa2xx_udc_mach_info ixp4xx_udc_info;
  295. void __init ixp4xx_set_udc_info(struct pxa2xx_udc_mach_info *info)
  296. {
  297. memcpy(&ixp4xx_udc_info, info, sizeof *info);
  298. }
  299. static struct resource ixp4xx_udc_resources[] = {
  300. [0] = {
  301. .start = 0xc800b000,
  302. .end = 0xc800bfff,
  303. .flags = IORESOURCE_MEM,
  304. },
  305. [1] = {
  306. .start = IRQ_IXP4XX_USB,
  307. .end = IRQ_IXP4XX_USB,
  308. .flags = IORESOURCE_IRQ,
  309. },
  310. };
  311. /*
  312. * USB device controller. The IXP4xx uses the same controller as PXA25X,
  313. * so we just use the same device.
  314. */
  315. static struct platform_device ixp4xx_udc_device = {
  316. .name = "pxa25x-udc",
  317. .id = -1,
  318. .num_resources = 2,
  319. .resource = ixp4xx_udc_resources,
  320. .dev = {
  321. .platform_data = &ixp4xx_udc_info,
  322. },
  323. };
  324. static struct platform_device *ixp4xx_devices[] __initdata = {
  325. &ixp4xx_udc_device,
  326. };
  327. static struct resource ixp46x_i2c_resources[] = {
  328. [0] = {
  329. .start = 0xc8011000,
  330. .end = 0xc801101c,
  331. .flags = IORESOURCE_MEM,
  332. },
  333. [1] = {
  334. .start = IRQ_IXP4XX_I2C,
  335. .end = IRQ_IXP4XX_I2C,
  336. .flags = IORESOURCE_IRQ
  337. }
  338. };
  339. /*
  340. * I2C controller. The IXP46x uses the same block as the IOP3xx, so
  341. * we just use the same device name.
  342. */
  343. static struct platform_device ixp46x_i2c_controller = {
  344. .name = "IOP3xx-I2C",
  345. .id = 0,
  346. .num_resources = 2,
  347. .resource = ixp46x_i2c_resources
  348. };
  349. static struct platform_device *ixp46x_devices[] __initdata = {
  350. &ixp46x_i2c_controller
  351. };
  352. unsigned long ixp4xx_exp_bus_size;
  353. EXPORT_SYMBOL(ixp4xx_exp_bus_size);
  354. static int ixp4xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
  355. {
  356. gpio_line_config(gpio, IXP4XX_GPIO_IN);
  357. return 0;
  358. }
  359. static int ixp4xx_gpio_direction_output(struct gpio_chip *chip, unsigned gpio,
  360. int level)
  361. {
  362. gpio_line_set(gpio, level);
  363. gpio_line_config(gpio, IXP4XX_GPIO_OUT);
  364. return 0;
  365. }
  366. static int ixp4xx_gpio_get_value(struct gpio_chip *chip, unsigned gpio)
  367. {
  368. int value;
  369. gpio_line_get(gpio, &value);
  370. return value;
  371. }
  372. static void ixp4xx_gpio_set_value(struct gpio_chip *chip, unsigned gpio,
  373. int value)
  374. {
  375. gpio_line_set(gpio, value);
  376. }
  377. static struct gpio_chip ixp4xx_gpio_chip = {
  378. .label = "IXP4XX_GPIO_CHIP",
  379. .direction_input = ixp4xx_gpio_direction_input,
  380. .direction_output = ixp4xx_gpio_direction_output,
  381. .get = ixp4xx_gpio_get_value,
  382. .set = ixp4xx_gpio_set_value,
  383. .to_irq = ixp4xx_gpio_to_irq,
  384. .base = 0,
  385. .ngpio = 16,
  386. };
  387. void __init ixp4xx_sys_init(void)
  388. {
  389. ixp4xx_exp_bus_size = SZ_16M;
  390. platform_add_devices(ixp4xx_devices, ARRAY_SIZE(ixp4xx_devices));
  391. gpiochip_add_data(&ixp4xx_gpio_chip, NULL);
  392. if (cpu_is_ixp46x()) {
  393. int region;
  394. platform_add_devices(ixp46x_devices,
  395. ARRAY_SIZE(ixp46x_devices));
  396. for (region = 0; region < 7; region++) {
  397. if((*(IXP4XX_EXP_REG(0x4 * region)) & 0x200)) {
  398. ixp4xx_exp_bus_size = SZ_32M;
  399. break;
  400. }
  401. }
  402. }
  403. printk("IXP4xx: Using %luMiB expansion bus window size\n",
  404. ixp4xx_exp_bus_size >> 20);
  405. }
  406. /*
  407. * sched_clock()
  408. */
  409. static u64 notrace ixp4xx_read_sched_clock(void)
  410. {
  411. return *IXP4XX_OSTS;
  412. }
  413. /*
  414. * clocksource
  415. */
  416. static cycle_t ixp4xx_clocksource_read(struct clocksource *c)
  417. {
  418. return *IXP4XX_OSTS;
  419. }
  420. unsigned long ixp4xx_timer_freq = IXP4XX_TIMER_FREQ;
  421. EXPORT_SYMBOL(ixp4xx_timer_freq);
  422. static void __init ixp4xx_clocksource_init(void)
  423. {
  424. sched_clock_register(ixp4xx_read_sched_clock, 32, ixp4xx_timer_freq);
  425. clocksource_mmio_init(NULL, "OSTS", ixp4xx_timer_freq, 200, 32,
  426. ixp4xx_clocksource_read);
  427. }
  428. /*
  429. * clockevents
  430. */
  431. static int ixp4xx_set_next_event(unsigned long evt,
  432. struct clock_event_device *unused)
  433. {
  434. unsigned long opts = *IXP4XX_OSRT1 & IXP4XX_OST_RELOAD_MASK;
  435. *IXP4XX_OSRT1 = (evt & ~IXP4XX_OST_RELOAD_MASK) | opts;
  436. return 0;
  437. }
  438. static int ixp4xx_shutdown(struct clock_event_device *evt)
  439. {
  440. unsigned long opts = *IXP4XX_OSRT1 & IXP4XX_OST_RELOAD_MASK;
  441. unsigned long osrt = *IXP4XX_OSRT1 & ~IXP4XX_OST_RELOAD_MASK;
  442. opts &= ~IXP4XX_OST_ENABLE;
  443. *IXP4XX_OSRT1 = osrt | opts;
  444. return 0;
  445. }
  446. static int ixp4xx_set_oneshot(struct clock_event_device *evt)
  447. {
  448. unsigned long opts = IXP4XX_OST_ENABLE | IXP4XX_OST_ONE_SHOT;
  449. unsigned long osrt = 0;
  450. /* period set by 'set next_event' */
  451. *IXP4XX_OSRT1 = osrt | opts;
  452. return 0;
  453. }
  454. static int ixp4xx_set_periodic(struct clock_event_device *evt)
  455. {
  456. unsigned long opts = IXP4XX_OST_ENABLE;
  457. unsigned long osrt = IXP4XX_LATCH & ~IXP4XX_OST_RELOAD_MASK;
  458. *IXP4XX_OSRT1 = osrt | opts;
  459. return 0;
  460. }
  461. static int ixp4xx_resume(struct clock_event_device *evt)
  462. {
  463. unsigned long opts = *IXP4XX_OSRT1 & IXP4XX_OST_RELOAD_MASK;
  464. unsigned long osrt = *IXP4XX_OSRT1 & ~IXP4XX_OST_RELOAD_MASK;
  465. opts |= IXP4XX_OST_ENABLE;
  466. *IXP4XX_OSRT1 = osrt | opts;
  467. return 0;
  468. }
  469. static struct clock_event_device clockevent_ixp4xx = {
  470. .name = "ixp4xx timer1",
  471. .features = CLOCK_EVT_FEAT_PERIODIC |
  472. CLOCK_EVT_FEAT_ONESHOT,
  473. .rating = 200,
  474. .set_state_shutdown = ixp4xx_shutdown,
  475. .set_state_periodic = ixp4xx_set_periodic,
  476. .set_state_oneshot = ixp4xx_set_oneshot,
  477. .tick_resume = ixp4xx_resume,
  478. .set_next_event = ixp4xx_set_next_event,
  479. };
  480. static void __init ixp4xx_clockevent_init(void)
  481. {
  482. clockevent_ixp4xx.cpumask = cpumask_of(0);
  483. clockevents_config_and_register(&clockevent_ixp4xx, IXP4XX_TIMER_FREQ,
  484. 0xf, 0xfffffffe);
  485. }
  486. void ixp4xx_restart(enum reboot_mode mode, const char *cmd)
  487. {
  488. if (mode == REBOOT_SOFT) {
  489. /* Jump into ROM at address 0 */
  490. soft_restart(0);
  491. } else {
  492. /* Use on-chip reset capability */
  493. /* set the "key" register to enable access to
  494. * "timer" and "enable" registers
  495. */
  496. *IXP4XX_OSWK = IXP4XX_WDT_KEY;
  497. /* write 0 to the timer register for an immediate reset */
  498. *IXP4XX_OSWT = 0;
  499. *IXP4XX_OSWE = IXP4XX_WDT_RESET_ENABLE | IXP4XX_WDT_COUNT_ENABLE;
  500. }
  501. }
  502. #ifdef CONFIG_PCI
  503. static int ixp4xx_needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size)
  504. {
  505. return (dma_addr + size) > SZ_64M;
  506. }
  507. static int ixp4xx_platform_notify_remove(struct device *dev)
  508. {
  509. if (dev_is_pci(dev))
  510. dmabounce_unregister_dev(dev);
  511. return 0;
  512. }
  513. #endif
  514. /*
  515. * Setup DMA mask to 64MB on PCI devices and 4 GB on all other things.
  516. */
  517. static int ixp4xx_platform_notify(struct device *dev)
  518. {
  519. dev->dma_mask = &dev->coherent_dma_mask;
  520. #ifdef CONFIG_PCI
  521. if (dev_is_pci(dev)) {
  522. dev->coherent_dma_mask = DMA_BIT_MASK(28); /* 64 MB */
  523. dmabounce_register_dev(dev, 2048, 4096, ixp4xx_needs_bounce);
  524. return 0;
  525. }
  526. #endif
  527. dev->coherent_dma_mask = DMA_BIT_MASK(32);
  528. return 0;
  529. }
  530. int dma_set_coherent_mask(struct device *dev, u64 mask)
  531. {
  532. if (dev_is_pci(dev))
  533. mask &= DMA_BIT_MASK(28); /* 64 MB */
  534. if ((mask & DMA_BIT_MASK(28)) == DMA_BIT_MASK(28)) {
  535. dev->coherent_dma_mask = mask;
  536. return 0;
  537. }
  538. return -EIO; /* device wanted sub-64MB mask */
  539. }
  540. EXPORT_SYMBOL(dma_set_coherent_mask);
  541. #ifdef CONFIG_IXP4XX_INDIRECT_PCI
  542. /*
  543. * In the case of using indirect PCI, we simply return the actual PCI
  544. * address and our read/write implementation use that to drive the
  545. * access registers. If something outside of PCI is ioremap'd, we
  546. * fallback to the default.
  547. */
  548. static void __iomem *ixp4xx_ioremap_caller(phys_addr_t addr, size_t size,
  549. unsigned int mtype, void *caller)
  550. {
  551. if (!is_pci_memory(addr))
  552. return __arm_ioremap_caller(addr, size, mtype, caller);
  553. return (void __iomem *)addr;
  554. }
  555. static void ixp4xx_iounmap(volatile void __iomem *addr)
  556. {
  557. if (!is_pci_memory((__force u32)addr))
  558. __iounmap(addr);
  559. }
  560. #endif
  561. void __init ixp4xx_init_early(void)
  562. {
  563. platform_notify = ixp4xx_platform_notify;
  564. #ifdef CONFIG_PCI
  565. platform_notify_remove = ixp4xx_platform_notify_remove;
  566. #endif
  567. #ifdef CONFIG_IXP4XX_INDIRECT_PCI
  568. arch_ioremap_caller = ixp4xx_ioremap_caller;
  569. arch_iounmap = ixp4xx_iounmap;
  570. #endif
  571. }