Lines Matching +full:reg +full:- +full:names
1 // SPDX-License-Identifier: GPL-2.0-or-later
20 #include <linux/hwmon-sysfs.h>
114 static int temp_from_raw(u16 reg, bool extended) in temp_from_raw() argument
117 int temp = reg & ~0xf; in temp_from_raw()
120 temp = temp - 64 * 256; in temp_from_raw()
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()
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()
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()
236 *str = data->channel[channel].label; in tmp421_read_string()
249 data->channel[channel].enabled = val; in tmp421_write()
253 ret = -EOPNOTSUPP; in tmp421_write()
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()
306 struct i2c_adapter *adapter = client->adapter; in tmp421_detect()
307 static const char * const names[] = { in tmp421_detect() local
311 int addr = client->addr; in tmp421_detect()
312 u8 reg; in tmp421_detect() local
315 return -ENODEV; in tmp421_detect()
317 reg = i2c_smbus_read_byte_data(client, TMP421_MANUFACTURER_ID_REG); in tmp421_detect()
318 if (reg != TMP421_MANUFACTURER_ID) in tmp421_detect()
319 return -ENODEV; in tmp421_detect()
321 reg = i2c_smbus_read_byte_data(client, TMP421_CONVERSION_RATE_REG); in tmp421_detect()
322 if (reg & 0xf8) in tmp421_detect()
323 return -ENODEV; in tmp421_detect()
325 reg = i2c_smbus_read_byte_data(client, TMP421_STATUS_REG); in tmp421_detect()
326 if (reg & 0x7f) in tmp421_detect()
327 return -ENODEV; in tmp421_detect()
329 reg = i2c_smbus_read_byte_data(client, TMP421_DEVICE_ID_REG); in tmp421_detect()
330 switch (reg) { 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()
368 struct device *dev = &client->dev; in tmp421_probe_child_from_dt()
373 err = of_property_read_u32(child, "reg", &i); in tmp421_probe_child_from_dt()
375 dev_err(dev, "missing reg property of %pOFn\n", child); in tmp421_probe_child_from_dt()
379 if (i >= data->channels) { in tmp421_probe_child_from_dt()
380 dev_err(dev, "invalid reg %d of %pOFn\n", i, child); 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()
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()
417 if (strcmp(child->name, "channel")) in tmp421_probe_from_dt()
439 struct device *dev = &client->dev; in tmp421_probe()
446 return -ENOMEM; in tmp421_probe()
448 mutex_init(&data->update_lock); in tmp421_probe()
449 if (client->dev.of_node) in tmp421_probe()
450 data->channels = (unsigned long) in tmp421_probe()
451 of_device_get_match_data(&client->dev); in tmp421_probe()
453 data->channels = i2c_match_id(tmp421_id, client)->driver_data; in tmp421_probe()
454 data->client = client; in tmp421_probe()
456 for (i = 0; i < data->channels; i++) { in tmp421_probe()
457 data->temp_config[i] = HWMON_T_INPUT | HWMON_T_FAULT | HWMON_T_ENABLE; in tmp421_probe()
458 data->channel[i].enabled = true; in tmp421_probe()
469 data->chip.ops = &tmp421_ops; in tmp421_probe()
470 data->chip.info = data->info; in tmp421_probe()
472 data->info[0] = &data->temp_info; in tmp421_probe()
474 data->temp_info.type = hwmon_temp; in tmp421_probe()
475 data->temp_info.config = data->temp_config; in tmp421_probe()
477 hwmon_dev = devm_hwmon_device_register_with_info(dev, client->name, in tmp421_probe()
479 &data->chip, in tmp421_probe()