1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <linux/module.h>
25#include <linux/errno.h>
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/i2c.h>
29#include <linux/i2c-algo-bit.h>
30#include <asm/io.h>
31
32#include <linux/scx200_gpio.h>
33
34#define NAME "scx200_i2c"
35
36MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
37MODULE_DESCRIPTION("NatSemi SCx200 I2C Driver");
38MODULE_LICENSE("GPL");
39
40static int scl = CONFIG_SCx200_I2C_SCL;
41static int sda = CONFIG_SCx200_I2C_SDA;
42
43module_param(scl, int, 0);
44MODULE_PARM_DESC(scl, "GPIO line for SCL");
45module_param(sda, int, 0);
46MODULE_PARM_DESC(sda, "GPIO line for SDA");
47
48static void scx200_i2c_setscl(void *data, int state)
49{
50 scx200_gpio_set(scl, state);
51}
52
53static void scx200_i2c_setsda(void *data, int state)
54{
55 scx200_gpio_set(sda, state);
56}
57
58static int scx200_i2c_getscl(void *data)
59{
60 return scx200_gpio_get(scl);
61}
62
63static int scx200_i2c_getsda(void *data)
64{
65 return scx200_gpio_get(sda);
66}
67
68
69
70
71
72
73static struct i2c_algo_bit_data scx200_i2c_data = {
74 .setsda = scx200_i2c_setsda,
75 .setscl = scx200_i2c_setscl,
76 .getsda = scx200_i2c_getsda,
77 .getscl = scx200_i2c_getscl,
78 .udelay = 10,
79 .timeout = HZ,
80};
81
82static struct i2c_adapter scx200_i2c_ops = {
83 .owner = THIS_MODULE,
84 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
85 .algo_data = &scx200_i2c_data,
86 .name = "NatSemi SCx200 I2C",
87};
88
89static int scx200_i2c_init(void)
90{
91 pr_debug(NAME ": NatSemi SCx200 I2C Driver\n");
92
93 if (!scx200_gpio_present()) {
94 printk(KERN_ERR NAME ": no SCx200 gpio pins available\n");
95 return -ENODEV;
96 }
97
98 pr_debug(NAME ": SCL=GPIO%02u, SDA=GPIO%02u\n", scl, sda);
99
100 if (scl == -1 || sda == -1 || scl == sda) {
101 printk(KERN_ERR NAME ": scl and sda must be specified\n");
102 return -EINVAL;
103 }
104
105
106 scx200_gpio_configure(scl, ~2, 5);
107 scx200_gpio_configure(sda, ~2, 5);
108
109 if (i2c_bit_add_bus(&scx200_i2c_ops) < 0) {
110 printk(KERN_ERR NAME ": adapter %s registration failed\n",
111 scx200_i2c_ops.name);
112 return -ENODEV;
113 }
114
115 return 0;
116}
117
118static void scx200_i2c_cleanup(void)
119{
120 i2c_del_adapter(&scx200_i2c_ops);
121}
122
123module_init(scx200_i2c_init);
124module_exit(scx200_i2c_cleanup);
125
126
127
128
129
130
131
132