Merge HEAD from master.kernel.org:/home/rmk/linux-2.6-mmc.git

+112 -22
+13 -16
drivers/mmc/mmc.c
··· 361 361 362 362 default: 363 363 printk("%s: card has unknown MMCA version %d\n", 364 - card->host->host_name, card->csd.mmca_vsn); 364 + mmc_hostname(card->host), card->csd.mmca_vsn); 365 365 mmc_card_set_bad(card); 366 366 break; 367 367 } ··· 383 383 csd_struct = UNSTUFF_BITS(resp, 126, 2); 384 384 if (csd_struct != 1 && csd_struct != 2) { 385 385 printk("%s: unrecognised CSD structure version %d\n", 386 - card->host->host_name, csd_struct); 386 + mmc_hostname(card->host), csd_struct); 387 387 mmc_card_set_bad(card); 388 388 return; 389 389 } ··· 551 551 } 552 552 if (err != MMC_ERR_NONE) { 553 553 printk(KERN_ERR "%s: error requesting CID: %d\n", 554 - host->host_name, err); 554 + mmc_hostname(host), err); 555 555 break; 556 556 } 557 557 ··· 796 796 { 797 797 struct mmc_host *host; 798 798 799 - host = kmalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL); 799 + host = mmc_alloc_host_sysfs(extra, dev); 800 800 if (host) { 801 - memset(host, 0, sizeof(struct mmc_host) + extra); 802 - 803 801 spin_lock_init(&host->lock); 804 802 init_waitqueue_head(&host->wq); 805 803 INIT_LIST_HEAD(&host->cards); 806 804 INIT_WORK(&host->detect, mmc_rescan, host); 807 - 808 - host->dev = dev; 809 805 810 806 /* 811 807 * By default, hosts do not support SGIO or large requests. ··· 824 828 */ 825 829 int mmc_add_host(struct mmc_host *host) 826 830 { 827 - static unsigned int host_num; 831 + int ret; 828 832 829 - snprintf(host->host_name, sizeof(host->host_name), 830 - "mmc%d", host_num++); 833 + ret = mmc_add_host_sysfs(host); 834 + if (ret == 0) { 835 + mmc_power_off(host); 836 + mmc_detect_change(host); 837 + } 831 838 832 - mmc_power_off(host); 833 - mmc_detect_change(host); 834 - 835 - return 0; 839 + return ret; 836 840 } 837 841 838 842 EXPORT_SYMBOL(mmc_add_host); ··· 855 859 } 856 860 857 861 mmc_power_off(host); 862 + mmc_remove_host_sysfs(host); 858 863 } 859 864 860 865 EXPORT_SYMBOL(mmc_remove_host); ··· 869 872 void mmc_free_host(struct mmc_host *host) 870 873 { 871 874 flush_scheduled_work(); 872 - kfree(host); 875 + mmc_free_host_sysfs(host); 873 876 } 874 877 875 878 EXPORT_SYMBOL(mmc_free_host);
+5
drivers/mmc/mmc.h
··· 13 13 void mmc_init_card(struct mmc_card *card, struct mmc_host *host); 14 14 int mmc_register_card(struct mmc_card *card); 15 15 void mmc_remove_card(struct mmc_card *card); 16 + 17 + struct mmc_host *mmc_alloc_host_sysfs(int extra, struct device *dev); 18 + int mmc_add_host_sysfs(struct mmc_host *host); 19 + void mmc_remove_host_sysfs(struct mmc_host *host); 20 + void mmc_free_host_sysfs(struct mmc_host *host); 16 21 #endif
+88 -2
drivers/mmc/mmc_sysfs.c
··· 12 12 #include <linux/module.h> 13 13 #include <linux/init.h> 14 14 #include <linux/device.h> 15 + #include <linux/idr.h> 15 16 16 17 #include <linux/mmc/card.h> 17 18 #include <linux/mmc/host.h> ··· 21 20 22 21 #define dev_to_mmc_card(d) container_of(d, struct mmc_card, dev) 23 22 #define to_mmc_driver(d) container_of(d, struct mmc_driver, drv) 23 + #define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev) 24 24 25 25 #define MMC_ATTR(name, fmt, args...) \ 26 26 static ssize_t mmc_##name##_show (struct device *dev, struct device_attribute *attr, char *buf) \ ··· 208 206 int mmc_register_card(struct mmc_card *card) 209 207 { 210 208 snprintf(card->dev.bus_id, sizeof(card->dev.bus_id), 211 - "%s:%04x", card->host->host_name, card->rca); 209 + "%s:%04x", mmc_hostname(card->host), card->rca); 212 210 213 211 return device_add(&card->dev); 214 212 } ··· 226 224 } 227 225 228 226 227 + static void mmc_host_classdev_release(struct class_device *dev) 228 + { 229 + struct mmc_host *host = cls_dev_to_mmc_host(dev); 230 + kfree(host); 231 + } 232 + 233 + static struct class mmc_host_class = { 234 + .name = "mmc_host", 235 + .release = mmc_host_classdev_release, 236 + }; 237 + 238 + static DEFINE_IDR(mmc_host_idr); 239 + static DEFINE_SPINLOCK(mmc_host_lock); 240 + 241 + /* 242 + * Internal function. Allocate a new MMC host. 243 + */ 244 + struct mmc_host *mmc_alloc_host_sysfs(int extra, struct device *dev) 245 + { 246 + struct mmc_host *host; 247 + 248 + host = kmalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL); 249 + if (host) { 250 + memset(host, 0, sizeof(struct mmc_host) + extra); 251 + 252 + host->dev = dev; 253 + host->class_dev.dev = host->dev; 254 + host->class_dev.class = &mmc_host_class; 255 + class_device_initialize(&host->class_dev); 256 + } 257 + 258 + return host; 259 + } 260 + 261 + /* 262 + * Internal function. Register a new MMC host with the MMC class. 263 + */ 264 + int mmc_add_host_sysfs(struct mmc_host *host) 265 + { 266 + int err; 267 + 268 + if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL)) 269 + return -ENOMEM; 270 + 271 + spin_lock(&mmc_host_lock); 272 + err = idr_get_new(&mmc_host_idr, host, &host->index); 273 + spin_unlock(&mmc_host_lock); 274 + if (err) 275 + return err; 276 + 277 + snprintf(host->class_dev.class_id, BUS_ID_SIZE, 278 + "mmc%d", host->index); 279 + 280 + return class_device_add(&host->class_dev); 281 + } 282 + 283 + /* 284 + * Internal function. Unregister a MMC host with the MMC class. 285 + */ 286 + void mmc_remove_host_sysfs(struct mmc_host *host) 287 + { 288 + class_device_del(&host->class_dev); 289 + 290 + spin_lock(&mmc_host_lock); 291 + idr_remove(&mmc_host_idr, host->index); 292 + spin_unlock(&mmc_host_lock); 293 + } 294 + 295 + /* 296 + * Internal function. Free a MMC host. 297 + */ 298 + void mmc_free_host_sysfs(struct mmc_host *host) 299 + { 300 + class_device_put(&host->class_dev); 301 + } 302 + 303 + 229 304 static int __init mmc_init(void) 230 305 { 231 - return bus_register(&mmc_bus_type); 306 + int ret = bus_register(&mmc_bus_type); 307 + if (ret == 0) { 308 + ret = class_register(&mmc_host_class); 309 + if (ret) 310 + bus_unregister(&mmc_bus_type); 311 + } 312 + return ret; 232 313 } 233 314 234 315 static void __exit mmc_exit(void) 235 316 { 317 + class_unregister(&mmc_host_class); 236 318 bus_unregister(&mmc_bus_type); 237 319 } 238 320
+2 -2
drivers/mmc/mmci.c
··· 34 34 35 35 #ifdef CONFIG_MMC_DEBUG 36 36 #define DBG(host,fmt,args...) \ 37 - pr_debug("%s: %s: " fmt, host->mmc->host_name, __func__ , args) 37 + pr_debug("%s: %s: " fmt, mmc_hostname(host->mmc), __func__ , args) 38 38 #else 39 39 #define DBG(host,fmt,args...) do { } while (0) 40 40 #endif ··· 541 541 mmc_add_host(mmc); 542 542 543 543 printk(KERN_INFO "%s: MMCI rev %x cfg %02x at 0x%08lx irq %d,%d\n", 544 - mmc->host_name, amba_rev(dev), amba_config(dev), 544 + mmc_hostname(mmc), amba_rev(dev), amba_config(dev), 545 545 dev->res.start, dev->irq[0], dev->irq[1]); 546 546 547 547 init_timer(&host->timer);
+1 -1
drivers/mmc/wbsd.c
··· 1796 1796 1797 1797 mmc_add_host(mmc); 1798 1798 1799 - printk(KERN_INFO "%s: W83L51xD", mmc->host_name); 1799 + printk(KERN_INFO "%s: W83L51xD", mmc_hostname(mmc)); 1800 1800 if (host->chip_id != 0) 1801 1801 printk(" id %x", (int)host->chip_id); 1802 1802 printk(" at 0x%x irq %d", (int)host->base, (int)host->irq);
+3 -1
include/linux/mmc/host.h
··· 63 63 64 64 struct mmc_host { 65 65 struct device *dev; 66 + struct class_device class_dev; 67 + int index; 66 68 struct mmc_host_ops *ops; 67 69 unsigned int f_min; 68 70 unsigned int f_max; 69 71 u32 ocr_avail; 70 - char host_name[8]; 71 72 72 73 /* host specific block data */ 73 74 unsigned int max_seg_size; /* see blk_queue_max_segment_size */ ··· 98 97 99 98 #define mmc_priv(x) ((void *)((x) + 1)) 100 99 #define mmc_dev(x) ((x)->dev) 100 + #define mmc_hostname(x) ((x)->class_dev.class_id) 101 101 102 102 extern int mmc_suspend_host(struct mmc_host *, pm_message_t); 103 103 extern int mmc_resume_host(struct mmc_host *);