0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056 #include "multiface.h"
0057 #include <linux/module.h>
0058 #include <linux/init.h>
0059 #include <linux/parport.h>
0060 #include <linux/delay.h>
0061 #include <linux/mc6821.h>
0062 #include <linux/zorro.h>
0063 #include <linux/interrupt.h>
0064 #include <asm/setup.h>
0065 #include <asm/amigahw.h>
0066 #include <asm/irq.h>
0067 #include <asm/amigaints.h>
0068
0069
0070 #define MAX_MFC 5
0071
0072 #undef DEBUG
0073
0074 static struct parport *this_port[MAX_MFC] = {NULL, };
0075 static volatile int dummy;
0076
0077 #define pia(dev) ((struct pia *)(dev->base))
0078 static struct parport_operations pp_mfc3_ops;
0079
0080 static void mfc3_write_data(struct parport *p, unsigned char data)
0081 {
0082 pr_debug("write_data %c\n", data);
0083
0084 dummy = pia(p)->pprb;
0085
0086 pia(p)->pprb = data;
0087 }
0088
0089 static unsigned char mfc3_read_data(struct parport *p)
0090 {
0091
0092 return pia(p)->pprb;
0093 }
0094
0095 static unsigned char control_pc_to_mfc3(unsigned char control)
0096 {
0097 unsigned char ret = 32|64;
0098
0099 if (control & PARPORT_CONTROL_SELECT)
0100 ret &= ~32;
0101 if (control & PARPORT_CONTROL_INIT)
0102 ret |= 128;
0103 if (control & PARPORT_CONTROL_AUTOFD)
0104 ret &= ~64;
0105 if (control & PARPORT_CONTROL_STROBE)
0106 ;
0107 return ret;
0108 }
0109
0110 static unsigned char control_mfc3_to_pc(unsigned char control)
0111 {
0112 unsigned char ret = PARPORT_CONTROL_STROBE
0113 | PARPORT_CONTROL_AUTOFD | PARPORT_CONTROL_SELECT;
0114
0115 if (control & 128)
0116 ret |= PARPORT_CONTROL_INIT;
0117 if (control & 64)
0118 ret &= ~PARPORT_CONTROL_AUTOFD;
0119 if (control & 32)
0120 ret &= ~PARPORT_CONTROL_SELECT;
0121 return ret;
0122 }
0123
0124 static void mfc3_write_control(struct parport *p, unsigned char control)
0125 {
0126 pr_debug("write_control %02x\n", control);
0127 pia(p)->ppra = (pia(p)->ppra & 0x1f) | control_pc_to_mfc3(control);
0128 }
0129
0130 static unsigned char mfc3_read_control( struct parport *p)
0131 {
0132 pr_debug("read_control\n");
0133 return control_mfc3_to_pc(pia(p)->ppra & 0xe0);
0134 }
0135
0136 static unsigned char mfc3_frob_control( struct parport *p, unsigned char mask, unsigned char val)
0137 {
0138 unsigned char old;
0139
0140 pr_debug("frob_control mask %02x, value %02x\n", mask, val);
0141 old = mfc3_read_control(p);
0142 mfc3_write_control(p, (old & ~mask) ^ val);
0143 return old;
0144 }
0145
0146 static unsigned char status_mfc3_to_pc(unsigned char status)
0147 {
0148 unsigned char ret = PARPORT_STATUS_BUSY;
0149
0150 if (status & 1)
0151 ret &= ~PARPORT_STATUS_BUSY;
0152 if (status & 2)
0153 ret |= PARPORT_STATUS_PAPEROUT;
0154 if (status & 4)
0155 ret |= PARPORT_STATUS_SELECT;
0156 if (status & 8)
0157 ret |= PARPORT_STATUS_ACK;
0158 if (status & 16)
0159 ret |= PARPORT_STATUS_ERROR;
0160
0161 return ret;
0162 }
0163
0164 static unsigned char mfc3_read_status(struct parport *p)
0165 {
0166 unsigned char status;
0167
0168 status = status_mfc3_to_pc(pia(p)->ppra & 0x1f);
0169 pr_debug("read_status %02x\n", status);
0170 return status;
0171 }
0172
0173 static int use_cnt;
0174
0175 static irqreturn_t mfc3_interrupt(int irq, void *dev_id)
0176 {
0177 int i;
0178
0179 for( i = 0; i < MAX_MFC; i++)
0180 if (this_port[i] != NULL)
0181 if (pia(this_port[i])->crb & 128) {
0182 dummy = pia(this_port[i])->pprb;
0183 parport_generic_irq(this_port[i]);
0184 }
0185 return IRQ_HANDLED;
0186 }
0187
0188 static void mfc3_enable_irq(struct parport *p)
0189 {
0190 pia(p)->crb |= PIA_C1_ENABLE_IRQ;
0191 }
0192
0193 static void mfc3_disable_irq(struct parport *p)
0194 {
0195 pia(p)->crb &= ~PIA_C1_ENABLE_IRQ;
0196 }
0197
0198 static void mfc3_data_forward(struct parport *p)
0199 {
0200 pr_debug("forward\n");
0201 pia(p)->crb &= ~PIA_DDR;
0202 pia(p)->pddrb = 255;
0203 pia(p)->crb |= PIA_DDR;
0204 }
0205
0206 static void mfc3_data_reverse(struct parport *p)
0207 {
0208 pr_debug("reverse\n");
0209 pia(p)->crb &= ~PIA_DDR;
0210 pia(p)->pddrb = 0;
0211 pia(p)->crb |= PIA_DDR;
0212 }
0213
0214 static void mfc3_init_state(struct pardevice *dev, struct parport_state *s)
0215 {
0216 s->u.amiga.data = 0;
0217 s->u.amiga.datadir = 255;
0218 s->u.amiga.status = 0;
0219 s->u.amiga.statusdir = 0xe0;
0220 }
0221
0222 static void mfc3_save_state(struct parport *p, struct parport_state *s)
0223 {
0224 s->u.amiga.data = pia(p)->pprb;
0225 pia(p)->crb &= ~PIA_DDR;
0226 s->u.amiga.datadir = pia(p)->pddrb;
0227 pia(p)->crb |= PIA_DDR;
0228 s->u.amiga.status = pia(p)->ppra;
0229 pia(p)->cra &= ~PIA_DDR;
0230 s->u.amiga.statusdir = pia(p)->pddrb;
0231 pia(p)->cra |= PIA_DDR;
0232 }
0233
0234 static void mfc3_restore_state(struct parport *p, struct parport_state *s)
0235 {
0236 pia(p)->pprb = s->u.amiga.data;
0237 pia(p)->crb &= ~PIA_DDR;
0238 pia(p)->pddrb = s->u.amiga.datadir;
0239 pia(p)->crb |= PIA_DDR;
0240 pia(p)->ppra = s->u.amiga.status;
0241 pia(p)->cra &= ~PIA_DDR;
0242 pia(p)->pddrb = s->u.amiga.statusdir;
0243 pia(p)->cra |= PIA_DDR;
0244 }
0245
0246 static struct parport_operations pp_mfc3_ops = {
0247 .write_data = mfc3_write_data,
0248 .read_data = mfc3_read_data,
0249
0250 .write_control = mfc3_write_control,
0251 .read_control = mfc3_read_control,
0252 .frob_control = mfc3_frob_control,
0253
0254 .read_status = mfc3_read_status,
0255
0256 .enable_irq = mfc3_enable_irq,
0257 .disable_irq = mfc3_disable_irq,
0258
0259 .data_forward = mfc3_data_forward,
0260 .data_reverse = mfc3_data_reverse,
0261
0262 .init_state = mfc3_init_state,
0263 .save_state = mfc3_save_state,
0264 .restore_state = mfc3_restore_state,
0265
0266 .epp_write_data = parport_ieee1284_epp_write_data,
0267 .epp_read_data = parport_ieee1284_epp_read_data,
0268 .epp_write_addr = parport_ieee1284_epp_write_addr,
0269 .epp_read_addr = parport_ieee1284_epp_read_addr,
0270
0271 .ecp_write_data = parport_ieee1284_ecp_write_data,
0272 .ecp_read_data = parport_ieee1284_ecp_read_data,
0273 .ecp_write_addr = parport_ieee1284_ecp_write_addr,
0274
0275 .compat_write_data = parport_ieee1284_write_compat,
0276 .nibble_read_data = parport_ieee1284_read_nibble,
0277 .byte_read_data = parport_ieee1284_read_byte,
0278
0279 .owner = THIS_MODULE,
0280 };
0281
0282
0283
0284 static int __init parport_mfc3_init(void)
0285 {
0286 struct parport *p;
0287 int pias = 0;
0288 struct pia *pp;
0289 struct zorro_dev *z = NULL;
0290
0291 if (!MACH_IS_AMIGA)
0292 return -ENODEV;
0293
0294 while ((z = zorro_find_device(ZORRO_PROD_BSC_MULTIFACE_III, z))) {
0295 unsigned long piabase = z->resource.start+PIABASE;
0296 if (!request_mem_region(piabase, sizeof(struct pia), "PIA"))
0297 continue;
0298
0299 pp = ZTWO_VADDR(piabase);
0300 pp->crb = 0;
0301 pp->pddrb = 255;
0302 pp->crb = PIA_DDR|32|8;
0303 dummy = pp->pddrb;
0304 pp->cra = 0;
0305 pp->pddra = 0xe0;
0306 pp->cra = PIA_DDR;
0307 pp->ppra = 0;
0308 udelay(10);
0309 pp->ppra = 128;
0310 p = parport_register_port((unsigned long)pp, IRQ_AMIGA_PORTS,
0311 PARPORT_DMA_NONE, &pp_mfc3_ops);
0312 if (!p)
0313 goto out_port;
0314
0315 if (p->irq != PARPORT_IRQ_NONE) {
0316 if (use_cnt++ == 0)
0317 if (request_irq(IRQ_AMIGA_PORTS, mfc3_interrupt, IRQF_SHARED, p->name, &pp_mfc3_ops))
0318 goto out_irq;
0319 }
0320 p->dev = &z->dev;
0321
0322 this_port[pias++] = p;
0323 pr_info("%s: Multiface III port using irq\n", p->name);
0324
0325
0326 p->private_data = (void *)piabase;
0327 parport_announce_port (p);
0328
0329 if (pias >= MAX_MFC)
0330 break;
0331 continue;
0332
0333 out_irq:
0334 parport_put_port(p);
0335 out_port:
0336 release_mem_region(piabase, sizeof(struct pia));
0337 }
0338
0339 return pias ? 0 : -ENODEV;
0340 }
0341
0342 static void __exit parport_mfc3_exit(void)
0343 {
0344 int i;
0345
0346 for (i = 0; i < MAX_MFC; i++) {
0347 if (!this_port[i])
0348 continue;
0349 parport_remove_port(this_port[i]);
0350 if (this_port[i]->irq != PARPORT_IRQ_NONE) {
0351 if (--use_cnt == 0)
0352 free_irq(IRQ_AMIGA_PORTS, &pp_mfc3_ops);
0353 }
0354 release_mem_region(ZTWO_PADDR(this_port[i]->private_data), sizeof(struct pia));
0355 parport_put_port(this_port[i]);
0356 }
0357 }
0358
0359
0360 MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
0361 MODULE_DESCRIPTION("Parport Driver for Multiface 3 expansion cards Parallel Port");
0362 MODULE_LICENSE("GPL");
0363
0364 module_init(parport_mfc3_init)
0365 module_exit(parport_mfc3_exit)