Skip to content

Commit fb49fa5

Browse files
author
Dominik Brodowski
committed
pcmcia: split up modify_configuration() into two fixup functions
pcmcia_modify_configuration() was only used by two drivers to fix up one issue each: setting the Vpp to a different value, and reducing the IO width to 8 bit. Introduce two explicitly named functions handling these things, and remove one further typedef. CC: netdev@vger.kernel.org CC: linux-mtd@lists.infradead.org Tested-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
1 parent cdb1380 commit fb49fa5

5 files changed

Lines changed: 68 additions & 90 deletions

File tree

‎drivers/mtd/maps/pcmciamtd.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,9 @@ static void pcmciamtd_set_vpp(struct map_info *map, int on)
316316
{
317317
struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1;
318318
struct pcmcia_device *link = dev->p_dev;
319-
modconf_t mod;
320-
int ret;
321-
322-
mod.Attributes = CONF_VPP1_CHANGE_VALID | CONF_VPP2_CHANGE_VALID;
323-
mod.Vcc = 0;
324-
mod.Vpp1 = mod.Vpp2 = on ? dev->vpp : 0;
325319

326320
DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp);
327-
ret = pcmcia_modify_configuration(link, &mod);
321+
pcmcia_fixup_vpp(link, on ? dev->vpp : 0);
328322
}
329323

330324

‎drivers/net/pcmcia/smc91c92_cs.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -816,13 +816,10 @@ static int check_sig(struct pcmcia_device *link)
816816
}
817817

818818
if (width) {
819-
modconf_t mod = {
820-
.Attributes = CONF_IO_CHANGE_WIDTH,
821-
};
822819
printk(KERN_INFO "smc91c92_cs: using 8-bit IO window.\n");
823820

824821
smc91c92_suspend(link);
825-
pcmcia_modify_configuration(link, &mod);
822+
pcmcia_fixup_iowidth(link);
826823
smc91c92_resume(link);
827824
return check_sig(link);
828825
}

‎drivers/pcmcia/pcmcia_resource.c‎

Lines changed: 63 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -226,92 +226,90 @@ int pcmcia_map_mem_page(struct pcmcia_device *p_dev, struct resource *res,
226226
EXPORT_SYMBOL(pcmcia_map_mem_page);
227227

228228

229-
/** pcmcia_modify_configuration
229+
/**
230+
* pcmcia_fixup_iowidth() - reduce io width to 8bit
230231
*
231-
* Modify a locked socket configuration
232+
* pcmcia_fixup_iowidth() allows a PCMCIA device driver to reduce the
233+
* IO width to 8bit after having called pcmcia_request_configuration()
234+
* previously.
232235
*/
233-
int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
234-
modconf_t *mod)
236+
int pcmcia_fixup_iowidth(struct pcmcia_device *p_dev)
235237
{
236-
struct pcmcia_socket *s;
237-
config_t *c;
238-
int ret;
239-
240-
s = p_dev->socket;
238+
struct pcmcia_socket *s = p_dev->socket;
239+
pccard_io_map io_off = { 0, 0, 0, 0, 1 };
240+
pccard_io_map io_on;
241+
int i, ret = 0;
241242

242243
mutex_lock(&s->ops_mutex);
243-
c = p_dev->function_config;
244244

245-
if (!(s->state & SOCKET_PRESENT)) {
246-
dev_dbg(&p_dev->dev, "No card present\n");
247-
ret = -ENODEV;
248-
goto unlock;
249-
}
250-
if (!(c->state & CONFIG_LOCKED)) {
251-
dev_dbg(&p_dev->dev, "Configuration isnt't locked\n");
245+
dev_dbg(&p_dev->dev, "fixup iowidth to 8bit\n");
246+
247+
if (!(s->state & SOCKET_PRESENT) ||
248+
!(p_dev->function_config->state & CONFIG_LOCKED)) {
249+
dev_dbg(&p_dev->dev, "No card? Config not locked?\n");
252250
ret = -EACCES;
253251
goto unlock;
254252
}
255253

256-
if (mod->Attributes & (CONF_IRQ_CHANGE_VALID | CONF_VCC_CHANGE_VALID)) {
257-
dev_dbg(&p_dev->dev,
258-
"changing Vcc or IRQ is not allowed at this time\n");
259-
ret = -EINVAL;
260-
goto unlock;
261-
}
254+
io_on.speed = io_speed;
255+
for (i = 0; i < MAX_IO_WIN; i++) {
256+
if (!s->io[i].res)
257+
continue;
258+
io_off.map = i;
259+
io_on.map = i;
262260

263-
/* We only allow changing Vpp1 and Vpp2 to the same value */
264-
if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) &&
265-
(mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
266-
if (mod->Vpp1 != mod->Vpp2) {
267-
dev_dbg(&p_dev->dev,
268-
"Vpp1 and Vpp2 must be the same\n");
269-
ret = -EINVAL;
270-
goto unlock;
271-
}
272-
s->socket.Vpp = mod->Vpp1;
273-
if (s->ops->set_socket(s, &s->socket)) {
274-
dev_printk(KERN_WARNING, &p_dev->dev,
275-
"Unable to set VPP\n");
276-
ret = -EIO;
277-
goto unlock;
278-
}
279-
} else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
280-
(mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
281-
dev_dbg(&p_dev->dev,
282-
"changing Vcc is not allowed at this time\n");
283-
ret = -EINVAL;
284-
goto unlock;
261+
io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8;
262+
io_on.start = s->io[i].res->start;
263+
io_on.stop = s->io[i].res->end;
264+
265+
s->ops->set_io_map(s, &io_off);
266+
mdelay(40);
267+
s->ops->set_io_map(s, &io_on);
285268
}
269+
unlock:
270+
mutex_unlock(&s->ops_mutex);
286271

287-
if (mod->Attributes & CONF_IO_CHANGE_WIDTH) {
288-
pccard_io_map io_off = { 0, 0, 0, 0, 1 };
289-
pccard_io_map io_on;
290-
int i;
272+
return ret;
273+
}
274+
EXPORT_SYMBOL(pcmcia_fixup_iowidth);
291275

292-
io_on.speed = io_speed;
293-
for (i = 0; i < MAX_IO_WIN; i++) {
294-
if (!s->io[i].res)
295-
continue;
296-
io_off.map = i;
297-
io_on.map = i;
298276

299-
io_on.flags = MAP_ACTIVE | IO_DATA_PATH_WIDTH_8;
300-
io_on.start = s->io[i].res->start;
301-
io_on.stop = s->io[i].res->end;
277+
/**
278+
* pcmcia_fixup_vpp() - set Vpp to a new voltage level
279+
*
280+
* pcmcia_fixup_vpp() allows a PCMCIA device driver to set Vpp to
281+
* a new voltage level between calls to pcmcia_request_configuration()
282+
* and pcmcia_disable_device().
283+
*/
284+
int pcmcia_fixup_vpp(struct pcmcia_device *p_dev, unsigned char new_vpp)
285+
{
286+
struct pcmcia_socket *s = p_dev->socket;
287+
int ret = 0;
302288

303-
s->ops->set_io_map(s, &io_off);
304-
mdelay(40);
305-
s->ops->set_io_map(s, &io_on);
306-
}
289+
mutex_lock(&s->ops_mutex);
290+
291+
dev_dbg(&p_dev->dev, "fixup Vpp to %d\n", new_vpp);
292+
293+
if (!(s->state & SOCKET_PRESENT) ||
294+
!(p_dev->function_config->state & CONFIG_LOCKED)) {
295+
dev_dbg(&p_dev->dev, "No card? Config not locked?\n");
296+
ret = -EACCES;
297+
goto unlock;
307298
}
308-
ret = 0;
299+
300+
s->socket.Vpp = new_vpp;
301+
if (s->ops->set_socket(s, &s->socket)) {
302+
dev_warn(&p_dev->dev, "Unable to set VPP\n");
303+
ret = -EIO;
304+
goto unlock;
305+
}
306+
309307
unlock:
310308
mutex_unlock(&s->ops_mutex);
311309

312310
return ret;
313-
} /* modify_configuration */
314-
EXPORT_SYMBOL(pcmcia_modify_configuration);
311+
}
312+
EXPORT_SYMBOL(pcmcia_fixup_vpp);
315313

316314

317315
int pcmcia_release_configuration(struct pcmcia_device *p_dev)

‎include/pcmcia/cs.h‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@
1919
#include <linux/interrupt.h>
2020
#endif
2121

22-
/* ModifyConfiguration */
23-
typedef struct modconf_t {
24-
u_int Attributes;
25-
u_int Vcc, Vpp1, Vpp2;
26-
} modconf_t;
27-
28-
/* Attributes for ModifyConfiguration */
29-
#define CONF_IRQ_CHANGE_VALID 0x0100
30-
#define CONF_VCC_CHANGE_VALID 0x0200
31-
#define CONF_VPP1_CHANGE_VALID 0x0400
32-
#define CONF_VPP2_CHANGE_VALID 0x0800
33-
#define CONF_IO_CHANGE_WIDTH 0x1000
34-
3522
/* For RequestConfiguration */
3623
typedef struct config_req_t {
3724
u_int Attributes;

‎include/pcmcia/ds.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ int pcmcia_release_window(struct pcmcia_device *p_dev, struct resource *res);
212212
int pcmcia_map_mem_page(struct pcmcia_device *p_dev, struct resource *res,
213213
unsigned int offset);
214214

215-
int pcmcia_modify_configuration(struct pcmcia_device *p_dev, modconf_t *mod);
215+
int pcmcia_fixup_vpp(struct pcmcia_device *p_dev, unsigned char new_vpp);
216+
int pcmcia_fixup_iowidth(struct pcmcia_device *p_dev);
217+
216218
void pcmcia_disable_device(struct pcmcia_device *p_dev);
217219

218220
/* IO ports */

0 commit comments

Comments
 (0)