Commit f8cfa618 authored by Dominik Brodowski's avatar Dominik Brodowski

[PATCH] pcmcia: unify attach, EVENT_CARD_INSERTION handlers into one probe callback

Unify the EVENT_CARD_INSERTION and "attach" callbacks to one unified
probe() callback. As all in-kernel drivers are changed to this new
callback, there will be no temporary backwards-compatibility. Inside a
probe() function, each driver _must_ set struct pcmcia_device
*p_dev->instance and instance->handle correctly.

With these patches, the basic driver interface for 16-bit PCMCIA drivers
now has the classic four callbacks known also from other buses:

        int (*probe)            (struct pcmcia_device *dev);
        void (*remove)          (struct pcmcia_device *dev);

        int (*suspend)          (struct pcmcia_device *dev);
        int (*resume)           (struct pcmcia_device *dev);
Signed-off-by: default avatarDominik Brodowski <linux@dominikbrodowski.net>
parent b4635811
This file details changes in 2.6 which affect PCMCIA card driver authors:
* Unify detach and REMOVAL event code (as of 2.6.16)
void (*remove) (struct pcmcia_device *dev);
* Unify detach and REMOVAL event code, as well as attach and INSERTION
code (as of 2.6.16)
void (*remove) (struct pcmcia_device *dev);
int (*probe) (struct pcmcia_device *dev);
* Move suspend, resume and reset out of event handler (as of 2.6.16)
int (*suspend) (struct pcmcia_device *dev);
......
......@@ -87,11 +87,7 @@ typedef struct bluecard_info_t {
static void bluecard_config(dev_link_t *link);
static void bluecard_release(dev_link_t *link);
static int bluecard_event(event_t event, int priority, event_callback_args_t *args);
static dev_info_t dev_info = "bluecard_cs";
static dev_link_t *bluecard_attach(void);
static void bluecard_detach(struct pcmcia_device *p_dev);
......@@ -860,17 +856,15 @@ static int bluecard_close(bluecard_info_t *info)
return 0;
}
static dev_link_t *bluecard_attach(void)
static int bluecard_attach(struct pcmcia_device *p_dev)
{
bluecard_info_t *info;
client_reg_t client_reg;
dev_link_t *link;
int ret;
/* Create new info device */
info = kzalloc(sizeof(*info), GFP_KERNEL);
if (!info)
return NULL;
return -ENOMEM;
link = &info->link;
link->priv = info;
......@@ -887,20 +881,13 @@ static dev_link_t *bluecard_attach(void)
link->conf.Vcc = 50;
link->conf.IntType = INT_MEMORY_AND_IO;
/* Register with Card Services */
link->next = NULL;
client_reg.dev_info = &dev_info;
client_reg.Version = 0x0210;
client_reg.event_callback_args.client_data = link;
ret = pcmcia_register_client(&link->handle, &client_reg);
if (ret != CS_SUCCESS) {
cs_error(link->handle, RegisterClient, ret);
bluecard_detach(link->handle);
return NULL;
}
link->handle = p_dev;
p_dev->instance = link;
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
bluecard_config(link);
return link;
return 0;
}
......@@ -1046,20 +1033,6 @@ static int bluecard_resume(struct pcmcia_device *dev)
return 0;
}
static int bluecard_event(event_t event, int priority, event_callback_args_t *args)
{
dev_link_t *link = args->client_data;
switch (event) {
case CS_EVENT_CARD_INSERTION:
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
bluecard_config(link);
break;
}
return 0;
}
static struct pcmcia_device_id bluecard_ids[] = {
PCMCIA_DEVICE_PROD_ID12("BlueCard", "LSE041", 0xbaf16fbf, 0x657cc15e),
PCMCIA_DEVICE_PROD_ID12("BTCFCARD", "LSE139", 0xe3987764, 0x2524b59c),
......@@ -1073,8 +1046,7 @@ static struct pcmcia_driver bluecard_driver = {
.drv = {
.name = "bluecard_cs",
},
.attach = bluecard_attach,
.event = bluecard_event,
.probe = bluecard_attach,
.remove = bluecard_detach,
.id_table = bluecard_ids,
.suspend = bluecard_suspend,
......
......@@ -90,11 +90,7 @@ typedef struct bt3c_info_t {
static void bt3c_config(dev_link_t *link);
static void bt3c_release(dev_link_t *link);
static int bt3c_event(event_t event, int priority, event_callback_args_t *args);
static dev_info_t dev_info = "bt3c_cs";
static dev_link_t *bt3c_attach(void);
static void bt3c_detach(struct pcmcia_device *p_dev);
......@@ -661,17 +657,15 @@ static int bt3c_close(bt3c_info_t *info)
return 0;
}
static dev_link_t *bt3c_attach(void)
static int bt3c_attach(struct pcmcia_device *p_dev)
{
bt3c_info_t *info;
client_reg_t client_reg;
dev_link_t *link;
int ret;
/* Create new info device */
info = kzalloc(sizeof(*info), GFP_KERNEL);
if (!info)
return NULL;
return -ENOMEM;
link = &info->link;
link->priv = info;
......@@ -688,20 +682,13 @@ static dev_link_t *bt3c_attach(void)
link->conf.Vcc = 50;
link->conf.IntType = INT_MEMORY_AND_IO;
/* Register with Card Services */
link->next = NULL;
client_reg.dev_info = &dev_info;
client_reg.Version = 0x0210;
client_reg.event_callback_args.client_data = link;
ret = pcmcia_register_client(&link->handle, &client_reg);
if (ret != CS_SUCCESS) {
cs_error(link->handle, RegisterClient, ret);
bt3c_detach(link->handle);
return NULL;
}
link->handle = p_dev;
p_dev->instance = link;
return link;
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
bt3c_config(link);
return 0;
}
......@@ -892,19 +879,6 @@ static int bt3c_resume(struct pcmcia_device *dev)
return 0;
}
static int bt3c_event(event_t event, int priority, event_callback_args_t *args)
{
dev_link_t *link = args->client_data;
switch (event) {
case CS_EVENT_CARD_INSERTION:
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
bt3c_config(link);
break;
}
return 0;
}
static struct pcmcia_device_id bt3c_ids[] = {
PCMCIA_DEVICE_PROD_ID13("3COM", "Bluetooth PC Card", 0xefce0a31, 0xd4ce9b02),
......@@ -917,8 +891,7 @@ static struct pcmcia_driver bt3c_driver = {
.drv = {
.name = "bt3c_cs",
},
.attach = bt3c_attach,
.event = bt3c_event,
.probe = bt3c_attach,
.remove = bt3c_detach,
.id_table = bt3c_ids,
.suspend = bt3c_suspend,
......
......@@ -86,11 +86,7 @@ typedef struct btuart_info_t {
static void btuart_config(dev_link_t *link);
static void btuart_release(dev_link_t *link);
static int btuart_event(event_t event, int priority, event_callback_args_t *args);
static dev_info_t dev_info = "btuart_cs";
static dev_link_t *btuart_attach(void);
static void btuart_detach(struct pcmcia_device *p_dev);
......@@ -580,17 +576,15 @@ static int btuart_close(btuart_info_t *info)
return 0;
}
static dev_link_t *btuart_attach(void)
static int btuart_attach(struct pcmcia_device *p_dev)
{
btuart_info_t *info;
client_reg_t client_reg;
dev_link_t *link;
int ret;
/* Create new info device */
info = kzalloc(sizeof(*info), GFP_KERNEL);
if (!info)
return NULL;
return -ENOMEM;
link = &info->link;
link->priv = info;
......@@ -607,20 +601,13 @@ static dev_link_t *btuart_attach(void)
link->conf.Vcc = 50;
link->conf.IntType = INT_MEMORY_AND_IO;
/* Register with Card Services */
link->next = NULL;
client_reg.dev_info = &dev_info;
client_reg.Version = 0x0210;
client_reg.event_callback_args.client_data = link;
ret = pcmcia_register_client(&link->handle, &client_reg);
if (ret != CS_SUCCESS) {
cs_error(link->handle, RegisterClient, ret);
btuart_detach(link->handle);
return NULL;
}
link->handle = p_dev;
p_dev->instance = link;
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
btuart_config(link);
return link;
return 0;
}
......@@ -813,20 +800,6 @@ static int btuart_resume(struct pcmcia_device *dev)
}
static int btuart_event(event_t event, int priority, event_callback_args_t *args)
{
dev_link_t *link = args->client_data;
switch (event) {
case CS_EVENT_CARD_INSERTION:
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
btuart_config(link);
break;
}
return 0;
}
static struct pcmcia_device_id btuart_ids[] = {
/* don't use this driver. Use serial_cs + hci_uart instead */
PCMCIA_DEVICE_NULL
......@@ -838,8 +811,7 @@ static struct pcmcia_driver btuart_driver = {
.drv = {
.name = "btuart_cs",
},
.attach = btuart_attach,
.event = btuart_event,
.probe = btuart_attach,
.remove = btuart_detach,
.id_table = btuart_ids,
.suspend = btuart_suspend,
......
......@@ -89,11 +89,7 @@ typedef struct dtl1_info_t {
static void dtl1_config(dev_link_t *link);
static void dtl1_release(dev_link_t *link);
static int dtl1_event(event_t event, int priority, event_callback_args_t *args);
static dev_info_t dev_info = "dtl1_cs";
static dev_link_t *dtl1_attach(void);
static void dtl1_detach(struct pcmcia_device *p_dev);
......@@ -559,17 +555,15 @@ static int dtl1_close(dtl1_info_t *info)
return 0;
}
static dev_link_t *dtl1_attach(void)
static int dtl1_attach(struct pcmcia_device *p_dev)
{
dtl1_info_t *info;
client_reg_t client_reg;
dev_link_t *link;
int ret;
/* Create new info device */
info = kzalloc(sizeof(*info), GFP_KERNEL);
if (!info)
return NULL;
return -ENOMEM;
link = &info->link;
link->priv = info;
......@@ -586,20 +580,13 @@ static dev_link_t *dtl1_attach(void)
link->conf.Vcc = 50;
link->conf.IntType = INT_MEMORY_AND_IO;
/* Register with Card Services */
link->next = NULL;
client_reg.dev_info = &dev_info;
client_reg.Version = 0x0210;
client_reg.event_callback_args.client_data = link;
ret = pcmcia_register_client(&link->handle, &client_reg);
if (ret != CS_SUCCESS) {
cs_error(link->handle, RegisterClient, ret);
dtl1_detach(link->handle);
return NULL;
}
link->handle = p_dev;
p_dev->instance = link;
return link;
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
dtl1_config(link);
return 0;
}
......@@ -764,19 +751,6 @@ static int dtl1_resume(struct pcmcia_device *dev)
return 0;
}
static int dtl1_event(event_t event, int priority, event_callback_args_t *args)
{
dev_link_t *link = args->client_data;
switch (event) {
case CS_EVENT_CARD_INSERTION:
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
dtl1_config(link);
break;
}
return 0;
}
static struct pcmcia_device_id dtl1_ids[] = {
PCMCIA_DEVICE_PROD_ID12("Nokia Mobile Phones", "DTL-1", 0xe1bfdd64, 0xe168480d),
......@@ -790,8 +764,7 @@ static struct pcmcia_driver dtl1_driver = {
.drv = {
.name = "dtl1_cs",
},
.attach = dtl1_attach,
.event = dtl1_event,
.probe = dtl1_attach,
.remove = dtl1_detach,
.id_table = dtl1_ids,
.suspend = dtl1_suspend,
......
......@@ -66,7 +66,6 @@ static char *version = "cm4000_cs.c v2.4.0gm5 - All bugs added by Harald Welte";
#define T_100MSEC msecs_to_jiffies(100)
#define T_500MSEC msecs_to_jiffies(500)
static void cm4000_detach(struct pcmcia_device *p_dev);
static void cm4000_release(dev_link_t *link);
static int major; /* major number we get from the kernel */
......@@ -156,7 +155,6 @@ struct cm4000_dev {
/*sbuf*/ 512*sizeof(char) - \
/*queue*/ 4*sizeof(wait_queue_head_t))
static dev_info_t dev_info = MODULE_NAME;
static dev_link_t *dev_table[CM4000_MAX_DEV];
/* This table doesn't use spaces after the comma between fields and thus
......@@ -1864,38 +1862,6 @@ static void cm4000_config(dev_link_t * link, int devno)
link->state &= ~DEV_CONFIG_PENDING;
}
static int cm4000_event(event_t event, int priority,
event_callback_args_t *args)
{
dev_link_t *link;
struct cm4000_dev *dev;
int devno;
link = args->client_data;
dev = link->priv;
DEBUGP(3, dev, "-> cm4000_event\n");
for (devno = 0; devno < CM4000_MAX_DEV; devno++)
if (dev_table[devno] == link)
break;
if (devno == CM4000_MAX_DEV)
return CS_BAD_ADAPTER;
switch (event) {
case CS_EVENT_CARD_INSERTION:
DEBUGP(5, dev, "CS_EVENT_CARD_INSERTION\n");
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
cm4000_config(link, devno);
break;
default:
DEBUGP(5, dev, "unknown event %.2x\n", event);
break;
}
DEBUGP(3, dev, "<- cm4000_event\n");
return CS_SUCCESS;
}
static int cm4000_suspend(struct pcmcia_device *p_dev)
{
dev_link_t *link = dev_to_instance(p_dev);
......@@ -1935,11 +1901,10 @@ static void cm4000_release(dev_link_t *link)
pcmcia_release_io(link->handle, &link->io);
}
static dev_link_t *cm4000_attach(void)
static int cm4000_attach(struct pcmcia_device *p_dev)
{
struct cm4000_dev *dev;
dev_link_t *link;
client_reg_t client_reg;
int i;
for (i = 0; i < CM4000_MAX_DEV; i++)
......@@ -1948,41 +1913,31 @@ static dev_link_t *cm4000_attach(void)
if (i == CM4000_MAX_DEV) {
printk(KERN_NOTICE MODULE_NAME ": all devices in use\n");
return NULL;
return -ENODEV;
}
/* create a new cm4000_cs device */
dev = kzalloc(sizeof(struct cm4000_dev), GFP_KERNEL);
if (dev == NULL)
return NULL;
return -ENOMEM;
link = &dev->link;
link->priv = dev;
link->conf.IntType = INT_MEMORY_AND_IO;
dev_table[i] = link;
/* register with card services */
client_reg.dev_info = &dev_info;
client_reg.EventMask =
CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
client_reg.Version = 0x0210;
client_reg.event_callback_args.client_data = link;
i = pcmcia_register_client(&link->handle, &client_reg);
if (i) {
cs_error(link->handle, RegisterClient, i);
cm4000_detach(link->handle);
return NULL;
}
init_waitqueue_head(&dev->devq);
init_waitqueue_head(&dev->ioq);
init_waitqueue_head(&dev->atrq);
init_waitqueue_head(&dev->readq);
return link;
link->handle = p_dev;
p_dev->instance = link;
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
cm4000_config(link, i);
return 0;
}
static void cm4000_detach(struct pcmcia_device *p_dev)
......@@ -2031,11 +1986,10 @@ static struct pcmcia_driver cm4000_driver = {
.drv = {
.name = "cm4000_cs",
},
.attach = cm4000_attach,
.probe = cm4000_attach,
.remove = cm4000_detach,
.suspend = cm4000_suspend,
.resume = cm4000_resume,
.event = cm4000_event,
.id_table = cm4000_ids,
};
......
......@@ -65,7 +65,6 @@ static char *version =
#define POLL_PERIOD msecs_to_jiffies(10)
static void reader_release(dev_link_t *link);
static void reader_detach(struct pcmcia_device *p_dev);
static int major;
......@@ -86,7 +85,6 @@ struct reader_dev {
struct timer_list poll_timer;
};
static dev_info_t dev_info = MODULE_NAME;
static dev_link_t *dev_table[CM_MAX_DEV];
#ifndef PCMCIA_DEBUG
......@@ -629,39 +627,6 @@ static void reader_config(dev_link_t *link, int devno)
link->state &= ~DEV_CONFIG_PENDING;
}
static int reader_event(event_t event, int priority,
event_callback_args_t *args)
{
dev_link_t *link;
struct reader_dev *dev;
int devno;
link = args->client_data;
dev = link->priv;
DEBUGP(3, dev, "-> reader_event\n");
for (devno = 0; devno < CM_MAX_DEV; devno++) {
if (dev_table[devno] == link)
break;
}
if (devno == CM_MAX_DEV)
return CS_BAD_ADAPTER;
switch (event) {
case CS_EVENT_CARD_INSERTION:
DEBUGP(5, dev, "CS_EVENT_CARD_INSERTION\n");
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
reader_config(link, devno);
break;
default:
DEBUGP(5, dev, "reader_event: unknown event %.2x\n",
event);
break;
}
DEBUGP(3, dev, "<- reader_event\n");
return CS_SUCCESS;
}
static int reader_suspend(struct pcmcia_device *p_dev)
{
dev_link_t *link = dev_to_instance(p_dev);
......@@ -691,11 +656,10 @@ static void reader_release(dev_link_t *link)
pcmcia_release_io(link->handle, &link->io);
}
static dev_link_t *reader_attach(void)
static int reader_attach(struct pcmcia_device *p_dev)
{
struct reader_dev *dev;
dev_link_t *link;
client_reg_t client_reg;
int i;
for (i = 0; i < CM_MAX_DEV; i++) {
......@@ -704,11 +668,11 @@ static dev_link_t *reader_attach(void)
}
if (i == CM_MAX_DEV)
return NULL;
return -ENODEV;
dev = kzalloc(sizeof(struct reader_dev), GFP_KERNEL);
if (dev == NULL)
return NULL;
return -ENOMEM;
dev->timeout = CCID_DRIVER_MINIMUM_TIMEOUT;
dev->buffer_status = 0;
......@@ -719,20 +683,6 @@ static dev_link_t *reader_attach(void)
link->conf.IntType = INT_MEMORY_AND_IO;
dev_table[i] = link;
client_reg.dev_info = &dev_info;
client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
client_reg.EventMask=
CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
client_reg.Version = 0x0210;
client_reg.event_callback_args.client_data = link;
i = pcmcia_register_client(&link->handle, &client_reg);
if (i) {
cs_error(link->handle, RegisterClient, i);
reader_detach(link->handle);
return NULL;
}
init_waitqueue_head(&dev->devq);
init_waitqueue_head(&dev->poll_wait);
init_waitqueue_head(&dev->read_wait);
......@@ -740,7 +690,13 @@ static dev_link_t *reader_attach(void)
init_timer(&dev->poll_timer);
dev->poll_timer.function = &cm4040_do_poll;
return link;
link->handle = p_dev;
p_dev->instance = link;
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
reader_config(link, i);
return 0;
}
static void reader_detach(struct pcmcia_device *p_dev)
......@@ -790,11 +746,10 @@ static struct pcmcia_driver reader_driver = {
.drv = {
.name = "cm4040_cs",
},
.attach = reader_attach,
.probe = reader_attach,
.remove = reader_detach,
.suspend = reader_suspend,
.resume = reader_resume,
.event = reader_event,
.id_table = cm4040_ids,
};
......
......@@ -486,13 +486,8 @@ static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout);
static void mgslpc_config(dev_link_t *link);
static void mgslpc_release(u_long arg);
static int mgslpc_event(event_t event, int priority,
event_callback_args_t *args);
static dev_link_t *mgslpc_attach(void);
static void mgslpc_detach(struct pcmcia_device *p_dev);
static dev_info_t dev_info = "synclink_cs";
/*
* 1st function defined in .text section. Calling this function in
* init_module() followed by a breakpoint allows a remote debugger
......@@ -538,12 +533,10 @@ static void ldisc_receive_buf(struct tty_struct *tty,
}
}
static dev_link_t *mgslpc_attach(void)
static int mgslpc_attach(struct pcmcia_device *p_dev)
{
MGSLPC_INFO *info;
dev_link_t *link;
client_reg_t client_reg;
int ret;
if (debug_level >= DEBUG_LEVEL_INFO)
printk("mgslpc_attach\n");
......@@ -551,7 +544,7 @@ static dev_link_t *mgslpc_attach(void)
info = (MGSLPC_INFO *)kmalloc(sizeof(MGSLPC_INFO), GFP_KERNEL);
if (!info) {
printk("Error can't allocate device instance data\n");
return NULL;
return -ENOMEM;
}
memset(info, 0, sizeof(MGSLPC_INFO));
......@@ -586,23 +579,15 @@ static dev_link_t *mgslpc_attach(void)
link->conf.Vcc = 50;
link->conf.IntType = INT_MEMORY_AND_IO;
/* Register with Card Services */
link->next = NULL;
client_reg.dev_info = &dev_info;
client_reg.Version = 0x0210;
client_reg.event_callback_args.client_data = link;
link->handle = p_dev;
p_dev->instance = link;
ret = pcmcia_register_client(&link->handle, &client_reg);
if (ret != CS_SUCCESS) {
cs_error(link->handle, RegisterClient, ret);
mgslpc_detach(link->handle);
return NULL;
}
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
mgslpc_config(link);
mgslpc_add_device(info);
return link;
return 0;
}
/* Card has been inserted.
......@@ -778,23 +763,6 @@ static int mgslpc_resume(struct pcmcia_device *dev)
}
static int mgslpc_event(event_t event, int priority,
event_callback_args_t *args)
{
dev_link_t *link = args->client_data;
if (debug_level >= DEBUG_LEVEL_INFO)
printk("mgslpc_event(0x%06x)\n", event);
switch (event) {
case CS_EVENT_CARD_INSERTION:
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
mgslpc_config(link);
break;
}
return 0;
}
static inline int mgslpc_paranoia_check(MGSLPC_INFO *info,
char *name, const char *routine)
{
......@@ -3071,8 +3039,7 @@ static struct pcmcia_driver mgslpc_driver = {
.drv = {
.name = "synclink_cs",
},
.attach = mgslpc_attach,
.event = mgslpc_event,