From patchwork Sun Mar 11 20:26:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Kaneko X-Patchwork-Id: 10274913 X-Patchwork-Delegate: geert@linux-m68k.org 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 3B5D3602C2 for ; Sun, 11 Mar 2018 20:27:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C840286A3 for ; Sun, 11 Mar 2018 20:27:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F71F28CD5; Sun, 11 Mar 2018 20:27:15 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI 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 77A2328CCC for ; Sun, 11 Mar 2018 20:27:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932251AbeCKU1N (ORCPT ); Sun, 11 Mar 2018 16:27:13 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:39378 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932210AbeCKU1M (ORCPT ); Sun, 11 Mar 2018 16:27:12 -0400 Received: by mail-pl0-f66.google.com with SMTP id s13-v6so8170475plq.6; Sun, 11 Mar 2018 13:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zbIabwGu5mAwGDbxeDqzVOhPA3R6Lam6GFGCA3ZoOEY=; b=HWES4q4SU6aIAzCyQ8e09jzstGnc4T87E4KRWZhteMPhJY3tKAJlOrIyNjXJ0x0OCR kuuebKmrOtOxBXMBuyIxsVwDAs2bRMTZFNmeX8tVghv6nR7fEbt2SyvH+/ztSlPgozfO ej5KbrfsioEDXD7YuVzh7SXU+Iuz6xSv/UhMpVFeI8laQu7T8OXrZj/H9zbgk4Zhl21N 4RVD6FubAssDs2UDxWLowzDWEkKfXbitlGOkBWfc7pj1kwKoFDM8QVsEgY3M8K0w4nhc +iGSM3q9g92QltnBlSfYqdBy0NqszxQAh9S8W2hRMA+L0KlHO9lx0jaa30xlx0jZkJGO aZCw== 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:in-reply-to :references; bh=zbIabwGu5mAwGDbxeDqzVOhPA3R6Lam6GFGCA3ZoOEY=; b=MM/gW2As3yn+aPxK1ME2HCuaP82SJhC3ZEpDPmvtAOZVzJgowju3uNuJc1dYECOtRT einQuTIv64OG1RpjttzjG9n693tSdouoA+XLGADLRZiA6tDqw2b4cyFneSQUs0SeD4jV yhZKqh2ZDwCTQ/0jouLfu12gnA05nim1Z450gOuxJYF3iZruiZVJDT1kgc5SaQl0Lwnz UVTx2979AXvnyVx3z2Su0OpP9S0g4omu40613iRq5qvvCRgQBisifcRwXeMSYj6iTQXY j9QT4LdaFoo1G/tKKWpeMPkTF3KzczsEoWSZ4SLnSJ/B1V6/8xwmAz8HHSyY4G04yNlP XoWw== X-Gm-Message-State: AElRT7H2dbW07R7Ij9ALj8sbzuiFJNRHbYk0797X8Ouv9ju4vksxov7j eefMO6xO7u6blq8O6sIdaow1MQ== X-Google-Smtp-Source: AG47ELttSyJFFkxDrS775n1HCF7l9SfiMSuypoQJFJv3lH5W1ofybRdVWJfMPD60IjdZKvD196GXnQ== X-Received: by 2002:a17:902:8f8f:: with SMTP id z15-v6mr5873025plo.315.1520800032043; Sun, 11 Mar 2018 13:27:12 -0700 (PDT) Received: from localhost.localdomain (KD118152108246.ppp-bb.dion.ne.jp. [118.152.108.246]) by smtp.gmail.com with ESMTPSA id h67sm14313206pfk.184.2018.03.11.13.27.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 11 Mar 2018 13:27:11 -0700 (PDT) From: Yoshihiro Kaneko To: linux-renesas-soc@vger.kernel.org Cc: Zhang Rui , Eduardo Valentin , Rob Herring , linux-pm@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH/RFT 1/3] thermal: rcar_thermal: add r8a77995 support Date: Mon, 12 Mar 2018 05:26:33 +0900 Message-Id: <1520799995-26347-2-git-send-email-ykaneko0929@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1520799995-26347-1-git-send-email-ykaneko0929@gmail.com> References: <1520799995-26347-1-git-send-email-ykaneko0929@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add support for R-Car D3 (r8a77995) thermal sensor. Signed-off-by: Yoshihiro Kaneko --- drivers/thermal/rcar_thermal.c | 141 ++++++++++++++++++++++++++++++++--------- 1 file changed, 112 insertions(+), 29 deletions(-) diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c index 73e5fee..d517155 100644 --- a/drivers/thermal/rcar_thermal.c +++ b/drivers/thermal/rcar_thermal.c @@ -69,6 +69,30 @@ struct rcar_thermal_priv { u32 ctemp; }; +enum rcar_thermal_type { + RCAR_THERMAL, + RCAR_GEN2_THERMAL, + RCAR_GEN3_THERMAL, +}; + +struct rcar_thermal_chip { + int use_of_thermal; + enum rcar_thermal_type type; +}; + +static const struct rcar_thermal_chip rcar_thermal = { + .use_of_thermal = 0, + .type = RCAR_THERMAL, +}; +static const struct rcar_thermal_chip rcar_gen2_thermal = { + .use_of_thermal = 1, + .type = RCAR_GEN2_THERMAL, +}; +static const struct rcar_thermal_chip rcar_gen3_thermal = { + .use_of_thermal = 1, + .type = RCAR_GEN3_THERMAL, +}; + #define rcar_thermal_for_each_priv(pos, common) \ list_for_each_entry(pos, &common->head, list) @@ -77,13 +101,23 @@ struct rcar_thermal_priv { #define rcar_priv_to_dev(priv) ((priv)->common->dev) #define rcar_has_irq_support(priv) ((priv)->common->base) #define rcar_id_to_shift(priv) ((priv)->id * 8) -#define rcar_of_data(dev) ((unsigned long)of_device_get_match_data(dev)) -#define rcar_use_of_thermal(dev) (rcar_of_data(dev) == USE_OF_THERMAL) +#define rcar_of_data(dev) \ + ((struct rcar_thermal_chip *)of_device_get_match_data(dev)) +#define rcar_use_of_thermal(dev) (rcar_of_data(dev)->use_of_thermal) -#define USE_OF_THERMAL 1 static const struct of_device_id rcar_thermal_dt_ids[] = { - { .compatible = "renesas,rcar-thermal", }, - { .compatible = "renesas,rcar-gen2-thermal", .data = (void *)USE_OF_THERMAL }, + { + .compatible = "renesas,rcar-thermal", + .data = (void *)&rcar_thermal, + }, + { + .compatible = "renesas,rcar-gen2-thermal", + .data = (void *)&rcar_gen2_thermal, + }, + { + .compatible = "renesas,thermal-r8a77995", + .data = (void *)&rcar_gen3_thermal, + }, {}, }; MODULE_DEVICE_TABLE(of, rcar_thermal_dt_ids); @@ -190,7 +224,8 @@ static int rcar_thermal_update_temp(struct rcar_thermal_priv *priv) * enable IRQ */ if (rcar_has_irq_support(priv)) { - rcar_thermal_write(priv, FILONOFF, 0); + if (rcar_of_data(dev)->type != RCAR_GEN3_THERMAL) + rcar_thermal_write(priv, FILONOFF, 0); /* enable Rising/Falling edge interrupt */ rcar_thermal_write(priv, POSNEG, 0x1); @@ -438,6 +473,7 @@ static int rcar_thermal_probe(struct platform_device *pdev) struct rcar_thermal_priv *priv; struct device *dev = &pdev->dev; struct resource *res, *irq; + int nirq = rcar_of_data(dev)->type == RCAR_GEN3_THERMAL ? 2 : 1; int mres = 0; int i; int ret = -ENODEV; @@ -457,19 +493,35 @@ static int rcar_thermal_probe(struct platform_device *pdev) pm_runtime_enable(dev); pm_runtime_get_sync(dev); - irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); - if (irq) { - /* - * platform has IRQ support. - * Then, driver uses common registers - * rcar_has_irq_support() will be enabled - */ - res = platform_get_resource(pdev, IORESOURCE_MEM, mres++); - common->base = devm_ioremap_resource(dev, res); - if (IS_ERR(common->base)) - return PTR_ERR(common->base); + for (i = 0; i < nirq; i++) { + irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); + if (!irq) + continue; + if (!common->base) { + /* + * platform has IRQ support. + * Then, driver uses common registers + * rcar_has_irq_support() will be enabled + */ + res = platform_get_resource(pdev, IORESOURCE_MEM, + mres++); + common->base = devm_ioremap_resource(dev, res); + if (IS_ERR(common->base)) + return PTR_ERR(common->base); - idle = 0; /* polling delay is not needed */ + idle = 0; /* polling delay is not needed */ + } + + ret = devm_request_irq(dev, irq->start, rcar_thermal_irq, + IRQF_SHARED, dev_name(dev), common); + if (ret) { + dev_err(dev, "irq request failed\n "); + goto error_unregister; + } + + /* update ENR bits */ + if (rcar_of_data(dev)->type == RCAR_GEN3_THERMAL) + enr_bits |= 1 << i; } for (i = 0;; i++) { @@ -531,20 +583,12 @@ static int rcar_thermal_probe(struct platform_device *pdev) list_move_tail(&priv->list, &common->head); /* update ENR bits */ - enr_bits |= 3 << (i * 8); + if (rcar_of_data(dev)->type != RCAR_GEN3_THERMAL) + enr_bits |= 3 << (i * 8); } - /* enable temperature comparation */ - if (irq) { - ret = devm_request_irq(dev, irq->start, rcar_thermal_irq, 0, - dev_name(dev), common); - if (ret) { - dev_err(dev, "irq request failed\n "); - goto error_unregister; - } - + if (enr_bits) rcar_thermal_common_write(common, ENR, enr_bits); - } dev_info(dev, "%d sensor probed\n", i); @@ -556,9 +600,48 @@ static int rcar_thermal_probe(struct platform_device *pdev) return ret; } +#ifdef CONFIG_PM_SLEEP +static int rcar_thermal_suspend(struct device *dev) +{ + struct rcar_thermal_common *common = dev_get_drvdata(dev); + struct rcar_thermal_priv *priv; + + if (rcar_of_data(dev)->type == RCAR_GEN3_THERMAL) { + rcar_thermal_common_write(common, ENR, 0); + priv = list_first_entry(&common->head, typeof(*priv), list); + rcar_thermal_irq_disable(priv); + rcar_thermal_bset(priv, THSCR, CPCTL, 0); + } + + return 0; +} + +static int rcar_thermal_resume(struct device *dev) +{ + struct rcar_thermal_common *common = dev_get_drvdata(dev); + struct rcar_thermal_priv *priv; + int ret; + + if (rcar_of_data(dev)->type == RCAR_GEN3_THERMAL) { + priv = list_first_entry(&common->head, typeof(*priv), list); + ret = rcar_thermal_update_temp(priv); + if (ret < 0) + return ret; + rcar_thermal_irq_enable(priv); + rcar_thermal_common_write(common, ENR, 0x03); + } + + return 0; +} +#endif + +static SIMPLE_DEV_PM_OPS(rcar_thermal_pm_ops, rcar_thermal_suspend, + rcar_thermal_resume); + static struct platform_driver rcar_thermal_driver = { .driver = { .name = "rcar_thermal", + .pm = &rcar_thermal_pm_ops, .of_match_table = rcar_thermal_dt_ids, }, .probe = rcar_thermal_probe,