Source
96
96
return sprintf(buf, "%d\n", pcf8591_read_channel(dev, channel));\
97
97
} \
98
98
static DEVICE_ATTR(in##channel##_input, S_IRUGO, \
99
99
show_in##channel##_input, NULL);
100
100
101
101
show_in_channel(0);
102
102
show_in_channel(1);
103
103
show_in_channel(2);
104
104
show_in_channel(3);
105
105
106
-
static ssize_t show_out0_ouput(struct device *dev,
107
-
struct device_attribute *attr, char *buf)
106
+
static ssize_t out0_output_show(struct device *dev,
107
+
struct device_attribute *attr, char *buf)
108
108
{
109
109
struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev));
110
110
return sprintf(buf, "%d\n", data->aout * 10);
111
111
}
112
112
113
-
static ssize_t set_out0_output(struct device *dev,
114
-
struct device_attribute *attr,
115
-
const char *buf, size_t count)
113
+
static ssize_t out0_output_store(struct device *dev,
114
+
struct device_attribute *attr,
115
+
const char *buf, size_t count)
116
116
{
117
117
unsigned long val;
118
118
struct i2c_client *client = to_i2c_client(dev);
119
119
struct pcf8591_data *data = i2c_get_clientdata(client);
120
120
int err;
121
121
122
122
err = kstrtoul(buf, 10, &val);
123
123
if (err)
124
124
return err;
125
125
126
126
val /= 10;
127
127
if (val > 255)
128
128
return -EINVAL;
129
129
130
130
data->aout = val;
131
131
i2c_smbus_write_byte_data(client, data->control, data->aout);
132
132
return count;
133
133
}
134
134
135
-
static DEVICE_ATTR(out0_output, S_IWUSR | S_IRUGO,
136
-
show_out0_ouput, set_out0_output);
135
+
static DEVICE_ATTR_RW(out0_output);
137
136
138
-
static ssize_t show_out0_enable(struct device *dev,
137
+
static ssize_t out0_enable_show(struct device *dev,
139
138
struct device_attribute *attr, char *buf)
140
139
{
141
140
struct pcf8591_data *data = i2c_get_clientdata(to_i2c_client(dev));
142
141
return sprintf(buf, "%u\n", !(!(data->control & PCF8591_CONTROL_AOEF)));
143
142
}
144
143
145
-
static ssize_t set_out0_enable(struct device *dev,
146
-
struct device_attribute *attr,
147
-
const char *buf, size_t count)
144
+
static ssize_t out0_enable_store(struct device *dev,
145
+
struct device_attribute *attr,
146
+
const char *buf, size_t count)
148
147
{
149
148
struct i2c_client *client = to_i2c_client(dev);
150
149
struct pcf8591_data *data = i2c_get_clientdata(client);
151
150
unsigned long val;
152
151
int err;
153
152
154
153
err = kstrtoul(buf, 10, &val);
155
154
if (err)
156
155
return err;
157
156
158
157
mutex_lock(&data->update_lock);
159
158
if (val)
160
159
data->control |= PCF8591_CONTROL_AOEF;
161
160
else
162
161
data->control &= ~PCF8591_CONTROL_AOEF;
163
162
i2c_smbus_write_byte(client, data->control);
164
163
mutex_unlock(&data->update_lock);
165
164
return count;
166
165
}
167
166
168
-
static DEVICE_ATTR(out0_enable, S_IWUSR | S_IRUGO,
169
-
show_out0_enable, set_out0_enable);
167
+
static DEVICE_ATTR_RW(out0_enable);
170
168
171
169
static struct attribute *pcf8591_attributes[] = {
172
170
&dev_attr_out0_enable.attr,
173
171
&dev_attr_out0_output.attr,
174
172
&dev_attr_in0_input.attr,
175
173
&dev_attr_in1_input.attr,
176
174
NULL
177
175
};
178
176
179
177
static const struct attribute_group pcf8591_attr_group = {