diff options
-rw-r--r-- | drivers/firmware/arm_scpi.c | 216 |
1 files changed, 129 insertions, 87 deletions
diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c index dfb373c8ba2a..7da9f1b83ebe 100644 --- a/drivers/firmware/arm_scpi.c +++ b/drivers/firmware/arm_scpi.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 28 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
29 | 29 | ||
30 | #include <linux/bitmap.h> | 30 | #include <linux/bitmap.h> |
31 | #include <linux/bitfield.h> | ||
32 | #include <linux/device.h> | 31 | #include <linux/device.h> |
33 | #include <linux/err.h> | 32 | #include <linux/err.h> |
34 | #include <linux/export.h> | 33 | #include <linux/export.h> |
@@ -73,13 +72,21 @@ | |||
73 | 72 | ||
74 | #define MAX_DVFS_DOMAINS 8 | 73 | #define MAX_DVFS_DOMAINS 8 |
75 | #define MAX_DVFS_OPPS 16 | 74 | #define MAX_DVFS_OPPS 16 |
76 | 75 | #define DVFS_LATENCY(hdr) (le32_to_cpu(hdr) >> 16) | |
77 | #define PROTO_REV_MAJOR_MASK GENMASK(31, 16) | 76 | #define DVFS_OPP_COUNT(hdr) ((le32_to_cpu(hdr) >> 8) & 0xff) |
78 | #define PROTO_REV_MINOR_MASK GENMASK(15, 0) | 77 | |
79 | 78 | #define PROTOCOL_REV_MINOR_BITS 16 | |
80 | #define FW_REV_MAJOR_MASK GENMASK(31, 24) | 79 | #define PROTOCOL_REV_MINOR_MASK ((1U << PROTOCOL_REV_MINOR_BITS) - 1) |
81 | #define FW_REV_MINOR_MASK GENMASK(23, 16) | 80 | #define PROTOCOL_REV_MAJOR(x) ((x) >> PROTOCOL_REV_MINOR_BITS) |
82 | #define FW_REV_PATCH_MASK GENMASK(15, 0) | 81 | #define PROTOCOL_REV_MINOR(x) ((x) & PROTOCOL_REV_MINOR_MASK) |
82 | |||
83 | #define FW_REV_MAJOR_BITS 24 | ||
84 | #define FW_REV_MINOR_BITS 16 | ||
85 | #define FW_REV_PATCH_MASK ((1U << FW_REV_MINOR_BITS) - 1) | ||
86 | #define FW_REV_MINOR_MASK ((1U << FW_REV_MAJOR_BITS) - 1) | ||
87 | #define FW_REV_MAJOR(x) ((x) >> FW_REV_MAJOR_BITS) | ||
88 | #define FW_REV_MINOR(x) (((x) & FW_REV_MINOR_MASK) >> FW_REV_MINOR_BITS) | ||
89 | #define FW_REV_PATCH(x) ((x) & FW_REV_PATCH_MASK) | ||
83 | 90 | ||
84 | #define MAX_RX_TIMEOUT (msecs_to_jiffies(30)) | 91 | #define MAX_RX_TIMEOUT (msecs_to_jiffies(30)) |
85 | 92 | ||
@@ -304,6 +311,10 @@ struct clk_get_info { | |||
304 | u8 name[20]; | 311 | u8 name[20]; |
305 | } __packed; | 312 | } __packed; |
306 | 313 | ||
314 | struct clk_get_value { | ||
315 | __le32 rate; | ||
316 | } __packed; | ||
317 | |||
307 | struct clk_set_value { | 318 | struct clk_set_value { |
308 | __le16 id; | 319 | __le16 id; |
309 | __le16 reserved; | 320 | __le16 reserved; |
@@ -317,9 +328,7 @@ struct legacy_clk_set_value { | |||
317 | } __packed; | 328 | } __packed; |
318 | 329 | ||
319 | struct dvfs_info { | 330 | struct dvfs_info { |
320 | u8 domain; | 331 | __le32 header; |
321 | u8 opp_count; | ||
322 | __le16 latency; | ||
323 | struct { | 332 | struct { |
324 | __le32 freq; | 333 | __le32 freq; |
325 | __le32 m_volt; | 334 | __le32 m_volt; |
@@ -342,6 +351,11 @@ struct _scpi_sensor_info { | |||
342 | char name[20]; | 351 | char name[20]; |
343 | }; | 352 | }; |
344 | 353 | ||
354 | struct sensor_value { | ||
355 | __le32 lo_val; | ||
356 | __le32 hi_val; | ||
357 | } __packed; | ||
358 | |||
345 | struct dev_pstate_set { | 359 | struct dev_pstate_set { |
346 | __le16 dev_id; | 360 | __le16 dev_id; |
347 | u8 pstate; | 361 | u8 pstate; |
@@ -405,20 +419,19 @@ static void scpi_process_cmd(struct scpi_chan *ch, u32 cmd) | |||
405 | unsigned int len; | 419 | unsigned int len; |
406 | 420 | ||
407 | if (scpi_info->is_legacy) { | 421 | if (scpi_info->is_legacy) { |
408 | struct legacy_scpi_shared_mem __iomem *mem = | 422 | struct legacy_scpi_shared_mem *mem = ch->rx_payload; |
409 | ch->rx_payload; | ||
410 | 423 | ||
411 | /* RX Length is not replied by the legacy Firmware */ | 424 | /* RX Length is not replied by the legacy Firmware */ |
412 | len = match->rx_len; | 425 | len = match->rx_len; |
413 | 426 | ||
414 | match->status = ioread32(&mem->status); | 427 | match->status = le32_to_cpu(mem->status); |
415 | memcpy_fromio(match->rx_buf, mem->payload, len); | 428 | memcpy_fromio(match->rx_buf, mem->payload, len); |
416 | } else { | 429 | } else { |
417 | struct scpi_shared_mem __iomem *mem = ch->rx_payload; | 430 | struct scpi_shared_mem *mem = ch->rx_payload; |
418 | 431 | ||
419 | len = min(match->rx_len, CMD_SIZE(cmd)); | 432 | len = min(match->rx_len, CMD_SIZE(cmd)); |
420 | 433 | ||
421 | match->status = ioread32(&mem->status); | 434 | match->status = le32_to_cpu(mem->status); |
422 | memcpy_fromio(match->rx_buf, mem->payload, len); | 435 | memcpy_fromio(match->rx_buf, mem->payload, len); |
423 | } | 436 | } |
424 | 437 | ||
@@ -432,11 +445,11 @@ static void scpi_process_cmd(struct scpi_chan *ch, u32 cmd) | |||
432 | static void scpi_handle_remote_msg(struct mbox_client *c, void *msg) | 445 | static void scpi_handle_remote_msg(struct mbox_client *c, void *msg) |
433 | { | 446 | { |
434 | struct scpi_chan *ch = container_of(c, struct scpi_chan, cl); | 447 | struct scpi_chan *ch = container_of(c, struct scpi_chan, cl); |
435 | struct scpi_shared_mem __iomem *mem = ch->rx_payload; | 448 | struct scpi_shared_mem *mem = ch->rx_payload; |
436 | u32 cmd = 0; | 449 | u32 cmd = 0; |
437 | 450 | ||
438 | if (!scpi_info->is_legacy) | 451 | if (!scpi_info->is_legacy) |
439 | cmd = ioread32(&mem->command); | 452 | cmd = le32_to_cpu(mem->command); |
440 | 453 | ||
441 | scpi_process_cmd(ch, cmd); | 454 | scpi_process_cmd(ch, cmd); |
442 | } | 455 | } |
@@ -446,7 +459,7 @@ static void scpi_tx_prepare(struct mbox_client *c, void *msg) | |||
446 | unsigned long flags; | 459 | unsigned long flags; |
447 | struct scpi_xfer *t = msg; | 460 | struct scpi_xfer *t = msg; |
448 | struct scpi_chan *ch = container_of(c, struct scpi_chan, cl); | 461 | struct scpi_chan *ch = container_of(c, struct scpi_chan, cl); |
449 | struct scpi_shared_mem __iomem *mem = ch->tx_payload; | 462 | struct scpi_shared_mem *mem = (struct scpi_shared_mem *)ch->tx_payload; |
450 | 463 | ||
451 | if (t->tx_buf) { | 464 | if (t->tx_buf) { |
452 | if (scpi_info->is_legacy) | 465 | if (scpi_info->is_legacy) |
@@ -465,7 +478,7 @@ static void scpi_tx_prepare(struct mbox_client *c, void *msg) | |||
465 | } | 478 | } |
466 | 479 | ||
467 | if (!scpi_info->is_legacy) | 480 | if (!scpi_info->is_legacy) |
468 | iowrite32(t->cmd, &mem->command); | 481 | mem->command = cpu_to_le32(t->cmd); |
469 | } | 482 | } |
470 | 483 | ||
471 | static struct scpi_xfer *get_scpi_xfer(struct scpi_chan *ch) | 484 | static struct scpi_xfer *get_scpi_xfer(struct scpi_chan *ch) |
@@ -570,13 +583,13 @@ scpi_clk_get_range(u16 clk_id, unsigned long *min, unsigned long *max) | |||
570 | static unsigned long scpi_clk_get_val(u16 clk_id) | 583 | static unsigned long scpi_clk_get_val(u16 clk_id) |
571 | { | 584 | { |
572 | int ret; | 585 | int ret; |
573 | __le32 rate; | 586 | struct clk_get_value clk; |
574 | __le16 le_clk_id = cpu_to_le16(clk_id); | 587 | __le16 le_clk_id = cpu_to_le16(clk_id); |
575 | 588 | ||
576 | ret = scpi_send_message(CMD_GET_CLOCK_VALUE, &le_clk_id, | 589 | ret = scpi_send_message(CMD_GET_CLOCK_VALUE, &le_clk_id, |
577 | sizeof(le_clk_id), &rate, sizeof(rate)); | 590 | sizeof(le_clk_id), &clk, sizeof(clk)); |
578 | 591 | ||
579 | return ret ? ret : le32_to_cpu(rate); | 592 | return ret ? ret : le32_to_cpu(clk.rate); |
580 | } | 593 | } |
581 | 594 | ||
582 | static int scpi_clk_set_val(u16 clk_id, unsigned long rate) | 595 | static int scpi_clk_set_val(u16 clk_id, unsigned long rate) |
@@ -632,34 +645,34 @@ static int opp_cmp_func(const void *opp1, const void *opp2) | |||
632 | 645 | ||
633 | static struct scpi_dvfs_info *scpi_dvfs_get_info(u8 domain) | 646 | static struct scpi_dvfs_info *scpi_dvfs_get_info(u8 domain) |
634 | { | 647 | { |
635 | if (domain >= MAX_DVFS_DOMAINS) | ||
636 | return ERR_PTR(-EINVAL); | ||
637 | |||
638 | return scpi_info->dvfs[domain] ?: ERR_PTR(-EINVAL); | ||
639 | } | ||
640 | |||
641 | static int scpi_dvfs_populate_info(struct device *dev, u8 domain) | ||
642 | { | ||
643 | struct scpi_dvfs_info *info; | 648 | struct scpi_dvfs_info *info; |
644 | struct scpi_opp *opp; | 649 | struct scpi_opp *opp; |
645 | struct dvfs_info buf; | 650 | struct dvfs_info buf; |
646 | int ret, i; | 651 | int ret, i; |
647 | 652 | ||
653 | if (domain >= MAX_DVFS_DOMAINS) | ||
654 | return ERR_PTR(-EINVAL); | ||
655 | |||
656 | if (scpi_info->dvfs[domain]) /* data already populated */ | ||
657 | return scpi_info->dvfs[domain]; | ||
658 | |||
648 | ret = scpi_send_message(CMD_GET_DVFS_INFO, &domain, sizeof(domain), | 659 | ret = scpi_send_message(CMD_GET_DVFS_INFO, &domain, sizeof(domain), |
649 | &buf, sizeof(buf)); | 660 | &buf, sizeof(buf)); |
650 | if (ret) | 661 | if (ret) |
651 | return ret; | 662 | return ERR_PTR(ret); |
652 | 663 | ||
653 | info = devm_kmalloc(dev, sizeof(*info), GFP_KERNEL); | 664 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
654 | if (!info) | 665 | if (!info) |
655 | return -ENOMEM; | 666 | return ERR_PTR(-ENOMEM); |
656 | 667 | ||
657 | info->count = buf.opp_count; | 668 | info->count = DVFS_OPP_COUNT(buf.header); |
658 | info->latency = le16_to_cpu(buf.latency) * 1000; /* uS to nS */ | 669 | info->latency = DVFS_LATENCY(buf.header) * 1000; /* uS to nS */ |
659 | 670 | ||
660 | info->opps = devm_kcalloc(dev, info->count, sizeof(*opp), GFP_KERNEL); | 671 | info->opps = kcalloc(info->count, sizeof(*opp), GFP_KERNEL); |
661 | if (!info->opps) | 672 | if (!info->opps) { |
662 | return -ENOMEM; | 673 | kfree(info); |
674 | return ERR_PTR(-ENOMEM); | ||
675 | } | ||
663 | 676 | ||
664 | for (i = 0, opp = info->opps; i < info->count; i++, opp++) { | 677 | for (i = 0, opp = info->opps; i < info->count; i++, opp++) { |
665 | opp->freq = le32_to_cpu(buf.opps[i].freq); | 678 | opp->freq = le32_to_cpu(buf.opps[i].freq); |
@@ -669,15 +682,7 @@ static int scpi_dvfs_populate_info(struct device *dev, u8 domain) | |||
669 | sort(info->opps, info->count, sizeof(*opp), opp_cmp_func, NULL); | 682 | sort(info->opps, info->count, sizeof(*opp), opp_cmp_func, NULL); |
670 | 683 | ||
671 | scpi_info->dvfs[domain] = info; | 684 | scpi_info->dvfs[domain] = info; |
672 | return 0; | 685 | return info; |
673 | } | ||
674 | |||
675 | static void scpi_dvfs_populate(struct device *dev) | ||
676 | { | ||
677 | int domain; | ||
678 | |||
679 | for (domain = 0; domain < MAX_DVFS_DOMAINS; domain++) | ||
680 | scpi_dvfs_populate_info(dev, domain); | ||
681 | } | 686 | } |
682 | 687 | ||
683 | static int scpi_dev_domain_id(struct device *dev) | 688 | static int scpi_dev_domain_id(struct device *dev) |
@@ -708,6 +713,9 @@ static int scpi_dvfs_get_transition_latency(struct device *dev) | |||
708 | if (IS_ERR(info)) | 713 | if (IS_ERR(info)) |
709 | return PTR_ERR(info); | 714 | return PTR_ERR(info); |
710 | 715 | ||
716 | if (!info->latency) | ||
717 | return 0; | ||
718 | |||
711 | return info->latency; | 719 | return info->latency; |
712 | } | 720 | } |
713 | 721 | ||
@@ -768,19 +776,20 @@ static int scpi_sensor_get_info(u16 sensor_id, struct scpi_sensor_info *info) | |||
768 | static int scpi_sensor_get_value(u16 sensor, u64 *val) | 776 | static int scpi_sensor_get_value(u16 sensor, u64 *val) |
769 | { | 777 | { |
770 | __le16 id = cpu_to_le16(sensor); | 778 | __le16 id = cpu_to_le16(sensor); |
771 | __le64 value; | 779 | struct sensor_value buf; |
772 | int ret; | 780 | int ret; |
773 | 781 | ||
774 | ret = scpi_send_message(CMD_SENSOR_VALUE, &id, sizeof(id), | 782 | ret = scpi_send_message(CMD_SENSOR_VALUE, &id, sizeof(id), |
775 | &value, sizeof(value)); | 783 | &buf, sizeof(buf)); |
776 | if (ret) | 784 | if (ret) |
777 | return ret; | 785 | return ret; |
778 | 786 | ||
779 | if (scpi_info->is_legacy) | 787 | if (scpi_info->is_legacy) |
780 | /* only 32-bits supported, upper 32 bits can be junk */ | 788 | /* only 32-bits supported, hi_val can be junk */ |
781 | *val = le32_to_cpup((__le32 *)&value); | 789 | *val = le32_to_cpu(buf.lo_val); |
782 | else | 790 | else |
783 | *val = le64_to_cpu(value); | 791 | *val = (u64)le32_to_cpu(buf.hi_val) << 32 | |
792 | le32_to_cpu(buf.lo_val); | ||
784 | 793 | ||
785 | return 0; | 794 | return 0; |
786 | } | 795 | } |
@@ -853,19 +862,23 @@ static int scpi_init_versions(struct scpi_drvinfo *info) | |||
853 | static ssize_t protocol_version_show(struct device *dev, | 862 | static ssize_t protocol_version_show(struct device *dev, |
854 | struct device_attribute *attr, char *buf) | 863 | struct device_attribute *attr, char *buf) |
855 | { | 864 | { |
856 | return sprintf(buf, "%lu.%lu\n", | 865 | struct scpi_drvinfo *scpi_info = dev_get_drvdata(dev); |
857 | FIELD_GET(PROTO_REV_MAJOR_MASK, scpi_info->protocol_version), | 866 | |
858 | FIELD_GET(PROTO_REV_MINOR_MASK, scpi_info->protocol_version)); | 867 | return sprintf(buf, "%d.%d\n", |
868 | PROTOCOL_REV_MAJOR(scpi_info->protocol_version), | ||
869 | PROTOCOL_REV_MINOR(scpi_info->protocol_version)); | ||
859 | } | 870 | } |
860 | static DEVICE_ATTR_RO(protocol_version); | 871 | static DEVICE_ATTR_RO(protocol_version); |
861 | 872 | ||
862 | static ssize_t firmware_version_show(struct device *dev, | 873 | static ssize_t firmware_version_show(struct device *dev, |
863 | struct device_attribute *attr, char *buf) | 874 | struct device_attribute *attr, char *buf) |
864 | { | 875 | { |
865 | return sprintf(buf, "%lu.%lu.%lu\n", | 876 | struct scpi_drvinfo *scpi_info = dev_get_drvdata(dev); |
866 | FIELD_GET(FW_REV_MAJOR_MASK, scpi_info->firmware_version), | 877 | |
867 | FIELD_GET(FW_REV_MINOR_MASK, scpi_info->firmware_version), | 878 | return sprintf(buf, "%d.%d.%d\n", |
868 | FIELD_GET(FW_REV_PATCH_MASK, scpi_info->firmware_version)); | 879 | FW_REV_MAJOR(scpi_info->firmware_version), |
880 | FW_REV_MINOR(scpi_info->firmware_version), | ||
881 | FW_REV_PATCH(scpi_info->firmware_version)); | ||
869 | } | 882 | } |
870 | static DEVICE_ATTR_RO(firmware_version); | 883 | static DEVICE_ATTR_RO(firmware_version); |
871 | 884 | ||
@@ -876,13 +889,39 @@ static struct attribute *versions_attrs[] = { | |||
876 | }; | 889 | }; |
877 | ATTRIBUTE_GROUPS(versions); | 890 | ATTRIBUTE_GROUPS(versions); |
878 | 891 | ||
879 | static void scpi_free_channels(void *data) | 892 | static void |
893 | scpi_free_channels(struct device *dev, struct scpi_chan *pchan, int count) | ||
880 | { | 894 | { |
881 | struct scpi_drvinfo *info = data; | ||
882 | int i; | 895 | int i; |
883 | 896 | ||
884 | for (i = 0; i < info->num_chans; i++) | 897 | for (i = 0; i < count && pchan->chan; i++, pchan++) { |
885 | mbox_free_channel(info->channels[i].chan); | 898 | mbox_free_channel(pchan->chan); |
899 | devm_kfree(dev, pchan->xfers); | ||
900 | devm_iounmap(dev, pchan->rx_payload); | ||
901 | } | ||
902 | } | ||
903 | |||
904 | static int scpi_remove(struct platform_device *pdev) | ||
905 | { | ||
906 | int i; | ||
907 | struct device *dev = &pdev->dev; | ||
908 | struct scpi_drvinfo *info = platform_get_drvdata(pdev); | ||
909 | |||
910 | scpi_info = NULL; /* stop exporting SCPI ops through get_scpi_ops */ | ||
911 | |||
912 | of_platform_depopulate(dev); | ||
913 | sysfs_remove_groups(&dev->kobj, versions_groups); | ||
914 | scpi_free_channels(dev, info->channels, info->num_chans); | ||
915 | platform_set_drvdata(pdev, NULL); | ||
916 | |||
917 | for (i = 0; i < MAX_DVFS_DOMAINS && info->dvfs[i]; i++) { | ||
918 | kfree(info->dvfs[i]->opps); | ||
919 | kfree(info->dvfs[i]); | ||
920 | } | ||
921 | devm_kfree(dev, info->channels); | ||
922 | devm_kfree(dev, info); | ||
923 | |||
924 | return 0; | ||
886 | } | 925 | } |
887 | 926 | ||
888 | #define MAX_SCPI_XFERS 10 | 927 | #define MAX_SCPI_XFERS 10 |
@@ -913,6 +952,7 @@ static int scpi_probe(struct platform_device *pdev) | |||
913 | { | 952 | { |
914 | int count, idx, ret; | 953 | int count, idx, ret; |
915 | struct resource res; | 954 | struct resource res; |
955 | struct scpi_chan *scpi_chan; | ||
916 | struct device *dev = &pdev->dev; | 956 | struct device *dev = &pdev->dev; |
917 | struct device_node *np = dev->of_node; | 957 | struct device_node *np = dev->of_node; |
918 | 958 | ||
@@ -929,19 +969,13 @@ static int scpi_probe(struct platform_device *pdev) | |||
929 | return -ENODEV; | 969 | return -ENODEV; |
930 | } | 970 | } |
931 | 971 | ||
932 | scpi_info->channels = devm_kcalloc(dev, count, sizeof(struct scpi_chan), | 972 | scpi_chan = devm_kcalloc(dev, count, sizeof(*scpi_chan), GFP_KERNEL); |
933 | GFP_KERNEL); | 973 | if (!scpi_chan) |
934 | if (!scpi_info->channels) | ||
935 | return -ENOMEM; | 974 | return -ENOMEM; |
936 | 975 | ||
937 | ret = devm_add_action(dev, scpi_free_channels, scpi_info); | 976 | for (idx = 0; idx < count; idx++) { |
938 | if (ret) | ||
939 | return ret; | ||
940 | |||
941 | for (; scpi_info->num_chans < count; scpi_info->num_chans++) { | ||
942 | resource_size_t size; | 977 | resource_size_t size; |
943 | int idx = scpi_info->num_chans; | 978 | struct scpi_chan *pchan = scpi_chan + idx; |
944 | struct scpi_chan *pchan = scpi_info->channels + idx; | ||
945 | struct mbox_client *cl = &pchan->cl; | 979 | struct mbox_client *cl = &pchan->cl; |
946 | struct device_node *shmem = of_parse_phandle(np, "shmem", idx); | 980 | struct device_node *shmem = of_parse_phandle(np, "shmem", idx); |
947 | 981 | ||
@@ -949,14 +983,15 @@ static int scpi_probe(struct platform_device *pdev) | |||
949 | of_node_put(shmem); | 983 | of_node_put(shmem); |
950 | if (ret) { | 984 | if (ret) { |
951 | dev_err(dev, "failed to get SCPI payload mem resource\n"); | 985 | dev_err(dev, "failed to get SCPI payload mem resource\n"); |
952 | return ret; | 986 | goto err; |
953 | } | 987 | } |
954 | 988 | ||
955 | size = resource_size(&res); | 989 | size = resource_size(&res); |
956 | pchan->rx_payload = devm_ioremap(dev, res.start, size); | 990 | pchan->rx_payload = devm_ioremap(dev, res.start, size); |
957 | if (!pchan->rx_payload) { | 991 | if (!pchan->rx_payload) { |
958 | dev_err(dev, "failed to ioremap SCPI payload\n"); | 992 | dev_err(dev, "failed to ioremap SCPI payload\n"); |
959 | return -EADDRNOTAVAIL; | 993 | ret = -EADDRNOTAVAIL; |
994 | goto err; | ||
960 | } | 995 | } |
961 | pchan->tx_payload = pchan->rx_payload + (size >> 1); | 996 | pchan->tx_payload = pchan->rx_payload + (size >> 1); |
962 | 997 | ||
@@ -982,11 +1017,17 @@ static int scpi_probe(struct platform_device *pdev) | |||
982 | dev_err(dev, "failed to get channel%d err %d\n", | 1017 | dev_err(dev, "failed to get channel%d err %d\n", |
983 | idx, ret); | 1018 | idx, ret); |
984 | } | 1019 | } |
1020 | err: | ||
1021 | scpi_free_channels(dev, scpi_chan, idx); | ||
1022 | scpi_info = NULL; | ||
985 | return ret; | 1023 | return ret; |
986 | } | 1024 | } |
987 | 1025 | ||
1026 | scpi_info->channels = scpi_chan; | ||
1027 | scpi_info->num_chans = count; | ||
988 | scpi_info->commands = scpi_std_commands; | 1028 | scpi_info->commands = scpi_std_commands; |
989 | scpi_info->scpi_ops = &scpi_ops; | 1029 | |
1030 | platform_set_drvdata(pdev, scpi_info); | ||
990 | 1031 | ||
991 | if (scpi_info->is_legacy) { | 1032 | if (scpi_info->is_legacy) { |
992 | /* Replace with legacy variants */ | 1033 | /* Replace with legacy variants */ |
@@ -1002,23 +1043,23 @@ static int scpi_probe(struct platform_device *pdev) | |||
1002 | ret = scpi_init_versions(scpi_info); | 1043 | ret = scpi_init_versions(scpi_info); |
1003 | if (ret) { | 1044 | if (ret) { |
1004 | dev_err(dev, "incorrect or no SCP firmware found\n"); | 1045 | dev_err(dev, "incorrect or no SCP firmware found\n"); |
1046 | scpi_remove(pdev); | ||
1005 | return ret; | 1047 | return ret; |
1006 | } | 1048 | } |
1007 | 1049 | ||
1008 | scpi_dvfs_populate(dev); | 1050 | _dev_info(dev, "SCP Protocol %d.%d Firmware %d.%d.%d version\n", |
1009 | 1051 | PROTOCOL_REV_MAJOR(scpi_info->protocol_version), | |
1010 | _dev_info(dev, "SCP Protocol %lu.%lu Firmware %lu.%lu.%lu version\n", | 1052 | PROTOCOL_REV_MINOR(scpi_info->protocol_version), |
1011 | FIELD_GET(PROTO_REV_MAJOR_MASK, scpi_info->protocol_version), | 1053 | FW_REV_MAJOR(scpi_info->firmware_version), |
1012 | FIELD_GET(PROTO_REV_MINOR_MASK, scpi_info->protocol_version), | 1054 | FW_REV_MINOR(scpi_info->firmware_version), |
1013 | FIELD_GET(FW_REV_MAJOR_MASK, scpi_info->firmware_version), | 1055 | FW_REV_PATCH(scpi_info->firmware_version)); |
1014 | FIELD_GET(FW_REV_MINOR_MASK, scpi_info->firmware_version), | 1056 | scpi_info->scpi_ops = &scpi_ops; |
1015 | FIELD_GET(FW_REV_PATCH_MASK, scpi_info->firmware_version)); | ||
1016 | 1057 | ||
1017 | ret = devm_device_add_groups(dev, versions_groups); | 1058 | ret = sysfs_create_groups(&dev->kobj, versions_groups); |
1018 | if (ret) | 1059 | if (ret) |
1019 | dev_err(dev, "unable to create sysfs version group\n"); | 1060 | dev_err(dev, "unable to create sysfs version group\n"); |
1020 | 1061 | ||
1021 | return devm_of_platform_populate(dev); | 1062 | return of_platform_populate(dev->of_node, NULL, NULL, dev); |
1022 | } | 1063 | } |
1023 | 1064 | ||
1024 | static const struct of_device_id scpi_of_match[] = { | 1065 | static const struct of_device_id scpi_of_match[] = { |
@@ -1035,6 +1076,7 @@ static struct platform_driver scpi_driver = { | |||
1035 | .of_match_table = scpi_of_match, | 1076 | .of_match_table = scpi_of_match, |
1036 | }, | 1077 | }, |
1037 | .probe = scpi_probe, | 1078 | .probe = scpi_probe, |
1079 | .remove = scpi_remove, | ||
1038 | }; | 1080 | }; |
1039 | module_platform_driver(scpi_driver); | 1081 | module_platform_driver(scpi_driver); |
1040 | 1082 | ||