4 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
6 * GPL v2, can be found in COPYING.
9 #include <linux/module.h>
12 MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
13 MODULE_LICENSE("GPL");
14 MODULE_DESCRIPTION("Apple Soundbus");
16 struct soundbus_dev
*soundbus_dev_get(struct soundbus_dev
*dev
)
22 tmp
= get_device(&dev
->ofdev
.dev
);
24 return to_soundbus_device(tmp
);
28 EXPORT_SYMBOL_GPL(soundbus_dev_get
);
30 void soundbus_dev_put(struct soundbus_dev
*dev
)
33 put_device(&dev
->ofdev
.dev
);
35 EXPORT_SYMBOL_GPL(soundbus_dev_put
);
37 static int soundbus_probe(struct device
*dev
)
40 struct soundbus_driver
*drv
;
41 struct soundbus_dev
*soundbus_dev
;
43 drv
= to_soundbus_driver(dev
->driver
);
44 soundbus_dev
= to_soundbus_device(dev
);
49 soundbus_dev_get(soundbus_dev
);
51 error
= drv
->probe(soundbus_dev
);
53 soundbus_dev_put(soundbus_dev
);
59 static int soundbus_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
61 struct soundbus_dev
* soundbus_dev
;
62 struct platform_device
* of
;
70 soundbus_dev
= to_soundbus_device(dev
);
74 of
= &soundbus_dev
->ofdev
;
76 /* stuff we want to pass to /sbin/hotplug */
77 retval
= add_uevent_var(env
, "OF_NAME=%s", of
->dev
.of_node
->name
);
81 retval
= add_uevent_var(env
, "OF_TYPE=%s", of
->dev
.of_node
->type
);
85 /* Since the compatible field can contain pretty much anything
86 * it's not really legal to split it out with commas. We split it
87 * up using a number of environment variables instead. */
89 compat
= of_get_property(of
->dev
.of_node
, "compatible", &cplen
);
90 while (compat
&& cplen
> 0) {
91 int tmp
= env
->buflen
;
92 retval
= add_uevent_var(env
, "OF_COMPATIBLE_%d=%s", seen
, compat
);
95 compat
+= env
->buflen
- tmp
;
96 cplen
-= env
->buflen
- tmp
;
100 retval
= add_uevent_var(env
, "OF_COMPATIBLE_N=%d", seen
);
103 retval
= add_uevent_var(env
, "MODALIAS=%s", soundbus_dev
->modalias
);
108 static int soundbus_device_remove(struct device
*dev
)
110 struct soundbus_dev
* soundbus_dev
= to_soundbus_device(dev
);
111 struct soundbus_driver
* drv
= to_soundbus_driver(dev
->driver
);
113 if (dev
->driver
&& drv
->remove
)
114 drv
->remove(soundbus_dev
);
115 soundbus_dev_put(soundbus_dev
);
120 static void soundbus_device_shutdown(struct device
*dev
)
122 struct soundbus_dev
* soundbus_dev
= to_soundbus_device(dev
);
123 struct soundbus_driver
* drv
= to_soundbus_driver(dev
->driver
);
125 if (dev
->driver
&& drv
->shutdown
)
126 drv
->shutdown(soundbus_dev
);
129 /* soundbus_dev_attrs is declared in sysfs.c */
130 ATTRIBUTE_GROUPS(soundbus_dev
);
131 static struct bus_type soundbus_bus_type
= {
132 .name
= "aoa-soundbus",
133 .probe
= soundbus_probe
,
134 .uevent
= soundbus_uevent
,
135 .remove
= soundbus_device_remove
,
136 .shutdown
= soundbus_device_shutdown
,
137 .dev_groups
= soundbus_dev_groups
,
140 int soundbus_add_one(struct soundbus_dev
*dev
)
145 if (!dev
->attach_codec
||
146 !dev
->ofdev
.dev
.of_node
||
149 printk(KERN_ERR
"soundbus: adding device failed sanity check!\n");
153 dev_set_name(&dev
->ofdev
.dev
, "soundbus:%x", ++devcount
);
154 dev
->ofdev
.dev
.bus
= &soundbus_bus_type
;
155 return of_device_register(&dev
->ofdev
);
157 EXPORT_SYMBOL_GPL(soundbus_add_one
);
159 void soundbus_remove_one(struct soundbus_dev
*dev
)
161 of_device_unregister(&dev
->ofdev
);
163 EXPORT_SYMBOL_GPL(soundbus_remove_one
);
165 int soundbus_register_driver(struct soundbus_driver
*drv
)
167 /* initialize common driver fields */
168 drv
->driver
.name
= drv
->name
;
169 drv
->driver
.bus
= &soundbus_bus_type
;
171 /* register with core */
172 return driver_register(&drv
->driver
);
174 EXPORT_SYMBOL_GPL(soundbus_register_driver
);
176 void soundbus_unregister_driver(struct soundbus_driver
*drv
)
178 driver_unregister(&drv
->driver
);
180 EXPORT_SYMBOL_GPL(soundbus_unregister_driver
);
182 static int __init
soundbus_init(void)
184 return bus_register(&soundbus_bus_type
);
187 static void __exit
soundbus_exit(void)
189 bus_unregister(&soundbus_bus_type
);
192 subsys_initcall(soundbus_init
);
193 module_exit(soundbus_exit
);