Skip to content

Commit

Permalink
pcmcia: pcmcia_config_loop() default CIS entry handling
Browse files Browse the repository at this point in the history
Many drivers use the default CIS entry within their pcmcia_config_loop()
callback function. Therefore, factor the default CIS entry handling out.

Signed-off-by: Dominik Brodowski <[email protected]>
  • Loading branch information
Dominik Brodowski committed Aug 22, 2008
1 parent 498ac18 commit 8e2fc39
Show file tree
Hide file tree
Showing 32 changed files with 158 additions and 165 deletions.
33 changes: 15 additions & 18 deletions drivers/ata/pata_pcmcia.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,36 +151,38 @@ do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)

struct pcmcia_config_check {
config_info_t conf;
cistpl_cftable_entry_t dflt;
unsigned long ctl_base;
int skip_vcc;
int is_kme;
};

static int pcmcia_check_one_config(struct pcmcia_device *pdev,
cistpl_cftable_entry_t *cfg,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
struct pcmcia_config_check *stk = priv_data;

/* Check for matching Vcc, unless we're desperate */
if (!stk->skip_vcc) {
if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
if (stk->conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
goto next_entry;
} else if (stk->dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
if (stk->conf.Vcc != stk->dflt.vcc.param[CISTPL_POWER_VNOM] / 10000)
goto next_entry;
if (stk->conf.Vcc !=
cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
return -ENODEV;
} else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
if (stk->conf.Vcc !=
dflt->vcc.param[CISTPL_POWER_VNOM] / 10000)
return -ENODEV;
}
}

if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
pdev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
else if (stk->dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
pdev->conf.Vpp = stk->dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
pdev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;

if ((cfg->io.nwin > 0) || (stk->dflt.io.nwin > 0)) {
cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &stk->dflt.io;
if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
pdev->io.BasePort1 = io->win[0].base;
pdev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
if (!(io->flags & CISTPL_IO_16BIT))
Expand All @@ -190,23 +192,19 @@ static int pcmcia_check_one_config(struct pcmcia_device *pdev,
pdev->io.BasePort2 = io->win[1].base;
pdev->io.NumPorts2 = (stk->is_kme) ? 2 : 1;
if (pcmcia_request_io(pdev, &pdev->io) != 0)
goto next_entry;
return -ENODEV;
stk->ctl_base = pdev->io.BasePort2;
} else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
pdev->io.NumPorts1 = io->win[0].len;
pdev->io.NumPorts2 = 0;
if (pcmcia_request_io(pdev, &pdev->io) != 0)
goto next_entry;
return -ENODEV;
stk->ctl_base = pdev->io.BasePort1 + 0x0e;
} else
goto next_entry;
return -ENODEV;
/* If we've got this far, we're done */
return 0;
}
next_entry:
if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
memcpy(&stk->dflt, cfg, sizeof(stk->dflt));

return -ENODEV;
}

Expand Down Expand Up @@ -264,7 +262,6 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(pdev, &stk->conf));
stk->skip_vcc = io_base = ctl_base = 0;
if (pcmcia_loop_config(pdev, pcmcia_check_one_config, stk)) {
memset(&stk->dflt, 0, sizeof(stk->dflt));
stk->skip_vcc = 1;
if (pcmcia_loop_config(pdev, pcmcia_check_one_config, stk))
goto failed; /* No suitable config found */
Expand Down
2 changes: 2 additions & 0 deletions drivers/bluetooth/bt3c_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ static void bt3c_detach(struct pcmcia_device *link)

static int bt3c_check_config(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cf,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
unsigned long try = (unsigned long) priv_data;
Expand All @@ -699,6 +700,7 @@ static int bt3c_check_config(struct pcmcia_device *p_dev,

static int bt3c_check_config_notpicky(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cf,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
Expand Down
2 changes: 2 additions & 0 deletions drivers/bluetooth/btuart_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ static void btuart_detach(struct pcmcia_device *link)

static int btuart_check_config(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cf,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
unsigned long try = (unsigned long) priv_data;
Expand All @@ -628,6 +629,7 @@ static int btuart_check_config(struct pcmcia_device *p_dev,

static int btuart_check_config_notpicky(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cf,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
Expand Down
1 change: 1 addition & 0 deletions drivers/bluetooth/dtl1_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ static void dtl1_detach(struct pcmcia_device *link)

static int dtl1_confcheck(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cf,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
if ((cf->io.nwin == 1) && (cf->io.win[0].len > 8)) {
Expand Down
1 change: 1 addition & 0 deletions drivers/char/pcmcia/cm4000_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,7 @@ static void cmm_cm4000_release(struct pcmcia_device * link)

static int cm4000_config_check(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cfg,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
if (!cfg->io.nwin)
Expand Down
1 change: 1 addition & 0 deletions drivers/char/pcmcia/cm4040_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ static void cm4040_reader_release(struct pcmcia_device *link)

static int cm4040_config_check(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cfg,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
int rc;
Expand Down
33 changes: 15 additions & 18 deletions drivers/ide/legacy/ide-cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,36 +222,38 @@ do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)

struct pcmcia_config_check {
config_info_t conf;
cistpl_cftable_entry_t dflt;
unsigned long ctl_base;
int skip_vcc;
int is_kme;
};

static int pcmcia_check_one_config(struct pcmcia_device *pdev,
cistpl_cftable_entry_t *cfg,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
struct pcmcia_config_check *stk = priv_data;

/* Check for matching Vcc, unless we're desperate */
if (!stk->skip_vcc) {
if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
if (stk->conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
goto next_entry;
} else if (stk->dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
if (stk->conf.Vcc != stk->dflt.vcc.param[CISTPL_POWER_VNOM] / 10000)
goto next_entry;
if (stk->conf.Vcc !=
cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
return -ENODEV;
} else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
if (stk->conf.Vcc !=
dflt->vcc.param[CISTPL_POWER_VNOM] / 10000)
return -ENODEV;
}
}

if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
pdev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
else if (stk->dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
pdev->conf.Vpp = stk->dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
pdev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;

if ((cfg->io.nwin > 0) || (stk->dflt.io.nwin > 0)) {
cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &stk->dflt.io;
if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
pdev->conf.ConfigIndex = cfg->index;
pdev->io.BasePort1 = io->win[0].base;
pdev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
Expand All @@ -262,23 +264,19 @@ static int pcmcia_check_one_config(struct pcmcia_device *pdev,
pdev->io.BasePort2 = io->win[1].base;
pdev->io.NumPorts2 = (stk->is_kme) ? 2 : 1;
if (pcmcia_request_io(pdev, &pdev->io) != 0)
goto next_entry;
return -ENODEV;
stk->ctl_base = pdev->io.BasePort2;
} else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
pdev->io.NumPorts1 = io->win[0].len;
pdev->io.NumPorts2 = 0;
if (pcmcia_request_io(pdev, &pdev->io) != 0)
goto next_entry;
return -ENODEV;
stk->ctl_base = pdev->io.BasePort1 + 0x0e;
} else
goto next_entry;
return -ENODEV;
/* If we've got this far, we're done */
return 0;
}
next_entry:
if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
memcpy(&stk->dflt, cfg, sizeof(stk->dflt));

return -ENODEV;
}

Expand All @@ -305,7 +303,6 @@ static int ide_config(struct pcmcia_device *link)
CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &stk->conf));
stk->skip_vcc = io_base = ctl_base = 0;
if (pcmcia_loop_config(link, pcmcia_check_one_config, stk)) {
memset(&stk->dflt, 0, sizeof(stk->dflt));
stk->skip_vcc = 1;
if (pcmcia_loop_config(link, pcmcia_check_one_config, stk))
goto failed; /* No suitable config found */
Expand Down
1 change: 1 addition & 0 deletions drivers/isdn/hardware/avm/avm_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ static void avmcs_detach(struct pcmcia_device *link)

static int avmcs_configcheck(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cf,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
if (cf->io.nwin <= 0)
Expand Down
5 changes: 3 additions & 2 deletions drivers/isdn/hisax/avma1_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ static void avma1cs_detach(struct pcmcia_device *link)
======================================================================*/

static int avma1cs_configcheck(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cf,
void *priv_data)
cistpl_cftable_entry_t *cf,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
if (cf->io.nwin <= 0)
return -ENODEV;
Expand Down
1 change: 1 addition & 0 deletions drivers/isdn/hisax/elsa_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ static void elsa_cs_detach(struct pcmcia_device *link)

static int elsa_cs_configcheck(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cf,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
int j;
Expand Down
26 changes: 13 additions & 13 deletions drivers/isdn/hisax/sedlbauer_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,17 @@ static void sedlbauer_detach(struct pcmcia_device *link)
do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)

struct sedlbauer_config_data {
cistpl_cftable_entry_t dflt;
config_info_t conf;
win_req_t req;
};

static int sedlbauer_config_check(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cfg,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
struct sedlbauer_config_data *cfg_mem = priv_data;

if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
cfg_mem->dflt = *cfg;
if (cfg->index == 0)
return -ENODEV;

Expand All @@ -243,26 +241,28 @@ static int sedlbauer_config_check(struct pcmcia_device *p_dev,
/* 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 (cfg_mem->conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000)
if (cfg_mem->conf.Vcc !=
cfg->vcc.param[CISTPL_POWER_VNOM]/10000)
return -ENODEV;
} else if (cfg_mem->dflt.vcc.present & (1<<CISTPL_POWER_VNOM)) {
if (cfg_mem->conf.Vcc != cfg_mem->dflt.vcc.param[CISTPL_POWER_VNOM]/10000)
} else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
if (cfg_mem->conf.Vcc !=
dflt->vcc.param[CISTPL_POWER_VNOM]/10000)
return -ENODEV;
}

if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
else if (cfg_mem->dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
p_dev->conf.Vpp = cfg_mem->dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;

/* Do we need to allocate an interrupt? */
if (cfg->irq.IRQInfo1 || cfg_mem->dflt.irq.IRQInfo1)
if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
p_dev->conf.Attributes |= CONF_ENABLE_IRQ;

/* IO window settings */
p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
if ((cfg->io.nwin > 0) || (cfg_mem->dflt.io.nwin > 0)) {
cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &cfg_mem->dflt.io;
if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
if (!(io->flags & CISTPL_IO_8BIT))
p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
Expand Down Expand Up @@ -291,8 +291,8 @@ static int sedlbauer_config_check(struct pcmcia_device *p_dev,
needs to be mapped to virtual space with ioremap() before it
is used.
*/
if ((cfg->mem.nwin > 0) || (cfg_mem->dflt.mem.nwin > 0)) {
cistpl_mem_t *mem = (cfg->mem.nwin) ? &cfg->mem : &cfg_mem->dflt.mem;
if ((cfg->mem.nwin > 0) || (dflt->mem.nwin > 0)) {
cistpl_mem_t *mem = (cfg->mem.nwin) ? &cfg->mem : &dflt->mem;
memreq_t map;
cfg_mem->req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
cfg_mem->req.Attributes |= WIN_ENABLE;
Expand Down
1 change: 1 addition & 0 deletions drivers/isdn/hisax/teles_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ static void teles_detach(struct pcmcia_device *link)

static int teles_cs_configcheck(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cf,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
int j;
Expand Down
1 change: 1 addition & 0 deletions drivers/net/pcmcia/axnet_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ static int try_io_port(struct pcmcia_device *link)

static int axnet_configcheck(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cfg,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
int i;
Expand Down
1 change: 1 addition & 0 deletions drivers/net/pcmcia/pcnet_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ static int try_io_port(struct pcmcia_device *link)

static int pcnet_confcheck(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cfg,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
int *has_shmem = priv_data;
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/pcmcia/smc91c92_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ static int mhz_3288_power(struct pcmcia_device *link)

static int mhz_mfc_config_check(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cf,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
int k;
Expand Down Expand Up @@ -651,6 +652,7 @@ static int mot_setup(struct pcmcia_device *link)

static int smc_configcheck(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cf,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
p_dev->io.BasePort1 = cf->io.win[0].base;
Expand Down
2 changes: 2 additions & 0 deletions drivers/net/pcmcia/xirc2ps_cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ has_ce2_string(struct pcmcia_device * p_dev)
static int
xirc2ps_config_modem(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cf,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
unsigned int ioaddr;
Expand All @@ -736,6 +737,7 @@ xirc2ps_config_modem(struct pcmcia_device *p_dev,
static int
xirc2ps_config_check(struct pcmcia_device *p_dev,
cistpl_cftable_entry_t *cf,
cistpl_cftable_entry_t *dflt,
void *priv_data)
{
int *pass = priv_data;
Expand Down
Loading

0 comments on commit 8e2fc39

Please sign in to comment.