#include <pcmcia/cs.h>
#include <pcmcia/cistpl.h>
#include <pcmcia/ds.h>
-/*
- A linked list of "instances" of the das08_pcmcia device. Each actual
- PCMCIA card corresponds to one device instance, and is described
- by one dev_link_t structure (defined in ds.h).
- You may not want to use a linked list for this -- for example, the
- memory card driver uses an array of dev_link_t pointers, where minor
- device numbers are used to derive the corresponding array index.
-*/
-static dev_link_t *dev_list = NULL;
+static struct pcmcia_device *cur_dev = NULL;
#define thisboard ((const struct das08_board_struct *)dev->board_ptr)
{
int ret;
unsigned long iobase;
- dev_link_t *link = dev_list; // XXX hack
+ struct pcmcia_device *link = cur_dev; // XXX hack
if((ret=alloc_private(dev,sizeof(struct das08_private_struct)))<0)
return ret;
#endif
/*====================================================================*/
-static void das08_pcmcia_config(dev_link_t *link);
-static void das08_pcmcia_release(u_long arg);
+static void das08_pcmcia_config(struct pcmcia_device *link);
+static void das08_pcmcia_release(struct pcmcia_device *link);
static int das08_pcmcia_suspend(struct pcmcia_device *p_dev);
static int das08_pcmcia_resume(struct pcmcia_device *p_dev);
static const dev_info_t dev_info = "pcm-das08";
-/*
- A dev_link_t structure has fields for most things that are needed
- to keep track of a socket, but there will usually be some device
- specific information that also needs to be kept track of. The
- 'priv' pointer in a dev_link_t structure can be used to point to
- a device-specific private data structure, like this.
-
- To simplify the data structure handling, we actually include the
- dev_link_t structure in the device's private data structure.
-
- A driver needs to provide a dev_node_t structure for each device
- on a card. In some cases, there is only one device per card (for
- example, ethernet cards, modems). In other cases, there may be
- many actual or logical devices (SCSI adapters, memory cards with
- multiple partitions). The dev_node_t structures need to be kept
- in a linked list starting at the 'dev' field of a dev_link_t
- structure. We allocate them in the card's private data structure,
- because they generally shouldn't be allocated dynamically.
-
- In this case, we also provide a flag to indicate if a device is
- "stopped" due to a power management event, or card ejection. The
- device IO routines can use a flag like this to throttle IO to a
- card that is not ready to accept it.
-
- The bus_operations pointer is used on platforms for which we need
- to use special socket-specific versions of normal IO primitives
- (inb, outb, readb, writeb, etc) for card IO.
-*/
-
typedef struct local_info_t {
- dev_link_t link;
+ struct pcmcia_device *link;
dev_node_t node;
int stop;
struct bus_operations *bus;
======================================================================*/
-static int das08_pcmcia_attach(struct pcmcia_device *p_dev)
+static int das08_pcmcia_attach(struct pcmcia_device *link)
{
local_info_t *local;
- dev_link_t *link;
DEBUG(0, "das08_pcmcia_attach()\n");
local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
if (!local) return -ENOMEM;
memset(local, 0, sizeof(local_info_t));
- link = &local->link; link->priv = local;
+ local->link = link;
+ link->priv = local;
/* Interrupt setup */
link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
device, and can be hard-wired here.
*/
link->conf.Attributes = 0;
- link->conf.Vcc = 50;
link->conf.IntType = INT_MEMORY_AND_IO;
- link->next = dev_list;
- dev_list = link;
+ cur_dev = link;
- link->handle = p_dev;
- p_dev->instance = link;
- link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
das08_pcmcia_config(link);
return 0;
======================================================================*/
-static void das08_pcmcia_detach(struct pcmcia_device *p_dev)
+static void das08_pcmcia_detach(struct pcmcia_device *link)
{
- dev_link_t *link = dev_to_instance(p_dev);
- dev_link_t **linkp;
DEBUG(0, "das08_pcmcia_detach(0x%p)\n", link);
- /* Locate device structure */
- for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
- if (*linkp == link) break;
- if (*linkp == NULL)
- return;
-
- /*
- If the device is currently configured and active, we won't
- actually delete it yet. Instead, it is marked so that when
- the release() function is called, that will trigger a proper
- detach().
- */
- if (link->state & DEV_CONFIG)
+ if(link->dev_node)
{
((local_info_t *)link->priv)->stop = 1;
- das08_pcmcia_release((u_long)link);
+ das08_pcmcia_release(link);
}
- /* Unlink device structure, and free it */
- *linkp = link->next;
/* This points to the parent local_info_t struct */
- kfree(link->priv);
+ if(link->priv)
+ kfree(link->priv);
} /* das08_pcmcia_detach */
======================================================================*/
-static void das08_pcmcia_config(dev_link_t *link)
+static void das08_pcmcia_config(struct pcmcia_device *link)
{
- client_handle_t handle = link->handle;
local_info_t *dev = link->priv;
tuple_t tuple;
cisparse_t parse;
int last_fn, last_ret;
u_char buf[64];
- config_info_t conf;
cistpl_cftable_entry_t dflt = { 0 };
DEBUG(0, "das08_pcmcia_config(0x%p)\n", link);
tuple.TupleDataMax = sizeof(buf);
tuple.TupleOffset = 0;
last_fn = GetFirstTuple;
- if((last_ret = pcmcia_get_first_tuple(handle, &tuple)) != 0) goto cs_failed;
+ if((last_ret = pcmcia_get_first_tuple(link, &tuple)) != 0) goto cs_failed;
last_fn = GetTupleData;
- if((last_ret = pcmcia_get_tuple_data(handle, &tuple)) != 0) goto cs_failed;
+ if((last_ret = pcmcia_get_tuple_data(link, &tuple)) != 0) goto cs_failed;
last_fn = ParseTuple;
- if((last_ret = pcmcia_parse_tuple(handle, &tuple, &parse)) != 0) goto cs_failed;
+ if((last_ret = pcmcia_parse_tuple(link, &tuple, &parse)) != 0) goto cs_failed;
link->conf.ConfigBase = parse.config.base;
link->conf.Present = parse.config.rmask[0];
- /* Configure card */
- link->state |= DEV_CONFIG;
-
- /* Look up the current Vcc */
- last_fn = GetConfigurationInfo;
- if((last_ret = pcmcia_get_configuration_info(handle, &conf)) != 0) goto cs_failed;
- link->conf.Vcc = conf.Vcc;
-
/*
In this loop, we scan the CIS for configuration table entries,
each of which describes a valid card configuration, including
*/
tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
last_fn = GetFirstTuple;
- if((last_ret = pcmcia_get_first_tuple(handle, &tuple)) != 0) goto cs_failed;
+ if((last_ret = pcmcia_get_first_tuple(link, &tuple)) != 0) goto cs_failed;
while (1) {
cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
- if((last_ret = pcmcia_get_tuple_data(handle, &tuple)) != 0) goto next_entry;
- if((last_ret = pcmcia_parse_tuple(handle, &tuple, &parse)) != 0) goto next_entry;
+ if((last_ret = pcmcia_get_tuple_data(link, &tuple)) != 0) goto next_entry;
+ if((last_ret = pcmcia_parse_tuple(link, &tuple, &parse)) != 0) goto next_entry;
if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
if (cfg->index == 0) goto next_entry;
link->conf.Status = CCSR_AUDIO_ENA;
}
*/
- /* Use power settings for Vcc and Vpp if present */
- /* Note that the CIS values need to be rescaled */
- if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
- if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000)
- goto next_entry;
- } else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM)) {
- if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM]/10000)
- goto next_entry;
- }
-
- if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
- link->conf.Vpp1 = link->conf.Vpp2 =
- cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
- else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
- link->conf.Vpp1 = link->conf.Vpp2 =
- dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
-
/* Do we need to allocate an interrupt? */
if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
link->conf.Attributes |= CONF_ENABLE_IRQ;
link->io.NumPorts2 = io->win[1].len;
}
/* This reserves IO space but doesn't actually enable it */
- if(pcmcia_request_io(link->handle, &link->io) != 0) goto next_entry;
+ if(pcmcia_request_io(link, &link->io) != 0) goto next_entry;
}
/* If we got this far, we're cool! */
break;
next_entry:
- if (link->io.NumPorts1)
- pcmcia_release_io(link->handle, &link->io);
last_fn = GetNextTuple;
- if((last_ret = pcmcia_get_next_tuple(handle, &tuple)) != 0) goto cs_failed;
+ if((last_ret = pcmcia_get_next_tuple(link, &tuple)) != 0) goto cs_failed;
}
- /*
- Allocate an interrupt line. Note that this does not assign a
- handler to the interrupt, unless the 'Handler' member of the
- irq structure is initialized.
- */
if (link->conf.Attributes & CONF_ENABLE_IRQ)
{
last_fn = RequestIRQ;
- if((last_ret = pcmcia_request_irq(handle, &link->irq)) != 0) goto cs_failed;
+ if((last_ret = pcmcia_request_irq(link, &link->irq)) != 0) goto cs_failed;
}
/*
card and host interface into "Memory and IO" mode.
*/
last_fn = RequestConfiguration;
- if((last_ret = pcmcia_request_configuration(link->handle, &link->conf)) != 0) goto cs_failed;
+ if((last_ret = pcmcia_request_configuration(link, &link->conf)) != 0) goto cs_failed;
/*
At this point, the dev_node_t structure(s) need to be
*/
sprintf(dev->node.dev_name, "pcm-das08");
dev->node.major = dev->node.minor = 0;
- link->dev = &dev->node;
+ link->dev_node = &dev->node;
/* Finally, report what we've done */
- printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d",
- dev->node.dev_name, link->conf.ConfigIndex,
- link->conf.Vcc/10, link->conf.Vcc%10);
- if (link->conf.Vpp1)
- printk(", Vpp %d.%d", link->conf.Vpp1/10, link->conf.Vpp1%10);
+ printk(KERN_INFO "%s: index 0x%02x",
+ dev->node.dev_name, link->conf.ConfigIndex);
if (link->conf.Attributes & CONF_ENABLE_IRQ)
- printk(", irq %u", link->irq.AssignedIRQ);
+ printk(", irq %u", link->irq.AssignedIRQ);
if (link->io.NumPorts1)
- printk(", io 0x%04x-0x%04x", link->io.BasePort1,
+ printk(", io 0x%04x-0x%04x", link->io.BasePort1,
link->io.BasePort1+link->io.NumPorts1-1);
if (link->io.NumPorts2)
- printk(" & 0x%04x-0x%04x", link->io.BasePort2,
+ printk(" & 0x%04x-0x%04x", link->io.BasePort2,
link->io.BasePort2+link->io.NumPorts2-1);
printk("\n");
- link->state &= ~DEV_CONFIG_PENDING;
return;
cs_failed:
- cs_error(link->handle, last_fn, last_ret);
- das08_pcmcia_release((u_long)link);
+ cs_error(link, last_fn, last_ret);
+ das08_pcmcia_release(link);
} /* das08_pcmcia_config */
======================================================================*/
-static void das08_pcmcia_release(u_long arg)
+static void das08_pcmcia_release(struct pcmcia_device *link)
{
- dev_link_t *link = (dev_link_t *)arg;
-
DEBUG(0, "das08_pcmcia_release(0x%p)\n", link);
-
- /* Unlink the device chain */
- link->dev = NULL;
-
- /*
- In a normal driver, additional code may be needed to release
- other kernel data structures associated with this device.
- */
-
- /* Don't bother checking to see if these succeed or not */
- pcmcia_release_configuration(link->handle);
- if (link->io.NumPorts1)
- pcmcia_release_io(link->handle, &link->io);
- if (link->irq.AssignedIRQ)
- pcmcia_release_irq(link->handle, &link->irq);
- link->state &= ~DEV_CONFIG;
-
+ pcmcia_disable_device(link);
} /* das08_pcmcia_release */
/*======================================================================
======================================================================*/
-static int das08_pcmcia_suspend(struct pcmcia_device *p_dev)
+static int das08_pcmcia_suspend(struct pcmcia_device *link)
{
- dev_link_t *link = dev_to_instance(p_dev);
local_info_t *local = link->priv;
-
- link->state |= DEV_SUSPEND;
/* Mark the device as stopped, to block IO until later */
local->stop = 1;
- if (link->state & DEV_CONFIG)
- pcmcia_release_configuration(link->handle);
return 0;
} /* das08_pcmcia_suspend */
-static int das08_pcmcia_resume(struct pcmcia_device *p_dev)
+static int das08_pcmcia_resume(struct pcmcia_device *link)
{
- dev_link_t *link = dev_to_instance(p_dev);
local_info_t *local = link->priv;
-
- link->state &= ~DEV_SUSPEND;
- if (link->state & DEV_CONFIG)
- pcmcia_request_configuration(link->handle, &link->conf);
+
local->stop = 0;
return 0;
} /* das08_pcmcia_resume */
{
DEBUG(0, "das08_pcmcia_cs: unloading\n");
pcmcia_unregister_driver(&das08_cs_driver);
- while (dev_list != NULL)
- {
- if (dev_list->state & DEV_CONFIG)
- das08_pcmcia_release((u_long)dev_list);
- das08_pcmcia_detach(dev_list->handle);
- }
}
static int __init das08_cs_init_module(void)