Lines Matching refs:occ

133 static int occ_poll(struct occ *occ)  in occ_poll()  argument
144 cmd[4] = occ->poll_cmd_data; /* data */ in occ_poll()
149 rc = occ->send_cmd(occ, cmd, sizeof(cmd), &occ->resp, sizeof(occ->resp)); in occ_poll()
151 occ->last_error = rc; in occ_poll()
152 if (occ->error_count++ > OCC_ERROR_COUNT_THRESHOLD) in occ_poll()
153 occ->error = rc; in occ_poll()
159 occ->error_count = 0; in occ_poll()
160 occ->last_error = 0; in occ_poll()
161 occ->error = 0; in occ_poll()
164 header = (struct occ_poll_response_header *)occ->resp.data; in occ_poll()
166 if (occ->last_safe) { in occ_poll()
168 occ->last_safe + OCC_SAFE_TIMEOUT)) in occ_poll()
169 occ->error = -EHOSTDOWN; in occ_poll()
171 occ->last_safe = jiffies; in occ_poll()
174 occ->last_safe = 0; in occ_poll()
178 occ_sysfs_poll_done(occ); in occ_poll()
182 static int occ_set_user_power_cap(struct occ *occ, u16 user_power_cap) in occ_set_user_power_cap() argument
199 rc = mutex_lock_interruptible(&occ->lock); in occ_set_user_power_cap()
203 rc = occ->send_cmd(occ, cmd, sizeof(cmd), resp, sizeof(resp)); in occ_set_user_power_cap()
205 mutex_unlock(&occ->lock); in occ_set_user_power_cap()
210 int occ_update_response(struct occ *occ) in occ_update_response() argument
212 int rc = mutex_lock_interruptible(&occ->lock); in occ_update_response()
218 if (time_after(jiffies, occ->next_update)) { in occ_update_response()
219 rc = occ_poll(occ); in occ_update_response()
220 occ->next_update = jiffies + OCC_UPDATE_FREQUENCY; in occ_update_response()
222 rc = occ->last_error; in occ_update_response()
225 mutex_unlock(&occ->lock); in occ_update_response()
235 struct occ *occ = dev_get_drvdata(dev); in occ_show_temp_1() local
236 struct occ_sensors *sensors = &occ->sensors; in occ_show_temp_1()
239 rc = occ_update_response(occ); in occ_show_temp_1()
271 struct occ *occ = dev_get_drvdata(dev); in occ_show_temp_2() local
272 struct occ_sensors *sensors = &occ->sensors; in occ_show_temp_2()
275 rc = occ_update_response(occ); in occ_show_temp_2()
322 struct occ *occ = dev_get_drvdata(dev); in occ_show_temp_10() local
323 struct occ_sensors *sensors = &occ->sensors; in occ_show_temp_10()
326 rc = occ_update_response(occ); in occ_show_temp_10()
369 struct occ *occ = dev_get_drvdata(dev); in occ_show_freq_1() local
370 struct occ_sensors *sensors = &occ->sensors; in occ_show_freq_1()
373 rc = occ_update_response(occ); in occ_show_freq_1()
399 struct occ *occ = dev_get_drvdata(dev); in occ_show_freq_2() local
400 struct occ_sensors *sensors = &occ->sensors; in occ_show_freq_2()
403 rc = occ_update_response(occ); in occ_show_freq_2()
429 struct occ *occ = dev_get_drvdata(dev); in occ_show_power_1() local
430 struct occ_sensors *sensors = &occ->sensors; in occ_show_power_1()
433 rc = occ_update_response(occ); in occ_show_power_1()
450 occ->powr_sample_time_us; in occ_show_power_1()
476 struct occ *occ = dev_get_drvdata(dev); in occ_show_power_2() local
477 struct occ_sensors *sensors = &occ->sensors; in occ_show_power_2()
480 rc = occ_update_response(occ); in occ_show_power_2()
497 occ->powr_sample_time_us; in occ_show_power_2()
515 struct occ *occ = dev_get_drvdata(dev); in occ_show_power_a0() local
516 struct occ_sensors *sensors = &occ->sensors; in occ_show_power_a0()
519 rc = occ_update_response(occ); in occ_show_power_a0()
535 occ->powr_sample_time_us; in occ_show_power_a0()
549 occ->powr_sample_time_us; in occ_show_power_a0()
563 occ->powr_sample_time_us; in occ_show_power_a0()
577 occ->powr_sample_time_us; in occ_show_power_a0()
595 struct occ *occ = dev_get_drvdata(dev); in occ_show_caps_1_2() local
596 struct occ_sensors *sensors = &occ->sensors; in occ_show_caps_1_2()
599 rc = occ_update_response(occ); in occ_show_caps_1_2()
627 if (occ->sensors.caps.version == 1) in occ_show_caps_1_2()
645 struct occ *occ = dev_get_drvdata(dev); in occ_show_caps_3() local
646 struct occ_sensors *sensors = &occ->sensors; in occ_show_caps_3()
649 rc = occ_update_response(occ); in occ_show_caps_3()
696 struct occ *occ = dev_get_drvdata(dev); in occ_store_caps_user() local
704 rc = occ_set_user_power_cap(occ, user_power_cap); in occ_store_caps_user()
716 struct occ *occ = dev_get_drvdata(dev); in occ_show_extended() local
717 struct occ_sensors *sensors = &occ->sensors; in occ_show_extended()
720 rc = occ_update_response(occ); in occ_show_extended()
777 static int occ_setup_sensor_attrs(struct occ *occ) in occ_setup_sensor_attrs() argument
780 struct device *dev = occ->bus_dev; in occ_setup_sensor_attrs()
781 struct occ_sensors *sensors = &occ->sensors; in occ_setup_sensor_attrs()
858 occ->attrs = devm_kzalloc(dev, sizeof(*occ->attrs) * num_attrs, in occ_setup_sensor_attrs()
860 if (!occ->attrs) in occ_setup_sensor_attrs()
864 occ->group.attrs = devm_kzalloc(dev, sizeof(*occ->group.attrs) * in occ_setup_sensor_attrs()
866 if (!occ->group.attrs) in occ_setup_sensor_attrs()
869 attr = occ->attrs; in occ_setup_sensor_attrs()
1085 sysfs_attr_init(&occ->attrs[i].sensor.dev_attr.attr); in occ_setup_sensor_attrs()
1086 occ->group.attrs[i] = &occ->attrs[i].sensor.dev_attr.attr; in occ_setup_sensor_attrs()
1093 static void occ_parse_poll_response(struct occ *occ) in occ_parse_poll_response() argument
1097 struct occ_sensors *sensors = &occ->sensors; in occ_parse_poll_response()
1098 struct occ_response *resp = &occ->resp; in occ_parse_poll_response()
1104 dev_info(occ->bus_dev, "OCC found, code level: %.16s\n", in occ_parse_poll_response()
1116 dev_warn(occ->bus_dev, "exceeded response buffer\n"); in occ_parse_poll_response()
1120 dev_dbg(occ->bus_dev, " %04x..%04x: %.4s (%d sensors)\n", in occ_parse_poll_response()
1136 dev_warn(occ->bus_dev, "sensor not supported %.4s\n", in occ_parse_poll_response()
1146 dev_dbg(occ->bus_dev, "Max resp size: %u+%zd=%zd\n", size, in occ_parse_poll_response()
1150 int occ_active(struct occ *occ, bool active) in occ_active() argument
1152 int rc = mutex_lock_interruptible(&occ->lock); in occ_active()
1158 if (occ->active) { in occ_active()
1163 occ->error_count = 0; in occ_active()
1164 occ->last_safe = 0; in occ_active()
1166 rc = occ_poll(occ); in occ_active()
1168 dev_err(occ->bus_dev, in occ_active()
1170 occ->resp.return_status, rc); in occ_active()
1174 occ->active = true; in occ_active()
1175 occ->next_update = jiffies + OCC_UPDATE_FREQUENCY; in occ_active()
1176 occ_parse_poll_response(occ); in occ_active()
1178 rc = occ_setup_sensor_attrs(occ); in occ_active()
1180 dev_err(occ->bus_dev, in occ_active()
1185 occ->hwmon = hwmon_device_register_with_groups(occ->bus_dev, in occ_active()
1186 "occ", occ, in occ_active()
1187 occ->groups); in occ_active()
1188 if (IS_ERR(occ->hwmon)) { in occ_active()
1189 rc = PTR_ERR(occ->hwmon); in occ_active()
1190 occ->hwmon = NULL; in occ_active()
1191 dev_err(occ->bus_dev, in occ_active()
1196 if (!occ->active) { in occ_active()
1201 if (occ->hwmon) in occ_active()
1202 hwmon_device_unregister(occ->hwmon); in occ_active()
1203 occ->active = false; in occ_active()
1204 occ->hwmon = NULL; in occ_active()
1208 mutex_unlock(&occ->lock); in occ_active()
1212 int occ_setup(struct occ *occ) in occ_setup() argument
1216 mutex_init(&occ->lock); in occ_setup()
1217 occ->groups[0] = &occ->group; in occ_setup()
1219 rc = occ_setup_sysfs(occ); in occ_setup()
1221 dev_err(occ->bus_dev, "failed to setup sysfs: %d\n", rc); in occ_setup()
1225 if (!device_property_read_bool(occ->bus_dev, "ibm,no-poll-on-init")) { in occ_setup()
1226 rc = occ_active(occ, true); in occ_setup()
1228 occ_shutdown_sysfs(occ); in occ_setup()
1235 void occ_shutdown(struct occ *occ) in occ_shutdown() argument
1237 mutex_lock(&occ->lock); in occ_shutdown()
1239 occ_shutdown_sysfs(occ); in occ_shutdown()
1241 if (occ->hwmon) in occ_shutdown()
1242 hwmon_device_unregister(occ->hwmon); in occ_shutdown()
1243 occ->hwmon = NULL; in occ_shutdown()
1245 mutex_unlock(&occ->lock); in occ_shutdown()