Skip to content

Commit 6c4bc7a

Browse files
committed
reset: starfive: Add JH7100 audio reset driver
The audio resets are almost identical to the system resets, there are just fewer of them. So factor out and export generic probe function, so so most of the reset controller implementation can be shared. Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
1 parent c09463c commit 6c4bc7a

6 files changed

Lines changed: 112 additions & 15 deletions

File tree

MAINTAINERS

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17882,12 +17882,12 @@ F: Documentation/devicetree/bindings/pinctrl/starfive,jh7100-pinctrl.yaml
1788217882
F: drivers/pinctrl/pinctrl-starfive.c
1788317883
F: include/dt-bindings/pinctrl/pinctrl-starfive.h
1788417884

17885-
STARFIVE JH7100 RESET CONTROLLER DRIVER
17885+
STARFIVE JH7100 RESET CONTROLLER DRIVERS
1788617886
M: Emil Renner Berthing <kernel@esmil.dk>
1788717887
S: Maintained
17888-
F: Documentation/devicetree/bindings/reset/starfive,jh7100-reset.yaml
17889-
F: drivers/reset/starfive/reset-starfive-jh7100.c
17890-
F: include/dt-bindings/reset/starfive-jh7100.h
17888+
F: Documentation/devicetree/bindings/reset/starfive,jh7100-*.yaml
17889+
F: drivers/reset/starfive/reset-starfive-jh7100*
17890+
F: include/dt-bindings/reset/starfive-jh7100*.h
1789117891

1789217892
STATIC BRANCH/CALL
1789317893
M: Peter Zijlstra <peterz@infradead.org>

drivers/reset/starfive/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ config RESET_STARFIVE_JH7100
66
default SOC_STARFIVE
77
help
88
This enables the reset controller driver for the StarFive JH7100 SoC.
9+
10+
config RESET_STARFIVE_JH7100_AUDIO
11+
tristate "StarFive JH7100 Audio Reset Driver"
12+
depends on RESET_STARFIVE_JH7100
13+
default SOC_STARFIVE
14+
help
15+
This enables the audio reset driver for the StarFive JH7100 SoC.

drivers/reset/starfive/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# SPDX-License-Identifier: GPL-2.0
22
obj-$(CONFIG_RESET_STARFIVE_JH7100) += reset-starfive-jh7100.o
3+
obj-$(CONFIG_RESET_STARFIVE_JH7100_AUDIO) += reset-starfive-jh7100-audio.o
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Audio reset driver for the StarFive JH7100 SoC
4+
*
5+
* Copyright (C) 2021 Emil Renner Berthing <kernel@esmil.dk>
6+
*/
7+
8+
#include <linux/mod_devicetable.h>
9+
#include <linux/module.h>
10+
#include <linux/platform_device.h>
11+
#include <linux/reset-controller.h>
12+
13+
#include <dt-bindings/reset/starfive-jh7100-audio.h>
14+
15+
#include "reset-starfive-jh7100.h"
16+
17+
/* register offsets */
18+
#define JH7100_AUDRST_ASSERT0 0x00
19+
#define JH7100_AUDRST_STATUS0 0x04
20+
21+
/*
22+
* Writing a 1 to the n'th bit of the ASSERT register asserts
23+
* line n, and writing a 0 deasserts the same line.
24+
* Most reset lines have their status inverted so a 0 bit in the STATUS
25+
* register means the line is asserted and a 1 means it's deasserted. A few
26+
* lines don't though, so store the expected value of the status registers when
27+
* all lines are asserted.
28+
*/
29+
static const u32 jh7100_audrst_asserted[1] = {
30+
BIT(JH7100_AUDRST_USB_AXI) |
31+
BIT(JH7100_AUDRST_USB_PWRUP_RST_N) |
32+
BIT(JH7100_AUDRST_USB_PONRST)
33+
};
34+
35+
static int jh7100_audrst_probe(struct platform_device *pdev)
36+
{
37+
return reset_starfive_jh7100_generic_probe(pdev, jh7100_audrst_asserted,
38+
JH7100_AUDRST_STATUS0, JH7100_AUDRSTN_END);
39+
}
40+
41+
static const struct of_device_id jh7100_audrst_dt_ids[] = {
42+
{ .compatible = "starfive,jh7100-audrst" },
43+
{ /* sentinel */ }
44+
};
45+
MODULE_DEVICE_TABLE(of, jh7100_audrst_dt_ids);
46+
47+
static struct platform_driver jh7100_audrst_driver = {
48+
.probe = jh7100_audrst_probe,
49+
.driver = {
50+
.name = "jh7100-reset-audio",
51+
.of_match_table = jh7100_audrst_dt_ids,
52+
},
53+
};
54+
module_platform_driver(jh7100_audrst_driver);
55+
56+
MODULE_AUTHOR("Emil Renner Berthing");
57+
MODULE_DESCRIPTION("StarFive JH7100 audio reset driver");
58+
MODULE_LICENSE("GPL");

drivers/reset/starfive/reset-starfive-jh7100.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include <dt-bindings/reset/starfive-jh7100.h>
1717

18+
#include "reset-starfive-jh7100.h"
19+
1820
/* register offsets */
1921
#define JH7100_RESET_ASSERT0 0x00
2022
#define JH7100_RESET_ASSERT1 0x04
@@ -51,7 +53,9 @@ struct jh7100_reset {
5153
struct reset_controller_dev rcdev;
5254
/* protect registers against concurrent read-modify-write */
5355
spinlock_t lock;
54-
void __iomem *base;
56+
void __iomem *assert;
57+
void __iomem *status;
58+
const u32 *asserted;
5559
};
5660

5761
static inline struct jh7100_reset *
@@ -66,9 +70,9 @@ static int jh7100_reset_update(struct reset_controller_dev *rcdev,
6670
struct jh7100_reset *data = jh7100_reset_from(rcdev);
6771
unsigned long offset = id / 32;
6872
u32 mask = BIT(id % 32);
69-
void __iomem *reg_assert = data->base + JH7100_RESET_ASSERT0 + offset * sizeof(u32);
70-
void __iomem *reg_status = data->base + JH7100_RESET_STATUS0 + offset * sizeof(u32);
71-
u32 done = jh7100_reset_asserted[offset] & mask;
73+
void __iomem *reg_assert = data->assert + offset * sizeof(u32);
74+
void __iomem *reg_status = data->status + offset * sizeof(u32);
75+
u32 done = data->asserted[offset] & mask;
7276
u32 value;
7377
unsigned long flags;
7478
int ret;
@@ -122,10 +126,10 @@ static int jh7100_reset_status(struct reset_controller_dev *rcdev,
122126
struct jh7100_reset *data = jh7100_reset_from(rcdev);
123127
unsigned long offset = id / 32;
124128
u32 mask = BIT(id % 32);
125-
void __iomem *reg_status = data->base + JH7100_RESET_STATUS0 + offset * sizeof(u32);
129+
void __iomem *reg_status = data->status + offset * sizeof(u32);
126130
u32 value = readl(reg_status);
127131

128-
return !((value ^ jh7100_reset_asserted[offset]) & mask);
132+
return !((value ^ data->asserted[offset]) & mask);
129133
}
130134

131135
static const struct reset_control_ops jh7100_reset_ops = {
@@ -135,27 +139,38 @@ static const struct reset_control_ops jh7100_reset_ops = {
135139
.status = jh7100_reset_status,
136140
};
137141

138-
static int __init jh7100_reset_probe(struct platform_device *pdev)
142+
int reset_starfive_jh7100_generic_probe(struct platform_device *pdev, const u32 *asserted,
143+
unsigned int status_offset, unsigned int nr_resets)
139144
{
140145
struct jh7100_reset *data;
141146

142147
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
143148
if (!data)
144149
return -ENOMEM;
145150

146-
data->base = devm_platform_ioremap_resource(pdev, 0);
147-
if (IS_ERR(data->base))
148-
return PTR_ERR(data->base);
151+
data->assert = devm_platform_ioremap_resource(pdev, 0);
152+
if (IS_ERR(data->assert))
153+
return PTR_ERR(data->assert);
149154

150155
data->rcdev.ops = &jh7100_reset_ops;
151156
data->rcdev.owner = THIS_MODULE;
152-
data->rcdev.nr_resets = JH7100_RSTN_END;
157+
data->rcdev.nr_resets = nr_resets;
153158
data->rcdev.dev = &pdev->dev;
154159
data->rcdev.of_node = pdev->dev.of_node;
160+
155161
spin_lock_init(&data->lock);
162+
data->status = data->assert + status_offset;
163+
data->asserted = asserted;
156164

157165
return devm_reset_controller_register(&pdev->dev, &data->rcdev);
158166
}
167+
EXPORT_SYMBOL_GPL(reset_starfive_jh7100_generic_probe);
168+
169+
static int __init jh7100_reset_probe(struct platform_device *pdev)
170+
{
171+
return reset_starfive_jh7100_generic_probe(pdev, jh7100_reset_asserted,
172+
JH7100_RESET_STATUS0, JH7100_RSTN_END);
173+
}
159174

160175
static const struct of_device_id jh7100_reset_dt_ids[] = {
161176
{ .compatible = "starfive,jh7100-reset" },
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright (C) 2021 Emil Renner Berthing <kernel@esmil.dk>
4+
*/
5+
6+
#ifndef _RESET_STARFIVE_JH7100_H_
7+
#define _RESET_STARFIVE_JH7100_H_
8+
9+
#include <linux/platform_device.h>
10+
11+
int reset_starfive_jh7100_generic_probe(struct platform_device *pdev,
12+
const u32 *asserted,
13+
unsigned int status_offset,
14+
unsigned int nr_resets);
15+
16+
#endif

0 commit comments

Comments
 (0)