ltc2991.c (3bf3e21c15d4386a5f15118ec39bbc1b67ea5759) | ltc2991.c (34c76a51205a32f2665cc2ef1247b4408187d4f0) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 2023 Analog Devices, Inc. 4 * Author: Antoniu Miclaus <antoniu.miclaus@analog.com> 5 */ 6 7#include <linux/bitops.h> 8#include <linux/err.h> --- 40 unchanged lines hidden (view full) --- 49#define LTC2991_REPEAT_ACQ_EN BIT(4) 50#define LTC2991_T_INT_FILT_EN BIT(3) 51 52#define LTC2991_MAX_CHANNEL 4 53#define LTC2991_T_INT_CH_NR 4 54#define LTC2991_VCC_CH_NR 0 55 56struct ltc2991_state { | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (C) 2023 Analog Devices, Inc. 4 * Author: Antoniu Miclaus <antoniu.miclaus@analog.com> 5 */ 6 7#include <linux/bitops.h> 8#include <linux/err.h> --- 40 unchanged lines hidden (view full) --- 49#define LTC2991_REPEAT_ACQ_EN BIT(4) 50#define LTC2991_T_INT_FILT_EN BIT(3) 51 52#define LTC2991_MAX_CHANNEL 4 53#define LTC2991_T_INT_CH_NR 4 54#define LTC2991_VCC_CH_NR 0 55 56struct ltc2991_state { |
57 struct device *dev; | |
58 struct regmap *regmap; 59 u32 r_sense_uohm[LTC2991_MAX_CHANNEL]; 60 bool temp_en[LTC2991_MAX_CHANNEL]; 61}; 62 63static int ltc2991_read_reg(struct ltc2991_state *st, u8 addr, u8 reg_len, 64 int *val) 65{ --- 212 unchanged lines hidden (view full) --- 278}; 279 280static const struct regmap_config ltc2991_regmap_config = { 281 .reg_bits = 8, 282 .val_bits = 8, 283 .max_register = 0x1D, 284}; 285 | 57 struct regmap *regmap; 58 u32 r_sense_uohm[LTC2991_MAX_CHANNEL]; 59 bool temp_en[LTC2991_MAX_CHANNEL]; 60}; 61 62static int ltc2991_read_reg(struct ltc2991_state *st, u8 addr, u8 reg_len, 63 int *val) 64{ --- 212 unchanged lines hidden (view full) --- 277}; 278 279static const struct regmap_config ltc2991_regmap_config = { 280 .reg_bits = 8, 281 .val_bits = 8, 282 .max_register = 0x1D, 283}; 284 |
286static int ltc2991_init(struct ltc2991_state *st) | 285static int ltc2991_init(struct ltc2991_state *st, struct device *dev) |
287{ 288 struct fwnode_handle *child; 289 int ret; 290 u32 val, addr; 291 u8 v5_v8_reg_data = 0, v1_v4_reg_data = 0; 292 | 286{ 287 struct fwnode_handle *child; 288 int ret; 289 u32 val, addr; 290 u8 v5_v8_reg_data = 0, v1_v4_reg_data = 0; 291 |
293 ret = devm_regulator_get_enable(st->dev, "vcc"); | 292 ret = devm_regulator_get_enable(dev, "vcc"); |
294 if (ret) | 293 if (ret) |
295 return dev_err_probe(st->dev, ret, | 294 return dev_err_probe(dev, ret, |
296 "failed to enable regulator\n"); 297 | 295 "failed to enable regulator\n"); 296 |
298 device_for_each_child_node(st->dev, child) { | 297 device_for_each_child_node(dev, child) { |
299 ret = fwnode_property_read_u32(child, "reg", &addr); 300 if (ret < 0) { 301 fwnode_handle_put(child); 302 return ret; 303 } 304 305 if (addr > 3) { 306 fwnode_handle_put(child); 307 return -EINVAL; 308 } 309 310 ret = fwnode_property_read_u32(child, 311 "shunt-resistor-micro-ohms", 312 &val); 313 if (!ret) { 314 if (!val) | 298 ret = fwnode_property_read_u32(child, "reg", &addr); 299 if (ret < 0) { 300 fwnode_handle_put(child); 301 return ret; 302 } 303 304 if (addr > 3) { 305 fwnode_handle_put(child); 306 return -EINVAL; 307 } 308 309 ret = fwnode_property_read_u32(child, 310 "shunt-resistor-micro-ohms", 311 &val); 312 if (!ret) { 313 if (!val) |
315 return dev_err_probe(st->dev, -EINVAL, | 314 return dev_err_probe(dev, -EINVAL, |
316 "shunt resistor value cannot be zero\n"); 317 318 st->r_sense_uohm[addr] = val; 319 320 switch (addr) { 321 case 0: 322 v1_v4_reg_data |= LTC2991_V1_V2_DIFF_EN; 323 break; --- 32 unchanged lines hidden (view full) --- 356 default: 357 break; 358 } 359 } 360 } 361 362 ret = regmap_write(st->regmap, LTC2991_V5_V8_CTRL, v5_v8_reg_data); 363 if (ret) | 315 "shunt resistor value cannot be zero\n"); 316 317 st->r_sense_uohm[addr] = val; 318 319 switch (addr) { 320 case 0: 321 v1_v4_reg_data |= LTC2991_V1_V2_DIFF_EN; 322 break; --- 32 unchanged lines hidden (view full) --- 355 default: 356 break; 357 } 358 } 359 } 360 361 ret = regmap_write(st->regmap, LTC2991_V5_V8_CTRL, v5_v8_reg_data); 362 if (ret) |
364 return dev_err_probe(st->dev, ret, | 363 return dev_err_probe(dev, ret, |
365 "Error: Failed to set V5-V8 CTRL reg.\n"); 366 367 ret = regmap_write(st->regmap, LTC2991_V1_V4_CTRL, v1_v4_reg_data); 368 if (ret) | 364 "Error: Failed to set V5-V8 CTRL reg.\n"); 365 366 ret = regmap_write(st->regmap, LTC2991_V1_V4_CTRL, v1_v4_reg_data); 367 if (ret) |
369 return dev_err_probe(st->dev, ret, | 368 return dev_err_probe(dev, ret, |
370 "Error: Failed to set V1-V4 CTRL reg.\n"); 371 372 ret = regmap_write(st->regmap, LTC2991_PWM_TH_LSB_T_INT, 373 LTC2991_REPEAT_ACQ_EN); 374 if (ret) | 369 "Error: Failed to set V1-V4 CTRL reg.\n"); 370 371 ret = regmap_write(st->regmap, LTC2991_PWM_TH_LSB_T_INT, 372 LTC2991_REPEAT_ACQ_EN); 373 if (ret) |
375 return dev_err_probe(st->dev, ret, 376 "Error: Failed to set contiuous mode.\n"); | 374 return dev_err_probe(dev, ret, 375 "Error: Failed to set continuous mode.\n"); |
377 378 /* Enable all channels and trigger conversions */ 379 return regmap_write(st->regmap, LTC2991_CH_EN_TRIGGER, 380 LTC2991_V7_V8_EN | LTC2991_V5_V6_EN | 381 LTC2991_V3_V4_EN | LTC2991_V1_V2_EN | 382 LTC2991_T_INT_VCC_EN); 383} 384 385static int ltc2991_i2c_probe(struct i2c_client *client) 386{ 387 int ret; 388 struct device *hwmon_dev; 389 struct ltc2991_state *st; 390 391 st = devm_kzalloc(&client->dev, sizeof(*st), GFP_KERNEL); 392 if (!st) 393 return -ENOMEM; 394 | 376 377 /* Enable all channels and trigger conversions */ 378 return regmap_write(st->regmap, LTC2991_CH_EN_TRIGGER, 379 LTC2991_V7_V8_EN | LTC2991_V5_V6_EN | 380 LTC2991_V3_V4_EN | LTC2991_V1_V2_EN | 381 LTC2991_T_INT_VCC_EN); 382} 383 384static int ltc2991_i2c_probe(struct i2c_client *client) 385{ 386 int ret; 387 struct device *hwmon_dev; 388 struct ltc2991_state *st; 389 390 st = devm_kzalloc(&client->dev, sizeof(*st), GFP_KERNEL); 391 if (!st) 392 return -ENOMEM; 393 |
395 st->dev = &client->dev; | |
396 st->regmap = devm_regmap_init_i2c(client, <c2991_regmap_config); 397 if (IS_ERR(st->regmap)) 398 return PTR_ERR(st->regmap); 399 | 394 st->regmap = devm_regmap_init_i2c(client, <c2991_regmap_config); 395 if (IS_ERR(st->regmap)) 396 return PTR_ERR(st->regmap); 397 |
400 ret = ltc2991_init(st); | 398 ret = ltc2991_init(st, &client->dev); |
401 if (ret) 402 return ret; 403 404 hwmon_dev = devm_hwmon_device_register_with_info(&client->dev, 405 client->name, st, 406 <c2991_chip_info, 407 NULL); 408 --- 29 unchanged lines hidden --- | 399 if (ret) 400 return ret; 401 402 hwmon_dev = devm_hwmon_device_register_with_info(&client->dev, 403 client->name, st, 404 <c2991_chip_info, 405 NULL); 406 --- 29 unchanged lines hidden --- |