19 #include <linux/slab.h>
20 #include <linux/module.h>
22 #define DRIVER_NAME "memstick"
24 static unsigned int cmd_retries = 3;
35 if ((id->
type == card->
id.type)
37 && (id->
class == card->
id.class))
55 if (memstick_dev_match(card, ids))
80 static int memstick_device_probe(
struct device *dev)
90 rc = drv->
probe(card);
97 static int memstick_device_remove(
struct device *dev)
125 return drv->
suspend(card, state);
144 #define memstick_device_suspend NULL
145 #define memstick_device_resume NULL
149 #define MEMSTICK_ATTR(name, format) \
150 static ssize_t name##_show(struct device *dev, struct device_attribute *attr, \
153 struct memstick_dev *card = container_of(dev, struct memstick_dev, \
155 return sprintf(buf, format, card->id.name); \
162 #define MEMSTICK_ATTR_RO(name) __ATTR(name, S_IRUGO, name##_show, NULL)
171 static struct bus_type memstick_bus_type = {
173 .dev_attrs = memstick_dev_attrs,
174 .match = memstick_bus_match,
175 .uevent = memstick_uevent,
176 .probe = memstick_device_probe,
177 .remove = memstick_device_remove,
182 static void memstick_free(
struct device *dev)
189 static struct class memstick_host_class = {
190 .name =
"memstick_host",
191 .dev_release = memstick_free
194 static void memstick_free_card(
struct device *dev)
201 static int memstick_dummy_check(
struct memstick_dev *card)
230 if ((*mrq) && (*mrq)->error && host->
retries) {
236 if (host->
card && host->
card->next_request)
237 rc = host->
card->next_request(host->
card, mrq);
240 host->
retries = cmd_retries > 1 ? cmd_retries - 1 : 1;
327 static int h_memstick_read_dev_id(
struct memstick_dev *card,
338 if (!(*mrq)->error) {
339 memcpy(&id_reg, (*mrq)->data,
sizeof(id_reg));
341 card->
id.type = id_reg.type;
342 card->
id.category = id_reg.category;
343 card->
id.class = id_reg.class;
344 dev_dbg(&card->
dev,
"if_mode = %02x\n", id_reg.if_mode);
351 static int h_memstick_set_rw_addr(
struct memstick_dev *card,
391 card->
dev.parent = &host->
dev;
392 card->
dev.bus = &memstick_bus_type;
393 card->
dev.release = memstick_free_card;
394 card->
check = memstick_dummy_check;
397 card->
reg_addr.r_length =
sizeof(id_reg);
399 card->
reg_addr.w_length =
sizeof(id_reg);
414 host->
card = old_card;
417 host->
card = old_card;
438 dev_dbg(&host->
dev,
"memstick_check started\n");
441 if (memstick_power_on(host))
443 }
else if (host->
card->stop)
446 card = memstick_alloc_card(host);
454 dev_dbg(&host->
dev,
"new card %02x, %02x, %02x\n",
455 card->
id.type, card->
id.category, card->
id.class);
458 || !memstick_dev_match(host->
card, &card->
id)
459 || !(host->
card->check(host->
card))) {
462 }
else if (host->
card->start)
482 dev_dbg(&host->
dev,
"memstick_check finished\n");
499 host->
dev.class = &memstick_host_class;
519 spin_lock(&memstick_host_lock);
521 spin_unlock(&memstick_host_lock);
532 spin_lock(&memstick_host_lock);
534 spin_unlock(&memstick_host_lock);
558 spin_lock(&memstick_host_lock);
560 spin_unlock(&memstick_host_lock);
598 rc = memstick_power_on(host);
608 drv->
driver.bus = &memstick_bus_type;
621 static int __init memstick_init(
void)
642 static void __exit memstick_exit(
void)