summaryrefslogtreecommitdiff
path: root/drivers/hwmon/adt7475.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2020-03-30 13:34:25 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2020-03-30 13:34:25 -0700
commit47acac8cae28b36668bf89400c56b7fdebca3e75 (patch)
treee3b4e97c3846f74ed7a34ebaccf95a71206c562c /drivers/hwmon/adt7475.c
parentff7b862a4c354793580545afa64c56fafa18952b (diff)
parent5b10a8194664a0d3b025f9b53de4476754ce8e41 (diff)
Merge tag 'hwmon-for-v5.7' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon updates from Guenter Roeck: - New driver for AXI fan control - Attenuator bypass support and support for inverting pwm output in adt7475 driver - Support for new power supply version in ibm-cffps driver - PMBus drivers: * support for multi-phase chips * ltc2978 driver: add support for LTC2972, LTC2979, LTC3884, LTC3889, LTC7880, LTM4664, LTM4677, LTM4678, LTM4680, and LTM4700/ * tps53679 driver: add support for TPS53681, TPS53647, and TPS53667 * isl68137 driver: support for various 2nd Gen Renesas digital multiphase chips added to isl68137 driver - Minor improvements and fixes in nct7904, ibmpowernv, lm73, ibmaem, and k10temp drivers * tag 'hwmon-for-v5.7' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: (29 commits) docs: hwmon: Update documentation for isl68137 pmbus driver hwmon: (pmbus) add support for 2nd Gen Renesas digital multiphase hwmon: (pmbus/ibm-cffps) Add another PSU CCIN to version detection hwmon: (nct7904) Fix the incorrect quantity for fan & temp attributes hwmon: (ibmpowernv) Use scnprintf() for avoiding potential buffer overflow hwmon: (adt7475) Add support for inverting pwm output hwmon: (adt7475) Add attenuator bypass support dt-bindings: hwmon: Document adt7475 pwm-active-state property dt-bindings: hwmon: Document adt7475 bypass-attenuator property dt-bindings: hwmon: Document adt7475 binding hwmon: (lm73) Add support for of_match_table dt-bindings: Add TI LM73 as a trivial device hwmon: (pmbus/tps53679) Add documentation hwmon: (pmbus/tps53679) Add support for TPS53647 and TPS53667 hwmon: (pmbus/tps53679) Add support for TPS53681 hwmon: (pmbus/tps53679) Add support for IIN and PIN to TPS53679 and TPS53688 hwmon: (pmbus/tps53679) Add support for multiple chips IDs hwmon: (pmbus) Implement multi-phase support hwmon: (pmbus) Add 'phase' parameter where needed for multi-phase support hwmon: (pmbus) Add IC_DEVICE_ID and IC_DEVICE_REV command definitions ...
Diffstat (limited to 'drivers/hwmon/adt7475.c')
-rw-r--r--drivers/hwmon/adt7475.c95
1 files changed, 92 insertions, 3 deletions
diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index 01c2eeb02aa9..054080443b47 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -19,6 +19,7 @@
#include <linux/hwmon-vid.h>
#include <linux/err.h>
#include <linux/jiffies.h>
+#include <linux/of.h>
#include <linux/util_macros.h>
/* Indexes for the sysfs hooks */
@@ -193,6 +194,7 @@ struct adt7475_data {
unsigned long measure_updated;
bool valid;
+ u8 config2;
u8 config4;
u8 config5;
u8 has_voltage;
@@ -1458,6 +1460,85 @@ static int adt7475_update_limits(struct i2c_client *client)
return 0;
}
+static int set_property_bit(const struct i2c_client *client, char *property,
+ u8 *config, u8 bit_index)
+{
+ u32 prop_value = 0;
+ int ret = of_property_read_u32(client->dev.of_node, property,
+ &prop_value);
+
+ if (!ret) {
+ if (prop_value)
+ *config |= (1 << bit_index);
+ else
+ *config &= ~(1 << bit_index);
+ }
+
+ return ret;
+}
+
+static int load_attenuators(const struct i2c_client *client, int chip,
+ struct adt7475_data *data)
+{
+ int ret;
+
+ if (chip == adt7476 || chip == adt7490) {
+ set_property_bit(client, "adi,bypass-attenuator-in0",
+ &data->config4, 4);
+ set_property_bit(client, "adi,bypass-attenuator-in1",
+ &data->config4, 5);
+ set_property_bit(client, "adi,bypass-attenuator-in3",
+ &data->config4, 6);
+ set_property_bit(client, "adi,bypass-attenuator-in4",
+ &data->config4, 7);
+
+ ret = i2c_smbus_write_byte_data(client, REG_CONFIG4,
+ data->config4);
+ if (ret < 0)
+ return ret;
+ } else if (chip == adt7473 || chip == adt7475) {
+ set_property_bit(client, "adi,bypass-attenuator-in1",
+ &data->config2, 5);
+
+ ret = i2c_smbus_write_byte_data(client, REG_CONFIG2,
+ data->config2);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
+static int adt7475_set_pwm_polarity(struct i2c_client *client)
+{
+ u32 states[ADT7475_PWM_COUNT];
+ int ret, i;
+ u8 val;
+
+ ret = of_property_read_u32_array(client->dev.of_node,
+ "adi,pwm-active-state", states,
+ ARRAY_SIZE(states));
+ if (ret)
+ return ret;
+
+ for (i = 0; i < ADT7475_PWM_COUNT; i++) {
+ ret = adt7475_read(PWM_CONFIG_REG(i));
+ if (ret < 0)
+ return ret;
+ val = ret;
+ if (states[i])
+ val &= ~BIT(4);
+ else
+ val |= BIT(4);
+
+ ret = i2c_smbus_write_byte_data(client, PWM_CONFIG_REG(i), val);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
static int adt7475_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
@@ -1472,7 +1553,7 @@ static int adt7475_probe(struct i2c_client *client,
struct adt7475_data *data;
struct device *hwmon_dev;
int i, ret = 0, revision, group_num = 0;
- u8 config2, config3;
+ u8 config3;
data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
if (data == NULL)
@@ -1546,8 +1627,12 @@ static int adt7475_probe(struct i2c_client *client,
}
/* Voltage attenuators can be bypassed, globally or individually */
- config2 = adt7475_read(REG_CONFIG2);
- if (config2 & CONFIG2_ATTN) {
+ data->config2 = adt7475_read(REG_CONFIG2);
+ ret = load_attenuators(client, chip, data);
+ if (ret)
+ dev_warn(&client->dev, "Error configuring attenuator bypass\n");
+
+ if (data->config2 & CONFIG2_ATTN) {
data->bypass_attn = (0x3 << 3) | 0x3;
} else {
data->bypass_attn = ((data->config4 & CONFIG4_ATTN_IN10) >> 4) |
@@ -1562,6 +1647,10 @@ static int adt7475_probe(struct i2c_client *client,
for (i = 0; i < ADT7475_PWM_COUNT; i++)
adt7475_read_pwm(client, i);
+ ret = adt7475_set_pwm_polarity(client);
+ if (ret && ret != -EINVAL)
+ dev_warn(&client->dev, "Error configuring pwm polarity\n");
+
/* Start monitoring */
switch (chip) {
case adt7475: