From patchwork Wed Nov 23 08:07:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 83563 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp2513545qge; Wed, 23 Nov 2016 00:11:05 -0800 (PST) X-Received: by 10.84.139.67 with SMTP id 61mr4019614plq.65.1479888665118; Wed, 23 Nov 2016 00:11:05 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id b141si32628047pfb.177.2016.11.23.00.11.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Nov 2016 00:11:05 -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 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.85_2 #1 (Red Hat Linux)) id 1c9Sd2-0001lf-Dp; Wed, 23 Nov 2016 08:10:04 +0000 Received: from mail-pf0-x229.google.com ([2607:f8b0:400e:c00::229]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c9Sck-0001Zt-Pk for linux-arm-kernel@lists.infradead.org; Wed, 23 Nov 2016 08:09:48 +0000 Received: by mail-pf0-x229.google.com with SMTP id c4so2177521pfb.1 for ; Wed, 23 Nov 2016 00:09:26 -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=Qcp0L82+qsjVkwOhWTdSBxNAtoozN6qGcfQQ2if0sBs=; b=beLKelrMu2hUnm8ubpBwM+/X7v2bo+4nIJdED9Ln8eu5kWSWPvSpETxMO8VlCs/2Ix HiF7U3aTNOB3cqC0hJ3hISMYdqWunVX00pMOtnCqM79WXsF/Ycubq5ByTgjU1B05M7qs V+MSgpR+wFX1cfzCAY9wTuPQcu/6YoWSucoaA= 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:in-reply-to :references; bh=Qcp0L82+qsjVkwOhWTdSBxNAtoozN6qGcfQQ2if0sBs=; b=DOUA0vs9E4OWFvQe+OSMAx6pNHTJ2NBRkyT+fzhX3tM+54HISO5EMfWW0V9OEmYmHy xsNciwXzehu36rzfzZ7MKdsrvYlCddfVCKWNEbeaDR1MjIqp7l9B7cShUKVEizMv24yC 3CYdWKnmZMJAQ//HW3AY88gUlB6jpdM2wKgKCU4vw5KMyTbcLEixt+lpInj3mSFGQa8i aeaINTDmnlM5E0jr5zPHjDQuTjEj2irF1CmySGa69+usrHGz78ov3/WaxgNslZ0iC3bc u5GrKMlUYPzl/d7u5rniz+bG1dCLhyzq4NO+Q7VQ22EkJhQE5JRKyhR8EPo0YGE35PTB 6aGA== X-Gm-Message-State: AKaTC01F6eGZ7zaCs1sASAUGeRzh9g3bnPs1mmDYHpOcoNP6zHZKfKheREG5s81TDMPPHK6M X-Received: by 10.99.246.83 with SMTP id u19mr3146854pgj.165.1479888565745; Wed, 23 Nov 2016 00:09:25 -0800 (PST) Received: from localhost.localdomain ([104.237.91.22]) by smtp.gmail.com with ESMTPSA id s8sm50422542pfj.45.2016.11.23.00.09.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Nov 2016 00:09:24 -0800 (PST) From: Zhangfei Gao To: Philipp Zabel Subject: [RFC V2: PATCH 2/2] reset: hisilicon: add reset-hi3660 Date: Wed, 23 Nov 2016 16:07:56 +0800 Message-Id: <1479888476-13138-3-git-send-email-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479888476-13138-1-git-send-email-zhangfei.gao@linaro.org> References: ,> <1479888476-13138-1-git-send-email-zhangfei.gao@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161123_000946_973989_FBA7F98A X-CRM114-Status: GOOD ( 19.52 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -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_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Zhangfei Gao MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Add hi3660 reset driver Reset offset & bits should be listed in dts Like: iomcu_rst: iomcu_rst_controller { compatible = "hisilicon,hi3660-reset"; #reset-cells = <1>; hisi,rst-syscon = <&iomcu>; hisi,reset-bits = <0x20 0x8 /* 0: i2c0 */ 0x20 0x10 /* 1: i2c1 */ 0x20 0x20 /* 2: i2c2 */ 0x20 0x8000000>; /* 3: i2c6 */ }; Signed-off-by: Zhangfei Gao --- drivers/reset/hisilicon/Kconfig | 7 ++ drivers/reset/hisilicon/Makefile | 1 + drivers/reset/hisilicon/reset-hi3660.c | 144 +++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 drivers/reset/hisilicon/reset-hi3660.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/hisilicon/Kconfig b/drivers/reset/hisilicon/Kconfig index 1ff8b0c..10134dc 100644 --- a/drivers/reset/hisilicon/Kconfig +++ b/drivers/reset/hisilicon/Kconfig @@ -1,3 +1,10 @@ +config COMMON_RESET_HI3660 + tristate "Hi3660 Reset Driver" + depends on ARCH_HISI || COMPILE_TEST + default ARCH_HISI + help + Build the Hisilicon Hi3660 reset driver. + config COMMON_RESET_HI6220 tristate "Hi6220 Reset Driver" depends on ARCH_HISI || COMPILE_TEST diff --git a/drivers/reset/hisilicon/Makefile b/drivers/reset/hisilicon/Makefile index c932f86..ab8a7bf 100644 --- a/drivers/reset/hisilicon/Makefile +++ b/drivers/reset/hisilicon/Makefile @@ -1 +1,2 @@ obj-$(CONFIG_COMMON_RESET_HI6220) += hi6220_reset.o +obj-$(CONFIG_COMMON_RESET_HI3660) += reset-hi3660.o diff --git a/drivers/reset/hisilicon/reset-hi3660.c b/drivers/reset/hisilicon/reset-hi3660.c new file mode 100644 index 0000000..3307252 --- /dev/null +++ b/drivers/reset/hisilicon/reset-hi3660.c @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2016-2017 Linaro Ltd. + * Copyright (c) 2016-2017 HiSilicon Technologies Co., Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ +#include +#include +#include +#include +#include +#include +#include + +struct hi3660_reset_data { + unsigned int off; + unsigned int bits; +}; + +struct hi3660_reset_controller { + struct reset_controller_dev rst; + struct regmap *map; + const struct hi3660_reset_data *datas; +}; + +#define to_hi3660_reset_controller(_rst) \ + container_of(_rst, struct hi3660_reset_controller, rst) + +static int hi3660_reset_program_hw(struct reset_controller_dev *rcdev, + unsigned long idx, bool assert) +{ + struct hi3660_reset_controller *rc = to_hi3660_reset_controller(rcdev); + const struct hi3660_reset_data *d; + + if (idx >= rcdev->nr_resets) + return -EINVAL; + + d = &rc->datas[idx]; + + if (assert) + return regmap_write(rc->map, d->off, d->bits); + else + return regmap_write(rc->map, d->off + 4, d->bits); +} + +static int hi3660_reset_assert(struct reset_controller_dev *rcdev, + unsigned long idx) +{ + return hi3660_reset_program_hw(rcdev, idx, true); +} + +static int hi3660_reset_deassert(struct reset_controller_dev *rcdev, + unsigned long idx) +{ + return hi3660_reset_program_hw(rcdev, idx, false); +} + +static int hi3660_reset_dev(struct reset_controller_dev *rcdev, + unsigned long idx) +{ + int err; + + err = hi3660_reset_assert(rcdev, idx); + if (err) + return err; + + return hi3660_reset_deassert(rcdev, idx); +} + +static struct reset_control_ops hi3660_reset_ops = { + .reset = hi3660_reset_dev, + .assert = hi3660_reset_assert, + .deassert = hi3660_reset_deassert, +}; + +static int hi3660_reset_probe(struct platform_device *pdev) +{ + struct hi3660_reset_controller *rc; + struct device_node *np = pdev->dev.of_node; + struct device *dev = &pdev->dev; + struct hi3660_reset_data *datas; + const __be32 *list; + int size, nr, i; + + rc = devm_kzalloc(dev, sizeof(*rc), GFP_KERNEL); + if (!rc) + return -ENOMEM; + + rc->map = syscon_regmap_lookup_by_phandle(np, "hisi,rst-syscon"); + if (IS_ERR(rc->map)) { + dev_err(dev, "failed to get hi3660,rst-syscon\n"); + return PTR_ERR(rc->map); + } + + list = of_get_property(np, "hisi,reset-bits", &size); + if (!list || (size / sizeof(*list)) % 2 != 0) { + dev_err(dev, "invalid DT reset description\n"); + return -EINVAL; + } + + nr = (size / sizeof(*list)) / 2; + datas = devm_kzalloc(dev, nr * sizeof(*datas), GFP_KERNEL); + if (!datas) + return -ENOMEM; + + for (i = 0; i < nr; i++) { + datas[i].off = be32_to_cpup(list++); + datas[i].bits = be32_to_cpup(list++); + } + + rc->rst.ops = &hi3660_reset_ops, + rc->rst.of_node = np; + rc->rst.nr_resets = nr; + rc->datas = datas; + + return reset_controller_register(&rc->rst); +} + +static const struct of_device_id hi3660_reset_match[] = { + { .compatible = "hisilicon,hi3660-reset", }, + {}, +}; +MODULE_DEVICE_TABLE(of, hi3660_reset_match); + +static struct platform_driver hi3660_reset_driver = { + .probe = hi3660_reset_probe, + .driver = { + .name = "hi3660-reset", + .of_match_table = hi3660_reset_match, + }, +}; + +static int __init hi3660_reset_init(void) +{ + return platform_driver_register(&hi3660_reset_driver); +} +arch_initcall(hi3660_reset_init); + +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:hi3660-reset"); +MODULE_DESCRIPTION("HiSilicon Hi3660 Reset Driver");