[adm5120] add custom GPIO-based I2C driver
[openwrt/svn-archive/archive.git] / target / linux / adm5120 / files / drivers / i2c / busses / i2c-gpio-custom.c
1 /*
2 * Custom GPIO-based I2C driver
3 *
4 * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
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 as
8 * published by the Free Software Foundation.
9 */
10
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/platform_device.h>
15
16 #include <linux/i2c-gpio.h>
17
18 #define DRV_NAME "i2c-gpio-custom"
19 #define DRV_DESC "Custom GPIO I2C device driver"
20
21 static unsigned int sda = CONFIG_I2C_GPIO_CUSTOM_SDA;
22 static unsigned int scl = CONFIG_I2C_GPIO_CUSTOM_SCL;
23 static int id = CONFIG_I2C_GPIO_CUSTOM_DEVICE_ID;
24
25 module_param(sda, uint, S_IRUGO);
26 MODULE_PARM_DESC(sda, "GPIO pin for SDA");
27
28 module_param(scl, uint, S_IRUGO);
29 MODULE_PARM_DESC(scl, "GPIO pin for SCL");
30
31 module_param(id, int, S_IRUGO);
32 MODULE_PARM_DESC(id, "device id of the i2c-gpio device");
33
34 static struct i2c_gpio_platform_data i2c_data;
35 static struct platform_device i2c_device;
36
37 static void i2c_gpio_custom_release(struct platform_device *pdev)
38 {
39 /* nothing to do */
40 }
41
42 static int __init i2c_gpio_custom_init(void)
43 {
44 int err;
45
46 i2c_data.sda_pin = sda;
47 i2c_data.scl_pin = scl;
48
49 i2c_device.name = "i2c-gpio";
50 i2c_device.id = id;
51
52 i2c_device.dev.platform_data = &i2c_data,
53 i2c_device.dev.release = i2c_gpio_custom_release,
54
55 err = platform_device_register(&i2c_device);
56
57 return err;
58 }
59
60 static void __exit i2c_gpio_custom_exit(void)
61 {
62 platform_device_unregister(&i2c_device);
63 }
64
65 module_init(i2c_gpio_custom_init);
66 module_exit(i2c_gpio_custom_exit);
67
68 MODULE_LICENSE("GPL v2");
69 MODULE_AUTHOR("Gabor Juhos <juhosg at openwrt.org >");
70 MODULE_DESCRIPTION(DRV_DESC);
71