Source
163
163
static int reg_to_rpm(u16 reg)
164
164
{
165
165
if (reg == 0)
166
166
return -EIO;
167
167
if (reg == 0xffff)
168
168
return 0;
169
169
170
170
return 5400540 / reg;
171
171
}
172
172
173
-
static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
174
-
char *buf)
173
+
static ssize_t name_show(struct device *dev, struct device_attribute *devattr,
174
+
char *buf)
175
175
{
176
176
return snprintf(buf, PAGE_SIZE, "%s\n", DEVNAME);
177
177
}
178
178
179
-
static ssize_t show_in_value(struct device *dev, struct device_attribute
180
-
*devattr, char *buf)
179
+
static ssize_t in_value_show(struct device *dev,
180
+
struct device_attribute *devattr, char *buf)
181
181
{
182
182
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
183
183
struct sch5636_data *data = sch5636_update_device(dev);
184
184
int val;
185
185
186
186
if (IS_ERR(data))
187
187
return PTR_ERR(data);
188
188
189
189
val = DIV_ROUND_CLOSEST(
190
190
data->in[attr->index] * SCH5636_REG_IN_FACTORS[attr->index],
191
191
255);
192
192
return snprintf(buf, PAGE_SIZE, "%d\n", val);
193
193
}
194
194
195
-
static ssize_t show_in_label(struct device *dev, struct device_attribute
196
-
*devattr, char *buf)
195
+
static ssize_t in_label_show(struct device *dev,
196
+
struct device_attribute *devattr, char *buf)
197
197
{
198
198
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
199
199
200
200
return snprintf(buf, PAGE_SIZE, "%s\n",
201
201
SCH5636_IN_LABELS[attr->index]);
202
202
}
203
203
204
-
static ssize_t show_temp_value(struct device *dev, struct device_attribute
205
-
*devattr, char *buf)
204
+
static ssize_t temp_value_show(struct device *dev,
205
+
struct device_attribute *devattr, char *buf)
206
206
{
207
207
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
208
208
struct sch5636_data *data = sch5636_update_device(dev);
209
209
int val;
210
210
211
211
if (IS_ERR(data))
212
212
return PTR_ERR(data);
213
213
214
214
val = (data->temp_val[attr->index] - 64) * 1000;
215
215
return snprintf(buf, PAGE_SIZE, "%d\n", val);
216
216
}
217
217
218
-
static ssize_t show_temp_fault(struct device *dev, struct device_attribute
219
-
*devattr, char *buf)
218
+
static ssize_t temp_fault_show(struct device *dev,
219
+
struct device_attribute *devattr, char *buf)
220
220
{
221
221
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
222
222
struct sch5636_data *data = sch5636_update_device(dev);
223
223
int val;
224
224
225
225
if (IS_ERR(data))
226
226
return PTR_ERR(data);
227
227
228
228
val = (data->temp_ctrl[attr->index] & SCH5636_TEMP_WORKING) ? 0 : 1;
229
229
return snprintf(buf, PAGE_SIZE, "%d\n", val);
230
230
}
231
231
232
-
static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
233
-
*devattr, char *buf)
232
+
static ssize_t temp_alarm_show(struct device *dev,
233
+
struct device_attribute *devattr, char *buf)
234
234
{
235
235
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
236
236
struct sch5636_data *data = sch5636_update_device(dev);
237
237
int val;
238
238
239
239
if (IS_ERR(data))
240
240
return PTR_ERR(data);
241
241
242
242
val = (data->temp_ctrl[attr->index] & SCH5636_TEMP_ALARM) ? 1 : 0;
243
243
return snprintf(buf, PAGE_SIZE, "%d\n", val);
244
244
}
245
245
246
-
static ssize_t show_fan_value(struct device *dev, struct device_attribute
247
-
*devattr, char *buf)
246
+
static ssize_t fan_value_show(struct device *dev,
247
+
struct device_attribute *devattr, char *buf)
248
248
{
249
249
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
250
250
struct sch5636_data *data = sch5636_update_device(dev);
251
251
int val;
252
252
253
253
if (IS_ERR(data))
254
254
return PTR_ERR(data);
255
255
256
256
val = reg_to_rpm(data->fan_val[attr->index]);
257
257
if (val < 0)
258
258
return val;
259
259
260
260
return snprintf(buf, PAGE_SIZE, "%d\n", val);
261
261
}
262
262
263
-
static ssize_t show_fan_fault(struct device *dev, struct device_attribute
264
-
*devattr, char *buf)
263
+
static ssize_t fan_fault_show(struct device *dev,
264
+
struct device_attribute *devattr, char *buf)
265
265
{
266
266
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
267
267
struct sch5636_data *data = sch5636_update_device(dev);
268
268
int val;
269
269
270
270
if (IS_ERR(data))
271
271
return PTR_ERR(data);
272
272
273
273
val = (data->fan_ctrl[attr->index] & SCH5636_FAN_NOT_PRESENT) ? 1 : 0;
274
274
return snprintf(buf, PAGE_SIZE, "%d\n", val);
275
275
}
276
276
277
-
static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
278
-
*devattr, char *buf)
277
+
static ssize_t fan_alarm_show(struct device *dev,
278
+
struct device_attribute *devattr, char *buf)
279
279
{
280
280
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
281
281
struct sch5636_data *data = sch5636_update_device(dev);
282
282
int val;
283
283
284
284
if (IS_ERR(data))
285
285
return PTR_ERR(data);
286
286
287
287
val = (data->fan_ctrl[attr->index] & SCH5636_FAN_ALARM) ? 1 : 0;
288
288
return snprintf(buf, PAGE_SIZE, "%d\n", val);
289
289
}
290
290
291
291
static struct sensor_device_attribute sch5636_attr[] = {
292
-
SENSOR_ATTR(name, 0444, show_name, NULL, 0),
293
-
SENSOR_ATTR(in0_input, 0444, show_in_value, NULL, 0),
294
-
SENSOR_ATTR(in0_label, 0444, show_in_label, NULL, 0),
295
-
SENSOR_ATTR(in1_input, 0444, show_in_value, NULL, 1),
296
-
SENSOR_ATTR(in1_label, 0444, show_in_label, NULL, 1),
297
-
SENSOR_ATTR(in2_input, 0444, show_in_value, NULL, 2),
298
-
SENSOR_ATTR(in2_label, 0444, show_in_label, NULL, 2),
299
-
SENSOR_ATTR(in3_input, 0444, show_in_value, NULL, 3),
300
-
SENSOR_ATTR(in3_label, 0444, show_in_label, NULL, 3),
301
-
SENSOR_ATTR(in4_input, 0444, show_in_value, NULL, 4),
302
-
SENSOR_ATTR(in4_label, 0444, show_in_label, NULL, 4),
292
+
SENSOR_ATTR_RO(name, name, 0),
293
+
SENSOR_ATTR_RO(in0_input, in_value, 0),
294
+
SENSOR_ATTR_RO(in0_label, in_label, 0),
295
+
SENSOR_ATTR_RO(in1_input, in_value, 1),
296
+
SENSOR_ATTR_RO(in1_label, in_label, 1),
297
+
SENSOR_ATTR_RO(in2_input, in_value, 2),
298
+
SENSOR_ATTR_RO(in2_label, in_label, 2),
299
+
SENSOR_ATTR_RO(in3_input, in_value, 3),
300
+
SENSOR_ATTR_RO(in3_label, in_label, 3),
301
+
SENSOR_ATTR_RO(in4_input, in_value, 4),
302
+
SENSOR_ATTR_RO(in4_label, in_label, 4),
303
303
};
304
304
305
305
static struct sensor_device_attribute sch5636_temp_attr[] = {
306
-
SENSOR_ATTR(temp1_input, 0444, show_temp_value, NULL, 0),
307
-
SENSOR_ATTR(temp1_fault, 0444, show_temp_fault, NULL, 0),
308
-
SENSOR_ATTR(temp1_alarm, 0444, show_temp_alarm, NULL, 0),
309
-
SENSOR_ATTR(temp2_input, 0444, show_temp_value, NULL, 1),
310
-
SENSOR_ATTR(temp2_fault, 0444, show_temp_fault, NULL, 1),
311
-
SENSOR_ATTR(temp2_alarm, 0444, show_temp_alarm, NULL, 1),
312
-
SENSOR_ATTR(temp3_input, 0444, show_temp_value, NULL, 2),
313
-
SENSOR_ATTR(temp3_fault, 0444, show_temp_fault, NULL, 2),
314
-
SENSOR_ATTR(temp3_alarm, 0444, show_temp_alarm, NULL, 2),
315
-
SENSOR_ATTR(temp4_input, 0444, show_temp_value, NULL, 3),
316
-
SENSOR_ATTR(temp4_fault, 0444, show_temp_fault, NULL, 3),
317
-
SENSOR_ATTR(temp4_alarm, 0444, show_temp_alarm, NULL, 3),
318
-
SENSOR_ATTR(temp5_input, 0444, show_temp_value, NULL, 4),
319
-
SENSOR_ATTR(temp5_fault, 0444, show_temp_fault, NULL, 4),
320
-
SENSOR_ATTR(temp5_alarm, 0444, show_temp_alarm, NULL, 4),
321
-
SENSOR_ATTR(temp6_input, 0444, show_temp_value, NULL, 5),
322
-
SENSOR_ATTR(temp6_fault, 0444, show_temp_fault, NULL, 5),
323
-
SENSOR_ATTR(temp6_alarm, 0444, show_temp_alarm, NULL, 5),
324
-
SENSOR_ATTR(temp7_input, 0444, show_temp_value, NULL, 6),
325
-
SENSOR_ATTR(temp7_fault, 0444, show_temp_fault, NULL, 6),
326
-
SENSOR_ATTR(temp7_alarm, 0444, show_temp_alarm, NULL, 6),
327
-
SENSOR_ATTR(temp8_input, 0444, show_temp_value, NULL, 7),
328
-
SENSOR_ATTR(temp8_fault, 0444, show_temp_fault, NULL, 7),
329
-
SENSOR_ATTR(temp8_alarm, 0444, show_temp_alarm, NULL, 7),
330
-
SENSOR_ATTR(temp9_input, 0444, show_temp_value, NULL, 8),
331
-
SENSOR_ATTR(temp9_fault, 0444, show_temp_fault, NULL, 8),
332
-
SENSOR_ATTR(temp9_alarm, 0444, show_temp_alarm, NULL, 8),
333
-
SENSOR_ATTR(temp10_input, 0444, show_temp_value, NULL, 9),
334
-
SENSOR_ATTR(temp10_fault, 0444, show_temp_fault, NULL, 9),
335
-
SENSOR_ATTR(temp10_alarm, 0444, show_temp_alarm, NULL, 9),
336
-
SENSOR_ATTR(temp11_input, 0444, show_temp_value, NULL, 10),
337
-
SENSOR_ATTR(temp11_fault, 0444, show_temp_fault, NULL, 10),
338
-
SENSOR_ATTR(temp11_alarm, 0444, show_temp_alarm, NULL, 10),
339
-
SENSOR_ATTR(temp12_input, 0444, show_temp_value, NULL, 11),
340
-
SENSOR_ATTR(temp12_fault, 0444, show_temp_fault, NULL, 11),
341
-
SENSOR_ATTR(temp12_alarm, 0444, show_temp_alarm, NULL, 11),
342
-
SENSOR_ATTR(temp13_input, 0444, show_temp_value, NULL, 12),
343
-
SENSOR_ATTR(temp13_fault, 0444, show_temp_fault, NULL, 12),
344
-
SENSOR_ATTR(temp13_alarm, 0444, show_temp_alarm, NULL, 12),
345
-
SENSOR_ATTR(temp14_input, 0444, show_temp_value, NULL, 13),
346
-
SENSOR_ATTR(temp14_fault, 0444, show_temp_fault, NULL, 13),
347
-
SENSOR_ATTR(temp14_alarm, 0444, show_temp_alarm, NULL, 13),
348
-
SENSOR_ATTR(temp15_input, 0444, show_temp_value, NULL, 14),
349
-
SENSOR_ATTR(temp15_fault, 0444, show_temp_fault, NULL, 14),
350
-
SENSOR_ATTR(temp15_alarm, 0444, show_temp_alarm, NULL, 14),
351
-
SENSOR_ATTR(temp16_input, 0444, show_temp_value, NULL, 15),
352
-
SENSOR_ATTR(temp16_fault, 0444, show_temp_fault, NULL, 15),
353
-
SENSOR_ATTR(temp16_alarm, 0444, show_temp_alarm, NULL, 15),
306
+
SENSOR_ATTR_RO(temp1_input, temp_value, 0),
307
+
SENSOR_ATTR_RO(temp1_fault, temp_fault, 0),
308
+
SENSOR_ATTR_RO(temp1_alarm, temp_alarm, 0),
309
+
SENSOR_ATTR_RO(temp2_input, temp_value, 1),
310
+
SENSOR_ATTR_RO(temp2_fault, temp_fault, 1),
311
+
SENSOR_ATTR_RO(temp2_alarm, temp_alarm, 1),
312
+
SENSOR_ATTR_RO(temp3_input, temp_value, 2),
313
+
SENSOR_ATTR_RO(temp3_fault, temp_fault, 2),
314
+
SENSOR_ATTR_RO(temp3_alarm, temp_alarm, 2),
315
+
SENSOR_ATTR_RO(temp4_input, temp_value, 3),
316
+
SENSOR_ATTR_RO(temp4_fault, temp_fault, 3),
317
+
SENSOR_ATTR_RO(temp4_alarm, temp_alarm, 3),
318
+
SENSOR_ATTR_RO(temp5_input, temp_value, 4),
319
+
SENSOR_ATTR_RO(temp5_fault, temp_fault, 4),
320
+
SENSOR_ATTR_RO(temp5_alarm, temp_alarm, 4),
321
+
SENSOR_ATTR_RO(temp6_input, temp_value, 5),
322
+
SENSOR_ATTR_RO(temp6_fault, temp_fault, 5),
323
+
SENSOR_ATTR_RO(temp6_alarm, temp_alarm, 5),
324
+
SENSOR_ATTR_RO(temp7_input, temp_value, 6),
325
+
SENSOR_ATTR_RO(temp7_fault, temp_fault, 6),
326
+
SENSOR_ATTR_RO(temp7_alarm, temp_alarm, 6),
327
+
SENSOR_ATTR_RO(temp8_input, temp_value, 7),
328
+
SENSOR_ATTR_RO(temp8_fault, temp_fault, 7),
329
+
SENSOR_ATTR_RO(temp8_alarm, temp_alarm, 7),
330
+
SENSOR_ATTR_RO(temp9_input, temp_value, 8),
331
+
SENSOR_ATTR_RO(temp9_fault, temp_fault, 8),
332
+
SENSOR_ATTR_RO(temp9_alarm, temp_alarm, 8),
333
+
SENSOR_ATTR_RO(temp10_input, temp_value, 9),
334
+
SENSOR_ATTR_RO(temp10_fault, temp_fault, 9),
335
+
SENSOR_ATTR_RO(temp10_alarm, temp_alarm, 9),
336
+
SENSOR_ATTR_RO(temp11_input, temp_value, 10),
337
+
SENSOR_ATTR_RO(temp11_fault, temp_fault, 10),
338
+
SENSOR_ATTR_RO(temp11_alarm, temp_alarm, 10),
339
+
SENSOR_ATTR_RO(temp12_input, temp_value, 11),
340
+
SENSOR_ATTR_RO(temp12_fault, temp_fault, 11),
341
+
SENSOR_ATTR_RO(temp12_alarm, temp_alarm, 11),
342
+
SENSOR_ATTR_RO(temp13_input, temp_value, 12),
343
+
SENSOR_ATTR_RO(temp13_fault, temp_fault, 12),
344
+
SENSOR_ATTR_RO(temp13_alarm, temp_alarm, 12),
345
+
SENSOR_ATTR_RO(temp14_input, temp_value, 13),
346
+
SENSOR_ATTR_RO(temp14_fault, temp_fault, 13),
347
+
SENSOR_ATTR_RO(temp14_alarm, temp_alarm, 13),
348
+
SENSOR_ATTR_RO(temp15_input, temp_value, 14),
349
+
SENSOR_ATTR_RO(temp15_fault, temp_fault, 14),
350
+
SENSOR_ATTR_RO(temp15_alarm, temp_alarm, 14),
351
+
SENSOR_ATTR_RO(temp16_input, temp_value, 15),
352
+
SENSOR_ATTR_RO(temp16_fault, temp_fault, 15),
353
+
SENSOR_ATTR_RO(temp16_alarm, temp_alarm, 15),
354
354
};
355
355
356
356
static struct sensor_device_attribute sch5636_fan_attr[] = {
357
-
SENSOR_ATTR(fan1_input, 0444, show_fan_value, NULL, 0),
358
-
SENSOR_ATTR(fan1_fault, 0444, show_fan_fault, NULL, 0),
359
-
SENSOR_ATTR(fan1_alarm, 0444, show_fan_alarm, NULL, 0),
360
-
SENSOR_ATTR(fan2_input, 0444, show_fan_value, NULL, 1),
361
-
SENSOR_ATTR(fan2_fault, 0444, show_fan_fault, NULL, 1),
362
-
SENSOR_ATTR(fan2_alarm, 0444, show_fan_alarm, NULL, 1),
363
-
SENSOR_ATTR(fan3_input, 0444, show_fan_value, NULL, 2),
364
-
SENSOR_ATTR(fan3_fault, 0444, show_fan_fault, NULL, 2),
365
-
SENSOR_ATTR(fan3_alarm, 0444, show_fan_alarm, NULL, 2),
366
-
SENSOR_ATTR(fan4_input, 0444, show_fan_value, NULL, 3),
367
-
SENSOR_ATTR(fan4_fault, 0444, show_fan_fault, NULL, 3),
368
-
SENSOR_ATTR(fan4_alarm, 0444, show_fan_alarm, NULL, 3),
369
-
SENSOR_ATTR(fan5_input, 0444, show_fan_value, NULL, 4),
370
-
SENSOR_ATTR(fan5_fault, 0444, show_fan_fault, NULL, 4),
371
-
SENSOR_ATTR(fan5_alarm, 0444, show_fan_alarm, NULL, 4),
372
-
SENSOR_ATTR(fan6_input, 0444, show_fan_value, NULL, 5),
373
-
SENSOR_ATTR(fan6_fault, 0444, show_fan_fault, NULL, 5),
374
-
SENSOR_ATTR(fan6_alarm, 0444, show_fan_alarm, NULL, 5),
375
-
SENSOR_ATTR(fan7_input, 0444, show_fan_value, NULL, 6),
376
-
SENSOR_ATTR(fan7_fault, 0444, show_fan_fault, NULL, 6),
377
-
SENSOR_ATTR(fan7_alarm, 0444, show_fan_alarm, NULL, 6),
378
-
SENSOR_ATTR(fan8_input, 0444, show_fan_value, NULL, 7),
379
-
SENSOR_ATTR(fan8_fault, 0444, show_fan_fault, NULL, 7),
380
-
SENSOR_ATTR(fan8_alarm, 0444, show_fan_alarm, NULL, 7),
357
+
SENSOR_ATTR_RO(fan1_input, fan_value, 0),
358
+
SENSOR_ATTR_RO(fan1_fault, fan_fault, 0),
359
+
SENSOR_ATTR_RO(fan1_alarm, fan_alarm, 0),
360
+
SENSOR_ATTR_RO(fan2_input, fan_value, 1),
361
+
SENSOR_ATTR_RO(fan2_fault, fan_fault, 1),
362
+
SENSOR_ATTR_RO(fan2_alarm, fan_alarm, 1),
363
+
SENSOR_ATTR_RO(fan3_input, fan_value, 2),
364
+
SENSOR_ATTR_RO(fan3_fault, fan_fault, 2),
365
+
SENSOR_ATTR_RO(fan3_alarm, fan_alarm, 2),
366
+
SENSOR_ATTR_RO(fan4_input, fan_value, 3),
367
+
SENSOR_ATTR_RO(fan4_fault, fan_fault, 3),
368
+
SENSOR_ATTR_RO(fan4_alarm, fan_alarm, 3),
369
+
SENSOR_ATTR_RO(fan5_input, fan_value, 4),
370
+
SENSOR_ATTR_RO(fan5_fault, fan_fault, 4),
371
+
SENSOR_ATTR_RO(fan5_alarm, fan_alarm, 4),
372
+
SENSOR_ATTR_RO(fan6_input, fan_value, 5),
373
+
SENSOR_ATTR_RO(fan6_fault, fan_fault, 5),
374
+
SENSOR_ATTR_RO(fan6_alarm, fan_alarm, 5),
375
+
SENSOR_ATTR_RO(fan7_input, fan_value, 6),
376
+
SENSOR_ATTR_RO(fan7_fault, fan_fault, 6),
377
+
SENSOR_ATTR_RO(fan7_alarm, fan_alarm, 6),
378
+
SENSOR_ATTR_RO(fan8_input, fan_value, 7),
379
+
SENSOR_ATTR_RO(fan8_fault, fan_fault, 7),
380
+
SENSOR_ATTR_RO(fan8_alarm, fan_alarm, 7),
381
381
};
382
382
383
383
static int sch5636_remove(struct platform_device *pdev)
384
384
{
385
385
struct sch5636_data *data = platform_get_drvdata(pdev);
386
386
int i;
387
387
388
388
if (data->watchdog)
389
389
sch56xx_watchdog_unregister(data->watchdog);
390
390