thmc50.c (f0967eea80ec2a19a4fe1ad27e3ff1b22c79a3c7) thmc50.c (4d387df74e175659ad9c8a16ae8e5b364b7d3f56)
1/*
1/*
2 thmc50.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (C) 2007 Krzysztof Helt <krzysztof.h1@wp.pl>
5 Based on 2.4 driver by Frodo Looijaard <frodol@dds.nl> and
6 Philip Edelbrock <phil@netroedge.com>
2 * thmc50.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring
4 * Copyright (C) 2007 Krzysztof Helt <krzysztof.h1@wp.pl>
5 * Based on 2.4 driver by Frodo Looijaard <frodol@dds.nl> and
6 * Philip Edelbrock <phil@netroedge.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
7
22
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/slab.h>
26#include <linux/i2c.h>
27#include <linux/hwmon.h>
28#include <linux/hwmon-sysfs.h>
29#include <linux/err.h>
30#include <linux/mutex.h>

--- 88 unchanged lines hidden (view full) ---

119}
120
121static ssize_t set_analog_out(struct device *dev,
122 struct device_attribute *attr,
123 const char *buf, size_t count)
124{
125 struct i2c_client *client = to_i2c_client(dev);
126 struct thmc50_data *data = i2c_get_clientdata(client);
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/slab.h>
26#include <linux/i2c.h>
27#include <linux/hwmon.h>
28#include <linux/hwmon-sysfs.h>
29#include <linux/err.h>
30#include <linux/mutex.h>

--- 88 unchanged lines hidden (view full) ---

119}
120
121static ssize_t set_analog_out(struct device *dev,
122 struct device_attribute *attr,
123 const char *buf, size_t count)
124{
125 struct i2c_client *client = to_i2c_client(dev);
126 struct thmc50_data *data = i2c_get_clientdata(client);
127 int tmp = simple_strtoul(buf, NULL, 10);
128 int config;
127 int config;
128 unsigned long tmp;
129 int err;
129
130
131 err = kstrtoul(buf, 10, &tmp);
132 if (err)
133 return err;
134
130 mutex_lock(&data->update_lock);
131 data->analog_out = SENSORS_LIMIT(tmp, 0, 255);
132 i2c_smbus_write_byte_data(client, THMC50_REG_ANALOG_OUT,
133 data->analog_out);
134
135 config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF);
136 if (data->analog_out == 0)
137 config &= ~THMC50_REG_CONF_nFANOFF;

--- 30 unchanged lines hidden (view full) ---

168}
169
170static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
171 const char *buf, size_t count)
172{
173 int nr = to_sensor_dev_attr(attr)->index;
174 struct i2c_client *client = to_i2c_client(dev);
175 struct thmc50_data *data = i2c_get_clientdata(client);
135 mutex_lock(&data->update_lock);
136 data->analog_out = SENSORS_LIMIT(tmp, 0, 255);
137 i2c_smbus_write_byte_data(client, THMC50_REG_ANALOG_OUT,
138 data->analog_out);
139
140 config = i2c_smbus_read_byte_data(client, THMC50_REG_CONF);
141 if (data->analog_out == 0)
142 config &= ~THMC50_REG_CONF_nFANOFF;

--- 30 unchanged lines hidden (view full) ---

173}
174
175static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
176 const char *buf, size_t count)
177{
178 int nr = to_sensor_dev_attr(attr)->index;
179 struct i2c_client *client = to_i2c_client(dev);
180 struct thmc50_data *data = i2c_get_clientdata(client);
176 int val = simple_strtol(buf, NULL, 10);
181 long val;
182 int err;
177
183
184 err = kstrtol(buf, 10, &val);
185 if (err)
186 return err;
187
178 mutex_lock(&data->update_lock);
179 data->temp_min[nr] = SENSORS_LIMIT(val / 1000, -128, 127);
180 i2c_smbus_write_byte_data(client, THMC50_REG_TEMP_MIN[nr],
181 data->temp_min[nr]);
182 mutex_unlock(&data->update_lock);
183 return count;
184}
185

--- 6 unchanged lines hidden (view full) ---

192}
193
194static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
195 const char *buf, size_t count)
196{
197 int nr = to_sensor_dev_attr(attr)->index;
198 struct i2c_client *client = to_i2c_client(dev);
199 struct thmc50_data *data = i2c_get_clientdata(client);
188 mutex_lock(&data->update_lock);
189 data->temp_min[nr] = SENSORS_LIMIT(val / 1000, -128, 127);
190 i2c_smbus_write_byte_data(client, THMC50_REG_TEMP_MIN[nr],
191 data->temp_min[nr]);
192 mutex_unlock(&data->update_lock);
193 return count;
194}
195

--- 6 unchanged lines hidden (view full) ---

202}
203
204static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
205 const char *buf, size_t count)
206{
207 int nr = to_sensor_dev_attr(attr)->index;
208 struct i2c_client *client = to_i2c_client(dev);
209 struct thmc50_data *data = i2c_get_clientdata(client);
200 int val = simple_strtol(buf, NULL, 10);
210 long val;
211 int err;
201
212
213 err = kstrtol(buf, 10, &val);
214 if (err)
215 return err;
216
202 mutex_lock(&data->update_lock);
203 data->temp_max[nr] = SENSORS_LIMIT(val / 1000, -128, 127);
204 i2c_smbus_write_byte_data(client, THMC50_REG_TEMP_MAX[nr],
205 data->temp_max[nr]);
206 mutex_unlock(&data->update_lock);
207 return count;
208}
209

--- 145 unchanged lines hidden (view full) ---

355
356 i2c_set_clientdata(client, data);
357 data->type = id->driver_data;
358 mutex_init(&data->update_lock);
359
360 thmc50_init_client(client);
361
362 /* Register sysfs hooks */
217 mutex_lock(&data->update_lock);
218 data->temp_max[nr] = SENSORS_LIMIT(val / 1000, -128, 127);
219 i2c_smbus_write_byte_data(client, THMC50_REG_TEMP_MAX[nr],
220 data->temp_max[nr]);
221 mutex_unlock(&data->update_lock);
222 return count;
223}
224

--- 145 unchanged lines hidden (view full) ---

370
371 i2c_set_clientdata(client, data);
372 data->type = id->driver_data;
373 mutex_init(&data->update_lock);
374
375 thmc50_init_client(client);
376
377 /* Register sysfs hooks */
363 if ((err = sysfs_create_group(&client->dev.kobj, &thmc50_group)))
378 err = sysfs_create_group(&client->dev.kobj, &thmc50_group);
379 if (err)
364 goto exit_free;
365
366 /* Register ADM1022 sysfs hooks */
380 goto exit_free;
381
382 /* Register ADM1022 sysfs hooks */
367 if (data->has_temp3)
368 if ((err = sysfs_create_group(&client->dev.kobj,
369 &temp3_group)))
383 if (data->has_temp3) {
384 err = sysfs_create_group(&client->dev.kobj, &temp3_group);
385 if (err)
370 goto exit_remove_sysfs_thmc50;
386 goto exit_remove_sysfs_thmc50;
387 }
371
372 /* Register a new directory entry with module sensors */
373 data->hwmon_dev = hwmon_device_register(&client->dev);
374 if (IS_ERR(data->hwmon_dev)) {
375 err = PTR_ERR(data->hwmon_dev);
376 goto exit_remove_sysfs;
377 }
378

--- 93 unchanged lines hidden ---
388
389 /* Register a new directory entry with module sensors */
390 data->hwmon_dev = hwmon_device_register(&client->dev);
391 if (IS_ERR(data->hwmon_dev)) {
392 err = PTR_ERR(data->hwmon_dev);
393 goto exit_remove_sysfs;
394 }
395

--- 93 unchanged lines hidden ---