From patchwork Tue Apr 2 13:37:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Quadros X-Patchwork-Id: 161626 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp1758502jan; Tue, 2 Apr 2019 06:38:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqyLjRB2bmyZXX+1TMCwR9uP1KzOBeYZ2WxuCmlpzK+Ukac91k2NOmQvy+XJkSLjmEZdsMci X-Received: by 2002:a65:47c6:: with SMTP id f6mr49585848pgs.173.1554212287325; Tue, 02 Apr 2019 06:38:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554212287; cv=none; d=google.com; s=arc-20160816; b=Dp2Vvz/qMmyfOBbEA64ug75siU7RqjmM98tydzYD9gNdixSXdTWYDXeCszWpV/yJf4 l+vYpXMqK0IqKsfaMBDwEgVU9vLX+5OHWAFgCgfUPwpNWrEf9fcHK/K7CkjQX76qiQ/q OEwLDRLwf40ByRc18gmeWOVPXdGGjNfv8dl13RjzFKSZIp/FdjluHUGOaiTXSjn5+F8Z +Mjm4DkjOJjVdJEch5b64AEDkkE5E4wOiW5G0XtsToGM6mjzfTU0zrPoagCfREokJAyV Jd2hfx1aCWoQDiiRiBZQ/6EW7Mfb+abBiEJnOMx+qsDlFfA2udOw7MHiDtNr9xBbgsMm hYnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=aAk0r9TUo1AqkBkCxh24GlYC3DNt9KEpMWg5nv+RvLQ=; b=JSn1fU+QPl8gMVeekRpVTBkuWEt87PcG6LDjiyri+W6MR5hYh5gobpbO5dckVz5rPz plzSdYuP5dIpwyVt2vwT17g7iYzn+tsnwCoNHuYzt5BGU39Fv8xqBoqwFiFJ1QHIL9jy L//kRjMVhr8w8J5cZrqHTu+x7Nu7Wu4Py40sdRvFI3HWUDjSi0aUq538KVuUn9jd9T0T +ucRn3RQ9BJDbFkkGXcHWIGFnopfC/+mm8vY/TZqAm1k42+Jaoiq8NBBKtTctnpwea5H AS0SiCVrWbsOf2wbdZwtj/2zC+sA/TCSkBgWLWOG/zO5wepNTAmZLX9yzBcFGzMZwUZp k9LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=JJP1JIR+; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b22si4110631pls.285.2019.04.02.06.38.07; Tue, 02 Apr 2019 06:38:07 -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; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=JJP1JIR+; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730695AbfDBNiG (ORCPT + 31 others); Tue, 2 Apr 2019 09:38:06 -0400 Received: from fllv0016.ext.ti.com ([198.47.19.142]:60154 "EHLO fllv0016.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728105AbfDBNiE (ORCPT ); Tue, 2 Apr 2019 09:38:04 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id x32Dc2lM023114; Tue, 2 Apr 2019 08:38:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1554212282; bh=aAk0r9TUo1AqkBkCxh24GlYC3DNt9KEpMWg5nv+RvLQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=JJP1JIR+ChPZJCf05+ZpB9w0KhVeOwG1X8wXR6XiLCr0/FVkwyO3JGb1NdU8p/bkJ 9pMkHSi3zqtdpe5RVcXWgzwGoASStdpDPSpZMTvsXE8xigmbAjnroo8fOQldmYnz4c W+h6gbBQSHFycF2l9b3Fjn9x7HI3vf51zZ42teNU= Received: from DFLE109.ent.ti.com (dfle109.ent.ti.com [10.64.6.30]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x32Dc2a7018468 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 2 Apr 2019 08:38:02 -0500 Received: from DFLE105.ent.ti.com (10.64.6.26) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 2 Apr 2019 08:38:00 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE105.ent.ti.com (10.64.6.26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 2 Apr 2019 08:38:00 -0500 Received: from lta0400828d.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id x32DbsU0051551; Tue, 2 Apr 2019 08:37:58 -0500 From: Roger Quadros To: CC: , , , Roger Quadros Subject: [RFC PATCH 2/4] bus: ti-sysc: Add generic enable/disable functions Date: Tue, 2 Apr 2019 16:37:50 +0300 Message-ID: <20190402133752.6912-3-rogerq@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190402133752.6912-1-rogerq@ti.com> References: <20190402133752.6912-1-rogerq@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For non legacy cases, add generic sysc_enable_module() and sysc_disable_module() functions. Signed-off-by: Roger Quadros --- drivers/bus/ti-sysc.c | 114 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki diff --git a/drivers/bus/ti-sysc.c b/drivers/bus/ti-sysc.c index 5c0dd80021cc..1e63b6265764 100644 --- a/drivers/bus/ti-sysc.c +++ b/drivers/bus/ti-sysc.c @@ -793,6 +793,112 @@ static void sysc_show_registers(struct sysc *ddata) buf); } +#define SYSC_IDLE_MASK (SYSC_NR_IDLEMODES - 1) + +static int sysc_enable_module(struct device *dev) +{ + struct sysc *ddata; + const struct sysc_regbits *regbits; + u32 reg, idlemodes, best_mode; + + ddata = dev_get_drvdata(dev); + if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV) + return 0; + + regbits = ddata->cap->regbits; + reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]); + + /* Set SIDLE mode */ + idlemodes = ddata->cfg.sidlemodes; + if (!idlemodes || regbits->sidle_shift < 0) + goto set_midle; + + best_mode = fls(ddata->cfg.sidlemodes) - 1; + if (best_mode > SYSC_IDLE_MASK) { + dev_err(dev, "%s: invalid sidlemode\n", __func__); + return -EINVAL; + } + + reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift); + reg |= best_mode << regbits->sidle_shift; + sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg); + +set_midle: + /* Set MIDLE mode */ + idlemodes = ddata->cfg.midlemodes; + if (!idlemodes || regbits->midle_shift < 0) + return 0; + + best_mode = fls(ddata->cfg.midlemodes) - 1; + if (best_mode > SYSC_IDLE_MASK) { + dev_err(dev, "%s: invalid midlemode\n", __func__); + return -EINVAL; + } + + reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift); + reg |= best_mode << regbits->midle_shift; + sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg); + + return 0; +} + +static int sysc_disable_module(struct device *dev) +{ + struct sysc *ddata; + const struct sysc_regbits *regbits; + u32 reg, idlemodes, best_mode; + + ddata = dev_get_drvdata(dev); + if (ddata->offsets[SYSC_SYSCONFIG] == -ENODEV) + return 0; + + regbits = ddata->cap->regbits; + reg = sysc_read(ddata, ddata->offsets[SYSC_SYSCONFIG]); + + /* Set MIDLE mode */ + idlemodes = ddata->cfg.midlemodes; + if (!idlemodes || regbits->midle_shift < 0) + goto set_sidle; + + if (idlemodes & BIT(SYSC_IDLE_SMART_WKUP)) { + best_mode = SYSC_IDLE_SMART_WKUP; + } else if (idlemodes & BIT(SYSC_IDLE_SMART)) { + best_mode = SYSC_IDLE_SMART; + } else if (idlemodes & SYSC_IDLE_FORCE) { + best_mode = SYSC_IDLE_FORCE; + } else { + dev_err(dev, "%s: invalid midlemode\n", __func__); + return -EINVAL; + } + + reg &= ~(SYSC_IDLE_MASK << regbits->midle_shift); + reg |= best_mode << regbits->midle_shift; + sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg); + +set_sidle: + /* Set SIDLE mode */ + idlemodes = ddata->cfg.sidlemodes; + if (!idlemodes || regbits->sidle_shift < 0) + return 0; + + if (idlemodes & BIT(SYSC_IDLE_SMART_WKUP)) { + best_mode = SYSC_IDLE_SMART_WKUP; + } else if (idlemodes & BIT(SYSC_IDLE_SMART)) { + best_mode = SYSC_IDLE_SMART; + } else if (idlemodes & SYSC_IDLE_FORCE) { + best_mode = SYSC_IDLE_FORCE; + } else { + dev_err(dev, "%s: invalid sidlemode\n", __func__); + return -EINVAL; + } + + reg &= ~(SYSC_IDLE_MASK << regbits->sidle_shift); + reg |= best_mode << regbits->sidle_shift; + sysc_write(ddata, ddata->offsets[SYSC_SYSCONFIG], reg); + + return 0; +} + static int __maybe_unused sysc_runtime_suspend_legacy(struct device *dev, struct sysc *ddata) { @@ -849,6 +955,10 @@ static int __maybe_unused sysc_runtime_suspend(struct device *dev) error = sysc_runtime_suspend_legacy(dev, ddata); if (error) return error; + } else { + error = sysc_disable_module(dev); + if (error) + return error; } sysc_disable_main_clocks(ddata); @@ -885,6 +995,10 @@ static int __maybe_unused sysc_runtime_resume(struct device *dev) error = sysc_runtime_resume_legacy(dev, ddata); if (error) goto err_main_clocks; + } else { + error = sysc_enable_module(dev); + if (error) + goto err_main_clocks; } ddata->enabled = true;