Lines Matching +full:control +full:- +full:channel

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2001-2004 Aurelien Jarno <aurelien@aurel32.net>
30 * The PCF8591 control byte
51 * Channel selection
52 * 0x00 = channel 0
53 * 0x01 = channel 1
54 * 0x02 = channel 2
55 * 0x03 = channel 3
64 #define REG_TO_SIGNED(reg) (((reg) & 0x80) ? ((reg) - 256) : (reg))
70 u8 control; member
75 static int pcf8591_read_channel(struct device *dev, int channel);
78 #define show_in_channel(channel) \ argument
79 static ssize_t show_in##channel##_input(struct device *dev, \
83 return sprintf(buf, "%d\n", pcf8591_read_channel(dev, channel));\
85 static DEVICE_ATTR(in##channel##_input, S_IRUGO, \
86 show_in##channel##_input, NULL);
97 return sprintf(buf, "%d\n", data->aout * 10); in out0_output_show()
115 return -EINVAL; in out0_output_store()
117 data->aout = val; in out0_output_store()
118 i2c_smbus_write_byte_data(client, data->control, data->aout); in out0_output_store()
128 return sprintf(buf, "%u\n", !(!(data->control & PCF8591_CONTROL_AOEF))); in out0_enable_show()
144 mutex_lock(&data->update_lock); in out0_enable_store()
146 data->control |= PCF8591_CONTROL_AOEF; in out0_enable_store()
148 data->control &= ~PCF8591_CONTROL_AOEF; in out0_enable_store()
149 i2c_smbus_write_byte(client, data->control); in out0_enable_store()
150 mutex_unlock(&data->update_lock); in out0_enable_store()
187 data = devm_kzalloc(&client->dev, sizeof(struct pcf8591_data), in pcf8591_probe()
190 return -ENOMEM; in pcf8591_probe()
193 mutex_init(&data->update_lock); in pcf8591_probe()
199 err = sysfs_create_group(&client->dev.kobj, &pcf8591_attr_group); in pcf8591_probe()
205 err = device_create_file(&client->dev, &dev_attr_in2_input); in pcf8591_probe()
212 err = device_create_file(&client->dev, &dev_attr_in3_input); in pcf8591_probe()
217 data->hwmon_dev = hwmon_device_register(&client->dev); in pcf8591_probe()
218 if (IS_ERR(data->hwmon_dev)) { in pcf8591_probe()
219 err = PTR_ERR(data->hwmon_dev); in pcf8591_probe()
226 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); in pcf8591_probe()
227 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); in pcf8591_probe()
235 hwmon_device_unregister(data->hwmon_dev); in pcf8591_remove()
236 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); in pcf8591_remove()
237 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); in pcf8591_remove()
244 data->control = PCF8591_INIT_CONTROL; in pcf8591_init_client()
245 data->aout = PCF8591_INIT_AOUT; in pcf8591_init_client()
247 i2c_smbus_write_byte_data(client, data->control, data->aout); in pcf8591_init_client()
256 static int pcf8591_read_channel(struct device *dev, int channel) in pcf8591_read_channel() argument
262 mutex_lock(&data->update_lock); in pcf8591_read_channel()
264 if ((data->control & PCF8591_CONTROL_AICH_MASK) != channel) { in pcf8591_read_channel()
265 data->control = (data->control & ~PCF8591_CONTROL_AICH_MASK) in pcf8591_read_channel()
266 | channel; in pcf8591_read_channel()
267 i2c_smbus_write_byte(client, data->control); in pcf8591_read_channel()
277 mutex_unlock(&data->update_lock); in pcf8591_read_channel()
279 if ((channel == 2 && input_mode == 2) || in pcf8591_read_channel()
280 (channel != 3 && (input_mode == 1 || input_mode == 3))) in pcf8591_read_channel()