2003-03-10 04:50:40

by Adam Belay

[permalink] [raw]
Subject: [PATCH] PnP Changes for 2.5.64

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.1077 -> 1.1078
# drivers/pnp/resource.c 1.9 -> 1.10
# drivers/pnp/manager.c 1.4 -> 1.5
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/03/06 [email protected] 1.1078
# Manual Resource Setting Update
#
# This patch allows for partial setting of manual resources as needed by ALSA.
# It does not change any existing APIs.
# --------------------------------------------
#
diff -Nru a/drivers/pnp/manager.c b/drivers/pnp/manager.c
--- a/drivers/pnp/manager.c Sun Mar 9 23:48:20 2003
+++ b/drivers/pnp/manager.c Sun Mar 9 23:48:20 2003
@@ -532,6 +532,39 @@
return error;
}

+static void pnp_process_manual_resources(struct pnp_resource_table * ctab, struct pnp_resource_table * ntab)
+{
+ int idx;
+ for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
+ if (ntab->irq_resource[idx].flags & IORESOURCE_AUTO)
+ continue;
+ ctab->irq_resource[idx].start = ntab->irq_resource[idx].start;
+ ctab->irq_resource[idx].end = ntab->irq_resource[idx].end;
+ ctab->irq_resource[idx].flags = ntab->irq_resource[idx].flags;
+ }
+ for (idx = 0; idx < PNP_MAX_DMA; idx++) {
+ if (ntab->dma_resource[idx].flags & IORESOURCE_AUTO)
+ continue;
+ ctab->dma_resource[idx].start = ntab->dma_resource[idx].start;
+ ctab->dma_resource[idx].end = ntab->dma_resource[idx].end;
+ ctab->dma_resource[idx].flags = ntab->dma_resource[idx].flags;
+ }
+ for (idx = 0; idx < PNP_MAX_PORT; idx++) {
+ if (ntab->port_resource[idx].flags & IORESOURCE_AUTO)
+ continue;
+ ctab->port_resource[idx].start = ntab->port_resource[idx].start;
+ ctab->port_resource[idx].end = ntab->port_resource[idx].end;
+ ctab->port_resource[idx].flags = ntab->port_resource[idx].flags;
+ }
+ for (idx = 0; idx < PNP_MAX_MEM; idx++) {
+ if (ntab->irq_resource[idx].flags & IORESOURCE_AUTO)
+ continue;
+ ctab->irq_resource[idx].start = ntab->mem_resource[idx].start;
+ ctab->irq_resource[idx].end = ntab->mem_resource[idx].end;
+ ctab->irq_resource[idx].flags = ntab->mem_resource[idx].flags;
+ }
+}
+
/**
* pnp_manual_config_dev - Disables Auto Config and Manually sets the resource table
* @dev: pointer to the desired device
@@ -554,7 +587,7 @@
*bak = dev->res;

spin_lock(&pnp_lock);
- dev->res = *res;
+ pnp_process_manual_resources(&dev->res, res);
if (!(mode & PNP_CONFIG_FORCE)) {
for (i = 0; i < PNP_MAX_PORT; i++) {
if(pnp_check_port(dev,i))
@@ -681,7 +714,7 @@
return -1;
}
dev->active = 0; /* just in case the protocol doesn't do this */
- pnp_dbg("the device '%s' has been disabled.", dev->dev.bus_id);
+ pnp_dbg("res: the device '%s' has been disabled.", dev->dev.bus_id);
return 0;
}

diff -Nru a/drivers/pnp/resource.c b/drivers/pnp/resource.c
--- a/drivers/pnp/resource.c Sun Mar 9 23:48:20 2003
+++ b/drivers/pnp/resource.c Sun Mar 9 23:48:20 2003
@@ -558,25 +558,25 @@
table->irq_resource[idx].name = NULL;
table->irq_resource[idx].start = -1;
table->irq_resource[idx].end = -1;
- table->irq_resource[idx].flags = 0;
+ table->irq_resource[idx].flags = IORESOURCE_AUTO;
}
for (idx = 0; idx < PNP_MAX_DMA; idx++) {
table->dma_resource[idx].name = NULL;
table->dma_resource[idx].start = -1;
table->dma_resource[idx].end = -1;
- table->dma_resource[idx].flags = 0;
+ table->dma_resource[idx].flags = IORESOURCE_AUTO;
}
for (idx = 0; idx < PNP_MAX_PORT; idx++) {
table->port_resource[idx].name = NULL;
table->port_resource[idx].start = 0;
table->port_resource[idx].end = 0;
- table->port_resource[idx].flags = 0;
+ table->port_resource[idx].flags = IORESOURCE_AUTO;
}
for (idx = 0; idx < PNP_MAX_MEM; idx++) {
table->mem_resource[idx].name = NULL;
table->mem_resource[idx].start = 0;
table->mem_resource[idx].end = 0;
- table->mem_resource[idx].flags = 0;
+ table->mem_resource[idx].flags = IORESOURCE_AUTO;
}
}


2003-03-10 04:51:40

by Adam Belay

[permalink] [raw]
Subject: Re: [PATCH] PnP Changes for 2.5.64

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.1078 -> 1.1079
# drivers/pnp/interface.c 1.13 -> 1.14
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/03/09 [email protected] 1.1079
# Interface Changes
#
# A few minor revisions. Simpifies a few commands and adds config mode
# information.
# --------------------------------------------
#
diff -Nru a/drivers/pnp/interface.c b/drivers/pnp/interface.c
--- a/drivers/pnp/interface.c Sun Mar 9 23:48:09 2003
+++ b/drivers/pnp/interface.c Sun Mar 9 23:48:09 2003
@@ -332,11 +332,18 @@
buffer->buffer = buf;
buffer->curr = buffer->buffer;

+ pnp_printf(buffer,"mode = ");
+ if (dev->config_mode & PNP_CONFIG_MANUAL)
+ pnp_printf(buffer,"manual\n");
+ else
+ pnp_printf(buffer,"auto\n");
+
pnp_printf(buffer,"state = ");
if (dev->active)
pnp_printf(buffer,"active\n");
else
pnp_printf(buffer,"disabled\n");
+
for (i = 0; i < PNP_MAX_PORT; i++) {
if (pnp_port_valid(dev, i)) {
pnp_printf(buffer,"io");
@@ -402,13 +409,13 @@
retval = pnp_activate_dev(dev);
goto done;
}
- if (!strnicmp(buf,"auto-config",11)) {
+ if (!strnicmp(buf,"auto",4)) {
if (dev->active)
goto done;
retval = pnp_auto_config_dev(dev);
goto done;
}
- if (!strnicmp(buf,"clear-config",12)) {
+ if (!strnicmp(buf,"clear",5)) {
if (dev->active)
goto done;
spin_lock(&pnp_lock);

2003-03-10 04:53:06

by Adam Belay

[permalink] [raw]
Subject: Re: [PATCH] PnP Changes for 2.5.64

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.1080 -> 1.1081
# drivers/pnp/Makefile 1.12 -> 1.13
# drivers/pnp/Kconfig 1.3 -> 1.4
# drivers/pnp/isapnp/core.c 1.31 -> 1.32
# drivers/pnp/driver.c 1.12 -> 1.13
# drivers/pnp/card.c 1.8 -> 1.9
# include/linux/pnp.h 1.14 -> 1.15
# drivers/pnp/system.c 1.6 -> 1.7
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/03/09 [email protected] 1.1081
# PnP Card Serivice Revisions
#
# This set of changes addresses the following issues with the existing card
# service implementation:
#
# 1.) Only one driver can be bound to a card.
# 2.) repetive code is required for pnp_request_card_device and other
# functions
#
# This patch will make the card services usable by ALSA.
# --------------------------------------------
#
diff -Nru a/drivers/pnp/Kconfig b/drivers/pnp/Kconfig
--- a/drivers/pnp/Kconfig Sun Mar 9 23:47:56 2003
+++ b/drivers/pnp/Kconfig Sun Mar 9 23:47:56 2003
@@ -30,15 +30,6 @@

If unsure, say Y.

-config PNP_CARD
- bool "Plug and Play card services"
- depends on PNP
- help
- Select Y if you want the PnP Layer to manage cards. Cards are groups
- of PnP devices. Some drivers, especially PnP sound card drivers, use
- these cards. If you want to use the protocol ISAPNP you will need to
- say Y here.
-
config PNP_DEBUG
bool "PnP Debug Messages"
depends on PNP
@@ -51,7 +42,7 @@

config ISAPNP
bool "ISA Plug and Play support (EXPERIMENTAL)"
- depends on PNP && EXPERIMENTAL && PNP_CARD
+ depends on PNP && EXPERIMENTAL
help
Say Y here if you would like support for ISA Plug and Play devices.
Some information is in <file:Documentation/isapnp.txt>.
diff -Nru a/drivers/pnp/Makefile b/drivers/pnp/Makefile
--- a/drivers/pnp/Makefile Sun Mar 9 23:47:56 2003
+++ b/drivers/pnp/Makefile Sun Mar 9 23:47:56 2003
@@ -2,9 +2,7 @@
# Makefile for the Linux Plug-and-Play Support.
#

-pnp-card-$(CONFIG_PNP_CARD) = card.o
-
-obj-y := core.o driver.o resource.o manager.o support.o interface.o quirks.o names.o system.o $(pnp-card-y)
+obj-y := core.o card.o driver.o resource.o manager.o support.o interface.o quirks.o names.o system.o

obj-$(CONFIG_PNPBIOS) += pnpbios/
obj-$(CONFIG_ISAPNP) += isapnp/
diff -Nru a/drivers/pnp/card.c b/drivers/pnp/card.c
--- a/drivers/pnp/card.c Sun Mar 9 23:47:56 2003
+++ b/drivers/pnp/card.c Sun Mar 9 23:47:56 2003
@@ -16,15 +16,14 @@
#endif

#include <linux/pnp.h>
-#include <linux/init.h>
#include "base.h"

-
LIST_HEAD(pnp_cards);

-static const struct pnp_card_id * match_card(struct pnpc_driver *drv, struct pnp_card *card)
+
+static const struct pnp_card_id * match_card(struct pnp_card_driver * drv, struct pnp_card * card)
{
- const struct pnp_card_id *drv_id = drv->id_table;
+ const struct pnp_card_id * drv_id = drv->id_table;
while (*drv_id->id){
if (compare_pnp_id(card->id,drv_id->id))
return drv_id;
@@ -33,31 +32,26 @@
return NULL;
}

-static int card_bus_match(struct device *dev, struct device_driver *drv)
+static void generic_card_remove_handler(struct pnp_dev * dev)
{
- struct pnp_card * card = to_pnp_card(dev);
- struct pnpc_driver * pnp_drv = to_pnpc_driver(drv);
- if (match_card(pnp_drv, card) == NULL)
- return 0;
- return 1;
+ struct pnp_card_driver * drv = to_pnp_card_driver(dev->driver);
+ if (!dev->card || !drv)
+ return;
+ if (drv->remove)
+ drv->remove(dev->card);
+ drv->link.remove = NULL;
}

-struct bus_type pnpc_bus_type = {
- .name = "pnp_card",
- .match = card_bus_match,
-};
-
-
/**
- * pnpc_add_id - adds an EISA id to the specified card
+ * pnp_add_card_id - adds an EISA id to the specified card
* @id: pointer to a pnp_id structure
* @card: pointer to the desired card
*
*/

-int pnpc_add_id(struct pnp_id *id, struct pnp_card *card)
+int pnp_add_card_id(struct pnp_id *id, struct pnp_card * card)
{
- struct pnp_id *ptr;
+ struct pnp_id * ptr;
if (!id)
return -EINVAL;
if (!card)
@@ -73,7 +67,7 @@
return 0;
}

-static void pnpc_free_ids(struct pnp_card *card)
+static void pnp_free_card_ids(struct pnp_card * card)
{
struct pnp_id * id;
struct pnp_id *next;
@@ -87,50 +81,39 @@
}
}

-static void pnp_release_card(struct device *dmdev)
-{
- struct pnp_card * card = to_pnp_card(dmdev);
- pnpc_free_ids(card);
- kfree(card);
-}
-
/**
- * pnpc_add_card - adds a PnP card to the PnP Layer
+ * pnp_add_card - adds a PnP card to the PnP Layer
* @card: pointer to the card to add
*/

-int pnpc_add_card(struct pnp_card *card)
+int pnp_add_card(struct pnp_card * card)
{
int error = 0;
+ struct list_head * pos;
if (!card || !card->protocol)
return -EINVAL;
- sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number, card->number);
- INIT_LIST_HEAD(&card->rdevs);
- card->dev.parent = &card->protocol->dev;
- card->dev.bus = &pnpc_bus_type;
- card->dev.release = &pnp_release_card;
- card->status = PNP_READY;
- error = device_register(&card->dev);
- if (error == 0){
- struct list_head *pos;
- spin_lock(&pnp_lock);
- list_add_tail(&card->global_list, &pnp_cards);
- list_add_tail(&card->protocol_list, &card->protocol->cards);
- spin_unlock(&pnp_lock);
- list_for_each(pos,&card->devices){
- struct pnp_dev *dev = card_to_pnp_dev(pos);
- __pnp_add_device(dev);
- }
+
+ spin_lock(&pnp_lock);
+ list_add_tail(&card->global_list, &pnp_cards);
+ list_add_tail(&card->protocol_list, &card->protocol->cards);
+ spin_unlock(&pnp_lock);
+
+ /* we wait until now to add devices in order to ensure the drivers
+ * will be able to use all of the related devices on the card
+ * without waiting any unresonable length of time */
+ list_for_each(pos,&card->devices){
+ struct pnp_dev *dev = card_to_pnp_dev(pos);
+ __pnp_add_device(dev);
}
return error;
}

/**
- * pnpc_remove_card - removes a PnP card from the PnP Layer
+ * pnp_remove_card - removes a PnP card from the PnP Layer
* @card: pointer to the card to remove
*/

-void pnpc_remove_card(struct pnp_card *card)
+void pnp_remove_card(struct pnp_card * card)
{
struct list_head *pos, *temp;
if (!card)
@@ -142,22 +125,25 @@
spin_unlock(&pnp_lock);
list_for_each_safe(pos,temp,&card->devices){
struct pnp_dev *dev = card_to_pnp_dev(pos);
- pnpc_remove_device(dev);
+ pnp_remove_card_device(dev);
}
+ pnp_free_card_ids(card);
+ kfree(card);
}

/**
- * pnpc_add_device - adds a device to the specified card
+ * pnp_add_card_device - adds a device to the specified card
* @card: pointer to the card to add to
* @dev: pointer to the device to add
*/

-int pnpc_add_device(struct pnp_card *card, struct pnp_dev *dev)
+int pnp_add_card_device(struct pnp_card * card, struct pnp_dev * dev)
{
- if (!dev || !dev->protocol || !card)
+ if (!card || !dev || !dev->protocol)
return -EINVAL;
- dev->dev.parent = &card->dev;
- sprintf(dev->dev.bus_id, "%02x:%02x.%02x", dev->protocol->number, card->number,dev->number);
+ dev->dev.parent = &dev->protocol->dev;
+ snprintf(dev->dev.bus_id, BUS_ID_SIZE, "%02x:%02x.%02x", dev->protocol->number,
+ card->number,dev->number);
spin_lock(&pnp_lock);
dev->card = card;
list_add_tail(&dev->card_list, &card->devices);
@@ -166,12 +152,12 @@
}

/**
- * pnpc_remove_device- removes a device from the specified card
+ * pnp_remove_card_device- removes a device from the specified card
* @card: pointer to the card to remove from
* @dev: pointer to the device to remove
*/

-void pnpc_remove_device(struct pnp_dev *dev)
+void pnp_remove_card_device(struct pnp_dev * dev)
{
spin_lock(&pnp_lock);
dev->card = NULL;
@@ -182,19 +168,17 @@

/**
* pnp_request_card_device - Searches for a PnP device under the specified card
+ * @drv: pointer to the driver requesting the card
* @card: pointer to the card to search under, cannot be NULL
* @id: pointer to a PnP ID structure that explains the rules for finding the device
* @from: Starting place to search from. If NULL it will start from the begining.
- *
- * Will activate the device
*/

-struct pnp_dev * pnp_request_card_device(struct pnp_card *card, const char *id, struct pnp_dev *from)
+struct pnp_dev * pnp_request_card_device(struct pnp_card_driver * drv, struct pnp_card *card, const char * id, struct pnp_dev * from)
{
- struct list_head *pos;
- struct pnp_dev *dev;
- struct pnpc_driver *cdrv;
- if (!card || !id)
+ struct list_head * pos;
+ struct pnp_dev * dev;
+ if (!card || !id || !drv)
goto done;
if (!from) {
pos = card->devices.next;
@@ -214,168 +198,87 @@
return NULL;

found:
- if (pnp_device_attach(dev) < 0)
- return NULL;
- cdrv = to_pnpc_driver(card->dev.driver);
- if (dev->active == 0) {
- if (!(cdrv->flags & PNPC_DRIVER_DO_NOT_ACTIVATE)) {
- if(pnp_activate_dev(dev)<0) {
- pnp_device_detach(dev);
- return NULL;
- }
+ down_write(&dev->dev.bus->subsys.rwsem);
+ dev->dev.driver = &drv->link.driver;
+ if (drv->link.driver.probe) {
+ if (drv->link.driver.probe(&dev->dev)) {
+ dev->dev.driver = NULL;
+ return NULL;
}
- } else {
- if ((cdrv->flags & PNPC_DRIVER_DO_NOT_ACTIVATE))
- pnp_disable_dev(dev);
}
- spin_lock(&pnp_lock);
- list_add_tail(&dev->rdev_list, &card->rdevs);
- spin_unlock(&pnp_lock);
+ device_bind_driver(&dev->dev);
+ up_write(&dev->dev.bus->subsys.rwsem);
+
return dev;
}

/**
* pnp_release_card_device - call this when the driver no longer needs the device
* @dev: pointer to the PnP device stucture
- *
- * Will disable the device
*/

-void pnp_release_card_device(struct pnp_dev *dev)
-{
- spin_lock(&pnp_lock);
- list_del(&dev->rdev_list);
- spin_unlock(&pnp_lock);
- pnp_device_detach(dev);
-}
-
-static void pnpc_recover_devices(struct pnp_card *card)
-{
- struct list_head *pos, *temp;
- list_for_each_safe(pos,temp,&card->rdevs){
- struct pnp_dev *dev = list_entry(pos, struct pnp_dev, rdev_list);
- pnp_release_card_device(dev);
- }
-}
-
-int pnpc_attach(struct pnp_card *pnp_card)
+void pnp_release_card_device(struct pnp_dev * dev)
{
- spin_lock(&pnp_lock);
- if(pnp_card->status != PNP_READY){
- spin_unlock(&pnp_lock);
- return -EBUSY;
- }
- pnp_card->status = PNP_ATTACHED;
- spin_unlock(&pnp_lock);
- return 0;
-}
-
-void pnpc_detach(struct pnp_card *pnp_card)
-{
- spin_lock(&pnp_lock);
- if (pnp_card->status == PNP_ATTACHED)
- pnp_card->status = PNP_READY;
- spin_unlock(&pnp_lock);
- pnpc_recover_devices(pnp_card);
-}
-
-static int pnpc_card_probe(struct device *dev)
-{
- int error = 0;
- struct pnpc_driver *drv = to_pnpc_driver(dev->driver);
- struct pnp_card *card = to_pnp_card(dev);
- const struct pnp_card_id *card_id = NULL;
-
- pnp_dbg("pnp: match found with the PnP card '%s' and the driver '%s'", dev->bus_id,drv->name);
-
- error = pnpc_attach(card);
- if (error < 0)
- return error;
- if (drv->probe) {
- card_id = match_card(drv, card);
- if (card_id != NULL)
- error = drv->probe(card, card_id);
- if (error >= 0){
- card->driver = drv;
- error = 0;
- } else
- pnpc_detach(card);
- }
- return error;
-}
-
-static int pnpc_card_remove(struct device *dev)
-{
- struct pnp_card * card = to_pnp_card(dev);
- struct pnpc_driver * drv = card->driver;
-
- if (drv) {
- if (drv->remove)
- drv->remove(card);
- card->driver = NULL;
- }
- pnpc_detach(card);
- return 0;
+ struct pnp_card_driver * drv = to_pnp_card_driver(to_pnp_driver(dev->dev.driver));
+ if (!drv)
+ return;
+ down_write(&dev->dev.bus->subsys.rwsem);
+ drv->link.remove = NULL;
+ device_release_driver(&dev->dev);
+ drv->link.remove = &generic_card_remove_handler;
+ up_write(&dev->dev.bus->subsys.rwsem);
}

/**
- * pnpc_register_driver - registers a PnP card driver with the PnP Layer
- * @cdrv: pointer to the driver to register
+ * pnp_register_card_driver - registers a PnP card driver with the PnP Layer
+ * @drv: pointer to the driver to register
*/

-int pnpc_register_driver(struct pnpc_driver * drv)
+int pnp_register_card_driver(struct pnp_card_driver * drv)
{
- int count;
- struct list_head *pos;
-
- drv->driver.name = drv->name;
- drv->driver.bus = &pnpc_bus_type;
- drv->driver.probe = pnpc_card_probe;
- drv->driver.remove = pnpc_card_remove;
-
- pnp_dbg("the card driver '%s' has been registered", drv->name);
-
- count = driver_register(&drv->driver);
+ int count = 0;
+ struct list_head *pos, *temp;

- /* get the number of initial matches */
- if (count >= 0){
- count = 0;
- list_for_each(pos,&drv->driver.devices){
- count++;
+ drv->link.name = drv->name;
+ drv->link.id_table = NULL; /* this will disable auto matching */
+ drv->link.flags = drv->flags;
+ drv->link.probe = NULL;
+ drv->link.remove = &generic_card_remove_handler;
+
+ pnp_register_driver(&drv->link);
+
+ list_for_each_safe(pos,temp,&pnp_cards){
+ struct pnp_card *card = list_entry(pos, struct pnp_card, global_list);
+ const struct pnp_card_id *id = match_card(drv,card);
+ if (id) {
+ if (drv->probe) {
+ if (drv->probe(card, id)>=0)
+ count++;
+ } else
+ count++;
}
}
return count;
}

/**
- * pnpc_unregister_driver - unregisters a PnP card driver from the PnP Layer
- * @cdrv: pointer to the driver to unregister
- *
- * Automatically disables requested devices
+ * pnp_unregister_card_driver - unregisters a PnP card driver from the PnP Layer
+ * @drv: pointer to the driver to unregister
*/

-void pnpc_unregister_driver(struct pnpc_driver *drv)
+void pnp_unregister_card_driver(struct pnp_card_driver * drv)
{
- driver_unregister(&drv->driver);
- pnp_dbg("the card driver '%s' has been unregistered", drv->name);
-}
+ pnp_unregister_driver(&drv->link);

-static int __init pnp_card_init(void)
-{
- printk(KERN_INFO "pnp: Enabling Plug and Play Card Services.\n");
- return bus_register(&pnpc_bus_type);
+ pnp_dbg("the card driver '%s' has been unregistered", drv->name);
}

-subsys_initcall(pnp_card_init);
-
-EXPORT_SYMBOL(pnpc_add_card);
-EXPORT_SYMBOL(pnpc_remove_card);
-EXPORT_SYMBOL(pnpc_add_device);
-EXPORT_SYMBOL(pnpc_remove_device);
+EXPORT_SYMBOL(pnp_add_card);
+EXPORT_SYMBOL(pnp_remove_card);
+EXPORT_SYMBOL(pnp_add_card_device);
+EXPORT_SYMBOL(pnp_remove_card_device);
+EXPORT_SYMBOL(pnp_add_card_id);
EXPORT_SYMBOL(pnp_request_card_device);
EXPORT_SYMBOL(pnp_release_card_device);
-EXPORT_SYMBOL(pnpc_register_driver);
-EXPORT_SYMBOL(pnpc_unregister_driver);
-EXPORT_SYMBOL(pnpc_add_id);
-EXPORT_SYMBOL(pnpc_attach);
-EXPORT_SYMBOL(pnpc_detach);
+EXPORT_SYMBOL(pnp_register_card_driver);
+EXPORT_SYMBOL(pnp_unregister_card_driver);
diff -Nru a/drivers/pnp/driver.c b/drivers/pnp/driver.c
--- a/drivers/pnp/driver.c Sun Mar 9 23:47:56 2003
+++ b/drivers/pnp/driver.c Sun Mar 9 23:47:56 2003
@@ -53,12 +53,11 @@
static const struct pnp_device_id * match_device(struct pnp_driver *drv, struct pnp_dev *dev)
{
const struct pnp_device_id *drv_id = drv->id_table;
- if (!drv)
+ if (!drv_id)
return NULL;
- if (!dev)
- return NULL;
- while (*drv_id->id){
- if (compare_pnp_id(dev->id,drv_id->id))
+
+ while (*drv_id->id) {
+ if (compare_pnp_id(dev->id, drv_id->id))
return drv_id;
drv_id++;
}
@@ -102,14 +101,18 @@
return error;

if (pnp_dev->active == 0) {
- if (!(pnp_drv->flags & PNP_DRIVER_DO_NOT_ACTIVATE)) {
+ if (!(pnp_drv->flags & PNP_DRIVER_RES_DO_NOT_CHANGE)) {
error = pnp_activate_dev(pnp_dev);
if (error < 0)
return error;
}
+ } else if (pnp_drv->flags & PNP_DRIVER_RES_DISABLE) {
+ error = pnp_disable_dev(pnp_dev);
+ if (error < 0)
+ return error;
}
error = 0;
- if (pnp_drv->probe && pnp_dev->active) {
+ if (pnp_drv->probe) {
dev_id = match_device(pnp_drv, pnp_dev);
if (dev_id != NULL)
error = pnp_drv->probe(pnp_dev, dev_id);
@@ -117,9 +120,8 @@
if (error >= 0){
pnp_dev->driver = pnp_drv;
error = 0;
- }
- else
- goto fail;
+ } else
+ goto fail;
return error;

fail:
diff -Nru a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c
--- a/drivers/pnp/isapnp/core.c Sun Mar 9 23:47:56 2003
+++ b/drivers/pnp/isapnp/core.c Sun Mar 9 23:47:56 2003
@@ -626,7 +626,7 @@
isapnp_peek(name, size1);
name[size1] = '\0';
*size -= size1;
-
+
/* clean whitespace from end of string */
while (size1 > 0 && name[--size1] == ' ')
name[size1] = '\0';
@@ -647,7 +647,7 @@
return 1;
if (pnp_build_resource(dev, 0) == NULL)
return 1;
- pnpc_add_device(card,dev);
+ pnp_add_card_device(card,dev);
while (1) {
if (isapnp_read_tag(&type, &size)<0)
return 1;
@@ -659,7 +659,7 @@
if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
return 1;
pnp_build_resource(dev,0);
- pnpc_add_device(card,dev);
+ pnp_add_card_device(card,dev);
size = 0;
skip = 0;
} else {
@@ -852,7 +852,7 @@
device & 0x0f,
(device >> 12) & 0x0f,
(device >> 8) & 0x0f);
- pnpc_add_id(id,card);
+ pnp_add_card_id(id,card);
}


@@ -962,7 +962,7 @@
isapnp_parse_current_resources(dev, &dev->res);
}

- pnpc_add_card(card);
+ pnp_add_card(card);
}
isapnp_wait();
return 0;
diff -Nru a/drivers/pnp/system.c b/drivers/pnp/system.c
--- a/drivers/pnp/system.c Sun Mar 9 23:47:56 2003
+++ b/drivers/pnp/system.c Sun Mar 9 23:47:56 2003
@@ -93,7 +93,7 @@

static struct pnp_driver system_pnp_driver = {
.name = "system",
- .flags = PNP_DRIVER_DO_NOT_ACTIVATE,
+ .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
.id_table = pnp_dev_table,
.probe = system_pnp_probe,
.remove = NULL,
diff -Nru a/include/linux/pnp.h b/include/linux/pnp.h
--- a/include/linux/pnp.h Sun Mar 9 23:47:56 2003
+++ b/include/linux/pnp.h Sun Mar 9 23:47:56 2003
@@ -138,11 +138,9 @@
struct list_head global_list; /* node in global list of cards */
struct list_head protocol_list; /* node in protocol's list of cards */
struct list_head devices; /* devices attached to the card */
- struct list_head rdevs; /* a list of devices requested by the card driver */
int status;

struct pnp_protocol * protocol;
- struct pnpc_driver * driver;
struct pnp_id * id; /* contains supported EISA IDs*/

void * protocol_data; /* Used to store protocol specific data */
@@ -161,22 +159,22 @@
(card) != global_to_pnp_card(&pnp_cards); \
(card) = global_to_pnp_card((card)->global_list.next))

-static inline void *pnpc_get_drvdata (struct pnp_card *pcard)
+static inline void *pnp_get_card_drvdata (struct pnp_card *pcard)
{
return dev_get_drvdata(&pcard->dev);
}

-static inline void pnpc_set_drvdata (struct pnp_card *pcard, void *data)
+static inline void pnp_set_card_drvdata (struct pnp_card *pcard, void *data)
{
dev_set_drvdata(&pcard->dev, data);
}

-static inline void *pnpc_get_protodata (struct pnp_card *pcard)
+static inline void *pnp_get_card_protodata (struct pnp_card *pcard)
{
return pcard->protocol_data;
}

-static inline void pnpc_set_protodata (struct pnp_card *pcard, void *data)
+static inline void pnp_set_card_protodata (struct pnp_card *pcard, void *data)
{
pcard->protocol_data = data;
}
@@ -299,11 +297,8 @@
} devs[PNP_MAX_DEVICES]; /* logical devices */
};

-#define PNP_DRIVER_DO_NOT_ACTIVATE (1<<0)
-
struct pnp_driver {
- struct list_head node;
- char *name;
+ char * name;
const struct pnp_device_id *id_table;
unsigned int flags;
int (*probe) (struct pnp_dev *dev, const struct pnp_device_id *dev_id);
@@ -311,21 +306,22 @@
struct device_driver driver;
};

-#define to_pnp_driver(drv) container_of(drv,struct pnp_driver, driver)
-
-#define PNPC_DRIVER_DO_NOT_ACTIVATE (1<<0)
+#define to_pnp_driver(drv) container_of(drv, struct pnp_driver, driver)

-struct pnpc_driver {
- struct list_head node;
- char *name;
+struct pnp_card_driver {
+ char * name;
const struct pnp_card_id *id_table;
unsigned int flags;
int (*probe) (struct pnp_card *card, const struct pnp_card_id *card_id);
void (*remove) (struct pnp_card *card);
- struct device_driver driver;
+ struct pnp_driver link;
};

-#define to_pnpc_driver(drv) container_of(drv,struct pnpc_driver, driver)
+#define to_pnp_card_driver(drv) container_of(drv, struct pnp_card_driver, link)
+
+/* pnp driver flags */
+#define PNP_DRIVER_RES_DO_NOT_CHANGE 0x0001 /* do not change the state of the device */
+#define PNP_DRIVER_RES_DISABLE 0x0003 /* ensure the device is disabled */


/*
@@ -366,9 +362,21 @@
void pnp_unregister_protocol(struct pnp_protocol *protocol);
int pnp_add_device(struct pnp_dev *dev);
void pnp_remove_device(struct pnp_dev *dev);
-extern struct list_head pnp_global;
int pnp_device_attach(struct pnp_dev *pnp_dev);
void pnp_device_detach(struct pnp_dev *pnp_dev);
+extern struct list_head pnp_global;
+
+/* card */
+int pnp_add_card(struct pnp_card *card);
+void pnp_remove_card(struct pnp_card *card);
+int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
+void pnp_remove_card_device(struct pnp_dev *dev);
+int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card);
+struct pnp_dev * pnp_request_card_device(struct pnp_card_driver * drv, struct pnp_card *card, const char * id, struct pnp_dev * from);
+void pnp_release_card_device(struct pnp_dev * dev);
+int pnp_register_card_driver(struct pnp_card_driver * drv);
+void pnp_unregister_card_driver(struct pnp_card_driver * drv);
+extern struct list_head pnp_cards;

/* resource */
struct pnp_resources * pnp_build_resource(struct pnp_dev *dev, int dependent);
@@ -413,6 +421,17 @@
static inline int pnp_device_attach(struct pnp_dev *pnp_dev) { return -ENODEV; }
static inline void pnp_device_detach(struct pnp_dev *pnp_dev) { ; }

+/* card */
+static inline int pnp_add_card(struct pnp_card *card) { return -ENODEV; }
+static inline void pnp_remove_card(struct pnp_card *card) { ; }
+static inline int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev) { return -ENODEV; }
+static inline void pnp_remove_card_device(struct pnp_dev *dev) { ; }
+static inline int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card) { return -ENODEV; }
+static inline struct pnp_dev * pnp_request_card_device(struct pnp_card_driver * drv, struct pnp_card *card, const char * id, struct pnp_dev * from) { return -ENODEV; }
+static inline void pnp_release_card_device(struct pnp_dev * dev) { ; }
+static inline int pnp_register_card_driver(struct pnp_card_driver * drv) { return -ENODEV; }
+static inline void pnp_unregister_card_driver(struct pnp_card_driver * drv) { ; }
+
/* resource */
static inline struct pnp_resources * pnp_build_resource(struct pnp_dev *dev, int dependent) { return NULL; }
static inline struct pnp_resources * pnp_find_resources(struct pnp_dev *dev, int depnum) { return NULL; }
@@ -445,37 +464,6 @@

#endif /* CONFIG_PNP */

-
-#if defined(CONFIG_PNP_CARD)
-
-/* card */
-int pnpc_add_card(struct pnp_card *card);
-void pnpc_remove_card(struct pnp_card *card);
-int pnpc_add_device(struct pnp_card *card, struct pnp_dev *dev);
-void pnpc_remove_device(struct pnp_dev *dev);
-struct pnp_dev * pnp_request_card_device(struct pnp_card *card, const char *id, struct pnp_dev *from);
-void pnp_release_card_device(struct pnp_dev *dev);
-int pnpc_register_driver(struct pnpc_driver * drv);
-void pnpc_unregister_driver(struct pnpc_driver *drv);
-int pnpc_add_id(struct pnp_id *id, struct pnp_card *card);
-extern struct list_head pnp_cards;
-int pnpc_attach(struct pnp_card *card);
-void pnpc_detach(struct pnp_card *card);
-
-#else
-
-/* card */
-static inline int pnpc_add_card(struct pnp_card *card) { return -ENODEV; }
-static inline void pnpc_remove_card(struct pnp_card *card) { ; }
-static inline int pnpc_add_device(struct pnp_card *card, struct pnp_dev *dev) { return -ENODEV; }
-static inline void pnpc_remove_device(struct pnp_dev *dev) { ; }
-static inline struct pnp_dev * pnp_request_card_device(struct pnp_card *card, const char *id, struct pnp_dev *from) { return NULL; }
-static inline void pnp_release_card_device(struct pnp_dev *dev) { ; }
-static inline int pnpc_register_driver(struct pnpc_driver *drv) { return -ENODEV; }
-static inline void pnpc_unregister_driver(struct pnpc_driver *drv) { ; }
-static inline int pnpc_add_id(struct pnp_id *id, struct pnp_card *card) { return -ENODEV; }
-
-#endif /* CONFIG_PNP_CARD */

#define pnp_err(format, arg...) printk(KERN_ERR "pnp: " format "\n" , ## arg)
#define pnp_info(format, arg...) printk(KERN_INFO "pnp: " format "\n" , ## arg)

2003-03-10 04:55:33

by Adam Belay

[permalink] [raw]
Subject: Re: [PATCH] PnP Changes for 2.5.64

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.1083 -> 1.1084
# sound/isa/als100.c 1.8 -> 1.9
# sound/oss/sb_card.h 1.1 -> 1.2
# sound/oss/sb_card.c 1.16 -> 1.17
# drivers/pnp/driver.c 1.13 -> 1.14
# drivers/pnp/card.c 1.9 -> 1.10
# include/linux/pnp.h 1.15 -> 1.16
# drivers/pnp/system.c 1.7 -> 1.8
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/03/09 [email protected] 1.1084
# Aditional Card Service Changes
#
# Fixes many issues that were discovered after testing. Also cleans up the
# card service code and fixes the card_drvdata bug in which only one driver
# at a time could have driver data.
# --------------------------------------------
#
diff -Nru a/drivers/pnp/card.c b/drivers/pnp/card.c
--- a/drivers/pnp/card.c Sun Mar 9 23:47:21 2003
+++ b/drivers/pnp/card.c Sun Mar 9 23:47:21 2003
@@ -32,14 +32,21 @@
return NULL;
}

-static void generic_card_remove_handler(struct pnp_dev * dev)
+static void generic_card_remove(struct pnp_dev * dev)
+{
+ dev->card_link = NULL;
+}
+
+static void generic_card_remove_first(struct pnp_dev * dev)
{
struct pnp_card_driver * drv = to_pnp_card_driver(dev->driver);
if (!dev->card || !drv)
return;
if (drv->remove)
- drv->remove(dev->card);
- drv->link.remove = NULL;
+ drv->remove(dev->card_link);
+ drv->link.remove = &generic_card_remove;
+ kfree(dev->card_link);
+ generic_card_remove(dev);
}

/**
@@ -81,6 +88,13 @@
}
}

+static void pnp_release_card(struct device *dmdev)
+{
+ struct pnp_card * card = to_pnp_card(dmdev);
+ pnp_free_card_ids(card);
+ kfree(card);
+}
+
/**
* pnp_add_card - adds a PnP card to the PnP Layer
* @card: pointer to the card to add
@@ -88,23 +102,31 @@

int pnp_add_card(struct pnp_card * card)
{
- int error = 0;
+ int error;
struct list_head * pos;
if (!card || !card->protocol)
return -EINVAL;

- spin_lock(&pnp_lock);
- list_add_tail(&card->global_list, &pnp_cards);
- list_add_tail(&card->protocol_list, &card->protocol->cards);
- spin_unlock(&pnp_lock);
-
- /* we wait until now to add devices in order to ensure the drivers
- * will be able to use all of the related devices on the card
- * without waiting any unresonable length of time */
- list_for_each(pos,&card->devices){
- struct pnp_dev *dev = card_to_pnp_dev(pos);
- __pnp_add_device(dev);
- }
+ sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number, card->number);
+ card->dev.parent = &card->protocol->dev;
+ card->dev.bus = NULL;
+ card->dev.release = &pnp_release_card;
+ error = device_register(&card->dev);
+ if (error == 0) {
+ spin_lock(&pnp_lock);
+ list_add_tail(&card->global_list, &pnp_cards);
+ list_add_tail(&card->protocol_list, &card->protocol->cards);
+ spin_unlock(&pnp_lock);
+
+ /* we wait until now to add devices in order to ensure the drivers
+ * will be able to use all of the related devices on the card
+ * without waiting any unresonable length of time */
+ list_for_each(pos,&card->devices){
+ struct pnp_dev *dev = card_to_pnp_dev(pos);
+ __pnp_add_device(dev);
+ }
+ } else
+ pnp_err("sysfs failure, card '%s' will be unavailable", card->dev.bus_id);
return error;
}

@@ -127,8 +149,6 @@
struct pnp_dev *dev = card_to_pnp_dev(pos);
pnp_remove_card_device(dev);
}
- pnp_free_card_ids(card);
- kfree(card);
}

/**
@@ -141,7 +161,8 @@
{
if (!card || !dev || !dev->protocol)
return -EINVAL;
- dev->dev.parent = &dev->protocol->dev;
+ dev->dev.parent = &card->dev;
+ dev->card_link = NULL;
snprintf(dev->dev.bus_id, BUS_ID_SIZE, "%02x:%02x.%02x", dev->protocol->number,
card->number,dev->number);
spin_lock(&pnp_lock);
@@ -168,18 +189,21 @@

/**
* pnp_request_card_device - Searches for a PnP device under the specified card
- * @drv: pointer to the driver requesting the card
- * @card: pointer to the card to search under, cannot be NULL
+ * @lcard: pointer to the card link, cannot be NULL
* @id: pointer to a PnP ID structure that explains the rules for finding the device
* @from: Starting place to search from. If NULL it will start from the begining.
*/

-struct pnp_dev * pnp_request_card_device(struct pnp_card_driver * drv, struct pnp_card *card, const char * id, struct pnp_dev * from)
+struct pnp_dev * pnp_request_card_device(struct pnp_card_link *clink, const char * id, struct pnp_dev * from)
{
struct list_head * pos;
struct pnp_dev * dev;
- if (!card || !id || !drv)
+ struct pnp_card_driver * drv;
+ struct pnp_card * card;
+ if (!clink || !id)
goto done;
+ card = clink->card;
+ drv = clink->driver;
if (!from) {
pos = card->devices.next;
} else {
@@ -189,7 +213,7 @@
}
while (pos != &card->devices) {
dev = card_to_pnp_dev(pos);
- if (compare_pnp_id(dev->id,id))
+ if ((!dev->card_link) && compare_pnp_id(dev->id,id))
goto found;
pos = pos->next;
}
@@ -199,6 +223,7 @@

found:
down_write(&dev->dev.bus->subsys.rwsem);
+ dev->card_link = clink;
dev->dev.driver = &drv->link.driver;
if (drv->link.driver.probe) {
if (drv->link.driver.probe(&dev->dev)) {
@@ -219,13 +244,13 @@

void pnp_release_card_device(struct pnp_dev * dev)
{
- struct pnp_card_driver * drv = to_pnp_card_driver(to_pnp_driver(dev->dev.driver));
+ struct pnp_card_driver * drv = dev->card_link->driver;
if (!drv)
return;
down_write(&dev->dev.bus->subsys.rwsem);
- drv->link.remove = NULL;
+ drv->link.remove = &generic_card_remove;
device_release_driver(&dev->dev);
- drv->link.remove = &generic_card_remove_handler;
+ drv->link.remove = &generic_card_remove_first;
up_write(&dev->dev.bus->subsys.rwsem);
}

@@ -243,7 +268,7 @@
drv->link.id_table = NULL; /* this will disable auto matching */
drv->link.flags = drv->flags;
drv->link.probe = NULL;
- drv->link.remove = &generic_card_remove_handler;
+ drv->link.remove = &generic_card_remove_first;

pnp_register_driver(&drv->link);

@@ -251,8 +276,13 @@
struct pnp_card *card = list_entry(pos, struct pnp_card, global_list);
const struct pnp_card_id *id = match_card(drv,card);
if (id) {
+ struct pnp_card_link * clink = pnp_alloc(sizeof(struct pnp_card_link));
+ if (!clink)
+ continue;
+ clink->card = card;
+ clink->driver = drv;
if (drv->probe) {
- if (drv->probe(card, id)>=0)
+ if (drv->probe(clink, id)>=0)
count++;
} else
count++;
diff -Nru a/drivers/pnp/driver.c b/drivers/pnp/driver.c
--- a/drivers/pnp/driver.c Sun Mar 9 23:47:21 2003
+++ b/drivers/pnp/driver.c Sun Mar 9 23:47:21 2003
@@ -106,7 +106,8 @@
if (error < 0)
return error;
}
- } else if (pnp_drv->flags & PNP_DRIVER_RES_DISABLE) {
+ } else if ((pnp_drv->flags & PNP_DRIVER_RES_DISABLE)
+ == PNP_DRIVER_RES_DISABLE) {
error = pnp_disable_dev(pnp_dev);
if (error < 0)
return error;
diff -Nru a/drivers/pnp/system.c b/drivers/pnp/system.c
--- a/drivers/pnp/system.c Sun Mar 9 23:47:21 2003
+++ b/drivers/pnp/system.c Sun Mar 9 23:47:21 2003
@@ -93,8 +93,8 @@

static struct pnp_driver system_pnp_driver = {
.name = "system",
- .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
.id_table = pnp_dev_table,
+ .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
.probe = system_pnp_probe,
.remove = NULL,
};
diff -Nru a/include/linux/pnp.h b/include/linux/pnp.h
--- a/include/linux/pnp.h Sun Mar 9 23:47:21 2003
+++ b/include/linux/pnp.h Sun Mar 9 23:47:21 2003
@@ -138,7 +138,6 @@
struct list_head global_list; /* node in global list of cards */
struct list_head protocol_list; /* node in protocol's list of cards */
struct list_head devices; /* devices attached to the card */
- int status;

struct pnp_protocol * protocol;
struct pnp_id * id; /* contains supported EISA IDs*/
@@ -159,24 +158,30 @@
(card) != global_to_pnp_card(&pnp_cards); \
(card) = global_to_pnp_card((card)->global_list.next))

-static inline void *pnp_get_card_drvdata (struct pnp_card *pcard)
+static inline void *pnp_get_card_protodata (struct pnp_card *pcard)
{
- return dev_get_drvdata(&pcard->dev);
+ return pcard->protocol_data;
}

-static inline void pnp_set_card_drvdata (struct pnp_card *pcard, void *data)
+static inline void pnp_set_card_protodata (struct pnp_card *pcard, void *data)
{
- dev_set_drvdata(&pcard->dev, data);
+ pcard->protocol_data = data;
}

-static inline void *pnp_get_card_protodata (struct pnp_card *pcard)
+struct pnp_card_link {
+ struct pnp_card * card;
+ struct pnp_card_driver * driver;
+ void * driver_data;
+};
+
+static inline void *pnp_get_card_drvdata (struct pnp_card_link *pcard)
{
- return pcard->protocol_data;
+ return pcard->driver_data;
}

-static inline void pnp_set_card_protodata (struct pnp_card *pcard, void *data)
+static inline void pnp_set_card_drvdata (struct pnp_card_link *pcard, void *data)
{
- pcard->protocol_data = data;
+ pcard->driver_data = data;
}

struct pnp_dev {
@@ -194,6 +199,7 @@
struct pnp_protocol * protocol;
struct pnp_card * card; /* card the device is attached to, none if NULL */
struct pnp_driver * driver;
+ struct pnp_card_link * card_link;

struct pnp_id * id; /* supported EISA IDs*/
struct pnp_resource_table res; /* contains the currently chosen resources */
@@ -312,8 +318,8 @@
char * name;
const struct pnp_card_id *id_table;
unsigned int flags;
- int (*probe) (struct pnp_card *card, const struct pnp_card_id *card_id);
- void (*remove) (struct pnp_card *card);
+ int (*probe) (struct pnp_card_link *card, const struct pnp_card_id *card_id);
+ void (*remove) (struct pnp_card_link *card);
struct pnp_driver link;
};

@@ -372,7 +378,7 @@
int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
void pnp_remove_card_device(struct pnp_dev *dev);
int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card);
-struct pnp_dev * pnp_request_card_device(struct pnp_card_driver * drv, struct pnp_card *card, const char * id, struct pnp_dev * from);
+struct pnp_dev * pnp_request_card_device(struct pnp_card_link *clink, const char * id, struct pnp_dev * from);
void pnp_release_card_device(struct pnp_dev * dev);
int pnp_register_card_driver(struct pnp_card_driver * drv);
void pnp_unregister_card_driver(struct pnp_card_driver * drv);
@@ -427,7 +433,7 @@
static inline int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev) { return -ENODEV; }
static inline void pnp_remove_card_device(struct pnp_dev *dev) { ; }
static inline int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card) { return -ENODEV; }
-static inline struct pnp_dev * pnp_request_card_device(struct pnp_card_driver * drv, struct pnp_card *card, const char * id, struct pnp_dev * from) { return -ENODEV; }
+static inline struct pnp_dev * pnp_request_card_device(struct pnp_card_link *clink, const char * id, struct pnp_dev * from) { return -ENODEV; }
static inline void pnp_release_card_device(struct pnp_dev * dev) { ; }
static inline int pnp_register_card_driver(struct pnp_card_driver * drv) { return -ENODEV; }
static inline void pnp_unregister_card_driver(struct pnp_card_driver * drv) { ; }
diff -Nru a/sound/isa/als100.c b/sound/isa/als100.c
--- a/sound/isa/als100.c Sun Mar 9 23:47:21 2003
+++ b/sound/isa/als100.c Sun Mar 9 23:47:21 2003
@@ -116,10 +116,8 @@

#define DRIVER_NAME "snd-card-als100"

-static struct pnp_card_driver als100_pnpc_driver;
-
static int __devinit snd_card_als100_isapnp(int dev, struct snd_card_als100 *acard,
- struct pnp_card *card,
+ struct pnp_card_link *card,
const struct pnp_card_id *id)
{
struct pnp_dev *pdev;
@@ -127,13 +125,13 @@
int err;
if (!cfg)
return -ENOMEM;
- acard->dev = pnp_request_card_device(&als100_pnpc_driver, card, id->devs[0].id, NULL);
+ acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
if (acard->dev == NULL) {
kfree(cfg);
return -ENODEV;
}
- acard->devmpu = pnp_request_card_device(&als100_pnpc_driver, card, id->devs[1].id, acard->dev);
- acard->devopl = pnp_request_card_device(&als100_pnpc_driver, card, id->devs[2].id, acard->devmpu);
+ acard->devmpu = pnp_request_card_device(card, id->devs[1].id, acard->dev);
+ acard->devopl = pnp_request_card_device(card, id->devs[2].id, acard->devmpu);

pdev = acard->dev;

@@ -210,7 +208,7 @@
}

static int __init snd_card_als100_probe(int dev,
- struct pnp_card *pcard,
+ struct pnp_card_link *pcard,
const struct pnp_card_id *pid)
{
int error;
@@ -288,7 +286,7 @@
return 0;
}

-static int __devinit snd_als100_pnp_detect(struct pnp_card *card,
+static int __devinit snd_als100_pnp_detect(struct pnp_card_link *card,
const struct pnp_card_id *id)
{
static int dev;
@@ -306,7 +304,7 @@
return -ENODEV;
}

-static void __devexit snd_als100_pnp_remove(struct pnp_card * pcard)
+static void __devexit snd_als100_pnp_remove(struct pnp_card_link * pcard)
{
snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);

diff -Nru a/sound/oss/sb_card.c b/sound/oss/sb_card.c
--- a/sound/oss/sb_card.c Sun Mar 9 23:47:21 2003
+++ b/sound/oss/sb_card.c Sun Mar 9 23:47:21 2003
@@ -32,9 +32,9 @@
#include "sound_config.h"
#include "sb_mixer.h"
#include "sb.h"
-#ifdef CONFIG_PNP_CARD
+#ifdef CONFIG_PNP
#include <linux/pnp.h>
-#endif
+#endif /* CONFIG_PNP */
#include "sb_card.h"

MODULE_DESCRIPTION("OSS Soundblaster ISA PnP and legacy sound driver");
@@ -54,7 +54,7 @@

struct sb_card_config *legacy = NULL;

-#ifdef CONFIG_PNP_CARD
+#ifdef CONFIG_PNP
static int __initdata pnp = 1;
/*
static int __initdata uart401 = 0;
@@ -85,7 +85,7 @@
MODULE_PARM_DESC(acer, "Set this to detect cards in some ACER notebooks "\
"(doesn't work with pnp)");

-#ifdef CONFIG_PNP_CARD
+#ifdef CONFIG_PNP
module_param(pnp, int, 000);
MODULE_PARM_DESC(pnp, "Went set to 0 will disable detection using PnP. "\
"Default is 1.\n");
@@ -95,7 +95,7 @@
MODULE_PARM_DESC(uart401, "When set to 1, will attempt to detect and enable"\
"the mpu on some clones");
*/
-#endif /* CONFIG_PNP_CARD */
+#endif /* CONFIG_PNP */

/* OSS subsystem card registration shared by PnP and legacy routines */
static int sb_register_oss(struct sb_card_config *scc, struct sb_module_options *sbmo)
@@ -157,7 +157,7 @@
return sb_register_oss(legacy, &sbmo);
}

-#ifdef CONFIG_PNP_CARD
+#ifdef CONFIG_PNP

/* Populate the OSS subsystem structures with information from PnP */
static void sb_dev2cfg(struct pnp_dev *dev, struct sb_card_config *scc)
@@ -224,7 +224,7 @@
}

/* Probe callback function for the PnP API */
-static int sb_pnp_probe(struct pnp_card *card, const struct pnp_card_id *card_id)
+static int sb_pnp_probe(struct pnp_card_link *card, const struct pnp_card_id *card_id)
{
struct sb_card_config *scc;
struct sb_module_options sbmo = {0}; /* Default to 0 for PnP */
@@ -257,7 +257,7 @@
return sb_register_oss(scc, &sbmo);
}

-static void sb_pnp_remove(struct pnp_card *card)
+static void sb_pnp_remove(struct pnp_card_link *card)
{
struct sb_card_config *scc = pnp_get_card_drvdata(card);

@@ -275,7 +275,7 @@
.probe = sb_pnp_probe,
.remove = sb_pnp_remove,
};
-#endif /* CONFIG_PNP_CARD */
+#endif /* CONFIG_PNP */

static int __init sb_init(void)
{
@@ -293,7 +293,7 @@
printk(KERN_ERR "sb: Error: At least io, irq, and dma "\
"must be set for legacy cards.\n");

-#ifdef CONFIG_PNP_CARD
+#ifdef CONFIG_PNP
if(pnp) {
pres = pnp_register_card_driver(&sb_pnp_driver);
}
@@ -315,7 +315,7 @@
sb_unload(legacy);
}

-#ifdef CONFIG_PNP_CARD
+#ifdef CONFIG_PNP
pnp_unregister_card_driver(&sb_pnp_driver);
#endif

diff -Nru a/sound/oss/sb_card.h b/sound/oss/sb_card.h
--- a/sound/oss/sb_card.h Sun Mar 9 23:47:21 2003
+++ b/sound/oss/sb_card.h Sun Mar 9 23:47:21 2003
@@ -16,7 +16,7 @@
int mpu;
};

-#ifdef CONFIG_PNP_CARD
+#ifdef CONFIG_PNP

/*
* SoundBlaster PnP tables and structures.

2003-03-10 04:54:18

by Adam Belay

[permalink] [raw]
Subject: Re: [PATCH] PnP Changes for 2.5.64

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.1081 -> 1.1082
# sound/isa/als100.c 1.7 -> 1.8
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/03/09 [email protected] 1.1082
# ALS100 Updates
#
# Updates the als100 driver to use the pnp apis. Includes resource config
# templates.
# --------------------------------------------
#
diff -Nru a/sound/isa/als100.c b/sound/isa/als100.c
--- a/sound/isa/als100.c Sun Mar 9 23:47:46 2003
+++ b/sound/isa/als100.c Sun Mar 9 23:47:46 2003
@@ -24,11 +24,7 @@
#include <linux/init.h>
#include <linux/wait.h>
#include <linux/time.h>
-#ifndef LINUX_ISAPNP_H
-#include <linux/isapnp.h>
-#define isapnp_card pci_bus
-#define isapnp_dev pci_dev
-#endif
+#include <linux/pnp.h>
#include <sound/core.h>
#define SNDRV_GET_ID
#include <sound/initval.h>
@@ -96,167 +92,126 @@
MODULE_PARM_SYNTAX(dma16, SNDRV_DMA16_DESC);

struct snd_card_als100 {
-#ifdef __ISAPNP__
- struct isapnp_dev *dev;
- struct isapnp_dev *devmpu;
- struct isapnp_dev *devopl;
-#endif /* __ISAPNP__ */
+ int dev_no;
+ struct pnp_dev *dev;
+ struct pnp_dev *devmpu;
+ struct pnp_dev *devopl;
};

-static snd_card_t *snd_als100_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
-
-#ifdef __ISAPNP__
-static struct isapnp_card *snd_als100_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
-static const struct isapnp_card_id *snd_als100_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
-
-#define ISAPNP_ALS100(_va, _vb, _vc, _device, _audio, _mpu401, _opl) \
- { \
- ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
- devs : { ISAPNP_DEVICE_ID('@', '@', '@', _audio), \
- ISAPNP_DEVICE_ID('@', 'X', '@', _mpu401), \
- ISAPNP_DEVICE_ID('@', 'H', '@', _opl) } \
- }
-
-static struct isapnp_card_id snd_als100_pnpids[] __devinitdata = {
+static struct pnp_card_id snd_als100_pnpids[] __devinitdata = {
/* ALS100 - PRO16PNP */
- ISAPNP_ALS100('A','L','S',0x0001,0x0001,0x0001,0x0001),
+ { .id = "ALS0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
/* ALS110 - MF1000 - Digimate 3D Sound */
- ISAPNP_ALS100('A','L','S',0x0110,0x1001,0x1001,0x1001),
+ { .id = "ALS0110", .devs = { { "@@@1001" }, { "@X@1001" }, { "@H@1001" }, } },
/* ALS120 */
- ISAPNP_ALS100('A','L','S',0x0120,0x2001,0x2001,0x2001),
+ { .id = "ALS0120", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" }, } },
/* ALS200 */
- ISAPNP_ALS100('A','L','S',0x0200,0x0020,0x0020,0x0001),
+ { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0001" }, } },
/* RTL3000 */
- ISAPNP_ALS100('R','T','L',0x3000,0x2001,0x2001,0x2001),
- { ISAPNP_CARD_END, }
+ { .id = "RTL3000", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" }, } },
+ { .id = "", } /* end */
};

-ISAPNP_CARD_TABLE(snd_als100_pnpids);
-
-#endif /* __ISAPNP__ */
+MODULE_DEVICE_TABLE(pnp_card, snd_als100_pnpids);

#define DRIVER_NAME "snd-card-als100"

+static struct pnp_card_driver als100_pnpc_driver;

-#ifdef __ISAPNP__
-static int __init snd_card_als100_isapnp(int dev, struct snd_card_als100 *acard)
+static int __devinit snd_card_als100_isapnp(int dev, struct snd_card_als100 *acard,
+ struct pnp_card *card,
+ const struct pnp_card_id *id)
{
- const struct isapnp_card_id *id = snd_als100_isapnp_id[dev];
- struct isapnp_card *card = snd_als100_isapnp_cards[dev];
- struct isapnp_dev *pdev;
-
- acard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
- if (acard->dev->active) {
- acard->dev = NULL;
- return -EBUSY;
- }
- acard->devmpu = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL);
- if (acard->devmpu->active) {
- acard->dev = acard->devmpu = NULL;
- return -EBUSY;
- }
- acard->devopl = isapnp_find_dev(card, id->devs[2].vendor, id->devs[2].function, NULL);
- if (acard->devopl->active) {
- acard->dev = acard->devmpu = acard->devopl = NULL;
- return -EBUSY;
+ struct pnp_dev *pdev;
+ struct pnp_resource_table * cfg = kmalloc(GFP_ATOMIC, sizeof(struct pnp_resource_table));
+ int err;
+ if (!cfg)
+ return -ENOMEM;
+ acard->dev = pnp_request_card_device(&als100_pnpc_driver, card, id->devs[0].id, NULL);
+ if (acard->dev == NULL) {
+ kfree(cfg);
+ return -ENODEV;
}
+ acard->devmpu = pnp_request_card_device(&als100_pnpc_driver, card, id->devs[1].id, acard->dev);
+ acard->devopl = pnp_request_card_device(&als100_pnpc_driver, card, id->devs[2].id, acard->devmpu);

pdev = acard->dev;
- if (pdev->prepare(pdev)<0)
- return -EAGAIN;

+ pnp_init_resource_table(cfg);
+
+ /* override resources */
if (port[dev] != SNDRV_AUTO_PORT)
- isapnp_resource_change(&pdev->resource[0], port[dev], 16);
+ pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
if (dma8[dev] != SNDRV_AUTO_DMA)
- isapnp_resource_change(&pdev->dma_resource[0], dma8[dev],
- 1);
+ pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
if (dma16[dev] != SNDRV_AUTO_DMA)
- isapnp_resource_change(&pdev->dma_resource[1], dma16[dev],
- 1);
+ pnp_resource_change(&cfg->dma_resource[1], dma16[dev], 1);
if (irq[dev] != SNDRV_AUTO_IRQ)
- isapnp_resource_change(&pdev->irq_resource[0], irq[dev], 1);
-
- if (pdev->activate(pdev)<0) {
- printk(KERN_ERR PFX "AUDIO isapnp configure failure\n");
- return -EBUSY;
- }
-
- port[dev] = pdev->resource[0].start;
- dma8[dev] = pdev->dma_resource[1].start;
- dma16[dev] = pdev->dma_resource[0].start;
- irq[dev] = pdev->irq_resource[0].start;
+ pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
+ if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
+ printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0) {
+ printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
+ return err;
+ }
+ port[dev] = pnp_port_start(pdev, 0);
+ dma8[dev] = pnp_dma(pdev, 1);
+ dma16[dev] = pnp_dma(pdev, 0);
+ irq[dev] = pnp_irq(pdev, 0);

pdev = acard->devmpu;
- if (pdev == NULL || pdev->prepare(pdev)<0) {
- mpu_port[dev] = -1;
- return 0;
- }
-
- if (mpu_port[dev] != SNDRV_AUTO_PORT)
- isapnp_resource_change(&pdev->resource[0], mpu_port[dev],
- 2);
- if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
- isapnp_resource_change(&pdev->irq_resource[0], mpu_irq[dev],
- 1);
-
- if (pdev->activate(pdev)<0) {
- printk(KERN_ERR PFX "MPU-401 isapnp configure failure\n");
- mpu_port[dev] = -1;
- acard->devmpu = NULL;
+ if (pdev != NULL) {
+ pnp_init_resource_table(cfg);
+ if (mpu_port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
+ if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
+ pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
+ if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
+ printk(KERN_ERR PFX "MPU401 the requested resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0)
+ goto __mpu_error;
+ mpu_port[dev] = pnp_port_start(pdev, 0);
+ mpu_irq[dev] = pnp_irq(pdev, 0);
} else {
- mpu_port[dev] = pdev->resource[0].start;
- mpu_irq[dev] = pdev->irq_resource[0].start;
+ __mpu_error:
+ if (pdev) {
+ pnp_release_card_device(pdev);
+ printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
+ }
+ acard->devmpu = NULL;
+ mpu_port[dev] = -1;
}

pdev = acard->devopl;
- if (pdev == NULL || pdev->prepare(pdev)<0) {
- fm_port[dev] = -1;
- return 0;
- }
-
- if (fm_port[dev] != SNDRV_AUTO_PORT)
- isapnp_resource_change(&pdev->resource[0], fm_port[dev], 4);
-
- if (pdev->activate(pdev)<0) {
- printk(KERN_ERR PFX "OPL isapnp configure failure\n");
- fm_port[dev] = -1;
- acard->devopl = NULL;
+ if (pdev != NULL) {
+ pnp_init_resource_table(cfg);
+ if (fm_port[dev] != SNDRV_AUTO_PORT)
+ pnp_resource_change(&cfg->port_resource[0], fm_port[dev], 4);
+ if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
+ printk(KERN_ERR PFX "OPL3 the requested resources are invalid, using auto config\n");
+ err = pnp_activate_dev(pdev);
+ if (err < 0)
+ goto __fm_error;
+ fm_port[dev] = pnp_port_start(pdev, 0);
} else {
- fm_port[dev] = pdev->resource[0].start;
+ __fm_error:
+ if (pdev) {
+ pnp_release_card_device(pdev);
+ printk(KERN_ERR PFX "OPL3 pnp configure failure, skipping\n");
+ }
+ acard->devopl = NULL;
+ fm_port[dev] = -1;
}

+ kfree(cfg);
return 0;
}

-static void snd_card_als100_deactivate(struct snd_card_als100 *acard)
-{
- if (acard->dev) {
- acard->dev->deactivate(acard->dev);
- acard->dev = NULL;
- }
- if (acard->devmpu) {
- acard->devmpu->deactivate(acard->devmpu);
- acard->devmpu = NULL;
- }
- if (acard->devopl) {
- acard->devopl->deactivate(acard->devopl);
- acard->devopl = NULL;
- }
-}
-#endif /* __ISAPNP__ */
-
-static void snd_card_als100_free(snd_card_t *card)
-{
- struct snd_card_als100 *acard = (struct snd_card_als100 *)card->private_data;
-
- if (acard) {
-#ifdef __ISAPNP__
- snd_card_als100_deactivate(acard);
-#endif /* __ISAPNP__ */
- }
-}
-
-static int __init snd_card_als100_probe(int dev)
+static int __init snd_card_als100_probe(int dev,
+ struct pnp_card *pcard,
+ const struct pnp_card_id *pid)
{
int error;
sb_t *chip;
@@ -268,18 +223,11 @@
sizeof(struct snd_card_als100))) == NULL)
return -ENOMEM;
acard = (struct snd_card_als100 *)card->private_data;
- card->private_free = snd_card_als100_free;

-#ifdef __ISAPNP__
- if ((error = snd_card_als100_isapnp(dev, acard))) {
+ if ((error = snd_card_als100_isapnp(dev, acard, pcard, pid))) {
snd_card_free(card);
return error;
}
-#else
- printk(KERN_ERR PFX "you have to enable PnP support ...\n");
- snd_card_free(card);
- return -ENOSYS;
-#endif /* __ISAPNP__ */

if ((error = snd_sbdsp_create(card, port[dev],
irq[dev],
@@ -336,13 +284,12 @@
snd_card_free(card);
return error;
}
- snd_als100_cards[dev] = card;
+ pnp_set_card_drvdata(pcard, card);
return 0;
}

-#ifdef __ISAPNP__
-static int __init snd_als100_isapnp_detect(struct isapnp_card *card,
- const struct isapnp_card_id *id)
+static int __devinit snd_als100_pnp_detect(struct pnp_card *card,
+ const struct pnp_card_id *id)
{
static int dev;
int res;
@@ -350,9 +297,7 @@
for ( ; dev < SNDRV_CARDS; dev++) {
if (!enable[dev])
continue;
- snd_als100_isapnp_cards[dev] = card;
- snd_als100_isapnp_id[dev] = id;
- res = snd_card_als100_probe(dev);
+ res = snd_card_als100_probe(dev, card, id);
if (res < 0)
return res;
dev++;
@@ -360,17 +305,28 @@
}
return -ENODEV;
}
-#endif
+
+static void __devexit snd_als100_pnp_remove(struct pnp_card * pcard)
+{
+ snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
+
+ snd_card_disconnect(card);
+ snd_card_free_in_thread(card);
+}
+
+static struct pnp_card_driver als100_pnpc_driver = {
+ .flags = PNP_DRIVER_RES_DISABLE,
+ .name = "als100",
+ .id_table = snd_als100_pnpids,
+ .probe = snd_als100_pnp_detect,
+ .remove = __devexit_p(snd_als100_pnp_remove),
+};

static int __init alsa_card_als100_init(void)
{
int cards = 0;

-#ifdef __ISAPNP__
- cards += isapnp_probe_cards(snd_als100_pnpids, snd_als100_isapnp_detect);
-#else
- printk(KERN_ERR PFX "you have to enable ISA PnP support.\n");
-#endif
+ cards += pnp_register_card_driver(&als100_pnpc_driver);
#ifdef MODULE
if (!cards)
printk(KERN_ERR "no ALS100 based soundcards found\n");
@@ -380,10 +336,7 @@

static void __exit alsa_card_als100_exit(void)
{
- int dev;
-
- for (dev = 0; dev < SNDRV_CARDS; dev++)
- snd_card_free(snd_als100_cards[dev]);
+ pnp_unregister_card_driver(&als100_pnpc_driver);
}

module_init(alsa_card_als100_init)

2003-03-10 04:54:18

by Adam Belay

[permalink] [raw]
Subject: Re: [PATCH] PnP Changes for 2.5.64

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
# ChangeSet 1.1082 -> 1.1083
# sound/oss/sb_card.c 1.15 -> 1.16
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 03/03/09 [email protected] 1.1083
# OSS SB driver Updates
#
# Compatibility update for the latest changes.
# --------------------------------------------
#
diff -Nru a/sound/oss/sb_card.c b/sound/oss/sb_card.c
--- a/sound/oss/sb_card.c Sun Mar 9 23:47:34 2003
+++ b/sound/oss/sb_card.c Sun Mar 9 23:47:34 2003
@@ -252,14 +252,14 @@
"dma=%d, dma16=%d\n", scc->conf.io_base, scc->conf.irq,
scc->conf.dma, scc->conf.dma2);

- pnpc_set_drvdata(card, scc);
+ pnp_set_card_drvdata(card, scc);

return sb_register_oss(scc, &sbmo);
}

static void sb_pnp_remove(struct pnp_card *card)
{
- struct sb_card_config *scc = pnpc_get_drvdata(card);
+ struct sb_card_config *scc = pnp_get_card_drvdata(card);

if(!scc)
return;
@@ -269,7 +269,7 @@
sb_unload(scc);
}

-static struct pnpc_driver sb_pnp_driver = {
+static struct pnp_card_driver sb_pnp_driver = {
.name = "OSS SndBlstr", /* 16 character limit */
.id_table = sb_pnp_card_table,
.probe = sb_pnp_probe,
@@ -295,7 +295,7 @@

#ifdef CONFIG_PNP_CARD
if(pnp) {
- pres = pnpc_register_driver(&sb_pnp_driver);
+ pres = pnp_register_card_driver(&sb_pnp_driver);
}
#endif
printk(KERN_INFO "sb: Init: Done\n");
@@ -316,7 +316,7 @@
}

#ifdef CONFIG_PNP_CARD
- pnpc_unregister_driver(&sb_pnp_driver);
+ pnp_unregister_card_driver(&sb_pnp_driver);
#endif

if (smw_free) {

2003-03-10 23:05:14

by Ruslan U. Zakirov

[permalink] [raw]
Subject: Re: [PATCH] PnP Changes for 2.5.64

Hello, Adam and other.
Now with this changes, driver depend on CONFIG_PNP.
What to do if I want compile kernel without PnP layer and I want use my
soundcard?
Best regards, Ruslan.

On Mon, 10 Mar 2003, Adam Belay wrote:
> # This is a BitKeeper generated patch for the following project:
> # Project Name: Linux kernel tree
> # This patch format is intended for GNU patch command version 2.5 or higher.
> # This patch includes the following deltas:
> # ChangeSet 1.1081 -> 1.1082
> # sound/isa/als100.c 1.7 -> 1.8
> #
> # The following is the BitKeeper ChangeSet Log
> # --------------------------------------------
> # 03/03/09 [email protected] 1.1082
> # ALS100 Updates
> #
> # Updates the als100 driver to use the pnp apis. Includes resource config
> # templates.
> # --------------------------------------------
> #
> diff -Nru a/sound/isa/als100.c b/sound/isa/als100.c
> --- a/sound/isa/als100.c Sun Mar 9 23:47:46 2003
> +++ b/sound/isa/als100.c Sun Mar 9 23:47:46 2003
> @@ -24,11 +24,7 @@
> #include <linux/init.h>
> #include <linux/wait.h>
> #include <linux/time.h>
> -#ifndef LINUX_ISAPNP_H
> -#include <linux/isapnp.h>
> -#define isapnp_card pci_bus
> -#define isapnp_dev pci_dev
> -#endif
> +#include <linux/pnp.h>
> #include <sound/core.h>
> #define SNDRV_GET_ID
> #include <sound/initval.h>
> @@ -96,167 +92,126 @@
> MODULE_PARM_SYNTAX(dma16, SNDRV_DMA16_DESC);
>
> struct snd_card_als100 {
> -#ifdef __ISAPNP__
> - struct isapnp_dev *dev;
> - struct isapnp_dev *devmpu;
> - struct isapnp_dev *devopl;
> -#endif /* __ISAPNP__ */
> + int dev_no;
> + struct pnp_dev *dev;
> + struct pnp_dev *devmpu;
> + struct pnp_dev *devopl;
> };
>
> -static snd_card_t *snd_als100_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
> -
> -#ifdef __ISAPNP__
> -static struct isapnp_card *snd_als100_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
> -static const struct isapnp_card_id *snd_als100_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
> -
> -#define ISAPNP_ALS100(_va, _vb, _vc, _device, _audio, _mpu401, _opl) \
> - { \
> - ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
> - devs : { ISAPNP_DEVICE_ID('@', '@', '@', _audio), \
> - ISAPNP_DEVICE_ID('@', 'X', '@', _mpu401), \
> - ISAPNP_DEVICE_ID('@', 'H', '@', _opl) } \
> - }
> -
> -static struct isapnp_card_id snd_als100_pnpids[] __devinitdata = {
> +static struct pnp_card_id snd_als100_pnpids[] __devinitdata = {
> /* ALS100 - PRO16PNP */
> - ISAPNP_ALS100('A','L','S',0x0001,0x0001,0x0001,0x0001),
> + { .id = "ALS0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
> /* ALS110 - MF1000 - Digimate 3D Sound */
> - ISAPNP_ALS100('A','L','S',0x0110,0x1001,0x1001,0x1001),
> + { .id = "ALS0110", .devs = { { "@@@1001" }, { "@X@1001" }, { "@H@1001" }, } },
> /* ALS120 */
> - ISAPNP_ALS100('A','L','S',0x0120,0x2001,0x2001,0x2001),
> + { .id = "ALS0120", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" }, } },
> /* ALS200 */
> - ISAPNP_ALS100('A','L','S',0x0200,0x0020,0x0020,0x0001),
> + { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0001" }, } },
> /* RTL3000 */
> - ISAPNP_ALS100('R','T','L',0x3000,0x2001,0x2001,0x2001),
> - { ISAPNP_CARD_END, }
> + { .id = "RTL3000", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" }, } },
> + { .id = "", } /* end */
> };
>
> -ISAPNP_CARD_TABLE(snd_als100_pnpids);
> -
> -#endif /* __ISAPNP__ */
> +MODULE_DEVICE_TABLE(pnp_card, snd_als100_pnpids);
>
> #define DRIVER_NAME "snd-card-als100"
>
> +static struct pnp_card_driver als100_pnpc_driver;
>
> -#ifdef __ISAPNP__
> -static int __init snd_card_als100_isapnp(int dev, struct snd_card_als100 *acard)
> +static int __devinit snd_card_als100_isapnp(int dev, struct snd_card_als100 *acard,
> + struct pnp_card *card,
> + const struct pnp_card_id *id)
> {
> - const struct isapnp_card_id *id = snd_als100_isapnp_id[dev];
> - struct isapnp_card *card = snd_als100_isapnp_cards[dev];
> - struct isapnp_dev *pdev;
> -
> - acard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL);
> - if (acard->dev->active) {
> - acard->dev = NULL;
> - return -EBUSY;
> - }
> - acard->devmpu = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL);
> - if (acard->devmpu->active) {
> - acard->dev = acard->devmpu = NULL;
> - return -EBUSY;
> - }
> - acard->devopl = isapnp_find_dev(card, id->devs[2].vendor, id->devs[2].function, NULL);
> - if (acard->devopl->active) {
> - acard->dev = acard->devmpu = acard->devopl = NULL;
> - return -EBUSY;
> + struct pnp_dev *pdev;
> + struct pnp_resource_table * cfg = kmalloc(GFP_ATOMIC, sizeof(struct pnp_resource_table));
> + int err;
> + if (!cfg)
> + return -ENOMEM;
> + acard->dev = pnp_request_card_device(&als100_pnpc_driver, card, id->devs[0].id, NULL);
> + if (acard->dev == NULL) {
> + kfree(cfg);
> + return -ENODEV;
> }
> + acard->devmpu = pnp_request_card_device(&als100_pnpc_driver, card, id->devs[1].id, acard->dev);
> + acard->devopl = pnp_request_card_device(&als100_pnpc_driver, card, id->devs[2].id, acard->devmpu);
>
> pdev = acard->dev;
> - if (pdev->prepare(pdev)<0)
> - return -EAGAIN;
>
> + pnp_init_resource_table(cfg);
> +
> + /* override resources */
> if (port[dev] != SNDRV_AUTO_PORT)
> - isapnp_resource_change(&pdev->resource[0], port[dev], 16);
> + pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
> if (dma8[dev] != SNDRV_AUTO_DMA)
> - isapnp_resource_change(&pdev->dma_resource[0], dma8[dev],
> - 1);
> + pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
> if (dma16[dev] != SNDRV_AUTO_DMA)
> - isapnp_resource_change(&pdev->dma_resource[1], dma16[dev],
> - 1);
> + pnp_resource_change(&cfg->dma_resource[1], dma16[dev], 1);
> if (irq[dev] != SNDRV_AUTO_IRQ)
> - isapnp_resource_change(&pdev->irq_resource[0], irq[dev], 1);
> -
> - if (pdev->activate(pdev)<0) {
> - printk(KERN_ERR PFX "AUDIO isapnp configure failure\n");
> - return -EBUSY;
> - }
> -
> - port[dev] = pdev->resource[0].start;
> - dma8[dev] = pdev->dma_resource[1].start;
> - dma16[dev] = pdev->dma_resource[0].start;
> - irq[dev] = pdev->irq_resource[0].start;
> + pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
> + if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
> + printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
> + err = pnp_activate_dev(pdev);
> + if (err < 0) {
> + printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
> + return err;
> + }
> + port[dev] = pnp_port_start(pdev, 0);
> + dma8[dev] = pnp_dma(pdev, 1);
> + dma16[dev] = pnp_dma(pdev, 0);
> + irq[dev] = pnp_irq(pdev, 0);
>
> pdev = acard->devmpu;
> - if (pdev == NULL || pdev->prepare(pdev)<0) {
> - mpu_port[dev] = -1;
> - return 0;
> - }
> -
> - if (mpu_port[dev] != SNDRV_AUTO_PORT)
> - isapnp_resource_change(&pdev->resource[0], mpu_port[dev],
> - 2);
> - if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
> - isapnp_resource_change(&pdev->irq_resource[0], mpu_irq[dev],
> - 1);
> -
> - if (pdev->activate(pdev)<0) {
> - printk(KERN_ERR PFX "MPU-401 isapnp configure failure\n");
> - mpu_port[dev] = -1;
> - acard->devmpu = NULL;
> + if (pdev != NULL) {
> + pnp_init_resource_table(cfg);
> + if (mpu_port[dev] != SNDRV_AUTO_PORT)
> + pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
> + if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
> + pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
> + if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
> + printk(KERN_ERR PFX "MPU401 the requested resources are invalid, using auto config\n");
> + err = pnp_activate_dev(pdev);
> + if (err < 0)
> + goto __mpu_error;
> + mpu_port[dev] = pnp_port_start(pdev, 0);
> + mpu_irq[dev] = pnp_irq(pdev, 0);
> } else {
> - mpu_port[dev] = pdev->resource[0].start;
> - mpu_irq[dev] = pdev->irq_resource[0].start;
> + __mpu_error:
> + if (pdev) {
> + pnp_release_card_device(pdev);
> + printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
> + }
> + acard->devmpu = NULL;
> + mpu_port[dev] = -1;
> }
>
> pdev = acard->devopl;
> - if (pdev == NULL || pdev->prepare(pdev)<0) {
> - fm_port[dev] = -1;
> - return 0;
> - }
> -
> - if (fm_port[dev] != SNDRV_AUTO_PORT)
> - isapnp_resource_change(&pdev->resource[0], fm_port[dev], 4);
> -
> - if (pdev->activate(pdev)<0) {
> - printk(KERN_ERR PFX "OPL isapnp configure failure\n");
> - fm_port[dev] = -1;
> - acard->devopl = NULL;
> + if (pdev != NULL) {
> + pnp_init_resource_table(cfg);
> + if (fm_port[dev] != SNDRV_AUTO_PORT)
> + pnp_resource_change(&cfg->port_resource[0], fm_port[dev], 4);
> + if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
> + printk(KERN_ERR PFX "OPL3 the requested resources are invalid, using auto config\n");
> + err = pnp_activate_dev(pdev);
> + if (err < 0)
> + goto __fm_error;
> + fm_port[dev] = pnp_port_start(pdev, 0);
> } else {
> - fm_port[dev] = pdev->resource[0].start;
> + __fm_error:
> + if (pdev) {
> + pnp_release_card_device(pdev);
> + printk(KERN_ERR PFX "OPL3 pnp configure failure, skipping\n");
> + }
> + acard->devopl = NULL;
> + fm_port[dev] = -1;
> }
>
> + kfree(cfg);
> return 0;
> }
>
> -static void snd_card_als100_deactivate(struct snd_card_als100 *acard)
> -{
> - if (acard->dev) {
> - acard->dev->deactivate(acard->dev);
> - acard->dev = NULL;
> - }
> - if (acard->devmpu) {
> - acard->devmpu->deactivate(acard->devmpu);
> - acard->devmpu = NULL;
> - }
> - if (acard->devopl) {
> - acard->devopl->deactivate(acard->devopl);
> - acard->devopl = NULL;
> - }
> -}
> -#endif /* __ISAPNP__ */
> -
> -static void snd_card_als100_free(snd_card_t *card)
> -{
> - struct snd_card_als100 *acard = (struct snd_card_als100 *)card->private_data;
> -
> - if (acard) {
> -#ifdef __ISAPNP__
> - snd_card_als100_deactivate(acard);
> -#endif /* __ISAPNP__ */
> - }
> -}
> -
> -static int __init snd_card_als100_probe(int dev)
> +static int __init snd_card_als100_probe(int dev,
> + struct pnp_card *pcard,
> + const struct pnp_card_id *pid)
> {
> int error;
> sb_t *chip;
> @@ -268,18 +223,11 @@
> sizeof(struct snd_card_als100))) == NULL)
> return -ENOMEM;
> acard = (struct snd_card_als100 *)card->private_data;
> - card->private_free = snd_card_als100_free;
>
> -#ifdef __ISAPNP__
> - if ((error = snd_card_als100_isapnp(dev, acard))) {
> + if ((error = snd_card_als100_isapnp(dev, acard, pcard, pid))) {
> snd_card_free(card);
> return error;
> }
> -#else
> - printk(KERN_ERR PFX "you have to enable PnP support ...\n");
> - snd_card_free(card);
> - return -ENOSYS;
> -#endif /* __ISAPNP__ */
>
> if ((error = snd_sbdsp_create(card, port[dev],
> irq[dev],
> @@ -336,13 +284,12 @@
> snd_card_free(card);
> return error;
> }
> - snd_als100_cards[dev] = card;
> + pnp_set_card_drvdata(pcard, card);
> return 0;
> }
>
> -#ifdef __ISAPNP__
> -static int __init snd_als100_isapnp_detect(struct isapnp_card *card,
> - const struct isapnp_card_id *id)
> +static int __devinit snd_als100_pnp_detect(struct pnp_card *card,
> + const struct pnp_card_id *id)
> {
> static int dev;
> int res;
> @@ -350,9 +297,7 @@
> for ( ; dev < SNDRV_CARDS; dev++) {
> if (!enable[dev])
> continue;
> - snd_als100_isapnp_cards[dev] = card;
> - snd_als100_isapnp_id[dev] = id;
> - res = snd_card_als100_probe(dev);
> + res = snd_card_als100_probe(dev, card, id);
> if (res < 0)
> return res;
> dev++;
> @@ -360,17 +305,28 @@
> }
> return -ENODEV;
> }
> -#endif
> +
> +static void __devexit snd_als100_pnp_remove(struct pnp_card * pcard)
> +{
> + snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
> +
> + snd_card_disconnect(card);
> + snd_card_free_in_thread(card);
> +}
> +
> +static struct pnp_card_driver als100_pnpc_driver = {
> + .flags = PNP_DRIVER_RES_DISABLE,
> + .name = "als100",
> + .id_table = snd_als100_pnpids,
> + .probe = snd_als100_pnp_detect,
> + .remove = __devexit_p(snd_als100_pnp_remove),
> +};
>
> static int __init alsa_card_als100_init(void)
> {
> int cards = 0;
>
> -#ifdef __ISAPNP__
> - cards += isapnp_probe_cards(snd_als100_pnpids, snd_als100_isapnp_detect);
> -#else
> - printk(KERN_ERR PFX "you have to enable ISA PnP support.\n");
> -#endif
> + cards += pnp_register_card_driver(&als100_pnpc_driver);
> #ifdef MODULE
> if (!cards)
> printk(KERN_ERR "no ALS100 based soundcards found\n");
> @@ -380,10 +336,7 @@
>
> static void __exit alsa_card_als100_exit(void)
> {
> - int dev;
> -
> - for (dev = 0; dev < SNDRV_CARDS; dev++)
> - snd_card_free(snd_als100_cards[dev]);
> + pnp_unregister_card_driver(&als100_pnpc_driver);
> }
>
> module_init(alsa_card_als100_init)
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>

2003-03-11 01:03:31

by Adam Belay

[permalink] [raw]
Subject: Re: [PATCH] PnP Changes for 2.5.64

On Tue, Mar 11, 2003 at 02:15:11AM +0300, Ruslan U. Zakirov wrote:
> Hello, Adam and other.
> Now with this changes, driver depend on CONFIG_PNP.
> What to do if I want compile kernel without PnP layer and I want use my
> soundcard?
> Best regards, Ruslan.

Hi Ruslan,

I understand your concern, actually the code that prevents users from using
als100 without CONFIG_PNP is hidden in kconfig.

config SND_ALS100
tristate "Avance Logic ALS100/ALS120"
depends on SND && ISAPNP
help
Say 'Y' or 'M' to include support for Avance Logic ALS100, ALS110,
ALS120 and ALS200 soundcards.

--->Notice ISAPNP

Also the pnp functions are declared as blank inline functions if CONFIG_PNP
isn't set (see pnp.h). This will prevent compile errors. When ALSA drivers
contain support for both pnp and nonpnp devices (such as sb16), CONFIG_PNP
will be used directly in the code.

Best regards to you as well.

Thanks,
Adam