1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Copyright IBM Corp 2019 */
7 #include <linux/hwmon-sysfs.h>
8 #include <linux/mutex.h>
9 #include <linux/sysfs.h>
13 #define OCC_RESP_DATA_BYTES 4089
16 * Same response format for all OCC versions.
17 * Allocate the largest possible response.
24 u8 data[OCC_RESP_DATA_BYTES];
28 struct occ_sensor_data_block_header {
36 struct occ_sensor_data_block {
37 struct occ_sensor_data_block_header header;
41 struct occ_poll_response_header {
50 __be32 error_log_start_address;
51 __be16 error_log_length;
53 u8 occ_code_level[16];
55 u8 num_sensor_data_blocks;
56 u8 sensor_data_block_header_version;
59 struct occ_poll_response {
60 struct occ_poll_response_header header;
61 struct occ_sensor_data_block block;
67 void *data; /* pointer to sensor data start within response */
71 * OCC only provides one sensor data block of each type, but any number of
72 * sensors within that block.
75 struct occ_sensor temp;
76 struct occ_sensor freq;
77 struct occ_sensor power;
78 struct occ_sensor caps;
79 struct occ_sensor extended;
83 * Use our own attribute struct so we can dynamically allocate space for the
86 struct occ_attribute {
88 struct sensor_device_attribute_2 sensor;
92 struct device *bus_dev;
94 struct occ_response resp;
95 struct occ_sensors sensors;
97 int powr_sample_time_us; /* average power sample time */
98 u8 poll_cmd_data; /* to perform OCC poll command */
99 int (*send_cmd)(struct occ *occ, u8 *cmd);
101 unsigned long last_update;
102 struct mutex lock; /* lock OCC access */
104 struct device *hwmon;
105 struct occ_attribute *attrs;
106 struct attribute_group group;
107 const struct attribute_group *groups[2];
109 int error; /* final transfer error after retry */
110 int last_error; /* latest transfer error */
111 unsigned int error_count; /* number of xfr errors observed */
112 unsigned long last_safe; /* time OCC entered "safe" state */
115 * Store the previous state data for comparison in order to notify
116 * sysfs readers of state changes.
121 u8 prev_occs_present;
124 int occ_setup(struct occ *occ, const char *name);
125 int occ_setup_sysfs(struct occ *occ);
126 void occ_shutdown(struct occ *occ);
127 void occ_sysfs_poll_done(struct occ *occ);
128 int occ_update_response(struct occ *occ);
130 #endif /* OCC_COMMON_H */