diff options
author | H Hartley Sweeten <hsweeten@visionengravers.com> | 2013-06-18 16:20:51 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-06-24 18:50:38 -0400 |
commit | f45a1f26eae4cadbfeb65b4b36bfa3583f694066 (patch) | |
tree | 38dd762d427bb5bf896c0125da07fa3e937f80d0 | |
parent | 75ec11370ec4bbc144af9a412d7eeb578e7b3d59 (diff) |
staging: comedi: pcmuio: tidy up the register map defines
Add namespace to the register map defines. Gather them together
and tidy them up a bit.
Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/staging/comedi/drivers/pcmuio.c | 107 |
1 files changed, 42 insertions, 65 deletions
diff --git a/drivers/staging/comedi/drivers/pcmuio.c b/drivers/staging/comedi/drivers/pcmuio.c index 5e7045b29bf1..9fb75a47fb77 100644 --- a/drivers/staging/comedi/drivers/pcmuio.c +++ b/drivers/staging/comedi/drivers/pcmuio.c | |||
@@ -80,6 +80,34 @@ | |||
80 | 80 | ||
81 | #include "comedi_fc.h" | 81 | #include "comedi_fc.h" |
82 | 82 | ||
83 | /* | ||
84 | * Register I/O map | ||
85 | * | ||
86 | * Offset Page 0 Page 1 Page 2 Page 3 | ||
87 | * ------ ----------- ----------- ----------- ----------- | ||
88 | * 0x00 Port 0 I/O Port 0 I/O Port 0 I/O Port 0 I/O | ||
89 | * 0x01 Port 1 I/O Port 1 I/O Port 1 I/O Port 1 I/O | ||
90 | * 0x02 Port 2 I/O Port 2 I/O Port 2 I/O Port 2 I/O | ||
91 | * 0x03 Port 3 I/O Port 3 I/O Port 3 I/O Port 3 I/O | ||
92 | * 0x04 Port 4 I/O Port 4 I/O Port 4 I/O Port 4 I/O | ||
93 | * 0x05 Port 5 I/O Port 5 I/O Port 5 I/O Port 5 I/O | ||
94 | * 0x06 INT_PENDING INT_PENDING INT_PENDING INT_PENDING | ||
95 | * 0x07 Page/Lock Page/Lock Page/Lock Page/Lock | ||
96 | * 0x08 N/A POL_0 ENAB_0 INT_ID0 | ||
97 | * 0x09 N/A POL_1 ENAB_1 INT_ID1 | ||
98 | * 0x0a N/A POL_2 ENAB_2 INT_ID2 | ||
99 | */ | ||
100 | #define PCMUIO_PORT_REG(x) (0x00 + (x)) | ||
101 | #define PCMUIO_INT_PENDING_REG 0x06 | ||
102 | #define PCMUIO_PAGE_LOCK_REG 0x07 | ||
103 | #define PCMUIO_LOCK_PORT(x) ((1 << (x)) & 0x3f) | ||
104 | #define PCMUIO_PAGE(x) (((x) & 0x3) << 6) | ||
105 | #define PCMUIO_PAGE_MASK PCMUIO_PAGE(3) | ||
106 | #define PCMUIO_PAGE_POL 1 | ||
107 | #define PCMUIO_PAGE_ENAB 2 | ||
108 | #define PCMUIO_PAGE_INT_ID 3 | ||
109 | #define PCMUIO_PAGE_REG(x) (0x08 + (x)) | ||
110 | |||
83 | #define CHANS_PER_PORT 8 | 111 | #define CHANS_PER_PORT 8 |
84 | #define PORTS_PER_ASIC 6 | 112 | #define PORTS_PER_ASIC 6 |
85 | #define INTR_PORTS_PER_ASIC 3 | 113 | #define INTR_PORTS_PER_ASIC 3 |
@@ -97,53 +125,9 @@ | |||
97 | #define PCMUIO48_IOSIZE ASIC_IOSIZE | 125 | #define PCMUIO48_IOSIZE ASIC_IOSIZE |
98 | #define PCMUIO96_IOSIZE (ASIC_IOSIZE * 2) | 126 | #define PCMUIO96_IOSIZE (ASIC_IOSIZE * 2) |
99 | 127 | ||
100 | /* | ||
101 | * Some offsets - these are all in the 16byte IO memory offset from | ||
102 | * the base address. Note that there is a paging scheme to swap out | ||
103 | * offsets 0x8-0xA using the PAGELOCK register. See the table below. | ||
104 | * | ||
105 | * Register(s) Pages R/W? Description | ||
106 | * -------------------------------------------------------------------------- | ||
107 | * REG_PORTx All R/W Read/Write/Configure IO | ||
108 | * REG_INT_PENDING All ReadOnly Which INT_IDx has int. | ||
109 | * REG_PAGELOCK All WriteOnly Select a page | ||
110 | * REG_POLx Pg. 1 only WriteOnly Select edge-detection polarity | ||
111 | * REG_ENABx Pg. 2 only WriteOnly Enable/Disable edge-detect int. | ||
112 | * REG_INT_IDx Pg. 3 only R/W See which ports/bits have ints. | ||
113 | */ | ||
114 | #define REG_PORT0 0x0 | ||
115 | #define REG_PORT1 0x1 | ||
116 | #define REG_PORT2 0x2 | ||
117 | #define REG_PORT3 0x3 | ||
118 | #define REG_PORT4 0x4 | ||
119 | #define REG_PORT5 0x5 | ||
120 | #define REG_INT_PENDING 0x6 | ||
121 | /* | ||
122 | * page selector register | ||
123 | * Upper 2 bits select a page and bits 0-5 are used to | ||
124 | * 'lock down' a particular port above to make it readonly. | ||
125 | */ | ||
126 | #define REG_PAGELOCK 0x7 | ||
127 | #define REG_POL0 0x8 | ||
128 | #define REG_POL1 0x9 | ||
129 | #define REG_POL2 0xa | ||
130 | #define REG_ENAB0 0x8 | ||
131 | #define REG_ENAB1 0x9 | ||
132 | #define REG_ENAB2 0xa | ||
133 | #define REG_INT_ID0 0x8 | ||
134 | #define REG_INT_ID1 0x9 | ||
135 | #define REG_INT_ID2 0xa | ||
136 | |||
137 | #define NUM_PAGED_REGS 3 | 128 | #define NUM_PAGED_REGS 3 |
138 | #define NUM_PAGES 4 | 129 | #define NUM_PAGES 4 |
139 | #define FIRST_PAGED_REG 0x8 | 130 | #define FIRST_PAGED_REG 0x8 |
140 | #define REG_PAGE_BITOFFSET 6 | ||
141 | #define REG_LOCK_BITOFFSET 0 | ||
142 | #define REG_PAGE_MASK (~((0x1 << REG_PAGE_BITOFFSET) - 1)) | ||
143 | #define REG_LOCK_MASK ~(REG_PAGE_MASK) | ||
144 | #define PAGE_POL 1 | ||
145 | #define PAGE_ENAB 2 | ||
146 | #define PAGE_INT_ID 3 | ||
147 | 131 | ||
148 | struct pcmuio_board { | 132 | struct pcmuio_board { |
149 | const char *name; | 133 | const char *name; |
@@ -336,12 +320,12 @@ static void switch_page(struct comedi_device *dev, int asic, int page) | |||
336 | if (page < 0 || page >= NUM_PAGES) | 320 | if (page < 0 || page >= NUM_PAGES) |
337 | return; /* more paranoia */ | 321 | return; /* more paranoia */ |
338 | 322 | ||
339 | devpriv->asics[asic].pagelock &= ~REG_PAGE_MASK; | 323 | devpriv->asics[asic].pagelock &= ~PCMUIO_PAGE_MASK; |
340 | devpriv->asics[asic].pagelock |= page << REG_PAGE_BITOFFSET; | 324 | devpriv->asics[asic].pagelock |= PCMUIO_PAGE(page); |
341 | 325 | ||
342 | /* now write out the shadow register */ | 326 | /* now write out the shadow register */ |
343 | outb(devpriv->asics[asic].pagelock, | 327 | outb(devpriv->asics[asic].pagelock, |
344 | dev->iobase + ASIC_IOSIZE * asic + REG_PAGELOCK); | 328 | dev->iobase + ASIC_IOSIZE * asic + PCMUIO_PAGE_LOCK_REG); |
345 | } | 329 | } |
346 | 330 | ||
347 | static void init_asics(struct comedi_device *dev) | 331 | static void init_asics(struct comedi_device *dev) |
@@ -358,7 +342,7 @@ static void init_asics(struct comedi_device *dev) | |||
358 | 342 | ||
359 | /* first, clear all the DIO port bits */ | 343 | /* first, clear all the DIO port bits */ |
360 | for (port = 0; port < PORTS_PER_ASIC; ++port) | 344 | for (port = 0; port < PORTS_PER_ASIC; ++port) |
361 | outb(0, baseaddr + REG_PORT0 + port); | 345 | outb(0, baseaddr + PCMUIO_PORT_REG(port)); |
362 | 346 | ||
363 | /* Next, clear all the paged registers for each page */ | 347 | /* Next, clear all the paged registers for each page */ |
364 | for (page = 1; page < NUM_PAGES; ++page) { | 348 | for (page = 1; page < NUM_PAGES; ++page) { |
@@ -370,13 +354,6 @@ static void init_asics(struct comedi_device *dev) | |||
370 | outb(0, baseaddr + reg); | 354 | outb(0, baseaddr + reg); |
371 | } | 355 | } |
372 | 356 | ||
373 | /* DEBUG set rising edge interrupts on port0 of both asics */ | ||
374 | /*switch_page(dev, asic, PAGE_POL); | ||
375 | outb(0xff, baseaddr + REG_POL0); | ||
376 | switch_page(dev, asic, PAGE_ENAB); | ||
377 | outb(0xff, baseaddr + REG_ENAB0); */ | ||
378 | /* END DEBUG */ | ||
379 | |||
380 | /* switch back to default page 0 */ | 357 | /* switch back to default page 0 */ |
381 | switch_page(dev, asic, 0); | 358 | switch_page(dev, asic, 0); |
382 | } | 359 | } |
@@ -398,10 +375,10 @@ static void pcmuio_stop_intr(struct comedi_device *dev, | |||
398 | s->async->inttrig = NULL; | 375 | s->async->inttrig = NULL; |
399 | nports = subpriv->intr.num_asic_chans / CHANS_PER_PORT; | 376 | nports = subpriv->intr.num_asic_chans / CHANS_PER_PORT; |
400 | firstport = subpriv->intr.asic_chan / CHANS_PER_PORT; | 377 | firstport = subpriv->intr.asic_chan / CHANS_PER_PORT; |
401 | switch_page(dev, asic, PAGE_ENAB); | 378 | switch_page(dev, asic, PCMUIO_PAGE_ENAB); |
402 | for (port = firstport; port < firstport + nports; ++port) { | 379 | for (port = firstport; port < firstport + nports; ++port) { |
403 | /* disable all intrs for this subdev.. */ | 380 | /* disable all intrs for this subdev.. */ |
404 | outb(0, devpriv->asics[asic].iobase + REG_ENAB0 + port); | 381 | outb(0, devpriv->asics[asic].iobase + PCMUIO_PAGE_REG(port)); |
405 | } | 382 | } |
406 | } | 383 | } |
407 | 384 | ||
@@ -478,17 +455,17 @@ static int pcmuio_handle_asic_interrupt(struct comedi_device *dev, int asic) | |||
478 | 455 | ||
479 | spin_lock_irqsave(&devpriv->asics[asic].spinlock, flags); | 456 | spin_lock_irqsave(&devpriv->asics[asic].spinlock, flags); |
480 | 457 | ||
481 | int_pend = inb(iobase + REG_INT_PENDING) & 0x07; | 458 | int_pend = inb(iobase + PCMUIO_INT_PENDING_REG) & 0x07; |
482 | if (int_pend) { | 459 | if (int_pend) { |
483 | for (i = 0; i < INTR_PORTS_PER_ASIC; ++i) { | 460 | for (i = 0; i < INTR_PORTS_PER_ASIC; ++i) { |
484 | if (int_pend & (0x1 << i)) { | 461 | if (int_pend & (0x1 << i)) { |
485 | unsigned char val; | 462 | unsigned char val; |
486 | 463 | ||
487 | switch_page(dev, asic, PAGE_INT_ID); | 464 | switch_page(dev, asic, PCMUIO_PAGE_INT_ID); |
488 | val = inb(iobase + REG_INT_ID0 + i); | 465 | val = inb(iobase + PCMUIO_PAGE_REG(i)); |
489 | if (val) | 466 | if (val) |
490 | /* clear pending interrupt */ | 467 | /* clear pending interrupt */ |
491 | outb(0, iobase + REG_INT_ID0 + i); | 468 | outb(0, iobase + PCMUIO_PAGE_REG(i)); |
492 | 469 | ||
493 | triggered |= (val << (i * 8)); | 470 | triggered |= (val << (i * 8)); |
494 | } | 471 | } |
@@ -574,7 +551,7 @@ static int pcmuio_start_intr(struct comedi_device *dev, | |||
574 | 1) << subpriv->intr.first_chan; | 551 | 1) << subpriv->intr.first_chan; |
575 | subpriv->intr.enabled_mask = bits; | 552 | subpriv->intr.enabled_mask = bits; |
576 | 553 | ||
577 | switch_page(dev, asic, PAGE_ENAB); | 554 | switch_page(dev, asic, PCMUIO_PAGE_ENAB); |
578 | for (port = firstport; port < firstport + nports; ++port) { | 555 | for (port = firstport; port < firstport + nports; ++port) { |
579 | unsigned enab = | 556 | unsigned enab = |
580 | bits >> (subpriv->intr.first_chan + (port - | 557 | bits >> (subpriv->intr.first_chan + (port - |
@@ -584,10 +561,10 @@ static int pcmuio_start_intr(struct comedi_device *dev, | |||
584 | (port - firstport) * 8) & 0xff; | 561 | (port - firstport) * 8) & 0xff; |
585 | /* set enab intrs for this subdev.. */ | 562 | /* set enab intrs for this subdev.. */ |
586 | outb(enab, | 563 | outb(enab, |
587 | devpriv->asics[asic].iobase + REG_ENAB0 + port); | 564 | devpriv->asics[asic].iobase + PCMUIO_PAGE_REG(port)); |
588 | switch_page(dev, asic, PAGE_POL); | 565 | switch_page(dev, asic, PCMUIO_PAGE_POL); |
589 | outb(pol, | 566 | outb(pol, |
590 | devpriv->asics[asic].iobase + REG_ENAB0 + port); | 567 | devpriv->asics[asic].iobase + PCMUIO_PAGE_REG(port)); |
591 | } | 568 | } |
592 | } | 569 | } |
593 | return 0; | 570 | return 0; |