Skip to content

Commit 3748daf

Browse files
committed
firmware: arm_scmi: Segregate tx channel handling and prepare to add rx
The transmit(Tx) channels are specified as the first entry and the receive(Rx) channels are the second entry as per the device tree bindings. Since we currently just support Tx, index 0 is hardcoded at all required callsites. In order to prepare for adding Rx support, let's remove those hardcoded index and add boolean parameter to identify Tx/Rx channels when setting them up. Signed-off-by: Sudeep Holla <[email protected]>
1 parent 2747a96 commit 3748daf

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

drivers/firmware/arm_scmi/driver.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct scmi_chan_info {
112112
* @version: SCMI revision information containing protocol version,
113113
* implementation version and (sub-)vendor identification.
114114
* @minfo: Message info
115-
* @tx_idr: IDR object to map protocol id to channel info pointer
115+
* @tx_idr: IDR object to map protocol id to Tx channel info pointer
116116
* @protocols_imp: List of protocols implemented, currently maximum of
117117
* MAX_PROTOCOLS_IMP elements allocated by the base protocol
118118
* @node: List head
@@ -640,22 +640,27 @@ static int scmi_xfer_info_init(struct scmi_info *sinfo)
640640
return 0;
641641
}
642642

643-
static int scmi_mailbox_check(struct device_node *np)
643+
static int scmi_mailbox_check(struct device_node *np, int idx)
644644
{
645-
return of_parse_phandle_with_args(np, "mboxes", "#mbox-cells", 0, NULL);
645+
return of_parse_phandle_with_args(np, "mboxes", "#mbox-cells",
646+
idx, NULL);
646647
}
647648

648-
static inline int
649-
scmi_mbox_chan_setup(struct scmi_info *info, struct device *dev, int prot_id)
649+
static int scmi_mbox_chan_setup(struct scmi_info *info, struct device *dev,
650+
int prot_id, bool tx)
650651
{
651-
int ret;
652+
int ret, idx;
652653
struct resource res;
653654
resource_size_t size;
654655
struct device_node *shmem, *np = dev->of_node;
655656
struct scmi_chan_info *cinfo;
656657
struct mbox_client *cl;
658+
const char *desc = tx ? "Tx" : "Rx";
659+
660+
/* Transmit channel is first entry i.e. index 0 */
661+
idx = tx ? 0 : 1;
657662

658-
if (scmi_mailbox_check(np)) {
663+
if (scmi_mailbox_check(np, idx)) {
659664
cinfo = idr_find(&info->tx_idr, SCMI_PROTOCOL_BASE);
660665
goto idr_alloc;
661666
}
@@ -669,31 +674,31 @@ scmi_mbox_chan_setup(struct scmi_info *info, struct device *dev, int prot_id)
669674
cl = &cinfo->cl;
670675
cl->dev = dev;
671676
cl->rx_callback = scmi_rx_callback;
672-
cl->tx_prepare = scmi_tx_prepare;
677+
cl->tx_prepare = tx ? scmi_tx_prepare : NULL;
673678
cl->tx_block = false;
674-
cl->knows_txdone = true;
679+
cl->knows_txdone = tx;
675680

676-
shmem = of_parse_phandle(np, "shmem", 0);
681+
shmem = of_parse_phandle(np, "shmem", idx);
677682
ret = of_address_to_resource(shmem, 0, &res);
678683
of_node_put(shmem);
679684
if (ret) {
680-
dev_err(dev, "failed to get SCMI Tx payload mem resource\n");
685+
dev_err(dev, "failed to get SCMI %s payload memory\n", desc);
681686
return ret;
682687
}
683688

684689
size = resource_size(&res);
685690
cinfo->payload = devm_ioremap(info->dev, res.start, size);
686691
if (!cinfo->payload) {
687-
dev_err(dev, "failed to ioremap SCMI Tx payload\n");
692+
dev_err(dev, "failed to ioremap SCMI %s payload\n", desc);
688693
return -EADDRNOTAVAIL;
689694
}
690695

691-
/* Transmit channel is first entry i.e. index 0 */
692-
cinfo->chan = mbox_request_channel(cl, 0);
696+
cinfo->chan = mbox_request_channel(cl, idx);
693697
if (IS_ERR(cinfo->chan)) {
694698
ret = PTR_ERR(cinfo->chan);
695699
if (ret != -EPROBE_DEFER)
696-
dev_err(dev, "failed to request SCMI Tx mailbox\n");
700+
dev_err(dev, "failed to request SCMI %s mailbox\n",
701+
desc);
697702
return ret;
698703
}
699704

@@ -721,7 +726,7 @@ scmi_create_protocol_device(struct device_node *np, struct scmi_info *info,
721726
return;
722727
}
723728

724-
if (scmi_mbox_chan_setup(info, &sdev->dev, prot_id)) {
729+
if (scmi_mbox_chan_setup(info, &sdev->dev, prot_id, true)) {
725730
dev_err(&sdev->dev, "failed to setup transport\n");
726731
scmi_device_destroy(sdev);
727732
return;
@@ -741,7 +746,7 @@ static int scmi_probe(struct platform_device *pdev)
741746
struct device_node *child, *np = dev->of_node;
742747

743748
/* Only mailbox method supported, check for the presence of one */
744-
if (scmi_mailbox_check(np)) {
749+
if (scmi_mailbox_check(np, 0)) {
745750
dev_err(dev, "no mailbox found in %pOF\n", np);
746751
return -EINVAL;
747752
}
@@ -769,7 +774,7 @@ static int scmi_probe(struct platform_device *pdev)
769774
handle->dev = info->dev;
770775
handle->version = &info->version;
771776

772-
ret = scmi_mbox_chan_setup(info, dev, SCMI_PROTOCOL_BASE);
777+
ret = scmi_mbox_chan_setup(info, dev, SCMI_PROTOCOL_BASE, true);
773778
if (ret)
774779
return ret;
775780

0 commit comments

Comments
 (0)