Commit 02fe2fd9 authored by Guenter Roeck's avatar Guenter Roeck Committed by Guenter Roeck

hwmon: (lm77) Fix checkpatch issues

Fixed:
ERROR: code indent should use tabs where possible
ERROR: do not use assignment in if condition
ERROR: trailing whitespace
WARNING: line over 80 characters
WARNING: please, no space before tabs
WARNING: simple_strtol is obsolete, use kstrtol instead
WARNING: simple_strtoul is obsolete, use kstrtoul instead

Modify multi-line comments to follow Documentation/CodingStyle.
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent f445a9af
/* /*
lm77.c - Part of lm_sensors, Linux kernel modules for hardware * lm77.c - Part of lm_sensors, Linux kernel modules for hardware
monitoring * monitoring
*
Copyright (c) 2004 Andras BALI <drewie@freemail.hu> * Copyright (c) 2004 Andras BALI <drewie@freemail.hu>
*
Heavily based on lm75.c by Frodo Looijaard <frodol@dds.nl>. The LM77 * Heavily based on lm75.c by Frodo Looijaard <frodol@dds.nl>. The LM77
is a temperature sensor and thermal window comparator with 0.5 deg * is a temperature sensor and thermal window comparator with 0.5 deg
resolution made by National Semiconductor. Complete datasheet can be * resolution made by National Semiconductor. Complete datasheet can be
obtained at their site: * obtained at their site:
http://www.national.com/pf/LM/LM77.html * http://www.national.com/pf/LM/LM77.html
*
This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. * (at your option) any later version.
*
This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. * GNU General Public License for more details.
*
You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -49,7 +49,7 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, ...@@ -49,7 +49,7 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
/* Each client has this additional data */ /* Each client has this additional data */
struct lm77_data { struct lm77_data {
struct device *hwmon_dev; struct device *hwmon_dev;
struct mutex update_lock; struct mutex update_lock;
char valid; char valid;
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
...@@ -95,8 +95,10 @@ static struct i2c_driver lm77_driver = { ...@@ -95,8 +95,10 @@ static struct i2c_driver lm77_driver = {
#define LM77_TEMP_MIN (-55000) #define LM77_TEMP_MIN (-55000)
#define LM77_TEMP_MAX 125000 #define LM77_TEMP_MAX 125000
/* In the temperature registers, the low 3 bits are not part of the /*
temperature values; they are the status bits. */ * In the temperature registers, the low 3 bits are not part of the
* temperature values; they are the status bits.
*/
static inline s16 LM77_TEMP_TO_REG(int temp) static inline s16 LM77_TEMP_TO_REG(int temp)
{ {
int ntemp = SENSORS_LIMIT(temp, LM77_TEMP_MIN, LM77_TEMP_MAX); int ntemp = SENSORS_LIMIT(temp, LM77_TEMP_MIN, LM77_TEMP_MAX);
...@@ -112,7 +114,9 @@ static inline int LM77_TEMP_FROM_REG(s16 reg) ...@@ -112,7 +114,9 @@ static inline int LM77_TEMP_FROM_REG(s16 reg)
/* read routines for temperature limits */ /* read routines for temperature limits */
#define show(value) \ #define show(value) \
static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ static ssize_t show_##value(struct device *dev, \
struct device_attribute *attr, \
char *buf) \
{ \ { \
struct lm77_data *data = lm77_update_device(dev); \ struct lm77_data *data = lm77_update_device(dev); \
return sprintf(buf, "%d\n", data->value); \ return sprintf(buf, "%d\n", data->value); \
...@@ -124,17 +128,20 @@ show(temp_min); ...@@ -124,17 +128,20 @@ show(temp_min);
show(temp_max); show(temp_max);
/* read routines for hysteresis values */ /* read routines for hysteresis values */
static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_temp_crit_hyst(struct device *dev,
struct device_attribute *attr, char *buf)
{ {
struct lm77_data *data = lm77_update_device(dev); struct lm77_data *data = lm77_update_device(dev);
return sprintf(buf, "%d\n", data->temp_crit - data->temp_hyst); return sprintf(buf, "%d\n", data->temp_crit - data->temp_hyst);
} }
static ssize_t show_temp_min_hyst(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_temp_min_hyst(struct device *dev,
struct device_attribute *attr, char *buf)
{ {
struct lm77_data *data = lm77_update_device(dev); struct lm77_data *data = lm77_update_device(dev);
return sprintf(buf, "%d\n", data->temp_min + data->temp_hyst); return sprintf(buf, "%d\n", data->temp_min + data->temp_hyst);
} }
static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t show_temp_max_hyst(struct device *dev,
struct device_attribute *attr, char *buf)
{ {
struct lm77_data *data = lm77_update_device(dev); struct lm77_data *data = lm77_update_device(dev);
return sprintf(buf, "%d\n", data->temp_max - data->temp_hyst); return sprintf(buf, "%d\n", data->temp_max - data->temp_hyst);
...@@ -142,29 +149,42 @@ static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute *a ...@@ -142,29 +149,42 @@ static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute *a
/* write routines */ /* write routines */
#define set(value, reg) \ #define set(value, reg) \
static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, \
{ \ const char *buf, size_t count) \
struct i2c_client *client = to_i2c_client(dev); \ { \
struct lm77_data *data = i2c_get_clientdata(client); \ struct i2c_client *client = to_i2c_client(dev); \
long val = simple_strtol(buf, NULL, 10); \ struct lm77_data *data = i2c_get_clientdata(client); \
\ long val; \
mutex_lock(&data->update_lock); \ int err = kstrtol(buf, 10, &val); \
data->value = val; \ if (err) \
lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \ return err; \
mutex_unlock(&data->update_lock); \ \
return count; \ mutex_lock(&data->update_lock); \
data->value = val; \
lm77_write_value(client, reg, LM77_TEMP_TO_REG(data->value)); \
mutex_unlock(&data->update_lock); \
return count; \
} }
set(temp_min, LM77_REG_TEMP_MIN); set(temp_min, LM77_REG_TEMP_MIN);
set(temp_max, LM77_REG_TEMP_MAX); set(temp_max, LM77_REG_TEMP_MAX);
/* hysteresis is stored as a relative value on the chip, so it has to be /*
converted first */ * hysteresis is stored as a relative value on the chip, so it has to be
static ssize_t set_temp_crit_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) * converted first
*/
static ssize_t set_temp_crit_hyst(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm77_data *data = i2c_get_clientdata(client); struct lm77_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10); unsigned long val;
int err;
err = kstrtoul(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
data->temp_hyst = data->temp_crit - val; data->temp_hyst = data->temp_crit - val;
...@@ -175,13 +195,19 @@ static ssize_t set_temp_crit_hyst(struct device *dev, struct device_attribute *a ...@@ -175,13 +195,19 @@ static ssize_t set_temp_crit_hyst(struct device *dev, struct device_attribute *a
} }
/* preserve hysteresis when setting T_crit */ /* preserve hysteresis when setting T_crit */
static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm77_data *data = i2c_get_clientdata(client); struct lm77_data *data = i2c_get_clientdata(client);
long val = simple_strtoul(buf, NULL, 10);
int oldcrithyst; int oldcrithyst;
unsigned long val;
int err;
err = kstrtoul(buf, 10, &val);
if (err)
return err;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
oldcrithyst = data->temp_crit - data->temp_hyst; oldcrithyst = data->temp_crit - data->temp_hyst;
data->temp_crit = val; data->temp_crit = val;
...@@ -251,17 +277,19 @@ static int lm77_detect(struct i2c_client *new_client, ...@@ -251,17 +277,19 @@ static int lm77_detect(struct i2c_client *new_client,
I2C_FUNC_SMBUS_WORD_DATA)) I2C_FUNC_SMBUS_WORD_DATA))
return -ENODEV; return -ENODEV;
/* Here comes the remaining detection. Since the LM77 has no /*
register dedicated to identification, we have to rely on the * Here comes the remaining detection. Since the LM77 has no
following tricks: * register dedicated to identification, we have to rely on the
* following tricks:
1. the high 4 bits represent the sign and thus they should *
always be the same * 1. the high 4 bits represent the sign and thus they should
2. the high 3 bits are unused in the configuration register * always be the same
3. addresses 0x06 and 0x07 return the last read value * 2. the high 3 bits are unused in the configuration register
4. registers cycling over 8-address boundaries * 3. addresses 0x06 and 0x07 return the last read value
* 4. registers cycling over 8-address boundaries
Word-sized registers are high-byte first. */ *
* Word-sized registers are high-byte first.
*/
/* addresses cycling */ /* addresses cycling */
cur = i2c_smbus_read_word_data(new_client, 0); cur = i2c_smbus_read_word_data(new_client, 0);
...@@ -330,7 +358,8 @@ static int lm77_probe(struct i2c_client *new_client, ...@@ -330,7 +358,8 @@ static int lm77_probe(struct i2c_client *new_client,
lm77_init_client(new_client); lm77_init_client(new_client);
/* Register sysfs hooks */ /* Register sysfs hooks */
if ((err = sysfs_create_group(&new_client->dev.kobj, &lm77_group))) err = sysfs_create_group(&new_client->dev.kobj, &lm77_group);
if (err)
goto exit_free; goto exit_free;
data->hwmon_dev = hwmon_device_register(&new_client->dev); data->hwmon_dev = hwmon_device_register(&new_client->dev);
...@@ -358,8 +387,10 @@ static int lm77_remove(struct i2c_client *client) ...@@ -358,8 +387,10 @@ static int lm77_remove(struct i2c_client *client)
return 0; return 0;
} }
/* All registers are word-sized, except for the configuration register. /*
The LM77 uses the high-byte first convention. */ * All registers are word-sized, except for the configuration register.
* The LM77 uses the high-byte first convention.
*/
static u16 lm77_read_value(struct i2c_client *client, u8 reg) static u16 lm77_read_value(struct i2c_client *client, u8 reg)
{ {
if (reg == LM77_REG_CONF) if (reg == LM77_REG_CONF)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment