2 * linux/arch/arm/common/it8152.c
4 * Copyright Compulab Ltd, 2002-2007
5 * Mike Rapoport <mike@compulab.co.il>
7 * The DMA bouncing part is taken from arch/arm/mach-ixp4xx/common-pci.c
8 * (see this file for respective copyrights)
10 * Thanks to Guennadi Liakhovetski <gl@dsa-ac.de> for IRQ enumberation
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
18 #include <linux/sched.h>
19 #include <linux/kernel.h>
20 #include <linux/pci.h>
21 #include <linux/ptrace.h>
22 #include <linux/interrupt.h>
24 #include <linux/slab.h>
25 #include <linux/init.h>
26 #include <linux/ioport.h>
27 #include <linux/irq.h>
30 #include <asm/mach/pci.h>
31 #include <asm/hardware/it8152.h>
35 static void it8152_mask_irq(unsigned int irq)
37 if (irq >= IT8152_LD_IRQ(0)) {
38 __raw_writel((__raw_readl(IT8152_INTC_LDCNIMR) |
39 (1 << (irq - IT8152_LD_IRQ(0)))),
41 } else if (irq >= IT8152_LP_IRQ(0)) {
42 __raw_writel((__raw_readl(IT8152_INTC_LPCNIMR) |
43 (1 << (irq - IT8152_LP_IRQ(0)))),
45 } else if (irq >= IT8152_PD_IRQ(0)) {
46 __raw_writel((__raw_readl(IT8152_INTC_PDCNIMR) |
47 (1 << (irq - IT8152_PD_IRQ(0)))),
52 static void it8152_unmask_irq(unsigned int irq)
54 if (irq >= IT8152_LD_IRQ(0)) {
55 __raw_writel((__raw_readl(IT8152_INTC_LDCNIMR) &
56 ~(1 << (irq - IT8152_LD_IRQ(0)))),
58 } else if (irq >= IT8152_LP_IRQ(0)) {
59 __raw_writel((__raw_readl(IT8152_INTC_LPCNIMR) &
60 ~(1 << (irq - IT8152_LP_IRQ(0)))),
62 } else if (irq >= IT8152_PD_IRQ(0)) {
63 __raw_writel((__raw_readl(IT8152_INTC_PDCNIMR) &
64 ~(1 << (irq - IT8152_PD_IRQ(0)))),
69 static struct irq_chip it8152_irq_chip = {
71 .ack = it8152_mask_irq,
72 .mask = it8152_mask_irq,
73 .unmask = it8152_unmask_irq,
76 void it8152_init_irq(void)
80 __raw_writel((0xffff), IT8152_INTC_PDCNIMR);
81 __raw_writel((0), IT8152_INTC_PDCNIRR);
82 __raw_writel((0xffff), IT8152_INTC_LPCNIMR);
83 __raw_writel((0), IT8152_INTC_LPCNIRR);
84 __raw_writel((0xffff), IT8152_INTC_LDCNIMR);
85 __raw_writel((0), IT8152_INTC_LDCNIRR);
87 for (irq = IT8152_IRQ(0); irq <= IT8152_LAST_IRQ; irq++) {
88 set_irq_chip(irq, &it8152_irq_chip);
89 set_irq_handler(irq, handle_level_irq);
90 set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
94 void it8152_irq_demux(unsigned int irq, struct irq_desc *desc)
96 int bits_pd, bits_lp, bits_ld;
101 bits_pd = __raw_readl(IT8152_INTC_PDCNIRR);
102 bits_lp = __raw_readl(IT8152_INTC_LPCNIRR);
103 bits_ld = __raw_readl(IT8152_INTC_LDCNIRR);
106 __raw_writel((~bits_pd), IT8152_INTC_PDCNIRR);
107 __raw_writel((~bits_lp), IT8152_INTC_LPCNIRR);
108 __raw_writel((~bits_ld), IT8152_INTC_LDCNIRR);
110 if (!(bits_ld | bits_lp | bits_pd)) {
111 /* Re-read to guarantee, that there was a moment of
112 time, when they all three were 0. */
113 bits_pd = __raw_readl(IT8152_INTC_PDCNIRR);
114 bits_lp = __raw_readl(IT8152_INTC_LPCNIRR);
115 bits_ld = __raw_readl(IT8152_INTC_LDCNIRR);
116 if (!(bits_ld | bits_lp | bits_pd))
120 bits_pd &= ((1 << IT8152_PD_IRQ_COUNT) - 1);
123 generic_handle_irq(IT8152_PD_IRQ(i));
124 bits_pd &= ~(1 << i);
127 bits_lp &= ((1 << IT8152_LP_IRQ_COUNT) - 1);
130 generic_handle_irq(IT8152_LP_IRQ(i));
131 bits_lp &= ~(1 << i);
134 bits_ld &= ((1 << IT8152_LD_IRQ_COUNT) - 1);
137 generic_handle_irq(IT8152_LD_IRQ(i));
138 bits_ld &= ~(1 << i);
143 /* mapping for on-chip devices */
144 int __init it8152_pci_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
146 if ((dev->vendor == PCI_VENDOR_ID_ITE) &&
147 (dev->device == PCI_DEVICE_ID_ITE_8152)) {
148 if ((dev->class >> 8) == PCI_CLASS_MULTIMEDIA_AUDIO)
149 return IT8152_AUDIO_INT;
150 if ((dev->class >> 8) == PCI_CLASS_SERIAL_USB)
151 return IT8152_USB_INT;
152 if ((dev->class >> 8) == PCI_CLASS_SYSTEM_DMA)
153 return IT8152_CDMA_INT;
159 static unsigned long it8152_pci_dev_base_address(struct pci_bus *bus,
162 unsigned long addr = 0;
164 if (bus->number == 0) {
165 if (devfn < PCI_DEVFN(MAX_SLOTS, 0))
168 addr = (bus->number << 16) | (devfn << 8);
173 static int it8152_pci_read_config(struct pci_bus *bus,
174 unsigned int devfn, int where,
175 int size, u32 *value)
177 unsigned long addr = it8152_pci_dev_base_address(bus, devfn);
183 __raw_writel((addr + where), IT8152_PCI_CFG_ADDR);
184 v = (__raw_readl(IT8152_PCI_CFG_DATA) >> (8 * (shift)));
188 return PCIBIOS_SUCCESSFUL;
191 static int it8152_pci_write_config(struct pci_bus *bus,
192 unsigned int devfn, int where,
195 unsigned long addr = it8152_pci_dev_base_address(bus, devfn);
196 u32 v, vtemp, mask = 0;
206 __raw_writel((addr + where), IT8152_PCI_CFG_ADDR);
207 vtemp = __raw_readl(IT8152_PCI_CFG_DATA);
210 vtemp &= ~(mask << (8 * shift));
214 v = (value << (8 * shift));
215 __raw_writel((addr + where), IT8152_PCI_CFG_ADDR);
216 __raw_writel((v | vtemp), IT8152_PCI_CFG_DATA);
218 return PCIBIOS_SUCCESSFUL;
221 static struct pci_ops it8152_ops = {
222 .read = it8152_pci_read_config,
223 .write = it8152_pci_write_config,
226 static struct resource it8152_io = {
227 .name = "IT8152 PCI I/O region",
228 .flags = IORESOURCE_IO,
231 static struct resource it8152_mem = {
232 .name = "IT8152 PCI memory region",
235 .flags = IORESOURCE_MEM,
239 * The following functions are needed for DMA bouncing.
240 * ITE8152 chip can addrees up to 64MByte, so all the devices
241 * connected to ITE8152 (PCI and USB) should have limited DMA window
245 * Setup DMA mask to 64MB on devices connected to ITE8152. Ignore all
248 static int it8152_pci_platform_notify(struct device *dev)
250 if (dev->bus == &pci_bus_type) {
252 *dev->dma_mask = (SZ_64M - 1) | PHYS_OFFSET;
253 dev->coherent_dma_mask = (SZ_64M - 1) | PHYS_OFFSET;
254 dmabounce_register_dev(dev, 2048, 4096);
259 static int it8152_pci_platform_notify_remove(struct device *dev)
261 if (dev->bus == &pci_bus_type)
262 dmabounce_unregister_dev(dev);
267 int dma_needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size)
269 dev_dbg(dev, "%s: dma_addr %08x, size %08x\n",
270 __func__, dma_addr, size);
271 return (dev->bus == &pci_bus_type) &&
272 ((dma_addr + size - PHYS_OFFSET) >= SZ_64M);
276 * We override these so we properly do dmabounce otherwise drivers
277 * are able to set the dma_mask to 0xffffffff and we can no longer
280 * We just return true on everyhing except for < 64MB in which case
281 * we will fail miseralby and die since we can't handle that case.
283 int pci_set_dma_mask(struct pci_dev *dev, u64 mask)
285 dev_dbg(&dev->dev, "%s: %llx\n", __func__, mask);
286 if (mask >= PHYS_OFFSET + SZ_64M - 1)
293 pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
295 dev_dbg(&dev->dev, "%s: %llx\n", __func__, mask);
296 if (mask >= PHYS_OFFSET + SZ_64M - 1)
302 int __init it8152_pci_setup(int nr, struct pci_sys_data *sys)
304 it8152_io.start = IT8152_IO_BASE + 0x12000;
305 it8152_io.end = IT8152_IO_BASE + 0x12000 + 0x100000;
307 sys->mem_offset = 0x10000000;
308 sys->io_offset = IT8152_IO_BASE;
310 if (request_resource(&ioport_resource, &it8152_io)) {
311 printk(KERN_ERR "PCI: unable to allocate IO region\n");
314 if (request_resource(&iomem_resource, &it8152_mem)) {
315 printk(KERN_ERR "PCI: unable to allocate memory region\n");
319 sys->resource[0] = &it8152_io;
320 sys->resource[1] = &it8152_mem;
322 if (platform_notify || platform_notify_remove) {
323 printk(KERN_ERR "PCI: Can't use platform_notify\n");
327 platform_notify = it8152_pci_platform_notify;
328 platform_notify_remove = it8152_pci_platform_notify_remove;
333 release_resource(&it8152_io);
335 release_resource(&it8152_mem);
341 * If we set up a device for bus mastering, we need to check the latency
342 * timer as we don't have even crappy BIOSes to set it properly.
343 * The implementation is from arch/i386/pci/i386.c
345 unsigned int pcibios_max_latency = 255;
347 void pcibios_set_master(struct pci_dev *dev)
351 /* no need to update on-chip OHCI controller */
352 if ((dev->vendor == PCI_VENDOR_ID_ITE) &&
353 (dev->device == PCI_DEVICE_ID_ITE_8152) &&
354 ((dev->class >> 8) == PCI_CLASS_SERIAL_USB))
357 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
359 lat = (64 <= pcibios_max_latency) ? 64 : pcibios_max_latency;
360 else if (lat > pcibios_max_latency)
361 lat = pcibios_max_latency;
364 printk(KERN_DEBUG "PCI: Setting latency timer of device %s to %d\n",
366 pci_write_config_byte(dev, PCI_LATENCY_TIMER, lat);
370 struct pci_bus * __init it8152_pci_scan_bus(int nr, struct pci_sys_data *sys)
372 return pci_scan_bus(nr, &it8152_ops, sys);