* card.c - contains functions for managing groups of PnP devices
*
* Copyright 2002 Adam Belay <ambx1@neo.rr.com>
- *
*/
#include <linux/module.h>
struct pnp_card *card)
{
const struct pnp_card_device_id *drv_id = drv->id_table;
+
while (*drv_id->id) {
if (compare_pnp_id(card->id, drv_id->id)) {
int i = 0;
+
for (;;) {
int found;
struct pnp_dev *dev;
- if (i == PNP_MAX_DEVICES
- || !*drv_id->devs[i].id)
+
+ if (i == PNP_MAX_DEVICES ||
+ !*drv_id->devs[i].id)
return drv_id;
found = 0;
card_for_each_dev(card, dev) {
- if (compare_pnp_id
- (dev->id, drv_id->devs[i].id)) {
+ if (compare_pnp_id(dev->id,
+ drv_id->devs[i].id)) {
found = 1;
break;
}
static void 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)
* 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 pnp_add_card_id(struct pnp_id *id, struct pnp_card *card)
{
struct pnp_id *ptr;
- if (!id)
- return -EINVAL;
- if (!card)
- return -EINVAL;
+
id->next = NULL;
ptr = card->id;
while (ptr && ptr->next)
{
struct pnp_id *id;
struct pnp_id *next;
- if (!card)
- return;
+
id = card->id;
while (id) {
next = id->next;
static void pnp_release_card(struct device *dmdev)
{
struct pnp_card *card = to_pnp_card(dmdev);
+
pnp_free_card_ids(card);
kfree(card);
}
{
char *str = buf;
struct pnp_card *card = to_pnp_card(dmdev);
+
str += sprintf(str, "%s\n", card->name);
return (str - buf);
}
static int pnp_interface_attach_card(struct pnp_card *card)
{
int rc = device_create_file(&card->dev, &dev_attr_name);
+
if (rc)
return rc;
return 0;
- err_name:
+err_name:
device_remove_file(&card->dev, &dev_attr_name);
return rc;
}
* pnp_add_card - adds a PnP card to the PnP Layer
* @card: pointer to the card to add
*/
-
int pnp_add_card(struct pnp_card *card)
{
int error;
struct list_head *pos, *temp;
- if (!card || !card->protocol)
- return -EINVAL;
sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number,
card->number);
card->dev.bus = NULL;
card->dev.release = &pnp_release_card;
error = device_register(&card->dev);
+ if (error) {
+ dev_err(&card->dev, "could not register (err=%d)\n", error);
+ return error;
+ }
- if (error == 0) {
- pnp_interface_attach_card(card);
- 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);
- }
+ pnp_interface_attach_card(card);
+ 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);
- /* match with card drivers */
- list_for_each_safe(pos, temp, &pnp_card_drivers) {
- struct pnp_card_driver *drv =
- list_entry(pos, struct pnp_card_driver,
- global_list);
- card_probe(card, drv);
- }
- } else
- pnp_err("sysfs failure, card '%s' will be unavailable",
- card->dev.bus_id);
- return error;
+ /* 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 an unreasonable length of time */
+ list_for_each(pos, &card->devices) {
+ struct pnp_dev *dev = card_to_pnp_dev(pos);
+ __pnp_add_device(dev);
+ }
+
+ /* match with card drivers */
+ list_for_each_safe(pos, temp, &pnp_card_drivers) {
+ struct pnp_card_driver *drv =
+ list_entry(pos, struct pnp_card_driver,
+ global_list);
+ card_probe(card, drv);
+ }
+ return 0;
}
/**
* pnp_remove_card - removes a PnP card from the PnP Layer
* @card: pointer to the card to remove
*/
-
void pnp_remove_card(struct pnp_card *card)
{
struct list_head *pos, *temp;
- if (!card)
- return;
+
device_unregister(&card->dev);
spin_lock(&pnp_lock);
list_del(&card->global_list);
* @card: pointer to the card to add to
* @dev: pointer to the device to add
*/
-
int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev)
{
- if (!card || !dev || !dev->protocol)
- return -EINVAL;
dev->dev.parent = &card->dev;
dev->card_link = NULL;
snprintf(dev->dev.bus_id, BUS_ID_SIZE, "%02x:%02x.%02x",
* pnp_remove_card_device- removes a device from the specified card
* @dev: pointer to the device to remove
*/
-
void pnp_remove_card_device(struct pnp_dev *dev)
{
spin_lock(&pnp_lock);
* @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_link *clink,
const char *id, struct pnp_dev *from)
{
struct pnp_dev *dev;
struct pnp_card_driver *drv;
struct pnp_card *card;
+
if (!clink || !id)
- goto done;
+ return NULL;
+
card = clink->card;
drv = clink->driver;
if (!from) {
pos = card->devices.next;
} else {
if (from->card != card)
- goto done;
+ return NULL;
pos = from->card_list.next;
}
while (pos != &card->devices) {
pos = pos->next;
}
- done:
return NULL;
- found:
+found:
dev->card_link = clink;
dev->dev.driver = &drv->link.driver;
if (pnp_bus_type.probe(&dev->dev))
return dev;
- err_out:
+err_out:
dev->dev.driver = NULL;
dev->card_link = NULL;
return NULL;
* pnp_release_card_device - call this when the driver no longer needs the device
* @dev: pointer to the PnP device stucture
*/
-
void pnp_release_card_device(struct pnp_dev *dev)
{
struct pnp_card_driver *drv = dev->card_link->driver;
- if (!drv)
- return;
+
drv->link.remove = &card_remove;
device_release_driver(&dev->dev);
drv->link.remove = &card_remove_first;
static int card_suspend(struct pnp_dev *dev, pm_message_t state)
{
struct pnp_card_link *link = dev->card_link;
+
if (link->pm_state.event == state.event)
return 0;
link->pm_state = state;
static int card_resume(struct pnp_dev *dev)
{
struct pnp_card_link *link = dev->card_link;
+
if (link->pm_state.event == PM_EVENT_ON)
return 0;
link->pm_state = PMSG_ON;
* pnp_register_card_driver - registers a PnP card driver with the PnP Layer
* @drv: pointer to the driver to register
*/
-
int pnp_register_card_driver(struct pnp_card_driver *drv)
{
int error;
* pnp_unregister_card_driver - unregisters a PnP card driver from the PnP Layer
* @drv: pointer to the driver to unregister
*/
-
void pnp_unregister_card_driver(struct pnp_card_driver *drv)
{
spin_lock(&pnp_lock);
pnp_unregister_driver(&drv->link);
}
-#if 0
-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);
-#endif /* 0 */
EXPORT_SYMBOL(pnp_request_card_device);
EXPORT_SYMBOL(pnp_release_card_device);
EXPORT_SYMBOL(pnp_register_card_driver);