Lines Matching +full:single +full:- +full:channel
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2001-2004 Aurelien Jarno <aurelien@aurel32.net>
25 " 0 = four single ended inputs\n"
27 " 2 = single ended and differential mixed\n"
41 * 0x00 = four single ended inputs
43 * 0x20 = single ended and differential mixed
52 * Channel selection
53 * 0x00 = channel 0
54 * 0x01 = channel 1
55 * 0x02 = channel 2
56 * 0x03 = channel 3
65 #define REG_TO_SIGNED(reg) (((reg) & 0x80) ? ((reg) - 256) : (reg))
76 static int pcf8591_read_channel(struct device *dev, int channel);
79 #define show_in_channel(channel) \ argument
80 static ssize_t show_in##channel##_input(struct device *dev, \
84 return sprintf(buf, "%d\n", pcf8591_read_channel(dev, channel));\
86 static DEVICE_ATTR(in##channel##_input, S_IRUGO, \
87 show_in##channel##_input, NULL);
98 return sprintf(buf, "%d\n", data->aout * 10); in out0_output_show()
116 return -EINVAL; in out0_output_store()
118 data->aout = val; in out0_output_store()
119 i2c_smbus_write_byte_data(client, data->control, data->aout); in out0_output_store()
129 return sprintf(buf, "%u\n", !(!(data->control & PCF8591_CONTROL_AOEF))); in out0_enable_show()
145 mutex_lock(&data->update_lock); in out0_enable_store()
147 data->control |= PCF8591_CONTROL_AOEF; in out0_enable_store()
149 data->control &= ~PCF8591_CONTROL_AOEF; in out0_enable_store()
150 i2c_smbus_write_byte(client, data->control); in out0_enable_store()
151 mutex_unlock(&data->update_lock); in out0_enable_store()
188 data = devm_kzalloc(&client->dev, sizeof(struct pcf8591_data), in pcf8591_probe()
191 return -ENOMEM; in pcf8591_probe()
194 mutex_init(&data->update_lock); in pcf8591_probe()
200 err = sysfs_create_group(&client->dev.kobj, &pcf8591_attr_group); in pcf8591_probe()
206 err = device_create_file(&client->dev, &dev_attr_in2_input); in pcf8591_probe()
211 /* Register input3 only in "four single ended inputs" mode */ in pcf8591_probe()
213 err = device_create_file(&client->dev, &dev_attr_in3_input); in pcf8591_probe()
218 data->hwmon_dev = hwmon_device_register(&client->dev); in pcf8591_probe()
219 if (IS_ERR(data->hwmon_dev)) { in pcf8591_probe()
220 err = PTR_ERR(data->hwmon_dev); in pcf8591_probe()
227 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); in pcf8591_probe()
228 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); in pcf8591_probe()
236 hwmon_device_unregister(data->hwmon_dev); in pcf8591_remove()
237 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); in pcf8591_remove()
238 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); in pcf8591_remove()
245 data->control = PCF8591_INIT_CONTROL; in pcf8591_init_client()
246 data->aout = PCF8591_INIT_AOUT; in pcf8591_init_client()
248 i2c_smbus_write_byte_data(client, data->control, data->aout); in pcf8591_init_client()
257 static int pcf8591_read_channel(struct device *dev, int channel) in pcf8591_read_channel() argument
263 mutex_lock(&data->update_lock); in pcf8591_read_channel()
265 if ((data->control & PCF8591_CONTROL_AICH_MASK) != channel) { in pcf8591_read_channel()
266 data->control = (data->control & ~PCF8591_CONTROL_AICH_MASK) in pcf8591_read_channel()
267 | channel; in pcf8591_read_channel()
268 i2c_smbus_write_byte(client, data->control); in pcf8591_read_channel()
278 mutex_unlock(&data->update_lock); in pcf8591_read_channel()
280 if ((channel == 2 && input_mode == 2) || in pcf8591_read_channel()
281 (channel != 3 && (input_mode == 1 || input_mode == 3))) in pcf8591_read_channel()