Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 317674
b: refs/heads/master
c: 944a2f1
h: refs/heads/master
v: v3
  • Loading branch information
H Hartley Sweeten authored and Greg Kroah-Hartman committed Jul 6, 2012
1 parent 751d204 commit 6d72769
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 100 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6f37e28821c38ea1981cef26ca6187cf307ea612
refs/heads/master: 944a2f111f5cb82c46b75a4990aa3afa4b243b35
182 changes: 83 additions & 99 deletions trunk/drivers/staging/comedi/drivers/ni_670x.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,105 +103,6 @@ struct ni_670x_private {

static struct comedi_lrange range_0_20mA = { 1, {RANGE_mA(0, 20)} };

static int ni_670x_find_device(struct comedi_device *dev, int bus, int slot);

static int ni_670x_ao_winsn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data);
static int ni_670x_ao_rinsn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data);
static int ni_670x_dio_insn_bits(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data);
static int ni_670x_dio_insn_config(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned int *data);

static int ni_670x_attach(struct comedi_device *dev,
struct comedi_devconfig *it)
{
struct comedi_subdevice *s;
int ret;
int i;

printk(KERN_INFO "comedi%d: ni_670x: ", dev->minor);

ret = alloc_private(dev, sizeof(struct ni_670x_private));
if (ret < 0)
return ret;

ret = ni_670x_find_device(dev, it->options[0], it->options[1]);
if (ret < 0)
return ret;

ret = mite_setup(devpriv->mite);
if (ret < 0) {
printk(KERN_WARNING "error setting up mite\n");
return ret;
}
dev->board_name = thisboard->name;
dev->irq = mite_irq(devpriv->mite);
printk(KERN_INFO " %s", dev->board_name);

ret = comedi_alloc_subdevices(dev, 2);
if (ret)
return ret;

s = dev->subdevices + 0;
/* analog output subdevice */
s->type = COMEDI_SUBD_AO;
s->subdev_flags = SDF_WRITABLE;
s->n_chan = thisboard->ao_chans;
s->maxdata = 0xffff;
if (s->n_chan == 32) {
const struct comedi_lrange **range_table_list;

range_table_list = kmalloc(sizeof(struct comedi_lrange *) * 32,
GFP_KERNEL);
if (!range_table_list)
return -ENOMEM;
s->range_table_list = range_table_list;
for (i = 0; i < 16; i++) {
range_table_list[i] = &range_bipolar10;
range_table_list[16 + i] = &range_0_20mA;
}
} else {
s->range_table = &range_bipolar10;
}
s->insn_write = &ni_670x_ao_winsn;
s->insn_read = &ni_670x_ao_rinsn;

s = dev->subdevices + 1;
/* digital i/o subdevice */
s->type = COMEDI_SUBD_DIO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
s->n_chan = 8;
s->maxdata = 1;
s->range_table = &range_digital;
s->insn_bits = ni_670x_dio_insn_bits;
s->insn_config = ni_670x_dio_insn_config;

/* Config of misc registers */
writel(0x10, devpriv->mite->daq_io_addr + MISC_CONTROL_OFFSET);
/* Config of ao registers */
writel(0x00, devpriv->mite->daq_io_addr + AO_CONTROL_OFFSET);

printk(KERN_INFO "attached\n");

return 1;
}

static void ni_670x_detach(struct comedi_device *dev)
{
kfree(dev->subdevices[0].range_table_list);
if (dev->private && devpriv->mite)
mite_unsetup(devpriv->mite);
if (dev->irq)
free_irq(dev->irq, dev);
}

static int ni_670x_ao_winsn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
Expand Down Expand Up @@ -320,6 +221,89 @@ static int ni_670x_find_device(struct comedi_device *dev, int bus, int slot)
return -EIO;
}

static int ni_670x_attach(struct comedi_device *dev,
struct comedi_devconfig *it)
{
struct comedi_subdevice *s;
int ret;
int i;

printk(KERN_INFO "comedi%d: ni_670x: ", dev->minor);

ret = alloc_private(dev, sizeof(struct ni_670x_private));
if (ret < 0)
return ret;

ret = ni_670x_find_device(dev, it->options[0], it->options[1]);
if (ret < 0)
return ret;

ret = mite_setup(devpriv->mite);
if (ret < 0) {
printk(KERN_WARNING "error setting up mite\n");
return ret;
}
dev->board_name = thisboard->name;
dev->irq = mite_irq(devpriv->mite);
printk(KERN_INFO " %s", dev->board_name);

ret = comedi_alloc_subdevices(dev, 2);
if (ret)
return ret;

s = dev->subdevices + 0;
/* analog output subdevice */
s->type = COMEDI_SUBD_AO;
s->subdev_flags = SDF_WRITABLE;
s->n_chan = thisboard->ao_chans;
s->maxdata = 0xffff;
if (s->n_chan == 32) {
const struct comedi_lrange **range_table_list;

range_table_list = kmalloc(sizeof(struct comedi_lrange *) * 32,
GFP_KERNEL);
if (!range_table_list)
return -ENOMEM;
s->range_table_list = range_table_list;
for (i = 0; i < 16; i++) {
range_table_list[i] = &range_bipolar10;
range_table_list[16 + i] = &range_0_20mA;
}
} else {
s->range_table = &range_bipolar10;
}
s->insn_write = &ni_670x_ao_winsn;
s->insn_read = &ni_670x_ao_rinsn;

s = dev->subdevices + 1;
/* digital i/o subdevice */
s->type = COMEDI_SUBD_DIO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
s->n_chan = 8;
s->maxdata = 1;
s->range_table = &range_digital;
s->insn_bits = ni_670x_dio_insn_bits;
s->insn_config = ni_670x_dio_insn_config;

/* Config of misc registers */
writel(0x10, devpriv->mite->daq_io_addr + MISC_CONTROL_OFFSET);
/* Config of ao registers */
writel(0x00, devpriv->mite->daq_io_addr + AO_CONTROL_OFFSET);

printk(KERN_INFO "attached\n");

return 1;
}

static void ni_670x_detach(struct comedi_device *dev)
{
kfree(dev->subdevices[0].range_table_list);
if (dev->private && devpriv->mite)
mite_unsetup(devpriv->mite);
if (dev->irq)
free_irq(dev->irq, dev);
}

static struct comedi_driver ni_670x_driver = {
.driver_name = "ni_670x",
.module = THIS_MODULE,
Expand Down

0 comments on commit 6d72769

Please sign in to comment.