2020-04-17 02:16:24

by Baolin Wang

[permalink] [raw]
Subject: [PATCH 1/2] mfd: syscon: Support physical regmap bus

Some platforms such as Spreadtrum platform, define a special method to
update bits of the registers instead of reading and writing, which means
we should use a physical regmap bus to define the reg_update_bits()
operation instead of the MMIO regmap bus.

Thus add a new helper for the syscon driver to allow to register a physical
regmap bus to support this new requirement.

Signed-off-by: Baolin Wang <[email protected]>
---
drivers/mfd/syscon.c | 23 +++++++++++++++++++++--
include/linux/mfd/syscon.h | 7 +++++++
2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index 3a97816d0cba..92bfe87038ca 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -24,6 +24,7 @@
#include <linux/slab.h>

static struct platform_driver syscon_driver;
+static struct regmap_bus *syscon_phy_regmap_bus;

static DEFINE_SPINLOCK(syscon_list_slock);
static LIST_HEAD(syscon_list);
@@ -106,14 +107,25 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
syscon_config.val_bits = reg_io_width * 8;
syscon_config.max_register = resource_size(&res) - reg_io_width;

- regmap = regmap_init_mmio(NULL, base, &syscon_config);
+ /*
+ * The Spreadtrum syscon need register a real physical regmap bus
+ * with new atomic bits updating operation instead of using
+ * read-modify-write.
+ */
+ if (IS_ENABLED(CONFIG_ARCH_SPRD) &&
+ of_device_is_compatible(np, "sprd,atomic-syscon") &&
+ syscon_phy_regmap_bus)
+ regmap = regmap_init(NULL, syscon_phy_regmap_bus, base,
+ &syscon_config);
+ else
+ regmap = regmap_init_mmio(NULL, base, &syscon_config);
if (IS_ERR(regmap)) {
pr_err("regmap init failed\n");
ret = PTR_ERR(regmap);
goto err_regmap;
}

- if (check_clk) {
+ if (check_clk && !syscon_phy_regmap_bus) {
clk = of_clk_get(np, 0);
if (IS_ERR(clk)) {
ret = PTR_ERR(clk);
@@ -172,6 +184,13 @@ static struct regmap *device_node_get_regmap(struct device_node *np,
return syscon->regmap;
}

+void syscon_register_phys_regmap_bus(struct regmap_bus *phy_regmap_bus)
+{
+ if (phy_regmap_bus)
+ syscon_phy_regmap_bus = phy_regmap_bus;
+}
+EXPORT_SYMBOL_GPL(syscon_register_phys_regmap_bus);
+
struct regmap *device_node_to_regmap(struct device_node *np)
{
return device_node_get_regmap(np, false);
diff --git a/include/linux/mfd/syscon.h b/include/linux/mfd/syscon.h
index 7f20e9b502a5..fbc2a2f0f414 100644
--- a/include/linux/mfd/syscon.h
+++ b/include/linux/mfd/syscon.h
@@ -13,6 +13,7 @@

#include <linux/err.h>
#include <linux/errno.h>
+#include <linux/regmap.h>

struct device_node;

@@ -28,6 +29,7 @@ extern struct regmap *syscon_regmap_lookup_by_phandle_args(
const char *property,
int arg_count,
unsigned int *out_args);
+extern void syscon_register_phys_regmap_bus(struct regmap_bus *phy_regmap_bus);
#else
static inline struct regmap *device_node_to_regmap(struct device_node *np)
{
@@ -59,6 +61,11 @@ static inline struct regmap *syscon_regmap_lookup_by_phandle_args(
{
return ERR_PTR(-ENOTSUPP);
}
+
+static inline void
+syscon_register_phys_regmap_bus(struct regmap_bus *phy_regmap_bus)
+{
+}
#endif

#endif /* __LINUX_MFD_SYSCON_H__ */
--
2.17.1


2020-04-24 08:13:47

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH 1/2] mfd: syscon: Support physical regmap bus

On Fri, 17 Apr 2020, Baolin Wang wrote:

> Some platforms such as Spreadtrum platform, define a special method to
> update bits of the registers instead of reading and writing, which means
> we should use a physical regmap bus to define the reg_update_bits()
> operation instead of the MMIO regmap bus.
>
> Thus add a new helper for the syscon driver to allow to register a physical
> regmap bus to support this new requirement.
>
> Signed-off-by: Baolin Wang <[email protected]>
> ---
> drivers/mfd/syscon.c | 23 +++++++++++++++++++++--
> include/linux/mfd/syscon.h | 7 +++++++
> 2 files changed, 28 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
> index 3a97816d0cba..92bfe87038ca 100644
> --- a/drivers/mfd/syscon.c
> +++ b/drivers/mfd/syscon.c
> @@ -24,6 +24,7 @@
> #include <linux/slab.h>
>
> static struct platform_driver syscon_driver;
> +static struct regmap_bus *syscon_phy_regmap_bus;
>
> static DEFINE_SPINLOCK(syscon_list_slock);
> static LIST_HEAD(syscon_list);
> @@ -106,14 +107,25 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
> syscon_config.val_bits = reg_io_width * 8;
> syscon_config.max_register = resource_size(&res) - reg_io_width;
>
> - regmap = regmap_init_mmio(NULL, base, &syscon_config);
> + /*
> + * The Spreadtrum syscon need register a real physical regmap bus
> + * with new atomic bits updating operation instead of using
> + * read-modify-write.
> + */
> + if (IS_ENABLED(CONFIG_ARCH_SPRD) &&
> + of_device_is_compatible(np, "sprd,atomic-syscon") &&

Please find a more generic way of supporting your use-case. This is a
generic driver, and as such I am vehemently against adding any sort of
vendor specific code in here.

> + syscon_phy_regmap_bus)
> + regmap = regmap_init(NULL, syscon_phy_regmap_bus, base,
> + &syscon_config);
> + else
> + regmap = regmap_init_mmio(NULL, base, &syscon_config);

--
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2020-04-24 08:26:22

by Arnd Bergmann

[permalink] [raw]
Subject: Re: [PATCH 1/2] mfd: syscon: Support physical regmap bus

On Fri, Apr 24, 2020 at 10:11 AM Lee Jones <[email protected]> wrote:
> On Fri, 17 Apr 2020, Baolin Wang wrote:
> > @@ -106,14 +107,25 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
> > syscon_config.val_bits = reg_io_width * 8;
> > syscon_config.max_register = resource_size(&res) - reg_io_width;
> >
> > - regmap = regmap_init_mmio(NULL, base, &syscon_config);
> > + /*
> > + * The Spreadtrum syscon need register a real physical regmap bus
> > + * with new atomic bits updating operation instead of using
> > + * read-modify-write.
> > + */
> > + if (IS_ENABLED(CONFIG_ARCH_SPRD) &&
> > + of_device_is_compatible(np, "sprd,atomic-syscon") &&
>
> Please find a more generic way of supporting your use-case. This is a
> generic driver, and as such I am vehemently against adding any sort of
> vendor specific code in here.

I suggested doing it this way, as all alternatives seemed worse than this.

Arnd

2020-04-24 08:34:47

by Lee Jones

[permalink] [raw]
Subject: Re: [PATCH 1/2] mfd: syscon: Support physical regmap bus

On Fri, 24 Apr 2020, Arnd Bergmann wrote:

> On Fri, Apr 24, 2020 at 10:11 AM Lee Jones <[email protected]> wrote:
> > On Fri, 17 Apr 2020, Baolin Wang wrote:
> > > @@ -106,14 +107,25 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
> > > syscon_config.val_bits = reg_io_width * 8;
> > > syscon_config.max_register = resource_size(&res) - reg_io_width;
> > >
> > > - regmap = regmap_init_mmio(NULL, base, &syscon_config);
> > > + /*
> > > + * The Spreadtrum syscon need register a real physical regmap bus
> > > + * with new atomic bits updating operation instead of using
> > > + * read-modify-write.
> > > + */
> > > + if (IS_ENABLED(CONFIG_ARCH_SPRD) &&
> > > + of_device_is_compatible(np, "sprd,atomic-syscon") &&
> >
> > Please find a more generic way of supporting your use-case. This is a
> > generic driver, and as such I am vehemently against adding any sort of
> > vendor specific code in here.
>
> I suggested doing it this way, as all alternatives seemed worse than this.

If we're using a registration function (could probably be swapped out
for or accompanied by a Device Tree property) anyway, then why conduct
the vendor platform checks?

--
Lee Jones [李琼斯]
Linaro Services Technical Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

2020-04-24 08:44:49

by Baolin Wang

[permalink] [raw]
Subject: Re: [PATCH 1/2] mfd: syscon: Support physical regmap bus

On Fri, Apr 24, 2020 at 4:32 PM Lee Jones <[email protected]> wrote:
>
> On Fri, 24 Apr 2020, Arnd Bergmann wrote:
>
> > On Fri, Apr 24, 2020 at 10:11 AM Lee Jones <[email protected]> wrote:
> > > On Fri, 17 Apr 2020, Baolin Wang wrote:
> > > > @@ -106,14 +107,25 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
> > > > syscon_config.val_bits = reg_io_width * 8;
> > > > syscon_config.max_register = resource_size(&res) - reg_io_width;
> > > >
> > > > - regmap = regmap_init_mmio(NULL, base, &syscon_config);
> > > > + /*
> > > > + * The Spreadtrum syscon need register a real physical regmap bus
> > > > + * with new atomic bits updating operation instead of using
> > > > + * read-modify-write.
> > > > + */
> > > > + if (IS_ENABLED(CONFIG_ARCH_SPRD) &&
> > > > + of_device_is_compatible(np, "sprd,atomic-syscon") &&
> > >
> > > Please find a more generic way of supporting your use-case. This is a
> > > generic driver, and as such I am vehemently against adding any sort of
> > > vendor specific code in here.
> >
> > I suggested doing it this way, as all alternatives seemed worse than this.
>
> If we're using a registration function (could probably be swapped out
> for or accompanied by a Device Tree property) anyway, then why conduct
> the vendor platform checks?

Actually I've send out the v3 patch according to Arnd's suggestion. In
v3 patch, I removed the registration function, but we agreed that
adding the vendor specific support in the syscon driver seems a better
way than others.

--
Baolin Wang

2020-04-24 08:46:10

by Baolin Wang

[permalink] [raw]
Subject: Re: [PATCH 1/2] mfd: syscon: Support physical regmap bus

On Fri, Apr 24, 2020 at 4:42 PM Baolin Wang <[email protected]> wrote:
>
> On Fri, Apr 24, 2020 at 4:32 PM Lee Jones <[email protected]> wrote:
> >
> > On Fri, 24 Apr 2020, Arnd Bergmann wrote:
> >
> > > On Fri, Apr 24, 2020 at 10:11 AM Lee Jones <[email protected]> wrote:
> > > > On Fri, 17 Apr 2020, Baolin Wang wrote:
> > > > > @@ -106,14 +107,25 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
> > > > > syscon_config.val_bits = reg_io_width * 8;
> > > > > syscon_config.max_register = resource_size(&res) - reg_io_width;
> > > > >
> > > > > - regmap = regmap_init_mmio(NULL, base, &syscon_config);
> > > > > + /*
> > > > > + * The Spreadtrum syscon need register a real physical regmap bus
> > > > > + * with new atomic bits updating operation instead of using
> > > > > + * read-modify-write.
> > > > > + */
> > > > > + if (IS_ENABLED(CONFIG_ARCH_SPRD) &&
> > > > > + of_device_is_compatible(np, "sprd,atomic-syscon") &&
> > > >
> > > > Please find a more generic way of supporting your use-case. This is a
> > > > generic driver, and as such I am vehemently against adding any sort of
> > > > vendor specific code in here.
> > >
> > > I suggested doing it this way, as all alternatives seemed worse than this.
> >
> > If we're using a registration function (could probably be swapped out
> > for or accompanied by a Device Tree property) anyway, then why conduct
> > the vendor platform checks?
>
> Actually I've send out the v3 patch according to Arnd's suggestion. In
> v3 patch, I removed the registration function, but we agreed that
> adding the vendor specific support in the syscon driver seems a better
> way than others.

Sorry, I forgot the link:
https://lore.kernel.org/patchwork/patch/1228160/

--
Baolin Wang