Lines Matching +full:2 +full:x32 +full:- +full:bit
1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
3 * LTC2992 - Dual Wide Range Power Monitor
62 #define LTC2992_POWER(x) (LTC2992_POWER1 + ((x) * 0x32))
63 #define LTC2992_POWER_MAX(x) (LTC2992_POWER1_MAX + ((x) * 0x32))
64 #define LTC2992_POWER_MIN(x) (LTC2992_POWER1_MIN + ((x) * 0x32))
65 #define LTC2992_POWER_MAX_THRESH(x) (LTC2992_POWER1_MAX_THRESH + ((x) * 0x32))
66 #define LTC2992_POWER_MIN_THRESH(x) (LTC2992_POWER1_MIN_THRESH + ((x) * 0x32))
67 #define LTC2992_DSENSE(x) (LTC2992_DSENSE1 + ((x) * 0x32))
68 #define LTC2992_DSENSE_MAX(x) (LTC2992_DSENSE1_MAX + ((x) * 0x32))
69 #define LTC2992_DSENSE_MIN(x) (LTC2992_DSENSE1_MIN + ((x) * 0x32))
70 #define LTC2992_DSENSE_MAX_THRESH(x) (LTC2992_DSENSE1_MAX_THRESH + ((x) * 0x32))
71 #define LTC2992_DSENSE_MIN_THRESH(x) (LTC2992_DSENSE1_MIN_THRESH + ((x) * 0x32))
72 #define LTC2992_SENSE(x) (LTC2992_SENSE1 + ((x) * 0x32))
73 #define LTC2992_SENSE_MAX(x) (LTC2992_SENSE1_MAX + ((x) * 0x32))
74 #define LTC2992_SENSE_MIN(x) (LTC2992_SENSE1_MIN + ((x) * 0x32))
75 #define LTC2992_SENSE_MAX_THRESH(x) (LTC2992_SENSE1_MAX_THRESH + ((x) * 0x32))
76 #define LTC2992_SENSE_MIN_THRESH(x) (LTC2992_SENSE1_MIN_THRESH + ((x) * 0x32))
77 #define LTC2992_POWER_FAULT(x) (LTC2992_FAULT1 + ((x) * 0x32))
78 #define LTC2992_SENSE_FAULT(x) (LTC2992_FAULT1 + ((x) * 0x32))
79 #define LTC2992_DSENSE_FAULT(x) (LTC2992_FAULT1 + ((x) * 0x32))
82 #define LTC2992_RESET_HISTORY BIT(3)
85 #define LTC2992_POWER_FAULT_MSK(x) (BIT(6) << (x))
86 #define LTC2992_DSENSE_FAULT_MSK(x) (BIT(4) << (x))
87 #define LTC2992_SENSE_FAULT_MSK(x) (BIT(2) << (x))
90 #define LTC2992_GPIO1_FAULT_MSK(x) (BIT(0) << (x))
93 #define LTC2992_GPIO2_FAULT_MSK(x) (BIT(0) << (x))
96 #define LTC2992_GPIO3_FAULT_MSK(x) (BIT(6) << (x))
97 #define LTC2992_GPIO4_FAULT_MSK(x) (BIT(4) << (x))
108 #define LTC2992_GPIO_BIT(x) (LTC2992_GPIO_NR - (x) - 1)
116 u32 r_sense_uohm[2];
194 ret = regmap_bulk_read(st->regmap, addr, regvals, reg_len); in ltc2992_read_reg()
200 val |= regvals[reg_len - i - 1] << (i * 8); in ltc2992_read_reg()
211 regvals[reg_len - i - 1] = (val >> (i * 8)) & 0xFF; in ltc2992_write_reg()
213 return regmap_bulk_write(st->regmap, addr, regvals, reg_len); in ltc2992_write_reg()
222 mutex_lock(&st->gpio_mutex); in ltc2992_gpio_get()
224 mutex_unlock(&st->gpio_mutex); in ltc2992_gpio_get()
242 mutex_lock(&st->gpio_mutex); in ltc2992_gpio_get_multiple()
244 mutex_unlock(&st->gpio_mutex); in ltc2992_gpio_get_multiple()
265 mutex_lock(&st->gpio_mutex); in ltc2992_gpio_set()
268 mutex_unlock(&st->gpio_mutex); in ltc2992_gpio_set()
276 mutex_unlock(&st->gpio_mutex); in ltc2992_gpio_set()
295 mutex_lock(&st->gpio_mutex); in ltc2992_gpio_set_multiple()
298 mutex_unlock(&st->gpio_mutex); in ltc2992_gpio_set_multiple()
303 const char *name = dev_name(&st->client->dev); in ltc2992_config_gpio()
312 mutex_init(&st->gpio_mutex); in ltc2992_config_gpio()
314 for (i = 0; i < ARRAY_SIZE(st->gpio_names); i++) { in ltc2992_config_gpio()
315 gpio_name = devm_kasprintf(&st->client->dev, GFP_KERNEL, "ltc2992-%x-%s", in ltc2992_config_gpio()
316 st->client->addr, ltc2992_gpio_names[i]); in ltc2992_config_gpio()
318 return -ENOMEM; in ltc2992_config_gpio()
320 st->gpio_names[i] = gpio_name; in ltc2992_config_gpio()
323 st->gc.label = name; in ltc2992_config_gpio()
324 st->gc.parent = &st->client->dev; in ltc2992_config_gpio()
325 st->gc.owner = THIS_MODULE; in ltc2992_config_gpio()
326 st->gc.can_sleep = true; in ltc2992_config_gpio()
327 st->gc.base = -1; in ltc2992_config_gpio()
328 st->gc.names = st->gpio_names; in ltc2992_config_gpio()
329 st->gc.ngpio = ARRAY_SIZE(st->gpio_names); in ltc2992_config_gpio()
330 st->gc.get = ltc2992_gpio_get; in ltc2992_config_gpio()
331 st->gc.get_multiple = ltc2992_gpio_get_multiple; in ltc2992_config_gpio()
332 st->gc.set = ltc2992_gpio_set; in ltc2992_config_gpio()
333 st->gc.set_multiple = ltc2992_gpio_set_multiple; in ltc2992_config_gpio()
335 ret = devm_gpiochip_add_data(&st->client->dev, &st->gc, st); in ltc2992_config_gpio()
337 dev_err(&st->client->dev, "GPIO registering failed (%d)\n", ret); in ltc2992_config_gpio()
374 if (st->r_sense_uohm[channel]) in ltc2992_is_visible()
379 if (st->r_sense_uohm[channel]) in ltc2992_is_visible()
391 if (st->r_sense_uohm[channel]) in ltc2992_is_visible()
396 if (st->r_sense_uohm[channel]) in ltc2992_is_visible()
412 reg_val = ltc2992_read_reg(st, reg, 2); in ltc2992_get_voltage()
427 return ltc2992_write_reg(st, reg, 2, val); in ltc2992_set_voltage()
475 return -EOPNOTSUPP; in ltc2992_read_gpios_in()
507 return ltc2992_read_gpios_in(dev, attr, channel - 2, val); in ltc2992_read_in()
529 return -EOPNOTSUPP; in ltc2992_read_in()
539 reg_val = ltc2992_read_reg(st, reg, 2); in ltc2992_get_current()
544 *val = DIV_ROUND_CLOSEST(reg_val * LTC2992_IADC_NANOV_LSB, st->r_sense_uohm[channel]); in ltc2992_get_current()
553 reg_val = DIV_ROUND_CLOSEST(val * st->r_sense_uohm[channel], LTC2992_IADC_NANOV_LSB); in ltc2992_set_current()
556 return ltc2992_write_reg(st, reg, 2, reg_val); in ltc2992_set_current()
604 return -EOPNOTSUPP; in ltc2992_read_curr()
619 st->r_sense_uohm[channel] * 1000); in ltc2992_get_power()
628 reg_val = mul_u64_u32_div(val, st->r_sense_uohm[channel] * 1000, in ltc2992_set_power()
679 return -EOPNOTSUPP; in ltc2992_read_power()
696 return -EOPNOTSUPP; in ltc2992_read()
713 return -EOPNOTSUPP; in ltc2992_write_curr()
732 return -EOPNOTSUPP; in ltc2992_write_gpios_in()
744 return ltc2992_write_gpios_in(dev, attr, channel - 2, val); in ltc2992_write_in()
754 return -EOPNOTSUPP; in ltc2992_write_in()
773 return -EOPNOTSUPP; in ltc2992_write_power()
785 return regmap_update_bits(st->regmap, LTC2992_CTRLB, LTC2992_RESET_HISTORY, in ltc2992_write_chip()
788 return -EOPNOTSUPP; in ltc2992_write_chip()
805 return -EOPNOTSUPP; in ltc2992_write()
861 device_for_each_child_node_scoped(&st->client->dev, child) { in ltc2992_parse_dt()
867 return -EINVAL; in ltc2992_parse_dt()
869 ret = fwnode_property_read_u32(child, "shunt-resistor-micro-ohms", &val); in ltc2992_parse_dt()
872 return dev_err_probe(&st->client->dev, -EINVAL, in ltc2992_parse_dt()
875 st->r_sense_uohm[addr] = val; in ltc2992_parse_dt()
888 st = devm_kzalloc(&client->dev, sizeof(*st), GFP_KERNEL); in ltc2992_i2c_probe()
890 return -ENOMEM; in ltc2992_i2c_probe()
892 st->client = client; in ltc2992_i2c_probe()
893 st->regmap = devm_regmap_init_i2c(client, <c2992_regmap_config); in ltc2992_i2c_probe()
894 if (IS_ERR(st->regmap)) in ltc2992_i2c_probe()
895 return PTR_ERR(st->regmap); in ltc2992_i2c_probe()
905 hwmon_dev = devm_hwmon_device_register_with_info(&client->dev, client->name, st, in ltc2992_i2c_probe()