21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/i2c.h>
36 "Analog input mode:\n"
37 " 0 = four single ended inputs\n"
38 " 1 = three differential inputs\n"
39 " 2 = single ended and differential mixed\n"
40 " 3 = two differential inputs\n");
49 #define PCF8591_CONTROL_AOEF 0x40
58 #define PCF8591_CONTROL_AIP_MASK 0x30
61 #define PCF8591_CONTROL_AINC 0x04
70 #define PCF8591_CONTROL_AICH_MASK 0x03
73 #define PCF8591_INIT_CONTROL ((input_mode << 4) | PCF8591_CONTROL_AOEF)
74 #define PCF8591_INIT_AOUT 0
77 #define REG_TO_SIGNED(reg) (((reg) & 0x80) ? ((reg) - 256) : (reg))
91 #define show_in_channel(channel) \
92 static ssize_t show_in##channel##_input(struct device *dev, \
93 struct device_attribute *attr, \
96 return sprintf(buf, "%d\n", pcf8591_read_channel(dev, channel));\
98 static DEVICE_ATTR(in##channel##_input, S_IRUGO, \
99 show_in##channel##_input, NULL);
115 const char *buf,
size_t count)
122 err = kstrtoul(buf, 10, &val);
136 show_out0_ouput, set_out0_output);
147 const char *buf,
size_t count)
154 err = kstrtoul(buf, 10, &val);
169 show_out0_enable, set_out0_enable);
171 static struct attribute *pcf8591_attributes[] = {
172 &dev_attr_out0_enable.attr,
173 &dev_attr_out0_output.attr,
174 &dev_attr_in0_input.attr,
175 &dev_attr_in1_input.attr,
180 .attrs = pcf8591_attributes,
183 static struct attribute *pcf8591_attributes_opt[] = {
184 &dev_attr_in2_input.attr,
185 &dev_attr_in3_input.attr,
190 .attrs = pcf8591_attributes_opt,
197 static int pcf8591_probe(
struct i2c_client *client,
208 i2c_set_clientdata(client, data);
212 pcf8591_init_client(client);
223 goto exit_sysfs_remove;
230 goto exit_sysfs_remove;
236 goto exit_sysfs_remove;
247 static int pcf8591_remove(
struct i2c_client *client)
258 static void pcf8591_init_client(
struct i2c_client *client)
273 static int pcf8591_read_channel(
struct device *dev,
int channel)
313 .probe = pcf8591_probe,
314 .remove = pcf8591_remove,
315 .id_table = pcf8591_id,
318 static int __init pcf8591_init(
void)
324 return i2c_add_driver(&pcf8591_driver);
327 static void __exit pcf8591_exit(
void)