From patchwork Thu Sep 28 13:11:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 114427 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp727716qgf; Thu, 28 Sep 2017 06:14:34 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAbBcN5ifas7Mx2fYOCtZfTHVUvb3bTHPW/wViLQS98UywoPGopHAmSzFvFqewzhm1WpeYK X-Received: by 10.98.166.136 with SMTP id r8mr4370372pfl.228.1506604474195; Thu, 28 Sep 2017 06:14:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506604474; cv=none; d=google.com; s=arc-20160816; b=0ZmXkheG7IItP4EWvcN6vwePycwJ8YcXQ+fCfpkycQmpgFEdOjp5GJNj+qNbmHdKr6 03UdeCNpizpboEJroARVxkPWA/BhvMCm16nZzRLkz2AM314NcHc52FgGRldWLtve/Q1p 2/0xVamYNKLaYFpGdDbG8cqtkfXvksgzxcY55wrQ86mvrDVrHQ/xdZgyxFhVnfng+AoN hT5hmTeeh6n+jNjv9+KMXlYtGK7+a5+O8PaLYeEnXNKp55G8HqTtfymFFORCjqjbdkfM rEdNWbvxj52my3SGubfGwvCEwOatFMWt1N9I8GgAUhJyLDZ2VJLbvu+gBQQlOp1MxBWf v/kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=8HD3uBlhpb0UoM1VxKVwjePtg3/iRNjQDgTenjBhArE=; b=d12qtVCfs2jkONjiLHkKJ0W0Nqf1rciBnFjlknerx9M0S5xaPGynRm+me8nsfSLOoQ q1ihDksH5QgySHj0Px3qp77okK0i01K4tSY9k4PpTaJh88Q3GQtr4bqzOvDkb5p/v02i 5X6WvJ8jLO7yXAye1IZJqhduUQU6XxbYep199YrzhpAHKLgzQmKPX5iCeQmMLEgg3HvQ eca/2dstfbpgLkSmp4y1yLbFb13REjYTrGEp6n2CIf6vOJ/YMcmgvwmcoejsMdxkHh5U BCkvTp6JKYudNzHQdQRvnBTbEEwabsWZRswW/OFdAwTErxjg1LTXeXOWUOGoU/yoyBkK Gt0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p11si1436340plk.297.2017.09.28.06.14.33; Thu, 28 Sep 2017 06:14:34 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753342AbdI1NOc (ORCPT + 26 others); Thu, 28 Sep 2017 09:14:32 -0400 Received: from foss.arm.com ([217.140.101.70]:57070 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753317AbdI1NO2 (ORCPT ); Thu, 28 Sep 2017 09:14:28 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3CF0D1991; Thu, 28 Sep 2017 06:14:28 -0700 (PDT) Received: from e107155-lin.cambridge.arm.com (unknown [10.1.210.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 29FDD3F483; Thu, 28 Sep 2017 06:14:26 -0700 (PDT) From: Sudeep Holla To: ALKML , LKML , DTML Cc: Sudeep Holla , Roy Franz , Harb Abdulhamid , Nishanth Menon , Arnd Bergmann , Loc Ho , Alexey Klimov , Ryan Harkin , Jassi Brar Subject: [PATCH v3 10/22] firmware: arm_scmi: probe and initialise all the supported protocols Date: Thu, 28 Sep 2017 14:11:34 +0100 Message-Id: <1506604306-20739-11-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506604306-20739-1-git-send-email-sudeep.holla@arm.com> References: <1506604306-20739-1-git-send-email-sudeep.holla@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that we have basic support for all the protocols in the specification, let's probe them individually and initialise them. Cc: Arnd Bergmann Signed-off-by: Sudeep Holla --- drivers/firmware/arm_scmi/common.h | 5 +++ drivers/firmware/arm_scmi/driver.c | 82 +++++++++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/drivers/firmware/arm_scmi/common.h b/drivers/firmware/arm_scmi/common.h index 0df52905ba48..07acddf5c060 100644 --- a/drivers/firmware/arm_scmi/common.h +++ b/drivers/firmware/arm_scmi/common.h @@ -119,4 +119,9 @@ int scmi_version_get(const struct scmi_handle *h, u8 protocol, u32 *version); void scmi_setup_protocol_implemented(const struct scmi_handle *handle, u8 *prot_imp); +typedef int (*scmi_prot_init_fn_t)(struct scmi_handle *); int scmi_base_protocol_init(struct scmi_handle *h); +int scmi_perf_protocol_init(struct scmi_handle *h); +int scmi_sensors_protocol_init(struct scmi_handle *h); +int scmi_power_protocol_init(struct scmi_handle *h); +int scmi_clock_protocol_init(struct scmi_handle *h); diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c index 5df76512a291..a1abcf2049ca 100644 --- a/drivers/firmware/arm_scmi/driver.c +++ b/drivers/firmware/arm_scmi/driver.c @@ -154,6 +154,12 @@ struct scmi_shared_mem { u8 msg_payload[0]; }; +struct scmi_protocol_match { + u8 protocol_id; + scmi_prot_init_fn_t fn; + char name[32]; +}; + static int scmi_linux_errmap[] = { /* better than switch case as long as return value is continuous */ 0, /* SCMI_SUCCESS */ @@ -686,6 +692,39 @@ static int scmi_xfer_info_init(struct scmi_info *sinfo) return 0; } +static const struct scmi_protocol_match scmi_protocols[] = { + { + .protocol_id = SCMI_PROTOCOL_PERF, + .fn = scmi_perf_protocol_init, + .name = "scmi-cpufreq", + }, { + .protocol_id = SCMI_PROTOCOL_CLOCK, + .fn = scmi_clock_protocol_init, + .name = "scmi-clocks", + }, { + .protocol_id = SCMI_PROTOCOL_POWER, + .fn = scmi_power_protocol_init, + .name = "scmi-power-domain", + }, { + .protocol_id = SCMI_PROTOCOL_SENSOR, + .fn = scmi_sensors_protocol_init, + .name = "scmi-hwmon", + }, + {} +}; + +static const struct scmi_protocol_match *scmi_protocol_match_get(u8 protocol_id) +{ + int i; + const struct scmi_protocol_match *loop = scmi_protocols; + + for (i = 0; i < ARRAY_SIZE(scmi_protocols); i++, loop++) + if (loop->protocol_id == protocol_id) + return loop; + + return NULL; +} + static int scmi_mailbox_check(struct device_node *np) { struct of_phandle_args arg; @@ -767,6 +806,27 @@ static inline int scmi_mbox_chan_setup(struct scmi_info *info) return 0; } +static inline void +scmi_create_protocol_device(struct device_node *np, struct scmi_info *info, + const struct scmi_protocol_match *match) +{ + int init_ret; + struct platform_device *cdev; + + cdev = of_platform_device_create(np, match->name, info->dev); + if (!cdev) { + dev_err(info->dev, "failed to create %s device\n", match->name); + return; + } + + init_ret = match->fn(&info->handle); + if (init_ret) { + dev_err(info->dev, "SCMI protocol %d init error %d\n", + match->protocol_id, init_ret); + of_platform_device_destroy(&cdev->dev, NULL); + } +} + static int scmi_probe(struct platform_device *pdev) { int ret; @@ -774,7 +834,7 @@ static int scmi_probe(struct platform_device *pdev) const struct scmi_desc *desc; struct scmi_info *info; struct device *dev = &pdev->dev; - struct device_node *np = dev->of_node; + struct device_node *child, *np = dev->of_node; /* Only mailbox method supported, check for the presence of one */ if (scmi_mailbox_check(np)) { @@ -813,6 +873,26 @@ static int scmi_probe(struct platform_device *pdev) return ret; } + for_each_available_child_of_node(np, child) { + u32 prot_id; + const struct scmi_protocol_match *match; + + if (of_property_read_u32(child, "reg", &prot_id)) + continue; + + prot_id &= MSG_PROTOCOL_ID_MASK; + + if (!scmi_is_protocol_implemented(handle, prot_id)) { + dev_err(dev, "SCMI protocol %d not implemented\n", + prot_id); + continue; + } + + match = scmi_protocol_match_get(prot_id); + if (match) + scmi_create_protocol_device(child, info, match); + } + mutex_lock(&scmi_list_mutex); list_add_tail(&info->node, &scmi_list); mutex_unlock(&scmi_list_mutex);