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