Lines Matching refs:occ

124 static int occ_poll(struct occ *occ)
127 u16 checksum = occ->poll_cmd_data + occ->seq_no + 1;
132 cmd[0] = occ->seq_no++; /* sequence number */
136 cmd[4] = occ->poll_cmd_data; /* data */
142 rc = occ->send_cmd(occ, cmd);
144 occ->last_error = rc;
145 if (occ->error_count++ > OCC_ERROR_COUNT_THRESHOLD)
146 occ->error = rc;
152 occ->error_count = 0;
153 occ->last_error = 0;
154 occ->error = 0;
157 header = (struct occ_poll_response_header *)occ->resp.data;
159 if (occ->last_safe) {
161 occ->last_safe + OCC_SAFE_TIMEOUT))
162 occ->error = -EHOSTDOWN;
164 occ->last_safe = jiffies;
167 occ->last_safe = 0;
171 occ_sysfs_poll_done(occ);
175 static int occ_set_user_power_cap(struct occ *occ, u16 user_power_cap)
193 rc = mutex_lock_interruptible(&occ->lock);
197 rc = occ->send_cmd(occ, cmd);
199 mutex_unlock(&occ->lock);
204 int occ_update_response(struct occ *occ)
206 int rc = mutex_lock_interruptible(&occ->lock);
212 if (time_after(jiffies, occ->next_update)) {
213 rc = occ_poll(occ);
214 occ->next_update = jiffies + OCC_UPDATE_FREQUENCY;
216 rc = occ->last_error;
219 mutex_unlock(&occ->lock);
229 struct occ *occ = dev_get_drvdata(dev);
230 struct occ_sensors *sensors = &occ->sensors;
233 rc = occ_update_response(occ);
265 struct occ *occ = dev_get_drvdata(dev);
266 struct occ_sensors *sensors = &occ->sensors;
269 rc = occ_update_response(occ);
316 struct occ *occ = dev_get_drvdata(dev);
317 struct occ_sensors *sensors = &occ->sensors;
320 rc = occ_update_response(occ);
346 struct occ *occ = dev_get_drvdata(dev);
347 struct occ_sensors *sensors = &occ->sensors;
350 rc = occ_update_response(occ);
376 struct occ *occ = dev_get_drvdata(dev);
377 struct occ_sensors *sensors = &occ->sensors;
380 rc = occ_update_response(occ);
397 occ->powr_sample_time_us;
423 struct occ *occ = dev_get_drvdata(dev);
424 struct occ_sensors *sensors = &occ->sensors;
427 rc = occ_update_response(occ);
444 occ->powr_sample_time_us;
462 struct occ *occ = dev_get_drvdata(dev);
463 struct occ_sensors *sensors = &occ->sensors;
466 rc = occ_update_response(occ);
482 occ->powr_sample_time_us;
496 occ->powr_sample_time_us;
510 occ->powr_sample_time_us;
524 occ->powr_sample_time_us;
542 struct occ *occ = dev_get_drvdata(dev);
543 struct occ_sensors *sensors = &occ->sensors;
546 rc = occ_update_response(occ);
574 if (occ->sensors.caps.version == 1)
592 struct occ *occ = dev_get_drvdata(dev);
593 struct occ_sensors *sensors = &occ->sensors;
596 rc = occ_update_response(occ);
640 struct occ *occ = dev_get_drvdata(dev);
648 rc = occ_set_user_power_cap(occ, user_power_cap);
660 struct occ *occ = dev_get_drvdata(dev);
661 struct occ_sensors *sensors = &occ->sensors;
664 rc = occ_update_response(occ);
724 static int occ_setup_sensor_attrs(struct occ *occ)
727 struct device *dev = occ->bus_dev;
728 struct occ_sensors *sensors = &occ->sensors;
800 occ->attrs = devm_kzalloc(dev, sizeof(*occ->attrs) * num_attrs,
802 if (!occ->attrs)
806 occ->group.attrs = devm_kzalloc(dev, sizeof(*occ->group.attrs) *
808 if (!occ->group.attrs)
811 attr = occ->attrs;
1009 sysfs_attr_init(&occ->attrs[i].sensor.dev_attr.attr);
1010 occ->group.attrs[i] = &occ->attrs[i].sensor.dev_attr.attr;
1017 static void occ_parse_poll_response(struct occ *occ)
1021 struct occ_sensors *sensors = &occ->sensors;
1022 struct occ_response *resp = &occ->resp;
1028 dev_info(occ->bus_dev, "OCC found, code level: %.16s\n",
1040 dev_warn(occ->bus_dev, "exceeded response buffer\n");
1044 dev_dbg(occ->bus_dev, " %04x..%04x: %.4s (%d sensors)\n",
1060 dev_warn(occ->bus_dev, "sensor not supported %.4s\n",
1070 dev_dbg(occ->bus_dev, "Max resp size: %u+%zd=%zd\n", size,
1074 int occ_setup(struct occ *occ, const char *name)
1078 mutex_init(&occ->lock);
1079 occ->groups[0] = &occ->group;
1082 rc = occ_poll(occ);
1084 dev_info(occ->bus_dev, "host is not ready\n");
1087 dev_err(occ->bus_dev, "failed to get OCC poll response: %d\n",
1092 occ->next_update = jiffies + OCC_UPDATE_FREQUENCY;
1093 occ_parse_poll_response(occ);
1095 rc = occ_setup_sensor_attrs(occ);
1097 dev_err(occ->bus_dev, "failed to setup sensor attrs: %d\n",
1102 occ->hwmon = devm_hwmon_device_register_with_groups(occ->bus_dev, name,
1103 occ, occ->groups);
1104 if (IS_ERR(occ->hwmon)) {
1105 rc = PTR_ERR(occ->hwmon);
1106 dev_err(occ->bus_dev, "failed to register hwmon device: %d\n",
1111 rc = occ_setup_sysfs(occ);
1113 dev_err(occ->bus_dev, "failed to setup sysfs: %d\n", rc);