Source
89
89
ret = spi_w8r16(spi, reg);
90
90
return ret;
91
91
}
92
92
93
93
static int ads7871_write_reg8(struct spi_device *spi, int reg, u8 val)
94
94
{
95
95
u8 tmp[2] = {reg, val};
96
96
return spi_write(spi, tmp, sizeof(tmp));
97
97
}
98
98
99
-
static ssize_t show_voltage(struct device *dev,
100
-
struct device_attribute *da, char *buf)
99
+
static ssize_t voltage_show(struct device *dev, struct device_attribute *da,
100
+
char *buf)
101
101
{
102
102
struct ads7871_data *pdata = dev_get_drvdata(dev);
103
103
struct spi_device *spi = pdata->spi;
104
104
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
105
105
int ret, val, i = 0;
106
106
uint8_t channel, mux_cnv;
107
107
108
108
channel = attr->index;
109
109
/*
110
110
* TODO: add support for conversions
131
131
if (mux_cnv == 0) {
132
132
val = ads7871_read_reg16(spi, REG_LS_BYTE);
133
133
/*result in volts*10000 = (val/8192)*2.5*10000*/
134
134
val = ((val >> 2) * 25000) / 8192;
135
135
return sprintf(buf, "%d\n", val);
136
136
} else {
137
137
return -1;
138
138
}
139
139
}
140
140
141
-
static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_voltage, NULL, 0);
142
-
static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_voltage, NULL, 1);
143
-
static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_voltage, NULL, 2);
144
-
static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_voltage, NULL, 3);
145
-
static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_voltage, NULL, 4);
146
-
static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_voltage, NULL, 5);
147
-
static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_voltage, NULL, 6);
148
-
static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_voltage, NULL, 7);
141
+
static SENSOR_DEVICE_ATTR_RO(in0_input, voltage, 0);
142
+
static SENSOR_DEVICE_ATTR_RO(in1_input, voltage, 1);
143
+
static SENSOR_DEVICE_ATTR_RO(in2_input, voltage, 2);
144
+
static SENSOR_DEVICE_ATTR_RO(in3_input, voltage, 3);
145
+
static SENSOR_DEVICE_ATTR_RO(in4_input, voltage, 4);
146
+
static SENSOR_DEVICE_ATTR_RO(in5_input, voltage, 5);
147
+
static SENSOR_DEVICE_ATTR_RO(in6_input, voltage, 6);
148
+
static SENSOR_DEVICE_ATTR_RO(in7_input, voltage, 7);
149
149
150
150
static struct attribute *ads7871_attrs[] = {
151
151
&sensor_dev_attr_in0_input.dev_attr.attr,
152
152
&sensor_dev_attr_in1_input.dev_attr.attr,
153
153
&sensor_dev_attr_in2_input.dev_attr.attr,
154
154
&sensor_dev_attr_in3_input.dev_attr.attr,
155
155
&sensor_dev_attr_in4_input.dev_attr.attr,
156
156
&sensor_dev_attr_in5_input.dev_attr.attr,
157
157
&sensor_dev_attr_in6_input.dev_attr.attr,
158
158
&sensor_dev_attr_in7_input.dev_attr.attr,