David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 1 | /* parport.h: sparc64 specific parport initialization and dma. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * Copyright (C) 1999 Eddie C. Dost (ecd@skynet.be) |
| 4 | */ |
| 5 | |
| 6 | #ifndef _ASM_SPARC64_PARPORT_H |
| 7 | #define _ASM_SPARC64_PARPORT_H 1 |
| 8 | |
| 9 | #include <asm/ebus.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <asm/ns87303.h> |
David S. Miller | 0fe85d5 | 2007-07-18 23:15:04 -0700 | [diff] [blame] | 11 | #include <asm/of_device.h> |
| 12 | #include <asm/prom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | #define PARPORT_PC_MAX_PORTS PARPORT_MAX |
| 15 | |
Al Viro | 7fbacd5 | 2005-05-04 05:39:32 +0100 | [diff] [blame] | 16 | /* |
| 17 | * While sparc64 doesn't have an ISA DMA API, we provide something that looks |
| 18 | * close enough to make parport_pc happy |
| 19 | */ |
| 20 | #define HAS_DMA |
| 21 | |
David S. Miller | 2ef5507 | 2007-03-08 14:48:36 -0800 | [diff] [blame] | 22 | static DEFINE_SPINLOCK(dma_spin_lock); |
| 23 | |
| 24 | #define claim_dma_lock() \ |
| 25 | ({ unsigned long flags; \ |
| 26 | spin_lock_irqsave(&dma_spin_lock, flags); \ |
| 27 | flags; \ |
| 28 | }) |
| 29 | |
| 30 | #define release_dma_lock(__flags) \ |
| 31 | spin_unlock_irqrestore(&dma_spin_lock, __flags); |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | static struct sparc_ebus_info { |
| 34 | struct ebus_dma_info info; |
| 35 | unsigned int addr; |
| 36 | unsigned int count; |
David S. Miller | 74bd7d0 | 2007-02-28 13:09:34 -0800 | [diff] [blame] | 37 | int lock; |
David S. Miller | 0fe85d5 | 2007-07-18 23:15:04 -0700 | [diff] [blame] | 38 | |
| 39 | struct parport *port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } sparc_ebus_dmas[PARPORT_PC_MAX_PORTS]; |
| 41 | |
David S. Miller | 0fe85d5 | 2007-07-18 23:15:04 -0700 | [diff] [blame] | 42 | static DECLARE_BITMAP(dma_slot_map, PARPORT_PC_MAX_PORTS); |
| 43 | |
David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 44 | static inline int request_dma(unsigned int dmanr, const char *device_id) |
David S. Miller | 74bd7d0 | 2007-02-28 13:09:34 -0800 | [diff] [blame] | 45 | { |
| 46 | if (dmanr >= PARPORT_PC_MAX_PORTS) |
| 47 | return -EINVAL; |
| 48 | if (xchg(&sparc_ebus_dmas[dmanr].lock, 1) != 0) |
| 49 | return -EBUSY; |
| 50 | return 0; |
| 51 | } |
| 52 | |
David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 53 | static inline void free_dma(unsigned int dmanr) |
David S. Miller | 74bd7d0 | 2007-02-28 13:09:34 -0800 | [diff] [blame] | 54 | { |
| 55 | if (dmanr >= PARPORT_PC_MAX_PORTS) { |
| 56 | printk(KERN_WARNING "Trying to free DMA%d\n", dmanr); |
| 57 | return; |
| 58 | } |
| 59 | if (xchg(&sparc_ebus_dmas[dmanr].lock, 0) == 0) { |
| 60 | printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr); |
| 61 | return; |
| 62 | } |
| 63 | } |
| 64 | |
David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 65 | static inline void enable_dma(unsigned int dmanr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
Eddie C. Dost | e3e01d6 | 2005-07-06 15:41:54 -0700 | [diff] [blame] | 67 | ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1); |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info, |
| 70 | sparc_ebus_dmas[dmanr].addr, |
| 71 | sparc_ebus_dmas[dmanr].count)) |
| 72 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
| 74 | |
David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 75 | static inline void disable_dma(unsigned int dmanr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
| 77 | ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0); |
| 78 | } |
| 79 | |
David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 80 | static inline void clear_dma_ff(unsigned int dmanr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
| 82 | /* nothing */ |
| 83 | } |
| 84 | |
David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 85 | static inline void set_dma_mode(unsigned int dmanr, char mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
| 87 | ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE)); |
| 88 | } |
| 89 | |
David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 90 | static inline void set_dma_addr(unsigned int dmanr, unsigned int addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
| 92 | sparc_ebus_dmas[dmanr].addr = addr; |
| 93 | } |
| 94 | |
David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 95 | static inline void set_dma_count(unsigned int dmanr, unsigned int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
| 97 | sparc_ebus_dmas[dmanr].count = count; |
| 98 | } |
| 99 | |
David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 100 | static inline unsigned int get_dma_residue(unsigned int dmanr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
| 102 | return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info); |
| 103 | } |
| 104 | |
David S. Miller | 0fe85d5 | 2007-07-18 23:15:04 -0700 | [diff] [blame] | 105 | static int __devinit ecpp_probe(struct of_device *op, const struct of_device_id *match) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
David S. Miller | 0fe85d5 | 2007-07-18 23:15:04 -0700 | [diff] [blame] | 107 | unsigned long base = op->resource[0].start; |
| 108 | unsigned long config = op->resource[1].start; |
| 109 | unsigned long d_base = op->resource[2].start; |
| 110 | unsigned long d_len; |
| 111 | struct device_node *parent; |
| 112 | struct parport *p; |
| 113 | int slot, err; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 114 | |
David S. Miller | 0fe85d5 | 2007-07-18 23:15:04 -0700 | [diff] [blame] | 115 | parent = op->node->parent; |
| 116 | if (!strcmp(parent->name, "dma")) { |
| 117 | p = parport_pc_probe_port(base, base + 0x400, |
| 118 | op->irqs[0], PARPORT_DMA_NOFIFO, |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 119 | op->dev.parent->parent); |
David S. Miller | 0fe85d5 | 2007-07-18 23:15:04 -0700 | [diff] [blame] | 120 | if (!p) |
| 121 | return -ENOMEM; |
| 122 | dev_set_drvdata(&op->dev, p); |
| 123 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
David S. Miller | 0fe85d5 | 2007-07-18 23:15:04 -0700 | [diff] [blame] | 125 | |
| 126 | for (slot = 0; slot < PARPORT_PC_MAX_PORTS; slot++) { |
| 127 | if (!test_and_set_bit(slot, dma_slot_map)) |
| 128 | break; |
| 129 | } |
| 130 | err = -ENODEV; |
| 131 | if (slot >= PARPORT_PC_MAX_PORTS) |
| 132 | goto out_err; |
| 133 | |
| 134 | spin_lock_init(&sparc_ebus_dmas[slot].info.lock); |
| 135 | |
| 136 | d_len = (op->resource[2].end - d_base) + 1UL; |
| 137 | sparc_ebus_dmas[slot].info.regs = |
| 138 | of_ioremap(&op->resource[2], 0, d_len, "ECPP DMA"); |
| 139 | |
| 140 | if (!sparc_ebus_dmas[slot].info.regs) |
| 141 | goto out_clear_map; |
| 142 | |
| 143 | sparc_ebus_dmas[slot].info.flags = 0; |
| 144 | sparc_ebus_dmas[slot].info.callback = NULL; |
| 145 | sparc_ebus_dmas[slot].info.client_cookie = NULL; |
| 146 | sparc_ebus_dmas[slot].info.irq = 0xdeadbeef; |
| 147 | strcpy(sparc_ebus_dmas[slot].info.name, "parport"); |
| 148 | if (ebus_dma_register(&sparc_ebus_dmas[slot].info)) |
| 149 | goto out_unmap_regs; |
| 150 | |
| 151 | ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 1); |
| 152 | |
| 153 | /* Configure IRQ to Push Pull, Level Low */ |
| 154 | /* Enable ECP, set bit 2 of the CTR first */ |
| 155 | outb(0x04, base + 0x02); |
| 156 | ns87303_modify(config, PCR, |
| 157 | PCR_EPP_ENABLE | |
| 158 | PCR_IRQ_ODRAIN, |
| 159 | PCR_ECP_ENABLE | |
| 160 | PCR_ECP_CLK_ENA | |
| 161 | PCR_IRQ_POLAR); |
| 162 | |
| 163 | /* CTR bit 5 controls direction of port */ |
| 164 | ns87303_modify(config, PTR, |
| 165 | 0, PTR_LPT_REG_DIR); |
| 166 | |
| 167 | p = parport_pc_probe_port(base, base + 0x400, |
| 168 | op->irqs[0], |
| 169 | slot, |
| 170 | op->dev.parent); |
| 171 | err = -ENOMEM; |
| 172 | if (!p) |
| 173 | goto out_disable_irq; |
| 174 | |
| 175 | dev_set_drvdata(&op->dev, p); |
| 176 | |
| 177 | return 0; |
| 178 | |
| 179 | out_disable_irq: |
| 180 | ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0); |
| 181 | ebus_dma_unregister(&sparc_ebus_dmas[slot].info); |
| 182 | |
| 183 | out_unmap_regs: |
| 184 | of_iounmap(&op->resource[2], sparc_ebus_dmas[slot].info.regs, d_len); |
| 185 | |
| 186 | out_clear_map: |
| 187 | clear_bit(slot, dma_slot_map); |
| 188 | |
| 189 | out_err: |
| 190 | return err; |
| 191 | } |
| 192 | |
| 193 | static int __devexit ecpp_remove(struct of_device *op) |
| 194 | { |
| 195 | struct parport *p = dev_get_drvdata(&op->dev); |
| 196 | int slot = p->dma; |
| 197 | |
| 198 | parport_pc_unregister_port(p); |
| 199 | |
| 200 | if (slot != PARPORT_DMA_NOFIFO) { |
| 201 | unsigned long d_base = op->resource[2].start; |
| 202 | unsigned long d_len; |
| 203 | |
| 204 | d_len = (op->resource[2].end - d_base) + 1UL; |
| 205 | |
| 206 | ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0); |
| 207 | ebus_dma_unregister(&sparc_ebus_dmas[slot].info); |
| 208 | of_iounmap(&op->resource[2], |
| 209 | sparc_ebus_dmas[slot].info.regs, |
| 210 | d_len); |
| 211 | clear_bit(slot, dma_slot_map); |
| 212 | } |
| 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | return 0; |
| 215 | } |
| 216 | |
David S. Miller | 0fe85d5 | 2007-07-18 23:15:04 -0700 | [diff] [blame] | 217 | static struct of_device_id ecpp_match[] = { |
| 218 | { |
| 219 | .name = "ecpp", |
| 220 | }, |
| 221 | { |
| 222 | .name = "parallel", |
| 223 | .compatible = "ecpp", |
| 224 | }, |
| 225 | { |
| 226 | .name = "parallel", |
| 227 | .compatible = "ns87317-ecpp", |
| 228 | }, |
| 229 | {}, |
| 230 | }; |
| 231 | |
| 232 | static struct of_platform_driver ecpp_driver = { |
| 233 | .name = "ecpp", |
| 234 | .match_table = ecpp_match, |
| 235 | .probe = ecpp_probe, |
| 236 | .remove = __devexit_p(ecpp_remove), |
| 237 | }; |
| 238 | |
| 239 | static int parport_pc_find_nonpci_ports(int autoirq, int autodma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | { |
David S. Miller | 0fe85d5 | 2007-07-18 23:15:04 -0700 | [diff] [blame] | 241 | of_register_driver(&ecpp_driver, &of_bus_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
David S. Miller | 0fe85d5 | 2007-07-18 23:15:04 -0700 | [diff] [blame] | 243 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | #endif /* !(_ASM_SPARC64_PARPORT_H */ |