1 --- a/drivers/w1/masters/Kconfig
2 +++ b/drivers/w1/masters/Kconfig
3 @@ -42,5 +42,15 @@ config W1_MASTER_DS1WM
4 in HP iPAQ devices like h5xxx, h2200, and ASIC3-based like
8 + tristate "GPIO 1-wire busmaster"
9 + depends on GENERIC_GPIO
11 + Say Y here if you want to communicate with your 1-wire devices using
12 + GPIO pins. This driver uses the GPIO API to control the wire.
14 + This support is also available as a module. If so, the module
15 + will be called w1-gpio.ko.
19 --- a/drivers/w1/masters/Makefile
20 +++ b/drivers/w1/masters/Makefile
21 @@ -6,3 +6,4 @@ obj-$(CONFIG_W1_MASTER_MATROX) += matro
22 obj-$(CONFIG_W1_MASTER_DS2490) += ds2490.o
23 obj-$(CONFIG_W1_MASTER_DS2482) += ds2482.o
24 obj-$(CONFIG_W1_MASTER_DS1WM) += ds1wm.o
25 +obj-$(CONFIG_W1_MASTER_GPIO) += w1-gpio.o
27 +++ b/drivers/w1/masters/w1-gpio.c
30 + * w1-gpio - GPIO w1 bus master driver
32 + * Copyright (C) 2007 Ville Syrjala <syrjala@sci.fi>
34 + * This program is free software; you can redistribute it and/or modify
35 + * it under the terms of the GNU General Public License version 2
36 + * as published by the Free Software Foundation.
39 +#include <linux/init.h>
40 +#include <linux/module.h>
41 +#include <linux/platform_device.h>
42 +#include <linux/w1-gpio.h>
45 +#include "../w1_int.h"
47 +#include <asm/gpio.h>
49 +static void w1_gpio_write_bit_dir(void *data, u8 bit)
51 + struct w1_gpio_platform_data *pdata = data;
54 + gpio_direction_input(pdata->pin);
56 + gpio_direction_output(pdata->pin, 0);
59 +static void w1_gpio_write_bit_val(void *data, u8 bit)
61 + struct w1_gpio_platform_data *pdata = data;
63 + gpio_set_value(pdata->pin, bit);
66 +static u8 w1_gpio_read_bit(void *data)
68 + struct w1_gpio_platform_data *pdata = data;
70 + return gpio_get_value(pdata->pin);
73 +static int __init w1_gpio_probe(struct platform_device *pdev)
75 + struct w1_bus_master *master;
76 + struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
82 + master = kzalloc(sizeof(struct w1_bus_master), GFP_KERNEL);
86 + err = gpio_request(pdata->pin, "w1");
90 + master->data = pdata;
91 + master->read_bit = w1_gpio_read_bit;
93 + if (pdata->is_open_drain) {
94 + gpio_direction_output(pdata->pin, 1);
95 + master->write_bit = w1_gpio_write_bit_val;
97 + gpio_direction_input(pdata->pin);
98 + master->write_bit = w1_gpio_write_bit_dir;
101 + err = w1_add_master_device(master);
105 + platform_set_drvdata(pdev, master);
110 + gpio_free(pdata->pin);
117 +static int __exit w1_gpio_remove(struct platform_device *pdev)
119 + struct w1_bus_master *master = platform_get_drvdata(pdev);
120 + struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
122 + w1_remove_master_device(master);
123 + gpio_free(pdata->pin);
129 +static struct platform_driver w1_gpio_driver = {
132 + .owner = THIS_MODULE,
134 + .remove = __exit_p(w1_gpio_remove),
137 +static int __init w1_gpio_init(void)
139 + return platform_driver_probe(&w1_gpio_driver, w1_gpio_probe);
142 +static void __exit w1_gpio_exit(void)
144 + platform_driver_unregister(&w1_gpio_driver);
147 +module_init(w1_gpio_init);
148 +module_exit(w1_gpio_exit);
150 +MODULE_DESCRIPTION("GPIO w1 bus master driver");
151 +MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
152 +MODULE_LICENSE("GPL");
154 +++ b/include/linux/w1-gpio.h
157 + * w1-gpio interface to platform code
159 + * Copyright (C) 2007 Ville Syrjala <syrjala@sci.fi>
161 + * This program is free software; you can redistribute it and/or modify
162 + * it under the terms of the GNU General Public License version 2
163 + * as published by the Free Software Foundation.
165 +#ifndef _LINUX_W1_GPIO_H
166 +#define _LINUX_W1_GPIO_H
169 + * struct w1_gpio_platform_data - Platform-dependent data for w1-gpio
170 + * @pin: GPIO pin to use
171 + * @is_open_drain: GPIO pin is configured as open drain
173 +struct w1_gpio_platform_data {
175 + unsigned int is_open_drain:1;
178 +#endif /* _LINUX_W1_GPIO_H */