Re: [PATCH v3 2/3] drivers: hwmon: Add W83773G driver
On Fri, Nov 10, 2017 at 10:49 PM, Guenter Roeckwrote: > On 11/08/2017 11:09 PM, Lei YU wrote: >> >> Nuvoton W83773G is a hardware monitor IC providing one local >> temperature and two remote temperature sensors. >> >> Signed-off-by: Lei YU > > > Nicely done. Couple of nitpicks left. > > Thanks! > Guenter > > >> --- >> v2: >> - Rewrite the driver using regmap >> - Add offset and update_interval >> v3: >> - Use devm_hwmon_device_register_with_info() with is_visible/read/write >> functions. >> --- >> drivers/hwmon/Kconfig | 10 ++ >> drivers/hwmon/Makefile | 1 + >> drivers/hwmon/w83773g.c | 348 >> >> 3 files changed, 359 insertions(+) >> create mode 100644 drivers/hwmon/w83773g.c >> >> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig >> index d654314..11c6248 100644 >> --- a/drivers/hwmon/Kconfig >> +++ b/drivers/hwmon/Kconfig >> @@ -1710,6 +1710,16 @@ config SENSORS_VT8231 >> This driver can also be built as a module. If so, the module >> will be called vt8231. >> +config SENSORS_W83773G >> + tristate "Nuvoton W83773G" >> + depends on I2C >> + help >> + If you say yes here you get support for the Nuvoton W83773G >> hardware >> + monitoring chip. >> + >> + This driver can also be built as a module. If so, the module >> + will be called w83773g. >> + >> config SENSORS_W83781D >> tristate "Winbond W83781D, W83782D, W83783S, Asus AS99127F" >> depends on I2C >> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile >> index c84d978..0649ad8 100644 >> --- a/drivers/hwmon/Makefile >> +++ b/drivers/hwmon/Makefile >> @@ -13,6 +13,7 @@ obj-$(CONFIG_SENSORS_ATK0110) += asus_atk0110.o >> # asb100, then w83781d go first, as they can override other drivers' >> addresses. >> obj-$(CONFIG_SENSORS_ASB100) += asb100.o >> obj-$(CONFIG_SENSORS_W83627HF)+= w83627hf.o >> +obj-$(CONFIG_SENSORS_W83773G) += w83773g.o >> obj-$(CONFIG_SENSORS_W83792D) += w83792d.o >> obj-$(CONFIG_SENSORS_W83793) += w83793.o >> obj-$(CONFIG_SENSORS_W83795) += w83795.o >> diff --git a/drivers/hwmon/w83773g.c b/drivers/hwmon/w83773g.c >> new file mode 100644 >> index 000..58ac45b >> --- /dev/null >> +++ b/drivers/hwmon/w83773g.c >> @@ -0,0 +1,348 @@ >> +/* >> + * Copyright (C) 2017 IBM Corp. >> + * >> + * 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 >> + * the Free Software Foundation; either version 2 of the License, or >> + * (at your option) any later version. >> + * >> + * Driver for the Nuvoton W83773G SMBus temperature sensor IC. >> + * Supported models: W83773G >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +/* Addresses to scan */ >> +static const unsigned short normal_i2c[] = { 0x4c, 0x4d, I2C_CLIENT_END >> }; >> + >> +/* W83773 has 3 channels */ >> +#define W83773_CHANNELS3 >> + >> +/* The W83773 registers */ >> +#define W83773_CONVERSION_RATE_REG_READ0x04 >> +#define W83773_CONVERSION_RATE_REG_WRITE 0x0A >> +#define W83773_MANUFACTURER_ID_REG 0xFE >> +#define W83773_LOCAL_TEMP 0x00 >> + >> +static const u8 W83773_STATUS[2] = { 0x02, 0x17 }; >> + >> +static const u8 W83773_TEMP_LSB[2] = { 0x10, 0x25 }; >> +static const u8 W83773_TEMP_MSB[2] = { 0x01, 0x24 }; >> + >> +static const u8 W83773_OFFSET_LSB[2] = { 0x12, 0x16 }; >> +static const u8 W83773_OFFSET_MSB[2] = { 0x11, 0x15 }; >> + >> +/* this is the number of sensors in the device */ >> +static const struct i2c_device_id w83773_id[] = { >> + { "w83773g" }, >> + { } >> +}; >> + >> +MODULE_DEVICE_TABLE(i2c, w83773_id); >> + >> +static const struct of_device_id w83773_of_match[] = { >> + { >> + .compatible = "nuvoton,w83773g" >> + }, >> + { }, >> +}; >> +MODULE_DEVICE_TABLE(of, w83773_of_match); >> + >> +static inline long temp_of_local(s8 reg) >> +{ >> + return reg * 1000; >> +} >> + >> +static inline long temp_of_remote(s8 hb, u8 lb) >> +{ >> + return (hb << 3 | lb >> 5) * 125; >> +} >> + >> +static int get_local_temp(struct regmap *regmap, long *val) >> +{ >> + unsigned int regval; >> + int ret; >> + >> + ret = regmap_read(regmap, W83773_LOCAL_TEMP, ); >> + if (ret < 0) >> + return ret; >> + >> + *val = temp_of_local(regval); >> + return 0; >> +} >> + >> +static int get_remote_temp(struct regmap *regmap, int index, long *val) >> +{ >> + unsigned int regval_high; >> + unsigned int regval_low; >> + int ret; >> + >> + ret = regmap_read(regmap, W83773_TEMP_MSB[index], _high); >> + if (ret < 0) >> + return ret; >> + >> + ret
Re: [PATCH v3 2/3] drivers: hwmon: Add W83773G driver
On Fri, Nov 10, 2017 at 10:49 PM, Guenter Roeck wrote: > On 11/08/2017 11:09 PM, Lei YU wrote: >> >> Nuvoton W83773G is a hardware monitor IC providing one local >> temperature and two remote temperature sensors. >> >> Signed-off-by: Lei YU > > > Nicely done. Couple of nitpicks left. > > Thanks! > Guenter > > >> --- >> v2: >> - Rewrite the driver using regmap >> - Add offset and update_interval >> v3: >> - Use devm_hwmon_device_register_with_info() with is_visible/read/write >> functions. >> --- >> drivers/hwmon/Kconfig | 10 ++ >> drivers/hwmon/Makefile | 1 + >> drivers/hwmon/w83773g.c | 348 >> >> 3 files changed, 359 insertions(+) >> create mode 100644 drivers/hwmon/w83773g.c >> >> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig >> index d654314..11c6248 100644 >> --- a/drivers/hwmon/Kconfig >> +++ b/drivers/hwmon/Kconfig >> @@ -1710,6 +1710,16 @@ config SENSORS_VT8231 >> This driver can also be built as a module. If so, the module >> will be called vt8231. >> +config SENSORS_W83773G >> + tristate "Nuvoton W83773G" >> + depends on I2C >> + help >> + If you say yes here you get support for the Nuvoton W83773G >> hardware >> + monitoring chip. >> + >> + This driver can also be built as a module. If so, the module >> + will be called w83773g. >> + >> config SENSORS_W83781D >> tristate "Winbond W83781D, W83782D, W83783S, Asus AS99127F" >> depends on I2C >> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile >> index c84d978..0649ad8 100644 >> --- a/drivers/hwmon/Makefile >> +++ b/drivers/hwmon/Makefile >> @@ -13,6 +13,7 @@ obj-$(CONFIG_SENSORS_ATK0110) += asus_atk0110.o >> # asb100, then w83781d go first, as they can override other drivers' >> addresses. >> obj-$(CONFIG_SENSORS_ASB100) += asb100.o >> obj-$(CONFIG_SENSORS_W83627HF)+= w83627hf.o >> +obj-$(CONFIG_SENSORS_W83773G) += w83773g.o >> obj-$(CONFIG_SENSORS_W83792D) += w83792d.o >> obj-$(CONFIG_SENSORS_W83793) += w83793.o >> obj-$(CONFIG_SENSORS_W83795) += w83795.o >> diff --git a/drivers/hwmon/w83773g.c b/drivers/hwmon/w83773g.c >> new file mode 100644 >> index 000..58ac45b >> --- /dev/null >> +++ b/drivers/hwmon/w83773g.c >> @@ -0,0 +1,348 @@ >> +/* >> + * Copyright (C) 2017 IBM Corp. >> + * >> + * 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 >> + * the Free Software Foundation; either version 2 of the License, or >> + * (at your option) any later version. >> + * >> + * Driver for the Nuvoton W83773G SMBus temperature sensor IC. >> + * Supported models: W83773G >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +/* Addresses to scan */ >> +static const unsigned short normal_i2c[] = { 0x4c, 0x4d, I2C_CLIENT_END >> }; >> + >> +/* W83773 has 3 channels */ >> +#define W83773_CHANNELS3 >> + >> +/* The W83773 registers */ >> +#define W83773_CONVERSION_RATE_REG_READ0x04 >> +#define W83773_CONVERSION_RATE_REG_WRITE 0x0A >> +#define W83773_MANUFACTURER_ID_REG 0xFE >> +#define W83773_LOCAL_TEMP 0x00 >> + >> +static const u8 W83773_STATUS[2] = { 0x02, 0x17 }; >> + >> +static const u8 W83773_TEMP_LSB[2] = { 0x10, 0x25 }; >> +static const u8 W83773_TEMP_MSB[2] = { 0x01, 0x24 }; >> + >> +static const u8 W83773_OFFSET_LSB[2] = { 0x12, 0x16 }; >> +static const u8 W83773_OFFSET_MSB[2] = { 0x11, 0x15 }; >> + >> +/* this is the number of sensors in the device */ >> +static const struct i2c_device_id w83773_id[] = { >> + { "w83773g" }, >> + { } >> +}; >> + >> +MODULE_DEVICE_TABLE(i2c, w83773_id); >> + >> +static const struct of_device_id w83773_of_match[] = { >> + { >> + .compatible = "nuvoton,w83773g" >> + }, >> + { }, >> +}; >> +MODULE_DEVICE_TABLE(of, w83773_of_match); >> + >> +static inline long temp_of_local(s8 reg) >> +{ >> + return reg * 1000; >> +} >> + >> +static inline long temp_of_remote(s8 hb, u8 lb) >> +{ >> + return (hb << 3 | lb >> 5) * 125; >> +} >> + >> +static int get_local_temp(struct regmap *regmap, long *val) >> +{ >> + unsigned int regval; >> + int ret; >> + >> + ret = regmap_read(regmap, W83773_LOCAL_TEMP, ); >> + if (ret < 0) >> + return ret; >> + >> + *val = temp_of_local(regval); >> + return 0; >> +} >> + >> +static int get_remote_temp(struct regmap *regmap, int index, long *val) >> +{ >> + unsigned int regval_high; >> + unsigned int regval_low; >> + int ret; >> + >> + ret = regmap_read(regmap, W83773_TEMP_MSB[index], _high); >> + if (ret < 0) >> + return ret; >> + >> + ret = regmap_read(regmap,
Re: [PATCH v3 2/3] drivers: hwmon: Add W83773G driver
On 11/08/2017 11:09 PM, Lei YU wrote: Nuvoton W83773G is a hardware monitor IC providing one local temperature and two remote temperature sensors. Signed-off-by: Lei YUNicely done. Couple of nitpicks left. Thanks! Guenter --- v2: - Rewrite the driver using regmap - Add offset and update_interval v3: - Use devm_hwmon_device_register_with_info() with is_visible/read/write functions. --- drivers/hwmon/Kconfig | 10 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/w83773g.c | 348 3 files changed, 359 insertions(+) create mode 100644 drivers/hwmon/w83773g.c diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index d654314..11c6248 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1710,6 +1710,16 @@ config SENSORS_VT8231 This driver can also be built as a module. If so, the module will be called vt8231. +config SENSORS_W83773G + tristate "Nuvoton W83773G" + depends on I2C + help + If you say yes here you get support for the Nuvoton W83773G hardware + monitoring chip. + + This driver can also be built as a module. If so, the module + will be called w83773g. + config SENSORS_W83781D tristate "Winbond W83781D, W83782D, W83783S, Asus AS99127F" depends on I2C diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index c84d978..0649ad8 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -13,6 +13,7 @@ obj-$(CONFIG_SENSORS_ATK0110) += asus_atk0110.o # asb100, then w83781d go first, as they can override other drivers' addresses. obj-$(CONFIG_SENSORS_ASB100) += asb100.o obj-$(CONFIG_SENSORS_W83627HF)+= w83627hf.o +obj-$(CONFIG_SENSORS_W83773G) += w83773g.o obj-$(CONFIG_SENSORS_W83792D) += w83792d.o obj-$(CONFIG_SENSORS_W83793) += w83793.o obj-$(CONFIG_SENSORS_W83795) += w83795.o diff --git a/drivers/hwmon/w83773g.c b/drivers/hwmon/w83773g.c new file mode 100644 index 000..58ac45b --- /dev/null +++ b/drivers/hwmon/w83773g.c @@ -0,0 +1,348 @@ +/* + * Copyright (C) 2017 IBM Corp. + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Driver for the Nuvoton W83773G SMBus temperature sensor IC. + * Supported models: W83773G + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* Addresses to scan */ +static const unsigned short normal_i2c[] = { 0x4c, 0x4d, I2C_CLIENT_END }; + +/* W83773 has 3 channels */ +#define W83773_CHANNELS3 + +/* The W83773 registers */ +#define W83773_CONVERSION_RATE_REG_READ0x04 +#define W83773_CONVERSION_RATE_REG_WRITE 0x0A +#define W83773_MANUFACTURER_ID_REG 0xFE +#define W83773_LOCAL_TEMP 0x00 + +static const u8 W83773_STATUS[2] = { 0x02, 0x17 }; + +static const u8 W83773_TEMP_LSB[2] = { 0x10, 0x25 }; +static const u8 W83773_TEMP_MSB[2] = { 0x01, 0x24 }; + +static const u8 W83773_OFFSET_LSB[2] = { 0x12, 0x16 }; +static const u8 W83773_OFFSET_MSB[2] = { 0x11, 0x15 }; + +/* this is the number of sensors in the device */ +static const struct i2c_device_id w83773_id[] = { + { "w83773g" }, + { } +}; + +MODULE_DEVICE_TABLE(i2c, w83773_id); + +static const struct of_device_id w83773_of_match[] = { + { + .compatible = "nuvoton,w83773g" + }, + { }, +}; +MODULE_DEVICE_TABLE(of, w83773_of_match); + +static inline long temp_of_local(s8 reg) +{ + return reg * 1000; +} + +static inline long temp_of_remote(s8 hb, u8 lb) +{ + return (hb << 3 | lb >> 5) * 125; +} + +static int get_local_temp(struct regmap *regmap, long *val) +{ + unsigned int regval; + int ret; + + ret = regmap_read(regmap, W83773_LOCAL_TEMP, ); + if (ret < 0) + return ret; + + *val = temp_of_local(regval); + return 0; +} + +static int get_remote_temp(struct regmap *regmap, int index, long *val) +{ + unsigned int regval_high; + unsigned int regval_low; + int ret; + + ret = regmap_read(regmap, W83773_TEMP_MSB[index], _high); + if (ret < 0) + return ret; + + ret = regmap_read(regmap, W83773_TEMP_LSB[index], _low); + if (ret < 0) + return ret; + + *val = temp_of_remote(regval_high, regval_low); + return 0; +} + +static int get_fault(struct regmap *regmap, int index, long *val) +{ + unsigned int regval; + int ret; + + ret = regmap_read(regmap, W83773_STATUS[index], ); + Drop the empty line please. + if (ret < 0) + return ret; + + *val = (u8)regval & 0x04 >> 2; + return 0; +} + +static int get_offset(struct
Re: [PATCH v3 2/3] drivers: hwmon: Add W83773G driver
On 11/08/2017 11:09 PM, Lei YU wrote: Nuvoton W83773G is a hardware monitor IC providing one local temperature and two remote temperature sensors. Signed-off-by: Lei YU Nicely done. Couple of nitpicks left. Thanks! Guenter --- v2: - Rewrite the driver using regmap - Add offset and update_interval v3: - Use devm_hwmon_device_register_with_info() with is_visible/read/write functions. --- drivers/hwmon/Kconfig | 10 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/w83773g.c | 348 3 files changed, 359 insertions(+) create mode 100644 drivers/hwmon/w83773g.c diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index d654314..11c6248 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1710,6 +1710,16 @@ config SENSORS_VT8231 This driver can also be built as a module. If so, the module will be called vt8231. +config SENSORS_W83773G + tristate "Nuvoton W83773G" + depends on I2C + help + If you say yes here you get support for the Nuvoton W83773G hardware + monitoring chip. + + This driver can also be built as a module. If so, the module + will be called w83773g. + config SENSORS_W83781D tristate "Winbond W83781D, W83782D, W83783S, Asus AS99127F" depends on I2C diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index c84d978..0649ad8 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -13,6 +13,7 @@ obj-$(CONFIG_SENSORS_ATK0110) += asus_atk0110.o # asb100, then w83781d go first, as they can override other drivers' addresses. obj-$(CONFIG_SENSORS_ASB100) += asb100.o obj-$(CONFIG_SENSORS_W83627HF)+= w83627hf.o +obj-$(CONFIG_SENSORS_W83773G) += w83773g.o obj-$(CONFIG_SENSORS_W83792D) += w83792d.o obj-$(CONFIG_SENSORS_W83793) += w83793.o obj-$(CONFIG_SENSORS_W83795) += w83795.o diff --git a/drivers/hwmon/w83773g.c b/drivers/hwmon/w83773g.c new file mode 100644 index 000..58ac45b --- /dev/null +++ b/drivers/hwmon/w83773g.c @@ -0,0 +1,348 @@ +/* + * Copyright (C) 2017 IBM Corp. + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Driver for the Nuvoton W83773G SMBus temperature sensor IC. + * Supported models: W83773G + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* Addresses to scan */ +static const unsigned short normal_i2c[] = { 0x4c, 0x4d, I2C_CLIENT_END }; + +/* W83773 has 3 channels */ +#define W83773_CHANNELS3 + +/* The W83773 registers */ +#define W83773_CONVERSION_RATE_REG_READ0x04 +#define W83773_CONVERSION_RATE_REG_WRITE 0x0A +#define W83773_MANUFACTURER_ID_REG 0xFE +#define W83773_LOCAL_TEMP 0x00 + +static const u8 W83773_STATUS[2] = { 0x02, 0x17 }; + +static const u8 W83773_TEMP_LSB[2] = { 0x10, 0x25 }; +static const u8 W83773_TEMP_MSB[2] = { 0x01, 0x24 }; + +static const u8 W83773_OFFSET_LSB[2] = { 0x12, 0x16 }; +static const u8 W83773_OFFSET_MSB[2] = { 0x11, 0x15 }; + +/* this is the number of sensors in the device */ +static const struct i2c_device_id w83773_id[] = { + { "w83773g" }, + { } +}; + +MODULE_DEVICE_TABLE(i2c, w83773_id); + +static const struct of_device_id w83773_of_match[] = { + { + .compatible = "nuvoton,w83773g" + }, + { }, +}; +MODULE_DEVICE_TABLE(of, w83773_of_match); + +static inline long temp_of_local(s8 reg) +{ + return reg * 1000; +} + +static inline long temp_of_remote(s8 hb, u8 lb) +{ + return (hb << 3 | lb >> 5) * 125; +} + +static int get_local_temp(struct regmap *regmap, long *val) +{ + unsigned int regval; + int ret; + + ret = regmap_read(regmap, W83773_LOCAL_TEMP, ); + if (ret < 0) + return ret; + + *val = temp_of_local(regval); + return 0; +} + +static int get_remote_temp(struct regmap *regmap, int index, long *val) +{ + unsigned int regval_high; + unsigned int regval_low; + int ret; + + ret = regmap_read(regmap, W83773_TEMP_MSB[index], _high); + if (ret < 0) + return ret; + + ret = regmap_read(regmap, W83773_TEMP_LSB[index], _low); + if (ret < 0) + return ret; + + *val = temp_of_remote(regval_high, regval_low); + return 0; +} + +static int get_fault(struct regmap *regmap, int index, long *val) +{ + unsigned int regval; + int ret; + + ret = regmap_read(regmap, W83773_STATUS[index], ); + Drop the empty line please. + if (ret < 0) + return ret; + + *val = (u8)regval & 0x04 >> 2; + return 0; +} + +static int get_offset(struct regmap *regmap, int
[PATCH v3 2/3] drivers: hwmon: Add W83773G driver
Nuvoton W83773G is a hardware monitor IC providing one local temperature and two remote temperature sensors. Signed-off-by: Lei YU--- v2: - Rewrite the driver using regmap - Add offset and update_interval v3: - Use devm_hwmon_device_register_with_info() with is_visible/read/write functions. --- drivers/hwmon/Kconfig | 10 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/w83773g.c | 348 3 files changed, 359 insertions(+) create mode 100644 drivers/hwmon/w83773g.c diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index d654314..11c6248 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1710,6 +1710,16 @@ config SENSORS_VT8231 This driver can also be built as a module. If so, the module will be called vt8231. +config SENSORS_W83773G + tristate "Nuvoton W83773G" + depends on I2C + help + If you say yes here you get support for the Nuvoton W83773G hardware + monitoring chip. + + This driver can also be built as a module. If so, the module + will be called w83773g. + config SENSORS_W83781D tristate "Winbond W83781D, W83782D, W83783S, Asus AS99127F" depends on I2C diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index c84d978..0649ad8 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -13,6 +13,7 @@ obj-$(CONFIG_SENSORS_ATK0110) += asus_atk0110.o # asb100, then w83781d go first, as they can override other drivers' addresses. obj-$(CONFIG_SENSORS_ASB100) += asb100.o obj-$(CONFIG_SENSORS_W83627HF) += w83627hf.o +obj-$(CONFIG_SENSORS_W83773G) += w83773g.o obj-$(CONFIG_SENSORS_W83792D) += w83792d.o obj-$(CONFIG_SENSORS_W83793) += w83793.o obj-$(CONFIG_SENSORS_W83795) += w83795.o diff --git a/drivers/hwmon/w83773g.c b/drivers/hwmon/w83773g.c new file mode 100644 index 000..58ac45b --- /dev/null +++ b/drivers/hwmon/w83773g.c @@ -0,0 +1,348 @@ +/* + * Copyright (C) 2017 IBM Corp. + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Driver for the Nuvoton W83773G SMBus temperature sensor IC. + * Supported models: W83773G + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* Addresses to scan */ +static const unsigned short normal_i2c[] = { 0x4c, 0x4d, I2C_CLIENT_END }; + +/* W83773 has 3 channels */ +#define W83773_CHANNELS3 + +/* The W83773 registers */ +#define W83773_CONVERSION_RATE_REG_READ0x04 +#define W83773_CONVERSION_RATE_REG_WRITE 0x0A +#define W83773_MANUFACTURER_ID_REG 0xFE +#define W83773_LOCAL_TEMP 0x00 + +static const u8 W83773_STATUS[2] = { 0x02, 0x17 }; + +static const u8 W83773_TEMP_LSB[2] = { 0x10, 0x25 }; +static const u8 W83773_TEMP_MSB[2] = { 0x01, 0x24 }; + +static const u8 W83773_OFFSET_LSB[2] = { 0x12, 0x16 }; +static const u8 W83773_OFFSET_MSB[2] = { 0x11, 0x15 }; + +/* this is the number of sensors in the device */ +static const struct i2c_device_id w83773_id[] = { + { "w83773g" }, + { } +}; + +MODULE_DEVICE_TABLE(i2c, w83773_id); + +static const struct of_device_id w83773_of_match[] = { + { + .compatible = "nuvoton,w83773g" + }, + { }, +}; +MODULE_DEVICE_TABLE(of, w83773_of_match); + +static inline long temp_of_local(s8 reg) +{ + return reg * 1000; +} + +static inline long temp_of_remote(s8 hb, u8 lb) +{ + return (hb << 3 | lb >> 5) * 125; +} + +static int get_local_temp(struct regmap *regmap, long *val) +{ + unsigned int regval; + int ret; + + ret = regmap_read(regmap, W83773_LOCAL_TEMP, ); + if (ret < 0) + return ret; + + *val = temp_of_local(regval); + return 0; +} + +static int get_remote_temp(struct regmap *regmap, int index, long *val) +{ + unsigned int regval_high; + unsigned int regval_low; + int ret; + + ret = regmap_read(regmap, W83773_TEMP_MSB[index], _high); + if (ret < 0) + return ret; + + ret = regmap_read(regmap, W83773_TEMP_LSB[index], _low); + if (ret < 0) + return ret; + + *val = temp_of_remote(regval_high, regval_low); + return 0; +} + +static int get_fault(struct regmap *regmap, int index, long *val) +{ + unsigned int regval; + int ret; + + ret = regmap_read(regmap, W83773_STATUS[index], ); + + if (ret < 0) + return ret; + + *val = (u8)regval & 0x04 >> 2; + return 0; +} + +static int get_offset(struct regmap *regmap, int index, long *val) +{ + unsigned int regval_high; + unsigned int regval_low; + int ret; + + ret =
[PATCH v3 2/3] drivers: hwmon: Add W83773G driver
Nuvoton W83773G is a hardware monitor IC providing one local temperature and two remote temperature sensors. Signed-off-by: Lei YU --- v2: - Rewrite the driver using regmap - Add offset and update_interval v3: - Use devm_hwmon_device_register_with_info() with is_visible/read/write functions. --- drivers/hwmon/Kconfig | 10 ++ drivers/hwmon/Makefile | 1 + drivers/hwmon/w83773g.c | 348 3 files changed, 359 insertions(+) create mode 100644 drivers/hwmon/w83773g.c diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index d654314..11c6248 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -1710,6 +1710,16 @@ config SENSORS_VT8231 This driver can also be built as a module. If so, the module will be called vt8231. +config SENSORS_W83773G + tristate "Nuvoton W83773G" + depends on I2C + help + If you say yes here you get support for the Nuvoton W83773G hardware + monitoring chip. + + This driver can also be built as a module. If so, the module + will be called w83773g. + config SENSORS_W83781D tristate "Winbond W83781D, W83782D, W83783S, Asus AS99127F" depends on I2C diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile index c84d978..0649ad8 100644 --- a/drivers/hwmon/Makefile +++ b/drivers/hwmon/Makefile @@ -13,6 +13,7 @@ obj-$(CONFIG_SENSORS_ATK0110) += asus_atk0110.o # asb100, then w83781d go first, as they can override other drivers' addresses. obj-$(CONFIG_SENSORS_ASB100) += asb100.o obj-$(CONFIG_SENSORS_W83627HF) += w83627hf.o +obj-$(CONFIG_SENSORS_W83773G) += w83773g.o obj-$(CONFIG_SENSORS_W83792D) += w83792d.o obj-$(CONFIG_SENSORS_W83793) += w83793.o obj-$(CONFIG_SENSORS_W83795) += w83795.o diff --git a/drivers/hwmon/w83773g.c b/drivers/hwmon/w83773g.c new file mode 100644 index 000..58ac45b --- /dev/null +++ b/drivers/hwmon/w83773g.c @@ -0,0 +1,348 @@ +/* + * Copyright (C) 2017 IBM Corp. + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Driver for the Nuvoton W83773G SMBus temperature sensor IC. + * Supported models: W83773G + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* Addresses to scan */ +static const unsigned short normal_i2c[] = { 0x4c, 0x4d, I2C_CLIENT_END }; + +/* W83773 has 3 channels */ +#define W83773_CHANNELS3 + +/* The W83773 registers */ +#define W83773_CONVERSION_RATE_REG_READ0x04 +#define W83773_CONVERSION_RATE_REG_WRITE 0x0A +#define W83773_MANUFACTURER_ID_REG 0xFE +#define W83773_LOCAL_TEMP 0x00 + +static const u8 W83773_STATUS[2] = { 0x02, 0x17 }; + +static const u8 W83773_TEMP_LSB[2] = { 0x10, 0x25 }; +static const u8 W83773_TEMP_MSB[2] = { 0x01, 0x24 }; + +static const u8 W83773_OFFSET_LSB[2] = { 0x12, 0x16 }; +static const u8 W83773_OFFSET_MSB[2] = { 0x11, 0x15 }; + +/* this is the number of sensors in the device */ +static const struct i2c_device_id w83773_id[] = { + { "w83773g" }, + { } +}; + +MODULE_DEVICE_TABLE(i2c, w83773_id); + +static const struct of_device_id w83773_of_match[] = { + { + .compatible = "nuvoton,w83773g" + }, + { }, +}; +MODULE_DEVICE_TABLE(of, w83773_of_match); + +static inline long temp_of_local(s8 reg) +{ + return reg * 1000; +} + +static inline long temp_of_remote(s8 hb, u8 lb) +{ + return (hb << 3 | lb >> 5) * 125; +} + +static int get_local_temp(struct regmap *regmap, long *val) +{ + unsigned int regval; + int ret; + + ret = regmap_read(regmap, W83773_LOCAL_TEMP, ); + if (ret < 0) + return ret; + + *val = temp_of_local(regval); + return 0; +} + +static int get_remote_temp(struct regmap *regmap, int index, long *val) +{ + unsigned int regval_high; + unsigned int regval_low; + int ret; + + ret = regmap_read(regmap, W83773_TEMP_MSB[index], _high); + if (ret < 0) + return ret; + + ret = regmap_read(regmap, W83773_TEMP_LSB[index], _low); + if (ret < 0) + return ret; + + *val = temp_of_remote(regval_high, regval_low); + return 0; +} + +static int get_fault(struct regmap *regmap, int index, long *val) +{ + unsigned int regval; + int ret; + + ret = regmap_read(regmap, W83773_STATUS[index], ); + + if (ret < 0) + return ret; + + *val = (u8)regval & 0x04 >> 2; + return 0; +} + +static int get_offset(struct regmap *regmap, int index, long *val) +{ + unsigned int regval_high; + unsigned int regval_low; + int ret; + + ret = regmap_read(regmap,