blob: d5e5229308f2291136ebe7c6061346507a733907 [file] [log] [blame]
Chen Fengf59d23c2015-11-20 10:10:05 +08001/*
2 * Hisilicon Hi6220 reset controller driver
3 *
Chen Feng8768a262016-06-20 11:50:06 +08004 * Copyright (c) 2016 Linaro Limited.
5 * Copyright (c) 2015-2016 Hisilicon Limited.
Chen Fengf59d23c2015-11-20 10:10:05 +08006 *
7 * Author: Feng Chen <puck.chen@hisilicon.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
14#include <linux/io.h>
15#include <linux/init.h>
Arnd Bergmann70b35902015-12-12 08:53:21 +010016#include <linux/module.h>
Chen Fengf59d23c2015-11-20 10:10:05 +080017#include <linux/bitops.h>
18#include <linux/of.h>
Chen Feng8768a262016-06-20 11:50:06 +080019#include <linux/of_device.h>
20#include <linux/regmap.h>
21#include <linux/mfd/syscon.h>
Chen Fengf59d23c2015-11-20 10:10:05 +080022#include <linux/reset-controller.h>
23#include <linux/reset.h>
24#include <linux/platform_device.h>
25
Chen Feng8768a262016-06-20 11:50:06 +080026#define PERIPH_ASSERT_OFFSET 0x300
27#define PERIPH_DEASSERT_OFFSET 0x304
28#define PERIPH_MAX_INDEX 0x509
Chen Fengf59d23c2015-11-20 10:10:05 +080029
Xinliang Liuab52b592016-06-20 11:50:07 +080030#define SC_MEDIA_RSTEN 0x052C
31#define SC_MEDIA_RSTDIS 0x0530
32#define MEDIA_MAX_INDEX 8
33
Chen Fengf59d23c2015-11-20 10:10:05 +080034#define to_reset_data(x) container_of(x, struct hi6220_reset_data, rc_dev)
35
Xinliang Liuab52b592016-06-20 11:50:07 +080036enum hi6220_reset_ctrl_type {
37 PERIPHERAL,
38 MEDIA,
39};
40
Chen Fengf59d23c2015-11-20 10:10:05 +080041struct hi6220_reset_data {
Chen Feng8768a262016-06-20 11:50:06 +080042 struct reset_controller_dev rc_dev;
43 struct regmap *regmap;
Chen Fengf59d23c2015-11-20 10:10:05 +080044};
45
Chen Feng8768a262016-06-20 11:50:06 +080046static int hi6220_peripheral_assert(struct reset_controller_dev *rc_dev,
47 unsigned long idx)
Chen Fengf59d23c2015-11-20 10:10:05 +080048{
49 struct hi6220_reset_data *data = to_reset_data(rc_dev);
Chen Feng8768a262016-06-20 11:50:06 +080050 struct regmap *regmap = data->regmap;
51 u32 bank = idx >> 8;
52 u32 offset = idx & 0xff;
53 u32 reg = PERIPH_ASSERT_OFFSET + bank * 0x10;
Chen Fengf59d23c2015-11-20 10:10:05 +080054
Chen Feng8768a262016-06-20 11:50:06 +080055 return regmap_write(regmap, reg, BIT(offset));
Chen Fengf59d23c2015-11-20 10:10:05 +080056}
57
Chen Feng8768a262016-06-20 11:50:06 +080058static int hi6220_peripheral_deassert(struct reset_controller_dev *rc_dev,
59 unsigned long idx)
Chen Fengf59d23c2015-11-20 10:10:05 +080060{
61 struct hi6220_reset_data *data = to_reset_data(rc_dev);
Chen Feng8768a262016-06-20 11:50:06 +080062 struct regmap *regmap = data->regmap;
63 u32 bank = idx >> 8;
64 u32 offset = idx & 0xff;
65 u32 reg = PERIPH_DEASSERT_OFFSET + bank * 0x10;
Chen Fengf59d23c2015-11-20 10:10:05 +080066
Chen Feng8768a262016-06-20 11:50:06 +080067 return regmap_write(regmap, reg, BIT(offset));
Chen Fengf59d23c2015-11-20 10:10:05 +080068}
69
Chen Feng8768a262016-06-20 11:50:06 +080070static const struct reset_control_ops hi6220_peripheral_reset_ops = {
71 .assert = hi6220_peripheral_assert,
72 .deassert = hi6220_peripheral_deassert,
Chen Fengf59d23c2015-11-20 10:10:05 +080073};
74
Xinliang Liuab52b592016-06-20 11:50:07 +080075static int hi6220_media_assert(struct reset_controller_dev *rc_dev,
76 unsigned long idx)
77{
78 struct hi6220_reset_data *data = to_reset_data(rc_dev);
79 struct regmap *regmap = data->regmap;
80
81 return regmap_write(regmap, SC_MEDIA_RSTEN, BIT(idx));
82}
83
84static int hi6220_media_deassert(struct reset_controller_dev *rc_dev,
85 unsigned long idx)
86{
87 struct hi6220_reset_data *data = to_reset_data(rc_dev);
88 struct regmap *regmap = data->regmap;
89
90 return regmap_write(regmap, SC_MEDIA_RSTDIS, BIT(idx));
91}
92
93static const struct reset_control_ops hi6220_media_reset_ops = {
94 .assert = hi6220_media_assert,
95 .deassert = hi6220_media_deassert,
96};
97
Chen Fengf59d23c2015-11-20 10:10:05 +080098static int hi6220_reset_probe(struct platform_device *pdev)
99{
Chen Feng8768a262016-06-20 11:50:06 +0800100 struct device_node *np = pdev->dev.of_node;
101 struct device *dev = &pdev->dev;
Xinliang Liuab52b592016-06-20 11:50:07 +0800102 enum hi6220_reset_ctrl_type type;
Chen Fengf59d23c2015-11-20 10:10:05 +0800103 struct hi6220_reset_data *data;
Chen Feng8768a262016-06-20 11:50:06 +0800104 struct regmap *regmap;
Chen Fengf59d23c2015-11-20 10:10:05 +0800105
Chen Feng8768a262016-06-20 11:50:06 +0800106 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
Chen Fengf59d23c2015-11-20 10:10:05 +0800107 if (!data)
108 return -ENOMEM;
109
Xinliang Liuab52b592016-06-20 11:50:07 +0800110 type = (enum hi6220_reset_ctrl_type)of_device_get_match_data(dev);
111
Chen Feng8768a262016-06-20 11:50:06 +0800112 regmap = syscon_node_to_regmap(np);
113 if (IS_ERR(regmap)) {
114 dev_err(dev, "failed to get reset controller regmap\n");
115 return PTR_ERR(regmap);
116 }
Chen Fengf59d23c2015-11-20 10:10:05 +0800117
Chen Feng8768a262016-06-20 11:50:06 +0800118 data->regmap = regmap;
119 data->rc_dev.of_node = np;
Xinliang Liuab52b592016-06-20 11:50:07 +0800120 if (type == MEDIA) {
121 data->rc_dev.ops = &hi6220_media_reset_ops;
122 data->rc_dev.nr_resets = MEDIA_MAX_INDEX;
123 } else {
124 data->rc_dev.ops = &hi6220_peripheral_reset_ops;
125 data->rc_dev.nr_resets = PERIPH_MAX_INDEX;
126 }
Chen Fengf59d23c2015-11-20 10:10:05 +0800127
Masahiro Yamadac41ef912016-01-24 01:19:57 +0900128 return reset_controller_register(&data->rc_dev);
Chen Fengf59d23c2015-11-20 10:10:05 +0800129}
130
131static const struct of_device_id hi6220_reset_match[] = {
Chen Feng8768a262016-06-20 11:50:06 +0800132 {
133 .compatible = "hisilicon,hi6220-sysctrl",
Xinliang Liuab52b592016-06-20 11:50:07 +0800134 .data = (void *)PERIPHERAL,
135 },
136 {
137 .compatible = "hisilicon,hi6220-mediactrl",
138 .data = (void *)MEDIA,
Chen Feng8768a262016-06-20 11:50:06 +0800139 },
140 { /* sentinel */ },
Chen Fengf59d23c2015-11-20 10:10:05 +0800141};
Chen Feng8768a262016-06-20 11:50:06 +0800142MODULE_DEVICE_TABLE(of, hi6220_reset_match);
Chen Fengf59d23c2015-11-20 10:10:05 +0800143
144static struct platform_driver hi6220_reset_driver = {
145 .probe = hi6220_reset_probe,
146 .driver = {
147 .name = "reset-hi6220",
148 .of_match_table = hi6220_reset_match,
149 },
150};
151
152static int __init hi6220_reset_init(void)
153{
154 return platform_driver_register(&hi6220_reset_driver);
155}
156
157postcore_initcall(hi6220_reset_init);
Jeremy Linton4497a222017-04-08 02:18:40 -0500158
159MODULE_LICENSE("GPL v2");