Lines Matching +full:data +full:- +full:channel
1 // SPDX-License-Identifier: GPL-2.0-or-later
20 #include <linux/hwmon-sysfs.h>
72 .data = (void *)2
76 .data = (void *)3
80 .data = (void *)4
84 .data = (void *)2
88 .data = (void *)3
111 struct tmp421_channel channel[MAX_CHANNELS]; member
120 temp = temp - 64 * 256; in temp_from_raw()
127 static int tmp421_update_device(struct tmp421_data *data) in tmp421_update_device() argument
129 struct i2c_client *client = data->client; in tmp421_update_device()
133 mutex_lock(&data->update_lock); in tmp421_update_device()
135 if (time_after(jiffies, data->last_updated + (HZ / 2)) || in tmp421_update_device()
136 !data->valid) { in tmp421_update_device()
140 data->config = ret; in tmp421_update_device()
142 for (i = 0; i < data->channels; i++) { in tmp421_update_device()
146 data->channel[i].temp = ret << 8; in tmp421_update_device()
151 data->channel[i].temp |= ret; in tmp421_update_device()
153 data->last_updated = jiffies; in tmp421_update_device()
154 data->valid = true; in tmp421_update_device()
158 mutex_unlock(&data->update_lock); in tmp421_update_device()
161 data->valid = false; in tmp421_update_device()
168 static int tmp421_enable_channels(struct tmp421_data *data) in tmp421_enable_channels() argument
171 struct i2c_client *client = data->client; in tmp421_enable_channels()
172 struct device *dev = &client->dev; in tmp421_enable_channels()
182 for (i = 0; i < data->channels; i++) in tmp421_enable_channels()
183 if (data->channel[i].enabled) in tmp421_enable_channels()
197 u32 attr, int channel, long *val) in tmp421_read() argument
208 if (!tmp421->channel[channel].enabled) in tmp421_read()
209 return -ENODATA; in tmp421_read()
210 *val = temp_from_raw(tmp421->channel[channel].temp, in tmp421_read()
211 tmp421->config & TMP421_CONFIG_RANGE); in tmp421_read()
214 if (!tmp421->channel[channel].enabled) in tmp421_read()
215 return -ENODATA; in tmp421_read()
220 *val = !!(tmp421->channel[channel].temp & 0x03); in tmp421_read()
223 *val = tmp421->channel[channel].enabled; in tmp421_read()
226 return -EOPNOTSUPP; in tmp421_read()
232 u32 attr, int channel, const char **str) in tmp421_read_string() argument
234 struct tmp421_data *data = dev_get_drvdata(dev); in tmp421_read_string() local
236 *str = data->channel[channel].label; in tmp421_read_string()
242 u32 attr, int channel, long val) in tmp421_write() argument
244 struct tmp421_data *data = dev_get_drvdata(dev); in tmp421_write() local
249 data->channel[channel].enabled = val; in tmp421_write()
250 ret = tmp421_enable_channels(data); in tmp421_write()
253 ret = -EOPNOTSUPP; in tmp421_write()
259 static umode_t tmp421_is_visible(const void *data, enum hwmon_sensor_types type, in tmp421_is_visible() argument
260 u32 attr, int channel) in tmp421_is_visible() argument
275 static int tmp421_init_client(struct tmp421_data *data) in tmp421_init_client() argument
278 struct i2c_client *client = data->client; in tmp421_init_client()
286 dev_err(&client->dev, in tmp421_init_client()
295 dev_info(&client->dev, "Enable monitoring chip\n"); in tmp421_init_client()
299 return tmp421_enable_channels(data); in tmp421_init_client()
306 struct i2c_adapter *adapter = client->adapter; in tmp421_detect()
311 int addr = client->addr; in tmp421_detect()
315 return -ENODEV; in tmp421_detect()
319 return -ENODEV; in tmp421_detect()
323 return -ENODEV; in tmp421_detect()
327 return -ENODEV; in tmp421_detect()
336 return -ENODEV; in tmp421_detect()
341 return -ENODEV; in tmp421_detect()
349 return -ENODEV; in tmp421_detect()
353 return -ENODEV; in tmp421_detect()
356 strscpy(info->type, tmp421_id[kind].name, I2C_NAME_SIZE); in tmp421_detect()
357 dev_info(&adapter->dev, "Detected TI %s chip at 0x%02x\n", in tmp421_detect()
358 names[kind], client->addr); in tmp421_detect()
365 struct tmp421_data *data) in tmp421_probe_child_from_dt() argument
368 struct device *dev = &client->dev; in tmp421_probe_child_from_dt()
379 if (i >= data->channels) { in tmp421_probe_child_from_dt()
381 return -EINVAL; in tmp421_probe_child_from_dt()
384 of_property_read_string(child, "label", &data->channel[i].label); in tmp421_probe_child_from_dt()
385 if (data->channel[i].label) in tmp421_probe_child_from_dt()
386 data->temp_config[i] |= HWMON_T_LABEL; in tmp421_probe_child_from_dt()
388 data->channel[i].enabled = of_device_is_available(child); in tmp421_probe_child_from_dt()
390 err = of_property_read_s32(child, "ti,n-factor", &val); in tmp421_probe_child_from_dt()
393 dev_err(dev, "n-factor can't be set for internal channel\n"); in tmp421_probe_child_from_dt()
394 return -EINVAL; in tmp421_probe_child_from_dt()
397 if (val > 127 || val < -128) { in tmp421_probe_child_from_dt()
398 dev_err(dev, "n-factor for channel %d invalid (%d)\n", in tmp421_probe_child_from_dt()
400 return -EINVAL; in tmp421_probe_child_from_dt()
402 i2c_smbus_write_byte_data(client, TMP421_N_FACTOR_REG_1 + i - 1, in tmp421_probe_child_from_dt()
409 static int tmp421_probe_from_dt(struct i2c_client *client, struct tmp421_data *data) in tmp421_probe_from_dt() argument
411 struct device *dev = &client->dev; in tmp421_probe_from_dt()
412 const struct device_node *np = dev->of_node; in tmp421_probe_from_dt()
416 if (strcmp(child->name, "channel")) in tmp421_probe_from_dt()
419 err = tmp421_probe_child_from_dt(client, child, data); in tmp421_probe_from_dt()
436 struct device *dev = &client->dev; in tmp421_probe()
438 struct tmp421_data *data; in tmp421_probe() local
441 data = devm_kzalloc(dev, sizeof(struct tmp421_data), GFP_KERNEL); in tmp421_probe()
442 if (!data) in tmp421_probe()
443 return -ENOMEM; in tmp421_probe()
445 mutex_init(&data->update_lock); in tmp421_probe()
446 data->channels = (unsigned long)i2c_get_match_data(client); in tmp421_probe()
447 data->client = client; in tmp421_probe()
449 for (i = 0; i < data->channels; i++) { in tmp421_probe()
450 data->temp_config[i] = HWMON_T_INPUT | HWMON_T_FAULT | HWMON_T_ENABLE; in tmp421_probe()
451 data->channel[i].enabled = true; in tmp421_probe()
454 err = tmp421_probe_from_dt(client, data); in tmp421_probe()
458 err = tmp421_init_client(data); in tmp421_probe()
462 data->chip.ops = &tmp421_ops; in tmp421_probe()
463 data->chip.info = data->info; in tmp421_probe()
465 data->info[0] = &data->temp_info; in tmp421_probe()
467 data->temp_info.type = hwmon_temp; in tmp421_probe()
468 data->temp_info.config = data->temp_config; in tmp421_probe()
470 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, in tmp421_probe()
471 data, in tmp421_probe()
472 &data->chip, in tmp421_probe()