added 2.6.29.6 aldebaran kernel
[nao-ulib.git] / kernel / 2.6.29.6-aldebaran-rt / drivers / w1 / masters / w1-gpio.c
bloba411702413d687af44676cf37e3e4c7720c64f82
1 /*
2 * w1-gpio - GPIO w1 bus master driver
4 * Copyright (C) 2007 Ville Syrjala <syrjala@sci.fi>
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 */
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/w1-gpio.h>
16 #include "../w1.h"
17 #include "../w1_int.h"
19 #include <asm/gpio.h>
21 static void w1_gpio_write_bit_dir(void *data, u8 bit)
23 struct w1_gpio_platform_data *pdata = data;
25 if (bit)
26 gpio_direction_input(pdata->pin);
27 else
28 gpio_direction_output(pdata->pin, 0);
31 static void w1_gpio_write_bit_val(void *data, u8 bit)
33 struct w1_gpio_platform_data *pdata = data;
35 gpio_set_value(pdata->pin, bit);
38 static u8 w1_gpio_read_bit(void *data)
40 struct w1_gpio_platform_data *pdata = data;
42 return gpio_get_value(pdata->pin) ? 1 : 0;
45 static int __init w1_gpio_probe(struct platform_device *pdev)
47 struct w1_bus_master *master;
48 struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
49 int err;
51 if (!pdata)
52 return -ENXIO;
54 master = kzalloc(sizeof(struct w1_bus_master), GFP_KERNEL);
55 if (!master)
56 return -ENOMEM;
58 err = gpio_request(pdata->pin, "w1");
59 if (err)
60 goto free_master;
62 master->data = pdata;
63 master->read_bit = w1_gpio_read_bit;
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;
73 err = w1_add_master_device(master);
74 if (err)
75 goto free_gpio;
77 platform_set_drvdata(pdev, master);
79 return 0;
81 free_gpio:
82 gpio_free(pdata->pin);
83 free_master:
84 kfree(master);
86 return err;
89 static int __exit w1_gpio_remove(struct platform_device *pdev)
91 struct w1_bus_master *master = platform_get_drvdata(pdev);
92 struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
94 w1_remove_master_device(master);
95 gpio_free(pdata->pin);
96 kfree(master);
98 return 0;
101 static struct platform_driver w1_gpio_driver = {
102 .driver = {
103 .name = "w1-gpio",
104 .owner = THIS_MODULE,
106 .remove = __exit_p(w1_gpio_remove),
109 static int __init w1_gpio_init(void)
111 return platform_driver_probe(&w1_gpio_driver, w1_gpio_probe);
114 static void __exit w1_gpio_exit(void)
116 platform_driver_unregister(&w1_gpio_driver);
119 module_init(w1_gpio_init);
120 module_exit(w1_gpio_exit);
122 MODULE_DESCRIPTION("GPIO w1 bus master driver");
123 MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
124 MODULE_LICENSE("GPL");