dc5aadfbcf4d9198f5ddb2f550f7cd3072fb0954
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.24 / 922-w1_gpio_driver_backport.patch
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
5 hx4700.
6
7 +config W1_MASTER_GPIO
8 + tristate "GPIO 1-wire busmaster"
9 + depends on GENERIC_GPIO
10 + help
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.
13 +
14 + This support is also available as a module. If so, the module
15 + will be called w1-gpio.ko.
16 +
17 endmenu
18
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
26 --- /dev/null
27 +++ b/drivers/w1/masters/w1-gpio.c
28 @@ -0,0 +1,124 @@
29 +/*
30 + * w1-gpio - GPIO w1 bus master driver
31 + *
32 + * Copyright (C) 2007 Ville Syrjala <syrjala@sci.fi>
33 + *
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.
37 + */
38 +
39 +#include <linux/init.h>
40 +#include <linux/module.h>
41 +#include <linux/platform_device.h>
42 +#include <linux/w1-gpio.h>
43 +
44 +#include "../w1.h"
45 +#include "../w1_int.h"
46 +
47 +#include <asm/gpio.h>
48 +
49 +static void w1_gpio_write_bit_dir(void *data, u8 bit)
50 +{
51 + struct w1_gpio_platform_data *pdata = data;
52 +
53 + if (bit)
54 + gpio_direction_input(pdata->pin);
55 + else
56 + gpio_direction_output(pdata->pin, 0);
57 +}
58 +
59 +static void w1_gpio_write_bit_val(void *data, u8 bit)
60 +{
61 + struct w1_gpio_platform_data *pdata = data;
62 +
63 + gpio_set_value(pdata->pin, bit);
64 +}
65 +
66 +static u8 w1_gpio_read_bit(void *data)
67 +{
68 + struct w1_gpio_platform_data *pdata = data;
69 +
70 + return gpio_get_value(pdata->pin);
71 +}
72 +
73 +static int __init w1_gpio_probe(struct platform_device *pdev)
74 +{
75 + struct w1_bus_master *master;
76 + struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
77 + int err;
78 +
79 + if (!pdata)
80 + return -ENXIO;
81 +
82 + master = kzalloc(sizeof(struct w1_bus_master), GFP_KERNEL);
83 + if (!master)
84 + return -ENOMEM;
85 +
86 + err = gpio_request(pdata->pin, "w1");
87 + if (err)
88 + goto free_master;
89 +
90 + master->data = pdata;
91 + master->read_bit = w1_gpio_read_bit;
92 +
93 + if (pdata->is_open_drain) {
94 + gpio_direction_output(pdata->pin, 1);
95 + master->write_bit = w1_gpio_write_bit_val;
96 + } else {
97 + gpio_direction_input(pdata->pin);
98 + master->write_bit = w1_gpio_write_bit_dir;
99 + }
100 +
101 + err = w1_add_master_device(master);
102 + if (err)
103 + goto free_gpio;
104 +
105 + platform_set_drvdata(pdev, master);
106 +
107 + return 0;
108 +
109 + free_gpio:
110 + gpio_free(pdata->pin);
111 + free_master:
112 + kfree(master);
113 +
114 + return err;
115 +}
116 +
117 +static int __exit w1_gpio_remove(struct platform_device *pdev)
118 +{
119 + struct w1_bus_master *master = platform_get_drvdata(pdev);
120 + struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
121 +
122 + w1_remove_master_device(master);
123 + gpio_free(pdata->pin);
124 + kfree(master);
125 +
126 + return 0;
127 +}
128 +
129 +static struct platform_driver w1_gpio_driver = {
130 + .driver = {
131 + .name = "w1-gpio",
132 + .owner = THIS_MODULE,
133 + },
134 + .remove = __exit_p(w1_gpio_remove),
135 +};
136 +
137 +static int __init w1_gpio_init(void)
138 +{
139 + return platform_driver_probe(&w1_gpio_driver, w1_gpio_probe);
140 +}
141 +
142 +static void __exit w1_gpio_exit(void)
143 +{
144 + platform_driver_unregister(&w1_gpio_driver);
145 +}
146 +
147 +module_init(w1_gpio_init);
148 +module_exit(w1_gpio_exit);
149 +
150 +MODULE_DESCRIPTION("GPIO w1 bus master driver");
151 +MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
152 +MODULE_LICENSE("GPL");
153 --- /dev/null
154 +++ b/include/linux/w1-gpio.h
155 @@ -0,0 +1,23 @@
156 +/*
157 + * w1-gpio interface to platform code
158 + *
159 + * Copyright (C) 2007 Ville Syrjala <syrjala@sci.fi>
160 + *
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.
164 + */
165 +#ifndef _LINUX_W1_GPIO_H
166 +#define _LINUX_W1_GPIO_H
167 +
168 +/**
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
172 + */
173 +struct w1_gpio_platform_data {
174 + unsigned int pin;
175 + unsigned int is_open_drain:1;
176 +};
177 +
178 +#endif /* _LINUX_W1_GPIO_H */
This page took 0.048352 seconds and 3 git commands to generate.