From patchwork Wed Oct 11 00:10:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hotran X-Patchwork-Id: 9998173 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 A8AD060230 for ; Wed, 11 Oct 2017 00:10:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9ABB4287FE for ; Wed, 11 Oct 2017 00:10:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8EF4C28801; Wed, 11 Oct 2017 00:10:52 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AB4F287FE for ; Wed, 11 Oct 2017 00:10:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756699AbdJKAKv (ORCPT ); Tue, 10 Oct 2017 20:10:51 -0400 Received: from mail-pg0-f46.google.com ([74.125.83.46]:54084 "EHLO mail-pg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751419AbdJKAKu (ORCPT ); Tue, 10 Oct 2017 20:10:50 -0400 Received: by mail-pg0-f46.google.com with SMTP id s2so53194pge.10 for ; Tue, 10 Oct 2017 17:10:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apm.com; s=apm; h=from:to:cc:subject:date:message-id; bh=2NUnk9yC6qTaZxZ0xlKyG+tm7PDLzsPck4Ud+rYFIOQ=; b=czqdEgw8GiNvkyBKnALDveEw9eMsNOJAyagHSipUN8QgEx3nndwIVCrI1Qf62q3Glj vr4ECTCYOVjUZyYkvxEk4vbC9Pd3enzUAc9l2I5h0Vsab8tiZHD3ijNT6Fbu/LAkM9G+ 5FQmdZ3ipu249rK6PLAWMKqMotOeQ4vjTB3hk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=2NUnk9yC6qTaZxZ0xlKyG+tm7PDLzsPck4Ud+rYFIOQ=; b=iHdb35S5skzHrPYGgOUTK/+katMEjCgswCwBpl0fb5LIY2rn84xrXUtJsS26gD/O+/ q08ragqW6alYPt4Iy0vMku+ZSjMCRUwJqD5VAmh4W4GNacwNm9HHUORSeGHQVEa3vbdZ fRtpuRqw9WM45ve/8wEUu/vS5YenItl8k7vLfNRQUEzvs4L7c15NDhT1dcHFhXJfEBeC On6WHSWGbU6/UKH4Rq2CenLJtck+WG+SiH+s1krIxZ7V3BrvOkbu3DcN/zM1SN85BkRP A50SRnY1NeYdwZq3nAYENW92nUsZbOAb1cd1POiGSe2xsgfUudPmZ+1FxZRxrSHj6VQk 0k4A== X-Gm-Message-State: AMCzsaVhvGemLByZOL56GjAJWhmU8Khvg2JFrsyZ+BWorINsD6zR/jDo li72gc2pDWL6Wbsys+xQG/eVIXjz X-Google-Smtp-Source: AOwi7QCNV4mhd46WZPbkaH4nsb+wy+Yjl8Xff2WLudRZ/0OidyRKUDNCToWQpzGIyBlvSIPv7rMBKA== X-Received: by 10.101.65.4 with SMTP id w4mr6105960pgp.74.1507680650098; Tue, 10 Oct 2017 17:10:50 -0700 (PDT) Received: from hotran_localhost.amcc.com ([206.80.4.98]) by smtp.gmail.com with ESMTPSA id q77sm18014179pfd.84.2017.10.10.17.10.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 10 Oct 2017 17:10:49 -0700 (PDT) From: Hoan Tran To: Guenter Roeck , Jean Delvare Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, lho@apm.com, kdinh@apm.com, patches@apm.com, Hoan Tran Subject: [PATCH v2] hwmon: xgene: Support hwmon v2 Date: Tue, 10 Oct 2017 17:10:31 -0700 Message-Id: <1507680631-4472-1-git-send-email-hotran@apm.com> X-Mailer: git-send-email 1.9.1 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch supports xgene-hwmon v2 which uses the non-cachable memory as the PCC shared memory. Signed-off-by: Hoan Tran --- v2 - Map PCC shared mem by ioremap() in case hwmon is v2 drivers/hwmon/xgene-hwmon.c | 52 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/drivers/hwmon/xgene-hwmon.c b/drivers/hwmon/xgene-hwmon.c index 9c0dbb8..52be7cd 100644 --- a/drivers/hwmon/xgene-hwmon.c +++ b/drivers/hwmon/xgene-hwmon.c @@ -91,6 +91,11 @@ #define to_xgene_hwmon_dev(cl) \ container_of(cl, struct xgene_hwmon_dev, mbox_client) +enum xgene_hwmon_version { + XGENE_HWMON_V1 = 0, + XGENE_HWMON_V2 = 1, +}; + struct slimpro_resp_msg { u32 msg; u32 param1; @@ -99,6 +104,7 @@ struct slimpro_resp_msg { struct xgene_hwmon_dev { struct device *dev; + int version; struct mbox_chan *mbox_chan; struct mbox_client mbox_client; int mbox_idx; @@ -135,6 +141,15 @@ static u16 xgene_word_tst_and_clr(u16 *addr, u16 mask) return ret; } +static void *xgene_pcc_ioremap(struct xgene_hwmon_dev *ctx, + phys_addr_t phys, size_t size) +{ + if (ctx->version == XGENE_HWMON_V2) + return (void __force *)ioremap(phys, size); + + return memremap(phys, size, MEMREMAP_WB); +} + static int xgene_hwmon_pcc_rd(struct xgene_hwmon_dev *ctx, u32 *msg) { struct acpi_pcct_shared_memory *generic_comm_base = ctx->pcc_comm_addr; @@ -609,6 +624,15 @@ static void xgene_hwmon_tx_done(struct mbox_client *cl, void *msg, int ret) } } +#ifdef CONFIG_ACPI +static const struct acpi_device_id xgene_hwmon_acpi_match[] = { + {"APMC0D29", XGENE_HWMON_V1}, + {"APMC0D8A", XGENE_HWMON_V2}, + {}, +}; +MODULE_DEVICE_TABLE(acpi, xgene_hwmon_acpi_match); +#endif + static int xgene_hwmon_probe(struct platform_device *pdev) { struct xgene_hwmon_dev *ctx; @@ -623,6 +647,20 @@ static int xgene_hwmon_probe(struct platform_device *pdev) platform_set_drvdata(pdev, ctx); cl = &ctx->mbox_client; +#ifdef CONFIG_ACPI + ctx->version = -EINVAL; + if (ACPI_COMPANION(&pdev->dev)) { + const struct acpi_device_id *acpi_id; + + acpi_id = acpi_match_device(xgene_hwmon_acpi_match, &pdev->dev); + if (acpi_id) + ctx->version = (int)acpi_id->driver_data; + } + + if (ctx->version < 0) + return -ENODEV; +#endif + spin_lock_init(&ctx->kfifo_lock); mutex_init(&ctx->rd_mutex); @@ -690,9 +728,9 @@ static int xgene_hwmon_probe(struct platform_device *pdev) */ ctx->comm_base_addr = cppc_ss->base_address; if (ctx->comm_base_addr) { - ctx->pcc_comm_addr = memremap(ctx->comm_base_addr, - cppc_ss->length, - MEMREMAP_WB); + ctx->pcc_comm_addr = xgene_pcc_ioremap(ctx, + ctx->comm_base_addr, + cppc_ss->length); } else { dev_err(&pdev->dev, "Failed to get PCC comm region\n"); rc = -ENODEV; @@ -758,14 +796,6 @@ static int xgene_hwmon_remove(struct platform_device *pdev) return 0; } -#ifdef CONFIG_ACPI -static const struct acpi_device_id xgene_hwmon_acpi_match[] = { - {"APMC0D29", 0}, - {}, -}; -MODULE_DEVICE_TABLE(acpi, xgene_hwmon_acpi_match); -#endif - static const struct of_device_id xgene_hwmon_of_match[] = { {.compatible = "apm,xgene-slimpro-hwmon"}, {}