0001
0002
0003
0004 #ifndef OCC_COMMON_H
0005 #define OCC_COMMON_H
0006
0007 #include <linux/hwmon-sysfs.h>
0008 #include <linux/mutex.h>
0009 #include <linux/sysfs.h>
0010
0011 struct device;
0012
0013 #define OCC_RESP_DATA_BYTES 4089
0014
0015
0016
0017
0018
0019 struct occ_response {
0020 u8 seq_no;
0021 u8 cmd_type;
0022 u8 return_status;
0023 __be16 data_length;
0024 u8 data[OCC_RESP_DATA_BYTES];
0025 __be16 checksum;
0026 } __packed;
0027
0028 struct occ_sensor_data_block_header {
0029 u8 eye_catcher[4];
0030 u8 reserved;
0031 u8 sensor_format;
0032 u8 sensor_length;
0033 u8 num_sensors;
0034 } __packed;
0035
0036 struct occ_sensor_data_block {
0037 struct occ_sensor_data_block_header header;
0038 u32 data;
0039 } __packed;
0040
0041 struct occ_poll_response_header {
0042 u8 status;
0043 u8 ext_status;
0044 u8 occs_present;
0045 u8 config_data;
0046 u8 occ_state;
0047 u8 mode;
0048 u8 ips_status;
0049 u8 error_log_id;
0050 __be32 error_log_start_address;
0051 __be16 error_log_length;
0052 u16 reserved;
0053 u8 occ_code_level[16];
0054 u8 eye_catcher[6];
0055 u8 num_sensor_data_blocks;
0056 u8 sensor_data_block_header_version;
0057 } __packed;
0058
0059 struct occ_poll_response {
0060 struct occ_poll_response_header header;
0061 struct occ_sensor_data_block block;
0062 } __packed;
0063
0064 struct occ_sensor {
0065 u8 num_sensors;
0066 u8 version;
0067 void *data;
0068 };
0069
0070
0071
0072
0073
0074 struct occ_sensors {
0075 struct occ_sensor temp;
0076 struct occ_sensor freq;
0077 struct occ_sensor power;
0078 struct occ_sensor caps;
0079 struct occ_sensor extended;
0080 };
0081
0082
0083
0084
0085
0086 struct occ_attribute {
0087 char name[32];
0088 struct sensor_device_attribute_2 sensor;
0089 };
0090
0091 struct occ {
0092 struct device *bus_dev;
0093
0094 struct occ_response resp;
0095 struct occ_sensors sensors;
0096
0097 int powr_sample_time_us;
0098 u8 poll_cmd_data;
0099 int (*send_cmd)(struct occ *occ, u8 *cmd, size_t len, void *resp,
0100 size_t resp_len);
0101
0102 unsigned long next_update;
0103 struct mutex lock;
0104
0105 struct device *hwmon;
0106 struct occ_attribute *attrs;
0107 struct attribute_group group;
0108 const struct attribute_group *groups[2];
0109
0110 bool active;
0111 int error;
0112 int last_error;
0113 unsigned int error_count;
0114 unsigned long last_safe;
0115
0116
0117
0118
0119
0120 int prev_error;
0121 u8 prev_stat;
0122 u8 prev_ext_stat;
0123 u8 prev_occs_present;
0124 u8 prev_ips_status;
0125 u8 prev_mode;
0126 };
0127
0128 int occ_active(struct occ *occ, bool active);
0129 int occ_setup(struct occ *occ);
0130 int occ_setup_sysfs(struct occ *occ);
0131 void occ_shutdown(struct occ *occ);
0132 void occ_shutdown_sysfs(struct occ *occ);
0133 void occ_sysfs_poll_done(struct occ *occ);
0134 int occ_update_response(struct occ *occ);
0135
0136 #endif