Received: by 2002:a17:90a:8582:0:0:0:0 with SMTP id m2csp2419564pjn; Tue, 2 Apr 2019 16:11:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqxz0B2YXnXIlvPC5lNabtDh4tCauGmDqPSSH5y8QjILpNtV9NricXi/XFamKPHiPJZ7VstY X-Received: by 2002:a62:1ac3:: with SMTP id a186mr70663420pfa.48.1554246704332; Tue, 02 Apr 2019 16:11:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554246704; cv=none; d=google.com; s=arc-20160816; b=GPV+kQ7L/XrY7UGGU6MU6Vb7D9jIsKajM99LwJCGPShAEl5NlGKyrFHuyi7fUCinA4 Ya0Gf2Om4uaYjRojiRVxNTER8LiN07ymn8mhuokn1ygzxVd7LpAJvTM+0p6ffjVnJYpR Q5Y5d5XKXd4NhvIbd/BBB5NvUIsOFKaJz487EYLJmCaqeeC/DYlAUgVHJWWVkbc5Yj0Z eWI+xU0eNHzVotSJObiYU74PdCTqENBQWGINwCy3hIf1W/ljUyGWkPt8kl2bMTtrKXym 6iE3RF0Fhrl8si5aHdhhAs2WjklIu90AxeTjtIOYjjZjCHZ6pLTwpq0niufM5DJsnxxd vBcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=hacseZew8TJlIqKYRC6D7Jvzm1ZXVCoDpcGnJF/I7V8=; b=rHgkili2oak7kJ+YHJzt88qGGBgK/tjqmmAIWS3/vY9bFflPOjTauOMbmWp473bymD IQGyXRNBj01uaQT5XJGmkqzFflJPPce7t+Xeo9pZnjTN6IY3BbaeH9TJheZ4KwAWySRe +Viof4eAKsSyiKgEoLtKIajRMH/SEjTt/UJaZbfodUy3r0cLYC9+GD6r1mfPP8qPFO0u 0dWolJ5B4m9+BCFdNN+dIAQPG6b7B2D10qKzIteJt76V4PMoQA7Rv0yp6oU/xlrCeGxI NSXwzXlcylfrd956/8O+NRIKVPEyGWSMoiBnhY9QWL1Ee1uAqSU9Jghw9OB+K8CBna7V tu+w== 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 r17si12360372pgh.311.2019.04.02.16.11.29; Tue, 02 Apr 2019 16:11:44 -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 S1726582AbfDBXKs (ORCPT + 99 others); Tue, 2 Apr 2019 19:10:48 -0400 Received: from smtp-out-so.shaw.ca ([64.59.136.137]:44654 "EHLO smtp-out-so.shaw.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725842AbfDBXKs (ORCPT ); Tue, 2 Apr 2019 19:10:48 -0400 X-Greylist: delayed 487 seconds by postgrey-1.27 at vger.kernel.org; Tue, 02 Apr 2019 19:10:47 EDT Received: from tethys.mmayer.net ([70.68.144.247]) by shaw.ca with ESMTP id BSQPhhrxvGusjBSQQhTVvB; Tue, 02 Apr 2019 17:02:39 -0600 X-Authority-Analysis: v=2.3 cv=fOdHIqSe c=1 sm=1 tr=0 a=5Vvn7CJLxh9yo+qVPaC6cg==:117 a=5Vvn7CJLxh9yo+qVPaC6cg==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=oexKYjalfGEA:10 a=Q-fNiiVtAAAA:8 a=IA7aKqN18JfRTjCajgUA:9 a=Fp8MccfUoT0GBdDC_Lng:22 Received: by tethys.mmayer.net (Postfix, from userid 501) id 819F33010142F9; Tue, 2 Apr 2019 16:02:37 -0700 (PDT) From: Markus Mayer To: Brian Norris , Florian Fainelli , Gregory Fong Cc: Markus Mayer , Broadcom Kernel List , ARM Kernel List , Linux Kernel Mailing List Subject: [PATCH 4/6] memory: brcmstb: dpfe: prepare support for multiple API versions Date: Tue, 2 Apr 2019 16:01:01 -0700 Message-Id: <20190402230103.25491-5-code@mmayer.net> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190402230103.25491-1-code@mmayer.net> References: <20190402230103.25491-1-code@mmayer.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfPu/6dCio4euRdjkWCoFdmjIYLxgses2eSHgdkJTgJ1jtZvUW3e7PHl5qYKt5NUxSItGEsR5MpJer9c+wNhw1wwgquzFaI+9BPTpnntkmqHB0jyWAZZ6 tnnqWiCjLPZnsLCyLT1rrdnfHGOoL7SyWH4wAdltrPJox0TfuIGIKnMEKO/s9GgKKifeknMHCTchiirmou8t6mvVAJBLxcWiMKBF3sglERea4QxfMowidv2T 9Rx4nAW4Dq1otRry/o5ngcXxI6l6GuycyjcXLAFlhuLBLsAHcIqilQyJDjJooZfAnDwQw0CFnyR9puwi4kjX3kwb1ym1nGkOaOZhoTw3Zsuo20jENM6M9z2x bnkq/6uEkRFOV/G0uA7mXgU0Zig59WsqoIVRu6lGnzGKiIxSVxZElufuT/3ehp8et8QOxXNs3cPV5cPqHT7qWY0DpMaNoQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Markus Mayer Extend the driver, so it can handle different API versions for interacting with the DCPU. This is in preparation for the upcoming API v3. Signed-off-by: Markus Mayer --- drivers/memory/brcmstb_dpfe.c | 87 ++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 28 deletions(-) diff --git a/drivers/memory/brcmstb_dpfe.c b/drivers/memory/brcmstb_dpfe.c index f8d05a8266c3..9ad5ea08c134 100644 --- a/drivers/memory/brcmstb_dpfe.c +++ b/drivers/memory/brcmstb_dpfe.c @@ -35,10 +35,10 @@ #include #include #include +#include #include #define DRVNAME "brcmstb-dpfe" -#define FIRMWARE_NAME "dpfe.bin" /* DCPU register offsets */ #define REG_DCPU_RESET 0x0 @@ -164,12 +164,20 @@ struct init_data { bool is_big_endian; }; +/* API version and corresponding commands */ +struct dpfe_api { + int version; + const char *fw_name; + u32 command[DPFE_CMD_MAX][MSG_FIELD_MAX]; +}; + /* Things we need for as long as we are active. */ struct private_data { void __iomem *regs; void __iomem *dmem; void __iomem *imem; struct device *dev; + const struct dpfe_api *dpfe_api; struct mutex lock; }; @@ -178,29 +186,33 @@ static const char *error_text[] = { "Incorrect checksum", "Malformed command", "Timed out", }; -/* List of supported firmware commands */ -static const u32 dpfe_commands[DPFE_CMD_MAX][MSG_FIELD_MAX] = { - [DPFE_CMD_GET_INFO] = { - [MSG_HEADER] = DPFE_MSG_TYPE_COMMAND, - [MSG_COMMAND] = 1, - [MSG_ARG_COUNT] = 1, - [MSG_ARG0] = 1, - [MSG_CHKSUM] = 4, - }, - [DPFE_CMD_GET_REFRESH] = { - [MSG_HEADER] = DPFE_MSG_TYPE_COMMAND, - [MSG_COMMAND] = 2, - [MSG_ARG_COUNT] = 1, - [MSG_ARG0] = 1, - [MSG_CHKSUM] = 5, - }, - [DPFE_CMD_GET_VENDOR] = { - [MSG_HEADER] = DPFE_MSG_TYPE_COMMAND, - [MSG_COMMAND] = 2, - [MSG_ARG_COUNT] = 1, - [MSG_ARG0] = 2, - [MSG_CHKSUM] = 6, - }, +/* API v2 firmware commands */ +static const struct dpfe_api dpfe_api_v2 = { + .version = 2, + .fw_name = "dpfe.bin", + .command = { + [DPFE_CMD_GET_INFO] = { + [MSG_HEADER] = DPFE_MSG_TYPE_COMMAND, + [MSG_COMMAND] = 1, + [MSG_ARG_COUNT] = 1, + [MSG_ARG0] = 1, + [MSG_CHKSUM] = 4, + }, + [DPFE_CMD_GET_REFRESH] = { + [MSG_HEADER] = DPFE_MSG_TYPE_COMMAND, + [MSG_COMMAND] = 2, + [MSG_ARG_COUNT] = 1, + [MSG_ARG0] = 1, + [MSG_CHKSUM] = 5, + }, + [DPFE_CMD_GET_VENDOR] = { + [MSG_HEADER] = DPFE_MSG_TYPE_COMMAND, + [MSG_COMMAND] = 2, + [MSG_ARG_COUNT] = 1, + [MSG_ARG0] = 2, + [MSG_CHKSUM] = 6, + }, + } }; static bool is_dcpu_enabled(void __iomem *regs) @@ -293,7 +305,7 @@ static void __iomem *get_msg_ptr(struct private_data *priv, u32 response, static int __send_command(struct private_data *priv, unsigned int cmd, u32 result[]) { - const u32 *msg = dpfe_commands[cmd]; + const u32 *msg = priv->dpfe_api->command[cmd]; void __iomem *regs = priv->regs; unsigned int i, chksum; int ret = 0; @@ -492,7 +504,15 @@ static int brcmstb_dpfe_download_firmware(struct platform_device *pdev, return 0; } - ret = request_firmware(&fw, FIRMWARE_NAME, dev); + /* + * If the firmware filename is NULL it means the boot firmware has to + * download the DCPU firmware for us. If that didn't work, we have to + * bail, since downloading it ourselves wouldn't work either. + */ + if (!priv->dpfe_api->fw_name) + return -ENODEV; + + ret = request_firmware(&fw, priv->dpfe_api->fw_name, dev); /* request_firmware() prints its own error messages. */ if (ret) return ret; @@ -714,6 +734,16 @@ static int brcmstb_dpfe_probe(struct platform_device *pdev) return -ENOENT; } + priv->dpfe_api = of_device_get_match_data(dev); + if (unlikely(!priv->dpfe_api)) { + /* + * It should be impossible to end up here, but to be safe we + * check anyway. + */ + dev_err(dev, "Couldn't determine API\n"); + return -ENOENT; + } + ret = brcmstb_dpfe_download_firmware(pdev, &init); if (ret) { dev_err(dev, "Couldn't download firmware -- %d\n", ret); @@ -722,7 +752,8 @@ static int brcmstb_dpfe_probe(struct platform_device *pdev) ret = sysfs_create_groups(&pdev->dev.kobj, dpfe_groups); if (!ret) - dev_info(dev, "registered.\n"); + dev_info(dev, "registered with API v%d.\n", + priv->dpfe_api->version); return ret; } @@ -735,7 +766,7 @@ static int brcmstb_dpfe_remove(struct platform_device *pdev) } static const struct of_device_id brcmstb_dpfe_of_match[] = { - { .compatible = "brcm,dpfe-cpu", }, + { .compatible = "brcm,dpfe-cpu", .data = &dpfe_api_v2 }, {} }; MODULE_DEVICE_TABLE(of, brcmstb_dpfe_of_match); -- 2.17.1