4a66308ece74e46962d60be5bc7759165e1f7d13
[openwrt/svn-archive/archive.git] / target / linux / generic-2.6 / patches-2.6.23 / 922-w1_gpio_driver_backport.patch
1 Index: linux-2.6.23.17/drivers/w1/masters/Kconfig
2 ===================================================================
3 --- linux-2.6.23.17.orig/drivers/w1/masters/Kconfig
4 +++ linux-2.6.23.17/drivers/w1/masters/Kconfig
5 @@ -42,5 +42,15 @@ config W1_MASTER_DS1WM
6 in HP iPAQ devices like h5xxx, h2200, and ASIC3-based like
7 hx4700.
8
9 +config W1_MASTER_GPIO
10 + tristate "GPIO 1-wire busmaster"
11 + depends on GENERIC_GPIO
12 + help
13 + Say Y here if you want to communicate with your 1-wire devices using
14 + GPIO pins. This driver uses the GPIO API to control the wire.
15 +
16 + This support is also available as a module. If so, the module
17 + will be called w1-gpio.ko.
18 +
19 endmenu
20
21 Index: linux-2.6.23.17/drivers/w1/masters/Makefile
22 ===================================================================
23 --- linux-2.6.23.17.orig/drivers/w1/masters/Makefile
24 +++ linux-2.6.23.17/drivers/w1/masters/Makefile
25 @@ -6,3 +6,4 @@ obj-$(CONFIG_W1_MASTER_MATROX) += matro
26 obj-$(CONFIG_W1_MASTER_DS2490) += ds2490.o
27 obj-$(CONFIG_W1_MASTER_DS2482) += ds2482.o
28 obj-$(CONFIG_W1_MASTER_DS1WM) += ds1wm.o
29 +obj-$(CONFIG_W1_MASTER_GPIO) += w1-gpio.o
30 Index: linux-2.6.23.17/drivers/w1/masters/w1-gpio.c
31 ===================================================================
32 --- /dev/null
33 +++ linux-2.6.23.17/drivers/w1/masters/w1-gpio.c
34 @@ -0,0 +1,124 @@
35 +/*
36 + * w1-gpio - GPIO w1 bus master driver
37 + *
38 + * Copyright (C) 2007 Ville Syrjala <syrjala@sci.fi>
39 + *
40 + * This program is free software; you can redistribute it and/or modify
41 + * it under the terms of the GNU General Public License version 2
42 + * as published by the Free Software Foundation.
43 + */
44 +
45 +#include <linux/init.h>
46 +#include <linux/module.h>
47 +#include <linux/platform_device.h>
48 +#include <linux/w1-gpio.h>
49 +
50 +#include "../w1.h"
51 +#include "../w1_int.h"
52 +
53 +#include <asm/gpio.h>
54 +
55 +static void w1_gpio_write_bit_dir(void *data, u8 bit)
56 +{
57 + struct w1_gpio_platform_data *pdata = data;
58 +
59 + if (bit)
60 + gpio_direction_input(pdata->pin);
61 + else
62 + gpio_direction_output(pdata->pin, 0);
63 +}
64 +
65 +static void w1_gpio_write_bit_val(void *data, u8 bit)
66 +{
67 + struct w1_gpio_platform_data *pdata = data;
68 +
69 + gpio_set_value(pdata->pin, bit);
70 +}
71 +
72 +static u8 w1_gpio_read_bit(void *data)
73 +{
74 + struct w1_gpio_platform_data *pdata = data;
75 +
76 + return gpio_get_value(pdata->pin);
77 +}
78 +
79 +static int __init w1_gpio_probe(struct platform_device *pdev)
80 +{
81 + struct w1_bus_master *master;
82 + struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
83 + int err;
84 +
85 + if (!pdata)
86 + return -ENXIO;
87 +
88 + master = kzalloc(sizeof(struct w1_bus_master), GFP_KERNEL);
89 + if (!master)
90 + return -ENOMEM;
91 +
92 + err = gpio_request(pdata->pin, "w1");
93 + if (err)
94 + goto free_master;
95 +
96 + master->data = pdata;
97 + master->read_bit = w1_gpio_read_bit;
98 +
99 + if (pdata->is_open_drain) {
100 + gpio_direction_output(pdata->pin, 1);
101 + master->write_bit = w1_gpio_write_bit_val;
102 + } else {
103 + gpio_direction_input(pdata->pin);
104 + master->write_bit = w1_gpio_write_bit_dir;
105 + }
106 +
107 + err = w1_add_master_device(master);
108 + if (err)
109 + goto free_gpio;
110 +
111 + platform_set_drvdata(pdev, master);
112 +
113 + return 0;
114 +
115 + free_gpio:
116 + gpio_free(pdata->pin);
117 + free_master:
118 + kfree(master);
119 +
120 + return err;
121 +}
122 +
123 +static int __exit w1_gpio_remove(struct platform_device *pdev)
124 +{
125 + struct w1_bus_master *master = platform_get_drvdata(pdev);
126 + struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
127 +
128 + w1_remove_master_device(master);
129 + gpio_free(pdata->pin);
130 + kfree(master);
131 +
132 + return 0;
133 +}
134 +
135 +static struct platform_driver w1_gpio_driver = {
136 + .driver = {
137 + .name = "w1-gpio",
138 + .owner = THIS_MODULE,
139 + },
140 + .remove = __exit_p(w1_gpio_remove),
141 +};
142 +
143 +static int __init w1_gpio_init(void)
144 +{
145 + return platform_driver_probe(&w1_gpio_driver, w1_gpio_probe);
146 +}
147 +
148 +static void __exit w1_gpio_exit(void)
149 +{
150 + platform_driver_unregister(&w1_gpio_driver);
151 +}
152 +
153 +module_init(w1_gpio_init);
154 +module_exit(w1_gpio_exit);
155 +
156 +MODULE_DESCRIPTION("GPIO w1 bus master driver");
157 +MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
158 +MODULE_LICENSE("GPL");
159 Index: linux-2.6.23.17/include/linux/w1-gpio.h
160 ===================================================================
161 --- /dev/null
162 +++ linux-2.6.23.17/include/linux/w1-gpio.h
163 @@ -0,0 +1,23 @@
164 +/*
165 + * w1-gpio interface to platform code
166 + *
167 + * Copyright (C) 2007 Ville Syrjala <syrjala@sci.fi>
168 + *
169 + * This program is free software; you can redistribute it and/or modify
170 + * it under the terms of the GNU General Public License version 2
171 + * as published by the Free Software Foundation.
172 + */
173 +#ifndef _LINUX_W1_GPIO_H
174 +#define _LINUX_W1_GPIO_H
175 +
176 +/**
177 + * struct w1_gpio_platform_data - Platform-dependent data for w1-gpio
178 + * @pin: GPIO pin to use
179 + * @is_open_drain: GPIO pin is configured as open drain
180 + */
181 +struct w1_gpio_platform_data {
182 + unsigned int pin;
183 + unsigned int is_open_drain:1;
184 +};
185 +
186 +#endif /* _LINUX_W1_GPIO_H */