122691aec19371c0817565c3af54e276884e908eeIan Abbott/* 222691aec19371c0817565c3af54e276884e908eeIan Abbott comedi/drivers/amplc_pci263.c 322691aec19371c0817565c3af54e276884e908eeIan Abbott Driver for Amplicon PCI263 relay board. 422691aec19371c0817565c3af54e276884e908eeIan Abbott 522691aec19371c0817565c3af54e276884e908eeIan Abbott Copyright (C) 2002 MEV Ltd. <http://www.mev.co.uk/> 622691aec19371c0817565c3af54e276884e908eeIan Abbott 722691aec19371c0817565c3af54e276884e908eeIan Abbott COMEDI - Linux Control and Measurement Device Interface 822691aec19371c0817565c3af54e276884e908eeIan Abbott Copyright (C) 2000 David A. Schleef <ds@schleef.org> 922691aec19371c0817565c3af54e276884e908eeIan Abbott 1022691aec19371c0817565c3af54e276884e908eeIan Abbott This program is free software; you can redistribute it and/or modify 1122691aec19371c0817565c3af54e276884e908eeIan Abbott it under the terms of the GNU General Public License as published by 1222691aec19371c0817565c3af54e276884e908eeIan Abbott the Free Software Foundation; either version 2 of the License, or 1322691aec19371c0817565c3af54e276884e908eeIan Abbott (at your option) any later version. 1422691aec19371c0817565c3af54e276884e908eeIan Abbott 1522691aec19371c0817565c3af54e276884e908eeIan Abbott This program is distributed in the hope that it will be useful, 1622691aec19371c0817565c3af54e276884e908eeIan Abbott but WITHOUT ANY WARRANTY; without even the implied warranty of 1722691aec19371c0817565c3af54e276884e908eeIan Abbott MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1822691aec19371c0817565c3af54e276884e908eeIan Abbott GNU General Public License for more details. 1922691aec19371c0817565c3af54e276884e908eeIan Abbott*/ 2022691aec19371c0817565c3af54e276884e908eeIan Abbott/* 2122691aec19371c0817565c3af54e276884e908eeIan AbbottDriver: amplc_pci263 2222691aec19371c0817565c3af54e276884e908eeIan AbbottDescription: Amplicon PCI263 2322691aec19371c0817565c3af54e276884e908eeIan AbbottAuthor: Ian Abbott <abbotti@mev.co.uk> 2422691aec19371c0817565c3af54e276884e908eeIan AbbottDevices: [Amplicon] PCI263 (amplc_pci263) 2522691aec19371c0817565c3af54e276884e908eeIan AbbottUpdated: Fri, 12 Apr 2013 15:19:36 +0100 2622691aec19371c0817565c3af54e276884e908eeIan AbbottStatus: works 2722691aec19371c0817565c3af54e276884e908eeIan Abbott 2822691aec19371c0817565c3af54e276884e908eeIan AbbottConfiguration options: not applicable, uses PCI auto config 2922691aec19371c0817565c3af54e276884e908eeIan Abbott 3022691aec19371c0817565c3af54e276884e908eeIan AbbottThe board appears as one subdevice, with 16 digital outputs, each 3122691aec19371c0817565c3af54e276884e908eeIan Abbottconnected to a reed-relay. Relay contacts are closed when output is 1. 3222691aec19371c0817565c3af54e276884e908eeIan AbbottThe state of the outputs can be read. 3322691aec19371c0817565c3af54e276884e908eeIan Abbott*/ 3422691aec19371c0817565c3af54e276884e908eeIan Abbott 35ce157f8032bbd46d9427034c335b0afd751da25dH Hartley Sweeten#include <linux/module.h> 3622691aec19371c0817565c3af54e276884e908eeIan Abbott#include <linux/pci.h> 3722691aec19371c0817565c3af54e276884e908eeIan Abbott 3822691aec19371c0817565c3af54e276884e908eeIan Abbott#include "../comedidev.h" 3922691aec19371c0817565c3af54e276884e908eeIan Abbott 4022691aec19371c0817565c3af54e276884e908eeIan Abbottstatic int pci263_do_insn_bits(struct comedi_device *dev, 4122691aec19371c0817565c3af54e276884e908eeIan Abbott struct comedi_subdevice *s, 4297f4289ad08cffe55de06d4ac4f89ac540450aeeH Hartley Sweeten struct comedi_insn *insn, 4397f4289ad08cffe55de06d4ac4f89ac540450aeeH Hartley Sweeten unsigned int *data) 4422691aec19371c0817565c3af54e276884e908eeIan Abbott{ 4597f4289ad08cffe55de06d4ac4f89ac540450aeeH Hartley Sweeten if (comedi_dio_update_state(s, data)) { 4697f4289ad08cffe55de06d4ac4f89ac540450aeeH Hartley Sweeten outb(s->state & 0xff, dev->iobase); 4797f4289ad08cffe55de06d4ac4f89ac540450aeeH Hartley Sweeten outb((s->state >> 8) & 0xff, dev->iobase + 1); 4822691aec19371c0817565c3af54e276884e908eeIan Abbott } 4997f4289ad08cffe55de06d4ac4f89ac540450aeeH Hartley Sweeten 5097f4289ad08cffe55de06d4ac4f89ac540450aeeH Hartley Sweeten data[1] = s->state; 5197f4289ad08cffe55de06d4ac4f89ac540450aeeH Hartley Sweeten 5222691aec19371c0817565c3af54e276884e908eeIan Abbott return insn->n; 5322691aec19371c0817565c3af54e276884e908eeIan Abbott} 5422691aec19371c0817565c3af54e276884e908eeIan Abbott 5522691aec19371c0817565c3af54e276884e908eeIan Abbottstatic int pci263_auto_attach(struct comedi_device *dev, 5622691aec19371c0817565c3af54e276884e908eeIan Abbott unsigned long context_unused) 5722691aec19371c0817565c3af54e276884e908eeIan Abbott{ 5822691aec19371c0817565c3af54e276884e908eeIan Abbott struct pci_dev *pci_dev = comedi_to_pci_dev(dev); 5922691aec19371c0817565c3af54e276884e908eeIan Abbott struct comedi_subdevice *s; 6022691aec19371c0817565c3af54e276884e908eeIan Abbott int ret; 6122691aec19371c0817565c3af54e276884e908eeIan Abbott 6222691aec19371c0817565c3af54e276884e908eeIan Abbott ret = comedi_pci_enable(dev); 6322691aec19371c0817565c3af54e276884e908eeIan Abbott if (ret) 6422691aec19371c0817565c3af54e276884e908eeIan Abbott return ret; 6522691aec19371c0817565c3af54e276884e908eeIan Abbott 6622691aec19371c0817565c3af54e276884e908eeIan Abbott dev->iobase = pci_resource_start(pci_dev, 2); 6722691aec19371c0817565c3af54e276884e908eeIan Abbott ret = comedi_alloc_subdevices(dev, 1); 6822691aec19371c0817565c3af54e276884e908eeIan Abbott if (ret) 6922691aec19371c0817565c3af54e276884e908eeIan Abbott return ret; 7022691aec19371c0817565c3af54e276884e908eeIan Abbott 7122691aec19371c0817565c3af54e276884e908eeIan Abbott s = &dev->subdevices[0]; 7222691aec19371c0817565c3af54e276884e908eeIan Abbott /* digital output subdevice */ 7322691aec19371c0817565c3af54e276884e908eeIan Abbott s->type = COMEDI_SUBD_DO; 7422691aec19371c0817565c3af54e276884e908eeIan Abbott s->subdev_flags = SDF_READABLE | SDF_WRITABLE; 7522691aec19371c0817565c3af54e276884e908eeIan Abbott s->n_chan = 16; 7622691aec19371c0817565c3af54e276884e908eeIan Abbott s->maxdata = 1; 7722691aec19371c0817565c3af54e276884e908eeIan Abbott s->range_table = &range_digital; 7822691aec19371c0817565c3af54e276884e908eeIan Abbott s->insn_bits = pci263_do_insn_bits; 7922691aec19371c0817565c3af54e276884e908eeIan Abbott /* read initial relay state */ 8022691aec19371c0817565c3af54e276884e908eeIan Abbott s->state = inb(dev->iobase) | (inb(dev->iobase + 1) << 8); 8122691aec19371c0817565c3af54e276884e908eeIan Abbott 8222691aec19371c0817565c3af54e276884e908eeIan Abbott return 0; 8322691aec19371c0817565c3af54e276884e908eeIan Abbott} 8422691aec19371c0817565c3af54e276884e908eeIan Abbott 8522691aec19371c0817565c3af54e276884e908eeIan Abbottstatic struct comedi_driver amplc_pci263_driver = { 863d03cfcaf6cde186f439ca1a318423007570760aH Hartley Sweeten .driver_name = "amplc_pci263", 8722691aec19371c0817565c3af54e276884e908eeIan Abbott .module = THIS_MODULE, 8822691aec19371c0817565c3af54e276884e908eeIan Abbott .auto_attach = pci263_auto_attach, 89aac307f9dd5ce1fe651140a036ab4b0a0571b54aH Hartley Sweeten .detach = comedi_pci_detach, 9022691aec19371c0817565c3af54e276884e908eeIan Abbott}; 9122691aec19371c0817565c3af54e276884e908eeIan Abbott 9241e043fcfa2236bb2c4a8335eb09f4c8cee224b3Jingoo Hanstatic const struct pci_device_id pci263_pci_table[] = { 93472cd3db7b47a0720678e4c7cc1a472d2c06c218H Hartley Sweeten { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, 0x000c) }, 9422691aec19371c0817565c3af54e276884e908eeIan Abbott {0} 9522691aec19371c0817565c3af54e276884e908eeIan Abbott}; 9622691aec19371c0817565c3af54e276884e908eeIan AbbottMODULE_DEVICE_TABLE(pci, pci263_pci_table); 9722691aec19371c0817565c3af54e276884e908eeIan Abbott 9822691aec19371c0817565c3af54e276884e908eeIan Abbottstatic int amplc_pci263_pci_probe(struct pci_dev *dev, 9922691aec19371c0817565c3af54e276884e908eeIan Abbott const struct pci_device_id *id) 10022691aec19371c0817565c3af54e276884e908eeIan Abbott{ 10122691aec19371c0817565c3af54e276884e908eeIan Abbott return comedi_pci_auto_config(dev, &lc_pci263_driver, 10222691aec19371c0817565c3af54e276884e908eeIan Abbott id->driver_data); 10322691aec19371c0817565c3af54e276884e908eeIan Abbott} 10422691aec19371c0817565c3af54e276884e908eeIan Abbott 10522691aec19371c0817565c3af54e276884e908eeIan Abbottstatic struct pci_driver amplc_pci263_pci_driver = { 1063d03cfcaf6cde186f439ca1a318423007570760aH Hartley Sweeten .name = "amplc_pci263", 10722691aec19371c0817565c3af54e276884e908eeIan Abbott .id_table = pci263_pci_table, 10822691aec19371c0817565c3af54e276884e908eeIan Abbott .probe = &lc_pci263_pci_probe, 10922691aec19371c0817565c3af54e276884e908eeIan Abbott .remove = comedi_pci_auto_unconfig, 11022691aec19371c0817565c3af54e276884e908eeIan Abbott}; 11122691aec19371c0817565c3af54e276884e908eeIan Abbottmodule_comedi_pci_driver(amplc_pci263_driver, amplc_pci263_pci_driver); 11222691aec19371c0817565c3af54e276884e908eeIan Abbott 11322691aec19371c0817565c3af54e276884e908eeIan AbbottMODULE_AUTHOR("Comedi http://www.comedi.org"); 11422691aec19371c0817565c3af54e276884e908eeIan AbbottMODULE_DESCRIPTION("Comedi driver for Amplicon PCI263 relay board"); 11522691aec19371c0817565c3af54e276884e908eeIan AbbottMODULE_LICENSE("GPL"); 116