17 #include <linux/slab.h>
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/netdevice.h>
87 int (*loop_tuple) (
tuple_t *tuple,
116 ret = loop_tuple(&tuple, parse, priv_data);
132 static int pcmcia_io_cfg_data_width(
unsigned int flags)
135 return IO_DATA_PATH_WIDTH_16;
137 return IO_DATA_PATH_WIDTH_8;
138 return IO_DATA_PATH_WIDTH_AUTO;
142 struct pcmcia_cfg_mem {
143 struct pcmcia_device *p_dev;
144 int (*conf_check) (
struct pcmcia_device *p_dev,
void *priv_data);
159 struct pcmcia_cfg_mem *cfg_mem =
priv;
160 struct pcmcia_device *p_dev = cfg_mem->p_dev;
163 unsigned int flags = p_dev->config_flags;
164 unsigned int vcc = p_dev->socket->socket.Vcc;
166 dev_dbg(&p_dev->dev,
"testing configuration %x, autoconf %x\n",
170 cfg_mem->p_dev->config_index = cfg->
index;
172 cfg_mem->dflt = *
cfg;
175 if (flags & CONF_AUTO_CHECK_VCC) {
186 if (flags & CONF_AUTO_SET_VPP) {
196 p_dev->config_flags |= CONF_ENABLE_SPKR;
200 if (flags & CONF_AUTO_SET_IO) {
204 p_dev->resource[0]->start = p_dev->resource[0]->end = 0;
205 p_dev->resource[1]->start = p_dev->resource[1]->end = 0;
209 p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
210 p_dev->resource[0]->flags |=
211 pcmcia_io_cfg_data_width(io->
flags);
216 i = (io->
win[1].len > io->
win[0].len);
217 p_dev->resource[1]->flags = p_dev->resource[0]->flags;
218 p_dev->resource[1]->start = io->
win[1-
i].base;
219 p_dev->resource[1]->end = io->
win[1-
i].len;
221 p_dev->resource[0]->start = io->
win[
i].base;
222 p_dev->resource[0]->end = io->
win[
i].len;
227 if (flags & CONF_AUTO_SET_IOMEM) {
231 p_dev->resource[2]->start = p_dev->resource[2]->end = 0;
235 p_dev->resource[2]->start = mem->
win[0].host_addr;
236 p_dev->resource[2]->end = mem->
win[0].len;
237 if (p_dev->resource[2]->end < 0x1000)
238 p_dev->resource[2]->end = 0x1000;
239 p_dev->card_addr = mem->
win[0].card_addr;
243 "checking configuration %x: %pr %pr %pr (%d lines)\n",
244 p_dev->config_index, p_dev->resource[0], p_dev->resource[1],
245 p_dev->resource[2], p_dev->io_lines);
247 return cfg_mem->conf_check(p_dev, cfg_mem->priv_data);
262 int pcmcia_loop_config(
struct pcmcia_device *p_dev,
263 int (*conf_check) (
struct pcmcia_device *p_dev,
267 struct pcmcia_cfg_mem *cfg_mem;
270 cfg_mem = kzalloc(
sizeof(
struct pcmcia_cfg_mem),
GFP_KERNEL);
274 cfg_mem->p_dev = p_dev;
275 cfg_mem->conf_check = conf_check;
276 cfg_mem->priv_data = priv_data;
280 cfg_mem, pcmcia_do_loop_config);
288 struct pcmcia_loop_mem {
289 struct pcmcia_device *p_dev;
291 int (*loop_tuple) (
struct pcmcia_device *p_dev,
305 struct pcmcia_loop_mem *loop =
priv;
307 return loop->loop_tuple(loop->p_dev, tuple, loop->priv_data);
322 int pcmcia_loop_tuple(
struct pcmcia_device *p_dev,
cisdata_t code,
323 int (*loop_tuple) (
struct pcmcia_device *p_dev,
328 struct pcmcia_loop_mem loop = {
330 .loop_tuple = loop_tuple,
331 .priv_data = priv_data};
334 &loop, pcmcia_do_loop_tuple);
339 struct pcmcia_loop_get {
353 static int pcmcia_do_get_tuple(
struct pcmcia_device *p_dev,
tuple_t *tuple,
356 struct pcmcia_loop_get *
get =
priv;
363 dev_dbg(&p_dev->dev,
"do_get_tuple: out of memory\n");
377 size_t pcmcia_get_tuple(
struct pcmcia_device *p_dev,
cisdata_t code,
380 struct pcmcia_loop_get
get = {
386 pcmcia_loop_tuple(p_dev, code, pcmcia_do_get_tuple, &
get);
401 static int pcmcia_do_get_mac(
struct pcmcia_device *p_dev,
tuple_t *tuple,
410 dev_warn(&p_dev->dev,
"Invalid CIS tuple length for "
416 dev_warn(&p_dev->dev,
"Invalid header for LAN_NODE_ID\n");
419 for (i = 0; i < 6; i++)
433 int pcmcia_get_mac_from_cis(
struct pcmcia_device *p_dev,
struct net_device *dev)
435 return pcmcia_loop_tuple(p_dev,
CISTPL_FUNCE, pcmcia_do_get_mac, dev);