2 * linux/drivers/mmc/core/sdio_bus.c
4 * Copyright 2007 Pierre Ossman
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
11 * SDIO function driver model
14 #include <linux/device.h>
15 #include <linux/err.h>
17 #include <linux/mmc/card.h>
18 #include <linux/mmc/sdio_func.h>
23 #define dev_to_sdio_func(d) container_of(d, struct sdio_func, dev)
26 * This currently matches any SDIO function to any driver in order
27 * to help initial development and testing.
29 static int sdio_bus_match(struct device *dev, struct device_driver *drv)
35 sdio_bus_uevent(struct device *dev, char **envp, int num_envp, char *buf,
43 static int sdio_bus_probe(struct device *dev)
48 static int sdio_bus_remove(struct device *dev)
53 static struct bus_type sdio_bus_type = {
55 .match = sdio_bus_match,
56 .uevent = sdio_bus_uevent,
57 .probe = sdio_bus_probe,
58 .remove = sdio_bus_remove,
61 int sdio_register_bus(void)
63 return bus_register(&sdio_bus_type);
66 void sdio_unregister_bus(void)
68 bus_unregister(&sdio_bus_type);
72 * sdio_register_driver - register a function driver
73 * @drv: SDIO function driver
75 int sdio_register_driver(struct sdio_driver *drv)
77 drv->drv.name = drv->name;
78 drv->drv.bus = &sdio_bus_type;
79 return driver_register(&drv->drv);
81 EXPORT_SYMBOL_GPL(sdio_register_driver);
84 * sdio_unregister_driver - unregister a function driver
85 * @drv: SDIO function driver
87 void sdio_unregister_driver(struct sdio_driver *drv)
89 drv->drv.bus = &sdio_bus_type;
90 driver_unregister(&drv->drv);
92 EXPORT_SYMBOL_GPL(sdio_unregister_driver);
94 static void sdio_release_func(struct device *dev)
96 struct sdio_func *func = dev_to_sdio_func(dev);
104 * Allocate and initialise a new SDIO function structure.
106 struct sdio_func *sdio_alloc_func(struct mmc_card *card)
108 struct sdio_func *func;
110 func = kmalloc(sizeof(struct sdio_func), GFP_KERNEL);
112 return ERR_PTR(-ENOMEM);
114 memset(func, 0, sizeof(struct sdio_func));
118 device_initialize(&func->dev);
120 func->dev.parent = &card->dev;
121 func->dev.bus = &sdio_bus_type;
122 func->dev.release = sdio_release_func;
128 * Register a new SDIO function with the driver model.
130 int sdio_add_func(struct sdio_func *func)
134 snprintf(func->dev.bus_id, sizeof(func->dev.bus_id),
135 "%s:%d", mmc_card_id(func->card), func->num);
137 ret = device_add(&func->dev);
139 sdio_func_set_present(func);
145 * Unregister a SDIO function with the driver model, and
146 * (eventually) free it.
148 void sdio_remove_func(struct sdio_func *func)
150 if (sdio_func_present(func))
151 device_del(&func->dev);
153 put_device(&func->dev);