aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorPierre Ossman <drzeus-list@drzeus.cx>2008-03-21 18:54:50 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-03-22 20:02:20 -0400
commit51ec92e295d563dd5712d198a7e46c2ae5ccccb2 (patch)
treefa45408fad483e89b29900b8ca5adf4bb3164467 /drivers
parent03c086a747d0b242878eb881971ec61c1555869d (diff)
mmc: use sysfs groups to handle conditional attributes
Suppressing uevents turned out to be a bad idea as it screws up the order of events, making user space very confused. Change the system to use sysfs groups instead. This is a regression that, for some odd reason, has gone unnoticed for some time. It confuses hal so that the block devices (which have the mmc device as a parent) are not registered. End result being that desktop magic when cards are inserted won't work. Signed-off-by: Pierre Ossman <drzeus@drzeus.cx> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mmc/core/Makefile2
-rw-r--r--drivers/mmc/core/bus.c23
-rw-r--r--drivers/mmc/core/bus.h11
-rw-r--r--drivers/mmc/core/core.h2
-rw-r--r--drivers/mmc/core/mmc.c90
-rw-r--r--drivers/mmc/core/sd.c95
-rw-r--r--drivers/mmc/core/sdio.c2
-rw-r--r--drivers/mmc/core/sysfs.c43
-rw-r--r--drivers/mmc/core/sysfs.h26
9 files changed, 96 insertions, 198 deletions
diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile
index 4985807257a8..19a1a254a0c5 100644
--- a/drivers/mmc/core/Makefile
+++ b/drivers/mmc/core/Makefile
@@ -7,7 +7,7 @@ ifeq ($(CONFIG_MMC_DEBUG),y)
7endif 7endif
8 8
9obj-$(CONFIG_MMC) += mmc_core.o 9obj-$(CONFIG_MMC) += mmc_core.o
10mmc_core-y := core.o sysfs.o bus.o host.o \ 10mmc_core-y := core.o bus.o host.o \
11 mmc.o mmc_ops.o sd.o sd_ops.o \ 11 mmc.o mmc_ops.o sd.o sd_ops.o \
12 sdio.o sdio_ops.o sdio_bus.o \ 12 sdio.o sdio_ops.o sdio_bus.o \
13 sdio_cis.o sdio_io.o sdio_irq.o 13 sdio_cis.o sdio_io.o sdio_irq.o
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index b0c22cad9423..fd95b18e988b 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -17,7 +17,6 @@
17#include <linux/mmc/card.h> 17#include <linux/mmc/card.h>
18#include <linux/mmc/host.h> 18#include <linux/mmc/host.h>
19 19
20#include "sysfs.h"
21#include "core.h" 20#include "core.h"
22#include "sdio_cis.h" 21#include "sdio_cis.h"
23#include "bus.h" 22#include "bus.h"
@@ -43,7 +42,7 @@ static ssize_t mmc_type_show(struct device *dev,
43} 42}
44 43
45static struct device_attribute mmc_dev_attrs[] = { 44static struct device_attribute mmc_dev_attrs[] = {
46 MMC_ATTR_RO(type), 45 __ATTR(type, S_IRUGO, mmc_type_show, NULL),
47 __ATTR_NULL, 46 __ATTR_NULL,
48}; 47};
49 48
@@ -189,7 +188,7 @@ static void mmc_release_card(struct device *dev)
189/* 188/*
190 * Allocate and initialise a new MMC card structure. 189 * Allocate and initialise a new MMC card structure.
191 */ 190 */
192struct mmc_card *mmc_alloc_card(struct mmc_host *host) 191struct mmc_card *mmc_alloc_card(struct mmc_host *host, struct device_type *type)
193{ 192{
194 struct mmc_card *card; 193 struct mmc_card *card;
195 194
@@ -204,6 +203,7 @@ struct mmc_card *mmc_alloc_card(struct mmc_host *host)
204 card->dev.parent = mmc_classdev(host); 203 card->dev.parent = mmc_classdev(host);
205 card->dev.bus = &mmc_bus_type; 204 card->dev.bus = &mmc_bus_type;
206 card->dev.release = mmc_release_card; 205 card->dev.release = mmc_release_card;
206 card->dev.type = type;
207 207
208 return card; 208 return card;
209} 209}
@@ -248,24 +248,10 @@ int mmc_add_card(struct mmc_card *card)
248 type, card->rca); 248 type, card->rca);
249 } 249 }
250 250
251 card->dev.uevent_suppress = 1;
252
253 ret = device_add(&card->dev); 251 ret = device_add(&card->dev);
254 if (ret) 252 if (ret)
255 return ret; 253 return ret;
256 254
257 if (card->host->bus_ops->sysfs_add) {
258 ret = card->host->bus_ops->sysfs_add(card->host, card);
259 if (ret) {
260 device_del(&card->dev);
261 return ret;
262 }
263 }
264
265 card->dev.uevent_suppress = 0;
266
267 kobject_uevent(&card->dev.kobj, KOBJ_ADD);
268
269 mmc_card_set_present(card); 255 mmc_card_set_present(card);
270 256
271 return 0; 257 return 0;
@@ -285,9 +271,6 @@ void mmc_remove_card(struct mmc_card *card)
285 printk(KERN_INFO "%s: card %04x removed\n", 271 printk(KERN_INFO "%s: card %04x removed\n",
286 mmc_hostname(card->host), card->rca); 272 mmc_hostname(card->host), card->rca);
287 } 273 }
288
289 if (card->host->bus_ops->sysfs_remove)
290 card->host->bus_ops->sysfs_remove(card->host, card);
291 device_del(&card->dev); 274 device_del(&card->dev);
292 } 275 }
293 276
diff --git a/drivers/mmc/core/bus.h b/drivers/mmc/core/bus.h
index 4f35431116a8..18178766ab46 100644
--- a/drivers/mmc/core/bus.h
+++ b/drivers/mmc/core/bus.h
@@ -11,7 +11,16 @@
11#ifndef _MMC_CORE_BUS_H 11#ifndef _MMC_CORE_BUS_H
12#define _MMC_CORE_BUS_H 12#define _MMC_CORE_BUS_H
13 13
14struct mmc_card *mmc_alloc_card(struct mmc_host *host); 14#define MMC_DEV_ATTR(name, fmt, args...) \
15static ssize_t mmc_##name##_show (struct device *dev, struct device_attribute *attr, char *buf) \
16{ \
17 struct mmc_card *card = container_of(dev, struct mmc_card, dev); \
18 return sprintf(buf, fmt, args); \
19} \
20static DEVICE_ATTR(name, S_IRUGO, mmc_##name##_show, NULL)
21
22struct mmc_card *mmc_alloc_card(struct mmc_host *host,
23 struct device_type *type);
15int mmc_add_card(struct mmc_card *card); 24int mmc_add_card(struct mmc_card *card);
16void mmc_remove_card(struct mmc_card *card); 25void mmc_remove_card(struct mmc_card *card);
17 26
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index 39daf2fb5dc4..cfa8e15b5923 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -18,8 +18,6 @@
18struct mmc_bus_ops { 18struct mmc_bus_ops {
19 void (*remove)(struct mmc_host *); 19 void (*remove)(struct mmc_host *);
20 void (*detect)(struct mmc_host *); 20 void (*detect)(struct mmc_host *);
21 int (*sysfs_add)(struct mmc_host *, struct mmc_card *card);
22 void (*sysfs_remove)(struct mmc_host *, struct mmc_card *card);
23 void (*suspend)(struct mmc_host *); 21 void (*suspend)(struct mmc_host *);
24 void (*resume)(struct mmc_host *); 22 void (*resume)(struct mmc_host *);
25}; 23};
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 68c0e3b2f0e8..3da29eef8f7d 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -17,7 +17,6 @@
17#include <linux/mmc/mmc.h> 17#include <linux/mmc/mmc.h>
18 18
19#include "core.h" 19#include "core.h"
20#include "sysfs.h"
21#include "bus.h" 20#include "bus.h"
22#include "mmc_ops.h" 21#include "mmc_ops.h"
23 22
@@ -248,6 +247,44 @@ out:
248 return err; 247 return err;
249} 248}
250 249
250MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
251 card->raw_cid[2], card->raw_cid[3]);
252MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
253 card->raw_csd[2], card->raw_csd[3]);
254MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
255MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev);
256MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
257MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
258MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
259MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
260MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
261
262static struct attribute *mmc_std_attrs[] = {
263 &dev_attr_cid.attr,
264 &dev_attr_csd.attr,
265 &dev_attr_date.attr,
266 &dev_attr_fwrev.attr,
267 &dev_attr_hwrev.attr,
268 &dev_attr_manfid.attr,
269 &dev_attr_name.attr,
270 &dev_attr_oemid.attr,
271 &dev_attr_serial.attr,
272 NULL,
273};
274
275static struct attribute_group mmc_std_attr_group = {
276 .attrs = mmc_std_attrs,
277};
278
279static struct attribute_group *mmc_attr_groups[] = {
280 &mmc_std_attr_group,
281 NULL,
282};
283
284static struct device_type mmc_type = {
285 .groups = mmc_attr_groups,
286};
287
251/* 288/*
252 * Handle the detection and initialisation of a card. 289 * Handle the detection and initialisation of a card.
253 * 290 *
@@ -308,7 +345,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
308 /* 345 /*
309 * Allocate card structure. 346 * Allocate card structure.
310 */ 347 */
311 card = mmc_alloc_card(host); 348 card = mmc_alloc_card(host, &mmc_type);
312 if (IS_ERR(card)) { 349 if (IS_ERR(card)) {
313 err = PTR_ERR(card); 350 err = PTR_ERR(card);
314 goto err; 351 goto err;
@@ -459,53 +496,6 @@ static void mmc_detect(struct mmc_host *host)
459 } 496 }
460} 497}
461 498
462MMC_ATTR_FN(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
463 card->raw_cid[2], card->raw_cid[3]);
464MMC_ATTR_FN(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
465 card->raw_csd[2], card->raw_csd[3]);
466MMC_ATTR_FN(date, "%02d/%04d\n", card->cid.month, card->cid.year);
467MMC_ATTR_FN(fwrev, "0x%x\n", card->cid.fwrev);
468MMC_ATTR_FN(hwrev, "0x%x\n", card->cid.hwrev);
469MMC_ATTR_FN(manfid, "0x%06x\n", card->cid.manfid);
470MMC_ATTR_FN(name, "%s\n", card->cid.prod_name);
471MMC_ATTR_FN(oemid, "0x%04x\n", card->cid.oemid);
472MMC_ATTR_FN(serial, "0x%08x\n", card->cid.serial);
473
474static struct device_attribute mmc_dev_attrs[] = {
475 MMC_ATTR_RO(cid),
476 MMC_ATTR_RO(csd),
477 MMC_ATTR_RO(date),
478 MMC_ATTR_RO(fwrev),
479 MMC_ATTR_RO(hwrev),
480 MMC_ATTR_RO(manfid),
481 MMC_ATTR_RO(name),
482 MMC_ATTR_RO(oemid),
483 MMC_ATTR_RO(serial),
484 __ATTR_NULL,
485};
486
487/*
488 * Adds sysfs entries as relevant.
489 */
490static int mmc_sysfs_add(struct mmc_host *host, struct mmc_card *card)
491{
492 int ret;
493
494 ret = mmc_add_attrs(card, mmc_dev_attrs);
495 if (ret < 0)
496 return ret;
497
498 return 0;
499}
500
501/*
502 * Removes the sysfs entries added by mmc_sysfs_add().
503 */
504static void mmc_sysfs_remove(struct mmc_host *host, struct mmc_card *card)
505{
506 mmc_remove_attrs(card, mmc_dev_attrs);
507}
508
509#ifdef CONFIG_MMC_UNSAFE_RESUME 499#ifdef CONFIG_MMC_UNSAFE_RESUME
510 500
511/* 501/*
@@ -560,8 +550,6 @@ static void mmc_resume(struct mmc_host *host)
560static const struct mmc_bus_ops mmc_ops = { 550static const struct mmc_bus_ops mmc_ops = {
561 .remove = mmc_remove, 551 .remove = mmc_remove,
562 .detect = mmc_detect, 552 .detect = mmc_detect,
563 .sysfs_add = mmc_sysfs_add,
564 .sysfs_remove = mmc_sysfs_remove,
565 .suspend = mmc_suspend, 553 .suspend = mmc_suspend,
566 .resume = mmc_resume, 554 .resume = mmc_resume,
567}; 555};
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index d1c1e0f592f1..7ef3b15c5e3d 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -18,7 +18,6 @@
18#include <linux/mmc/sd.h> 18#include <linux/mmc/sd.h>
19 19
20#include "core.h" 20#include "core.h"
21#include "sysfs.h"
22#include "bus.h" 21#include "bus.h"
23#include "mmc_ops.h" 22#include "mmc_ops.h"
24#include "sd_ops.h" 23#include "sd_ops.h"
@@ -283,6 +282,47 @@ out:
283 return err; 282 return err;
284} 283}
285 284
285MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
286 card->raw_cid[2], card->raw_cid[3]);
287MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
288 card->raw_csd[2], card->raw_csd[3]);
289MMC_DEV_ATTR(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]);
290MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
291MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev);
292MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
293MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
294MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
295MMC_DEV_ATTR(oemid, "0x%04x\n", card->cid.oemid);
296MMC_DEV_ATTR(serial, "0x%08x\n", card->cid.serial);
297
298
299static struct attribute *sd_std_attrs[] = {
300 &dev_attr_cid.attr,
301 &dev_attr_csd.attr,
302 &dev_attr_scr.attr,
303 &dev_attr_date.attr,
304 &dev_attr_fwrev.attr,
305 &dev_attr_hwrev.attr,
306 &dev_attr_manfid.attr,
307 &dev_attr_name.attr,
308 &dev_attr_oemid.attr,
309 &dev_attr_serial.attr,
310 NULL,
311};
312
313static struct attribute_group sd_std_attr_group = {
314 .attrs = sd_std_attrs,
315};
316
317static struct attribute_group *sd_attr_groups[] = {
318 &sd_std_attr_group,
319 NULL,
320};
321
322static struct device_type sd_type = {
323 .groups = sd_attr_groups,
324};
325
286/* 326/*
287 * Handle the detection and initialisation of a card. 327 * Handle the detection and initialisation of a card.
288 * 328 *
@@ -352,7 +392,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
352 /* 392 /*
353 * Allocate card structure. 393 * Allocate card structure.
354 */ 394 */
355 card = mmc_alloc_card(host); 395 card = mmc_alloc_card(host, &sd_type);
356 if (IS_ERR(card)) { 396 if (IS_ERR(card)) {
357 err = PTR_ERR(card); 397 err = PTR_ERR(card);
358 goto err; 398 goto err;
@@ -518,55 +558,6 @@ static void mmc_sd_detect(struct mmc_host *host)
518 } 558 }
519} 559}
520 560
521MMC_ATTR_FN(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
522 card->raw_cid[2], card->raw_cid[3]);
523MMC_ATTR_FN(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
524 card->raw_csd[2], card->raw_csd[3]);
525MMC_ATTR_FN(scr, "%08x%08x\n", card->raw_scr[0], card->raw_scr[1]);
526MMC_ATTR_FN(date, "%02d/%04d\n", card->cid.month, card->cid.year);
527MMC_ATTR_FN(fwrev, "0x%x\n", card->cid.fwrev);
528MMC_ATTR_FN(hwrev, "0x%x\n", card->cid.hwrev);
529MMC_ATTR_FN(manfid, "0x%06x\n", card->cid.manfid);
530MMC_ATTR_FN(name, "%s\n", card->cid.prod_name);
531MMC_ATTR_FN(oemid, "0x%04x\n", card->cid.oemid);
532MMC_ATTR_FN(serial, "0x%08x\n", card->cid.serial);
533
534static struct device_attribute mmc_sd_dev_attrs[] = {
535 MMC_ATTR_RO(cid),
536 MMC_ATTR_RO(csd),
537 MMC_ATTR_RO(scr),
538 MMC_ATTR_RO(date),
539 MMC_ATTR_RO(fwrev),
540 MMC_ATTR_RO(hwrev),
541 MMC_ATTR_RO(manfid),
542 MMC_ATTR_RO(name),
543 MMC_ATTR_RO(oemid),
544 MMC_ATTR_RO(serial),
545 __ATTR_NULL,
546};
547
548/*
549 * Adds sysfs entries as relevant.
550 */
551static int mmc_sd_sysfs_add(struct mmc_host *host, struct mmc_card *card)
552{
553 int ret;
554
555 ret = mmc_add_attrs(card, mmc_sd_dev_attrs);
556 if (ret < 0)
557 return ret;
558
559 return 0;
560}
561
562/*
563 * Removes the sysfs entries added by mmc_sysfs_add().
564 */
565static void mmc_sd_sysfs_remove(struct mmc_host *host, struct mmc_card *card)
566{
567 mmc_remove_attrs(card, mmc_sd_dev_attrs);
568}
569
570#ifdef CONFIG_MMC_UNSAFE_RESUME 561#ifdef CONFIG_MMC_UNSAFE_RESUME
571 562
572/* 563/*
@@ -621,8 +612,6 @@ static void mmc_sd_resume(struct mmc_host *host)
621static const struct mmc_bus_ops mmc_sd_ops = { 612static const struct mmc_bus_ops mmc_sd_ops = {
622 .remove = mmc_sd_remove, 613 .remove = mmc_sd_remove,
623 .detect = mmc_sd_detect, 614 .detect = mmc_sd_detect,
624 .sysfs_add = mmc_sd_sysfs_add,
625 .sysfs_remove = mmc_sd_sysfs_remove,
626 .suspend = mmc_sd_suspend, 615 .suspend = mmc_sd_suspend,
627 .resume = mmc_sd_resume, 616 .resume = mmc_sd_resume,
628}; 617};
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index 87a50f456efc..4eab79e09ccc 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -287,7 +287,7 @@ int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
287 /* 287 /*
288 * Allocate card structure. 288 * Allocate card structure.
289 */ 289 */
290 card = mmc_alloc_card(host); 290 card = mmc_alloc_card(host, NULL);
291 if (IS_ERR(card)) { 291 if (IS_ERR(card)) {
292 err = PTR_ERR(card); 292 err = PTR_ERR(card);
293 goto err; 293 goto err;
diff --git a/drivers/mmc/core/sysfs.c b/drivers/mmc/core/sysfs.c
deleted file mode 100644
index 00a97e70f914..000000000000
--- a/drivers/mmc/core/sysfs.c
+++ /dev/null
@@ -1,43 +0,0 @@
1/*
2 * linux/drivers/mmc/core/sysfs.c
3 *
4 * Copyright (C) 2003 Russell King, All Rights Reserved.
5 * Copyright 2007 Pierre Ossman
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * MMC sysfs/driver model support.
12 */
13#include <linux/device.h>
14
15#include <linux/mmc/card.h>
16
17#include "sysfs.h"
18
19int mmc_add_attrs(struct mmc_card *card, struct device_attribute *attrs)
20{
21 int error = 0;
22 int i;
23
24 for (i = 0; attr_name(attrs[i]); i++) {
25 error = device_create_file(&card->dev, &attrs[i]);
26 if (error) {
27 while (--i >= 0)
28 device_remove_file(&card->dev, &attrs[i]);
29 break;
30 }
31 }
32
33 return error;
34}
35
36void mmc_remove_attrs(struct mmc_card *card, struct device_attribute *attrs)
37{
38 int i;
39
40 for (i = 0; attr_name(attrs[i]); i++)
41 device_remove_file(&card->dev, &attrs[i]);
42}
43
diff --git a/drivers/mmc/core/sysfs.h b/drivers/mmc/core/sysfs.h
deleted file mode 100644
index 4b8f670bd10f..000000000000
--- a/drivers/mmc/core/sysfs.h
+++ /dev/null
@@ -1,26 +0,0 @@
1/*
2 * linux/drivers/mmc/core/sysfs.h
3 *
4 * Copyright (C) 2003 Russell King, All Rights Reserved.
5 * Copyright 2007 Pierre Ossman
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#ifndef _MMC_CORE_SYSFS_H
12#define _MMC_CORE_SYSFS_H
13
14#define MMC_ATTR_FN(name, fmt, args...) \
15static ssize_t mmc_##name##_show (struct device *dev, struct device_attribute *attr, char *buf) \
16{ \
17 struct mmc_card *card = container_of(dev, struct mmc_card, dev);\
18 return sprintf(buf, fmt, args); \
19}
20
21#define MMC_ATTR_RO(name) __ATTR(name, S_IRUGO, mmc_##name##_show, NULL)
22
23int mmc_add_attrs(struct mmc_card *card, struct device_attribute *attrs);
24void mmc_remove_attrs(struct mmc_card *card, struct device_attribute *attrs);
25
26#endif