Lines Matching +full:channel +full:- +full:7

1 // SPDX-License-Identifier: GPL-2.0-or-later
24 #define TMP464_NUM_CHANNELS 5 /* chan 0 is internal, 1-4 are remote */
25 #define TMP468_NUM_CHANNELS 9 /* chan 0 is internal, 1-8 are remote */
29 #define TMP464_TEMP_REG(channel) (channel) argument
30 #define TMP464_TEMP_OFFSET_REG(channel) (0x40 + ((channel) - 1) * 8) argument
31 #define TMP464_N_FACTOR_REG(channel) (0x41 + ((channel) - 1) * 8) argument
52 #define TMP464_CONFIG_REG_REN(x) (BIT(7 + (x)))
53 #define TMP464_CONFIG_REG_REN_MASK GENMASK(15, 7)
102 struct tmp464_channel channel[MAX_CHANNELS]; member
122 struct regmap *regmap = data->regmap; in tmp464_enable_channels()
126 for (i = 0; i < data->channels; i++) in tmp464_enable_channels()
127 if (data->channel[i].enabled) in tmp464_enable_channels()
133 static int tmp464_chip_read(struct device *dev, u32 attr, int channel, long *val) in tmp464_chip_read() argument
139 *val = data->update_interval; in tmp464_chip_read()
142 return -EOPNOTSUPP; in tmp464_chip_read()
146 static int tmp464_temp_read(struct device *dev, u32 attr, int channel, long *val) in tmp464_temp_read() argument
149 struct regmap *regmap = data->regmap; in tmp464_temp_read()
153 mutex_lock(&data->update_lock); in tmp464_temp_read()
160 *val = !!(regval & BIT(channel + 7)); in tmp464_temp_read()
166 *val = !!(regval & BIT(channel + 7)); in tmp464_temp_read()
175 if (!data->valid || time_after(jiffies, data->last_updated + in tmp464_temp_read()
176 msecs_to_jiffies(data->update_interval))) { in tmp464_temp_read()
180 data->open_reg = regval; in tmp464_temp_read()
181 data->last_updated = jiffies; in tmp464_temp_read()
182 data->valid = true; in tmp464_temp_read()
184 *val = !!(data->open_reg & BIT(channel + 7)); in tmp464_temp_read()
187 err = regmap_read(regmap, TMP464_THERM_LIMIT[channel], &regval); in tmp464_temp_read()
193 regval -= regval2; in tmp464_temp_read()
197 err = regmap_read(regmap, TMP464_THERM_LIMIT[channel], &regval); in tmp464_temp_read()
203 err = regmap_read(regmap, TMP464_THERM2_LIMIT[channel], &regval); in tmp464_temp_read()
209 regval -= regval2; in tmp464_temp_read()
213 err = regmap_read(regmap, TMP464_THERM2_LIMIT[channel], &regval); in tmp464_temp_read()
219 err = regmap_read(regmap, TMP464_TEMP_OFFSET_REG(channel), &regval); in tmp464_temp_read()
225 if (!data->channel[channel].enabled) { in tmp464_temp_read()
226 err = -ENODATA; in tmp464_temp_read()
229 err = regmap_read(regmap, TMP464_TEMP_REG(channel), &regval); in tmp464_temp_read()
235 *val = data->channel[channel].enabled; in tmp464_temp_read()
238 err = -EOPNOTSUPP; in tmp464_temp_read()
242 mutex_unlock(&data->update_lock); in tmp464_temp_read()
248 u32 attr, int channel, long *val) in tmp464_read() argument
252 return tmp464_chip_read(dev, attr, channel, val); in tmp464_read()
254 return tmp464_temp_read(dev, attr, channel, val); in tmp464_read()
256 return -EOPNOTSUPP; in tmp464_read()
261 u32 attr, int channel, const char **str) in tmp464_read_string() argument
265 *str = data->channel[channel].label; in tmp464_read_string()
275 * For valid rates, interval in milli-seconds can be calculated as in tmp464_set_convrate()
276 * interval = 125 << (7 - rate); in tmp464_set_convrate()
278 * interval = (1 << (7 - rate)) * 125; in tmp464_set_convrate()
280 * rate = 7 - __fls(interval / 125); in tmp464_set_convrate()
282 * rate = 7 - __fls(interval * 4 / (125 * 3)); in tmp464_set_convrate()
287 rate = 7 - __fls(interval * 4 / (125 * 3)); in tmp464_set_convrate()
288 data->update_interval = 125 << (7 - rate); in tmp464_set_convrate()
290 return regmap_update_bits(data->regmap, TMP464_CONFIG_REG, in tmp464_set_convrate()
295 static int tmp464_chip_write(struct tmp464_data *data, u32 attr, int channel, long val) in tmp464_chip_write() argument
301 return -EOPNOTSUPP; in tmp464_chip_write()
305 static int tmp464_temp_write(struct tmp464_data *data, u32 attr, int channel, long val) in tmp464_temp_write() argument
307 struct regmap *regmap = data->regmap; in tmp464_temp_write()
316 val = clamp_val(val, -256000, 256000); /* prevent overflow/underflow */ in tmp464_temp_write()
317 val = clamp_val(temp_from_reg(regval) - val, 0, 255000); in tmp464_temp_write()
319 DIV_ROUND_CLOSEST(val, 1000) << 7); in tmp464_temp_write()
322 val = temp_to_limit_reg(clamp_val(val, -255000, 255500)); in tmp464_temp_write()
323 err = regmap_write(regmap, TMP464_THERM_LIMIT[channel], val); in tmp464_temp_write()
326 val = temp_to_limit_reg(clamp_val(val, -255000, 255500)); in tmp464_temp_write()
327 err = regmap_write(regmap, TMP464_THERM2_LIMIT[channel], val); in tmp464_temp_write()
330 val = temp_to_offset_reg(clamp_val(val, -128000, 127937)); in tmp464_temp_write()
331 err = regmap_write(regmap, TMP464_TEMP_OFFSET_REG(channel), val); in tmp464_temp_write()
334 data->channel[channel].enabled = !!val; in tmp464_temp_write()
338 err = -EOPNOTSUPP; in tmp464_temp_write()
346 u32 attr, int channel, long val) in tmp464_write() argument
351 mutex_lock(&data->update_lock); in tmp464_write()
355 err = tmp464_chip_write(data, attr, channel, val); in tmp464_write()
358 err = tmp464_temp_write(data, attr, channel, val); in tmp464_write()
361 err = -EOPNOTSUPP; in tmp464_write()
365 mutex_unlock(&data->update_lock); in tmp464_write()
371 u32 attr, int channel) in tmp464_is_visible() argument
375 if (channel >= data->channels) in tmp464_is_visible()
395 if (!channel) in tmp464_is_visible()
399 if (data->channel[channel].label) in tmp464_is_visible()
403 if (channel) in tmp464_is_visible()
407 if (channel) in tmp464_is_visible()
424 regmap_write(data->regmap, TMP464_CONFIG_REG, data->config_orig); in tmp464_restore_config()
429 struct regmap *regmap = data->regmap; in tmp464_init_client()
450 data->config_orig = regval; in tmp464_init_client()
463 data->update_interval = 500; in tmp464_init_client()
471 struct i2c_adapter *adapter = client->adapter; in tmp464_detect()
476 return -ENODEV; in tmp464_detect()
482 return -ENODEV; in tmp464_detect()
489 return -ENODEV; in tmp464_detect()
494 return -ENODEV; in tmp464_detect()
509 return -ENODEV; in tmp464_detect()
512 strscpy(info->type, name, I2C_NAME_SIZE); in tmp464_detect()
513 dev_info(&adapter->dev, "Detected TI %s chip at 0x%02x\n", chip, client->addr); in tmp464_detect()
523 struct regmap *regmap = data->regmap; in tmp464_probe_child_from_dt()
524 u32 channel; in tmp464_probe_child_from_dt() local
528 err = of_property_read_u32(child, "reg", &channel); in tmp464_probe_child_from_dt()
534 if (channel >= data->channels) { in tmp464_probe_child_from_dt()
535 dev_err(dev, "invalid reg %d of %pOFn\n", channel, child); in tmp464_probe_child_from_dt()
536 return -EINVAL; in tmp464_probe_child_from_dt()
539 of_property_read_string(child, "label", &data->channel[channel].label); in tmp464_probe_child_from_dt()
541 data->channel[channel].enabled = of_device_is_available(child); in tmp464_probe_child_from_dt()
543 err = of_property_read_s32(child, "ti,n-factor", &nfactor); in tmp464_probe_child_from_dt()
544 if (err && err != -EINVAL) in tmp464_probe_child_from_dt()
547 if (channel == 0) { in tmp464_probe_child_from_dt()
548 dev_err(dev, "n-factor can't be set for internal channel\n"); in tmp464_probe_child_from_dt()
549 return -EINVAL; in tmp464_probe_child_from_dt()
551 if (nfactor > 127 || nfactor < -128) { in tmp464_probe_child_from_dt()
552 dev_err(dev, "n-factor for channel %d invalid (%d)\n", in tmp464_probe_child_from_dt()
553 channel, nfactor); in tmp464_probe_child_from_dt()
554 return -EINVAL; in tmp464_probe_child_from_dt()
556 err = regmap_write(regmap, TMP464_N_FACTOR_REG(channel), in tmp464_probe_child_from_dt()
567 const struct device_node *np = dev->of_node; in tmp464_probe_from_dt()
572 if (strcmp(child->name, "channel")) in tmp464_probe_from_dt()
654 struct device *dev = &client->dev; in tmp464_probe()
659 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WORD_DATA)) { in tmp464_probe()
660 dev_err(&client->dev, "i2c functionality check failed\n"); in tmp464_probe()
661 return -ENODEV; in tmp464_probe()
665 return -ENOMEM; in tmp464_probe()
667 mutex_init(&data->update_lock); in tmp464_probe()
669 if (dev->of_node) in tmp464_probe()
670 data->channels = (int)(unsigned long)of_device_get_match_data(&client->dev); in tmp464_probe()
672 data->channels = i2c_match_id(tmp464_id, client)->driver_data; in tmp464_probe()
674 data->regmap = devm_regmap_init_i2c(client, &tmp464_regmap_config); in tmp464_probe()
675 if (IS_ERR(data->regmap)) in tmp464_probe()
676 return PTR_ERR(data->regmap); in tmp464_probe()
678 for (i = 0; i < data->channels; i++) in tmp464_probe()
679 data->channel[i].enabled = true; in tmp464_probe()
685 if (dev->of_node) { in tmp464_probe()
691 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, in tmp464_probe()