summaryrefslogtreecommitdiff
path: root/drivers/hwmon/nct7904.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/nct7904.c')
-rw-r--r--drivers/hwmon/nct7904.c71
1 files changed, 28 insertions, 43 deletions
diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c
index b1c837fc407a..2fa091720c79 100644
--- a/drivers/hwmon/nct7904.c
+++ b/drivers/hwmon/nct7904.c
@@ -21,7 +21,6 @@
#include <linux/device.h>
#include <linux/init.h>
#include <linux/i2c.h>
-#include <linux/mutex.h>
#include <linux/hwmon.h>
#include <linux/watchdog.h>
@@ -128,7 +127,6 @@ static const unsigned short normal_i2c[] = {
struct nct7904_data {
struct i2c_client *client;
struct watchdog_device wdt;
- struct mutex bank_lock;
int bank_sel;
u32 fanin_mask;
u32 vsen_mask;
@@ -142,24 +140,19 @@ struct nct7904_data {
};
/* Access functions */
-static int nct7904_bank_lock(struct nct7904_data *data, unsigned int bank)
+static int nct7904_bank_select(struct nct7904_data *data, unsigned int bank)
{
int ret;
- mutex_lock(&data->bank_lock);
if (data->bank_sel == bank)
return 0;
ret = i2c_smbus_write_byte_data(data->client, BANK_SEL_REG, bank);
- if (ret == 0)
- data->bank_sel = bank;
- else
+ if (ret < 0) {
data->bank_sel = -1;
- return ret;
-}
-
-static inline void nct7904_bank_release(struct nct7904_data *data)
-{
- mutex_unlock(&data->bank_lock);
+ return ret;
+ }
+ data->bank_sel = bank;
+ return 0;
}
/* Read 1-byte register. Returns unsigned reg or -ERRNO on error. */
@@ -169,12 +162,10 @@ static int nct7904_read_reg(struct nct7904_data *data,
struct i2c_client *client = data->client;
int ret;
- ret = nct7904_bank_lock(data, bank);
- if (ret == 0)
- ret = i2c_smbus_read_byte_data(client, reg);
-
- nct7904_bank_release(data);
- return ret;
+ ret = nct7904_bank_select(data, bank);
+ if (ret < 0)
+ return ret;
+ return i2c_smbus_read_byte_data(client, reg);
}
/*
@@ -187,19 +178,16 @@ static int nct7904_read_reg16(struct nct7904_data *data,
struct i2c_client *client = data->client;
int ret, hi;
- ret = nct7904_bank_lock(data, bank);
- if (ret == 0) {
- ret = i2c_smbus_read_byte_data(client, reg);
- if (ret >= 0) {
- hi = ret;
- ret = i2c_smbus_read_byte_data(client, reg + 1);
- if (ret >= 0)
- ret |= hi << 8;
- }
- }
-
- nct7904_bank_release(data);
- return ret;
+ ret = nct7904_bank_select(data, bank);
+ if (ret < 0)
+ return ret;
+ hi = i2c_smbus_read_byte_data(client, reg);
+ if (hi < 0)
+ return hi;
+ ret = i2c_smbus_read_byte_data(client, reg + 1);
+ if (ret < 0)
+ return ret;
+ return ret | (hi << 8);
}
/* Write 1-byte register. Returns 0 or -ERRNO on error. */
@@ -209,12 +197,10 @@ static int nct7904_write_reg(struct nct7904_data *data,
struct i2c_client *client = data->client;
int ret;
- ret = nct7904_bank_lock(data, bank);
- if (ret == 0)
- ret = i2c_smbus_write_byte_data(client, reg, val);
-
- nct7904_bank_release(data);
- return ret;
+ ret = nct7904_bank_select(data, bank);
+ if (ret < 0)
+ return ret;
+ return i2c_smbus_write_byte_data(client, reg, val);
}
static int nct7904_read_fan(struct device *dev, u32 attr, int channel,
@@ -798,12 +784,12 @@ static int nct7904_detect(struct i2c_client *client,
(i2c_smbus_read_byte_data(client, BANK_SEL_REG) & 0xf8) != 0x00)
return -ENODEV;
- strlcpy(info->type, "nct7904", I2C_NAME_SIZE);
+ strscpy(info->type, "nct7904", I2C_NAME_SIZE);
return 0;
}
-static const struct hwmon_channel_info *nct7904_info[] = {
+static const struct hwmon_channel_info * const nct7904_info[] = {
HWMON_CHANNEL_INFO(in,
/* dummy, skipped in is_visible */
HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX |
@@ -1023,7 +1009,6 @@ static int nct7904_probe(struct i2c_client *client)
return -ENOMEM;
data->client = client;
- mutex_init(&data->bank_lock);
data->bank_sel = -1;
/* Setup sensor groups. */
@@ -1161,7 +1146,7 @@ static int nct7904_probe(struct i2c_client *client)
}
static const struct i2c_device_id nct7904_id[] = {
- {"nct7904", 0},
+ {"nct7904"},
{}
};
MODULE_DEVICE_TABLE(i2c, nct7904_id);
@@ -1171,7 +1156,7 @@ static struct i2c_driver nct7904_driver = {
.driver = {
.name = "nct7904",
},
- .probe_new = nct7904_probe,
+ .probe = nct7904_probe,
.id_table = nct7904_id,
.detect = nct7904_detect,
.address_list = normal_i2c,