From patchwork Thu Aug 18 10:10:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 9287269 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 BA9BC60574 for ; Thu, 18 Aug 2016 10:13:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB76628FD9 for ; Thu, 18 Aug 2016 10:13:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E87828FDA; Thu, 18 Aug 2016 10:13:01 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID 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 42B9C28FD5 for ; Thu, 18 Aug 2016 10:13:01 +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 1baKJh-0001BC-Vp; Thu, 18 Aug 2016 10:12:54 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1baKIe-00009L-G3 for linux-amlogic@lists.infradead.org; Thu, 18 Aug 2016 10:11:56 +0000 Received: by mail-wm0-x234.google.com with SMTP id o80so24581160wme.1 for ; Thu, 18 Aug 2016 03:11:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mikru5sqa4CUQioieGFcs8+Y7cEm8ufat8UeZEmigi4=; b=rhrNQigPjTKgkFBmYOfpEqHdsYtuq7jERoRjLZtkJaO7bsUqOa8jqe5jLktHqPy+ru 8b3aUkRvVp265z/CWzZ6RDA3jhcfUGWevqvhhIn7WBQH3A9kQ9Jq+QA9Lu5yNRFC/TNw GV0lSV6BY2CGSxQEdb+1Gx5k0ECPuLD0EkfB1Mnl6w7K9QPP+e5X3Rxh09EkRV7X6b1x zAmvHb4wINMdnqHe6+q/SFodqdp41m0lrYqA5TmBU0pVWypdUo2Gm1YTeYsUdB4m4tFW n3x47Uy/Htr+P5wrMmTdWSnvLyKSHh53lEGF29C7WMxg5Gf0j//McN5/I936JwU19axt Ldew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mikru5sqa4CUQioieGFcs8+Y7cEm8ufat8UeZEmigi4=; b=hNUpJ7s7aU6xuLjgi8DAi4E4XbxjVzaRMTniratzWkA8wznbvRjWA+ibfkkmC8/C5d /C/enjrieqC01PWARlwwm5QeF3ka4tyKBX9RlCY95u16UwblUUQOKwrmHJIDnTpj5LjJ Uki6oO134fg0YtSfqMfDe1OB/5LeReQ+jr9pWiKQ9nr5OGOFzZ0TZaWzjaLXUQbzcZe/ pGtQBLoCnw6DI6YErBS7aEsHAF9qWl56W67d9vX+i2FhcFnLd//SxVRGnC+F2YmTKjRu /+K9pLqEd+YNkwf5vBgBxg8VBfRk+TPl1+vtgWNwcI1/9ZYY8glJn6LbIpOrH4++RwC4 N/jQ== X-Gm-Message-State: AEkoouv3Rt0mSwItlMisa3BAe23q8xzZeaL+AWpdnWzoJd3hepnFI46BI6IRrDRRtrjAsaRg X-Received: by 10.28.104.137 with SMTP id d131mr30110900wmc.7.1471515086845; Thu, 18 Aug 2016 03:11:26 -0700 (PDT) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id f4sm30915247wmf.8.2016.08.18.03.11.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Aug 2016 03:11:26 -0700 (PDT) From: Neil Armstrong To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, sudeep.holla@arm.com Subject: [PATCH 06/13] scpi: add priv_scpi_ops and fill legacy structure Date: Thu, 18 Aug 2016 12:10:59 +0200 Message-Id: <1471515066-3626-7-git-send-email-narmstrong@baylibre.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1471515066-3626-1-git-send-email-narmstrong@baylibre.com> References: <1471515066-3626-1-git-send-email-narmstrong@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160818_031149_666628_D2706BFB X-CRM114-Status: GOOD ( 14.48 ) 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, Neil Armstrong , frank.wang@rock-chips.com, khilman@baylibre.com, linux-amlogic@lists.infradead.org, wxt@rock-chips.com MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In order to use the legacy functions variants, add a new priv_scpi_ops structure that will contain the internal alterne functions and then use these alternate call in the probe function. Signed-off-by: Neil Armstrong --- drivers/firmware/arm_scpi.c | 68 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c index b0d911b..3fe39fe 100644 --- a/drivers/firmware/arm_scpi.c +++ b/drivers/firmware/arm_scpi.c @@ -213,6 +213,7 @@ struct scpi_drvinfo { struct scpi_ops *scpi_ops; struct scpi_chan *channels; struct scpi_dvfs_info *dvfs[MAX_DVFS_DOMAINS]; + const struct priv_scpi_ops *ops; }; /* @@ -299,6 +300,17 @@ struct dev_pstate_set { u8 pstate; } __packed; +struct priv_scpi_ops { + /* Internal Specific Ops */ + void (*handle_remote_msg)(struct mbox_client *c, void *msg); + void (*tx_prepare)(struct mbox_client *c, void *msg); + /* Message Specific Ops */ + int (*init_versions)(struct scpi_drvinfo *info); + int (*dvfs_get_info)(u8 domain, struct dvfs_info *buf); + /* System wide Ops */ + struct scpi_ops *scpi_ops; +}; + static struct scpi_drvinfo *scpi_info; static int scpi_linux_errmap[SCPI_ERR_MAX] = { @@ -695,9 +707,12 @@ 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), + if (scpi_info->ops && scpi_info->ops->dvfs_get_info) + ret = scpi_info->ops->dvfs_get_info(domain, &buf); + else + ret = scpi_send_message(SCPI_CMD_GET_DVFS_INFO, + &domain, sizeof(domain), &buf, sizeof(buf)); - if (ret) return ERR_PTR(ret); @@ -855,6 +870,22 @@ static struct scpi_ops scpi_ops = { .vendor_send_message = scpi_ext_send_message, }; +static struct scpi_ops legacy_scpi_ops = { + .get_version = scpi_get_version, + .clk_get_range = NULL, + .clk_get_val = legacy_scpi_clk_get_val, + .clk_set_val = legacy_scpi_clk_set_val, + .dvfs_get_idx = legacy_scpi_dvfs_get_idx, + .dvfs_set_idx = legacy_scpi_dvfs_set_idx, + .dvfs_get_info = scpi_dvfs_get_info, + .sensor_get_capability = legacy_scpi_sensor_get_capability, + .sensor_get_info = legacy_scpi_sensor_get_info, + .sensor_get_value = legacy_scpi_sensor_get_value, + .device_get_power_state = NULL, + .device_set_power_state = NULL, + .vendor_send_message = legacy_scpi_send_message, +}; + struct scpi_ops *get_scpi_ops(void) { return scpi_info ? scpi_info->scpi_ops : NULL; @@ -972,8 +1003,17 @@ static int scpi_alloc_xfer_list(struct device *dev, struct scpi_chan *ch) return 0; } +static const struct priv_scpi_ops scpi_legacy_ops = { + .handle_remote_msg = legacy_scpi_handle_remote_msg, + .tx_prepare = legacy_scpi_tx_prepare, + .init_versions = legacy_scpi_init_versions, + .dvfs_get_info = legacy_scpi_dvfs_get_info, + .scpi_ops = &legacy_scpi_ops, +}; + static const struct of_device_id scpi_of_match[] = { {.compatible = "arm,scpi"}, + {.compatible = "amlogic,meson-gxbb-scpi", .data = &scpi_legacy_ops}, {}, }; @@ -986,11 +1026,18 @@ 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; + + match = of_match_device(scpi_of_match, &pdev->dev); + if (!match) + return -EINVAL; scpi_info = devm_kzalloc(dev, sizeof(*scpi_info), GFP_KERNEL); if (!scpi_info) return -ENOMEM; + scpi_info->ops = 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); @@ -1023,7 +1070,13 @@ static int scpi_probe(struct platform_device *pdev) pchan->tx_payload = pchan->rx_payload + (size >> 1); cl->dev = dev; - cl->rx_callback = scpi_handle_remote_msg; + if (scpi_info->ops && scpi_info->ops->handle_remote_msg) + cl->rx_callback = scpi_info->ops->handle_remote_msg; + else + cl->rx_callback = scpi_handle_remote_msg; + if (scpi_info->ops && scpi_info->ops->tx_prepare) + cl->tx_prepare = scpi_info->ops->tx_prepare; + else cl->tx_prepare = scpi_tx_prepare; cl->tx_block = true; cl->tx_tout = 20; @@ -1054,6 +1107,9 @@ err: scpi_info->num_chans = count; platform_set_drvdata(pdev, scpi_info); + if (scpi_info->ops && scpi_info->ops->init_versions) + ret = scpi_info->ops->init_versions(scpi_info); + else ret = scpi_init_versions(scpi_info); if (ret) { dev_err(dev, "incorrect or no SCP firmware found\n"); @@ -1067,7 +1123,11 @@ err: FW_REV_MAJOR(scpi_info->firmware_version), FW_REV_MINOR(scpi_info->firmware_version), FW_REV_PATCH(scpi_info->firmware_version)); - scpi_info->scpi_ops = &scpi_ops; + + if (scpi_info->ops && scpi_info->ops->scpi_ops) + scpi_info->scpi_ops = scpi_info->ops->scpi_ops; + else + scpi_info->scpi_ops = &scpi_ops; ret = sysfs_create_groups(&dev->kobj, versions_groups); if (ret)