0001
0002
0003
0004
0005
0006
0007 #ifndef _ASM_SPARC64_PARPORT_H
0008 #define _ASM_SPARC64_PARPORT_H 1
0009
0010 #include <linux/of_device.h>
0011
0012 #include <asm/ebus_dma.h>
0013 #include <asm/ns87303.h>
0014 #include <asm/prom.h>
0015
0016 #define PARPORT_PC_MAX_PORTS PARPORT_MAX
0017
0018
0019
0020
0021
0022 #define HAS_DMA
0023
0024 #ifdef CONFIG_PARPORT_PC_FIFO
0025 static DEFINE_SPINLOCK(dma_spin_lock);
0026
0027 #define claim_dma_lock() \
0028 ({ unsigned long flags; \
0029 spin_lock_irqsave(&dma_spin_lock, flags); \
0030 flags; \
0031 })
0032
0033 #define release_dma_lock(__flags) \
0034 spin_unlock_irqrestore(&dma_spin_lock, __flags);
0035 #endif
0036
0037 static struct sparc_ebus_info {
0038 struct ebus_dma_info info;
0039 unsigned int addr;
0040 unsigned int count;
0041 int lock;
0042
0043 struct parport *port;
0044 } sparc_ebus_dmas[PARPORT_PC_MAX_PORTS];
0045
0046 static DECLARE_BITMAP(dma_slot_map, PARPORT_PC_MAX_PORTS);
0047
0048 static inline int request_dma(unsigned int dmanr, const char *device_id)
0049 {
0050 if (dmanr >= PARPORT_PC_MAX_PORTS)
0051 return -EINVAL;
0052 if (xchg(&sparc_ebus_dmas[dmanr].lock, 1) != 0)
0053 return -EBUSY;
0054 return 0;
0055 }
0056
0057 static inline void free_dma(unsigned int dmanr)
0058 {
0059 if (dmanr >= PARPORT_PC_MAX_PORTS) {
0060 printk(KERN_WARNING "Trying to free DMA%d\n", dmanr);
0061 return;
0062 }
0063 if (xchg(&sparc_ebus_dmas[dmanr].lock, 0) == 0) {
0064 printk(KERN_WARNING "Trying to free free DMA%d\n", dmanr);
0065 return;
0066 }
0067 }
0068
0069 static inline void enable_dma(unsigned int dmanr)
0070 {
0071 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 1);
0072
0073 if (ebus_dma_request(&sparc_ebus_dmas[dmanr].info,
0074 sparc_ebus_dmas[dmanr].addr,
0075 sparc_ebus_dmas[dmanr].count))
0076 BUG();
0077 }
0078
0079 static inline void disable_dma(unsigned int dmanr)
0080 {
0081 ebus_dma_enable(&sparc_ebus_dmas[dmanr].info, 0);
0082 }
0083
0084 static inline void clear_dma_ff(unsigned int dmanr)
0085 {
0086
0087 }
0088
0089 static inline void set_dma_mode(unsigned int dmanr, char mode)
0090 {
0091 ebus_dma_prepare(&sparc_ebus_dmas[dmanr].info, (mode != DMA_MODE_WRITE));
0092 }
0093
0094 static inline void set_dma_addr(unsigned int dmanr, unsigned int addr)
0095 {
0096 sparc_ebus_dmas[dmanr].addr = addr;
0097 }
0098
0099 static inline void set_dma_count(unsigned int dmanr, unsigned int count)
0100 {
0101 sparc_ebus_dmas[dmanr].count = count;
0102 }
0103
0104 static inline unsigned int get_dma_residue(unsigned int dmanr)
0105 {
0106 return ebus_dma_residue(&sparc_ebus_dmas[dmanr].info);
0107 }
0108
0109 static int ecpp_probe(struct platform_device *op)
0110 {
0111 unsigned long base = op->resource[0].start;
0112 unsigned long config = op->resource[1].start;
0113 unsigned long d_base = op->resource[2].start;
0114 unsigned long d_len;
0115 struct device_node *parent;
0116 struct parport *p;
0117 int slot, err;
0118
0119 parent = op->dev.of_node->parent;
0120 if (of_node_name_eq(parent, "dma")) {
0121 p = parport_pc_probe_port(base, base + 0x400,
0122 op->archdata.irqs[0], PARPORT_DMA_NOFIFO,
0123 op->dev.parent->parent, 0);
0124 if (!p)
0125 return -ENOMEM;
0126 dev_set_drvdata(&op->dev, p);
0127 return 0;
0128 }
0129
0130 for (slot = 0; slot < PARPORT_PC_MAX_PORTS; slot++) {
0131 if (!test_and_set_bit(slot, dma_slot_map))
0132 break;
0133 }
0134 err = -ENODEV;
0135 if (slot >= PARPORT_PC_MAX_PORTS)
0136 goto out_err;
0137
0138 spin_lock_init(&sparc_ebus_dmas[slot].info.lock);
0139
0140 d_len = (op->resource[2].end - d_base) + 1UL;
0141 sparc_ebus_dmas[slot].info.regs =
0142 of_ioremap(&op->resource[2], 0, d_len, "ECPP DMA");
0143
0144 if (!sparc_ebus_dmas[slot].info.regs)
0145 goto out_clear_map;
0146
0147 sparc_ebus_dmas[slot].info.flags = 0;
0148 sparc_ebus_dmas[slot].info.callback = NULL;
0149 sparc_ebus_dmas[slot].info.client_cookie = NULL;
0150 sparc_ebus_dmas[slot].info.irq = 0xdeadbeef;
0151 strcpy(sparc_ebus_dmas[slot].info.name, "parport");
0152 if (ebus_dma_register(&sparc_ebus_dmas[slot].info))
0153 goto out_unmap_regs;
0154
0155 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 1);
0156
0157
0158
0159 outb(0x04, base + 0x02);
0160 ns87303_modify(config, PCR,
0161 PCR_EPP_ENABLE |
0162 PCR_IRQ_ODRAIN,
0163 PCR_ECP_ENABLE |
0164 PCR_ECP_CLK_ENA |
0165 PCR_IRQ_POLAR);
0166
0167
0168 ns87303_modify(config, PTR,
0169 0, PTR_LPT_REG_DIR);
0170
0171 p = parport_pc_probe_port(base, base + 0x400,
0172 op->archdata.irqs[0],
0173 slot,
0174 op->dev.parent,
0175 0);
0176 err = -ENOMEM;
0177 if (!p)
0178 goto out_disable_irq;
0179
0180 dev_set_drvdata(&op->dev, p);
0181
0182 return 0;
0183
0184 out_disable_irq:
0185 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
0186 ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
0187
0188 out_unmap_regs:
0189 of_iounmap(&op->resource[2], sparc_ebus_dmas[slot].info.regs, d_len);
0190
0191 out_clear_map:
0192 clear_bit(slot, dma_slot_map);
0193
0194 out_err:
0195 return err;
0196 }
0197
0198 static int ecpp_remove(struct platform_device *op)
0199 {
0200 struct parport *p = dev_get_drvdata(&op->dev);
0201 int slot = p->dma;
0202
0203 parport_pc_unregister_port(p);
0204
0205 if (slot != PARPORT_DMA_NOFIFO) {
0206 unsigned long d_base = op->resource[2].start;
0207 unsigned long d_len;
0208
0209 d_len = (op->resource[2].end - d_base) + 1UL;
0210
0211 ebus_dma_irq_enable(&sparc_ebus_dmas[slot].info, 0);
0212 ebus_dma_unregister(&sparc_ebus_dmas[slot].info);
0213 of_iounmap(&op->resource[2],
0214 sparc_ebus_dmas[slot].info.regs,
0215 d_len);
0216 clear_bit(slot, dma_slot_map);
0217 }
0218
0219 return 0;
0220 }
0221
0222 static const struct of_device_id ecpp_match[] = {
0223 {
0224 .name = "ecpp",
0225 },
0226 {
0227 .name = "parallel",
0228 .compatible = "ecpp",
0229 },
0230 {
0231 .name = "parallel",
0232 .compatible = "ns87317-ecpp",
0233 },
0234 {
0235 .name = "parallel",
0236 .compatible = "pnpALI,1533,3",
0237 },
0238 {},
0239 };
0240
0241 static struct platform_driver ecpp_driver = {
0242 .driver = {
0243 .name = "ecpp",
0244 .of_match_table = ecpp_match,
0245 },
0246 .probe = ecpp_probe,
0247 .remove = ecpp_remove,
0248 };
0249
0250 static int parport_pc_find_nonpci_ports(int autoirq, int autodma)
0251 {
0252 return platform_driver_register(&ecpp_driver);
0253 }
0254
0255 #endif