diff options
author | H Hartley Sweeten <hsweeten@visionengravers.com> | 2014-05-29 13:45:52 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-06-18 17:47:07 -0400 |
commit | f40c283a170a2c817b4eb3616adb3f86b4577f49 (patch) | |
tree | f6ee2fd5ed1b3d6e99d8275bbd5170f90e9bb402 | |
parent | 3e18c5284ad4ba93eafd1f1f528bff21a962e5d0 (diff) |
staging: comedi: ke_counter: add ability to select counter clock source
Add an (*insn_config) to the counter subdevice to allow the user to select
the clock source for the counters using the INSN_CONFIG_SET_CLOCK_SRC
instruction. The current selection can be queried with the instruction
INSN_CONFIG_GET_CLOCK_SRC.
Also, handle the INSN_CONFIG_RESET instruction to reset all the counters.
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/ke_counter.c | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/drivers/staging/comedi/drivers/ke_counter.c b/drivers/staging/comedi/drivers/ke_counter.c index ec43c38958de..ed873c45e011 100644 --- a/drivers/staging/comedi/drivers/ke_counter.c +++ b/drivers/staging/comedi/drivers/ke_counter.c | |||
@@ -93,6 +93,58 @@ static int ke_counter_insn_read(struct comedi_device *dev, | |||
93 | return insn->n; | 93 | return insn->n; |
94 | } | 94 | } |
95 | 95 | ||
96 | static void ke_counter_reset(struct comedi_device *dev) | ||
97 | { | ||
98 | unsigned int chan; | ||
99 | |||
100 | for (chan = 0; chan < 3; chan++) | ||
101 | outb(0, dev->iobase + KE_RESET_REG(chan)); | ||
102 | } | ||
103 | |||
104 | static int ke_counter_insn_config(struct comedi_device *dev, | ||
105 | struct comedi_subdevice *s, | ||
106 | struct comedi_insn *insn, | ||
107 | unsigned int *data) | ||
108 | { | ||
109 | switch (data[0]) { | ||
110 | case INSN_CONFIG_SET_CLOCK_SRC: | ||
111 | switch (data[1]) { | ||
112 | case KE_OSC_SEL_EXT: /* Pin 21 on D-sub */ | ||
113 | case KE_OSC_SEL_4MHZ: /* option */ | ||
114 | case KE_OSC_SEL_20MHZ: /* default */ | ||
115 | break; | ||
116 | default: | ||
117 | return -EINVAL; | ||
118 | } | ||
119 | outb(data[1], dev->iobase + KE_OSC_SEL_REG); | ||
120 | break; | ||
121 | case INSN_CONFIG_GET_CLOCK_SRC: | ||
122 | data[1] = inb(dev->iobase + KE_OSC_SEL_REG); | ||
123 | switch (data[1]) { | ||
124 | case KE_OSC_SEL_EXT: | ||
125 | data[2] = 0; /* Unknown */ | ||
126 | break; | ||
127 | case KE_OSC_SEL_4MHZ: | ||
128 | data[2] = 250; /* 250ns */ | ||
129 | break; | ||
130 | case KE_OSC_SEL_20MHZ: | ||
131 | data[2] = 50; /* 50ns */ | ||
132 | break; | ||
133 | default: | ||
134 | data[2] = 0; /* Invalid? */ | ||
135 | break; | ||
136 | } | ||
137 | break; | ||
138 | case INSN_CONFIG_RESET: | ||
139 | ke_counter_reset(dev); | ||
140 | break; | ||
141 | default: | ||
142 | return -EINVAL; | ||
143 | } | ||
144 | |||
145 | return insn->n; | ||
146 | } | ||
147 | |||
96 | static int ke_counter_do_insn_bits(struct comedi_device *dev, | 148 | static int ke_counter_do_insn_bits(struct comedi_device *dev, |
97 | struct comedi_subdevice *s, | 149 | struct comedi_subdevice *s, |
98 | struct comedi_insn *insn, | 150 | struct comedi_insn *insn, |
@@ -130,6 +182,7 @@ static int ke_counter_auto_attach(struct comedi_device *dev, | |||
130 | s->range_table = &range_unknown; | 182 | s->range_table = &range_unknown; |
131 | s->insn_read = ke_counter_insn_read; | 183 | s->insn_read = ke_counter_insn_read; |
132 | s->insn_write = ke_counter_insn_write; | 184 | s->insn_write = ke_counter_insn_write; |
185 | s->insn_config = ke_counter_insn_config; | ||
133 | 186 | ||
134 | s = &dev->subdevices[1]; | 187 | s = &dev->subdevices[1]; |
135 | s->type = COMEDI_SUBD_DO; | 188 | s->type = COMEDI_SUBD_DO; |
@@ -141,9 +194,7 @@ static int ke_counter_auto_attach(struct comedi_device *dev, | |||
141 | 194 | ||
142 | outb(KE_OSC_SEL_20MHZ, dev->iobase + KE_OSC_SEL_REG); | 195 | outb(KE_OSC_SEL_20MHZ, dev->iobase + KE_OSC_SEL_REG); |
143 | 196 | ||
144 | outb(0, dev->iobase + KE_RESET_REG(0)); | 197 | ke_counter_reset(dev); |
145 | outb(0, dev->iobase + KE_RESET_REG(1)); | ||
146 | outb(0, dev->iobase + KE_RESET_REG(2)); | ||
147 | 198 | ||
148 | return 0; | 199 | return 0; |
149 | } | 200 | } |