From patchwork Sat Dec 3 14:11:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoyou Xie X-Patchwork-Id: 86425 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp711700qgi; Sat, 3 Dec 2016 06:12:39 -0800 (PST) X-Received: by 10.99.125.65 with SMTP id m1mr88977481pgn.159.1480774359405; Sat, 03 Dec 2016 06:12:39 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 64si8864117ply.163.2016.12.03.06.12.39; Sat, 03 Dec 2016 06:12:39 -0800 (PST) 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=@linaro.org; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752960AbcLCOMa (ORCPT + 25 others); Sat, 3 Dec 2016 09:12:30 -0500 Received: from mail-pg0-f43.google.com ([74.125.83.43]:36787 "EHLO mail-pg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751175AbcLCOM2 (ORCPT ); Sat, 3 Dec 2016 09:12:28 -0500 Received: by mail-pg0-f43.google.com with SMTP id f188so118048868pgc.3 for ; Sat, 03 Dec 2016 06:12:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=lo2jTwhlegPatU14htdROy8cV+rhxcUgVNhhxgpwEX4=; b=Prs/55A1YpBYtkSxQdkmTEWIY0SUIq0dh6yMQ9IKDyzKQNJ+vshWZlsB+i/8UKshok nbx+uy7NBJPiwe4O/9cmhT/xqFR5g5Ypl0tkgu92EO69j2hyiFh7gHgUBUMPqy86AqjL ITozDS6FfNI1nVd5MRHKVqoRljEX126a9z31A= 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; bh=lo2jTwhlegPatU14htdROy8cV+rhxcUgVNhhxgpwEX4=; b=PkPJlPsexrdNSePmve+jaLTdiSe9R4+K0BLCr6h4CwvXW7wa0Pxz8RbIbW4QgyO0vf gqBLDR0cFBFt9xQZ7f7ZVq7Bxs/TEiABUb5FCtCnaLSpaJ42PJ+pJo6/eA2tD15z5Y1X OFFprw05nAiqMqBidPQuhCW5sspX1tSyDIk33P6s0Ljf2YScrOBzOo4oSRqkWHpTkK58 XdHcLxShyEyP7zoMjCld9dVZXn1Xj0RwfWCqODXKSSiJPuI/7YEplShsCy9DarRowejR d9XrHSgwkFFscjzNNZcryPnkqHkdtgbfNvIp8mn0nBJ/S6zy2GU1UM1t14sw1qw7hzHv GBDw== X-Gm-Message-State: AKaTC03NdxH3DKaKQTIWwv5EqmcKXdvjeXeHqEkOLtPyIxEvjXXHPr97X0UQFOgVXESeJZ/e X-Received: by 10.84.129.100 with SMTP id 91mr105579312plb.73.1480774347949; Sat, 03 Dec 2016 06:12:27 -0800 (PST) Received: from localhost.localdomain ([45.56.152.50]) by smtp.gmail.com with ESMTPSA id i11sm15437560pgn.17.2016.12.03.06.12.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 03 Dec 2016 06:12:27 -0800 (PST) From: Baoyou Xie To: jun.nie@linaro.org, gregkh@linuxfoundation.org, davem@davemloft.net, geert+renesas@glider.be, akpm@linux-foundation.org, mchehab@kernel.org, linux@roeck-us.net, ulf.hansson@linaro.org, arnd@arndb.de, oss@buserror.net, krzk@kernel.org, qiang.zhao@nxp.com, aar@pengutronix.de, claudiu.manoil@nxp.com, pankaj.dubey@samsung.com, f.fainelli@gmail.com, yangbo.lu@nxp.com, scott.branden@broadcom.com, rmk+kernel@armlinux.org.uk Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, baoyou.xie@linaro.org, xie.baoyou@zte.com.cn, chen.chaokai@zte.com.cn, wang.qiang01@zte.com.cn Subject: [PATCH 1/2] soc: zte: pm_domains: Prepare for supporting ARMv8 2967 family Date: Sat, 3 Dec 2016 22:11:30 +0800 Message-Id: <1480774291-6211-1-git-send-email-baoyou.xie@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ARMv8 2967 family (296718, 296716 etc) uses different value for controlling the power domain on/off registers, Choose the value depending on the compatible. Multiple domains are prepared for the family, it's privated by the drivers of boards. This patch prepares the common functions. Signed-off-by: Baoyou Xie --- MAINTAINERS | 1 + drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/zte/Kconfig | 13 ++++ drivers/soc/zte/Makefile | 4 ++ drivers/soc/zte/pm_domains.c | 138 +++++++++++++++++++++++++++++++++++++++++++ drivers/soc/zte/pm_domains.h | 29 +++++++++ 7 files changed, 187 insertions(+) create mode 100644 drivers/soc/zte/Kconfig create mode 100644 drivers/soc/zte/Makefile create mode 100644 drivers/soc/zte/pm_domains.c create mode 100644 drivers/soc/zte/pm_domains.h -- 2.7.4 diff --git a/MAINTAINERS b/MAINTAINERS index ad199da..8198389 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1979,6 +1979,7 @@ L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) S: Maintained F: arch/arm/mach-zx/ F: drivers/clk/zte/ +F: drivers/soc/zte/ F: Documentation/devicetree/bindings/arm/zte.txt F: Documentation/devicetree/bindings/clock/zx296702-clk.txt diff --git a/drivers/soc/Kconfig b/drivers/soc/Kconfig index f31bceb..f09023f 100644 --- a/drivers/soc/Kconfig +++ b/drivers/soc/Kconfig @@ -11,5 +11,6 @@ source "drivers/soc/tegra/Kconfig" source "drivers/soc/ti/Kconfig" source "drivers/soc/ux500/Kconfig" source "drivers/soc/versatile/Kconfig" +source "drivers/soc/zte/Kconfig" endmenu diff --git a/drivers/soc/Makefile b/drivers/soc/Makefile index 50c23d0..05eae52 100644 --- a/drivers/soc/Makefile +++ b/drivers/soc/Makefile @@ -16,3 +16,4 @@ obj-$(CONFIG_ARCH_TEGRA) += tegra/ obj-$(CONFIG_SOC_TI) += ti/ obj-$(CONFIG_ARCH_U8500) += ux500/ obj-$(CONFIG_PLAT_VERSATILE) += versatile/ +obj-$(CONFIG_ARCH_ZX) += zte/ diff --git a/drivers/soc/zte/Kconfig b/drivers/soc/zte/Kconfig new file mode 100644 index 0000000..4953c3fa --- /dev/null +++ b/drivers/soc/zte/Kconfig @@ -0,0 +1,13 @@ +# +# zx SoC drivers +# +menuconfig SOC_ZX + bool "zx SoC driver support" + +if SOC_ZX + +config ZX_PM_DOMAINS + bool "zx PM domains" + depends on PM_GENERIC_DOMAINS + +endif diff --git a/drivers/soc/zte/Makefile b/drivers/soc/zte/Makefile new file mode 100644 index 0000000..97ac8ea --- /dev/null +++ b/drivers/soc/zte/Makefile @@ -0,0 +1,4 @@ +# +# zx SOC drivers +# +obj-$(CONFIG_ZX_PM_DOMAINS) += pm_domains.o diff --git a/drivers/soc/zte/pm_domains.c b/drivers/soc/zte/pm_domains.c new file mode 100644 index 0000000..5792f21 --- /dev/null +++ b/drivers/soc/zte/pm_domains.c @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2015 ZTE Ltd. + * + * Author: Baoyou Xie + * License terms: GNU General Public License (GPL) version 2 + */ +#include +#include +#include +#include +#include "pm_domains.h" + +#define PCU_DM_CLKEN 0x18 +#define PCU_DM_RSTEN 0x20 +#define PCU_DM_ISOEN 0x1c +#define PCU_DM_PWREN 0x24 +#define PCU_DM_ACK_SYNC 0x28 + +static void __iomem *pcubase; + +int zx_normal_power_on(struct generic_pm_domain *domain) +{ + struct zx_pm_domain *zpd = (struct zx_pm_domain *)domain; + unsigned long loop = 20000; + u32 val; + + loop = 1000; + do { + val = readl_relaxed(pcubase + PCU_DM_PWREN); + val |= BIT(zpd->bit); + writel_relaxed(val, pcubase + PCU_DM_PWREN); + + udelay(1); + val = readl_relaxed(pcubase + PCU_DM_ACK_SYNC) & BIT(zpd->bit); + } while (--loop && !val); + + if (!loop) { + pr_err("Error: %s %s fail\n", __func__, domain->name); + return -EIO; + } + + val = readl_relaxed(pcubase + PCU_DM_RSTEN); + val &= ~BIT(zpd->bit); + writel_relaxed(val | BIT(zpd->bit), pcubase + PCU_DM_RSTEN); + udelay(5); + + val = readl_relaxed(pcubase + PCU_DM_ISOEN); + val &= ~BIT(zpd->bit); + writel_relaxed(val, pcubase + PCU_DM_ISOEN); + udelay(5); + + val = readl_relaxed(pcubase + PCU_DM_CLKEN); + val &= ~BIT(zpd->bit); + writel_relaxed(val | BIT(zpd->bit), pcubase + PCU_DM_CLKEN); + udelay(5); + + pr_info("normal poweron %s\n", domain->name); + + return 0; +} + +int zx_normal_power_off(struct generic_pm_domain *domain) +{ + struct zx_pm_domain *zpd = (struct zx_pm_domain *)domain; + unsigned long loop = 1000; + u32 val; + + val = readl_relaxed(pcubase + PCU_DM_CLKEN); + val &= ~BIT(zpd->bit); + writel_relaxed(val, pcubase + PCU_DM_CLKEN); + udelay(5); + + val = readl_relaxed(pcubase + PCU_DM_ISOEN); + val &= ~BIT(zpd->bit); + writel_relaxed(val | BIT(zpd->bit), pcubase + PCU_DM_ISOEN); + udelay(5); + + val = readl_relaxed(pcubase + PCU_DM_RSTEN); + val &= ~BIT(zpd->bit); + writel_relaxed(val, pcubase + PCU_DM_RSTEN); + udelay(5); + + loop = 1000; + do { + val = readl_relaxed(pcubase + PCU_DM_PWREN); + val &= ~BIT(zpd->bit); + writel_relaxed(val, pcubase + PCU_DM_PWREN); + + udelay(1); + + val = readl_relaxed(pcubase + PCU_DM_ACK_SYNC) & BIT(zpd->bit); + } while (--loop && val); + + if (!loop) { + pr_err("Error: %s %s fail\n", __func__, domain->name); + return -EIO; + } + + pr_info("normal poweroff %s\n", domain->name); + + return 0; +} + +int +zx_pd_probe(struct platform_device *pdev, + struct generic_pm_domain **zx_pm_domains, + int domain_num) +{ + struct genpd_onecell_data *genpd_data; + struct resource *res; + int i; + + genpd_data = devm_kzalloc(&pdev->dev, sizeof(*genpd_data), GFP_KERNEL); + if (!genpd_data) + return -ENOMEM; + + genpd_data->domains = zx_pm_domains; + genpd_data->num_domains = domain_num; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!res) { + dev_err(&pdev->dev, "no memory resource defined\n"); + return -ENODEV; + } + + pcubase = devm_ioremap_resource(&pdev->dev, res); + if (!pcubase) { + dev_err(&pdev->dev, "ioremap fail.\n"); + return -EIO; + } + + for (i = 0; i < domain_num; ++i) + pm_genpd_init(zx_pm_domains[i], NULL, false); + + of_genpd_add_provider_onecell(pdev->dev.of_node, genpd_data); + dev_info(&pdev->dev, "powerdomain init ok\n"); + return 0; +} diff --git a/drivers/soc/zte/pm_domains.h b/drivers/soc/zte/pm_domains.h new file mode 100644 index 0000000..613e0be --- /dev/null +++ b/drivers/soc/zte/pm_domains.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2015 ZTE Co., Ltd. + * http://www.zte.com.cn + * + * Header for ZTE's Power Domain Driver support + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#ifndef __ZTE_PM_DOMAIN_H +#define __ZTE_PM_DOMAIN_H + +#include +#include + +struct zx_pm_domain { + struct generic_pm_domain dm; + unsigned int bit; +}; + +extern int zx_normal_power_on(struct generic_pm_domain *domain); +extern int zx_normal_power_off(struct generic_pm_domain *domain); +extern int +zx_pd_probe(struct platform_device *pdev, + struct generic_pm_domain **zx_pm_domains, + int domain_num); +#endif /* __ZTE_PM_DOMAIN_H */