[cns3xxx]: rename 2.6.39 patches directory
[openwrt.git] / target / linux / cns3xxx / patches-2.6.31 / 101-laguna_support.patch
1 --- /dev/null
2 +++ b/drivers/hwmon/gsp.c
3 @@ -0,0 +1,310 @@
4 +/*
5 + * A hwmon driver for the Gateworks System Peripheral
6 + * Copyright (C) 2009 Gateworks Corporation
7 + *
8 + * Author: Chris Lang <clang@gateworks.com>
9 + *
10 + * This program is free software; you can redistribute it and/or modify
11 + * it under the terms of the GNU General Public License,
12 + * as published by the Free Software Foundation - version 2.
13 + */
14 +
15 +#include <linux/module.h>
16 +#include <linux/i2c.h>
17 +#include <linux/hwmon.h>
18 +#include <linux/hwmon-sysfs.h>
19 +#include <linux/err.h>
20 +
21 +
22 +#define DRV_VERSION "0.2"
23 +
24 +enum chips { gsp };
25 +
26 +/* AD7418 registers */
27 +#define GSP_REG_TEMP_IN 0x00
28 +#define GSP_REG_VIN 0x02
29 +#define GSP_REG_3P3 0x05
30 +#define GSP_REG_BAT 0x08
31 +#define GSP_REG_5P0 0x0b
32 +#define GSP_REG_CORE 0x0e
33 +#define GSP_REG_CPU1 0x11
34 +#define GSP_REG_CPU2 0x14
35 +#define GSP_REG_DRAM 0x17
36 +#define GSP_REG_EXT_BAT 0x1a
37 +#define GSP_REG_IO1 0x1d
38 +#define GSP_REG_IO2 0x20
39 +#define GSP_REG_PCIE 0x23
40 +#define GSP_REG_CURRENT 0x26
41 +#define GSP_FAN_0 0x2C
42 +#define GSP_FAN_1 0x2E
43 +#define GSP_FAN_2 0x30
44 +#define GSP_FAN_3 0x32
45 +#define GSP_FAN_4 0x34
46 +#define GSP_FAN_5 0x36
47 +
48 +struct gsp_sensor_info {
49 + const char* name;
50 + int reg;
51 +};
52 +
53 +static const struct gsp_sensor_info gsp_sensors[] = {
54 + {"temp", GSP_REG_TEMP_IN},
55 + {"vin", GSP_REG_VIN},
56 + {"3p3", GSP_REG_3P3},
57 + {"bat", GSP_REG_BAT},
58 + {"5p0", GSP_REG_5P0},
59 + {"core", GSP_REG_CORE},
60 + {"cpu1", GSP_REG_CPU1},
61 + {"cpu2", GSP_REG_CPU2},
62 + {"dram", GSP_REG_DRAM},
63 + {"ext_bat", GSP_REG_EXT_BAT},
64 + {"io1", GSP_REG_IO1},
65 + {"io2", GSP_REG_IO2},
66 + {"pci2", GSP_REG_PCIE},
67 + {"current", GSP_REG_CURRENT},
68 + {"fan_point0", GSP_FAN_0},
69 + {"fan_point1", GSP_FAN_1},
70 + {"fan_point2", GSP_FAN_2},
71 + {"fan_point3", GSP_FAN_3},
72 + {"fan_point4", GSP_FAN_4},
73 + {"fan_point5", GSP_FAN_5},
74 +};
75 +
76 +struct gsp_data {
77 + struct device *hwmon_dev;
78 + struct attribute_group attrs;
79 + enum chips type;
80 +};
81 +
82 +static int gsp_probe(struct i2c_client *client,
83 + const struct i2c_device_id *id);
84 +static int gsp_remove(struct i2c_client *client);
85 +
86 +static const struct i2c_device_id gsp_id[] = {
87 + { "gsp", 0 },
88 + { }
89 +};
90 +MODULE_DEVICE_TABLE(i2c, gsp_id);
91 +
92 +static struct i2c_driver gsp_driver = {
93 + .driver = {
94 + .name = "gsp",
95 + },
96 + .probe = gsp_probe,
97 + .remove = gsp_remove,
98 + .id_table = gsp_id,
99 +};
100 +
101 +/* All registers are word-sized, except for the configuration registers.
102 + * AD7418 uses a high-byte first convention. Do NOT use those functions to
103 + * access the configuration registers CONF and CONF2, as they are byte-sized.
104 + */
105 +static inline int gsp_read(struct i2c_client *client, u8 reg)
106 +{
107 + unsigned int adc = 0;
108 + if (reg == GSP_REG_TEMP_IN || reg > GSP_REG_CURRENT)
109 + {
110 + adc |= i2c_smbus_read_byte_data(client, reg);
111 + adc |= i2c_smbus_read_byte_data(client, reg + 1) << 8;
112 + return adc;
113 + }
114 + else
115 + {
116 + adc |= i2c_smbus_read_byte_data(client, reg);
117 + adc |= i2c_smbus_read_byte_data(client, reg + 1) << 8;
118 + adc |= i2c_smbus_read_byte_data(client, reg + 2) << 16;
119 + return adc;
120 + }
121 +}
122 +
123 +static inline int gsp_write(struct i2c_client *client, u8 reg, u16 value)
124 +{
125 + i2c_smbus_write_byte_data(client, reg, value & 0xff);
126 + i2c_smbus_write_byte_data(client, reg + 1, ((value >> 8) & 0xff));
127 + return 1;
128 +}
129 +
130 +static ssize_t show_adc(struct device *dev, struct device_attribute *devattr,
131 + char *buf)
132 +{
133 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
134 + struct i2c_client *client = to_i2c_client(dev);
135 + return sprintf(buf, "%d\n", gsp_read(client, gsp_sensors[attr->index].reg));
136 +}
137 +
138 +static ssize_t show_label(struct device *dev,
139 + struct device_attribute *devattr, char *buf)
140 +{
141 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
142 +
143 + return sprintf(buf, "%s\n", gsp_sensors[attr->index].name);
144 +}
145 +
146 +static ssize_t store_fan(struct device *dev,
147 + struct device_attribute *devattr, const char *buf, size_t count)
148 +{
149 + u16 val;
150 + struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
151 + struct i2c_client *client = to_i2c_client(dev);
152 + val = simple_strtoul(buf, NULL, 10);
153 + gsp_write(client, gsp_sensors[attr->index].reg, val);
154 + return count;
155 +}
156 +
157 +static SENSOR_DEVICE_ATTR(temp0_input, S_IRUGO, show_adc, NULL, 0);
158 +static SENSOR_DEVICE_ATTR(temp0_label, S_IRUGO, show_label, NULL, 0);
159 +
160 +static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_adc, NULL, 1);
161 +static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, show_label, NULL, 1);
162 +static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_adc, NULL, 2);
163 +static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, show_label, NULL, 2);
164 +static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_adc, NULL, 3);
165 +static SENSOR_DEVICE_ATTR(in2_label, S_IRUGO, show_label, NULL, 3);
166 +static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_adc, NULL, 4);
167 +static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 4);
168 +static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_adc, NULL, 5);
169 +static SENSOR_DEVICE_ATTR(in4_label, S_IRUGO, show_label, NULL, 5);
170 +static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_adc, NULL, 6);
171 +static SENSOR_DEVICE_ATTR(in5_label, S_IRUGO, show_label, NULL, 6);
172 +static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_adc, NULL, 7);
173 +static SENSOR_DEVICE_ATTR(in6_label, S_IRUGO, show_label, NULL, 7);
174 +static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_adc, NULL, 8);
175 +static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 8);
176 +static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_adc, NULL, 9);
177 +static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 9);
178 +static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, show_adc, NULL, 10);
179 +static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 10);
180 +static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, show_adc, NULL, 11);
181 +static SENSOR_DEVICE_ATTR(in10_label, S_IRUGO, show_label, NULL, 11);
182 +static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, show_adc, NULL, 12);
183 +static SENSOR_DEVICE_ATTR(in11_label, S_IRUGO, show_label, NULL, 12);
184 +static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, show_adc, NULL, 13);
185 +static SENSOR_DEVICE_ATTR(in12_label, S_IRUGO, show_label, NULL, 13);
186 +
187 +static SENSOR_DEVICE_ATTR(fan0_point0, S_IRUGO | S_IWUSR, show_adc, store_fan, 14);
188 +static SENSOR_DEVICE_ATTR(fan0_point1, S_IRUGO | S_IWUSR, show_adc, store_fan, 15);
189 +static SENSOR_DEVICE_ATTR(fan0_point2, S_IRUGO | S_IWUSR, show_adc, store_fan, 16);
190 +static SENSOR_DEVICE_ATTR(fan0_point3, S_IRUGO | S_IWUSR, show_adc, store_fan, 17);
191 +static SENSOR_DEVICE_ATTR(fan0_point4, S_IRUGO | S_IWUSR, show_adc, store_fan, 18);
192 +static SENSOR_DEVICE_ATTR(fan0_point5, S_IRUGO | S_IWUSR, show_adc, store_fan, 19);
193 +
194 +
195 +
196 +static struct attribute *gsp_attributes[] = {
197 + &sensor_dev_attr_temp0_input.dev_attr.attr,
198 + &sensor_dev_attr_in0_input.dev_attr.attr,
199 + &sensor_dev_attr_in1_input.dev_attr.attr,
200 + &sensor_dev_attr_in2_input.dev_attr.attr,
201 + &sensor_dev_attr_in3_input.dev_attr.attr,
202 + &sensor_dev_attr_in4_input.dev_attr.attr,
203 + &sensor_dev_attr_in5_input.dev_attr.attr,
204 + &sensor_dev_attr_in6_input.dev_attr.attr,
205 + &sensor_dev_attr_in7_input.dev_attr.attr,
206 + &sensor_dev_attr_in8_input.dev_attr.attr,
207 + &sensor_dev_attr_in9_input.dev_attr.attr,
208 + &sensor_dev_attr_in10_input.dev_attr.attr,
209 + &sensor_dev_attr_in11_input.dev_attr.attr,
210 + &sensor_dev_attr_in12_input.dev_attr.attr,
211 +
212 + &sensor_dev_attr_temp0_label.dev_attr.attr,
213 + &sensor_dev_attr_in0_label.dev_attr.attr,
214 + &sensor_dev_attr_in1_label.dev_attr.attr,
215 + &sensor_dev_attr_in2_label.dev_attr.attr,
216 + &sensor_dev_attr_in3_label.dev_attr.attr,
217 + &sensor_dev_attr_in4_label.dev_attr.attr,
218 + &sensor_dev_attr_in5_label.dev_attr.attr,
219 + &sensor_dev_attr_in6_label.dev_attr.attr,
220 + &sensor_dev_attr_in7_label.dev_attr.attr,
221 + &sensor_dev_attr_in8_label.dev_attr.attr,
222 + &sensor_dev_attr_in9_label.dev_attr.attr,
223 + &sensor_dev_attr_in10_label.dev_attr.attr,
224 + &sensor_dev_attr_in11_label.dev_attr.attr,
225 + &sensor_dev_attr_in12_label.dev_attr.attr,
226 +
227 + &sensor_dev_attr_fan0_point0.dev_attr.attr,
228 + &sensor_dev_attr_fan0_point1.dev_attr.attr,
229 + &sensor_dev_attr_fan0_point2.dev_attr.attr,
230 + &sensor_dev_attr_fan0_point3.dev_attr.attr,
231 + &sensor_dev_attr_fan0_point4.dev_attr.attr,
232 + &sensor_dev_attr_fan0_point5.dev_attr.attr,
233 +
234 + NULL
235 +};
236 +
237 +
238 +static int gsp_probe(struct i2c_client *client,
239 + const struct i2c_device_id *id)
240 +{
241 + struct i2c_adapter *adapter = client->adapter;
242 + struct gsp_data *data;
243 + int err;
244 +
245 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
246 + I2C_FUNC_SMBUS_WORD_DATA)) {
247 + err = -EOPNOTSUPP;
248 + goto exit;
249 + }
250 +
251 + if (!(data = kzalloc(sizeof(struct gsp_data), GFP_KERNEL))) {
252 + err = -ENOMEM;
253 + goto exit;
254 + }
255 +
256 + i2c_set_clientdata(client, data);
257 +
258 + data->type = id->driver_data;
259 +
260 + switch (data->type) {
261 + case 0:
262 + data->attrs.attrs = gsp_attributes;
263 + break;
264 + }
265 +
266 + dev_info(&client->dev, "%s chip found\n", client->name);
267 +
268 + /* Register sysfs hooks */
269 + if ((err = sysfs_create_group(&client->dev.kobj, &data->attrs)))
270 + goto exit_free;
271 +
272 + data->hwmon_dev = hwmon_device_register(&client->dev);
273 + if (IS_ERR(data->hwmon_dev)) {
274 + err = PTR_ERR(data->hwmon_dev);
275 + goto exit_remove;
276 + }
277 +
278 + return 0;
279 +
280 +exit_remove:
281 + sysfs_remove_group(&client->dev.kobj, &data->attrs);
282 +exit_free:
283 + kfree(data);
284 +exit:
285 + return err;
286 +}
287 +
288 +static int gsp_remove(struct i2c_client *client)
289 +{
290 + struct gsp_data *data = i2c_get_clientdata(client);
291 + hwmon_device_unregister(data->hwmon_dev);
292 + sysfs_remove_group(&client->dev.kobj, &data->attrs);
293 + kfree(data);
294 + return 0;
295 +}
296 +
297 +static int __init gsp_init(void)
298 +{
299 + return i2c_add_driver(&gsp_driver);
300 +}
301 +
302 +static void __exit gsp_exit(void)
303 +{
304 + i2c_del_driver(&gsp_driver);
305 +}
306 +
307 +MODULE_AUTHOR("Chris Lang <clang@gateworks.com>");
308 +MODULE_DESCRIPTION("GSP HWMON driver");
309 +MODULE_LICENSE("GPL");
310 +MODULE_VERSION(DRV_VERSION);
311 +
312 +module_init(gsp_init);
313 +module_exit(gsp_exit);
314 --- a/drivers/hwmon/Kconfig
315 +++ b/drivers/hwmon/Kconfig
316 @@ -57,6 +57,15 @@ config SENSORS_ABITUGURU3
317 This driver can also be built as a module. If so, the module
318 will be called abituguru3.
319
320 +config SENSORS_GSP
321 + tristate "Gateworks System Peripheral"
322 + depends on I2C && EXPERIMENTAL
323 + help
324 + If you say yes here you get support for the Gateworks System Peripherals.
325 +
326 + This driver can also be built as a module. If so, the module
327 + will be called gsp.
328 +
329 config SENSORS_AD7414
330 tristate "Analog Devices AD7414"
331 depends on I2C && EXPERIMENTAL
332 --- a/drivers/hwmon/Makefile
333 +++ b/drivers/hwmon/Makefile
334 @@ -15,6 +15,7 @@ obj-$(CONFIG_SENSORS_W83791D) += w83791d
335
336 obj-$(CONFIG_SENSORS_ABITUGURU) += abituguru.o
337 obj-$(CONFIG_SENSORS_ABITUGURU3)+= abituguru3.o
338 +obj-$(CONFIG_SENSORS_GSP) += gsp.o
339 obj-$(CONFIG_SENSORS_AD7414) += ad7414.o
340 obj-$(CONFIG_SENSORS_AD7418) += ad7418.o
341 obj-$(CONFIG_SENSORS_ADCXX) += adcxx.o
This page took 0.062931 seconds and 5 git commands to generate.