From patchwork Tue Nov 22 07:49:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangfei Gao X-Patchwork-Id: 83343 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp1967981qge; Mon, 21 Nov 2016 23:50:16 -0800 (PST) X-Received: by 10.98.72.129 with SMTP id q1mr23704557pfi.169.1479801016694; Mon, 21 Nov 2016 23:50:16 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q187si15139579pfb.256.2016.11.21.23.50.16; Mon, 21 Nov 2016 23:50:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; 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 devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753247AbcKVHuP (ORCPT + 7 others); Tue, 22 Nov 2016 02:50:15 -0500 Received: from mail-pg0-f46.google.com ([74.125.83.46]:33906 "EHLO mail-pg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752869AbcKVHuO (ORCPT ); Tue, 22 Nov 2016 02:50:14 -0500 Received: by mail-pg0-f46.google.com with SMTP id x23so5057017pgx.1 for ; Mon, 21 Nov 2016 23:50:14 -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=izbH9newMQXq2xGpbsTlWcMcoqSgb4uERvj26YEuSMk=; b=G4Ucy/Wbl3pr4PpFDtBcF92d4Rw0jVoXfoyUdPcNm99ReEz/blqDRwCETW1mbe1GBS aFQdZVvUsOWKW/Kjx/46Hp/hT5TMynZtG1vvtxi2Z3gWmC7ADALVsuGjq2/IgVqIxo8K NaRJujDRB3zuFaHACAIGV6k9KhOqol2CHaL8E= 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=izbH9newMQXq2xGpbsTlWcMcoqSgb4uERvj26YEuSMk=; b=WFKwOWuKSpAqH2k2/w6lhZB2z5zF9yJEZZB47Tinofvs4Uq5cS7dPe3ymC4Bpj7sUh N3nNkNwD8fO2Dl+o2YW+J2+uIL6i4xb1eGleo0FDZx2oLg6geDcOm8FSlOplMNdOgDB+ p6/7h+GKfT2OqS0kJnysSm+vrfJ3Z8Wg03T1mfBfAvJHVN7w3Rb5soi9NciXyv05+SVL BVbp8x5lDtmNRpa8hGzWT42lTc0JPX8DFn/U/bW+s0JUxpgFyoREQ5e/G5Mcwt45uqAJ 684MGGvm7aHEA24lJXRxKMyeTGBvqSwtS6rilvHcYRtIOW+RliqP4OmQBbstaTIfeojd kjUQ== X-Gm-Message-State: AKaTC03jo8KtVmwsOIAec/tSdbp8nKbYSF/p6LB/4d+vEPeToQBjvW5qkLvZHm/wY97+XCGu X-Received: by 10.98.59.154 with SMTP id w26mr23691747pfj.112.1479801013828; Mon, 21 Nov 2016 23:50:13 -0800 (PST) Received: from localhost.localdomain ([104.237.91.214]) by smtp.gmail.com with ESMTPSA id d1sm42635008pfb.76.2016.11.21.23.50.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Nov 2016 23:50:13 -0800 (PST) From: Zhangfei Gao To: Philipp Zabel , Rob Herring , haojian.zhuang@linaro.org, xuwei5@hisilicon.com, Chen Feng , Xinliang Liu , Xia Qing , Jiancheng Xue Cc: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Zhangfei Gao Subject: [PATCH 1/6] reset: hisilicon: add reset core Date: Tue, 22 Nov 2016 15:49:16 +0800 Message-Id: <1479800961-6249-2-git-send-email-zhangfei.gao@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1479800961-6249-1-git-send-email-zhangfei.gao@linaro.org> References: <1479800961-6249-1-git-send-email-zhangfei.gao@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org reset.c will be shared by hisilicon chips like hi3660 and hi6220 Signed-off-by: Zhangfei Gao --- drivers/reset/Makefile | 2 +- drivers/reset/hisilicon/Makefile | 1 + drivers/reset/hisilicon/reset.c | 108 +++++++++++++++++++++++++++++++++++++++ drivers/reset/hisilicon/reset.h | 37 ++++++++++++++ 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 drivers/reset/hisilicon/reset.c create mode 100644 drivers/reset/hisilicon/reset.h -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/reset/Makefile b/drivers/reset/Makefile index bbe7026..7e3dc4e 100644 --- a/drivers/reset/Makefile +++ b/drivers/reset/Makefile @@ -1,8 +1,8 @@ obj-y += core.o -obj-y += hisilicon/ obj-$(CONFIG_ARCH_STI) += sti/ obj-$(CONFIG_RESET_ATH79) += reset-ath79.o obj-$(CONFIG_RESET_BERLIN) += reset-berlin.o +obj-$(CONFIG_ARCH_HISI) += hisilicon/ obj-$(CONFIG_RESET_LPC18XX) += reset-lpc18xx.o obj-$(CONFIG_RESET_MESON) += reset-meson.o obj-$(CONFIG_RESET_OXNAS) += reset-oxnas.o diff --git a/drivers/reset/hisilicon/Makefile b/drivers/reset/hisilicon/Makefile index c932f86..df511f5 100644 --- a/drivers/reset/hisilicon/Makefile +++ b/drivers/reset/hisilicon/Makefile @@ -1 +1,2 @@ +obj-y += reset.o obj-$(CONFIG_COMMON_RESET_HI6220) += hi6220_reset.o diff --git a/drivers/reset/hisilicon/reset.c b/drivers/reset/hisilicon/reset.c new file mode 100644 index 0000000..c4971c9 --- /dev/null +++ b/drivers/reset/hisilicon/reset.c @@ -0,0 +1,108 @@ +/* + * 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 + +#include "reset.h" + +struct hisi_reset_controller { + struct reset_controller_dev rst; + const struct hisi_reset_channel_data *channels; + struct regmap *map; +}; + +#define to_hisi_reset_controller(_rst) \ + container_of(_rst, struct hisi_reset_controller, rst) + +static int hisi_reset_program_hw(struct reset_controller_dev *rcdev, + unsigned long idx, bool assert) +{ + struct hisi_reset_controller *rc = to_hisi_reset_controller(rcdev); + const struct hisi_reset_channel_data *ch; + + if (idx >= rcdev->nr_resets) + return -EINVAL; + + ch = &rc->channels[idx]; + + if (assert) + return regmap_write(rc->map, ch->enable.reg, + GENMASK(ch->enable.msb, ch->enable.lsb)); + else + return regmap_write(rc->map, ch->disable.reg, + GENMASK(ch->disable.msb, ch->disable.lsb)); +} + +static int hisi_reset_assert(struct reset_controller_dev *rcdev, + unsigned long idx) +{ + return hisi_reset_program_hw(rcdev, idx, true); +} + +static int hisi_reset_deassert(struct reset_controller_dev *rcdev, + unsigned long idx) +{ + return hisi_reset_program_hw(rcdev, idx, false); +} + +static int hisi_reset_dev(struct reset_controller_dev *rcdev, + unsigned long idx) +{ + int err; + + err = hisi_reset_assert(rcdev, idx); + if (err) + return err; + + return hisi_reset_deassert(rcdev, idx); +} + +static struct reset_control_ops hisi_reset_ops = { + .reset = hisi_reset_dev, + .assert = hisi_reset_assert, + .deassert = hisi_reset_deassert, +}; + +int hisi_reset_probe(struct platform_device *pdev) +{ + struct hisi_reset_controller *rc; + struct device_node *np = pdev->dev.of_node; + struct hisi_reset_controller_data *d; + struct device *dev = &pdev->dev; + const struct of_device_id *match; + + match = of_match_device(dev->driver->of_match_table, dev); + if (!match || !match->data) + return -EINVAL; + + d = (struct hisi_reset_controller_data *)match->data; + 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 hisi,rst-syscon\n"); + return PTR_ERR(rc->map); + } + + rc->rst.ops = &hisi_reset_ops, + rc->rst.of_node = np; + rc->rst.nr_resets = d->nr_channels; + rc->channels = d->channels; + + return reset_controller_register(&rc->rst); +} +EXPORT_SYMBOL_GPL(hisi_reset_probe); diff --git a/drivers/reset/hisilicon/reset.h b/drivers/reset/hisilicon/reset.h new file mode 100644 index 0000000..77259ee --- /dev/null +++ b/drivers/reset/hisilicon/reset.h @@ -0,0 +1,37 @@ +/* + * 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. + */ + +#ifndef __HISILICON_RESET_H +#define __HISILICON_RESET_H + +#include +#include +#include + +/* reset separated register offset is 0x4 */ +#define HISI_RST_SEP(off, bit) \ + { .enable = REG_FIELD(off, bit, bit), \ + .disable = REG_FIELD(off + 0x4, bit, bit), \ + .status = REG_FIELD(off + 0x8, bit, bit), } + +struct hisi_reset_channel_data { + struct reg_field enable; + struct reg_field disable; + struct reg_field status; +}; + +struct hisi_reset_controller_data { + int nr_channels; + const struct hisi_reset_channel_data *channels; +}; + +int hisi_reset_probe(struct platform_device *pdev); + +#endif /* __HISILICON_RESET_H */