aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Poulain <loic.poulain@linaro.org>2020-03-14 09:32:56 +0100
committerLoic Poulain <loic.poulain@linaro.org>2020-03-14 09:38:58 +0100
commitc756dc1c7685bd291fd06bbea53b97025cc25ef6 (patch)
tree8baf7b05dd6c2ea5dfc4e57a2fda760612043ea2
parent261a1cae51ef5f656de86882a87d12e6522aab95 (diff)
drivers: hwmon: tmp105: Add regmap supportlinaro_training_aa
Create an I2C regmap to simplify access to the sensor registers. There are four registers: 0: temperature value 1: configuration 2: max value threshold 3: min value threshold Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
-rw-r--r--drivers/hwmon/tmp105.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/drivers/hwmon/tmp105.c b/drivers/hwmon/tmp105.c
index cec57c6bcebd7..fabf84ff714be 100644
--- a/drivers/hwmon/tmp105.c
+++ b/drivers/hwmon/tmp105.c
@@ -12,6 +12,7 @@
#include <linux/hwmon.h>
#include <linux/pm_runtime.h>
#include <linux/delay.h>
+#include <linux/regmap.h>
#define TMP105_REG_TEMP 0x00
#define TMP105_REG_CTRL 0x01
@@ -20,6 +21,7 @@
struct tmp105_data {
struct i2c_client *client;
+ struct regmap *regmap;
struct delayed_work warn_work;
struct gpio_desc *alert;
int tmax;
@@ -89,7 +91,8 @@ static int tmp105_read(struct device *hwmon, enum hwmon_sensor_types type,
switch (attr) {
case hwmon_temp_input:
- *value = i2c_smbus_read_word_swapped(tmp105->client, TMP105_REG_TEMP);
+ regmap_read(tmp105->regmap, TMP105_REG_TEMP,
+ (unsigned int *)value);
*value = tmp105_reg_to_mc(*value);
break;
case hwmon_temp_max_alarm:
@@ -99,7 +102,8 @@ static int tmp105_read(struct device *hwmon, enum hwmon_sensor_types type,
break;
case hwmon_temp_max:
/* return t-high */
- *value = i2c_smbus_read_word_swapped(tmp105->client, TMP105_REG_THIG);
+ regmap_read(tmp105->regmap, TMP105_REG_THIG,
+ (unsigned int *)value);
*value = tmp105_reg_to_mc(*value);
break;
default:
@@ -128,10 +132,10 @@ static int tmp105_write(struct device *hwmon, enum hwmon_sensor_types type,
case hwmon_temp_max:
tmp105->tmax = value;
value = tmp105_mc_to_reg(value);
- i2c_smbus_write_word_swapped(tmp105->client, TMP105_REG_THIG,
- value);
- i2c_smbus_write_word_swapped(tmp105->client, TMP105_REG_TLOW,
- value);
+ regmap_write(tmp105->regmap, TMP105_REG_THIG,
+ (unsigned int)value);
+ regmap_write(tmp105->regmap, TMP105_REG_TLOW,
+ (unsigned int)value);
break;
default:
ret = -EOPNOTSUPP;
@@ -181,11 +185,19 @@ static const struct hwmon_chip_info tmp105_chip_info = {
.info = tmp105_info,
};
+static const struct regmap_config tmp105_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 16, /* all are 16-bit except conf reg */
+ .val_format_endian = REGMAP_ENDIAN_BIG,
+ .max_register = TMP105_REG_THIG,
+};
+
static int tmp105_probe(struct i2c_client *client,
const struct i2c_device_id *tmp105_id)
{
struct device *dev = &client->dev;
struct tmp105_data *tmp105;
+ struct regmap *regmap;
struct device *hwmon;
int err;
@@ -196,9 +208,17 @@ static int tmp105_probe(struct i2c_client *client,
if (!tmp105)
return -ENOMEM;
+ /* Create an I2C regmap */
+ regmap = devm_regmap_init_i2c(client, &tmp105_regmap_config);
+ if (IS_ERR(regmap)) {
+ dev_err(dev, "failed to allocate register map\n");
+ return PTR_ERR(regmap);
+ }
+
/* Link the i2c-device/tmp105 objects */
dev_set_drvdata(dev, tmp105);
tmp105->client = client;
+ tmp105->regmap = regmap;
/* init tmp105 struct */
INIT_DELAYED_WORK(&tmp105->warn_work, tmp105_warn_work);
@@ -235,8 +255,6 @@ static int tmp105_probe(struct i2c_client *client,
return PTR_ERR(hwmon);
return 0;
-
- //enable_irq_wake(gpiod_to_irq(tmp105->alert));
}
static int tmp105_remove(struct i2c_client *client)