24 #include <linux/kernel.h>
25 #include <linux/module.h>
28 #include <linux/slab.h>
29 #include <linux/i2c.h>
49 #define PEM_OPERATION 0x01
50 #define PEM_CLEAR_INFO_FLAGS 0x03
51 #define PEM_VOUT_COMMAND 0x21
52 #define PEM_VOUT_OV_FAULT_LIMIT 0x40
53 #define PEM_READ_DATA_STRING 0xd0
54 #define PEM_READ_INPUT_STRING 0xdc
55 #define PEM_READ_FIRMWARE_REV 0xdd
56 #define PEM_READ_RUN_TIMER 0xde
57 #define PEM_FAN_HI_SPEED 0xdf
58 #define PEM_FAN_NORMAL_SPEED 0xe0
59 #define PEM_READ_FAN_SPEED 0xe1
62 #define PEM_DATA_STATUS_2 0
63 #define PEM_DATA_STATUS_1 1
64 #define PEM_DATA_ALARM_2 2
65 #define PEM_DATA_ALARM_1 3
66 #define PEM_DATA_VOUT_LSB 4
67 #define PEM_DATA_VOUT_MSB 5
68 #define PEM_DATA_CURRENT 6
69 #define PEM_DATA_TEMP 7
72 #define PEM_DATA_TEMP_MAX 10
73 #define PEM_DATA_TEMP_CRIT 11
76 #define PEM_INPUT_VOLTAGE 0
77 #define PEM_INPUT_POWER_LSB 1
78 #define PEM_INPUT_POWER_MSB 2
81 #define PEM_FAN_ADJUSTMENT 0
82 #define PEM_FAN_FAN1 1
83 #define PEM_FAN_FAN2 2
84 #define PEM_FAN_FAN3 3
87 #define STS1_OUTPUT_ON (1 << 0)
88 #define STS1_LEDS_FLASHING (1 << 1)
89 #define STS1_EXT_FAULT (1 << 2)
90 #define STS1_SERVICE_LED_ON (1 << 3)
91 #define STS1_SHUTDOWN_OCCURRED (1 << 4)
92 #define STS1_INT_FAULT (1 << 5)
93 #define STS1_ISOLATION_TEST_OK (1 << 6)
95 #define STS2_ENABLE_PIN_HI (1 << 0)
96 #define STS2_DATA_OUT_RANGE (1 << 1)
97 #define STS2_RESTARTED_OK (1 << 1)
98 #define STS2_ISOLATION_TEST_FAIL (1 << 3)
99 #define STS2_HIGH_POWER_CAP (1 << 4)
100 #define STS2_INVALID_INSTR (1 << 5)
101 #define STS2_WILL_RESTART (1 << 6)
102 #define STS2_PEC_ERR (1 << 7)
105 #define ALRM1_VIN_OUT_LIMIT (1 << 0)
106 #define ALRM1_VOUT_OUT_LIMIT (1 << 1)
107 #define ALRM1_OV_VOLT_SHUTDOWN (1 << 2)
108 #define ALRM1_VIN_OVERCURRENT (1 << 3)
109 #define ALRM1_TEMP_WARNING (1 << 4)
110 #define ALRM1_TEMP_SHUTDOWN (1 << 5)
111 #define ALRM1_PRIMARY_FAULT (1 << 6)
112 #define ALRM1_POWER_LIMIT (1 << 7)
114 #define ALRM2_5V_OUT_LIMIT (1 << 1)
115 #define ALRM2_TEMP_FAULT (1 << 2)
116 #define ALRM2_OV_LOW (1 << 3)
117 #define ALRM2_DCDC_TEMP_HIGH (1 << 4)
118 #define ALRM2_PRI_TEMP_HIGH (1 << 5)
119 #define ALRM2_NO_PRIMARY (1 << 6)
120 #define ALRM2_FAN_FAULT (1 << 7)
122 #define FIRMWARE_REV_LEN 4
123 #define DATA_STRING_LEN 9
124 #define INPUT_STRING_LEN 5
125 #define FAN_SPEED_LEN 5
151 if (
unlikely(result == 0xff || result != data_len)) {
155 memcpy(data, block_buffer, data_len);
177 ret = ERR_PTR(result);
187 ret = ERR_PTR(result);
198 ret = ERR_PTR(result);
213 static long pem_get_data(
u8 *data,
int len,
int index)
219 val = (data[
index] + (data[index+1] << 8)) * 5 / 2;
222 val = data[
index] * 200;
225 val = data[
index] * 1000;
240 static long pem_get_input(
u8 *data,
int len,
int index)
247 val = (data[
index] + (data[index+1] << 8) - 75) * 1000;
249 val = (data[
index] - 75) * 1000;
254 val = (data[
index] + (data[index+1] << 8)) * 1000000
L;
263 static long pem_get_fan(
u8 *data,
int len,
int index)
271 val = data[
index] * 100;
288 struct pem_data *data = pem_update_device(dev);
292 return PTR_ERR(data);
302 struct pem_data *data = pem_update_device(dev);
306 return PTR_ERR(data);
318 struct pem_data *data = pem_update_device(dev);
322 return PTR_ERR(data);
334 struct pem_data *data = pem_update_device(dev);
338 return PTR_ERR(data);
395 static struct attribute *pem_attributes[] = {
396 &sensor_dev_attr_in1_input.dev_attr.attr,
397 &sensor_dev_attr_in1_alarm.dev_attr.attr,
398 &sensor_dev_attr_in1_crit_alarm.dev_attr.attr,
399 &sensor_dev_attr_in2_alarm.dev_attr.attr,
401 &sensor_dev_attr_curr1_alarm.dev_attr.attr,
403 &sensor_dev_attr_power1_alarm.dev_attr.attr,
405 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
407 &sensor_dev_attr_temp1_input.dev_attr.attr,
408 &sensor_dev_attr_temp1_max.dev_attr.attr,
409 &sensor_dev_attr_temp1_crit.dev_attr.attr,
410 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
411 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
412 &sensor_dev_attr_temp1_fault.dev_attr.attr,
418 .attrs = pem_attributes,
421 static struct attribute *pem_input_attributes[] = {
422 &sensor_dev_attr_in2_input.dev_attr.attr,
423 &sensor_dev_attr_curr1_input.dev_attr.attr,
424 &sensor_dev_attr_power1_input.dev_attr.attr,
428 .attrs = pem_input_attributes,
431 static struct attribute *pem_fan_attributes[] = {
432 &sensor_dev_attr_fan1_input.dev_attr.attr,
433 &sensor_dev_attr_fan2_input.dev_attr.attr,
434 &sensor_dev_attr_fan3_input.dev_attr.attr,
438 .attrs = pem_fan_attributes,
441 static int pem_probe(
struct i2c_client *client,
456 i2c_set_clientdata(client, data);
472 dev_info(&client->
dev,
"Firmware revision %d.%d.%d\n",
506 goto out_remove_groups;
523 goto out_remove_groups;
529 goto out_remove_groups;
541 static int pem_remove(
struct i2c_client *client)
543 struct pem_data *data = i2c_get_clientdata(client);
562 .name =
"lineage_pem",
565 .remove = pem_remove,