2 * Amlogic Meson Reset Controller driver
4 * This file is provided under a dual BSD/GPLv2 license. When using or
5 * redistributing this file, you may do so under either license.
9 * Copyright (c) 2016 BayLibre, SAS.
10 * Author: Neil Armstrong <narmstrong@baylibre.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 * The full GNU General Public License is included in this distribution
24 * in the file called COPYING.
28 * Copyright (c) 2016 BayLibre, SAS.
29 * Author: Neil Armstrong <narmstrong@baylibre.com>
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
35 * * Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * * Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in
39 * the documentation and/or other materials provided with the
41 * * Neither the name of Intel Corporation nor the names of its
42 * contributors may be used to endorse or promote products derived
43 * from this software without specific prior written permission.
45 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
46 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
47 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
48 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
49 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 #include <linux/err.h>
58 #include <linux/init.h>
61 #include <linux/platform_device.h>
62 #include <linux/reset-controller.h>
63 #include <linux/slab.h>
64 #include <linux/types.h>
67 #define BITS_PER_REG 32
70 void __iomem
*reg_base
;
71 struct reset_controller_dev rcdev
;
74 static int meson_reset_reset(struct reset_controller_dev
*rcdev
,
77 struct meson_reset
*data
=
78 container_of(rcdev
, struct meson_reset
, rcdev
);
79 unsigned int bank
= id
/ BITS_PER_REG
;
80 unsigned int offset
= id
% BITS_PER_REG
;
81 void __iomem
*reg_addr
= data
->reg_base
+ (bank
<< 2);
83 if (bank
>= REG_COUNT
)
86 writel(BIT(offset
), reg_addr
);
91 static const struct reset_control_ops meson_reset_ops
= {
92 .reset
= meson_reset_reset
,
95 static const struct of_device_id meson_reset_dt_ids
[] = {
96 { .compatible
= "amlogic,meson8b-reset", },
97 { .compatible
= "amlogic,meson-gxbb-reset", },
101 static int meson_reset_probe(struct platform_device
*pdev
)
103 struct meson_reset
*data
;
104 struct resource
*res
;
106 data
= devm_kzalloc(&pdev
->dev
, sizeof(*data
), GFP_KERNEL
);
110 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
111 data
->reg_base
= devm_ioremap_resource(&pdev
->dev
, res
);
112 if (IS_ERR(data
->reg_base
))
113 return PTR_ERR(data
->reg_base
);
115 platform_set_drvdata(pdev
, data
);
117 data
->rcdev
.owner
= THIS_MODULE
;
118 data
->rcdev
.nr_resets
= REG_COUNT
* BITS_PER_REG
;
119 data
->rcdev
.ops
= &meson_reset_ops
;
120 data
->rcdev
.of_node
= pdev
->dev
.of_node
;
122 return devm_reset_controller_register(&pdev
->dev
, &data
->rcdev
);
125 static struct platform_driver meson_reset_driver
= {
126 .probe
= meson_reset_probe
,
128 .name
= "meson_reset",
129 .of_match_table
= meson_reset_dt_ids
,
132 builtin_platform_driver(meson_reset_driver
);