Skip to content

Commit 781f60e

Browse files
committed
reset: mpfs: add non-auxiliary bus probing
While the auxiliary bus was a nice bandaid, and meant that re-writing the representation of the clock regions in devicetree was not required, it has run its course. The "mss_top_sysreg" region that contains the clock and reset regions, also contains pinctrl and an interrupt controller, so the time has come rewrite the devicetree and probe the reset controller from an mfd devicetree node, rather than implement those drivers using the auxiliary bus. Wanting to avoid propagating this naive/incorrect description of the hardware to the new pic64gx SoC is a major motivating factor here. Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> Acked-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Conor Dooley <conor.dooley@microchip.com>
1 parent bab55c2 commit 781f60e

4 files changed

Lines changed: 60 additions & 39 deletions

File tree

drivers/clk/microchip/clk-mpfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static const struct regmap_config mpfs_clk_regmap_config = {
3838
.reg_stride = 4,
3939
.val_bits = 32,
4040
.val_format_endian = REGMAP_ENDIAN_LITTLE,
41-
.max_register = REG_SUBBLK_CLOCK_CR,
41+
.max_register = REG_SUBBLK_RESET_CR,
4242
};
4343

4444
/*
@@ -502,7 +502,7 @@ static inline int mpfs_clk_old_format_probe(struct mpfs_clock_data *clk_data,
502502
if (IS_ERR(clk_data->regmap))
503503
return PTR_ERR(clk_data->regmap);
504504

505-
return mpfs_reset_controller_register(dev, clk_data->base + REG_SUBBLK_RESET_CR);
505+
return mpfs_reset_controller_register(dev, clk_data->regmap);
506506
}
507507

508508
static int mpfs_clk_probe(struct platform_device *pdev)

drivers/reset/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ config RESET_PISTACHIO
200200
config RESET_POLARFIRE_SOC
201201
bool "Microchip PolarFire SoC (MPFS) Reset Driver"
202202
depends on MCHP_CLK_MPFS
203+
depends on MFD_SYSCON
203204
select AUXILIARY_BUS
204205
default MCHP_CLK_MPFS
205206
help

drivers/reset/reset-mpfs.c

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
#include <linux/auxiliary_bus.h>
1010
#include <linux/delay.h>
1111
#include <linux/io.h>
12+
#include <linux/mfd/syscon.h>
1213
#include <linux/module.h>
1314
#include <linux/of.h>
1415
#include <linux/platform_device.h>
15-
#include <linux/slab.h>
16+
#include <linux/regmap.h>
1617
#include <linux/reset-controller.h>
18+
#include <linux/slab.h>
1719
#include <dt-bindings/clock/microchip,mpfs-clock.h>
1820
#include <soc/microchip/mpfs.h>
1921

@@ -27,11 +29,10 @@
2729
#define MPFS_SLEEP_MIN_US 100
2830
#define MPFS_SLEEP_MAX_US 200
2931

30-
/* block concurrent access to the soft reset register */
31-
static DEFINE_SPINLOCK(mpfs_reset_lock);
32+
#define REG_SUBBLK_RESET_CR 0x88u
3233

3334
struct mpfs_reset {
34-
void __iomem *base;
35+
struct regmap *regmap;
3536
struct reset_controller_dev rcdev;
3637
};
3738

@@ -46,41 +47,25 @@ static inline struct mpfs_reset *to_mpfs_reset(struct reset_controller_dev *rcde
4647
static int mpfs_assert(struct reset_controller_dev *rcdev, unsigned long id)
4748
{
4849
struct mpfs_reset *rst = to_mpfs_reset(rcdev);
49-
unsigned long flags;
50-
u32 reg;
51-
52-
spin_lock_irqsave(&mpfs_reset_lock, flags);
53-
54-
reg = readl(rst->base);
55-
reg |= BIT(id);
56-
writel(reg, rst->base);
5750

58-
spin_unlock_irqrestore(&mpfs_reset_lock, flags);
51+
return regmap_set_bits(rst->regmap, REG_SUBBLK_RESET_CR, BIT(id));
5952

60-
return 0;
6153
}
6254

6355
static int mpfs_deassert(struct reset_controller_dev *rcdev, unsigned long id)
6456
{
6557
struct mpfs_reset *rst = to_mpfs_reset(rcdev);
66-
unsigned long flags;
67-
u32 reg;
68-
69-
spin_lock_irqsave(&mpfs_reset_lock, flags);
7058

71-
reg = readl(rst->base);
72-
reg &= ~BIT(id);
73-
writel(reg, rst->base);
59+
return regmap_clear_bits(rst->regmap, REG_SUBBLK_RESET_CR, BIT(id));
7460

75-
spin_unlock_irqrestore(&mpfs_reset_lock, flags);
76-
77-
return 0;
7861
}
7962

8063
static int mpfs_status(struct reset_controller_dev *rcdev, unsigned long id)
8164
{
8265
struct mpfs_reset *rst = to_mpfs_reset(rcdev);
83-
u32 reg = readl(rst->base);
66+
u32 reg;
67+
68+
regmap_read(rst->regmap, REG_SUBBLK_RESET_CR, &reg);
8469

8570
/*
8671
* It is safe to return here as MPFS_NUM_RESETS makes sure the sign bit
@@ -130,23 +115,58 @@ static int mpfs_reset_xlate(struct reset_controller_dev *rcdev,
130115
return index - MPFS_PERIPH_OFFSET;
131116
}
132117

133-
static int mpfs_reset_probe(struct auxiliary_device *adev,
134-
const struct auxiliary_device_id *id)
118+
static int mpfs_reset_mfd_probe(struct platform_device *pdev)
119+
{
120+
struct reset_controller_dev *rcdev;
121+
struct device *dev = &pdev->dev;
122+
struct mpfs_reset *rst;
123+
124+
rst = devm_kzalloc(dev, sizeof(*rst), GFP_KERNEL);
125+
if (!rst)
126+
return -ENOMEM;
127+
128+
rcdev = &rst->rcdev;
129+
rcdev->dev = dev;
130+
rcdev->ops = &mpfs_reset_ops;
131+
132+
rcdev->of_node = pdev->dev.parent->of_node;
133+
rcdev->of_reset_n_cells = 1;
134+
rcdev->of_xlate = mpfs_reset_xlate;
135+
rcdev->nr_resets = MPFS_NUM_RESETS;
136+
137+
rst->regmap = device_node_to_regmap(pdev->dev.parent->of_node);
138+
if (IS_ERR(rst->regmap))
139+
return dev_err_probe(dev, PTR_ERR(rst->regmap),
140+
"Failed to find syscon regmap\n");
141+
142+
return devm_reset_controller_register(dev, rcdev);
143+
}
144+
145+
static struct platform_driver mpfs_reset_mfd_driver = {
146+
.probe = mpfs_reset_mfd_probe,
147+
.driver = {
148+
.name = "mpfs-reset",
149+
},
150+
};
151+
module_platform_driver(mpfs_reset_mfd_driver);
152+
153+
static int mpfs_reset_adev_probe(struct auxiliary_device *adev,
154+
const struct auxiliary_device_id *id)
135155
{
136-
struct device *dev = &adev->dev;
137156
struct reset_controller_dev *rcdev;
157+
struct device *dev = &adev->dev;
138158
struct mpfs_reset *rst;
139159

140160
rst = devm_kzalloc(dev, sizeof(*rst), GFP_KERNEL);
141161
if (!rst)
142162
return -ENOMEM;
143163

144-
rst->base = (void __iomem *)adev->dev.platform_data;
164+
rst->regmap = (struct regmap *)adev->dev.platform_data;
145165

146166
rcdev = &rst->rcdev;
147167
rcdev->dev = dev;
148-
rcdev->dev->parent = dev->parent;
149168
rcdev->ops = &mpfs_reset_ops;
169+
150170
rcdev->of_node = dev->parent->of_node;
151171
rcdev->of_reset_n_cells = 1;
152172
rcdev->of_xlate = mpfs_reset_xlate;
@@ -155,12 +175,11 @@ static int mpfs_reset_probe(struct auxiliary_device *adev,
155175
return devm_reset_controller_register(dev, rcdev);
156176
}
157177

158-
int mpfs_reset_controller_register(struct device *clk_dev, void __iomem *base)
178+
int mpfs_reset_controller_register(struct device *clk_dev, struct regmap *map)
159179
{
160180
struct auxiliary_device *adev;
161181

162-
adev = devm_auxiliary_device_create(clk_dev, "reset-mpfs",
163-
(__force void *)base);
182+
adev = devm_auxiliary_device_create(clk_dev, "reset-mpfs", (void *)map);
164183
if (!adev)
165184
return -ENODEV;
166185

@@ -176,12 +195,12 @@ static const struct auxiliary_device_id mpfs_reset_ids[] = {
176195
};
177196
MODULE_DEVICE_TABLE(auxiliary, mpfs_reset_ids);
178197

179-
static struct auxiliary_driver mpfs_reset_driver = {
180-
.probe = mpfs_reset_probe,
198+
static struct auxiliary_driver mpfs_reset_aux_driver = {
199+
.probe = mpfs_reset_adev_probe,
181200
.id_table = mpfs_reset_ids,
182201
};
183202

184-
module_auxiliary_driver(mpfs_reset_driver);
203+
module_auxiliary_driver(mpfs_reset_aux_driver);
185204

186205
MODULE_DESCRIPTION("Microchip PolarFire SoC Reset Driver");
187206
MODULE_AUTHOR("Conor Dooley <conor.dooley@microchip.com>");

include/soc/microchip/mpfs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <linux/types.h>
1616
#include <linux/of_device.h>
17+
#include <linux/regmap.h>
1718

1819
struct mpfs_sys_controller;
1920

@@ -44,7 +45,7 @@ struct mtd_info *mpfs_sys_controller_get_flash(struct mpfs_sys_controller *mpfs_
4445

4546
#if IS_ENABLED(CONFIG_MCHP_CLK_MPFS)
4647
#if IS_ENABLED(CONFIG_RESET_POLARFIRE_SOC)
47-
int mpfs_reset_controller_register(struct device *clk_dev, void __iomem *base);
48+
int mpfs_reset_controller_register(struct device *clk_dev, struct regmap *map);
4849
#else
4950
static inline int mpfs_reset_controller_register(struct device *clk_dev, void __iomem *base) { return 0; }
5051
#endif /* if IS_ENABLED(CONFIG_RESET_POLARFIRE_SOC) */

0 commit comments

Comments
 (0)