Skip to content

Commit 00990e7

Browse files
author
Dominik Brodowski
committed
pcmcia: use autoconfiguration feature for ioports and iomem
When CONF_AUTO_SET_IO or CONF_AUTO_SET_IOMEM are set, the corresponding fields in struct pcmcia_device *p_dev->resource[0,1,2] are set accordinly. Drivers wishing to override certain settings may do so in the callback function, but they no longer need to parse the CIS entries stored in cistpl_cftable_entry_t themselves. CC: netdev@vger.kernel.org CC: linux-wireless@vger.kernel.org CC: linux-ide@vger.kernel.org CC: linux-usb@vger.kernel.org CC: laforge@gnumonks.org CC: linux-mtd@lists.infradead.org CC: linux-bluetooth@vger.kernel.org CC: alsa-devel@alsa-project.org CC: linux-serial@vger.kernel.org CC: Jiri Kosina <jkosina@suse.cz> CC: linux-scsi@vger.kernel.org Tested-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
1 parent 440eed4 commit 00990e7

44 files changed

Lines changed: 515 additions & 1025 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/pcmcia/driver-changes.txt‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
This file details changes in 2.6 which affect PCMCIA card driver authors:
2+
* pcmcia_loop_config() and autoconfiguration (as of 2.6.36)
3+
If struct pcmcia_device *p_dev->config_flags is set accordingly,
4+
pcmcia_loop_config() now sets up certain configuration values
5+
automatically, though the driver may still override the settings
6+
in the callback function. The following autoconfiguration options
7+
are provided at the moment:
8+
CONF_AUTO_CHECK_VCC : check for matching Vcc
9+
CONF_AUTO_SET_VPP : set Vpp
10+
CONF_AUTO_AUDIO : auto-enable audio line, if required
11+
CONF_AUTO_SET_IO : set ioport resources (->resource[0,1])
12+
CONF_AUTO_SET_IOMEM : set first iomem resource (->resource[2])
13+
214
* pcmcia_request_configuration -> pcmcia_enable_device (as of 2.6.36)
315
pcmcia_request_configuration() got renamed to pcmcia_enable_device(),
416
as it mirrors pcmcia_disable_device(). Configuration settings are now

‎drivers/ata/pata_pcmcia.c‎

Lines changed: 26 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -167,45 +167,26 @@ static struct ata_port_operations pcmcia_8bit_port_ops = {
167167
};
168168

169169

170-
struct pcmcia_config_check {
171-
unsigned long ctl_base;
172-
int is_kme;
173-
};
174-
175-
static int pcmcia_check_one_config(struct pcmcia_device *pdev,
176-
cistpl_cftable_entry_t *cfg,
177-
cistpl_cftable_entry_t *dflt,
178-
void *priv_data)
170+
static int pcmcia_check_one_config(struct pcmcia_device *pdev, void *priv_data)
179171
{
180-
struct pcmcia_config_check *stk = priv_data;
181-
182-
if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
183-
cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
184-
pdev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
185-
pdev->resource[0]->start = io->win[0].base;
186-
if (!(io->flags & CISTPL_IO_16BIT)) {
187-
pdev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
188-
pdev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
189-
}
190-
if (io->nwin == 2) {
191-
pdev->resource[0]->end = 8;
192-
pdev->resource[1]->start = io->win[1].base;
193-
pdev->resource[1]->end = (stk->is_kme) ? 2 : 1;
194-
if (pcmcia_request_io(pdev) != 0)
195-
return -ENODEV;
196-
stk->ctl_base = pdev->resource[1]->start;
197-
} else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
198-
pdev->resource[0]->end = io->win[0].len;
199-
pdev->resource[1]->end = 0;
200-
if (pcmcia_request_io(pdev) != 0)
201-
return -ENODEV;
202-
stk->ctl_base = pdev->resource[0]->start + 0x0e;
203-
} else
172+
int *is_kme = priv_data;
173+
174+
if (!(pdev->resource[0]->flags & IO_DATA_PATH_WIDTH_8)) {
175+
pdev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
176+
pdev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
177+
}
178+
pdev->resource[1]->flags &= ~IO_DATA_PATH_WIDTH;
179+
pdev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
180+
181+
if (pdev->resource[1]->end) {
182+
pdev->resource[0]->end = 8;
183+
pdev->resource[1]->end = (*is_kme) ? 2 : 1;
184+
} else {
185+
if (pdev->resource[0]->end < 16)
204186
return -ENODEV;
205-
/* If we've got this far, we're done */
206-
return 0;
207187
}
208-
return -ENODEV;
188+
189+
return pcmcia_request_io(pdev);
209190
}
210191

211192
/**
@@ -220,40 +201,33 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
220201
{
221202
struct ata_host *host;
222203
struct ata_port *ap;
223-
struct pcmcia_config_check *stk = NULL;
224204
int is_kme = 0, ret = -ENOMEM, p;
225205
unsigned long io_base, ctl_base;
226206
void __iomem *io_addr, *ctl_addr;
227207
int n_ports = 1;
228208
struct ata_port_operations *ops = &pcmcia_port_ops;
229209

230210
/* Set up attributes in order to probe card and get resources */
231-
pdev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
232-
pdev->resource[1]->flags |= IO_DATA_PATH_WIDTH_8;
233-
pdev->config_flags |= CONF_ENABLE_IRQ;
234-
pdev->config_flags |= CONF_AUTO_SET_VPP | CONF_AUTO_CHECK_VCC;
211+
pdev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO |
212+
CONF_AUTO_SET_VPP | CONF_AUTO_CHECK_VCC;
235213

236214
/* See if we have a manufacturer identifier. Use it to set is_kme for
237215
vendor quirks */
238216
is_kme = ((pdev->manf_id == MANFID_KME) &&
239217
((pdev->card_id == PRODID_KME_KXLC005_A) ||
240218
(pdev->card_id == PRODID_KME_KXLC005_B)));
241219

242-
/* Allocate resoure probing structures */
243-
244-
stk = kzalloc(sizeof(*stk), GFP_KERNEL);
245-
if (!stk)
246-
goto out1;
247-
stk->is_kme = is_kme;
248-
io_base = ctl_base = 0;
249-
250-
if (pcmcia_loop_config(pdev, pcmcia_check_one_config, stk)) {
220+
if (pcmcia_loop_config(pdev, pcmcia_check_one_config, &is_kme)) {
251221
pdev->config_flags &= ~CONF_AUTO_CHECK_VCC;
252-
if (pcmcia_loop_config(pdev, pcmcia_check_one_config, stk))
222+
if (pcmcia_loop_config(pdev, pcmcia_check_one_config, &is_kme))
253223
goto failed; /* No suitable config found */
254224
}
255225
io_base = pdev->resource[0]->start;
256-
ctl_base = stk->ctl_base;
226+
if (pdev->resource[1]->end)
227+
ctl_base = pdev->resource[1]->start;
228+
else
229+
ctl_base = pdev->resource[0]->start + 0x0e;
230+
257231
if (!pdev->irq)
258232
goto failed;
259233

@@ -310,13 +284,10 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
310284
goto failed;
311285

312286
pdev->priv = host;
313-
kfree(stk);
314287
return 0;
315288

316289
failed:
317-
kfree(stk);
318290
pcmcia_disable_device(pdev);
319-
out1:
320291
return ret;
321292
}
322293

‎drivers/bluetooth/bt3c_cs.c‎

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,8 @@ static int bt3c_probe(struct pcmcia_device *link)
656656
info->p_dev = link;
657657
link->priv = info;
658658

659-
link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
660-
link->resource[0]->end = 8;
661-
662-
link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP;
659+
link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
660+
CONF_AUTO_SET_IO;
663661

664662
return bt3c_config(link);
665663
}
@@ -673,38 +671,41 @@ static void bt3c_detach(struct pcmcia_device *link)
673671
kfree(info);
674672
}
675673

676-
static int bt3c_check_config(struct pcmcia_device *p_dev,
677-
cistpl_cftable_entry_t *cf,
678-
cistpl_cftable_entry_t *dflt,
679-
void *priv_data)
674+
static int bt3c_check_config(struct pcmcia_device *p_dev, void *priv_data)
680675
{
681-
unsigned long try = (unsigned long) priv_data;
682-
p_dev->io_lines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
676+
int *try = priv_data;
683677

684-
if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) &&
685-
(cf->io.win[0].base != 0)) {
686-
p_dev->resource[0]->start = cf->io.win[0].base;
687-
if (!pcmcia_request_io(p_dev))
688-
return 0;
689-
}
690-
return -ENODEV;
678+
if (try == 0)
679+
p_dev->io_lines = 16;
680+
681+
if ((p_dev->resource[0]->end != 8) || (p_dev->resource[0]->start == 0))
682+
return -EINVAL;
683+
684+
p_dev->resource[0]->end = 8;
685+
p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
686+
p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
687+
688+
return pcmcia_request_io(p_dev);
691689
}
692690

693691
static int bt3c_check_config_notpicky(struct pcmcia_device *p_dev,
694-
cistpl_cftable_entry_t *cf,
695-
cistpl_cftable_entry_t *dflt,
696692
void *priv_data)
697693
{
698694
static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
699695
int j;
700696

701-
if ((cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
702-
for (j = 0; j < 5; j++) {
703-
p_dev->resource[0]->start = base[j];
704-
p_dev->io_lines = base[j] ? 16 : 3;
705-
if (!pcmcia_request_io(p_dev))
706-
return 0;
707-
}
697+
if (p_dev->io_lines > 3)
698+
return -ENODEV;
699+
700+
p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
701+
p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
702+
p_dev->resource[0]->end = 8;
703+
704+
for (j = 0; j < 5; j++) {
705+
p_dev->resource[0]->start = base[j];
706+
p_dev->io_lines = base[j] ? 16 : 3;
707+
if (!pcmcia_request_io(p_dev))
708+
return 0;
708709
}
709710
return -ENODEV;
710711
}

‎drivers/bluetooth/btuart_cs.c‎

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,8 @@ static int btuart_probe(struct pcmcia_device *link)
585585
info->p_dev = link;
586586
link->priv = info;
587587

588-
link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
589-
link->resource[0]->end = 8;
590-
591-
link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP;
588+
link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
589+
CONF_AUTO_SET_IO;
592590

593591
return btuart_config(link);
594592
}
@@ -602,38 +600,41 @@ static void btuart_detach(struct pcmcia_device *link)
602600
kfree(info);
603601
}
604602

605-
static int btuart_check_config(struct pcmcia_device *p_dev,
606-
cistpl_cftable_entry_t *cf,
607-
cistpl_cftable_entry_t *dflt,
608-
void *priv_data)
603+
static int btuart_check_config(struct pcmcia_device *p_dev, void *priv_data)
609604
{
610605
int *try = priv_data;
611-
p_dev->io_lines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
612606

613-
if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) &&
614-
(cf->io.win[0].base != 0)) {
615-
p_dev->resource[0]->start = cf->io.win[0].base;
616-
if (!pcmcia_request_io(p_dev))
617-
return 0;
618-
}
619-
return -ENODEV;
607+
if (try == 0)
608+
p_dev->io_lines = 16;
609+
610+
if ((p_dev->resource[0]->end != 8) || (p_dev->resource[0]->start == 0))
611+
return -EINVAL;
612+
613+
p_dev->resource[0]->end = 8;
614+
p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
615+
p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
616+
617+
return pcmcia_request_io(p_dev);
620618
}
621619

622620
static int btuart_check_config_notpicky(struct pcmcia_device *p_dev,
623-
cistpl_cftable_entry_t *cf,
624-
cistpl_cftable_entry_t *dflt,
625621
void *priv_data)
626622
{
627623
static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
628624
int j;
629625

630-
if ((cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
631-
for (j = 0; j < 5; j++) {
632-
p_dev->resource[0]->start = base[j];
633-
p_dev->io_lines = base[j] ? 16 : 3;
634-
if (!pcmcia_request_io(p_dev))
635-
return 0;
636-
}
626+
if (p_dev->io_lines > 3)
627+
return -ENODEV;
628+
629+
p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
630+
p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
631+
p_dev->resource[0]->end = 8;
632+
633+
for (j = 0; j < 5; j++) {
634+
p_dev->resource[0]->start = base[j];
635+
p_dev->io_lines = base[j] ? 16 : 3;
636+
if (!pcmcia_request_io(p_dev))
637+
return 0;
637638
}
638639
return -ENODEV;
639640
}

‎drivers/bluetooth/dtl1_cs.c‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -571,10 +571,7 @@ static int dtl1_probe(struct pcmcia_device *link)
571571
info->p_dev = link;
572572
link->priv = info;
573573

574-
link->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
575-
link->resource[0]->end = 8;
576-
577-
link->config_flags |= CONF_ENABLE_IRQ;
574+
link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
578575

579576
return dtl1_config(link);
580577
}
@@ -589,17 +586,14 @@ static void dtl1_detach(struct pcmcia_device *link)
589586
kfree(info);
590587
}
591588

592-
static int dtl1_confcheck(struct pcmcia_device *p_dev,
593-
cistpl_cftable_entry_t *cf,
594-
cistpl_cftable_entry_t *dflt,
595-
void *priv_data)
589+
static int dtl1_confcheck(struct pcmcia_device *p_dev, void *priv_data)
596590
{
597-
if ((cf->io.nwin != 1) || (cf->io.win[0].len <= 8))
591+
if ((p_dev->resource[1]->end) || (p_dev->resource[1]->end < 8))
598592
return -ENODEV;
599593

600-
p_dev->resource[0]->start = cf->io.win[0].base;
601-
p_dev->resource[0]->end = cf->io.win[0].len; /*yo */
602-
p_dev->io_lines = cf->io.flags & CISTPL_IO_LINES_MASK;
594+
p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
595+
p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
596+
603597
return pcmcia_request_io(p_dev);
604598
}
605599

‎drivers/char/pcmcia/cm4000_cs.c‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,26 +1741,17 @@ static void cmm_cm4000_release(struct pcmcia_device * link)
17411741

17421742
/*==== Interface to PCMCIA Layer =======================================*/
17431743

1744-
static int cm4000_config_check(struct pcmcia_device *p_dev,
1745-
cistpl_cftable_entry_t *cfg,
1746-
cistpl_cftable_entry_t *dflt,
1747-
void *priv_data)
1744+
static int cm4000_config_check(struct pcmcia_device *p_dev, void *priv_data)
17481745
{
1749-
if (!cfg->io.nwin)
1750-
return -ENODEV;
1751-
1752-
p_dev->resource[0]->start = cfg->io.win[0].base;
1753-
p_dev->resource[0]->end = cfg->io.win[0].len;
1754-
p_dev->resource[0]->flags |= pcmcia_io_cfg_data_width(cfg->io.flags);
1755-
p_dev->io_lines = cfg->io.flags & CISTPL_IO_LINES_MASK;
1756-
17571746
return pcmcia_request_io(p_dev);
17581747
}
17591748

17601749
static int cm4000_config(struct pcmcia_device * link, int devno)
17611750
{
17621751
struct cm4000_dev *dev;
17631752

1753+
link->config_flags |= CONF_AUTO_SET_IO;
1754+
17641755
/* read the config-tuples */
17651756
if (pcmcia_loop_config(link, cm4000_config_check, NULL))
17661757
goto cs_release;

‎drivers/char/pcmcia/cm4040_cs.c‎

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -515,25 +515,9 @@ static void cm4040_reader_release(struct pcmcia_device *link)
515515
return;
516516
}
517517

518-
static int cm4040_config_check(struct pcmcia_device *p_dev,
519-
cistpl_cftable_entry_t *cfg,
520-
cistpl_cftable_entry_t *dflt,
521-
void *priv_data)
518+
static int cm4040_config_check(struct pcmcia_device *p_dev, void *priv_data)
522519
{
523-
int rc;
524-
if (!cfg->io.nwin)
525-
return -ENODEV;
526-
527-
/* Get the IOaddr */
528-
p_dev->resource[0]->start = cfg->io.win[0].base;
529-
p_dev->resource[0]->end = cfg->io.win[0].len;
530-
p_dev->resource[0]->flags |= pcmcia_io_cfg_data_width(cfg->io.flags);
531-
p_dev->io_lines = cfg->io.flags & CISTPL_IO_LINES_MASK;
532-
rc = pcmcia_request_io(p_dev);
533-
534-
dev_printk(KERN_INFO, &p_dev->dev,
535-
"pcmcia_request_io returned 0x%x\n", rc);
536-
return rc;
520+
return pcmcia_request_io(p_dev);
537521
}
538522

539523

@@ -542,6 +526,8 @@ static int reader_config(struct pcmcia_device *link, int devno)
542526
struct reader_dev *dev;
543527
int fail_rc;
544528

529+
link->config_flags |= CONF_AUTO_SET_IO;
530+
545531
if (pcmcia_loop_config(link, cm4040_config_check, NULL))
546532
goto cs_release;
547533

0 commit comments

Comments
 (0)