Commit b4843c19 authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: amplc_pc263: Use IS_ENABLED()

Change conditional compilation on kernel options to use the IS_ENABLED()
macro.  Remove most of the #ifdef lines and add extra if
(IS_ENABLED(xxx)) tests so the compiler can remove unreachable code.
The pci_driver stuff and device table is still conditionally compiled.

In pc263_attach() move the call to alloc_private() as it is only used
for PCI devices.  (In pc263_detach(), for ISA devices a non-zero
dev->iobase means the I/O region needs releasing.)
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 61f5a223
...@@ -48,14 +48,6 @@ The state of the outputs can be read. ...@@ -48,14 +48,6 @@ The state of the outputs can be read.
#define PC263_DRIVER_NAME "amplc_pc263" #define PC263_DRIVER_NAME "amplc_pc263"
#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA_MODULE
#define CONFIG_COMEDI_AMPLC_PC263_ISA
#endif
#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI_MODULE
#define CONFIG_COMEDI_AMPLC_PC263_PCI
#endif
/* PCI263 PCI configuration register information */ /* PCI263 PCI configuration register information */
#define PCI_VENDOR_ID_AMPLICON 0x14dc #define PCI_VENDOR_ID_AMPLICON 0x14dc
#define PCI_DEVICE_ID_AMPLICON_PCI263 0x000c #define PCI_DEVICE_ID_AMPLICON_PCI263 0x000c
...@@ -79,7 +71,7 @@ struct pc263_board { ...@@ -79,7 +71,7 @@ struct pc263_board {
enum pc263_model model; enum pc263_model model;
}; };
static const struct pc263_board pc263_boards[] = { static const struct pc263_board pc263_boards[] = {
#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA #if IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_ISA)
{ {
.name = "pc263", .name = "pc263",
.fancy_name = "PC263", .fancy_name = "PC263",
...@@ -87,7 +79,7 @@ static const struct pc263_board pc263_boards[] = { ...@@ -87,7 +79,7 @@ static const struct pc263_board pc263_boards[] = {
.model = pc263_model, .model = pc263_model,
}, },
#endif #endif
#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI #if IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_PCI)
{ {
.name = "pci263", .name = "pci263",
.fancy_name = "PCI263", .fancy_name = "PCI263",
...@@ -105,7 +97,7 @@ static const struct pc263_board pc263_boards[] = { ...@@ -105,7 +97,7 @@ static const struct pc263_board pc263_boards[] = {
#endif #endif
}; };
#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI #if IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_PCI)
static DEFINE_PCI_DEVICE_TABLE(pc263_pci_table) = { static DEFINE_PCI_DEVICE_TABLE(pc263_pci_table) = {
{ PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI263) }, { PCI_DEVICE(PCI_VENDOR_ID_AMPLICON, PCI_DEVICE_ID_AMPLICON_PCI263) },
{0} {0}
...@@ -123,14 +115,12 @@ MODULE_DEVICE_TABLE(pci, pc263_pci_table); ...@@ -123,14 +115,12 @@ MODULE_DEVICE_TABLE(pci, pc263_pci_table);
several hardware drivers keep similar information in this structure, several hardware drivers keep similar information in this structure,
feel free to suggest moving the variable to the struct comedi_device struct. feel free to suggest moving the variable to the struct comedi_device struct.
*/ */
#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
struct pc263_private { struct pc263_private {
/* PCI device. */ /* PCI device. */
struct pci_dev *pci_dev; struct pci_dev *pci_dev;
}; };
#define devpriv ((struct pc263_private *)dev->private) #define devpriv ((struct pc263_private *)dev->private)
#endif /* CONFIG_COMEDI_AMPLC_PC263_PCI */
/* /*
* The struct comedi_driver structure tells the Comedi core module * The struct comedi_driver structure tells the Comedi core module
...@@ -150,10 +140,8 @@ static struct comedi_driver driver_amplc_pc263 = { ...@@ -150,10 +140,8 @@ static struct comedi_driver driver_amplc_pc263 = {
.num_names = ARRAY_SIZE(pc263_boards), .num_names = ARRAY_SIZE(pc263_boards),
}; };
#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA
static int pc263_request_region(unsigned minor, unsigned long from, static int pc263_request_region(unsigned minor, unsigned long from,
unsigned long extent); unsigned long extent);
#endif
static int pc263_do_insn_bits(struct comedi_device *dev, static int pc263_do_insn_bits(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data); struct comedi_insn *insn, unsigned int *data);
...@@ -162,7 +150,6 @@ static int pc263_do_insn_bits(struct comedi_device *dev, ...@@ -162,7 +150,6 @@ static int pc263_do_insn_bits(struct comedi_device *dev,
* This function looks for a PCI device matching the requested board name, * This function looks for a PCI device matching the requested board name,
* bus and slot. * bus and slot.
*/ */
#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
static int static int
pc263_find_pci(struct comedi_device *dev, int bus, int slot, pc263_find_pci(struct comedi_device *dev, int bus, int slot,
struct pci_dev **pci_dev_p) struct pci_dev **pci_dev_p)
...@@ -218,7 +205,6 @@ pc263_find_pci(struct comedi_device *dev, int bus, int slot, ...@@ -218,7 +205,6 @@ pc263_find_pci(struct comedi_device *dev, int bus, int slot,
} }
return -EIO; return -EIO;
} }
#endif
/* /*
* Attach is called by the Comedi core to configure the driver * Attach is called by the Comedi core to configure the driver
...@@ -230,60 +216,35 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -230,60 +216,35 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
{ {
struct comedi_subdevice *s; struct comedi_subdevice *s;
unsigned long iobase = 0; unsigned long iobase = 0;
#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
struct pci_dev *pci_dev = NULL;
int bus = 0, slot = 0;
#endif
int ret; int ret;
printk(KERN_DEBUG "comedi%d: %s: attach\n", dev->minor, printk(KERN_DEBUG "comedi%d: %s: attach\n", dev->minor,
PC263_DRIVER_NAME); PC263_DRIVER_NAME);
/*
* Allocate the private structure area. alloc_private() is a /* Process options and reserve resources according to bus type. */
* convenient macro defined in comedidev.h. if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_ISA) &&
*/ thisboard->bustype == isa_bustype) {
#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI iobase = it->options[0];
ret = pc263_request_region(dev->minor, iobase, PC263_IO_SIZE);
if (ret < 0)
return ret;
} else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_PCI) &&
thisboard->bustype == pci_bustype) {
struct pci_dev *pci_dev = NULL;
int bus, slot;
ret = alloc_private(dev, sizeof(struct pc263_private)); ret = alloc_private(dev, sizeof(struct pc263_private));
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR "comedi%d: error! out of memory!\n", printk(KERN_ERR "comedi%d: error! out of memory!\n",
dev->minor); dev->minor);
return ret; return ret;
} }
#endif
/* Process options. */
switch (thisboard->bustype) {
#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA
case isa_bustype:
iobase = it->options[0];
break;
#endif
#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
case pci_bustype:
bus = it->options[0]; bus = it->options[0];
slot = it->options[1]; slot = it->options[1];
ret = pc263_find_pci(dev, bus, slot, &pci_dev); ret = pc263_find_pci(dev, bus, slot, &pci_dev);
if (ret < 0) if (ret < 0)
return ret; return ret;
devpriv->pci_dev = pci_dev; devpriv->pci_dev = pci_dev;
break;
#endif
default:
printk(KERN_ERR
"comedi%d: %s: BUG! cannot determine board type!\n",
dev->minor, PC263_DRIVER_NAME);
return -EINVAL;
break;
}
/*
* Initialize dev->board_name.
*/
dev->board_name = thisboard->name;
/* Enable device and reserve I/O spaces. */
#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
if (pci_dev) {
ret = comedi_pci_enable(pci_dev, PC263_DRIVER_NAME); ret = comedi_pci_enable(pci_dev, PC263_DRIVER_NAME);
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR printk(KERN_ERR
...@@ -293,21 +254,16 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -293,21 +254,16 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
return ret; return ret;
} }
iobase = pci_resource_start(pci_dev, 2); iobase = pci_resource_start(pci_dev, 2);
} else } else {
#endif printk(KERN_ERR
{ "comedi%d: %s: BUG! cannot determine board type!\n",
#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA dev->minor, PC263_DRIVER_NAME);
ret = pc263_request_region(dev->minor, iobase, PC263_IO_SIZE); return -EINVAL;
if (ret < 0)
return ret;
#endif
} }
dev->board_name = thisboard->name;
dev->iobase = iobase; dev->iobase = iobase;
/*
* Allocate the subdevice structures. alloc_subdevice() is a
* convenient macro defined in comedidev.h.
*/
ret = alloc_subdevices(dev, 1); ret = alloc_subdevices(dev, 1);
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR "comedi%d: error! out of memory!\n", printk(KERN_ERR "comedi%d: error! out of memory!\n",
...@@ -327,20 +283,12 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -327,20 +283,12 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
s->state = inb(dev->iobase) | (inb(dev->iobase + 1) << 8); s->state = inb(dev->iobase) | (inb(dev->iobase + 1) << 8);
printk(KERN_INFO "comedi%d: %s ", dev->minor, dev->board_name); printk(KERN_INFO "comedi%d: %s ", dev->minor, dev->board_name);
switch (thisboard->bustype) { if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_ISA) &&
#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA thisboard->bustype == isa_bustype)
case isa_bustype:
printk("(base %#lx) ", iobase); printk("(base %#lx) ", iobase);
break; else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_PCI) &&
#endif thisboard->bustype == pci_bustype)
#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI printk("(pci %s) ", pci_name(devpriv->pci_dev));
case pci_bustype:
printk("(pci %s) ", pci_name(pci_dev));
break;
#endif
default:
break;
}
printk("attached\n"); printk("attached\n");
...@@ -349,23 +297,14 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -349,23 +297,14 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
static void pc263_detach(struct comedi_device *dev) static void pc263_detach(struct comedi_device *dev)
{ {
#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_PCI) && devpriv &&
if (devpriv) devpriv->pci_dev) {
#endif
{
#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI
if (devpriv->pci_dev) {
if (dev->iobase) if (dev->iobase)
comedi_pci_disable(devpriv->pci_dev); comedi_pci_disable(devpriv->pci_dev);
pci_dev_put(devpriv->pci_dev); pci_dev_put(devpriv->pci_dev);
} else } else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_ISA)) {
#endif
{
#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA
if (dev->iobase) if (dev->iobase)
release_region(dev->iobase, PC263_IO_SIZE); release_region(dev->iobase, PC263_IO_SIZE);
#endif
}
} }
} }
...@@ -373,7 +312,6 @@ static void pc263_detach(struct comedi_device *dev) ...@@ -373,7 +312,6 @@ static void pc263_detach(struct comedi_device *dev)
* This function checks and requests an I/O region, reporting an error * This function checks and requests an I/O region, reporting an error
* if there is a conflict. * if there is a conflict.
*/ */
#ifdef CONFIG_COMEDI_AMPLC_PC263_ISA
static int pc263_request_region(unsigned minor, unsigned long from, static int pc263_request_region(unsigned minor, unsigned long from,
unsigned long extent) unsigned long extent)
{ {
...@@ -384,7 +322,6 @@ static int pc263_request_region(unsigned minor, unsigned long from, ...@@ -384,7 +322,6 @@ static int pc263_request_region(unsigned minor, unsigned long from,
} }
return 0; return 0;
} }
#endif
static int pc263_do_insn_bits(struct comedi_device *dev, static int pc263_do_insn_bits(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
...@@ -416,7 +353,7 @@ static int pc263_do_insn_bits(struct comedi_device *dev, ...@@ -416,7 +353,7 @@ static int pc263_do_insn_bits(struct comedi_device *dev,
* A convenient macro that defines init_module() and cleanup_module(), * A convenient macro that defines init_module() and cleanup_module(),
* as necessary. * as necessary.
*/ */
#ifdef CONFIG_COMEDI_AMPLC_PC263_PCI #if IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_PCI)
static int __devinit driver_amplc_pc263_pci_probe(struct pci_dev *dev, static int __devinit driver_amplc_pc263_pci_probe(struct pci_dev *dev,
const struct pci_device_id const struct pci_device_id
*ent) *ent)
......
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