From patchwork Sat Jan 14 07:05:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoyou Xie X-Patchwork-Id: 91506 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp541369qgi; Fri, 13 Jan 2017 23:07:11 -0800 (PST) X-Received: by 10.98.15.143 with SMTP id 15mr18311162pfp.100.1484377631653; Fri, 13 Jan 2017 23:07:11 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id c78si14955852pfb.0.2017.01.13.23.07.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jan 2017 23:07:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cSIQg-0007VQ-0P; Sat, 14 Jan 2017 07:07:10 +0000 Received: from mail-pg0-x234.google.com ([2607:f8b0:400e:c05::234]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cSIQY-0006wu-09 for linux-arm-kernel@lists.infradead.org; Sat, 14 Jan 2017 07:07:05 +0000 Received: by mail-pg0-x234.google.com with SMTP id f188so1336415pgc.3 for ; Fri, 13 Jan 2017 23:06:45 -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:in-reply-to:references; bh=BQ7mQRphCn/Qwse/9Z/zC5T9RsCV765Bkq0mqDFCOjA=; b=PbJNyKtdQaJcRKCEkJ9JC5axiTyefLbTMamfhCCjDLFKO9oYs4B3fvm/LAys+n04+L u5Ofi4pZXNz3CEhruAiqgVEOO3SJLb2if2V+O435no1f7aSq9/HIUr05JrGij76NSB4s veIUF9I5keW8018i45r7k0fGlYuccfHLvRZdA= 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=BQ7mQRphCn/Qwse/9Z/zC5T9RsCV765Bkq0mqDFCOjA=; b=VBUxXhCegGKrmFLclG4J5y1Eu/GnVdM++sq5Rg1H1xtmWMfcaOY7WM9k56SySLB33A aVVdIZUMcbJ+gnxkecf9LrEXkxv/i/RQY1M4hCjgviAY3u8scQ7JzRoB1LDgzfTFcqZe ey1o9O6w5rPN0Rxs9lubl+u3gRfNstTWbOcrydHpsAMcWWMrvyVbvwO7CxGxlh/o9Olr yMSOvsUHpxZBpwKbQGtlVK9lY+XhioWahWfcu54F8uwYeN7qAkONPvLYrXjnCIcK+HPS imISfi6If7qDmfJa3xoumCD9ACUQX2N8ufnrtNyW4I3BbjcD3Grk/js7hiysena0ym38 +aag== X-Gm-Message-State: AIkVDXK7jHmD56sE8J3+/34X0Ye3seOVGVhDFJ/ywnm/7GgD2Z8Y3wrLdnyxYqtM6qF2a3MX X-Received: by 10.84.136.7 with SMTP id 7mr22012171plk.100.1484377605329; Fri, 13 Jan 2017 23:06:45 -0800 (PST) Received: from localhost.localdomain ([104.237.91.20]) by smtp.gmail.com with ESMTPSA id t21sm33246201pfa.1.2017.01.13.23.06.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Jan 2017 23:06:44 -0800 (PST) From: Baoyou Xie To: jun.nie@linaro.org, p.zabel@pengutronix.de, robh+dt@kernel.org, mark.rutland@arm.com Subject: [PATCH v1 3/3] reset: zx2967: add reset controller driver for ZTE's zx2967 family Date: Sat, 14 Jan 2017 15:05:30 +0800 Message-Id: <1484377530-30635-3-git-send-email-baoyou.xie@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484377530-30635-1-git-send-email-baoyou.xie@linaro.org> References: <1484377530-30635-1-git-send-email-baoyou.xie@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170113_230702_137277_766CCA0C X-CRM114-Status: GOOD ( 16.44 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:400e:c05:0:0:0:234 listed in] [list.dnswl.org] 0.0 HK_RANDOM_ENVFROM Envelope sender username looks random -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, xie.baoyou@zte.com.cn, linux-kernel@vger.kernel.org, chen.chaokai@zte.com.cn, wang.qiang01@zte.com.cn, baoyou.xie@linaro.org, shawnguo@kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org This patch adds reset controller driver for ZTE's zx2967 family. Signed-off-by: Baoyou Xie --- drivers/reset/Kconfig | 6 ++ drivers/reset/Makefile | 1 + drivers/reset/reset-zx2967.c | 136 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 drivers/reset/reset-zx2967.c -- 2.7.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/drivers/reset/Kconfig b/drivers/reset/Kconfig index 172dc96..972d077 100644 --- a/drivers/reset/Kconfig +++ b/drivers/reset/Kconfig @@ -92,6 +92,12 @@ config RESET_ZYNQ help This enables the reset controller driver for Xilinx Zynq SoCs. +config RESET_ZX2967 + bool "ZX2967 Reset Driver" + depends on ARCH_ZX || COMPILE_TEST + help + This enables the reset controller driver for ZTE zx2967 family. + source "drivers/reset/sti/Kconfig" source "drivers/reset/hisilicon/Kconfig" source "drivers/reset/tegra/Kconfig" diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile index 13b346e..807b77b 100644 --- a/drivers/reset/Makefile +++ b/drivers/reset/Makefile @@ -14,3 +14,4 @@ obj-$(CONFIG_RESET_SUNXI) += reset-sunxi.o obj-$(CONFIG_TI_SYSCON_RESET) += reset-ti-syscon.o obj-$(CONFIG_RESET_UNIPHIER) += reset-uniphier.o obj-$(CONFIG_RESET_ZYNQ) += reset-zynq.o +obj-$(CONFIG_RESET_ZX2967) += reset-zx2967.o diff --git a/drivers/reset/reset-zx2967.c b/drivers/reset/reset-zx2967.c new file mode 100644 index 0000000..63f9c41 --- /dev/null +++ b/drivers/reset/reset-zx2967.c @@ -0,0 +1,136 @@ +/* + * ZTE's zx2967 family thermal sensor driver + * + * Copyright (C) 2017 ZTE Ltd. + * + * Author: Baoyou Xie + * + * License terms: GNU General Public License (GPL) version 2 + */ + +#include +#include +#include +#include + +struct zx2967_reset { + void __iomem *reg_base; + spinlock_t lock; + struct reset_controller_dev rcdev; +}; + +static int zx2967_reset_assert(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct zx2967_reset *reset = NULL; + int bank = id / 32; + int offset = id % 32; + unsigned int reg; + unsigned long flags; + + reset = container_of(rcdev, struct zx2967_reset, rcdev); + + spin_lock_irqsave(&reset->lock, flags); + + reg = readl(reset->reg_base + (bank * 4)); + writel(reg & ~BIT(offset), reset->reg_base + (bank * 4)); + reg = readl(reset->reg_base + (bank * 4)); + + spin_unlock_irqrestore(&reset->lock, flags); + + return 0; +} + +static int zx2967_reset_deassert(struct reset_controller_dev *rcdev, + unsigned long id) +{ + struct zx2967_reset *reset = NULL; + int bank = id / 32; + int offset = id % 32; + unsigned int reg; + unsigned long flags; + + reset = container_of(rcdev, struct zx2967_reset, rcdev); + + spin_lock_irqsave(&reset->lock, flags); + + reg = readl(reset->reg_base + (bank * 4)); + writel(reg | BIT(offset), reset->reg_base + (bank * 4)); + reg = readl(reset->reg_base + (bank * 4)); + + spin_unlock_irqrestore(&reset->lock, flags); + + return 0; +} + +static struct reset_control_ops zx2967_reset_ops = { + .assert = zx2967_reset_assert, + .deassert = zx2967_reset_deassert, +}; + +static int zx2967_reset_probe(struct platform_device *pdev) +{ + struct zx2967_reset *reset; + struct resource *res; + + reset = devm_kzalloc(&pdev->dev, sizeof(*reset), GFP_KERNEL); + if (!reset) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + reset->reg_base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(reset->reg_base)) + return PTR_ERR(reset->reg_base); + + spin_lock_init(&reset->lock); + + reset->rcdev.owner = THIS_MODULE; + reset->rcdev.nr_resets = resource_size(res) * 8; + reset->rcdev.ops = &zx2967_reset_ops; + reset->rcdev.of_node = pdev->dev.of_node; + + dev_info(&pdev->dev, "reset controller cnt:%d", + reset->rcdev.nr_resets); + + return reset_controller_register(&reset->rcdev); +} + +static int zx2967_reset_remove(struct platform_device *pdev) +{ + struct zx2967_reset *reset = platform_get_drvdata(pdev); + + reset_controller_unregister(&reset->rcdev); + + return 0; +} + +static const struct of_device_id zx2967_reset_dt_ids[] = { + { .compatible = "zte,zx296718-reset", }, + {}, +}; +MODULE_DEVICE_TABLE(of, zx2967_reset_dt_ids); + +static struct platform_driver zx2967_reset_driver = { + .probe = zx2967_reset_probe, + .remove = zx2967_reset_remove, + .driver = { + .name = "zx2967-reset", + .of_match_table = zx2967_reset_dt_ids, + }, +}; + +static int __init zx2967_reset_init(void) +{ + return platform_driver_register(&zx2967_reset_driver); +} +arch_initcall(zx2967_reset_init); + +static void __exit zx2967_reset_exit(void) +{ + platform_driver_unregister(&zx2967_reset_driver); +} +module_exit(zx2967_reset_exit); + +MODULE_AUTHOR("Baoyou Xie "); +MODULE_DESCRIPTION("ZTE zx2967 Reset Controller Driver"); +MODULE_LICENSE("GPL");