[PATCH 6/9] staging: comedi: support auto_attach() for PCI and USB

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allow `comedi_pci_auto_config()` and `comedi_usb_auto_config()` to use
the new `auto_attach()` hook in the low-level driver's `struct
comedi_driver` if it is set and the `attach_pci()` or `attach_usb()`
hook (for PCI or USB respectively) is `NULL`.

Eventually, the `auto_attach()` hook will be the only way of
auto-configuring hardware devices as comedi devices and the bus-type
specific `attach_pci()` and `attach_usb()` hooks will be removed.

To allow the unlikely case of a low-level driver supporting both PCI and
USB devices, the `context` parameter of the `auto_attach()` hook will be
set to a value to disambiguate these cases.  Define values
`COMEDI_AUTO_ATTACH_PCI` and `COMEDI_AUTO_ATTACH_USB` for this purpose.
Most low-level drivers will just ignore the `context` parameter.

Signed-off-by: Ian Abbott <abbotti@xxxxxxxxx>
---
 drivers/staging/comedi/comedidev.h | 4 ++++
 drivers/staging/comedi/drivers.c   | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h
index dd94add..96d391a 100644
--- a/drivers/staging/comedi/comedidev.h
+++ b/drivers/staging/comedi/comedidev.h
@@ -62,6 +62,10 @@
 #define COMEDI_NUM_BOARD_MINORS 0x30
 #define COMEDI_FIRST_SUBDEVICE_MINOR COMEDI_NUM_BOARD_MINORS
 
+/* auto_attach() context values */
+#define COMEDI_AUTO_ATTACH_PCI	(-1UL)	/* from comedi_pci_auto_config() */
+#define COMEDI_AUTO_ATTACH_USB	(-2UL)	/* from comedi_usb_auto_config() */
+
 struct comedi_subdevice {
 	struct comedi_device *device;
 	int type;
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index d60fa55..ceeda76 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -1023,6 +1023,9 @@ int comedi_pci_auto_config(struct pci_dev *pcidev, struct comedi_driver *driver)
 
 	if (driver->attach_pci)
 		return comedi_new_pci_auto_config(pcidev, driver);
+	else if (driver->auto_attach)
+		return comedi_auto_config(&pcidev->dev, driver,
+					  COMEDI_AUTO_ATTACH_PCI);
 	else
 		return comedi_old_pci_auto_config(pcidev, driver);
 }
@@ -1093,6 +1096,9 @@ int comedi_usb_auto_config(struct usb_interface *intf,
 	BUG_ON(intf == NULL);
 	if (driver->attach_usb)
 		return comedi_new_usb_auto_config(intf, driver);
+	else if (driver->auto_attach)
+		return comedi_auto_config(&intf->dev, driver,
+					  COMEDI_AUTO_ATTACH_USB);
 	else
 		return comedi_old_usb_auto_config(intf, driver);
 }
-- 
1.7.12

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel


[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux