2 * Custom GPIO-based W1 driver
4 * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
5 * Copyright (C) 2008 Bifferos <bifferos at yahoo.co.uk>
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.
11 * ---------------------------------------------------------------------------
13 * The behaviour of this driver can be altered by setting some parameters
14 * from the insmod command line.
16 * The following parameters are adjustable:
18 * bus0 These four arguments must be arrays of
19 * bus1 3 unsigned integers as follows:
21 * bus3 <id>,<pin>,<od>
25 * <id> ID to used as device_id for the corresponding bus (required)
26 * <sda> GPIO pin ID of data pin (required)
27 * <od> Pin is configured as open drain.
29 * See include/w1-gpio.h for more information about the parameters.
31 * If this driver is built into the kernel, you can use the following kernel
32 * command line parameters, with the same values as the corresponding module
33 * parameters listed above:
41 #include <linux/kernel.h>
42 #include <linux/module.h>
43 #include <linux/init.h>
44 #include <linux/platform_device.h>
46 #include <linux/w1-gpio.h>
48 #define DRV_NAME "w1-gpio-custom"
49 #define DRV_DESC "Custom GPIO-based W1 driver"
50 #define DRV_VERSION "0.1.1"
52 #define PFX DRV_NAME ": "
54 #define BUS_PARAM_ID 0
55 #define BUS_PARAM_PIN 1
56 #define BUS_PARAM_OD 2
58 #define BUS_PARAM_REQUIRED 3
59 #define BUS_PARAM_COUNT 3
60 #define BUS_COUNT_MAX 4
62 static unsigned int bus0
[BUS_PARAM_COUNT
] __initdata
;
63 static unsigned int bus1
[BUS_PARAM_COUNT
] __initdata
;
64 static unsigned int bus2
[BUS_PARAM_COUNT
] __initdata
;
65 static unsigned int bus3
[BUS_PARAM_COUNT
] __initdata
;
67 static unsigned int bus_nump
[BUS_COUNT_MAX
] __initdata
;
69 #define BUS_PARM_DESC " config -> id,pin,od"
71 module_param_array(bus0
, uint
, &bus_nump
[0], 0);
72 MODULE_PARM_DESC(bus0
, "bus0" BUS_PARM_DESC
);
73 module_param_array(bus1
, uint
, &bus_nump
[1], 0);
74 MODULE_PARM_DESC(bus1
, "bus1" BUS_PARM_DESC
);
75 module_param_array(bus2
, uint
, &bus_nump
[2], 0);
76 MODULE_PARM_DESC(bus2
, "bus2" BUS_PARM_DESC
);
77 module_param_array(bus3
, uint
, &bus_nump
[3], 0);
78 MODULE_PARM_DESC(bus3
, "bus3" BUS_PARM_DESC
);
80 static struct platform_device
*devices
[BUS_COUNT_MAX
];
81 static unsigned int nr_devices
;
83 static void w1_gpio_custom_cleanup(void)
87 for (i
= 0; i
< nr_devices
; i
++)
89 platform_device_put(devices
[i
]);
92 static int __init
w1_gpio_custom_add_one(unsigned int id
, unsigned int *params
)
94 struct platform_device
*pdev
;
95 struct w1_gpio_platform_data pdata
;
101 if (bus_nump
[id
] < BUS_PARAM_REQUIRED
) {
102 printk(KERN_ERR PFX
"not enough parameters for bus%d\n", id
);
107 pdev
= platform_device_alloc("w1-gpio", params
[BUS_PARAM_ID
]);
113 pdata
.pin
= params
[BUS_PARAM_PIN
];
114 pdata
.is_open_drain
= params
[BUS_PARAM_OD
] ? 1:0;
116 err
= platform_device_add_data(pdev
, &pdata
, sizeof(pdata
));
120 err
= platform_device_add(pdev
);
124 devices
[nr_devices
++] = pdev
;
128 platform_device_put(pdev
);
133 static int __init
w1_gpio_custom_probe(void)
138 printk(KERN_INFO DRV_DESC
" version " DRV_VERSION
"\n");
140 err
= w1_gpio_custom_add_one(0, bus0
);
143 err
= w1_gpio_custom_add_one(1, bus1
);
146 err
= w1_gpio_custom_add_one(2, bus2
);
149 err
= w1_gpio_custom_add_one(3, bus3
);
153 printk(KERN_ERR PFX
"no bus parameter(s) specified\n");
161 w1_gpio_custom_cleanup();
166 static int __init
w1_gpio_custom_init(void)
168 return w1_gpio_custom_probe();
170 module_init(w1_gpio_custom_init
);
172 static void __exit
w1_gpio_custom_exit(void)
174 w1_gpio_custom_cleanup();
176 module_exit(w1_gpio_custom_exit
);
178 subsys_initcall(w1_gpio_custom_probe
);
181 MODULE_LICENSE("GPL v2");
182 MODULE_AUTHOR("Bifferos <bifferos at yahoo.co.uk >");
183 MODULE_DESCRIPTION(DRV_DESC
);
184 MODULE_VERSION(DRV_VERSION
);