diff options
author | Ville Syrjala <syrjala@sci.fi> | 2008-02-06 04:39:01 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-06 13:41:15 -0500 |
commit | ad8dc96e3b2c3e28854e0de4ab49351ed547b30c (patch) | |
tree | 6faab05e76206f130333ccff4c080600ed00d332 | |
parent | 4cdf854f7d60498bbda436068a118b95059b244b (diff) |
w1-gpio: add GPIO w1 bus master driver
Add a GPIO 1-wire bus master driver. The driver used the GPIO API to
control the wire and the GPIO pin can be specified using platform data
similar to i2c-gpio. The driver was tested with AT91SAM9260 + DS2401.
Signed-off-by: Ville Syrjala <syrjala@sci.fi>
Cc: Evgeniy Polyakov <johnpol@2ka.mipt.ru>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | Documentation/w1/masters/00-INDEX | 2 | ||||
-rw-r--r-- | Documentation/w1/masters/w1-gpio | 33 | ||||
-rw-r--r-- | drivers/w1/masters/Kconfig | 10 | ||||
-rw-r--r-- | drivers/w1/masters/Makefile | 1 | ||||
-rw-r--r-- | drivers/w1/masters/w1-gpio.c | 124 | ||||
-rw-r--r-- | include/linux/w1-gpio.h | 23 |
6 files changed, 193 insertions, 0 deletions
diff --git a/Documentation/w1/masters/00-INDEX b/Documentation/w1/masters/00-INDEX index 752613c4cea2..7b0ceaaad7af 100644 --- a/Documentation/w1/masters/00-INDEX +++ b/Documentation/w1/masters/00-INDEX | |||
@@ -4,3 +4,5 @@ ds2482 | |||
4 | - The Maxim/Dallas Semiconductor DS2482 provides 1-wire busses. | 4 | - The Maxim/Dallas Semiconductor DS2482 provides 1-wire busses. |
5 | ds2490 | 5 | ds2490 |
6 | - The Maxim/Dallas Semiconductor DS2490 builds USB <-> W1 bridges. | 6 | - The Maxim/Dallas Semiconductor DS2490 builds USB <-> W1 bridges. |
7 | w1-gpio | ||
8 | - GPIO 1-wire bus master driver. | ||
diff --git a/Documentation/w1/masters/w1-gpio b/Documentation/w1/masters/w1-gpio new file mode 100644 index 000000000000..af5d3b4aa851 --- /dev/null +++ b/Documentation/w1/masters/w1-gpio | |||
@@ -0,0 +1,33 @@ | |||
1 | Kernel driver w1-gpio | ||
2 | ===================== | ||
3 | |||
4 | Author: Ville Syrjala <syrjala@sci.fi> | ||
5 | |||
6 | |||
7 | Description | ||
8 | ----------- | ||
9 | |||
10 | GPIO 1-wire bus master driver. The driver uses the GPIO API to control the | ||
11 | wire and the GPIO pin can be specified using platform data. | ||
12 | |||
13 | |||
14 | Example (mach-at91) | ||
15 | ------------------- | ||
16 | |||
17 | #include <linux/w1-gpio.h> | ||
18 | |||
19 | static struct w1_gpio_platform_data foo_w1_gpio_pdata = { | ||
20 | .pin = AT91_PIN_PB20, | ||
21 | .is_open_drain = 1, | ||
22 | }; | ||
23 | |||
24 | static struct platform_device foo_w1_device = { | ||
25 | .name = "w1-gpio", | ||
26 | .id = -1, | ||
27 | .dev.platform_data = &foo_w1_gpio_pdata, | ||
28 | }; | ||
29 | |||
30 | ... | ||
31 | at91_set_GPIO_periph(foo_w1_gpio_pdata.pin, 1); | ||
32 | at91_set_multi_drive(foo_w1_gpio_pdata.pin, 1); | ||
33 | platform_device_register(&foo_w1_device); | ||
diff --git a/drivers/w1/masters/Kconfig b/drivers/w1/masters/Kconfig index 8236d447adf5..c4493091c655 100644 --- a/drivers/w1/masters/Kconfig +++ b/drivers/w1/masters/Kconfig | |||
@@ -42,5 +42,15 @@ config W1_MASTER_DS1WM | |||
42 | in HP iPAQ devices like h5xxx, h2200, and ASIC3-based like | 42 | in HP iPAQ devices like h5xxx, h2200, and ASIC3-based like |
43 | hx4700. | 43 | hx4700. |
44 | 44 | ||
45 | config W1_MASTER_GPIO | ||
46 | tristate "GPIO 1-wire busmaster" | ||
47 | depends on GENERIC_GPIO | ||
48 | help | ||
49 | Say Y here if you want to communicate with your 1-wire devices using | ||
50 | GPIO pins. This driver uses the GPIO API to control the wire. | ||
51 | |||
52 | This support is also available as a module. If so, the module | ||
53 | will be called w1-gpio.ko. | ||
54 | |||
45 | endmenu | 55 | endmenu |
46 | 56 | ||
diff --git a/drivers/w1/masters/Makefile b/drivers/w1/masters/Makefile index 11551b328186..1420b5bbdda8 100644 --- a/drivers/w1/masters/Makefile +++ b/drivers/w1/masters/Makefile | |||
@@ -6,3 +6,4 @@ obj-$(CONFIG_W1_MASTER_MATROX) += matrox_w1.o | |||
6 | obj-$(CONFIG_W1_MASTER_DS2490) += ds2490.o | 6 | obj-$(CONFIG_W1_MASTER_DS2490) += ds2490.o |
7 | obj-$(CONFIG_W1_MASTER_DS2482) += ds2482.o | 7 | obj-$(CONFIG_W1_MASTER_DS2482) += ds2482.o |
8 | obj-$(CONFIG_W1_MASTER_DS1WM) += ds1wm.o | 8 | obj-$(CONFIG_W1_MASTER_DS1WM) += ds1wm.o |
9 | obj-$(CONFIG_W1_MASTER_GPIO) += w1-gpio.o | ||
diff --git a/drivers/w1/masters/w1-gpio.c b/drivers/w1/masters/w1-gpio.c new file mode 100644 index 000000000000..9e1138a75e8b --- /dev/null +++ b/drivers/w1/masters/w1-gpio.c | |||
@@ -0,0 +1,124 @@ | |||
1 | /* | ||
2 | * w1-gpio - GPIO w1 bus master driver | ||
3 | * | ||
4 | * Copyright (C) 2007 Ville Syrjala <syrjala@sci.fi> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 | ||
8 | * as published by the Free Software Foundation. | ||
9 | */ | ||
10 | |||
11 | #include <linux/init.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/platform_device.h> | ||
14 | #include <linux/w1-gpio.h> | ||
15 | |||
16 | #include "../w1.h" | ||
17 | #include "../w1_int.h" | ||
18 | |||
19 | #include <asm/gpio.h> | ||
20 | |||
21 | static void w1_gpio_write_bit_dir(void *data, u8 bit) | ||
22 | { | ||
23 | struct w1_gpio_platform_data *pdata = data; | ||
24 | |||
25 | if (bit) | ||
26 | gpio_direction_input(pdata->pin); | ||
27 | else | ||
28 | gpio_direction_output(pdata->pin, 0); | ||
29 | } | ||
30 | |||
31 | static void w1_gpio_write_bit_val(void *data, u8 bit) | ||
32 | { | ||
33 | struct w1_gpio_platform_data *pdata = data; | ||
34 | |||
35 | gpio_set_value(pdata->pin, bit); | ||
36 | } | ||
37 | |||
38 | static u8 w1_gpio_read_bit(void *data) | ||
39 | { | ||
40 | struct w1_gpio_platform_data *pdata = data; | ||
41 | |||
42 | return gpio_get_value(pdata->pin); | ||
43 | } | ||
44 | |||
45 | static int __init w1_gpio_probe(struct platform_device *pdev) | ||
46 | { | ||
47 | struct w1_bus_master *master; | ||
48 | struct w1_gpio_platform_data *pdata = pdev->dev.platform_data; | ||
49 | int err; | ||
50 | |||
51 | if (!pdata) | ||
52 | return -ENXIO; | ||
53 | |||
54 | master = kzalloc(sizeof(struct w1_bus_master), GFP_KERNEL); | ||
55 | if (!master) | ||
56 | return -ENOMEM; | ||
57 | |||
58 | err = gpio_request(pdata->pin, "w1"); | ||
59 | if (err) | ||
60 | goto free_master; | ||
61 | |||
62 | master->data = pdata; | ||
63 | master->read_bit = w1_gpio_read_bit; | ||
64 | |||
65 | if (pdata->is_open_drain) { | ||
66 | gpio_direction_output(pdata->pin, 1); | ||
67 | master->write_bit = w1_gpio_write_bit_val; | ||
68 | } else { | ||
69 | gpio_direction_input(pdata->pin); | ||
70 | master->write_bit = w1_gpio_write_bit_dir; | ||
71 | } | ||
72 | |||
73 | err = w1_add_master_device(master); | ||
74 | if (err) | ||
75 | goto free_gpio; | ||
76 | |||
77 | platform_set_drvdata(pdev, master); | ||
78 | |||
79 | return 0; | ||
80 | |||
81 | free_gpio: | ||
82 | gpio_free(pdata->pin); | ||
83 | free_master: | ||
84 | kfree(master); | ||
85 | |||
86 | return err; | ||
87 | } | ||
88 | |||
89 | static int __exit w1_gpio_remove(struct platform_device *pdev) | ||
90 | { | ||
91 | struct w1_bus_master *master = platform_get_drvdata(pdev); | ||
92 | struct w1_gpio_platform_data *pdata = pdev->dev.platform_data; | ||
93 | |||
94 | w1_remove_master_device(master); | ||
95 | gpio_free(pdata->pin); | ||
96 | kfree(master); | ||
97 | |||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | static struct platform_driver w1_gpio_driver = { | ||
102 | .driver = { | ||
103 | .name = "w1-gpio", | ||
104 | .owner = THIS_MODULE, | ||
105 | }, | ||
106 | .remove = __exit_p(w1_gpio_remove), | ||
107 | }; | ||
108 | |||
109 | static int __init w1_gpio_init(void) | ||
110 | { | ||
111 | return platform_driver_probe(&w1_gpio_driver, w1_gpio_probe); | ||
112 | } | ||
113 | |||
114 | static void __exit w1_gpio_exit(void) | ||
115 | { | ||
116 | platform_driver_unregister(&w1_gpio_driver); | ||
117 | } | ||
118 | |||
119 | module_init(w1_gpio_init); | ||
120 | module_exit(w1_gpio_exit); | ||
121 | |||
122 | MODULE_DESCRIPTION("GPIO w1 bus master driver"); | ||
123 | MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>"); | ||
124 | MODULE_LICENSE("GPL"); | ||
diff --git a/include/linux/w1-gpio.h b/include/linux/w1-gpio.h new file mode 100644 index 000000000000..9797fec7748a --- /dev/null +++ b/include/linux/w1-gpio.h | |||
@@ -0,0 +1,23 @@ | |||
1 | /* | ||
2 | * w1-gpio interface to platform code | ||
3 | * | ||
4 | * Copyright (C) 2007 Ville Syrjala <syrjala@sci.fi> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 | ||
8 | * as published by the Free Software Foundation. | ||
9 | */ | ||
10 | #ifndef _LINUX_W1_GPIO_H | ||
11 | #define _LINUX_W1_GPIO_H | ||
12 | |||
13 | /** | ||
14 | * struct w1_gpio_platform_data - Platform-dependent data for w1-gpio | ||
15 | * @pin: GPIO pin to use | ||
16 | * @is_open_drain: GPIO pin is configured as open drain | ||
17 | */ | ||
18 | struct w1_gpio_platform_data { | ||
19 | unsigned int pin; | ||
20 | unsigned int is_open_drain:1; | ||
21 | }; | ||
22 | |||
23 | #endif /* _LINUX_W1_GPIO_H */ | ||