It is now possible to unload the module
Signed-off-by: Damien Nicolet <[email protected]>
---
drivers/w1/w1_sunxi.c | 55 ++++++++++++++++++++++++++++++++++---------------
1 file changed, 38 insertions(+), 17 deletions(-)
diff --git a/drivers/w1/w1_sunxi.c b/drivers/w1/w1_sunxi.c
index de24f06..e811cfe 100644
--- a/drivers/w1/w1_sunxi.c
+++ b/drivers/w1/w1_sunxi.c
@@ -9,35 +9,56 @@ static int gpio = -1;
module_param(gpio, int, 0444);
MODULE_PARM_DESC(gpio, "w1 gpio pin number");
-static struct w1_gpio_platform_data w1_gpio_pdata = {
- .pin = -1,
- .is_open_drain = 0,
-};
-
-static struct platform_device w1_device = {
- .name = "w1-gpio",
- .id = -1,
- .dev.platform_data = &w1_gpio_pdata,
-};
+static struct platform_device *w1_device;
static int __init w1_sunxi_init(void)
{
- int ret;
- if (!gpio_is_valid(gpio)) {
+ int ret = 0;
+ struct w1_gpio_platform_data w1_gpio_pdata = {
+ .pin = gpio,
+ .is_open_drain = 0,
+ };
+
+ if (!gpio_is_valid(w1_gpio_pdata.pin)) {
ret =
script_parser_fetch("w1_para", "gpio", &gpio, sizeof(int));
if (ret || !gpio_is_valid(gpio)) {
- pr_err("invalid gpio pin : %d\n", gpio);
- return -EINVAL;
+ pr_err("invalid gpio pin in fex configuration : %d\n",
+ gpio);
+ ret = -EINVAL;
+ goto err0;
}
+ w1_gpio_pdata.pin = gpio;
}
- w1_gpio_pdata.pin = gpio;
- return platform_device_register(&w1_device);
+
+ w1_device = platform_device_alloc("w1-gpio", 0);
+ if (!w1_device) {
+ ret = -ENOMEM;
+ goto err0;
+ }
+
+ ret =
+ platform_device_add_data(w1_device, &w1_gpio_pdata,
+ sizeof(struct w1_gpio_platform_data));
+ if (ret)
+ goto err1;
+
+ ret = platform_device_add(w1_device);
+ if (ret)
+ goto err1;
+
+ return 0;
+
+err1:
+ platform_device_put(w1_device);
+
+err0:
+ return ret;
}
static void __exit w1_sunxi_exit(void)
{
- platform_device_unregister(&w1_device);
+ platform_device_unregister(w1_device);
}
module_init(w1_sunxi_init);
--
1.7.10.4
--
You received this message because you are subscribed to the Google Groups
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.