7 #include <linux/kernel.h>
8 #include <linux/types.h>
9 #include <linux/slab.h>
10 #include <linux/module.h>
17 #define DRV_MODULE_VERSION "0.1"
25 #define REG_CMD 0x00UL
26 #define REG_CMD_RESET 0x80
27 #define REG_CMD_ESTAR 0x01
28 #define REG_STAT 0x01UL
29 #define REG_STAT_FWVER 0xf0
30 #define REG_STAT_TGOOD 0x08
31 #define REG_STAT_STALE 0x04
32 #define REG_STAT_BUSY 0x02
33 #define REG_STAT_FAULT 0x01
34 #define REG_DATA 0x40UL
35 #define REG_ADDR 0x41UL
36 #define REG_SIZE 0x42UL
39 #define IREG_FAN0 0x00
40 #define IREG_FAN1 0x01
41 #define IREG_FAN2 0x02
42 #define IREG_FAN3 0x03
43 #define IREG_FAN4 0x04
44 #define IREG_FAN5 0x05
45 #define IREG_LCL_TEMP 0x06
46 #define IREG_RMT1_TEMP 0x07
47 #define IREG_RMT2_TEMP 0x08
48 #define IREG_RMT3_TEMP 0x09
49 #define IREG_LM95221_TEMP 0x0a
50 #define IREG_FIRE_TEMP 0x0b
51 #define IREG_LSI1064_TEMP 0x0c
52 #define IREG_FRONT_TEMP 0x0d
53 #define IREG_FAN_STAT 0x0e
54 #define IREG_VCORE0 0x0f
55 #define IREG_VCORE1 0x10
56 #define IREG_VMEM0 0x11
57 #define IREG_VMEM1 0x12
58 #define IREG_PSU_TEMP 0x13
67 static u8 env_read(
struct env *
p,
u8 ireg)
74 spin_unlock(&p->
lock);
79 static void env_write(
struct env *
p,
u8 ireg,
u8 val)
84 spin_unlock(&p->
lock);
91 #define FAN_PERIOD_TO_RPM(x) ((90000 * 60) / (x))
92 #define FAN_RPM_TO_PERIOD FAN_PERIOD_TO_RPM
93 #define FAN_PERIOD_INVALID (0xff << 8)
94 #define FAN_DATA_VALID(x) ((x) && (x) != FAN_PERIOD_INVALID)
105 period = (
int) val << 8;
111 return sprintf(buf,
"%d\n", rpm);
124 err = kstrtoul(buf, 10, &rpm);
144 return sprintf(buf,
"%d\n", (val & (1 << fan_nr)) ? 1 : 0);
148 static SENSOR_DEVICE_ATTR(fan##index##_speed, S_IRUGO | S_IWUSR, \
149 show_fan_speed, set_fan_speed, index); \
150 static SENSOR_DEVICE_ATTR(fan##index##_fault, S_IRUGO, \
151 show_fan_fault, NULL, index)
169 return sprintf(buf,
"%d\n", ((
int) val) - 64);
190 return sprintf(buf,
"%d\n", (val & (1 << index)) ? 1 : 0);
206 return sprintf(buf,
"%d\n", val >> 4);
214 return sprintf(buf,
"ultra45\n");
219 static struct attribute *env_attributes[] = {
220 &sensor_dev_attr_fan0_speed.dev_attr.attr,
221 &sensor_dev_attr_fan0_fault.dev_attr.attr,
222 &sensor_dev_attr_fan1_speed.dev_attr.attr,
223 &sensor_dev_attr_fan1_fault.dev_attr.attr,
224 &sensor_dev_attr_fan2_speed.dev_attr.attr,
225 &sensor_dev_attr_fan2_fault.dev_attr.attr,
226 &sensor_dev_attr_fan3_speed.dev_attr.attr,
227 &sensor_dev_attr_fan3_fault.dev_attr.attr,
228 &sensor_dev_attr_fan4_speed.dev_attr.attr,
229 &sensor_dev_attr_fan4_fault.dev_attr.attr,
230 &sensor_dev_attr_psu_fan_fault.dev_attr.attr,
231 &sensor_dev_attr_adt7462_local_temp.dev_attr.attr,
232 &sensor_dev_attr_cpu0_temp.dev_attr.attr,
233 &sensor_dev_attr_cpu1_temp.dev_attr.attr,
234 &sensor_dev_attr_motherboard_temp.dev_attr.attr,
235 &sensor_dev_attr_lm95221_local_temp.dev_attr.attr,
236 &sensor_dev_attr_fire_temp.dev_attr.attr,
237 &sensor_dev_attr_lsi1064_local_temp.dev_attr.attr,
238 &sensor_dev_attr_front_panel_temp.dev_attr.attr,
239 &sensor_dev_attr_psu_temp.dev_attr.attr,
240 &sensor_dev_attr_fan_failure.dev_attr.attr,
241 &sensor_dev_attr_env_bus_busy.dev_attr.attr,
242 &sensor_dev_attr_env_data_stale.dev_attr.attr,
243 &sensor_dev_attr_tpm_self_test_passed.dev_attr.attr,
244 &sensor_dev_attr_firmware_version.dev_attr.attr,
245 &sensor_dev_attr_name.dev_attr.attr,
250 .attrs = env_attributes,
274 goto out_sysfs_remove_group;
277 platform_set_drvdata(op, p);
283 out_sysfs_remove_group:
296 struct env *p = platform_get_drvdata(op);
310 .name =
"env-monitor",
311 .compatible =
"SUNW,ebus-pic16f747-env",
319 .name =
"ultra45_env",
321 .of_match_table = env_match,