1// SPDX-License-Identifier: GPL-2.0+
2/*
3 *  das08_pci.c
4 *  comedi driver for DAS08 PCI boards
5 *
6 *  COMEDI - Linux Control and Measurement Device Interface
7 *  Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8 *  Copyright (C) 2001,2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net>
9 *  Copyright (C) 2004 Salvador E. Tropea <set@users.sf.net> <set@ieee.org>
10 */
11
12/*
13 * Driver: das08_pci
14 * Description: DAS-08 PCI compatible boards
15 * Devices: [ComputerBoards] PCI-DAS08 (pci-das08)
16 * Author: Warren Jasper, ds, Frank Hess
17 * Updated: Fri, 31 Aug 2012 19:19:06 +0100
18 * Status: works
19 *
20 * This is the PCI-specific support split off from the das08 driver.
21 *
22 * Configuration Options: not applicable, uses PCI auto config
23 */
24
25#include <linux/module.h>
26#include <linux/comedi/comedi_pci.h>
27
28#include "das08.h"
29
30static const struct das08_board_struct das08_pci_boards[] = {
31	{
32		.name		= "pci-das08",
33		.ai_nbits	= 12,
34		.ai_pg		= das08_bipolar5,
35		.ai_encoding	= das08_encode12,
36		.di_nchan	= 3,
37		.do_nchan	= 4,
38		.i8254_offset	= 4,
39		.iosize		= 8,
40	},
41};
42
43static int das08_pci_auto_attach(struct comedi_device *dev,
44				 unsigned long context_unused)
45{
46	struct pci_dev *pdev = comedi_to_pci_dev(dev);
47	struct das08_private_struct *devpriv;
48	int ret;
49
50	devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
51	if (!devpriv)
52		return -ENOMEM;
53
54	/* The das08 driver needs the board_ptr */
55	dev->board_ptr = &das08_pci_boards[0];
56
57	ret = comedi_pci_enable(dev);
58	if (ret)
59		return ret;
60	dev->iobase = pci_resource_start(pdev, 2);
61
62	return das08_common_attach(dev, dev->iobase);
63}
64
65static struct comedi_driver das08_pci_comedi_driver = {
66	.driver_name	= "pci-das08",
67	.module		= THIS_MODULE,
68	.auto_attach	= das08_pci_auto_attach,
69	.detach		= comedi_pci_detach,
70};
71
72static int das08_pci_probe(struct pci_dev *dev,
73			   const struct pci_device_id *id)
74{
75	return comedi_pci_auto_config(dev, &das08_pci_comedi_driver,
76				      id->driver_data);
77}
78
79static const struct pci_device_id das08_pci_table[] = {
80	{ PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0029) },
81	{ 0 }
82};
83MODULE_DEVICE_TABLE(pci, das08_pci_table);
84
85static struct pci_driver das08_pci_driver = {
86	.name		= "pci-das08",
87	.id_table	= das08_pci_table,
88	.probe		= das08_pci_probe,
89	.remove		= comedi_pci_auto_unconfig,
90};
91module_comedi_pci_driver(das08_pci_comedi_driver, das08_pci_driver);
92
93MODULE_AUTHOR("Comedi https://www.comedi.org");
94MODULE_DESCRIPTION("Comedi low-level driver");
95MODULE_LICENSE("GPL");
96