X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=include%2Fasm-sparc64%2Fparport.h;h=e9555b246c8d0ea909cfa5c9811b844688f42ca2;hb=4f4ae0d42680889c62db4e1f3e6b4aa7787a7257;hp=ab88349ddadc71e39a72e7fa6b32baeb32bb2362;hpb=1da177e4c3f41524e886b7f1b8a0c1fc7321cac2;p=safe%2Fjmp%2Flinux-2.6 diff --git a/include/asm-sparc64/parport.h b/include/asm-sparc64/parport.h index ab88349..e9555b2 100644 --- a/include/asm-sparc64/parport.h +++ b/include/asm-sparc64/parport.h @@ -1,5 +1,4 @@ -/* $Id: parport.h,v 1.11 2001/05/11 07:54:24 davem Exp $ - * parport.h: sparc64 specific parport initialization and dma. +/* parport.h: sparc64 specific parport initialization and dma. * * Copyright (C) 1999 Eddie C. Dost (ecd@skynet.be) */ @@ -8,168 +7,240 @@ #define _ASM_SPARC64_PARPORT_H 1 #include -#include #include +#include +#include #define PARPORT_PC_MAX_PORTS PARPORT_MAX +/* + * While sparc64 doesn't have an ISA DMA API, we provide something that looks + * close enough to make parport_pc happy + */ +#define HAS_DMA + +static DEFINE_SPINLOCK(dma_spin_lock); + +#define claim_dma_lock() \ +({ unsigned long flags; \ + spin_lock_irqsave(&dma_spin_lock, flags); \ + flags; \ +}) + +#define release_dma_lock(__flags) \ + spin_unlock_irqrestore(&dma_spin_lock, __flags); + static struct sparc_ebus_info { struct ebus_dma_info info; unsigned int addr; unsigned int count; + int lock; + + struct parport *port; } sparc_ebus_dmas[PARPORT_PC_MAX_PORTS]; -static __inline__ void enable_dma(unsigned int dmanr) +static DECLARE_BITMAP(dma_slot_map, PARPORT_PC_MAX_PORTS); + +static inline int request_dma(unsigned int dmanr, const char *device_id) { + if (dmanr >= PARPORT_PC_MAX_PORTS) + return -EINVAL; + if (xchg(&sparc_ebus_dmas[dmanr].lock, 1) != 0) + return -EBUSY; + return 0; +} + +static inline void free_dma(unsigned int dmanr) +{ + if (dmanr >= PARPORT_PC_MAX_PORTS) { + printk(KERN_WARNING "Trying to free DMA%d\n", dmanr); + return; + } + if (xchg(&sparc_ebus_dmas[dmanr].lock, 0) == 0) { + printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr); + return; + } +} + +static inline void enable_dma(unsigned int dmanr) +{ + ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1); + if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info, sparc_ebus_dmas[dmanr].addr, sparc_ebus_dmas[dmanr].count)) BUG(); - - ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1); } -static __inline__ void disable_dma(unsigned int dmanr) +static inline void disable_dma(unsigned int dmanr) { ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0); } -static __inline__ void clear_dma_ff(unsigned int dmanr) +static inline void clear_dma_ff(unsigned int dmanr) { /* nothing */ } -static __inline__ void set_dma_mode(unsigned int dmanr, char mode) +static inline void set_dma_mode(unsigned int dmanr, char mode) { ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE)); } -static __inline__ void set_dma_addr(unsigned int dmanr, unsigned int addr) +static inline void set_dma_addr(unsigned int dmanr, unsigned int addr) { sparc_ebus_dmas[dmanr].addr = addr; } -static __inline__ void set_dma_count(unsigned int dmanr, unsigned int count) +static inline void set_dma_count(unsigned int dmanr, unsigned int count) { sparc_ebus_dmas[dmanr].count = count; } -static __inline__ unsigned int get_dma_residue(unsigned int dmanr) +static inline unsigned int get_dma_residue(unsigned int dmanr) { return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info); } -static int ebus_ecpp_p(struct linux_ebus_device *edev) +static int __devinit ecpp_probe(struct of_device *op, const struct of_device_id *match) { - if (!strcmp(edev->prom_name, "ecpp")) - return 1; - if (!strcmp(edev->prom_name, "parallel")) { - char compat[19]; - prom_getstring(edev->prom_node, - "compatible", - compat, sizeof(compat)); - compat[18] = '\0'; - if (!strcmp(compat, "ecpp")) - return 1; - if (!strcmp(compat, "ns87317-ecpp") && - !strcmp(compat + 13, "ecpp")) - return 1; + unsigned long base = op->resource[0].start; + unsigned long config = op->resource[1].start; + unsigned long d_base = op->resource[2].start; + unsigned long d_len; + struct device_node *parent; + struct parport *p; + int slot, err; + + parent = op->node->parent; + if (!strcmp(parent->name, "dma")) { + p = parport_pc_probe_port(base, base + 0x400, + op->irqs[0], PARPORT_DMA_NOFIFO, + op->dev.parent->parent); + if (!p) + return -ENOMEM; + dev_set_drvdata(&op->dev, p); + return 0; } + + for (slot = 0; slot < PARPORT_PC_MAX_PORTS; slot++) { + if (!test_and_set_bit(slot, dma_slot_map)) + break; + } + err = -ENODEV; + if (slot >= PARPORT_PC_MAX_PORTS) + goto out_err; + + spin_lock_init(&sparc_ebus_dmas[slot].info.lock); + + d_len = (op->resource[2].end - d_base) + 1UL; + sparc_ebus_dmas[slot].info.regs = + of_ioremap(&op->resource[2], 0, d_len, "ECPP DMA"); + + if (!sparc_ebus_dmas[slot].info.regs) + goto out_clear_map; + + sparc_ebus_dmas[slot].info.flags = 0; + sparc_ebus_dmas[slot].info.callback = NULL; + sparc_ebus_dmas[slot].info.client_cookie = NULL; + sparc_ebus_dmas[slot].info.irq = 0xdeadbeef; + strcpy(sparc_ebus_dmas[slot].info.name, "parport"); + if (ebus_dma_register(&sparc_ebus_dmas[slot].info)) + goto out_unmap_regs; + + ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 1); + + /* Configure IRQ to Push Pull, Level Low */ + /* Enable ECP, set bit 2 of the CTR first */ + outb(0x04, base + 0x02); + ns87303_modify(config, PCR, + PCR_EPP_ENABLE | + PCR_IRQ_ODRAIN, + PCR_ECP_ENABLE | + PCR_ECP_CLK_ENA | + PCR_IRQ_POLAR); + + /* CTR bit 5 controls direction of port */ + ns87303_modify(config, PTR, + 0, PTR_LPT_REG_DIR); + + p = parport_pc_probe_port(base, base + 0x400, + op->irqs[0], + slot, + op->dev.parent); + err = -ENOMEM; + if (!p) + goto out_disable_irq; + + dev_set_drvdata(&op->dev, p); + return 0; + +out_disable_irq: + ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0); + ebus_dma_unregister(&sparc_ebus_dmas[slot].info); + +out_unmap_regs: + of_iounmap(&op->resource[2], sparc_ebus_dmas[slot].info.regs, d_len); + +out_clear_map: + clear_bit(slot, dma_slot_map); + +out_err: + return err; } -static int parport_isa_probe(int count) +static int __devexit ecpp_remove(struct of_device *op) { - struct sparc_isa_bridge *isa_br; - struct sparc_isa_device *isa_dev; - - for_each_isa(isa_br) { - for_each_isadev(isa_dev, isa_br) { - struct sparc_isa_device *child; - unsigned long base; - - if (strcmp(isa_dev->prom_name, "dma")) - continue; - - child = isa_dev->child; - while (child) { - if (!strcmp(child->prom_name, "parallel")) - break; - child = child->next; - } - if (!child) - continue; - - base = child->resource.start; - - /* No DMA, see commentary in - * asm-sparc64/floppy.h:isa_floppy_init() - */ - if (parport_pc_probe_port(base, base + 0x400, - child->irq, PARPORT_DMA_NOFIFO, - child->bus->self)) - count++; - } + struct parport *p = dev_get_drvdata(&op->dev); + int slot = p->dma; + + parport_pc_unregister_port(p); + + if (slot != PARPORT_DMA_NOFIFO) { + unsigned long d_base = op->resource[2].start; + unsigned long d_len; + + d_len = (op->resource[2].end - d_base) + 1UL; + + ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0); + ebus_dma_unregister(&sparc_ebus_dmas[slot].info); + of_iounmap(&op->resource[2], + sparc_ebus_dmas[slot].info.regs, + d_len); + clear_bit(slot, dma_slot_map); } - return count; + return 0; } -static int parport_pc_find_nonpci_ports (int autoirq, int autodma) +static struct of_device_id ecpp_match[] = { + { + .name = "ecpp", + }, + { + .name = "parallel", + .compatible = "ecpp", + }, + { + .name = "parallel", + .compatible = "ns87317-ecpp", + }, + {}, +}; + +static struct of_platform_driver ecpp_driver = { + .name = "ecpp", + .match_table = ecpp_match, + .probe = ecpp_probe, + .remove = __devexit_p(ecpp_remove), +}; + +static int parport_pc_find_nonpci_ports(int autoirq, int autodma) { - struct linux_ebus *ebus; - struct linux_ebus_device *edev; - int count = 0; - - for_each_ebus(ebus) { - for_each_ebusdev(edev, ebus) { - if (ebus_ecpp_p(edev)) { - unsigned long base = edev->resource[0].start; - unsigned long config = edev->resource[1].start; - unsigned long d_base = edev->resource[2].start; - unsigned long d_len; - - spin_lock_init(&sparc_ebus_dmas[count].info.lock); - d_len = (edev->resource[2].end - - d_base) + 1; - sparc_ebus_dmas[count].info.regs = - ioremap(d_base, d_len); - if (!sparc_ebus_dmas[count].info.regs) - continue; - sparc_ebus_dmas[count].info.flags = 0; - sparc_ebus_dmas[count].info.callback = NULL; - sparc_ebus_dmas[count].info.client_cookie = NULL; - sparc_ebus_dmas[count].info.irq = 0xdeadbeef; - strcpy(sparc_ebus_dmas[count].info.name, "parport"); - if (ebus_dma_register(&sparc_ebus_dmas[count].info)) - continue; - ebus_dma_irq_enable(&sparc_ebus_dmas[count].info, 1); - - /* Configure IRQ to Push Pull, Level Low */ - /* Enable ECP, set bit 2 of the CTR first */ - outb(0x04, base + 0x02); - ns87303_modify(config, PCR, - PCR_EPP_ENABLE | - PCR_IRQ_ODRAIN, - PCR_ECP_ENABLE | - PCR_ECP_CLK_ENA | - PCR_IRQ_POLAR); - - /* CTR bit 5 controls direction of port */ - ns87303_modify(config, PTR, - 0, PTR_LPT_REG_DIR); - - if (parport_pc_probe_port(base, base + 0x400, - edev->irqs[0], - count, ebus->self)) - count++; - } - } - } + of_register_driver(&ecpp_driver, &of_bus_type); - count = parport_isa_probe(count); - - return count; + return 0; } #endif /* !(_ASM_SPARC64_PARPORT_H */