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: 9440575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6098D60237 for ; Tue, 22 Nov 2016 07:52:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5505C2844E for ; Tue, 22 Nov 2016 07:52:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 49E6928479; Tue, 22 Nov 2016 07:52:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4A9692844E for ; Tue, 22 Nov 2016 07:52:15 +0000 (UTC) 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 1c95qr-0006xZ-FQ; Tue, 22 Nov 2016 07:50:49 +0000 Received: from mail-pg0-x235.google.com ([2607:f8b0:400e:c05::235]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c95qc-0005wD-Qf for linux-arm-kernel@lists.infradead.org; Tue, 22 Nov 2016 07:50:36 +0000 Received: by mail-pg0-x235.google.com with SMTP id 3so5064506pgd.0 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=alScC4urr7avhuCu3w8AOGJWc5bzLz49BJijwMOcTT3OjWZU8JTCrqAyrX5zLeslrh r6K7oRy2dJ9mg18GiMfxHpDGxmQfHgs0ezwYWMDqipFpT2eu2PYzjiRC9Zo2uqP3kTYc jmlFd+lZTj6zOKh9MebJ/Tvt7LBBXEK+pRNg9KSz84iMsBPFwBNtPaoa3yj2nc5RUo4H lZdnvg+4h7hEytksTCACcjixh7Me1HLvBAy+uaGX38A8nlvVquz6Qig/gxynijLuABv7 A6WKuf0RMOtbjHLjRbCHyc2K3aF3CHM8vu/5ivdEvOZr8N12RgVpC/wclK7suGtWqSa5 LRUw== X-Gm-Message-State: AKaTC02D3SGSc7aODCKHo6HIedVdFAZ7ZL95Z5ghnf1F7F2QNlWbLR93xBwBXT5E1hzV+LjP 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161121_235034_995327_56CEAAB7 X-CRM114-Status: GOOD ( 17.26 ) 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+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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 */