Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

firmware: arm_scmi: Port sensor protocol to new protocols interface

Convert internals of protocol implementation to use protocol handles and
expose a new protocol operations interface for SCMI driver using the new
get/put common operations, while keeping the old handle->sensor_ops still
around to ease transition.

Remove handle->sensor_priv now unused.

Link: https://lore.kernel.org/r/20210316124903.35011-24-cristian.marussi@arm.com
Tested-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>

authored by

Cristian Marussi and committed by
Sudeep Holla
9694a7f6 497ef0cb

+195 -104
+177 -100
drivers/firmware/arm_scmi/sensors.c
··· 201 201 struct scmi_sensor_info *sensors; 202 202 }; 203 203 204 - static int scmi_sensor_attributes_get(const struct scmi_handle *handle, 204 + static int scmi_sensor_attributes_get(const struct scmi_protocol_handle *ph, 205 205 struct sensors_info *si) 206 206 { 207 207 int ret; 208 208 struct scmi_xfer *t; 209 209 struct scmi_msg_resp_sensor_attributes *attr; 210 210 211 - ret = scmi_xfer_get_init(handle, PROTOCOL_ATTRIBUTES, 212 - SCMI_PROTOCOL_SENSOR, 0, sizeof(*attr), &t); 211 + ret = ph->xops->xfer_get_init(ph, PROTOCOL_ATTRIBUTES, 212 + 0, sizeof(*attr), &t); 213 213 if (ret) 214 214 return ret; 215 215 216 216 attr = t->rx.buf; 217 217 218 - ret = scmi_do_xfer(handle, t); 218 + ret = ph->xops->do_xfer(ph, t); 219 219 if (!ret) { 220 220 si->num_sensors = le16_to_cpu(attr->num_sensors); 221 221 si->max_requests = attr->max_requests; ··· 224 224 si->reg_size = le32_to_cpu(attr->reg_size); 225 225 } 226 226 227 - scmi_xfer_put(handle, t); 227 + ph->xops->xfer_put(ph, t); 228 228 return ret; 229 229 } 230 230 ··· 235 235 out->max_range = get_unaligned_le64((void *)&in->max_range_low); 236 236 } 237 237 238 - static int scmi_sensor_update_intervals(const struct scmi_handle *handle, 238 + static int scmi_sensor_update_intervals(const struct scmi_protocol_handle *ph, 239 239 struct scmi_sensor_info *s) 240 240 { 241 241 int ret, cnt; ··· 245 245 struct scmi_msg_resp_sensor_list_update_intervals *buf; 246 246 struct scmi_msg_sensor_list_update_intervals *msg; 247 247 248 - ret = scmi_xfer_get_init(handle, SENSOR_LIST_UPDATE_INTERVALS, 249 - SCMI_PROTOCOL_SENSOR, sizeof(*msg), 0, &ti); 248 + ret = ph->xops->xfer_get_init(ph, SENSOR_LIST_UPDATE_INTERVALS, 249 + sizeof(*msg), 0, &ti); 250 250 if (ret) 251 251 return ret; 252 252 ··· 259 259 msg->id = cpu_to_le32(s->id); 260 260 msg->index = cpu_to_le32(desc_index); 261 261 262 - ret = scmi_do_xfer(handle, ti); 262 + ret = ph->xops->do_xfer(ph, ti); 263 263 if (ret) 264 264 break; 265 265 ··· 277 277 /* segmented intervals are reported in one triplet */ 278 278 if (s->intervals.segmented && 279 279 (num_remaining || num_returned != 3)) { 280 - dev_err(handle->dev, 280 + dev_err(ph->dev, 281 281 "Sensor ID:%d advertises an invalid segmented interval (%d)\n", 282 282 s->id, s->intervals.count); 283 283 s->intervals.segmented = false; ··· 288 288 /* Direct allocation when exceeding pre-allocated */ 289 289 if (s->intervals.count >= SCMI_MAX_PREALLOC_POOL) { 290 290 s->intervals.desc = 291 - devm_kcalloc(handle->dev, 291 + devm_kcalloc(ph->dev, 292 292 s->intervals.count, 293 293 sizeof(*s->intervals.desc), 294 294 GFP_KERNEL); ··· 300 300 } 301 301 } 302 302 } else if (desc_index + num_returned > s->intervals.count) { 303 - dev_err(handle->dev, 303 + dev_err(ph->dev, 304 304 "No. of update intervals can't exceed %d\n", 305 305 s->intervals.count); 306 306 ret = -EINVAL; ··· 313 313 314 314 desc_index += num_returned; 315 315 316 - scmi_reset_rx_to_maxsz(handle, ti); 316 + ph->xops->reset_rx_to_maxsz(ph, ti); 317 317 /* 318 318 * check for both returned and remaining to avoid infinite 319 319 * loop due to buggy firmware 320 320 */ 321 321 } while (num_returned && num_remaining); 322 322 323 - scmi_xfer_put(handle, ti); 323 + ph->xops->xfer_put(ph, ti); 324 324 return ret; 325 325 } 326 326 327 - static int scmi_sensor_axis_description(const struct scmi_handle *handle, 327 + static int scmi_sensor_axis_description(const struct scmi_protocol_handle *ph, 328 328 struct scmi_sensor_info *s) 329 329 { 330 330 int ret, cnt; ··· 334 334 struct scmi_msg_resp_sensor_axis_description *buf; 335 335 struct scmi_msg_sensor_axis_description_get *msg; 336 336 337 - s->axis = devm_kcalloc(handle->dev, s->num_axis, 337 + s->axis = devm_kcalloc(ph->dev, s->num_axis, 338 338 sizeof(*s->axis), GFP_KERNEL); 339 339 if (!s->axis) 340 340 return -ENOMEM; 341 341 342 - ret = scmi_xfer_get_init(handle, SENSOR_AXIS_DESCRIPTION_GET, 343 - SCMI_PROTOCOL_SENSOR, sizeof(*msg), 0, &te); 342 + ret = ph->xops->xfer_get_init(ph, SENSOR_AXIS_DESCRIPTION_GET, 343 + sizeof(*msg), 0, &te); 344 344 if (ret) 345 345 return ret; 346 346 ··· 354 354 msg->id = cpu_to_le32(s->id); 355 355 msg->axis_desc_index = cpu_to_le32(desc_index); 356 356 357 - ret = scmi_do_xfer(handle, te); 357 + ret = ph->xops->do_xfer(ph, te); 358 358 if (ret) 359 359 break; 360 360 ··· 363 363 num_remaining = NUM_AXIS_REMAINING(flags); 364 364 365 365 if (desc_index + num_returned > s->num_axis) { 366 - dev_err(handle->dev, "No. of axis can't exceed %d\n", 366 + dev_err(ph->dev, "No. of axis can't exceed %d\n", 367 367 s->num_axis); 368 368 break; 369 369 } ··· 405 405 406 406 desc_index += num_returned; 407 407 408 - scmi_reset_rx_to_maxsz(handle, te); 408 + ph->xops->reset_rx_to_maxsz(ph, te); 409 409 /* 410 410 * check for both returned and remaining to avoid infinite 411 411 * loop due to buggy firmware 412 412 */ 413 413 } while (num_returned && num_remaining); 414 414 415 - scmi_xfer_put(handle, te); 415 + ph->xops->xfer_put(ph, te); 416 416 return ret; 417 417 } 418 418 419 - static int scmi_sensor_description_get(const struct scmi_handle *handle, 419 + static int scmi_sensor_description_get(const struct scmi_protocol_handle *ph, 420 420 struct sensors_info *si) 421 421 { 422 422 int ret, cnt; ··· 425 425 struct scmi_xfer *t; 426 426 struct scmi_msg_resp_sensor_description *buf; 427 427 428 - ret = scmi_xfer_get_init(handle, SENSOR_DESCRIPTION_GET, 429 - SCMI_PROTOCOL_SENSOR, sizeof(__le32), 0, &t); 428 + ret = ph->xops->xfer_get_init(ph, SENSOR_DESCRIPTION_GET, 429 + sizeof(__le32), 0, &t); 430 430 if (ret) 431 431 return ret; 432 432 ··· 437 437 438 438 /* Set the number of sensors to be skipped/already read */ 439 439 put_unaligned_le32(desc_index, t->tx.buf); 440 - ret = scmi_do_xfer(handle, t); 440 + 441 + ret = ph->xops->do_xfer(ph, t); 441 442 if (ret) 442 443 break; 443 444 ··· 446 445 num_remaining = le16_to_cpu(buf->num_remaining); 447 446 448 447 if (desc_index + num_returned > si->num_sensors) { 449 - dev_err(handle->dev, "No. of sensors can't exceed %d", 448 + dev_err(ph->dev, "No. of sensors can't exceed %d", 450 449 si->num_sensors); 451 450 break; 452 451 } ··· 501 500 * Since the command is optional, on error carry 502 501 * on without any update interval. 503 502 */ 504 - if (scmi_sensor_update_intervals(handle, s)) 505 - dev_dbg(handle->dev, 503 + if (scmi_sensor_update_intervals(ph, s)) 504 + dev_dbg(ph->dev, 506 505 "Update Intervals not available for sensor ID:%d\n", 507 506 s->id); 508 507 } ··· 536 535 } 537 536 } 538 537 if (s->num_axis > 0) { 539 - ret = scmi_sensor_axis_description(handle, s); 538 + ret = scmi_sensor_axis_description(ph, s); 540 539 if (ret) 541 540 goto out; 542 541 } ··· 546 545 547 546 desc_index += num_returned; 548 547 549 - scmi_reset_rx_to_maxsz(handle, t); 548 + ph->xops->reset_rx_to_maxsz(ph, t); 550 549 /* 551 550 * check for both returned and remaining to avoid infinite 552 551 * loop due to buggy firmware ··· 554 553 } while (num_returned && num_remaining); 555 554 556 555 out: 557 - scmi_xfer_put(handle, t); 556 + ph->xops->xfer_put(ph, t); 558 557 return ret; 559 558 } 560 559 561 560 static inline int 562 - scmi_sensor_request_notify(const struct scmi_handle *handle, u32 sensor_id, 561 + scmi_sensor_request_notify(const struct scmi_protocol_handle *ph, u32 sensor_id, 563 562 u8 message_id, bool enable) 564 563 { 565 564 int ret; ··· 567 566 struct scmi_xfer *t; 568 567 struct scmi_msg_sensor_request_notify *cfg; 569 568 570 - ret = scmi_xfer_get_init(handle, message_id, 571 - SCMI_PROTOCOL_SENSOR, sizeof(*cfg), 0, &t); 569 + ret = ph->xops->xfer_get_init(ph, message_id, sizeof(*cfg), 0, &t); 572 570 if (ret) 573 571 return ret; 574 572 ··· 575 575 cfg->id = cpu_to_le32(sensor_id); 576 576 cfg->event_control = cpu_to_le32(evt_cntl); 577 577 578 - ret = scmi_do_xfer(handle, t); 578 + ret = ph->xops->do_xfer(ph, t); 579 579 580 - scmi_xfer_put(handle, t); 580 + ph->xops->xfer_put(ph, t); 581 581 return ret; 582 582 } 583 583 584 - static int scmi_sensor_trip_point_notify(const struct scmi_handle *handle, 584 + static int scmi_sensor_trip_point_notify(const struct scmi_protocol_handle *ph, 585 585 u32 sensor_id, bool enable) 586 586 { 587 - return scmi_sensor_request_notify(handle, sensor_id, 587 + return scmi_sensor_request_notify(ph, sensor_id, 588 588 SENSOR_TRIP_POINT_NOTIFY, 589 589 enable); 590 590 } 591 591 592 592 static int 593 - scmi_sensor_continuous_update_notify(const struct scmi_handle *handle, 593 + scmi_sensor_continuous_update_notify(const struct scmi_protocol_handle *ph, 594 594 u32 sensor_id, bool enable) 595 595 { 596 - return scmi_sensor_request_notify(handle, sensor_id, 596 + return scmi_sensor_request_notify(ph, sensor_id, 597 597 SENSOR_CONTINUOUS_UPDATE_NOTIFY, 598 598 enable); 599 599 } 600 600 601 601 static int 602 - scmi_sensor_trip_point_config(const struct scmi_handle *handle, u32 sensor_id, 603 - u8 trip_id, u64 trip_value) 602 + scmi_sensor_trip_point_config(const struct scmi_protocol_handle *ph, 603 + u32 sensor_id, u8 trip_id, u64 trip_value) 604 604 { 605 605 int ret; 606 606 u32 evt_cntl = SENSOR_TP_BOTH; 607 607 struct scmi_xfer *t; 608 608 struct scmi_msg_set_sensor_trip_point *trip; 609 609 610 - ret = scmi_xfer_get_init(handle, SENSOR_TRIP_POINT_CONFIG, 611 - SCMI_PROTOCOL_SENSOR, sizeof(*trip), 0, &t); 610 + ret = ph->xops->xfer_get_init(ph, SENSOR_TRIP_POINT_CONFIG, 611 + sizeof(*trip), 0, &t); 612 612 if (ret) 613 613 return ret; 614 614 ··· 618 618 trip->value_low = cpu_to_le32(trip_value & 0xffffffff); 619 619 trip->value_high = cpu_to_le32(trip_value >> 32); 620 620 621 - ret = scmi_do_xfer(handle, t); 621 + ret = ph->xops->do_xfer(ph, t); 622 622 623 - scmi_xfer_put(handle, t); 623 + ph->xops->xfer_put(ph, t); 624 624 return ret; 625 625 } 626 626 627 - static int scmi_sensor_config_get(const struct scmi_handle *handle, 627 + static int 628 + __scmi_sensor_trip_point_config(const struct scmi_handle *handle, 629 + u32 sensor_id, u8 trip_id, u64 trip_value) 630 + { 631 + const struct scmi_protocol_handle *ph = 632 + scmi_map_protocol_handle(handle, SCMI_PROTOCOL_SENSOR); 633 + 634 + return scmi_sensor_trip_point_config(ph, sensor_id, trip_id, 635 + trip_value); 636 + } 637 + 638 + static int scmi_sensor_config_get(const struct scmi_protocol_handle *ph, 628 639 u32 sensor_id, u32 *sensor_config) 629 640 { 630 641 int ret; 631 642 struct scmi_xfer *t; 632 643 633 - ret = scmi_xfer_get_init(handle, SENSOR_CONFIG_GET, 634 - SCMI_PROTOCOL_SENSOR, sizeof(__le32), 635 - sizeof(__le32), &t); 644 + ret = ph->xops->xfer_get_init(ph, SENSOR_CONFIG_GET, 645 + sizeof(__le32), sizeof(__le32), &t); 636 646 if (ret) 637 647 return ret; 638 648 639 649 put_unaligned_le32(cpu_to_le32(sensor_id), t->tx.buf); 640 - ret = scmi_do_xfer(handle, t); 650 + ret = ph->xops->do_xfer(ph, t); 641 651 if (!ret) { 642 - struct sensors_info *si = handle->sensor_priv; 652 + struct sensors_info *si = ph->get_priv(ph); 643 653 struct scmi_sensor_info *s = si->sensors + sensor_id; 644 654 645 655 *sensor_config = get_unaligned_le64(t->rx.buf); 646 656 s->sensor_config = *sensor_config; 647 657 } 648 658 649 - scmi_xfer_put(handle, t); 659 + ph->xops->xfer_put(ph, t); 650 660 return ret; 651 661 } 652 662 653 - static int scmi_sensor_config_set(const struct scmi_handle *handle, 663 + static int __scmi_sensor_config_get(const struct scmi_handle *handle, 664 + u32 sensor_id, u32 *sensor_config) 665 + { 666 + const struct scmi_protocol_handle *ph = 667 + scmi_map_protocol_handle(handle, SCMI_PROTOCOL_SENSOR); 668 + 669 + return scmi_sensor_config_get(ph, sensor_id, sensor_config); 670 + } 671 + 672 + static int scmi_sensor_config_set(const struct scmi_protocol_handle *ph, 654 673 u32 sensor_id, u32 sensor_config) 655 674 { 656 675 int ret; 657 676 struct scmi_xfer *t; 658 677 struct scmi_msg_sensor_config_set *msg; 659 678 660 - ret = scmi_xfer_get_init(handle, SENSOR_CONFIG_SET, 661 - SCMI_PROTOCOL_SENSOR, sizeof(*msg), 0, &t); 679 + ret = ph->xops->xfer_get_init(ph, SENSOR_CONFIG_SET, 680 + sizeof(*msg), 0, &t); 662 681 if (ret) 663 682 return ret; 664 683 ··· 685 666 msg->id = cpu_to_le32(sensor_id); 686 667 msg->sensor_config = cpu_to_le32(sensor_config); 687 668 688 - ret = scmi_do_xfer(handle, t); 669 + ret = ph->xops->do_xfer(ph, t); 689 670 if (!ret) { 690 - struct sensors_info *si = handle->sensor_priv; 671 + struct sensors_info *si = ph->get_priv(ph); 691 672 struct scmi_sensor_info *s = si->sensors + sensor_id; 692 673 693 674 s->sensor_config = sensor_config; 694 675 } 695 676 696 - scmi_xfer_put(handle, t); 677 + ph->xops->xfer_put(ph, t); 697 678 return ret; 679 + } 680 + 681 + static int __scmi_sensor_config_set(const struct scmi_handle *handle, 682 + u32 sensor_id, u32 sensor_config) 683 + { 684 + const struct scmi_protocol_handle *ph = 685 + scmi_map_protocol_handle(handle, SCMI_PROTOCOL_SENSOR); 686 + 687 + return scmi_sensor_config_set(ph, sensor_id, sensor_config); 698 688 } 699 689 700 690 /** 701 691 * scmi_sensor_reading_get - Read scalar sensor value 702 - * @handle: Platform handle 692 + * @ph: Protocol handle 703 693 * @sensor_id: Sensor ID 704 694 * @value: The 64bit value sensor reading 705 695 * ··· 721 693 * 722 694 * Return: 0 on Success 723 695 */ 724 - static int scmi_sensor_reading_get(const struct scmi_handle *handle, 696 + static int scmi_sensor_reading_get(const struct scmi_protocol_handle *ph, 725 697 u32 sensor_id, u64 *value) 726 698 { 727 699 int ret; 728 700 struct scmi_xfer *t; 729 701 struct scmi_msg_sensor_reading_get *sensor; 730 - struct sensors_info *si = handle->sensor_priv; 702 + struct sensors_info *si = ph->get_priv(ph); 731 703 struct scmi_sensor_info *s = si->sensors + sensor_id; 732 704 733 - ret = scmi_xfer_get_init(handle, SENSOR_READING_GET, 734 - SCMI_PROTOCOL_SENSOR, sizeof(*sensor), 0, &t); 705 + ret = ph->xops->xfer_get_init(ph, SENSOR_READING_GET, 706 + sizeof(*sensor), 0, &t); 735 707 if (ret) 736 708 return ret; 737 709 ··· 739 711 sensor->id = cpu_to_le32(sensor_id); 740 712 if (s->async) { 741 713 sensor->flags = cpu_to_le32(SENSOR_READ_ASYNC); 742 - ret = scmi_do_xfer_with_response(handle, t); 714 + ret = ph->xops->do_xfer_with_response(ph, t); 743 715 if (!ret) { 744 716 struct scmi_resp_sensor_reading_complete *resp; 745 717 ··· 751 723 } 752 724 } else { 753 725 sensor->flags = cpu_to_le32(0); 754 - ret = scmi_do_xfer(handle, t); 726 + ret = ph->xops->do_xfer(ph, t); 755 727 if (!ret) 756 728 *value = get_unaligned_le64(t->rx.buf); 757 729 } 758 730 759 - scmi_xfer_put(handle, t); 731 + ph->xops->xfer_put(ph, t); 760 732 return ret; 733 + } 734 + 735 + static int __scmi_sensor_reading_get(const struct scmi_handle *handle, 736 + u32 sensor_id, u64 *value) 737 + { 738 + const struct scmi_protocol_handle *ph = 739 + scmi_map_protocol_handle(handle, SCMI_PROTOCOL_SENSOR); 740 + 741 + return scmi_sensor_reading_get(ph, sensor_id, value); 761 742 } 762 743 763 744 static inline void ··· 779 742 780 743 /** 781 744 * scmi_sensor_reading_get_timestamped - Read multiple-axis timestamped values 782 - * @handle: Platform handle 745 + * @ph: Protocol handle 783 746 * @sensor_id: Sensor ID 784 747 * @count: The length of the provided @readings array 785 748 * @readings: An array of elements each representing a timestamped per-axis ··· 792 755 * Return: 0 on Success 793 756 */ 794 757 static int 795 - scmi_sensor_reading_get_timestamped(const struct scmi_handle *handle, 758 + scmi_sensor_reading_get_timestamped(const struct scmi_protocol_handle *ph, 796 759 u32 sensor_id, u8 count, 797 760 struct scmi_sensor_reading *readings) 798 761 { 799 762 int ret; 800 763 struct scmi_xfer *t; 801 764 struct scmi_msg_sensor_reading_get *sensor; 802 - struct sensors_info *si = handle->sensor_priv; 765 + struct sensors_info *si = ph->get_priv(ph); 803 766 struct scmi_sensor_info *s = si->sensors + sensor_id; 804 767 805 768 if (!count || !readings || 806 769 (!s->num_axis && count > 1) || (s->num_axis && count > s->num_axis)) 807 770 return -EINVAL; 808 771 809 - ret = scmi_xfer_get_init(handle, SENSOR_READING_GET, 810 - SCMI_PROTOCOL_SENSOR, sizeof(*sensor), 0, &t); 772 + ret = ph->xops->xfer_get_init(ph, SENSOR_READING_GET, 773 + sizeof(*sensor), 0, &t); 811 774 if (ret) 812 775 return ret; 813 776 ··· 815 778 sensor->id = cpu_to_le32(sensor_id); 816 779 if (s->async) { 817 780 sensor->flags = cpu_to_le32(SENSOR_READ_ASYNC); 818 - ret = scmi_do_xfer_with_response(handle, t); 781 + ret = ph->xops->do_xfer_with_response(ph, t); 819 782 if (!ret) { 820 783 int i; 821 784 struct scmi_resp_sensor_reading_complete_v3 *resp; ··· 831 794 } 832 795 } else { 833 796 sensor->flags = cpu_to_le32(0); 834 - ret = scmi_do_xfer(handle, t); 797 + ret = ph->xops->do_xfer(ph, t); 835 798 if (!ret) { 836 799 int i; 837 800 struct scmi_sensor_reading_resp *resp_readings; ··· 843 806 } 844 807 } 845 808 846 - scmi_xfer_put(handle, t); 809 + ph->xops->xfer_put(ph, t); 847 810 return ret; 848 811 } 849 812 850 - static const struct scmi_sensor_info * 851 - scmi_sensor_info_get(const struct scmi_handle *handle, u32 sensor_id) 813 + static int 814 + __scmi_sensor_reading_get_timestamped(const struct scmi_handle *handle, 815 + u32 sensor_id, u8 count, 816 + struct scmi_sensor_reading *readings) 852 817 { 853 - struct sensors_info *si = handle->sensor_priv; 818 + const struct scmi_protocol_handle *ph = 819 + scmi_map_protocol_handle(handle, SCMI_PROTOCOL_SENSOR); 820 + 821 + return scmi_sensor_reading_get_timestamped(ph, sensor_id, count, 822 + readings); 823 + } 824 + 825 + static const struct scmi_sensor_info * 826 + scmi_sensor_info_get(const struct scmi_protocol_handle *ph, u32 sensor_id) 827 + { 828 + struct sensors_info *si = ph->get_priv(ph); 854 829 855 830 return si->sensors + sensor_id; 856 831 } 857 832 858 - static int scmi_sensor_count_get(const struct scmi_handle *handle) 833 + static const struct scmi_sensor_info * 834 + __scmi_sensor_info_get(const struct scmi_handle *handle, u32 sensor_id) 859 835 { 860 - struct sensors_info *si = handle->sensor_priv; 836 + const struct scmi_protocol_handle *ph = 837 + scmi_map_protocol_handle(handle, SCMI_PROTOCOL_SENSOR); 838 + 839 + return scmi_sensor_info_get(ph, sensor_id); 840 + } 841 + 842 + static int scmi_sensor_count_get(const struct scmi_protocol_handle *ph) 843 + { 844 + struct sensors_info *si = ph->get_priv(ph); 861 845 862 846 return si->num_sensors; 863 847 } 864 848 849 + static int __scmi_sensor_count_get(const struct scmi_handle *handle) 850 + { 851 + const struct scmi_protocol_handle *ph = 852 + scmi_map_protocol_handle(handle, SCMI_PROTOCOL_SENSOR); 853 + 854 + return scmi_sensor_count_get(ph); 855 + } 856 + 865 857 static const struct scmi_sensor_ops sensor_ops = { 858 + .count_get = __scmi_sensor_count_get, 859 + .info_get = __scmi_sensor_info_get, 860 + .trip_point_config = __scmi_sensor_trip_point_config, 861 + .reading_get = __scmi_sensor_reading_get, 862 + .reading_get_timestamped = __scmi_sensor_reading_get_timestamped, 863 + .config_get = __scmi_sensor_config_get, 864 + .config_set = __scmi_sensor_config_set, 865 + }; 866 + 867 + static const struct scmi_sensor_proto_ops sensor_proto_ops = { 866 868 .count_get = scmi_sensor_count_get, 867 869 .info_get = scmi_sensor_info_get, 868 870 .trip_point_config = scmi_sensor_trip_point_config, ··· 911 835 .config_set = scmi_sensor_config_set, 912 836 }; 913 837 914 - static int scmi_sensor_set_notify_enabled(const void *handle, 838 + static int scmi_sensor_set_notify_enabled(const void *ph, 915 839 u8 evt_id, u32 src_id, bool enable) 916 840 { 917 841 int ret; 918 842 919 843 switch (evt_id) { 920 844 case SCMI_EVENT_SENSOR_TRIP_POINT_EVENT: 921 - ret = scmi_sensor_trip_point_notify(handle, src_id, enable); 845 + ret = scmi_sensor_trip_point_notify(ph, src_id, enable); 922 846 break; 923 847 case SCMI_EVENT_SENSOR_UPDATE: 924 - ret = scmi_sensor_continuous_update_notify(handle, src_id, 925 - enable); 848 + ret = scmi_sensor_continuous_update_notify(ph, src_id, enable); 926 849 break; 927 850 default: 928 851 ret = -EINVAL; ··· 935 860 return ret; 936 861 } 937 862 938 - static void *scmi_sensor_fill_custom_report(const void *handle, 863 + static void *scmi_sensor_fill_custom_report(const void *ph, 939 864 u8 evt_id, ktime_t timestamp, 940 865 const void *payld, size_t payld_sz, 941 866 void *report, u32 *src_id) ··· 966 891 const struct scmi_sensor_update_notify_payld *p = payld; 967 892 struct scmi_sensor_update_report *r = report; 968 893 struct sensors_info *sinfo = 969 - ((const struct scmi_handle *)(handle))->sensor_priv; 894 + ((const struct scmi_protocol_handle *)ph)->get_priv(ph); 970 895 971 896 /* payld_sz is variable for this event */ 972 897 r->sensor_id = le32_to_cpu(p->sensor_id); ··· 996 921 return rep; 997 922 } 998 923 999 - static int scmi_sensor_get_num_sources(const void *handle) 924 + static int scmi_sensor_get_num_sources(const void *ph) 1000 925 { 1001 926 struct sensors_info *si = 1002 - ((const struct scmi_handle *)(handle))->sensor_priv; 927 + ((const struct scmi_protocol_handle *)ph)->get_priv(ph); 1003 928 1004 929 return si->num_sensors; 1005 930 } ··· 1035 960 .num_events = ARRAY_SIZE(sensor_events), 1036 961 }; 1037 962 1038 - static int scmi_sensors_protocol_init(struct scmi_handle *handle) 963 + static int scmi_sensors_protocol_init(const struct scmi_protocol_handle *ph) 1039 964 { 1040 965 u32 version; 1041 966 int ret; 1042 967 struct sensors_info *sinfo; 968 + struct scmi_handle *handle; 1043 969 1044 - scmi_version_get(handle, SCMI_PROTOCOL_SENSOR, &version); 970 + ph->xops->version_get(ph, &version); 1045 971 1046 - dev_dbg(handle->dev, "Sensor Version %d.%d\n", 972 + dev_dbg(ph->dev, "Sensor Version %d.%d\n", 1047 973 PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version)); 1048 974 1049 - sinfo = devm_kzalloc(handle->dev, sizeof(*sinfo), GFP_KERNEL); 975 + sinfo = devm_kzalloc(ph->dev, sizeof(*sinfo), GFP_KERNEL); 1050 976 if (!sinfo) 1051 977 return -ENOMEM; 1052 978 sinfo->version = version; 1053 979 1054 - ret = scmi_sensor_attributes_get(handle, sinfo); 980 + ret = scmi_sensor_attributes_get(ph, sinfo); 1055 981 if (ret) 1056 982 return ret; 1057 - sinfo->sensors = devm_kcalloc(handle->dev, sinfo->num_sensors, 983 + sinfo->sensors = devm_kcalloc(ph->dev, sinfo->num_sensors, 1058 984 sizeof(*sinfo->sensors), GFP_KERNEL); 1059 985 if (!sinfo->sensors) 1060 986 return -ENOMEM; 1061 987 1062 - ret = scmi_sensor_description_get(handle, sinfo); 988 + ret = scmi_sensor_description_get(ph, sinfo); 1063 989 if (ret) 1064 990 return ret; 1065 991 1066 - handle->sensor_priv = sinfo; 992 + /* Transient code for legacy ops interface */ 993 + handle = scmi_map_scmi_handle(ph); 1067 994 handle->sensor_ops = &sensor_ops; 1068 995 1069 - return 0; 996 + return ph->set_priv(ph, sinfo); 1070 997 } 1071 998 1072 999 static const struct scmi_protocol scmi_sensors = { 1073 1000 .id = SCMI_PROTOCOL_SENSOR, 1074 - .init = &scmi_sensors_protocol_init, 1075 - .ops = &sensor_ops, 1001 + .instance_init = &scmi_sensors_protocol_init, 1002 + .ops = &sensor_proto_ops, 1076 1003 .events = &sensor_protocol_events, 1077 1004 }; 1078 1005
+18 -4
include/linux/scmi_protocol.h
··· 431 431 }; 432 432 433 433 /** 434 - * struct scmi_sensor_ops - represents the various operations provided 434 + * struct scmi_sensor_proto_ops - represents the various operations provided 435 435 * by SCMI Sensor Protocol 436 436 * 437 437 * @count_get: get the count of sensors provided by SCMI ··· 446 446 * @config_get: Get sensor current configuration 447 447 * @config_set: Set sensor current configuration 448 448 */ 449 + struct scmi_sensor_proto_ops { 450 + int (*count_get)(const struct scmi_protocol_handle *ph); 451 + const struct scmi_sensor_info *(*info_get) 452 + (const struct scmi_protocol_handle *ph, u32 sensor_id); 453 + int (*trip_point_config)(const struct scmi_protocol_handle *ph, 454 + u32 sensor_id, u8 trip_id, u64 trip_value); 455 + int (*reading_get)(const struct scmi_protocol_handle *ph, u32 sensor_id, 456 + u64 *value); 457 + int (*reading_get_timestamped)(const struct scmi_protocol_handle *ph, 458 + u32 sensor_id, u8 count, 459 + struct scmi_sensor_reading *readings); 460 + int (*config_get)(const struct scmi_protocol_handle *ph, 461 + u32 sensor_id, u32 *sensor_config); 462 + int (*config_set)(const struct scmi_protocol_handle *ph, 463 + u32 sensor_id, u32 sensor_config); 464 + }; 465 + 449 466 struct scmi_sensor_ops { 450 467 int (*count_get)(const struct scmi_handle *handle); 451 468 const struct scmi_sensor_info *(*info_get) ··· 628 611 * operations and a dedicated protocol handler 629 612 * @devm_protocol_put: devres managed method to release a protocol 630 613 * @notify_ops: pointer to set of notifications related operations 631 - * @sensor_priv: pointer to private data structure specific to sensors 632 - * protocol(for internal use only) 633 614 * @voltage_priv: pointer to private data structure specific to voltage 634 615 * protocol(for internal use only) 635 616 * @notify_priv: pointer to private data structure specific to notifications ··· 646 631 647 632 const struct scmi_notify_ops *notify_ops; 648 633 /* for protocol internal use */ 649 - void *sensor_priv; 650 634 void *voltage_priv; 651 635 void *notify_priv; 652 636 void *system_priv;