Skip to content

Commit 098c290

Browse files
ConchuODbebarino
authored andcommitted
clock, reset: microchip: move all mpfs reset code to the reset subsystem
Stephen and Philipp, while reviewing patches, said that all of the aux device creation and the register read/write code could be moved to the reset subsystem, leaving the clock driver with no implementations of reset_* functions at all. Move them. Suggested-by: Philipp Zabel <p.zabel@pengutronix.de> Suggested-by: Stephen Boyd <sboyd@kernel.org> Signed-off-by: Conor Dooley <conor.dooley@microchip.com> Link: https://lore.kernel.org/r/20240424-strangle-sharpener-34755c5e6e3e@spud Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 4cece76 commit 098c290

File tree

3 files changed

+93
-104
lines changed

3 files changed

+93
-104
lines changed

drivers/clk/microchip/clk-mpfs.c

Lines changed: 2 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
*
55
* Copyright (C) 2020-2022 Microchip Technology Inc. All rights reserved.
66
*/
7-
#include <linux/auxiliary_bus.h>
87
#include <linux/clk-provider.h>
98
#include <linux/io.h>
109
#include <linux/module.h>
1110
#include <linux/platform_device.h>
12-
#include <linux/slab.h>
1311
#include <dt-bindings/clock/microchip,mpfs-clock.h>
1412
#include <soc/microchip/mpfs.h>
1513

@@ -361,93 +359,6 @@ static int mpfs_clk_register_periphs(struct device *dev, struct mpfs_periph_hw_c
361359
return 0;
362360
}
363361

364-
/*
365-
* Peripheral clock resets
366-
*/
367-
368-
#if IS_ENABLED(CONFIG_RESET_CONTROLLER)
369-
370-
u32 mpfs_reset_read(struct device *dev)
371-
{
372-
struct mpfs_clock_data *clock_data = dev_get_drvdata(dev->parent);
373-
374-
return readl_relaxed(clock_data->base + REG_SUBBLK_RESET_CR);
375-
}
376-
EXPORT_SYMBOL_NS_GPL(mpfs_reset_read, MCHP_CLK_MPFS);
377-
378-
void mpfs_reset_write(struct device *dev, u32 val)
379-
{
380-
struct mpfs_clock_data *clock_data = dev_get_drvdata(dev->parent);
381-
382-
writel_relaxed(val, clock_data->base + REG_SUBBLK_RESET_CR);
383-
}
384-
EXPORT_SYMBOL_NS_GPL(mpfs_reset_write, MCHP_CLK_MPFS);
385-
386-
static void mpfs_reset_unregister_adev(void *_adev)
387-
{
388-
struct auxiliary_device *adev = _adev;
389-
390-
auxiliary_device_delete(adev);
391-
auxiliary_device_uninit(adev);
392-
}
393-
394-
static void mpfs_reset_adev_release(struct device *dev)
395-
{
396-
struct auxiliary_device *adev = to_auxiliary_dev(dev);
397-
398-
kfree(adev);
399-
}
400-
401-
static struct auxiliary_device *mpfs_reset_adev_alloc(struct mpfs_clock_data *clk_data)
402-
{
403-
struct auxiliary_device *adev;
404-
int ret;
405-
406-
adev = kzalloc(sizeof(*adev), GFP_KERNEL);
407-
if (!adev)
408-
return ERR_PTR(-ENOMEM);
409-
410-
adev->name = "reset-mpfs";
411-
adev->dev.parent = clk_data->dev;
412-
adev->dev.release = mpfs_reset_adev_release;
413-
adev->id = 666u;
414-
415-
ret = auxiliary_device_init(adev);
416-
if (ret) {
417-
kfree(adev);
418-
return ERR_PTR(ret);
419-
}
420-
421-
return adev;
422-
}
423-
424-
static int mpfs_reset_controller_register(struct mpfs_clock_data *clk_data)
425-
{
426-
struct auxiliary_device *adev;
427-
int ret;
428-
429-
adev = mpfs_reset_adev_alloc(clk_data);
430-
if (IS_ERR(adev))
431-
return PTR_ERR(adev);
432-
433-
ret = auxiliary_device_add(adev);
434-
if (ret) {
435-
auxiliary_device_uninit(adev);
436-
return ret;
437-
}
438-
439-
return devm_add_action_or_reset(clk_data->dev, mpfs_reset_unregister_adev, adev);
440-
}
441-
442-
#else /* !CONFIG_RESET_CONTROLLER */
443-
444-
static int mpfs_reset_controller_register(struct mpfs_clock_data *clk_data)
445-
{
446-
return 0;
447-
}
448-
449-
#endif /* !CONFIG_RESET_CONTROLLER */
450-
451362
static int mpfs_clk_probe(struct platform_device *pdev)
452363
{
453364
struct device *dev = &pdev->dev;
@@ -499,7 +410,7 @@ static int mpfs_clk_probe(struct platform_device *pdev)
499410
if (ret)
500411
return ret;
501412

502-
return mpfs_reset_controller_register(clk_data);
413+
return mpfs_reset_controller_register(dev, clk_data->base + REG_SUBBLK_RESET_CR);
503414
}
504415

505416
static const struct of_device_id mpfs_clk_of_match_table[] = {
@@ -532,3 +443,4 @@ MODULE_DESCRIPTION("Microchip PolarFire SoC Clock Driver");
532443
MODULE_AUTHOR("Padmarao Begari <padmarao.begari@microchip.com>");
533444
MODULE_AUTHOR("Daire McNamara <daire.mcnamara@microchip.com>");
534445
MODULE_AUTHOR("Conor Dooley <conor.dooley@microchip.com>");
446+
MODULE_IMPORT_NS(MCHP_CLK_MPFS);

drivers/reset/reset-mpfs.c

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
*/
99
#include <linux/auxiliary_bus.h>
1010
#include <linux/delay.h>
11+
#include <linux/io.h>
1112
#include <linux/module.h>
1213
#include <linux/of.h>
1314
#include <linux/platform_device.h>
15+
#include <linux/slab.h>
1416
#include <linux/reset-controller.h>
1517
#include <dt-bindings/clock/microchip,mpfs-clock.h>
1618
#include <soc/microchip/mpfs.h>
@@ -28,20 +30,30 @@
2830
/* block concurrent access to the soft reset register */
2931
static DEFINE_SPINLOCK(mpfs_reset_lock);
3032

33+
struct mpfs_reset {
34+
void __iomem *base;
35+
struct reset_controller_dev rcdev;
36+
};
37+
38+
static inline struct mpfs_reset *to_mpfs_reset(struct reset_controller_dev *rcdev)
39+
{
40+
return container_of(rcdev, struct mpfs_reset, rcdev);
41+
}
42+
3143
/*
3244
* Peripheral clock resets
3345
*/
34-
3546
static int mpfs_assert(struct reset_controller_dev *rcdev, unsigned long id)
3647
{
48+
struct mpfs_reset *rst = to_mpfs_reset(rcdev);
3749
unsigned long flags;
3850
u32 reg;
3951

4052
spin_lock_irqsave(&mpfs_reset_lock, flags);
4153

42-
reg = mpfs_reset_read(rcdev->dev);
54+
reg = readl(rst->base);
4355
reg |= BIT(id);
44-
mpfs_reset_write(rcdev->dev, reg);
56+
writel(reg, rst->base);
4557

4658
spin_unlock_irqrestore(&mpfs_reset_lock, flags);
4759

@@ -50,14 +62,15 @@ static int mpfs_assert(struct reset_controller_dev *rcdev, unsigned long id)
5062

5163
static int mpfs_deassert(struct reset_controller_dev *rcdev, unsigned long id)
5264
{
65+
struct mpfs_reset *rst = to_mpfs_reset(rcdev);
5366
unsigned long flags;
5467
u32 reg;
5568

5669
spin_lock_irqsave(&mpfs_reset_lock, flags);
5770

58-
reg = mpfs_reset_read(rcdev->dev);
71+
reg = readl(rst->base);
5972
reg &= ~BIT(id);
60-
mpfs_reset_write(rcdev->dev, reg);
73+
writel(reg, rst->base);
6174

6275
spin_unlock_irqrestore(&mpfs_reset_lock, flags);
6376

@@ -66,7 +79,8 @@ static int mpfs_deassert(struct reset_controller_dev *rcdev, unsigned long id)
6679

6780
static int mpfs_status(struct reset_controller_dev *rcdev, unsigned long id)
6881
{
69-
u32 reg = mpfs_reset_read(rcdev->dev);
82+
struct mpfs_reset *rst = to_mpfs_reset(rcdev);
83+
u32 reg = readl(rst->base);
7084

7185
/*
7286
* It is safe to return here as MPFS_NUM_RESETS makes sure the sign bit
@@ -121,11 +135,15 @@ static int mpfs_reset_probe(struct auxiliary_device *adev,
121135
{
122136
struct device *dev = &adev->dev;
123137
struct reset_controller_dev *rcdev;
138+
struct mpfs_reset *rst;
124139

125-
rcdev = devm_kzalloc(dev, sizeof(*rcdev), GFP_KERNEL);
126-
if (!rcdev)
140+
rst = devm_kzalloc(dev, sizeof(*rst), GFP_KERNEL);
141+
if (!rst)
127142
return -ENOMEM;
128143

144+
rst->base = (void __iomem *)adev->dev.platform_data;
145+
146+
rcdev = &rst->rcdev;
129147
rcdev->dev = dev;
130148
rcdev->dev->parent = dev->parent;
131149
rcdev->ops = &mpfs_reset_ops;
@@ -137,9 +155,68 @@ static int mpfs_reset_probe(struct auxiliary_device *adev,
137155
return devm_reset_controller_register(dev, rcdev);
138156
}
139157

158+
static void mpfs_reset_unregister_adev(void *_adev)
159+
{
160+
struct auxiliary_device *adev = _adev;
161+
162+
auxiliary_device_delete(adev);
163+
auxiliary_device_uninit(adev);
164+
}
165+
166+
static void mpfs_reset_adev_release(struct device *dev)
167+
{
168+
struct auxiliary_device *adev = to_auxiliary_dev(dev);
169+
170+
kfree(adev);
171+
}
172+
173+
static struct auxiliary_device *mpfs_reset_adev_alloc(struct device *clk_dev)
174+
{
175+
struct auxiliary_device *adev;
176+
int ret;
177+
178+
adev = kzalloc(sizeof(*adev), GFP_KERNEL);
179+
if (!adev)
180+
return ERR_PTR(-ENOMEM);
181+
182+
adev->name = "reset-mpfs";
183+
adev->dev.parent = clk_dev;
184+
adev->dev.release = mpfs_reset_adev_release;
185+
adev->id = 666u;
186+
187+
ret = auxiliary_device_init(adev);
188+
if (ret) {
189+
kfree(adev);
190+
return ERR_PTR(ret);
191+
}
192+
193+
return adev;
194+
}
195+
196+
int mpfs_reset_controller_register(struct device *clk_dev, void __iomem *base)
197+
{
198+
struct auxiliary_device *adev;
199+
int ret;
200+
201+
adev = mpfs_reset_adev_alloc(clk_dev);
202+
if (IS_ERR(adev))
203+
return PTR_ERR(adev);
204+
205+
ret = auxiliary_device_add(adev);
206+
if (ret) {
207+
auxiliary_device_uninit(adev);
208+
return ret;
209+
}
210+
211+
adev->dev.platform_data = (__force void *)base;
212+
213+
return devm_add_action_or_reset(clk_dev, mpfs_reset_unregister_adev, adev);
214+
}
215+
EXPORT_SYMBOL_NS_GPL(mpfs_reset_controller_register, MCHP_CLK_MPFS);
216+
140217
static const struct auxiliary_device_id mpfs_reset_ids[] = {
141218
{
142-
.name = "clk_mpfs.reset-mpfs",
219+
.name = "reset_mpfs.reset-mpfs",
143220
},
144221
{ }
145222
};

include/soc/microchip/mpfs.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ struct mtd_info *mpfs_sys_controller_get_flash(struct mpfs_sys_controller *mpfs_
4343
#endif /* if IS_ENABLED(CONFIG_POLARFIRE_SOC_SYS_CTRL) */
4444

4545
#if IS_ENABLED(CONFIG_MCHP_CLK_MPFS)
46-
47-
u32 mpfs_reset_read(struct device *dev);
48-
49-
void mpfs_reset_write(struct device *dev, u32 val);
50-
46+
#if IS_ENABLED(CONFIG_RESET_CONTROLLER)
47+
int mpfs_reset_controller_register(struct device *clk_dev, void __iomem *base);
48+
#else
49+
static inline int mpfs_reset_controller_register(struct device *clk_dev, void __iomem *base) { return 0; }
50+
#endif /* if IS_ENABLED(CONFIG_RESET_CONTROLLER) */
5151
#endif /* if IS_ENABLED(CONFIG_MCHP_CLK_MPFS) */
5252

5353
#endif /* __SOC_MPFS_H__ */

0 commit comments

Comments
 (0)