Commit 18c284c6 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: pcl818: convert driver to use the comedi_8254 module

This driver uses an 8254 timer to generate the pacer clock used for analog
input data acquisition. Convert it to use the comedi_8254 module to provide
support for the 8254 timer.

Note that the pacer does not have to be stopped when starting a new async
command in pcl818_ai_cmd() or when the card is initialy reset by pcl818_reset().
The counters are all reset when the driver is initially attached and the
counters used by the pacer are stopped when a command is canceled.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f48c21fc
...@@ -191,6 +191,7 @@ config COMEDI_PCL816 ...@@ -191,6 +191,7 @@ config COMEDI_PCL816
config COMEDI_PCL818 config COMEDI_PCL818
tristate "Advantech PCL-718 and PCL-818 ISA card support" tristate "Advantech PCL-718 and PCL-818 ISA card support"
select COMEDI_ISADMA if ISA_DMA_API select COMEDI_ISADMA if ISA_DMA_API
select COMEDI_8254
---help--- ---help---
Enable support for Advantech PCL-818 ISA cards Enable support for Advantech PCL-818 ISA cards
PCL-818L, PCL-818H, PCL-818HD, PCL-818HG, PCL-818 and PCL-718 PCL-818L, PCL-818H, PCL-818HD, PCL-818HG, PCL-818 and PCL-718
......
...@@ -101,7 +101,7 @@ ...@@ -101,7 +101,7 @@
#include "comedi_isadma.h" #include "comedi_isadma.h"
#include "comedi_fc.h" #include "comedi_fc.h"
#include "8253.h" #include "comedi_8254.h"
/* boards constants */ /* boards constants */
...@@ -299,33 +299,15 @@ struct pcl818_private { ...@@ -299,33 +299,15 @@ struct pcl818_private {
struct comedi_isadma *dma; struct comedi_isadma *dma;
/* manimal allowed delay between samples (in us) for actual card */ /* manimal allowed delay between samples (in us) for actual card */
unsigned int ns_min; unsigned int ns_min;
int i8253_osc_base; /* 1/frequency of on board oscilator in ns */
/* MUX setting for actual AI operations */ /* MUX setting for actual AI operations */
unsigned int act_chanlist[16]; unsigned int act_chanlist[16];
unsigned int act_chanlist_len; /* how long is actual MUX list */ unsigned int act_chanlist_len; /* how long is actual MUX list */
unsigned int act_chanlist_pos; /* actual position in MUX list */ unsigned int act_chanlist_pos; /* actual position in MUX list */
unsigned int divisor1;
unsigned int divisor2;
unsigned int usefifo:1; unsigned int usefifo:1;
unsigned int ai_cmd_running:1; unsigned int ai_cmd_running:1;
unsigned int ai_cmd_canceled:1; unsigned int ai_cmd_canceled:1;
}; };
static void pcl818_start_pacer(struct comedi_device *dev, bool load_counters)
{
struct pcl818_private *devpriv = dev->private;
unsigned long timer_base = dev->iobase + PCL818_TIMER_BASE;
i8254_set_mode(timer_base, 0, 2, I8254_MODE2 | I8254_BINARY);
i8254_set_mode(timer_base, 0, 1, I8254_MODE2 | I8254_BINARY);
udelay(1);
if (load_counters) {
i8254_write(timer_base, 0, 2, devpriv->divisor2);
i8254_write(timer_base, 0, 1, devpriv->divisor1);
}
}
static void pcl818_ai_setup_dma(struct comedi_device *dev, static void pcl818_ai_setup_dma(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
unsigned int unread_samples) unsigned int unread_samples)
...@@ -663,9 +645,7 @@ static int ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, ...@@ -663,9 +645,7 @@ static int ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
struct comedi_cmd *cmd) struct comedi_cmd *cmd)
{ {
const struct pcl818_board *board = dev->board_ptr; const struct pcl818_board *board = dev->board_ptr;
struct pcl818_private *devpriv = dev->private;
int err = 0; int err = 0;
unsigned int arg;
/* Step 1 : check if triggers are trivially valid */ /* Step 1 : check if triggers are trivially valid */
...@@ -712,11 +692,9 @@ static int ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, ...@@ -712,11 +692,9 @@ static int ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
/* step 4: fix up any arguments */ /* step 4: fix up any arguments */
if (cmd->convert_src == TRIG_TIMER) { if (cmd->convert_src == TRIG_TIMER) {
arg = cmd->convert_arg; unsigned int arg = cmd->convert_arg;
i8253_cascade_ns_to_timer(devpriv->i8253_osc_base,
&devpriv->divisor1, comedi_8254_cascade_ns_to_timer(dev->pacer, &arg, cmd->flags);
&devpriv->divisor2,
&arg, cmd->flags);
err |= cfc_check_trigger_arg_is(&cmd->convert_arg, arg); err |= cfc_check_trigger_arg_is(&cmd->convert_arg, arg);
} }
...@@ -746,8 +724,6 @@ static int pcl818_ai_cmd(struct comedi_device *dev, ...@@ -746,8 +724,6 @@ static int pcl818_ai_cmd(struct comedi_device *dev,
if (devpriv->ai_cmd_running) if (devpriv->ai_cmd_running)
return -EBUSY; return -EBUSY;
pcl818_start_pacer(dev, false);
seglen = check_channel_list(dev, s, cmd->chanlist, cmd->chanlist_len); seglen = check_channel_list(dev, s, cmd->chanlist, cmd->chanlist_len);
if (seglen < 1) if (seglen < 1)
return -EINVAL; return -EINVAL;
...@@ -779,8 +755,10 @@ static int pcl818_ai_cmd(struct comedi_device *dev, ...@@ -779,8 +755,10 @@ static int pcl818_ai_cmd(struct comedi_device *dev,
} }
outb(ctrl, dev->iobase + PCL818_CTRL_REG); outb(ctrl, dev->iobase + PCL818_CTRL_REG);
if (cmd->convert_src == TRIG_TIMER) if (cmd->convert_src == TRIG_TIMER) {
pcl818_start_pacer(dev, true); comedi_8254_update_divisors(dev->pacer);
comedi_8254_pacer_enable(dev->pacer, 1, 2, true);
}
return 0; return 0;
} }
...@@ -812,7 +790,7 @@ static int pcl818_ai_cancel(struct comedi_device *dev, ...@@ -812,7 +790,7 @@ static int pcl818_ai_cancel(struct comedi_device *dev,
} }
outb(PCL818_CTRL_DISABLE_TRIG, dev->iobase + PCL818_CTRL_REG); outb(PCL818_CTRL_DISABLE_TRIG, dev->iobase + PCL818_CTRL_REG);
pcl818_start_pacer(dev, false); comedi_8254_pacer_enable(dev->pacer, 1, 2, false);
pcl818_ai_clear_eoc(dev); pcl818_ai_clear_eoc(dev);
if (devpriv->usefifo) { /* FIFO shutdown */ if (devpriv->usefifo) { /* FIFO shutdown */
...@@ -906,7 +884,6 @@ static int pcl818_do_insn_bits(struct comedi_device *dev, ...@@ -906,7 +884,6 @@ static int pcl818_do_insn_bits(struct comedi_device *dev,
static void pcl818_reset(struct comedi_device *dev) static void pcl818_reset(struct comedi_device *dev)
{ {
const struct pcl818_board *board = dev->board_ptr; const struct pcl818_board *board = dev->board_ptr;
unsigned long timer_base = dev->iobase + PCL818_TIMER_BASE;
unsigned int chan; unsigned int chan;
/* flush and disable the FIFO */ /* flush and disable the FIFO */
...@@ -924,9 +901,6 @@ static void pcl818_reset(struct comedi_device *dev) ...@@ -924,9 +901,6 @@ static void pcl818_reset(struct comedi_device *dev)
/* stop pacer */ /* stop pacer */
outb(PCL818_CNTENABLE_PACER_ENA, dev->iobase + PCL818_CNTENABLE_REG); outb(PCL818_CNTENABLE_PACER_ENA, dev->iobase + PCL818_CNTENABLE_REG);
i8254_set_mode(timer_base, 0, 2, I8254_MODE0 | I8254_BINARY);
i8254_set_mode(timer_base, 0, 1, I8254_MODE0 | I8254_BINARY);
i8254_set_mode(timer_base, 0, 0, I8254_MODE0 | I8254_BINARY);
/* set analog output channels to 0V */ /* set analog output channels to 0V */
for (chan = 0; chan < board->n_aochan; chan++) { for (chan = 0; chan < board->n_aochan; chan++) {
...@@ -1016,6 +990,7 @@ static int pcl818_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -1016,6 +990,7 @@ static int pcl818_attach(struct comedi_device *dev, struct comedi_devconfig *it)
const struct pcl818_board *board = dev->board_ptr; const struct pcl818_board *board = dev->board_ptr;
struct pcl818_private *devpriv; struct pcl818_private *devpriv;
struct comedi_subdevice *s; struct comedi_subdevice *s;
unsigned int osc_base;
int ret; int ret;
devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv)); devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
...@@ -1043,6 +1018,25 @@ static int pcl818_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -1043,6 +1018,25 @@ static int pcl818_attach(struct comedi_device *dev, struct comedi_devconfig *it)
if (dev->irq && board->has_dma) if (dev->irq && board->has_dma)
pcl818_alloc_dma(dev, it->options[2]); pcl818_alloc_dma(dev, it->options[2]);
/* use 1MHz or 10MHz oscilator */
if ((it->options[3] == 0) || (it->options[3] == 10))
osc_base = I8254_OSC_BASE_10MHZ;
else
osc_base = I8254_OSC_BASE_1MHZ;
dev->pacer = comedi_8254_init(dev->iobase + PCL818_TIMER_BASE,
osc_base, I8254_IO8, 0);
if (!dev->pacer)
return -ENOMEM;
/* max sampling speed */
devpriv->ns_min = board->ns_min;
if (!board->is_818) {
/* extended PCL718 to 100kHz DAC */
if ((it->options[6] == 1) || (it->options[6] == 100))
devpriv->ns_min = 10000;
}
ret = comedi_alloc_subdevices(dev, 4); ret = comedi_alloc_subdevices(dev, 4);
if (ret) if (ret)
return ret; return ret;
...@@ -1117,22 +1111,6 @@ static int pcl818_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -1117,22 +1111,6 @@ static int pcl818_attach(struct comedi_device *dev, struct comedi_devconfig *it)
s->range_table = &range_digital; s->range_table = &range_digital;
s->insn_bits = pcl818_do_insn_bits; s->insn_bits = pcl818_do_insn_bits;
/* select 1/10MHz oscilator */
if ((it->options[3] == 0) || (it->options[3] == 10))
devpriv->i8253_osc_base = I8254_OSC_BASE_10MHZ;
else
devpriv->i8253_osc_base = I8254_OSC_BASE_1MHZ;
/* max sampling speed */
devpriv->ns_min = board->ns_min;
if (!board->is_818) {
if ((it->options[6] == 1) || (it->options[6] == 100)) {
/* extended PCL718 to 100kHz DAC */
devpriv->ns_min = 10000;
}
}
pcl818_reset(dev); pcl818_reset(dev);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment