From patchwork Mon Aug 15 13:35:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 9280969 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 61D8960780 for ; Mon, 15 Aug 2016 13:36:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 52DD628C97 for ; Mon, 15 Aug 2016 13:36:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4764228C99; Mon, 15 Aug 2016 13:36:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DC26D28C97 for ; Mon, 15 Aug 2016 13:36:02 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZI3W-0005rx-QB; Mon, 15 Aug 2016 13:35:54 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZI3U-0005lM-Al; Mon, 15 Aug 2016 13:35:53 +0000 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 89E9E28; Mon, 15 Aug 2016 06:36:59 -0700 (PDT) Received: from [10.1.210.28] (unknown [10.1.210.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 11A5A3F213; Mon, 15 Aug 2016 06:35:25 -0700 (PDT) Subject: Re: [RFC PATCH v3 5/8] firmware: Add legacy SCPI protocol driver To: Neil Armstrong References: <1470738562-20026-1-git-send-email-narmstrong@baylibre.com> <1470738562-20026-6-git-send-email-narmstrong@baylibre.com> From: Sudeep Holla Organization: ARM Message-ID: Date: Mon, 15 Aug 2016 14:35:24 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <1470738562-20026-6-git-send-email-narmstrong@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160815_063552_428885_45850BD5 X-CRM114-Status: GOOD ( 26.26 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: heiko@sntech.de, frank.wang@rock-chips.com, khilman@baylibre.com, linux-kernel@vger.kernel.org, Sudeep Holla , linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, wxt@rock-chips.com Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Neil, On 09/08/16 11:29, Neil Armstrong wrote: > Add legacy protocol driver for an early published SCPI implementation > by supporting old command indexes and structure. > This driver also supports vendor messages and rockchip specific > mailbox data structure for message passing to SCP. > Sorry for the delay but I expected some attempts to reduce the duplication of code we have here. I really don't like the duplication of the code. As I mentioned earlier it can be reduced. I see lot of scope for that and I see that you made zero attempts since v2. > Signed-off-by: Neil Armstrong > --- > drivers/firmware/Kconfig | 20 ++ > drivers/firmware/Makefile | 1 + > drivers/firmware/legacy_scpi.c | 710 +++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 731 insertions(+) > create mode 100644 drivers/firmware/legacy_scpi.c > > diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig > index ff85511..f6226b7 100644 > --- a/drivers/firmware/Kconfig > +++ b/drivers/firmware/Kconfig > @@ -40,6 +40,26 @@ config ARM_SCPI_POWER_DOMAIN > This enables support for the SCPI power domains which can be > enabled or disabled via the SCP firmware > > +config LEGACY_SCPI_PROTOCOL > + bool "Legacy System Control and Power Interface (SCPI) Message Protocol" > + default y if ARCH_MESON > + select SCPI_FW > + help > + System Control and Power Interface (SCPI) Message Protocol is > + defined for the purpose of communication between the Application > + Cores(AP) and the System Control Processor(SCP). The MHU peripheral > + provides a mechanism for inter-processor communication between SCP > + and AP. > + > + SCP controls most of the power managament on the Application > + Processors. It offers control and management of: the core/cluster > + power states, various power domain DVFS including the core/cluster, > + certain system clocks configuration, thermal sensors and many > + others. > + > + This protocol library provides interface for all the client drivers > + making use of the features offered by the legacy SCP protocol. > + Why do we need this ? If we plan to enable this in defconfig, I would rather not introduce this as it serves nothing extra over the compatible. We need runtime check for this with DT compatibles. [...] > +enum legacy_scpi_client_id { > + SCPI_CL_NONE, > + SCPI_CL_CLOCKS, > + SCPI_CL_DVFS, > + SCPI_CL_POWER, > + SCPI_CL_THERMAL, > + SCPI_MAX, > +}; > + As I said before these values were introduced by me initially and I reckon firmware doesn't depend on that. Have you really tested dropping them ? This must go as they are useless and we now have tokens which are much better. I will stop here and ask why can't you start with simple change like below ? Then we can add or re-define the structures/enums when absolutely needed. Please don't just copy the entire driver and make changes where-ever needed or please try to adapt to the new driver and try to deviate as less as required by the firmware. Regards, Sudeep --->8 SCPI_ERR_PARAM = 1, /* Invalid parameter(s) */ @@ -162,6 +165,7 @@ struct scpi_drvinfo { u32 firmware_version; int num_chans; atomic_t next_chan; + scpi_send_msg_func send_msg; struct scpi_ops *scpi_ops; struct scpi_chan *channels; struct scpi_dvfs_info *dvfs[MAX_DVFS_DOMAINS]; @@ -397,8 +401,8 @@ scpi_clk_get_range(u16 clk_id, unsigned long *min, unsigned long *max) struct clk_get_info clk; __le16 le_clk_id = cpu_to_le16(clk_id); - ret = scpi_send_message(SCPI_CMD_GET_CLOCK_INFO, &le_clk_id, - sizeof(le_clk_id), &clk, sizeof(clk)); + ret = scpi_info->send_msg(SCPI_CMD_GET_CLOCK_INFO, &le_clk_id, + sizeof(le_clk_id), &clk, sizeof(clk)); if (!ret) { *min = le32_to_cpu(clk.min_rate); *max = le32_to_cpu(clk.max_rate); @@ -412,8 +416,8 @@ static unsigned long scpi_clk_get_val(u16 clk_id) struct clk_get_value clk; __le16 le_clk_id = cpu_to_le16(clk_id); - ret = scpi_send_message(SCPI_CMD_GET_CLOCK_VALUE, &le_clk_id, - sizeof(le_clk_id), &clk, sizeof(clk)); + ret = scpi_info->send_msg(SCPI_CMD_GET_CLOCK_VALUE, &le_clk_id, + sizeof(le_clk_id), &clk, sizeof(clk)); return ret ? ret : le32_to_cpu(clk.rate); } @@ -425,8 +429,8 @@ static int scpi_clk_set_val(u16 clk_id, unsigned long rate) .rate = cpu_to_le32(rate) }; - return scpi_send_message(SCPI_CMD_SET_CLOCK_VALUE, &clk, sizeof(clk), - &stat, sizeof(stat)); + return scpi_info->send_msg(SCPI_CMD_SET_CLOCK_VALUE, &clk, sizeof(clk), + &stat, sizeof(stat)); } static int scpi_dvfs_get_idx(u8 domain) @@ -434,8 +438,8 @@ static int scpi_dvfs_get_idx(u8 domain) int ret; u8 dvfs_idx; - ret = scpi_send_message(SCPI_CMD_GET_DVFS, &domain, sizeof(domain), - &dvfs_idx, sizeof(dvfs_idx)); + ret = scpi_info->send_msg(SCPI_CMD_GET_DVFS, &domain, sizeof(domain), + &dvfs_idx, sizeof(dvfs_idx)); return ret ? ret : dvfs_idx; } @@ -444,8 +448,8 @@ static int scpi_dvfs_set_idx(u8 domain, u8 index) int stat; struct dvfs_set dvfs = {domain, index}; - return scpi_send_message(SCPI_CMD_SET_DVFS, &dvfs, sizeof(dvfs), - &stat, sizeof(stat)); + return scpi_info->send_msg(SCPI_CMD_SET_DVFS, &dvfs, sizeof(dvfs), + &stat, sizeof(stat)); } static int opp_cmp_func(const void *opp1, const void *opp2) @@ -468,8 +472,8 @@ static struct scpi_dvfs_info *scpi_dvfs_get_info(u8 domain) if (scpi_info->dvfs[domain]) /* data already populated */ return scpi_info->dvfs[domain]; - ret = scpi_send_message(SCPI_CMD_GET_DVFS_INFO, &domain, sizeof(domain), - &buf, sizeof(buf)); + ret = scpi_info->send_msg(SCPI_CMD_GET_DVFS_INFO, &domain, + sizeof(domain), &buf, sizeof(buf)); if (ret) return ERR_PTR(ret); @@ -503,8 +507,8 @@ static int scpi_sensor_get_capability(u16 *sensors) struct sensor_capabilities cap_buf; int ret; - ret = scpi_send_message(SCPI_CMD_SENSOR_CAPABILITIES, NULL, 0, &cap_buf, - sizeof(cap_buf)); + ret = scpi_info->send_msg(SCPI_CMD_SENSOR_CAPABILITIES, NULL, 0, + &cap_buf, sizeof(cap_buf)); if (!ret) *sensors = le16_to_cpu(cap_buf.sensors); @@ -517,8 +521,8 @@ static int scpi_sensor_get_info(u16 sensor_id, struct scpi_sensor_info *info) struct _scpi_sensor_info _info; int ret; - ret = scpi_send_message(SCPI_CMD_SENSOR_INFO, &id, sizeof(id), - &_info, sizeof(_info)); + ret = scpi_info->send_msg(SCPI_CMD_SENSOR_INFO, &id, sizeof(id), + &_info, sizeof(_info)); if (!ret) { memcpy(info, &_info, sizeof(*info)); info->sensor_id = le16_to_cpu(_info.sensor_id); @@ -533,8 +537,8 @@ static int scpi_sensor_get_value(u16 sensor, u64 *val) struct sensor_value buf; int ret; - ret = scpi_send_message(SCPI_CMD_SENSOR_VALUE, &id, sizeof(id), - &buf, sizeof(buf)); + ret = scpi_info->send_msg(SCPI_CMD_SENSOR_VALUE, &id, sizeof(id), + &buf, sizeof(buf)); if (!ret) *val = (u64)le32_to_cpu(buf.hi_val) << 32 | le32_to_cpu(buf.lo_val); @@ -548,8 +552,8 @@ static int scpi_device_get_power_state(u16 dev_id) u8 pstate; __le16 id = cpu_to_le16(dev_id); - ret = scpi_send_message(SCPI_CMD_GET_DEVICE_PWR_STATE, &id, - sizeof(id), &pstate, sizeof(pstate)); + ret = scpi_info->send_msg(SCPI_CMD_GET_DEVICE_PWR_STATE, &id, + sizeof(id), &pstate, sizeof(pstate)); return ret ? ret : pstate; } @@ -561,8 +565,8 @@ static int scpi_device_set_power_state(u16 dev_id, u8 pstate) .pstate = pstate, }; - return scpi_send_message(SCPI_CMD_SET_DEVICE_PWR_STATE, &dev_set, - sizeof(dev_set), &stat, sizeof(stat)); + return scpi_info->send_msg(SCPI_CMD_SET_DEVICE_PWR_STATE, &dev_set, + sizeof(dev_set), &stat, sizeof(stat)); } static struct scpi_ops scpi_ops = { @@ -591,8 +595,8 @@ static int scpi_init_versions(struct scpi_drvinfo *info) int ret; struct scp_capabilities caps; - ret = scpi_send_message(SCPI_CMD_SCPI_CAPABILITIES, NULL, 0, - &caps, sizeof(caps)); + ret = scpi_info->send_msg(SCPI_CMD_SCPI_CAPABILITIES, NULL, 0, + &caps, sizeof(caps)); if (!ret) { info->protocol_version = le32_to_cpu(caps.protocol_version); info->firmware_version = le32_to_cpu(caps.platform_version); @@ -681,6 +685,14 @@ static int scpi_alloc_xfer_list(struct device *dev, struct scpi_chan *ch) return 0; } +static const struct of_device_id scpi_of_match[] = { + {.compatible = "arm,scpi", .data = scpi_send_message}, + {.compatible = "arm,scpi-legacy", .data = scpi_send_message}, + {}, +}; + +MODULE_DEVICE_TABLE(of, scpi_of_match); + static int scpi_probe(struct platform_device *pdev) { int count, idx, ret; @@ -688,11 +700,15 @@ static int scpi_probe(struct platform_device *pdev) struct scpi_chan *scpi_chan; struct device *dev = &pdev->dev; struct device_node *np = dev->of_node; + const struct of_device_id *match; scpi_info = devm_kzalloc(dev, sizeof(*scpi_info), GFP_KERNEL); if (!scpi_info) return -ENOMEM; + match = of_match_device(scpi_of_match, dev); + scpi_info->send_msg = match->data; + count = of_count_phandle_with_args(np, "mboxes", "#mbox-cells"); if (count < 0) { dev_err(dev, "no mboxes property in '%s'\n", np->full_name); @@ -778,13 +794,6 @@ static int scpi_probe(struct platform_device *pdev) return of_platform_populate(dev->of_node, NULL, NULL, dev); } -static const struct of_device_id scpi_of_match[] = { - {.compatible = "arm,scpi"}, - {}, -}; - -MODULE_DEVICE_TABLE(of, scpi_of_match); - static struct platform_driver scpi_driver = { .driver = { .name = "scpi_protocol", diff --git i/drivers/firmware/arm_scpi.c w/drivers/firmware/arm_scpi.c index 438893762076..b394ffb5939c 100644 --- i/drivers/firmware/arm_scpi.c +++ w/drivers/firmware/arm_scpi.c @@ -82,6 +82,9 @@ #define MAX_RX_TIMEOUT (msecs_to_jiffies(30)) +typedef int (*scpi_send_msg_func)(u8 cmd, void *tx_buf, unsigned int tx_len, + void *rx_buf, unsigned int rx_len); + enum scpi_error_codes { SCPI_SUCCESS = 0, /* Success */