Lines Matching +full:temp +full:- +full:sensor
1 // SPDX-License-Identifier: GPL-2.0+
7 #include <linux/hwmon-sysfs.h>
32 /* OCC sensor type and version definitions */
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()
165 if (header->occ_state == OCC_STATE_SAFE) { 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()
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()
212 int rc = mutex_lock_interruptible(&occ->lock); in occ_update_response()
218 if (time_after(jiffies, occ->next_update)) { 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()
234 struct temp_sensor_1 *temp; in occ_show_temp_1() local
236 struct occ_sensors *sensors = &occ->sensors; in occ_show_temp_1()
243 temp = ((struct temp_sensor_1 *)sensors->temp.data) + sattr->index; in occ_show_temp_1()
245 switch (sattr->nr) { in occ_show_temp_1()
247 val = get_unaligned_be16(&temp->sensor_id); in occ_show_temp_1()
251 * If a sensor reading has expired and couldn't be refreshed, in occ_show_temp_1()
252 * OCC returns 0xFFFF for that sensor. in occ_show_temp_1()
254 if (temp->value == 0xFFFF) in occ_show_temp_1()
255 return -EREMOTEIO; in occ_show_temp_1()
256 val = get_unaligned_be16(&temp->value) * 1000; in occ_show_temp_1()
259 return -EINVAL; in occ_show_temp_1()
270 struct temp_sensor_2 *temp; in occ_show_temp_2() local
272 struct occ_sensors *sensors = &occ->sensors; in occ_show_temp_2()
279 temp = ((struct temp_sensor_2 *)sensors->temp.data) + sattr->index; in occ_show_temp_2()
281 switch (sattr->nr) { in occ_show_temp_2()
283 val = get_unaligned_be32(&temp->sensor_id); in occ_show_temp_2()
286 val = temp->value; in occ_show_temp_2()
288 return -EREMOTEIO; in occ_show_temp_2()
295 if (temp->fru_type != OCC_FRU_TYPE_VRM) { in occ_show_temp_2()
296 /* sensor not ready */ in occ_show_temp_2()
298 return -EAGAIN; in occ_show_temp_2()
304 val = temp->fru_type; in occ_show_temp_2()
307 val = temp->value == OCC_TEMP_SENSOR_FAULT; in occ_show_temp_2()
310 return -EINVAL; in occ_show_temp_2()
321 struct temp_sensor_10 *temp; in occ_show_temp_10() local
323 struct occ_sensors *sensors = &occ->sensors; in occ_show_temp_10()
330 temp = ((struct temp_sensor_10 *)sensors->temp.data) + sattr->index; in occ_show_temp_10()
332 switch (sattr->nr) { in occ_show_temp_10()
334 val = get_unaligned_be32(&temp->sensor_id); in occ_show_temp_10()
337 val = temp->value; in occ_show_temp_10()
339 return -EREMOTEIO; in occ_show_temp_10()
341 /* sensor not ready */ in occ_show_temp_10()
343 return -EAGAIN; in occ_show_temp_10()
348 val = temp->fru_type; in occ_show_temp_10()
351 val = temp->value == OCC_TEMP_SENSOR_FAULT; in occ_show_temp_10()
354 val = temp->throttle * 1000; in occ_show_temp_10()
357 return -EINVAL; in occ_show_temp_10()
370 struct occ_sensors *sensors = &occ->sensors; in occ_show_freq_1()
377 freq = ((struct freq_sensor_1 *)sensors->freq.data) + sattr->index; in occ_show_freq_1()
379 switch (sattr->nr) { in occ_show_freq_1()
381 val = get_unaligned_be16(&freq->sensor_id); in occ_show_freq_1()
384 val = get_unaligned_be16(&freq->value); in occ_show_freq_1()
387 return -EINVAL; in occ_show_freq_1()
400 struct occ_sensors *sensors = &occ->sensors; in occ_show_freq_2()
407 freq = ((struct freq_sensor_2 *)sensors->freq.data) + sattr->index; in occ_show_freq_2()
409 switch (sattr->nr) { in occ_show_freq_2()
411 val = get_unaligned_be32(&freq->sensor_id); in occ_show_freq_2()
414 val = get_unaligned_be16(&freq->value); in occ_show_freq_2()
417 return -EINVAL; in occ_show_freq_2()
430 struct occ_sensors *sensors = &occ->sensors; in occ_show_power_1()
437 power = ((struct power_sensor_1 *)sensors->power.data) + sattr->index; in occ_show_power_1()
439 switch (sattr->nr) { in occ_show_power_1()
441 val = get_unaligned_be16(&power->sensor_id); in occ_show_power_1()
444 val = get_unaligned_be32(&power->accumulator) / in occ_show_power_1()
445 get_unaligned_be32(&power->update_tag); in occ_show_power_1()
449 val = (u64)get_unaligned_be32(&power->update_tag) * in occ_show_power_1()
450 occ->powr_sample_time_us; in occ_show_power_1()
453 val = get_unaligned_be16(&power->value) * 1000000ULL; in occ_show_power_1()
456 return -EINVAL; in occ_show_power_1()
477 struct occ_sensors *sensors = &occ->sensors; in occ_show_power_2()
484 power = ((struct power_sensor_2 *)sensors->power.data) + sattr->index; in occ_show_power_2()
486 switch (sattr->nr) { in occ_show_power_2()
489 get_unaligned_be32(&power->sensor_id), in occ_show_power_2()
490 power->function_id, power->apss_channel); in occ_show_power_2()
492 val = occ_get_powr_avg(&power->accumulator, in occ_show_power_2()
493 &power->update_tag); in occ_show_power_2()
496 val = (u64)get_unaligned_be32(&power->update_tag) * in occ_show_power_2()
497 occ->powr_sample_time_us; in occ_show_power_2()
500 val = get_unaligned_be16(&power->value) * 1000000ULL; in occ_show_power_2()
503 return -EINVAL; in occ_show_power_2()
516 struct occ_sensors *sensors = &occ->sensors; in occ_show_power_a0()
523 power = ((struct power_sensor_a0 *)sensors->power.data) + sattr->index; in occ_show_power_a0()
525 switch (sattr->nr) { in occ_show_power_a0()
528 get_unaligned_be32(&power->sensor_id)); in occ_show_power_a0()
530 val = occ_get_powr_avg(&power->system.accumulator, in occ_show_power_a0()
531 &power->system.update_tag); in occ_show_power_a0()
534 val = (u64)get_unaligned_be32(&power->system.update_tag) * in occ_show_power_a0()
535 occ->powr_sample_time_us; in occ_show_power_a0()
538 val = get_unaligned_be16(&power->system.value) * 1000000ULL; in occ_show_power_a0()
542 get_unaligned_be32(&power->sensor_id)); in occ_show_power_a0()
544 val = occ_get_powr_avg(&power->proc.accumulator, in occ_show_power_a0()
545 &power->proc.update_tag); in occ_show_power_a0()
548 val = (u64)get_unaligned_be32(&power->proc.update_tag) * in occ_show_power_a0()
549 occ->powr_sample_time_us; in occ_show_power_a0()
552 val = get_unaligned_be16(&power->proc.value) * 1000000ULL; in occ_show_power_a0()
556 get_unaligned_be32(&power->sensor_id)); in occ_show_power_a0()
558 val = occ_get_powr_avg(&power->vdd.accumulator, in occ_show_power_a0()
559 &power->vdd.update_tag); in occ_show_power_a0()
562 val = (u64)get_unaligned_be32(&power->vdd.update_tag) * in occ_show_power_a0()
563 occ->powr_sample_time_us; in occ_show_power_a0()
566 val = get_unaligned_be16(&power->vdd.value) * 1000000ULL; in occ_show_power_a0()
570 get_unaligned_be32(&power->sensor_id)); in occ_show_power_a0()
572 val = occ_get_powr_avg(&power->vdn.accumulator, in occ_show_power_a0()
573 &power->vdn.update_tag); in occ_show_power_a0()
576 val = (u64)get_unaligned_be32(&power->vdn.update_tag) * in occ_show_power_a0()
577 occ->powr_sample_time_us; in occ_show_power_a0()
580 val = get_unaligned_be16(&power->vdn.value) * 1000000ULL; in occ_show_power_a0()
583 return -EINVAL; in occ_show_power_a0()
596 struct occ_sensors *sensors = &occ->sensors; in occ_show_caps_1_2()
603 caps = ((struct caps_sensor_2 *)sensors->caps.data) + sattr->index; in occ_show_caps_1_2()
605 switch (sattr->nr) { in occ_show_caps_1_2()
609 val = get_unaligned_be16(&caps->cap) * 1000000ULL; in occ_show_caps_1_2()
612 val = get_unaligned_be16(&caps->system_power) * 1000000ULL; in occ_show_caps_1_2()
615 val = get_unaligned_be16(&caps->n_cap) * 1000000ULL; in occ_show_caps_1_2()
618 val = get_unaligned_be16(&caps->max) * 1000000ULL; in occ_show_caps_1_2()
621 val = get_unaligned_be16(&caps->min) * 1000000ULL; in occ_show_caps_1_2()
624 val = get_unaligned_be16(&caps->user) * 1000000ULL; in occ_show_caps_1_2()
627 if (occ->sensors.caps.version == 1) in occ_show_caps_1_2()
628 return -EINVAL; in occ_show_caps_1_2()
630 val = caps->user_source; in occ_show_caps_1_2()
633 return -EINVAL; in occ_show_caps_1_2()
646 struct occ_sensors *sensors = &occ->sensors; in occ_show_caps_3()
653 caps = ((struct caps_sensor_3 *)sensors->caps.data) + sattr->index; in occ_show_caps_3()
655 switch (sattr->nr) { in occ_show_caps_3()
659 val = get_unaligned_be16(&caps->cap) * 1000000ULL; in occ_show_caps_3()
662 val = get_unaligned_be16(&caps->system_power) * 1000000ULL; in occ_show_caps_3()
665 val = get_unaligned_be16(&caps->n_cap) * 1000000ULL; in occ_show_caps_3()
668 val = get_unaligned_be16(&caps->max) * 1000000ULL; in occ_show_caps_3()
671 val = get_unaligned_be16(&caps->hard_min) * 1000000ULL; in occ_show_caps_3()
674 val = get_unaligned_be16(&caps->user) * 1000000ULL; in occ_show_caps_3()
677 val = caps->user_source; in occ_show_caps_3()
680 val = get_unaligned_be16(&caps->soft_min) * 1000000ULL; in occ_show_caps_3()
683 return -EINVAL; in occ_show_caps_3()
717 struct occ_sensors *sensors = &occ->sensors; in occ_show_extended()
724 extn = ((struct extended_sensor *)sensors->extended.data) + in occ_show_extended()
725 sattr->index; in occ_show_extended()
727 switch (sattr->nr) { in occ_show_extended()
729 if (extn->flags & EXTN_FLAG_SENSOR_ID) { in occ_show_extended()
731 get_unaligned_be32(&extn->sensor_id)); in occ_show_extended()
733 rc = sysfs_emit(buf, "%4phN\n", extn->name); in occ_show_extended()
737 rc = sysfs_emit(buf, "%02x\n", extn->flags); in occ_show_extended()
740 rc = sysfs_emit(buf, "%6phN\n", extn->data); in occ_show_extended()
743 return -EINVAL; in occ_show_extended()
775 * use our own instead of the built-in hwmon attribute types.
780 struct device *dev = occ->bus_dev; in occ_setup_sensor_attrs()
781 struct occ_sensors *sensors = &occ->sensors; in occ_setup_sensor_attrs()
783 struct temp_sensor_2 *temp; in occ_setup_sensor_attrs() local
793 switch (sensors->temp.version) { in occ_setup_sensor_attrs()
795 num_attrs += (sensors->temp.num_sensors * 2); in occ_setup_sensor_attrs()
798 num_attrs += (sensors->temp.num_sensors * 4); in occ_setup_sensor_attrs()
802 num_attrs += (sensors->temp.num_sensors * 5); in occ_setup_sensor_attrs()
806 sensors->temp.num_sensors = 0; in occ_setup_sensor_attrs()
809 switch (sensors->freq.version) { in occ_setup_sensor_attrs()
814 num_attrs += (sensors->freq.num_sensors * 2); in occ_setup_sensor_attrs()
817 sensors->freq.num_sensors = 0; in occ_setup_sensor_attrs()
820 switch (sensors->power.version) { in occ_setup_sensor_attrs()
825 num_attrs += (sensors->power.num_sensors * 4); in occ_setup_sensor_attrs()
828 num_attrs += (sensors->power.num_sensors * 16); in occ_setup_sensor_attrs()
832 sensors->power.num_sensors = 0; in occ_setup_sensor_attrs()
835 switch (sensors->caps.version) { in occ_setup_sensor_attrs()
837 num_attrs += (sensors->caps.num_sensors * 7); in occ_setup_sensor_attrs()
840 num_attrs += (sensors->caps.num_sensors * 8); in occ_setup_sensor_attrs()
844 num_attrs += (sensors->caps.num_sensors * 9); in occ_setup_sensor_attrs()
847 sensors->caps.num_sensors = 0; in occ_setup_sensor_attrs()
850 switch (sensors->extended.version) { in occ_setup_sensor_attrs()
852 num_attrs += (sensors->extended.num_sensors * 3); in occ_setup_sensor_attrs()
855 sensors->extended.num_sensors = 0; 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()
861 return -ENOMEM; in occ_setup_sensor_attrs()
863 /* null-terminated list */ 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()
867 return -ENOMEM; in occ_setup_sensor_attrs()
869 attr = occ->attrs; in occ_setup_sensor_attrs()
871 for (i = 0; i < sensors->temp.num_sensors; ++i) { in occ_setup_sensor_attrs()
873 temp = ((struct temp_sensor_2 *)sensors->temp.data) + i; in occ_setup_sensor_attrs()
875 snprintf(attr->name, sizeof(attr->name), "temp%d_label", s); in occ_setup_sensor_attrs()
876 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, show_temp, NULL, in occ_setup_sensor_attrs()
880 if (sensors->temp.version == 2 && in occ_setup_sensor_attrs()
881 temp->fru_type == OCC_FRU_TYPE_VRM) { in occ_setup_sensor_attrs()
882 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
883 "temp%d_alarm", s); in occ_setup_sensor_attrs()
885 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
886 "temp%d_input", s); in occ_setup_sensor_attrs()
889 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, show_temp, NULL, in occ_setup_sensor_attrs()
893 if (sensors->temp.version > 1) { in occ_setup_sensor_attrs()
894 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
895 "temp%d_fru_type", s); in occ_setup_sensor_attrs()
896 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, in occ_setup_sensor_attrs()
900 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
901 "temp%d_fault", s); in occ_setup_sensor_attrs()
902 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, in occ_setup_sensor_attrs()
906 if (sensors->temp.version == 0x10) { in occ_setup_sensor_attrs()
907 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
908 "temp%d_max", s); in occ_setup_sensor_attrs()
909 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, in occ_setup_sensor_attrs()
917 for (i = 0; i < sensors->freq.num_sensors; ++i) { in occ_setup_sensor_attrs()
920 snprintf(attr->name, sizeof(attr->name), "freq%d_label", s); in occ_setup_sensor_attrs()
921 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, show_freq, NULL, in occ_setup_sensor_attrs()
925 snprintf(attr->name, sizeof(attr->name), "freq%d_input", s); in occ_setup_sensor_attrs()
926 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, show_freq, NULL, in occ_setup_sensor_attrs()
931 if (sensors->power.version == 0xA0) { in occ_setup_sensor_attrs()
933 * Special case for many-attribute power sensor. Split it into in occ_setup_sensor_attrs()
934 * a sensor number per power type, emulating several sensors. in occ_setup_sensor_attrs()
936 for (i = 0; i < sensors->power.num_sensors; ++i) { in occ_setup_sensor_attrs()
943 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
945 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, in occ_setup_sensor_attrs()
950 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
952 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, in occ_setup_sensor_attrs()
957 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
959 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, in occ_setup_sensor_attrs()
964 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
966 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, in occ_setup_sensor_attrs()
975 s = (sensors->power.num_sensors * 4) + 1; in occ_setup_sensor_attrs()
977 for (i = 0; i < sensors->power.num_sensors; ++i) { in occ_setup_sensor_attrs()
980 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
982 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, in occ_setup_sensor_attrs()
986 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
988 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, in occ_setup_sensor_attrs()
992 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
994 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, in occ_setup_sensor_attrs()
998 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
1000 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, in occ_setup_sensor_attrs()
1005 s = sensors->power.num_sensors + 1; in occ_setup_sensor_attrs()
1008 if (sensors->caps.num_sensors >= 1) { in occ_setup_sensor_attrs()
1009 snprintf(attr->name, sizeof(attr->name), "power%d_label", s); in occ_setup_sensor_attrs()
1010 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, show_caps, NULL, in occ_setup_sensor_attrs()
1014 snprintf(attr->name, sizeof(attr->name), "power%d_cap", s); in occ_setup_sensor_attrs()
1015 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, show_caps, NULL, in occ_setup_sensor_attrs()
1019 snprintf(attr->name, sizeof(attr->name), "power%d_input", s); in occ_setup_sensor_attrs()
1020 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, show_caps, NULL, in occ_setup_sensor_attrs()
1024 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
1026 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, show_caps, NULL, in occ_setup_sensor_attrs()
1030 snprintf(attr->name, sizeof(attr->name), "power%d_cap_max", s); in occ_setup_sensor_attrs()
1031 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, show_caps, NULL, in occ_setup_sensor_attrs()
1035 snprintf(attr->name, sizeof(attr->name), "power%d_cap_min", s); in occ_setup_sensor_attrs()
1036 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, show_caps, NULL, in occ_setup_sensor_attrs()
1040 snprintf(attr->name, sizeof(attr->name), "power%d_cap_user", in occ_setup_sensor_attrs()
1042 attr->sensor = OCC_INIT_ATTR(attr->name, 0644, show_caps, in occ_setup_sensor_attrs()
1046 if (sensors->caps.version > 1) { in occ_setup_sensor_attrs()
1047 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
1049 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, in occ_setup_sensor_attrs()
1053 if (sensors->caps.version > 2) { in occ_setup_sensor_attrs()
1054 snprintf(attr->name, sizeof(attr->name), in occ_setup_sensor_attrs()
1056 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, in occ_setup_sensor_attrs()
1064 for (i = 0; i < sensors->extended.num_sensors; ++i) { in occ_setup_sensor_attrs()
1067 snprintf(attr->name, sizeof(attr->name), "extn%d_label", s); in occ_setup_sensor_attrs()
1068 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, in occ_setup_sensor_attrs()
1072 snprintf(attr->name, sizeof(attr->name), "extn%d_flags", s); in occ_setup_sensor_attrs()
1073 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, in occ_setup_sensor_attrs()
1077 snprintf(attr->name, sizeof(attr->name), "extn%d_input", s); in occ_setup_sensor_attrs()
1078 attr->sensor = OCC_INIT_ATTR(attr->name, 0444, 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()
1096 struct occ_sensor *sensor; in occ_parse_poll_response() local
1097 struct occ_sensors *sensors = &occ->sensors; in occ_parse_poll_response()
1098 struct occ_response *resp = &occ->resp; in occ_parse_poll_response()
1100 (struct occ_poll_response *)&resp->data[0]; in occ_parse_poll_response()
1101 struct occ_poll_response_header *header = &poll->header; in occ_parse_poll_response()
1102 struct occ_sensor_data_block *block = &poll->block; in occ_parse_poll_response()
1104 dev_info(occ->bus_dev, "OCC found, code level: %.16s\n", in occ_parse_poll_response()
1105 header->occ_code_level); in occ_parse_poll_response()
1107 for (i = 0; i < header->num_sensor_data_blocks; ++i) { in occ_parse_poll_response()
1110 offset = (block->header.num_sensors * in occ_parse_poll_response()
1111 block->header.sensor_length) + sizeof(block->header); 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()
1121 old_offset, offset - 1, block->header.eye_catcher, in occ_parse_poll_response()
1122 block->header.num_sensors); in occ_parse_poll_response()
1124 /* match sensor block type */ in occ_parse_poll_response()
1125 if (strncmp(block->header.eye_catcher, "TEMP", 4) == 0) in occ_parse_poll_response()
1126 sensor = &sensors->temp; in occ_parse_poll_response()
1127 else if (strncmp(block->header.eye_catcher, "FREQ", 4) == 0) in occ_parse_poll_response()
1128 sensor = &sensors->freq; in occ_parse_poll_response()
1129 else if (strncmp(block->header.eye_catcher, "POWR", 4) == 0) in occ_parse_poll_response()
1130 sensor = &sensors->power; in occ_parse_poll_response()
1131 else if (strncmp(block->header.eye_catcher, "CAPS", 4) == 0) in occ_parse_poll_response()
1132 sensor = &sensors->caps; in occ_parse_poll_response()
1133 else if (strncmp(block->header.eye_catcher, "EXTN", 4) == 0) in occ_parse_poll_response()
1134 sensor = &sensors->extended; in occ_parse_poll_response()
1136 dev_warn(occ->bus_dev, "sensor not supported %.4s\n", in occ_parse_poll_response()
1137 block->header.eye_catcher); in occ_parse_poll_response()
1141 sensor->num_sensors = block->header.num_sensors; in occ_parse_poll_response()
1142 sensor->version = block->header.sensor_format; in occ_parse_poll_response()
1143 sensor->data = &block->data; in occ_parse_poll_response()
1146 dev_dbg(occ->bus_dev, "Max resp size: %u+%zd=%zd\n", size, in occ_parse_poll_response()
1152 int rc = mutex_lock_interruptible(&occ->lock); in occ_active()
1158 if (occ->active) { in occ_active()
1159 rc = -EALREADY; in occ_active()
1163 occ->error_count = 0; in occ_active()
1164 occ->last_safe = 0; 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()
1180 dev_err(occ->bus_dev, in occ_active()
1181 "failed to setup sensor attrs: %d\n", rc); in occ_active()
1185 occ->hwmon = hwmon_device_register_with_groups(occ->bus_dev, 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()
1197 rc = -EALREADY; 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()
1216 mutex_init(&occ->lock); in occ_setup()
1217 occ->groups[0] = &occ->group; 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()
1237 mutex_lock(&occ->lock); 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()