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
0057
0058
0059
0060
0061
0062 #if !defined(DEBUG_PARPORT_IP32)
0063 # define DEBUG_PARPORT_IP32 0
0064 #endif
0065
0066
0067
0068
0069
0070
0071 #if DEBUG_PARPORT_IP32 == 1
0072 # warning DEBUG_PARPORT_IP32 == 1
0073 #elif DEBUG_PARPORT_IP32 == 2
0074 # warning DEBUG_PARPORT_IP32 == 2
0075 #elif DEBUG_PARPORT_IP32 >= 3
0076 # warning DEBUG_PARPORT_IP32 >= 3
0077 # if !defined(DEBUG)
0078 # define DEBUG
0079 # endif
0080 #endif
0081
0082 #include <linux/completion.h>
0083 #include <linux/delay.h>
0084 #include <linux/dma-mapping.h>
0085 #include <linux/err.h>
0086 #include <linux/init.h>
0087 #include <linux/interrupt.h>
0088 #include <linux/jiffies.h>
0089 #include <linux/kernel.h>
0090 #include <linux/module.h>
0091 #include <linux/parport.h>
0092 #include <linux/sched/signal.h>
0093 #include <linux/slab.h>
0094 #include <linux/spinlock.h>
0095 #include <linux/stddef.h>
0096 #include <linux/types.h>
0097 #include <asm/io.h>
0098 #include <asm/ip32/ip32_ints.h>
0099 #include <asm/ip32/mace.h>
0100
0101
0102
0103
0104 #if DEBUG_PARPORT_IP32 >= 1
0105 # define DEFAULT_VERBOSE_PROBING 1
0106 #else
0107 # define DEFAULT_VERBOSE_PROBING 0
0108 #endif
0109
0110
0111 #define PPIP32 "parport_ip32: "
0112
0113
0114
0115
0116
0117
0118
0119 #define PARPORT_IP32_ENABLE_IRQ (1U << 0)
0120 #define PARPORT_IP32_ENABLE_DMA (1U << 1)
0121 #define PARPORT_IP32_ENABLE_SPP (1U << 2)
0122 #define PARPORT_IP32_ENABLE_EPP (1U << 3)
0123 #define PARPORT_IP32_ENABLE_ECP (1U << 4)
0124 static unsigned int features = ~0U;
0125 static bool verbose_probing = DEFAULT_VERBOSE_PROBING;
0126
0127
0128 static struct parport *this_port;
0129
0130
0131 #define FIFO_NFAULT_TIMEOUT 100
0132 #define FIFO_POLLING_INTERVAL 50
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155 struct parport_ip32_regs {
0156 void __iomem *data;
0157 void __iomem *dsr;
0158 void __iomem *dcr;
0159 void __iomem *eppAddr;
0160 void __iomem *eppData0;
0161 void __iomem *eppData1;
0162 void __iomem *eppData2;
0163 void __iomem *eppData3;
0164 void __iomem *ecpAFifo;
0165 void __iomem *fifo;
0166 void __iomem *cnfgA;
0167 void __iomem *cnfgB;
0168 void __iomem *ecr;
0169 };
0170
0171
0172 #define DSR_nBUSY (1U << 7)
0173 #define DSR_nACK (1U << 6)
0174 #define DSR_PERROR (1U << 5)
0175 #define DSR_SELECT (1U << 4)
0176 #define DSR_nFAULT (1U << 3)
0177 #define DSR_nPRINT (1U << 2)
0178
0179 #define DSR_TIMEOUT (1U << 0)
0180
0181
0182
0183 #define DCR_DIR (1U << 5)
0184 #define DCR_IRQ (1U << 4)
0185 #define DCR_SELECT (1U << 3)
0186 #define DCR_nINIT (1U << 2)
0187 #define DCR_AUTOFD (1U << 1)
0188 #define DCR_STROBE (1U << 0)
0189
0190
0191 #define CNFGA_IRQ (1U << 7)
0192 #define CNFGA_ID_MASK ((1U << 6) | (1U << 5) | (1U << 4))
0193 #define CNFGA_ID_SHIFT 4
0194 #define CNFGA_ID_16 (00U << CNFGA_ID_SHIFT)
0195 #define CNFGA_ID_8 (01U << CNFGA_ID_SHIFT)
0196 #define CNFGA_ID_32 (02U << CNFGA_ID_SHIFT)
0197
0198 #define CNFGA_nBYTEINTRANS (1U << 2)
0199 #define CNFGA_PWORDLEFT ((1U << 1) | (1U << 0))
0200
0201
0202 #define CNFGB_COMPRESS (1U << 7)
0203 #define CNFGB_INTRVAL (1U << 6)
0204 #define CNFGB_IRQ_MASK ((1U << 5) | (1U << 4) | (1U << 3))
0205 #define CNFGB_IRQ_SHIFT 3
0206 #define CNFGB_DMA_MASK ((1U << 2) | (1U << 1) | (1U << 0))
0207 #define CNFGB_DMA_SHIFT 0
0208
0209
0210 #define ECR_MODE_MASK ((1U << 7) | (1U << 6) | (1U << 5))
0211 #define ECR_MODE_SHIFT 5
0212 #define ECR_MODE_SPP (00U << ECR_MODE_SHIFT)
0213 #define ECR_MODE_PS2 (01U << ECR_MODE_SHIFT)
0214 #define ECR_MODE_PPF (02U << ECR_MODE_SHIFT)
0215 #define ECR_MODE_ECP (03U << ECR_MODE_SHIFT)
0216 #define ECR_MODE_EPP (04U << ECR_MODE_SHIFT)
0217
0218 #define ECR_MODE_TST (06U << ECR_MODE_SHIFT)
0219 #define ECR_MODE_CFG (07U << ECR_MODE_SHIFT)
0220 #define ECR_nERRINTR (1U << 4)
0221 #define ECR_DMAEN (1U << 3)
0222 #define ECR_SERVINTR (1U << 2)
0223 #define ECR_F_FULL (1U << 1)
0224 #define ECR_F_EMPTY (1U << 0)
0225
0226
0227
0228
0229
0230
0231
0232
0233 enum parport_ip32_irq_mode { PARPORT_IP32_IRQ_FWD, PARPORT_IP32_IRQ_HERE };
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249 struct parport_ip32_private {
0250 struct parport_ip32_regs regs;
0251 unsigned int dcr_cache;
0252 unsigned int dcr_writable;
0253 unsigned int pword;
0254 unsigned int fifo_depth;
0255 unsigned int readIntrThreshold;
0256 unsigned int writeIntrThreshold;
0257 enum parport_ip32_irq_mode irq_mode;
0258 struct completion irq_complete;
0259 };
0260
0261
0262
0263
0264
0265
0266
0267
0268 #if DEBUG_PARPORT_IP32 >= 1
0269 # define pr_debug1(...) printk(KERN_DEBUG __VA_ARGS__)
0270 #else
0271 # define pr_debug1(...) do { } while (0)
0272 #endif
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285 #define __pr_trace(pr, p, fmt, ...) \
0286 pr("%s: %s" fmt "\n", \
0287 ({ const struct parport *__p = (p); \
0288 __p ? __p->name : "parport_ip32"; }), \
0289 __func__ , ##__VA_ARGS__)
0290 #define pr_trace(p, fmt, ...) __pr_trace(pr_debug, p, fmt , ##__VA_ARGS__)
0291 #define pr_trace1(p, fmt, ...) __pr_trace(pr_debug1, p, fmt , ##__VA_ARGS__)
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301 #define __pr_probe(...) \
0302 do { if (verbose_probing) printk(__VA_ARGS__); } while (0)
0303 #define pr_probe(p, fmt, ...) \
0304 __pr_probe(KERN_INFO PPIP32 "0x%lx: " fmt, (p)->base , ##__VA_ARGS__)
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317 #if DEBUG_PARPORT_IP32 >= 2
0318 static void parport_ip32_dump_state(struct parport *p, char *str,
0319 unsigned int show_ecp_config)
0320 {
0321 struct parport_ip32_private * const priv = p->physport->private_data;
0322 unsigned int i;
0323
0324 printk(KERN_DEBUG PPIP32 "%s: state (%s):\n", p->name, str);
0325 {
0326 static const char ecr_modes[8][4] = {"SPP", "PS2", "PPF",
0327 "ECP", "EPP", "???",
0328 "TST", "CFG"};
0329 unsigned int ecr = readb(priv->regs.ecr);
0330 printk(KERN_DEBUG PPIP32 " ecr=0x%02x", ecr);
0331 pr_cont(" %s",
0332 ecr_modes[(ecr & ECR_MODE_MASK) >> ECR_MODE_SHIFT]);
0333 if (ecr & ECR_nERRINTR)
0334 pr_cont(",nErrIntrEn");
0335 if (ecr & ECR_DMAEN)
0336 pr_cont(",dmaEn");
0337 if (ecr & ECR_SERVINTR)
0338 pr_cont(",serviceIntr");
0339 if (ecr & ECR_F_FULL)
0340 pr_cont(",f_full");
0341 if (ecr & ECR_F_EMPTY)
0342 pr_cont(",f_empty");
0343 pr_cont("\n");
0344 }
0345 if (show_ecp_config) {
0346 unsigned int oecr, cnfgA, cnfgB;
0347 oecr = readb(priv->regs.ecr);
0348 writeb(ECR_MODE_PS2, priv->regs.ecr);
0349 writeb(ECR_MODE_CFG, priv->regs.ecr);
0350 cnfgA = readb(priv->regs.cnfgA);
0351 cnfgB = readb(priv->regs.cnfgB);
0352 writeb(ECR_MODE_PS2, priv->regs.ecr);
0353 writeb(oecr, priv->regs.ecr);
0354 printk(KERN_DEBUG PPIP32 " cnfgA=0x%02x", cnfgA);
0355 pr_cont(" ISA-%s", (cnfgA & CNFGA_IRQ) ? "Level" : "Pulses");
0356 switch (cnfgA & CNFGA_ID_MASK) {
0357 case CNFGA_ID_8:
0358 pr_cont(",8 bits");
0359 break;
0360 case CNFGA_ID_16:
0361 pr_cont(",16 bits");
0362 break;
0363 case CNFGA_ID_32:
0364 pr_cont(",32 bits");
0365 break;
0366 default:
0367 pr_cont(",unknown ID");
0368 break;
0369 }
0370 if (!(cnfgA & CNFGA_nBYTEINTRANS))
0371 pr_cont(",ByteInTrans");
0372 if ((cnfgA & CNFGA_ID_MASK) != CNFGA_ID_8)
0373 pr_cont(",%d byte%s left",
0374 cnfgA & CNFGA_PWORDLEFT,
0375 ((cnfgA & CNFGA_PWORDLEFT) > 1) ? "s" : "");
0376 pr_cont("\n");
0377 printk(KERN_DEBUG PPIP32 " cnfgB=0x%02x", cnfgB);
0378 pr_cont(" irq=%u,dma=%u",
0379 (cnfgB & CNFGB_IRQ_MASK) >> CNFGB_IRQ_SHIFT,
0380 (cnfgB & CNFGB_DMA_MASK) >> CNFGB_DMA_SHIFT);
0381 pr_cont(",intrValue=%d", !!(cnfgB & CNFGB_INTRVAL));
0382 if (cnfgB & CNFGB_COMPRESS)
0383 pr_cont(",compress");
0384 pr_cont("\n");
0385 }
0386 for (i = 0; i < 2; i++) {
0387 unsigned int dcr = i ? priv->dcr_cache : readb(priv->regs.dcr);
0388 printk(KERN_DEBUG PPIP32 " dcr(%s)=0x%02x",
0389 i ? "soft" : "hard", dcr);
0390 pr_cont(" %s", (dcr & DCR_DIR) ? "rev" : "fwd");
0391 if (dcr & DCR_IRQ)
0392 pr_cont(",ackIntEn");
0393 if (!(dcr & DCR_SELECT))
0394 pr_cont(",nSelectIn");
0395 if (dcr & DCR_nINIT)
0396 pr_cont(",nInit");
0397 if (!(dcr & DCR_AUTOFD))
0398 pr_cont(",nAutoFD");
0399 if (!(dcr & DCR_STROBE))
0400 pr_cont(",nStrobe");
0401 pr_cont("\n");
0402 }
0403 #define sep (f++ ? ',' : ' ')
0404 {
0405 unsigned int f = 0;
0406 unsigned int dsr = readb(priv->regs.dsr);
0407 printk(KERN_DEBUG PPIP32 " dsr=0x%02x", dsr);
0408 if (!(dsr & DSR_nBUSY))
0409 pr_cont("%cBusy", sep);
0410 if (dsr & DSR_nACK)
0411 pr_cont("%cnAck", sep);
0412 if (dsr & DSR_PERROR)
0413 pr_cont("%cPError", sep);
0414 if (dsr & DSR_SELECT)
0415 pr_cont("%cSelect", sep);
0416 if (dsr & DSR_nFAULT)
0417 pr_cont("%cnFault", sep);
0418 if (!(dsr & DSR_nPRINT))
0419 pr_cont("%c(Print)", sep);
0420 if (dsr & DSR_TIMEOUT)
0421 pr_cont("%cTimeout", sep);
0422 pr_cont("\n");
0423 }
0424 #undef sep
0425 }
0426 #else
0427 #define parport_ip32_dump_state(...) do { } while (0)
0428 #endif
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440 #if DEBUG_PARPORT_IP32 >= 1
0441 #define CHECK_EXTRA_BITS(p, b, m) \
0442 do { \
0443 unsigned int __b = (b), __m = (m); \
0444 if (__b & ~__m) \
0445 pr_debug1(PPIP32 "%s: extra bits in %s(%s): " \
0446 "0x%02x/0x%02x\n", \
0447 (p)->name, __func__, #b, __b, __m); \
0448 } while (0)
0449 #else
0450 #define CHECK_EXTRA_BITS(...) do { } while (0)
0451 #endif
0452
0453
0454
0455
0456
0457
0458
0459
0460
0461
0462
0463
0464
0465
0466 struct parport_ip32_dma_data {
0467 enum dma_data_direction dir;
0468 dma_addr_t buf;
0469 dma_addr_t next;
0470 size_t len;
0471 size_t left;
0472 unsigned int ctx;
0473 unsigned int irq_on;
0474 spinlock_t lock;
0475 };
0476 static struct parport_ip32_dma_data parport_ip32_dma;
0477
0478
0479
0480
0481
0482
0483
0484
0485 static void parport_ip32_dma_setup_context(unsigned int limit)
0486 {
0487 unsigned long flags;
0488
0489 spin_lock_irqsave(&parport_ip32_dma.lock, flags);
0490 if (parport_ip32_dma.left > 0) {
0491
0492
0493
0494 volatile u64 __iomem *ctxreg = (parport_ip32_dma.ctx == 0) ?
0495 &mace->perif.ctrl.parport.context_a :
0496 &mace->perif.ctrl.parport.context_b;
0497 u64 count;
0498 u64 ctxval;
0499 if (parport_ip32_dma.left <= limit) {
0500 count = parport_ip32_dma.left;
0501 ctxval = MACEPAR_CONTEXT_LASTFLAG;
0502 } else {
0503 count = limit;
0504 ctxval = 0;
0505 }
0506
0507 pr_trace(NULL,
0508 "(%u): 0x%04x:0x%04x, %u -> %u%s",
0509 limit,
0510 (unsigned int)parport_ip32_dma.buf,
0511 (unsigned int)parport_ip32_dma.next,
0512 (unsigned int)count,
0513 parport_ip32_dma.ctx, ctxval ? "*" : "");
0514
0515 ctxval |= parport_ip32_dma.next &
0516 MACEPAR_CONTEXT_BASEADDR_MASK;
0517 ctxval |= ((count - 1) << MACEPAR_CONTEXT_DATALEN_SHIFT) &
0518 MACEPAR_CONTEXT_DATALEN_MASK;
0519 writeq(ctxval, ctxreg);
0520 parport_ip32_dma.next += count;
0521 parport_ip32_dma.left -= count;
0522 parport_ip32_dma.ctx ^= 1U;
0523 }
0524
0525
0526
0527 if (parport_ip32_dma.left == 0 && parport_ip32_dma.irq_on) {
0528 pr_debug(PPIP32 "IRQ off (ctx)\n");
0529 disable_irq_nosync(MACEISA_PAR_CTXA_IRQ);
0530 disable_irq_nosync(MACEISA_PAR_CTXB_IRQ);
0531 parport_ip32_dma.irq_on = 0;
0532 }
0533 spin_unlock_irqrestore(&parport_ip32_dma.lock, flags);
0534 }
0535
0536
0537
0538
0539
0540
0541 static irqreturn_t parport_ip32_dma_interrupt(int irq, void *dev_id)
0542 {
0543 if (parport_ip32_dma.left)
0544 pr_trace(NULL, "(%d): ctx=%d", irq, parport_ip32_dma.ctx);
0545 parport_ip32_dma_setup_context(MACEPAR_CONTEXT_DATA_BOUND);
0546 return IRQ_HANDLED;
0547 }
0548
0549 #if DEBUG_PARPORT_IP32
0550 static irqreturn_t parport_ip32_merr_interrupt(int irq, void *dev_id)
0551 {
0552 pr_trace1(NULL, "(%d)", irq);
0553 return IRQ_HANDLED;
0554 }
0555 #endif
0556
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566
0567 static int parport_ip32_dma_start(struct parport *p,
0568 enum dma_data_direction dir, void *addr, size_t count)
0569 {
0570 unsigned int limit;
0571 u64 ctrl;
0572
0573 pr_trace(NULL, "(%d, %lu)", dir, (unsigned long)count);
0574
0575
0576
0577 BUG_ON(dir != DMA_TO_DEVICE);
0578
0579
0580 ctrl = MACEPAR_CTLSTAT_RESET;
0581 writeq(ctrl, &mace->perif.ctrl.parport.cntlstat);
0582
0583
0584 if (!parport_ip32_dma.irq_on) {
0585 WARN_ON(1);
0586 enable_irq(MACEISA_PAR_CTXA_IRQ);
0587 enable_irq(MACEISA_PAR_CTXB_IRQ);
0588 parport_ip32_dma.irq_on = 1;
0589 }
0590
0591
0592 parport_ip32_dma.dir = dir;
0593 parport_ip32_dma.buf = dma_map_single(&p->bus_dev, addr, count, dir);
0594 parport_ip32_dma.len = count;
0595 parport_ip32_dma.next = parport_ip32_dma.buf;
0596 parport_ip32_dma.left = parport_ip32_dma.len;
0597 parport_ip32_dma.ctx = 0;
0598
0599
0600 ctrl = (dir == DMA_TO_DEVICE) ? 0 : MACEPAR_CTLSTAT_DIRECTION;
0601 writeq(ctrl, &mace->perif.ctrl.parport.cntlstat);
0602
0603 limit = MACEPAR_CONTEXT_DATA_BOUND -
0604 (parport_ip32_dma.next & (MACEPAR_CONTEXT_DATA_BOUND - 1));
0605 parport_ip32_dma_setup_context(limit);
0606 parport_ip32_dma_setup_context(MACEPAR_CONTEXT_DATA_BOUND);
0607
0608
0609 ctrl |= MACEPAR_CTLSTAT_ENABLE;
0610 writeq(ctrl, &mace->perif.ctrl.parport.cntlstat);
0611
0612 return 0;
0613 }
0614
0615
0616
0617
0618
0619
0620
0621
0622 static void parport_ip32_dma_stop(struct parport *p)
0623 {
0624 u64 ctx_a;
0625 u64 ctx_b;
0626 u64 ctrl;
0627 u64 diag;
0628 size_t res[2];
0629
0630 pr_trace(NULL, "()");
0631
0632
0633 spin_lock_irq(&parport_ip32_dma.lock);
0634 if (parport_ip32_dma.irq_on) {
0635 pr_debug(PPIP32 "IRQ off (stop)\n");
0636 disable_irq_nosync(MACEISA_PAR_CTXA_IRQ);
0637 disable_irq_nosync(MACEISA_PAR_CTXB_IRQ);
0638 parport_ip32_dma.irq_on = 0;
0639 }
0640 spin_unlock_irq(&parport_ip32_dma.lock);
0641
0642
0643 synchronize_irq(MACEISA_PAR_CTXA_IRQ);
0644 synchronize_irq(MACEISA_PAR_CTXB_IRQ);
0645
0646
0647 ctrl = readq(&mace->perif.ctrl.parport.cntlstat);
0648 ctrl &= ~MACEPAR_CTLSTAT_ENABLE;
0649 writeq(ctrl, &mace->perif.ctrl.parport.cntlstat);
0650
0651
0652 ctx_a = readq(&mace->perif.ctrl.parport.context_a);
0653 ctx_b = readq(&mace->perif.ctrl.parport.context_b);
0654 ctrl = readq(&mace->perif.ctrl.parport.cntlstat);
0655 diag = readq(&mace->perif.ctrl.parport.diagnostic);
0656 res[0] = (ctrl & MACEPAR_CTLSTAT_CTXA_VALID) ?
0657 1 + ((ctx_a & MACEPAR_CONTEXT_DATALEN_MASK) >>
0658 MACEPAR_CONTEXT_DATALEN_SHIFT) :
0659 0;
0660 res[1] = (ctrl & MACEPAR_CTLSTAT_CTXB_VALID) ?
0661 1 + ((ctx_b & MACEPAR_CONTEXT_DATALEN_MASK) >>
0662 MACEPAR_CONTEXT_DATALEN_SHIFT) :
0663 0;
0664 if (diag & MACEPAR_DIAG_DMACTIVE)
0665 res[(diag & MACEPAR_DIAG_CTXINUSE) != 0] =
0666 1 + ((diag & MACEPAR_DIAG_CTRMASK) >>
0667 MACEPAR_DIAG_CTRSHIFT);
0668 parport_ip32_dma.left += res[0] + res[1];
0669
0670
0671 ctrl = MACEPAR_CTLSTAT_RESET;
0672 writeq(ctrl, &mace->perif.ctrl.parport.cntlstat);
0673 pr_debug(PPIP32 "IRQ on (stop)\n");
0674 enable_irq(MACEISA_PAR_CTXA_IRQ);
0675 enable_irq(MACEISA_PAR_CTXB_IRQ);
0676 parport_ip32_dma.irq_on = 1;
0677
0678 dma_unmap_single(&p->bus_dev, parport_ip32_dma.buf,
0679 parport_ip32_dma.len, parport_ip32_dma.dir);
0680 }
0681
0682
0683
0684
0685
0686
0687 static inline size_t parport_ip32_dma_get_residue(void)
0688 {
0689 return parport_ip32_dma.left;
0690 }
0691
0692
0693
0694
0695
0696
0697 static int parport_ip32_dma_register(void)
0698 {
0699 int err;
0700
0701 spin_lock_init(&parport_ip32_dma.lock);
0702 parport_ip32_dma.irq_on = 1;
0703
0704
0705 writeq(MACEPAR_CTLSTAT_RESET, &mace->perif.ctrl.parport.cntlstat);
0706
0707
0708 err = request_irq(MACEISA_PAR_CTXA_IRQ, parport_ip32_dma_interrupt,
0709 0, "parport_ip32", NULL);
0710 if (err)
0711 goto fail_a;
0712 err = request_irq(MACEISA_PAR_CTXB_IRQ, parport_ip32_dma_interrupt,
0713 0, "parport_ip32", NULL);
0714 if (err)
0715 goto fail_b;
0716 #if DEBUG_PARPORT_IP32
0717
0718 err = request_irq(MACEISA_PAR_MERR_IRQ, parport_ip32_merr_interrupt,
0719 0, "parport_ip32", NULL);
0720 if (err)
0721 goto fail_merr;
0722 #endif
0723 return 0;
0724
0725 #if DEBUG_PARPORT_IP32
0726 fail_merr:
0727 free_irq(MACEISA_PAR_CTXB_IRQ, NULL);
0728 #endif
0729 fail_b:
0730 free_irq(MACEISA_PAR_CTXA_IRQ, NULL);
0731 fail_a:
0732 return err;
0733 }
0734
0735
0736
0737
0738 static void parport_ip32_dma_unregister(void)
0739 {
0740 #if DEBUG_PARPORT_IP32
0741 free_irq(MACEISA_PAR_MERR_IRQ, NULL);
0742 #endif
0743 free_irq(MACEISA_PAR_CTXB_IRQ, NULL);
0744 free_irq(MACEISA_PAR_CTXA_IRQ, NULL);
0745 }
0746
0747
0748
0749
0750
0751
0752
0753 static inline void parport_ip32_wakeup(struct parport *p)
0754 {
0755 struct parport_ip32_private * const priv = p->physport->private_data;
0756 complete(&priv->irq_complete);
0757 }
0758
0759
0760
0761
0762
0763
0764
0765
0766
0767 static irqreturn_t parport_ip32_interrupt(int irq, void *dev_id)
0768 {
0769 struct parport * const p = dev_id;
0770 struct parport_ip32_private * const priv = p->physport->private_data;
0771 enum parport_ip32_irq_mode irq_mode = priv->irq_mode;
0772
0773 switch (irq_mode) {
0774 case PARPORT_IP32_IRQ_FWD:
0775 return parport_irq_handler(irq, dev_id);
0776
0777 case PARPORT_IP32_IRQ_HERE:
0778 parport_ip32_wakeup(p);
0779 break;
0780 }
0781
0782 return IRQ_HANDLED;
0783 }
0784
0785
0786
0787
0788
0789
0790
0791 static inline unsigned int parport_ip32_read_econtrol(struct parport *p)
0792 {
0793 struct parport_ip32_private * const priv = p->physport->private_data;
0794 return readb(priv->regs.ecr);
0795 }
0796
0797
0798
0799
0800
0801
0802 static inline void parport_ip32_write_econtrol(struct parport *p,
0803 unsigned int c)
0804 {
0805 struct parport_ip32_private * const priv = p->physport->private_data;
0806 writeb(c, priv->regs.ecr);
0807 }
0808
0809
0810
0811
0812
0813
0814
0815
0816
0817
0818 static inline void parport_ip32_frob_econtrol(struct parport *p,
0819 unsigned int mask,
0820 unsigned int val)
0821 {
0822 unsigned int c;
0823 c = (parport_ip32_read_econtrol(p) & ~mask) ^ val;
0824 parport_ip32_write_econtrol(p, c);
0825 }
0826
0827
0828
0829
0830
0831
0832
0833
0834
0835 static void parport_ip32_set_mode(struct parport *p, unsigned int mode)
0836 {
0837 unsigned int omode;
0838
0839 mode &= ECR_MODE_MASK;
0840 omode = parport_ip32_read_econtrol(p) & ECR_MODE_MASK;
0841
0842 if (!(mode == ECR_MODE_SPP || mode == ECR_MODE_PS2
0843 || omode == ECR_MODE_SPP || omode == ECR_MODE_PS2)) {
0844
0845 unsigned int ecr = ECR_MODE_PS2 | ECR_nERRINTR | ECR_SERVINTR;
0846 parport_ip32_write_econtrol(p, ecr);
0847 }
0848 parport_ip32_write_econtrol(p, mode | ECR_nERRINTR | ECR_SERVINTR);
0849 }
0850
0851
0852
0853
0854
0855
0856
0857 static inline unsigned char parport_ip32_read_data(struct parport *p)
0858 {
0859 struct parport_ip32_private * const priv = p->physport->private_data;
0860 return readb(priv->regs.data);
0861 }
0862
0863
0864
0865
0866
0867
0868 static inline void parport_ip32_write_data(struct parport *p, unsigned char d)
0869 {
0870 struct parport_ip32_private * const priv = p->physport->private_data;
0871 writeb(d, priv->regs.data);
0872 }
0873
0874
0875
0876
0877
0878 static inline unsigned char parport_ip32_read_status(struct parport *p)
0879 {
0880 struct parport_ip32_private * const priv = p->physport->private_data;
0881 return readb(priv->regs.dsr);
0882 }
0883
0884
0885
0886
0887
0888 static inline unsigned int __parport_ip32_read_control(struct parport *p)
0889 {
0890 struct parport_ip32_private * const priv = p->physport->private_data;
0891 return priv->dcr_cache;
0892 }
0893
0894
0895
0896
0897
0898
0899 static inline void __parport_ip32_write_control(struct parport *p,
0900 unsigned int c)
0901 {
0902 struct parport_ip32_private * const priv = p->physport->private_data;
0903 CHECK_EXTRA_BITS(p, c, priv->dcr_writable);
0904 c &= priv->dcr_writable;
0905 writeb(c, priv->regs.dcr);
0906 priv->dcr_cache = c;
0907 }
0908
0909
0910
0911
0912
0913
0914
0915
0916
0917
0918
0919 static inline void __parport_ip32_frob_control(struct parport *p,
0920 unsigned int mask,
0921 unsigned int val)
0922 {
0923 unsigned int c;
0924 c = (__parport_ip32_read_control(p) & ~mask) ^ val;
0925 __parport_ip32_write_control(p, c);
0926 }
0927
0928
0929
0930
0931
0932
0933
0934
0935 static inline unsigned char parport_ip32_read_control(struct parport *p)
0936 {
0937 const unsigned int rm =
0938 DCR_STROBE | DCR_AUTOFD | DCR_nINIT | DCR_SELECT;
0939 return __parport_ip32_read_control(p) & rm;
0940 }
0941
0942
0943
0944
0945
0946
0947
0948
0949
0950 static inline void parport_ip32_write_control(struct parport *p,
0951 unsigned char c)
0952 {
0953 const unsigned int wm =
0954 DCR_STROBE | DCR_AUTOFD | DCR_nINIT | DCR_SELECT;
0955 CHECK_EXTRA_BITS(p, c, wm);
0956 __parport_ip32_frob_control(p, wm, c & wm);
0957 }
0958
0959
0960
0961
0962
0963
0964
0965
0966
0967
0968 static inline unsigned char parport_ip32_frob_control(struct parport *p,
0969 unsigned char mask,
0970 unsigned char val)
0971 {
0972 const unsigned int wm =
0973 DCR_STROBE | DCR_AUTOFD | DCR_nINIT | DCR_SELECT;
0974 CHECK_EXTRA_BITS(p, mask, wm);
0975 CHECK_EXTRA_BITS(p, val, wm);
0976 __parport_ip32_frob_control(p, mask & wm, val & wm);
0977 return parport_ip32_read_control(p);
0978 }
0979
0980
0981
0982
0983
0984 static inline void parport_ip32_disable_irq(struct parport *p)
0985 {
0986 __parport_ip32_frob_control(p, DCR_IRQ, 0);
0987 }
0988
0989
0990
0991
0992
0993 static inline void parport_ip32_enable_irq(struct parport *p)
0994 {
0995 __parport_ip32_frob_control(p, DCR_IRQ, DCR_IRQ);
0996 }
0997
0998
0999
1000
1001
1002
1003
1004 static inline void parport_ip32_data_forward(struct parport *p)
1005 {
1006 __parport_ip32_frob_control(p, DCR_DIR, 0);
1007 }
1008
1009
1010
1011
1012
1013
1014
1015
1016 static inline void parport_ip32_data_reverse(struct parport *p)
1017 {
1018 __parport_ip32_frob_control(p, DCR_DIR, DCR_DIR);
1019 }
1020
1021
1022
1023
1024
1025
1026 static void parport_ip32_init_state(struct pardevice *dev,
1027 struct parport_state *s)
1028 {
1029 s->u.ip32.dcr = DCR_SELECT | DCR_nINIT;
1030 s->u.ip32.ecr = ECR_MODE_PS2 | ECR_nERRINTR | ECR_SERVINTR;
1031 }
1032
1033
1034
1035
1036
1037
1038 static void parport_ip32_save_state(struct parport *p,
1039 struct parport_state *s)
1040 {
1041 s->u.ip32.dcr = __parport_ip32_read_control(p);
1042 s->u.ip32.ecr = parport_ip32_read_econtrol(p);
1043 }
1044
1045
1046
1047
1048
1049
1050 static void parport_ip32_restore_state(struct parport *p,
1051 struct parport_state *s)
1052 {
1053 parport_ip32_set_mode(p, s->u.ip32.ecr & ECR_MODE_MASK);
1054 parport_ip32_write_econtrol(p, s->u.ip32.ecr);
1055 __parport_ip32_write_control(p, s->u.ip32.dcr);
1056 }
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066 static unsigned int parport_ip32_clear_epp_timeout(struct parport *p)
1067 {
1068 struct parport_ip32_private * const priv = p->physport->private_data;
1069 unsigned int cleared;
1070
1071 if (!(parport_ip32_read_status(p) & DSR_TIMEOUT))
1072 cleared = 1;
1073 else {
1074 unsigned int r;
1075
1076 parport_ip32_read_status(p);
1077 r = parport_ip32_read_status(p);
1078
1079 writeb(r | DSR_TIMEOUT, priv->regs.dsr);
1080
1081 writeb(r & ~DSR_TIMEOUT, priv->regs.dsr);
1082
1083 r = parport_ip32_read_status(p);
1084 cleared = !(r & DSR_TIMEOUT);
1085 }
1086
1087 pr_trace(p, "(): %s", cleared ? "cleared" : "failed");
1088 return cleared;
1089 }
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099 static size_t parport_ip32_epp_read(void __iomem *eppreg,
1100 struct parport *p, void *buf,
1101 size_t len, int flags)
1102 {
1103 struct parport_ip32_private * const priv = p->physport->private_data;
1104 size_t got;
1105 parport_ip32_set_mode(p, ECR_MODE_EPP);
1106 parport_ip32_data_reverse(p);
1107 parport_ip32_write_control(p, DCR_nINIT);
1108 if ((flags & PARPORT_EPP_FAST) && (len > 1)) {
1109 readsb(eppreg, buf, len);
1110 if (readb(priv->regs.dsr) & DSR_TIMEOUT) {
1111 parport_ip32_clear_epp_timeout(p);
1112 return -EIO;
1113 }
1114 got = len;
1115 } else {
1116 u8 *bufp = buf;
1117 for (got = 0; got < len; got++) {
1118 *bufp++ = readb(eppreg);
1119 if (readb(priv->regs.dsr) & DSR_TIMEOUT) {
1120 parport_ip32_clear_epp_timeout(p);
1121 break;
1122 }
1123 }
1124 }
1125 parport_ip32_data_forward(p);
1126 parport_ip32_set_mode(p, ECR_MODE_PS2);
1127 return got;
1128 }
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138 static size_t parport_ip32_epp_write(void __iomem *eppreg,
1139 struct parport *p, const void *buf,
1140 size_t len, int flags)
1141 {
1142 struct parport_ip32_private * const priv = p->physport->private_data;
1143 size_t written;
1144 parport_ip32_set_mode(p, ECR_MODE_EPP);
1145 parport_ip32_data_forward(p);
1146 parport_ip32_write_control(p, DCR_nINIT);
1147 if ((flags & PARPORT_EPP_FAST) && (len > 1)) {
1148 writesb(eppreg, buf, len);
1149 if (readb(priv->regs.dsr) & DSR_TIMEOUT) {
1150 parport_ip32_clear_epp_timeout(p);
1151 return -EIO;
1152 }
1153 written = len;
1154 } else {
1155 const u8 *bufp = buf;
1156 for (written = 0; written < len; written++) {
1157 writeb(*bufp++, eppreg);
1158 if (readb(priv->regs.dsr) & DSR_TIMEOUT) {
1159 parport_ip32_clear_epp_timeout(p);
1160 break;
1161 }
1162 }
1163 }
1164 parport_ip32_set_mode(p, ECR_MODE_PS2);
1165 return written;
1166 }
1167
1168
1169
1170
1171
1172
1173
1174
1175 static size_t parport_ip32_epp_read_data(struct parport *p, void *buf,
1176 size_t len, int flags)
1177 {
1178 struct parport_ip32_private * const priv = p->physport->private_data;
1179 return parport_ip32_epp_read(priv->regs.eppData0, p, buf, len, flags);
1180 }
1181
1182
1183
1184
1185
1186
1187
1188
1189 static size_t parport_ip32_epp_write_data(struct parport *p, const void *buf,
1190 size_t len, int flags)
1191 {
1192 struct parport_ip32_private * const priv = p->physport->private_data;
1193 return parport_ip32_epp_write(priv->regs.eppData0, p, buf, len, flags);
1194 }
1195
1196
1197
1198
1199
1200
1201
1202
1203 static size_t parport_ip32_epp_read_addr(struct parport *p, void *buf,
1204 size_t len, int flags)
1205 {
1206 struct parport_ip32_private * const priv = p->physport->private_data;
1207 return parport_ip32_epp_read(priv->regs.eppAddr, p, buf, len, flags);
1208 }
1209
1210
1211
1212
1213
1214
1215
1216
1217 static size_t parport_ip32_epp_write_addr(struct parport *p, const void *buf,
1218 size_t len, int flags)
1219 {
1220 struct parport_ip32_private * const priv = p->physport->private_data;
1221 return parport_ip32_epp_write(priv->regs.eppAddr, p, buf, len, flags);
1222 }
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238 static unsigned int parport_ip32_fifo_wait_break(struct parport *p,
1239 unsigned long expire)
1240 {
1241 cond_resched();
1242 if (time_after(jiffies, expire)) {
1243 pr_debug1(PPIP32 "%s: FIFO write timed out\n", p->name);
1244 return 1;
1245 }
1246 if (signal_pending(current)) {
1247 pr_debug1(PPIP32 "%s: Signal pending\n", p->name);
1248 return 1;
1249 }
1250 if (!(parport_ip32_read_status(p) & DSR_nFAULT)) {
1251 pr_debug1(PPIP32 "%s: nFault asserted low\n", p->name);
1252 return 1;
1253 }
1254 return 0;
1255 }
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265 static unsigned int parport_ip32_fwp_wait_polling(struct parport *p)
1266 {
1267 struct parport_ip32_private * const priv = p->physport->private_data;
1268 struct parport * const physport = p->physport;
1269 unsigned long expire;
1270 unsigned int count;
1271 unsigned int ecr;
1272
1273 expire = jiffies + physport->cad->timeout;
1274 count = 0;
1275 while (1) {
1276 if (parport_ip32_fifo_wait_break(p, expire))
1277 break;
1278
1279
1280
1281
1282
1283 ecr = parport_ip32_read_econtrol(p);
1284 if (ecr & ECR_F_EMPTY) {
1285
1286 count = priv->fifo_depth;
1287 break;
1288 }
1289
1290
1291 udelay(FIFO_POLLING_INTERVAL);
1292 }
1293
1294 return count;
1295 }
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305 static unsigned int parport_ip32_fwp_wait_interrupt(struct parport *p)
1306 {
1307 static unsigned int lost_interrupt = 0;
1308 struct parport_ip32_private * const priv = p->physport->private_data;
1309 struct parport * const physport = p->physport;
1310 unsigned long nfault_timeout;
1311 unsigned long expire;
1312 unsigned int count;
1313 unsigned int ecr;
1314
1315 nfault_timeout = min((unsigned long)physport->cad->timeout,
1316 msecs_to_jiffies(FIFO_NFAULT_TIMEOUT));
1317 expire = jiffies + physport->cad->timeout;
1318 count = 0;
1319 while (1) {
1320 if (parport_ip32_fifo_wait_break(p, expire))
1321 break;
1322
1323
1324 reinit_completion(&priv->irq_complete);
1325
1326
1327 parport_ip32_frob_econtrol(p, ECR_SERVINTR, 0);
1328
1329
1330
1331
1332 ecr = parport_ip32_read_econtrol(p);
1333 if (!(ecr & ECR_F_EMPTY)) {
1334
1335
1336 wait_for_completion_interruptible_timeout(
1337 &priv->irq_complete, nfault_timeout);
1338 ecr = parport_ip32_read_econtrol(p);
1339 if ((ecr & ECR_F_EMPTY) && !(ecr & ECR_SERVINTR)
1340 && !lost_interrupt) {
1341 pr_warn(PPIP32 "%s: lost interrupt in %s\n",
1342 p->name, __func__);
1343 lost_interrupt = 1;
1344 }
1345 }
1346
1347
1348 parport_ip32_frob_econtrol(p, ECR_SERVINTR, ECR_SERVINTR);
1349
1350
1351 if (ecr & ECR_F_EMPTY) {
1352
1353 count = priv->fifo_depth;
1354 break;
1355 } else if (ecr & ECR_SERVINTR) {
1356
1357
1358 count = priv->writeIntrThreshold;
1359 break;
1360 }
1361
1362
1363
1364
1365 }
1366
1367 return count;
1368 }
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381 static size_t parport_ip32_fifo_write_block_pio(struct parport *p,
1382 const void *buf, size_t len)
1383 {
1384 struct parport_ip32_private * const priv = p->physport->private_data;
1385 const u8 *bufp = buf;
1386 size_t left = len;
1387
1388 priv->irq_mode = PARPORT_IP32_IRQ_HERE;
1389
1390 while (left > 0) {
1391 unsigned int count;
1392
1393 count = (p->irq == PARPORT_IRQ_NONE) ?
1394 parport_ip32_fwp_wait_polling(p) :
1395 parport_ip32_fwp_wait_interrupt(p);
1396 if (count == 0)
1397 break;
1398 if (count > left)
1399 count = left;
1400 if (count == 1) {
1401 writeb(*bufp, priv->regs.fifo);
1402 bufp++, left--;
1403 } else {
1404 writesb(priv->regs.fifo, bufp, count);
1405 bufp += count, left -= count;
1406 }
1407 }
1408
1409 priv->irq_mode = PARPORT_IP32_IRQ_FWD;
1410
1411 return len - left;
1412 }
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425 static size_t parport_ip32_fifo_write_block_dma(struct parport *p,
1426 const void *buf, size_t len)
1427 {
1428 struct parport_ip32_private * const priv = p->physport->private_data;
1429 struct parport * const physport = p->physport;
1430 unsigned long nfault_timeout;
1431 unsigned long expire;
1432 size_t written;
1433 unsigned int ecr;
1434
1435 priv->irq_mode = PARPORT_IP32_IRQ_HERE;
1436
1437 parport_ip32_dma_start(p, DMA_TO_DEVICE, (void *)buf, len);
1438 reinit_completion(&priv->irq_complete);
1439 parport_ip32_frob_econtrol(p, ECR_DMAEN | ECR_SERVINTR, ECR_DMAEN);
1440
1441 nfault_timeout = min((unsigned long)physport->cad->timeout,
1442 msecs_to_jiffies(FIFO_NFAULT_TIMEOUT));
1443 expire = jiffies + physport->cad->timeout;
1444 while (1) {
1445 if (parport_ip32_fifo_wait_break(p, expire))
1446 break;
1447 wait_for_completion_interruptible_timeout(&priv->irq_complete,
1448 nfault_timeout);
1449 ecr = parport_ip32_read_econtrol(p);
1450 if (ecr & ECR_SERVINTR)
1451 break;
1452 }
1453 parport_ip32_dma_stop(p);
1454 written = len - parport_ip32_dma_get_residue();
1455
1456 priv->irq_mode = PARPORT_IP32_IRQ_FWD;
1457
1458 return written;
1459 }
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470 static size_t parport_ip32_fifo_write_block(struct parport *p,
1471 const void *buf, size_t len)
1472 {
1473 size_t written = 0;
1474 if (len)
1475
1476
1477 written = (p->modes & PARPORT_MODE_DMA) ?
1478 parport_ip32_fifo_write_block_dma(p, buf, len) :
1479 parport_ip32_fifo_write_block_pio(p, buf, len);
1480 return written;
1481 }
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491 static unsigned int parport_ip32_drain_fifo(struct parport *p,
1492 unsigned long timeout)
1493 {
1494 unsigned long expire = jiffies + timeout;
1495 unsigned int polling_interval;
1496 unsigned int counter;
1497
1498
1499 for (counter = 0; counter < 40; counter++) {
1500 if (parport_ip32_read_econtrol(p) & ECR_F_EMPTY)
1501 break;
1502 if (time_after(jiffies, expire))
1503 break;
1504 if (signal_pending(current))
1505 break;
1506 udelay(5);
1507 }
1508
1509
1510 polling_interval = 1;
1511 while (!(parport_ip32_read_econtrol(p) & ECR_F_EMPTY)) {
1512 if (time_after_eq(jiffies, expire))
1513 break;
1514 msleep_interruptible(polling_interval);
1515 if (signal_pending(current))
1516 break;
1517 if (polling_interval < 128)
1518 polling_interval *= 2;
1519 }
1520
1521 return !!(parport_ip32_read_econtrol(p) & ECR_F_EMPTY);
1522 }
1523
1524
1525
1526
1527
1528
1529
1530
1531 static unsigned int parport_ip32_get_fifo_residue(struct parport *p,
1532 unsigned int mode)
1533 {
1534 struct parport_ip32_private * const priv = p->physport->private_data;
1535 unsigned int residue;
1536 unsigned int cnfga;
1537
1538
1539
1540
1541
1542
1543 if (parport_ip32_read_econtrol(p) & ECR_F_EMPTY)
1544 residue = 0;
1545 else {
1546 pr_debug1(PPIP32 "%s: FIFO is stuck\n", p->name);
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560 parport_ip32_frob_control(p, DCR_STROBE, 0);
1561
1562
1563 for (residue = priv->fifo_depth; residue > 0; residue--) {
1564 if (parport_ip32_read_econtrol(p) & ECR_F_FULL)
1565 break;
1566 writeb(0x00, priv->regs.fifo);
1567 }
1568 }
1569 if (residue)
1570 pr_debug1(PPIP32 "%s: %d PWord%s left in FIFO\n",
1571 p->name, residue,
1572 (residue == 1) ? " was" : "s were");
1573
1574
1575 parport_ip32_set_mode(p, ECR_MODE_PS2);
1576
1577
1578 if (mode == ECR_MODE_ECP) {
1579 parport_ip32_data_reverse(p);
1580 parport_ip32_frob_control(p, DCR_nINIT, 0);
1581 if (parport_wait_peripheral(p, DSR_PERROR, 0))
1582 pr_debug1(PPIP32 "%s: PEerror timeout 1 in %s\n",
1583 p->name, __func__);
1584 parport_ip32_frob_control(p, DCR_STROBE, DCR_STROBE);
1585 parport_ip32_frob_control(p, DCR_nINIT, DCR_nINIT);
1586 if (parport_wait_peripheral(p, DSR_PERROR, DSR_PERROR))
1587 pr_debug1(PPIP32 "%s: PEerror timeout 2 in %s\n",
1588 p->name, __func__);
1589 }
1590
1591
1592 parport_ip32_set_mode(p, ECR_MODE_CFG);
1593 cnfga = readb(priv->regs.cnfgA);
1594 if (!(cnfga & CNFGA_nBYTEINTRANS)) {
1595 pr_debug1(PPIP32 "%s: cnfgA contains 0x%02x\n",
1596 p->name, cnfga);
1597 pr_debug1(PPIP32 "%s: Accounting for extra byte\n",
1598 p->name);
1599 residue++;
1600 }
1601
1602
1603
1604
1605
1606 parport_ip32_set_mode(p, ECR_MODE_PS2);
1607 parport_ip32_data_forward(p);
1608
1609 return residue;
1610 }
1611
1612
1613
1614
1615
1616
1617
1618
1619 static size_t parport_ip32_compat_write_data(struct parport *p,
1620 const void *buf, size_t len,
1621 int flags)
1622 {
1623 static unsigned int ready_before = 1;
1624 struct parport_ip32_private * const priv = p->physport->private_data;
1625 struct parport * const physport = p->physport;
1626 size_t written = 0;
1627
1628
1629
1630 if (physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
1631 return parport_ieee1284_write_compat(p, buf, len, flags);
1632
1633
1634 parport_ip32_set_mode(p, ECR_MODE_PS2);
1635 parport_ip32_write_control(p, DCR_SELECT | DCR_nINIT);
1636 parport_ip32_data_forward(p);
1637 parport_ip32_disable_irq(p);
1638 parport_ip32_set_mode(p, ECR_MODE_PPF);
1639 physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
1640
1641
1642 if (parport_wait_peripheral(p, DSR_nBUSY | DSR_nFAULT,
1643 DSR_nBUSY | DSR_nFAULT)) {
1644
1645 if (ready_before)
1646 pr_info(PPIP32 "%s: not ready in %s\n",
1647 p->name, __func__);
1648 ready_before = 0;
1649 goto stop;
1650 }
1651 ready_before = 1;
1652
1653 written = parport_ip32_fifo_write_block(p, buf, len);
1654
1655
1656 parport_ip32_drain_fifo(p, physport->cad->timeout * priv->fifo_depth);
1657
1658
1659 written -= parport_ip32_get_fifo_residue(p, ECR_MODE_PPF);
1660
1661
1662 if (parport_wait_peripheral(p, DSR_nBUSY, DSR_nBUSY))
1663 printk(KERN_DEBUG PPIP32 "%s: BUSY timeout in %s\n",
1664 p->name, __func__);
1665
1666 stop:
1667
1668 parport_ip32_set_mode(p, ECR_MODE_PS2);
1669 physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
1670
1671 return written;
1672 }
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685 static size_t parport_ip32_ecp_write_data(struct parport *p,
1686 const void *buf, size_t len,
1687 int flags)
1688 {
1689 static unsigned int ready_before = 1;
1690 struct parport_ip32_private * const priv = p->physport->private_data;
1691 struct parport * const physport = p->physport;
1692 size_t written = 0;
1693
1694
1695
1696 if (physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
1697 return parport_ieee1284_ecp_write_data(p, buf, len, flags);
1698
1699
1700 if (physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) {
1701
1702 parport_ip32_frob_control(p, DCR_nINIT | DCR_AUTOFD,
1703 DCR_nINIT | DCR_AUTOFD);
1704
1705
1706 if (parport_wait_peripheral(p, DSR_PERROR, DSR_PERROR)) {
1707 printk(KERN_DEBUG PPIP32 "%s: PError timeout in %s\n",
1708 p->name, __func__);
1709 physport->ieee1284.phase = IEEE1284_PH_ECP_DIR_UNKNOWN;
1710 return 0;
1711 }
1712 }
1713
1714
1715 parport_ip32_set_mode(p, ECR_MODE_PS2);
1716 parport_ip32_write_control(p, DCR_SELECT | DCR_nINIT);
1717 parport_ip32_data_forward(p);
1718 parport_ip32_disable_irq(p);
1719 parport_ip32_set_mode(p, ECR_MODE_ECP);
1720 physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
1721
1722
1723 if (parport_wait_peripheral(p, DSR_nBUSY | DSR_nFAULT,
1724 DSR_nBUSY | DSR_nFAULT)) {
1725
1726 if (ready_before)
1727 pr_info(PPIP32 "%s: not ready in %s\n",
1728 p->name, __func__);
1729 ready_before = 0;
1730 goto stop;
1731 }
1732 ready_before = 1;
1733
1734 written = parport_ip32_fifo_write_block(p, buf, len);
1735
1736
1737 parport_ip32_drain_fifo(p, physport->cad->timeout * priv->fifo_depth);
1738
1739
1740 written -= parport_ip32_get_fifo_residue(p, ECR_MODE_ECP);
1741
1742
1743 if (parport_wait_peripheral(p, DSR_nBUSY, DSR_nBUSY))
1744 printk(KERN_DEBUG PPIP32 "%s: BUSY timeout in %s\n",
1745 p->name, __func__);
1746
1747 stop:
1748
1749 parport_ip32_set_mode(p, ECR_MODE_PS2);
1750 physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
1751
1752 return written;
1753 }
1754
1755
1756
1757
1758
1759
1760
1761 static const struct parport_operations parport_ip32_ops __initconst = {
1762 .write_data = parport_ip32_write_data,
1763 .read_data = parport_ip32_read_data,
1764
1765 .write_control = parport_ip32_write_control,
1766 .read_control = parport_ip32_read_control,
1767 .frob_control = parport_ip32_frob_control,
1768
1769 .read_status = parport_ip32_read_status,
1770
1771 .enable_irq = parport_ip32_enable_irq,
1772 .disable_irq = parport_ip32_disable_irq,
1773
1774 .data_forward = parport_ip32_data_forward,
1775 .data_reverse = parport_ip32_data_reverse,
1776
1777 .init_state = parport_ip32_init_state,
1778 .save_state = parport_ip32_save_state,
1779 .restore_state = parport_ip32_restore_state,
1780
1781 .epp_write_data = parport_ieee1284_epp_write_data,
1782 .epp_read_data = parport_ieee1284_epp_read_data,
1783 .epp_write_addr = parport_ieee1284_epp_write_addr,
1784 .epp_read_addr = parport_ieee1284_epp_read_addr,
1785
1786 .ecp_write_data = parport_ieee1284_ecp_write_data,
1787 .ecp_read_data = parport_ieee1284_ecp_read_data,
1788 .ecp_write_addr = parport_ieee1284_ecp_write_addr,
1789
1790 .compat_write_data = parport_ieee1284_write_compat,
1791 .nibble_read_data = parport_ieee1284_read_nibble,
1792 .byte_read_data = parport_ieee1284_read_byte,
1793
1794 .owner = THIS_MODULE,
1795 };
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807 static __init unsigned int parport_ip32_ecp_supported(struct parport *p)
1808 {
1809 struct parport_ip32_private * const priv = p->physport->private_data;
1810 unsigned int ecr;
1811
1812 ecr = ECR_MODE_PS2 | ECR_nERRINTR | ECR_SERVINTR;
1813 writeb(ecr, priv->regs.ecr);
1814 if (readb(priv->regs.ecr) != (ecr | ECR_F_EMPTY))
1815 goto fail;
1816
1817 pr_probe(p, "Found working ECR register\n");
1818 parport_ip32_set_mode(p, ECR_MODE_SPP);
1819 parport_ip32_write_control(p, DCR_SELECT | DCR_nINIT);
1820 return 1;
1821
1822 fail:
1823 pr_probe(p, "ECR register not found\n");
1824 return 0;
1825 }
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835 static __init unsigned int parport_ip32_fifo_supported(struct parport *p)
1836 {
1837 struct parport_ip32_private * const priv = p->physport->private_data;
1838 unsigned int configa, configb;
1839 unsigned int pword;
1840 unsigned int i;
1841
1842
1843 parport_ip32_set_mode(p, ECR_MODE_CFG);
1844 configa = readb(priv->regs.cnfgA);
1845 configb = readb(priv->regs.cnfgB);
1846
1847
1848 switch (configa & CNFGA_ID_MASK) {
1849 case CNFGA_ID_8:
1850 pword = 1;
1851 break;
1852 case CNFGA_ID_16:
1853 pword = 2;
1854 break;
1855 case CNFGA_ID_32:
1856 pword = 4;
1857 break;
1858 default:
1859 pr_probe(p, "Unknown implementation ID: 0x%0x\n",
1860 (configa & CNFGA_ID_MASK) >> CNFGA_ID_SHIFT);
1861 goto fail;
1862 break;
1863 }
1864 if (pword != 1) {
1865 pr_probe(p, "Unsupported PWord size: %u\n", pword);
1866 goto fail;
1867 }
1868 priv->pword = pword;
1869 pr_probe(p, "PWord is %u bits\n", 8 * priv->pword);
1870
1871
1872 writeb(configb | CNFGB_COMPRESS, priv->regs.cnfgB);
1873 if (readb(priv->regs.cnfgB) & CNFGB_COMPRESS)
1874 pr_probe(p, "Hardware compression detected (unsupported)\n");
1875 writeb(configb & ~CNFGB_COMPRESS, priv->regs.cnfgB);
1876
1877
1878 parport_ip32_set_mode(p, ECR_MODE_TST);
1879
1880
1881 if (!(readb(priv->regs.ecr) & ECR_F_EMPTY)) {
1882 pr_probe(p, "FIFO not reset\n");
1883 goto fail;
1884 }
1885
1886
1887 priv->fifo_depth = 0;
1888 for (i = 0; i < 1024; i++) {
1889 if (readb(priv->regs.ecr) & ECR_F_FULL) {
1890
1891 priv->fifo_depth = i;
1892 break;
1893 }
1894 writeb((u8)i, priv->regs.fifo);
1895 }
1896 if (i >= 1024) {
1897 pr_probe(p, "Can't fill FIFO\n");
1898 goto fail;
1899 }
1900 if (!priv->fifo_depth) {
1901 pr_probe(p, "Can't get FIFO depth\n");
1902 goto fail;
1903 }
1904 pr_probe(p, "FIFO is %u PWords deep\n", priv->fifo_depth);
1905
1906
1907 parport_ip32_frob_econtrol(p, ECR_SERVINTR, 0);
1908
1909
1910
1911 priv->writeIntrThreshold = 0;
1912 for (i = 0; i < priv->fifo_depth; i++) {
1913 if (readb(priv->regs.fifo) != (u8)i) {
1914 pr_probe(p, "Invalid data in FIFO\n");
1915 goto fail;
1916 }
1917 if (!priv->writeIntrThreshold
1918 && readb(priv->regs.ecr) & ECR_SERVINTR)
1919
1920 priv->writeIntrThreshold = i + 1;
1921 if (i + 1 < priv->fifo_depth
1922 && readb(priv->regs.ecr) & ECR_F_EMPTY) {
1923
1924 pr_probe(p, "Data lost in FIFO\n");
1925 goto fail;
1926 }
1927 }
1928 if (!priv->writeIntrThreshold) {
1929 pr_probe(p, "Can't get writeIntrThreshold\n");
1930 goto fail;
1931 }
1932 pr_probe(p, "writeIntrThreshold is %u\n", priv->writeIntrThreshold);
1933
1934
1935 if (!(readb(priv->regs.ecr) & ECR_F_EMPTY)) {
1936 pr_probe(p, "Can't empty FIFO\n");
1937 goto fail;
1938 }
1939
1940
1941 parport_ip32_set_mode(p, ECR_MODE_PS2);
1942
1943 parport_ip32_data_reverse(p);
1944
1945 parport_ip32_set_mode(p, ECR_MODE_TST);
1946
1947 parport_ip32_frob_econtrol(p, ECR_SERVINTR, 0);
1948
1949
1950
1951 priv->readIntrThreshold = 0;
1952 for (i = 0; i < priv->fifo_depth; i++) {
1953 writeb(0xaa, priv->regs.fifo);
1954 if (readb(priv->regs.ecr) & ECR_SERVINTR) {
1955
1956 priv->readIntrThreshold = i + 1;
1957 break;
1958 }
1959 }
1960 if (!priv->readIntrThreshold) {
1961 pr_probe(p, "Can't get readIntrThreshold\n");
1962 goto fail;
1963 }
1964 pr_probe(p, "readIntrThreshold is %u\n", priv->readIntrThreshold);
1965
1966
1967 parport_ip32_set_mode(p, ECR_MODE_PS2);
1968 parport_ip32_data_forward(p);
1969 parport_ip32_set_mode(p, ECR_MODE_SPP);
1970 return 1;
1971
1972 fail:
1973 priv->fifo_depth = 0;
1974 parport_ip32_set_mode(p, ECR_MODE_SPP);
1975 return 0;
1976 }
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991 static void __init
1992 parport_ip32_make_isa_registers(struct parport_ip32_regs *regs,
1993 void __iomem *base, void __iomem *base_hi,
1994 unsigned int regshift)
1995 {
1996 #define r_base(offset) ((u8 __iomem *)base + ((offset) << regshift))
1997 #define r_base_hi(offset) ((u8 __iomem *)base_hi + ((offset) << regshift))
1998 *regs = (struct parport_ip32_regs){
1999 .data = r_base(0),
2000 .dsr = r_base(1),
2001 .dcr = r_base(2),
2002 .eppAddr = r_base(3),
2003 .eppData0 = r_base(4),
2004 .eppData1 = r_base(5),
2005 .eppData2 = r_base(6),
2006 .eppData3 = r_base(7),
2007 .ecpAFifo = r_base(0),
2008 .fifo = r_base_hi(0),
2009 .cnfgA = r_base_hi(0),
2010 .cnfgB = r_base_hi(1),
2011 .ecr = r_base_hi(2)
2012 };
2013 #undef r_base_hi
2014 #undef r_base
2015 }
2016
2017
2018
2019
2020
2021
2022
2023 static __init struct parport *parport_ip32_probe_port(void)
2024 {
2025 struct parport_ip32_regs regs;
2026 struct parport_ip32_private *priv = NULL;
2027 struct parport_operations *ops = NULL;
2028 struct parport *p = NULL;
2029 int err;
2030
2031 parport_ip32_make_isa_registers(®s, &mace->isa.parallel,
2032 &mace->isa.ecp1284, 8 );
2033
2034 ops = kmalloc(sizeof(struct parport_operations), GFP_KERNEL);
2035 priv = kmalloc(sizeof(struct parport_ip32_private), GFP_KERNEL);
2036 p = parport_register_port(0, PARPORT_IRQ_NONE, PARPORT_DMA_NONE, ops);
2037 if (ops == NULL || priv == NULL || p == NULL) {
2038 err = -ENOMEM;
2039 goto fail;
2040 }
2041 p->base = MACE_BASE + offsetof(struct sgi_mace, isa.parallel);
2042 p->base_hi = MACE_BASE + offsetof(struct sgi_mace, isa.ecp1284);
2043 p->private_data = priv;
2044
2045 *ops = parport_ip32_ops;
2046 *priv = (struct parport_ip32_private){
2047 .regs = regs,
2048 .dcr_writable = DCR_DIR | DCR_SELECT | DCR_nINIT |
2049 DCR_AUTOFD | DCR_STROBE,
2050 .irq_mode = PARPORT_IP32_IRQ_FWD,
2051 };
2052 init_completion(&priv->irq_complete);
2053
2054
2055 if (!parport_ip32_ecp_supported(p)) {
2056 err = -ENODEV;
2057 goto fail;
2058 }
2059 parport_ip32_dump_state(p, "begin init", 0);
2060
2061
2062
2063 p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
2064 p->modes |= PARPORT_MODE_TRISTATE;
2065
2066 if (!parport_ip32_fifo_supported(p)) {
2067 pr_warn(PPIP32 "%s: error: FIFO disabled\n", p->name);
2068
2069 features &= ~PARPORT_IP32_ENABLE_SPP;
2070 features &= ~PARPORT_IP32_ENABLE_ECP;
2071
2072 features &= ~PARPORT_IP32_ENABLE_DMA;
2073 }
2074
2075
2076 if (features & PARPORT_IP32_ENABLE_IRQ) {
2077 int irq = MACEISA_PARALLEL_IRQ;
2078 if (request_irq(irq, parport_ip32_interrupt, 0, p->name, p)) {
2079 pr_warn(PPIP32 "%s: error: IRQ disabled\n", p->name);
2080
2081 features &= ~PARPORT_IP32_ENABLE_DMA;
2082 } else {
2083 pr_probe(p, "Interrupt support enabled\n");
2084 p->irq = irq;
2085 priv->dcr_writable |= DCR_IRQ;
2086 }
2087 }
2088
2089
2090 if (features & PARPORT_IP32_ENABLE_DMA) {
2091 if (parport_ip32_dma_register())
2092 pr_warn(PPIP32 "%s: error: DMA disabled\n", p->name);
2093 else {
2094 pr_probe(p, "DMA support enabled\n");
2095 p->dma = 0;
2096 p->modes |= PARPORT_MODE_DMA;
2097 }
2098 }
2099
2100 if (features & PARPORT_IP32_ENABLE_SPP) {
2101
2102 p->ops->compat_write_data = parport_ip32_compat_write_data;
2103 p->modes |= PARPORT_MODE_COMPAT;
2104 pr_probe(p, "Hardware support for SPP mode enabled\n");
2105 }
2106 if (features & PARPORT_IP32_ENABLE_EPP) {
2107
2108 p->ops->epp_read_data = parport_ip32_epp_read_data;
2109 p->ops->epp_write_data = parport_ip32_epp_write_data;
2110 p->ops->epp_read_addr = parport_ip32_epp_read_addr;
2111 p->ops->epp_write_addr = parport_ip32_epp_write_addr;
2112 p->modes |= PARPORT_MODE_EPP;
2113 pr_probe(p, "Hardware support for EPP mode enabled\n");
2114 }
2115 if (features & PARPORT_IP32_ENABLE_ECP) {
2116
2117 p->ops->ecp_write_data = parport_ip32_ecp_write_data;
2118
2119
2120
2121 p->modes |= PARPORT_MODE_ECP;
2122 pr_probe(p, "Hardware support for ECP mode enabled\n");
2123 }
2124
2125
2126 parport_ip32_set_mode(p, ECR_MODE_PS2);
2127 parport_ip32_write_control(p, DCR_SELECT | DCR_nINIT);
2128 parport_ip32_data_forward(p);
2129 parport_ip32_disable_irq(p);
2130 parport_ip32_write_data(p, 0x00);
2131 parport_ip32_dump_state(p, "end init", 0);
2132
2133
2134 pr_info("%s: SGI IP32 at 0x%lx (0x%lx)", p->name, p->base, p->base_hi);
2135 if (p->irq != PARPORT_IRQ_NONE)
2136 pr_cont(", irq %d", p->irq);
2137 pr_cont(" [");
2138 #define printmode(x) \
2139 do { \
2140 if (p->modes & PARPORT_MODE_##x) \
2141 pr_cont("%s%s", f++ ? "," : "", #x); \
2142 } while (0)
2143 {
2144 unsigned int f = 0;
2145 printmode(PCSPP);
2146 printmode(TRISTATE);
2147 printmode(COMPAT);
2148 printmode(EPP);
2149 printmode(ECP);
2150 printmode(DMA);
2151 }
2152 #undef printmode
2153 pr_cont("]\n");
2154
2155 parport_announce_port(p);
2156 return p;
2157
2158 fail:
2159 if (p)
2160 parport_put_port(p);
2161 kfree(priv);
2162 kfree(ops);
2163 return ERR_PTR(err);
2164 }
2165
2166
2167
2168
2169
2170
2171
2172
2173 static __exit void parport_ip32_unregister_port(struct parport *p)
2174 {
2175 struct parport_ip32_private * const priv = p->physport->private_data;
2176 struct parport_operations *ops = p->ops;
2177
2178 parport_remove_port(p);
2179 if (p->modes & PARPORT_MODE_DMA)
2180 parport_ip32_dma_unregister();
2181 if (p->irq != PARPORT_IRQ_NONE)
2182 free_irq(p->irq, p);
2183 parport_put_port(p);
2184 kfree(priv);
2185 kfree(ops);
2186 }
2187
2188
2189
2190
2191 static int __init parport_ip32_init(void)
2192 {
2193 pr_info(PPIP32 "SGI IP32 built-in parallel port driver v0.6\n");
2194 this_port = parport_ip32_probe_port();
2195 return PTR_ERR_OR_ZERO(this_port);
2196 }
2197
2198
2199
2200
2201 static void __exit parport_ip32_exit(void)
2202 {
2203 parport_ip32_unregister_port(this_port);
2204 }
2205
2206
2207
2208 MODULE_AUTHOR("Arnaud Giersch <arnaud.giersch@free.fr>");
2209 MODULE_DESCRIPTION("SGI IP32 built-in parallel port driver");
2210 MODULE_LICENSE("GPL");
2211 MODULE_VERSION("0.6");
2212
2213 module_init(parport_ip32_init);
2214 module_exit(parport_ip32_exit);
2215
2216 module_param(verbose_probing, bool, S_IRUGO);
2217 MODULE_PARM_DESC(verbose_probing, "Log chit-chat during initialization");
2218
2219 module_param(features, uint, S_IRUGO);
2220 MODULE_PARM_DESC(features,
2221 "Bit mask of features to enable"
2222 ", bit 0: IRQ support"
2223 ", bit 1: DMA support"
2224 ", bit 2: hardware SPP mode"
2225 ", bit 3: hardware EPP mode"
2226 ", bit 4: hardware ECP mode");