add syscon driver based on regmap for general registers access
Subsystems (8)
v2 cover add syscon driver based on regmap for general registers access
This patch series mainly adds an syscon driver which is used to access general system controller registers like FSL IOMUXC GPR and ANATOP, after that, we convert all the exist private access general registers code to use standard API from regmap to access registers.
Finally we remove the old mfd anatop driver which is only for anatop register access.
The patch series is based on linus's tree 3.6-rc3 since commit 9160338.
Dong Aisheng (7):
mfd: add syscon driver based on regmap
ARM: imx6q: add iomuxc gpr support into syscon
ARM: imx6q: add anatop support into syscon
regulator: anatop-regulator: convert to use syscon to access anatop
register
ARM: imx6q: convert to use syscon to access anatop registers
ARM: dts: imx6q: add simple-bus compatible string for anatop
mfd: anatop-mfd: remove anatop driver
.../devicetree/bindings/mfd/imx-syscon.txt | 11 + arch/arm/boot/dts/imx6q.dtsi | 15 +- arch/arm/mach-imx/Kconfig | 2 +- arch/arm/mach-imx/mach-imx6q.c | 43 ++-- drivers/mfd/Kconfig | 13 +- drivers/mfd/Makefile | 2 +- drivers/mfd/anatop-mfd.c | 124 -------- drivers/mfd/syscon.c | 169 +++++++++++ drivers/regulator/Kconfig | 2 +- drivers/regulator/anatop-regulator.c | 25 +- include/linux/fsl/imx6q-iomuxc-gpr.h | 319 ++++++++++++++++++++ include/linux/mfd/anatop.h | 40 --- include/linux/mfd/syscon.h | 22 ++ 13 files changed, 576 insertions(+), 211 deletions(-) create mode 100644 Documentation/devicetree/bindings/mfd/imx-syscon.txt delete mode 100644 drivers/mfd/anatop-mfd.c create mode 100644 drivers/mfd/syscon.c create mode 100644 include/linux/fsl/imx6q-iomuxc-gpr.h delete mode 100644 include/linux/mfd/anatop.h create mode 100644 include/linux/mfd/syscon.h
PATCH v2 1/7 mfd: add syscon driver based on regmap
From: Dong Aisheng <[email protected]>
Add regmap based syscon driver.
This is usually used for access misc bits in registers which does not belong to a specific module, for example, IMX IOMUXC GPR and ANATOP. With this driver, client can use generic regmap API to access registers which are registered into syscon.
---
ChangeLog:v1->v2:
* provide a way of retrieving the regmap, suggested by Mark Brown.
* delete imx-syscon io accessors and using generic regmap API for client drivers.
* change to a more generic name for other SoCs to use.
--- .../devicetree/bindings/mfd/imx-syscon.txt | 11 ++ drivers/mfd/Kconfig | 7 + drivers/mfd/Makefile | 1 + drivers/mfd/syscon.c | 169 ++++++++++++++++++++ include/linux/mfd/syscon.h | 22 +++ 5 files changed, 210 insertions(+), 0 deletions(-)
Documentation/devicetree/bindings/mfd/imx-syscon.txt new file +11 -0
@@ -0,0 +1,11 @@ +* System Controller Registers R/W driver + +Required properties: +- compatible: Should contain "syscon". +- reg: the register range can be access from syscon + +Examples: +gpr: iomuxc-gpr at 020e0000 { + compatible = "fsl,imx6q-iomuxc", "syscon"; + reg = <0x020e0000 0x38>; +};
drivers/mfd/Kconfig +7 -0
@@ -993,6 +993,13 @@ config MFD_ANATOP MFD controller. This controller embeds regulator and thermal devices for Freescale i.MX platforms. +config MFD_SYSCON + bool "System Controller Register R/W Based on Regmap" + select REGMAP_MMIO + help + Select this option to enable accessing system control registers + via regmap. + config MFD_PALMAS bool "Support for the TI Palmas series chips" select MFD_CORE
drivers/mfd/Makefile +1 -0
@@ -131,4 +131,5 @@ obj-$(CONFIG_MFD_PALMAS) += palmas.o obj-$(CONFIG_MFD_RC5T583) += rc5t583.o rc5t583-irq.o obj-$(CONFIG_MFD_SEC_CORE) += sec-core.o sec-irq.o obj-$(CONFIG_MFD_ANATOP) += anatop-mfd.o +obj-$(CONFIG_MFD_SYSCON) += syscon.o obj-$(CONFIG_MFD_LM3533) += lm3533-core.o lm3533-ctrlbank.o
drivers/mfd/syscon.c new file +169 -0
169 lines not on this page · raw message
include/linux/mfd/syscon.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* System Control Driver +* +* Copyright (C) 2012 Freescale Semiconductor, Inc. +* Copyright (C) 2012 Linaro Ltd. +* +* Author: Dong Aisheng <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#ifndef __LINUX_MFD_SYSCON_H__ +#define __LINUX_MFD_SYSCON_H__ + +extern struct regmap *syscon_regmap_lookup_by_compatible (const char *s); +extern struct regmap *syscon_regmap_lookup_by_phandle ( +struct device_node *np, +const char *property); +#endif /* __LINUX_MFD_SYSCON_H__ */
Signature · 1 line
1.7.0.4
PATCH v2 2/7 ARM: imx6q: add iomuxc gpr support into syscon
In reply to Dong AishengFrom: Dong Aisheng <[email protected]>
Include headfile for easy using.
--- arch/arm/boot/dts/imx6q.dtsi | 5 + include/linux/fsl/imx6q-iomuxc-gpr.h | 319 ++++++++++++++++++++++++++++++++++ 2 files changed, 324 insertions(+), 0 deletions(-)
arch/arm/boot/dts/imx6q.dtsi +5 -0
@@ -507,6 +507,11 @@ interrupts = <0 89 0x04 0 90 0x04>; }; + gpr: iomuxc-gpr at 020e0000 { + compatible = "fsl,imx6q-iomuxc-gpr", "syscon"; + reg = <0x020e0000 0x38>; + }; + iomuxc at 020e0000 { compatible = "fsl,imx6q-iomuxc"; reg = <0x020e0000 0x4000>;
include/linux/fsl/imx6q-iomuxc-gpr.h new file +319 -0
319 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v2 3/7 ARM: imx6q: add anatop support into syscon
In reply to Dong AishengFrom: Dong Aisheng <[email protected]>
There're a few anatop registers need to be accessed by different modules. Add anatop registers into syscon support for easy access.
--- arch/arm/boot/dts/imx6q.dtsi | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
arch/arm/boot/dts/imx6q.dtsi +2 -2
@@ -378,8 +378,8 @@ interrupts = <0 87 0x04 0 88 0x04>; }; - anatop at 020c8000 { - compatible = "fsl,imx6q-anatop"; + anatop: anatop at 020c8000 { + compatible = "fsl,imx6q-anatop", "syscon"; reg = <0x020c8000 0x1000>; interrupts = <0 49 0x04 0 54 0x04 0 127 0x04>;
Signature · 1 line
1.7.0.4
PATCH v2 4/7 regulator: anatop-regulator: convert to use syscon to access anatop register
In reply to Dong AishengFrom: Dong Aisheng <[email protected]>
Using syscon to access anatop register.
---
ChangeLog v1-v2:
* update to use generic regmap api
--- arch/arm/boot/dts/imx6q.dtsi | 6 ++++++ drivers/regulator/Kconfig | 2 +- drivers/regulator/anatop-regulator.c | 25 +++++++++++++++---------- 3 files changed, 22 insertions(+), 11 deletions(-)
arch/arm/boot/dts/imx6q.dtsi +6 -0
@@ -395,6 +395,7 @@ anatop-min-bit-val = <4>; anatop-min-voltage = <800000>; anatop-max-voltage = <1375000>; + fsl,anatop = <&anatop>; }; regulator-3p0 at 120 {
@@ -409,6 +410,7 @@ anatop-min-bit-val = <0>; anatop-min-voltage = <2625000>; anatop-max-voltage = <3400000>; + fsl,anatop = <&anatop>; }; regulator-2p5 at 130 {
@@ -423,6 +425,7 @@ anatop-min-bit-val = <0>; anatop-min-voltage = <2000000>; anatop-max-voltage = <2750000>; + fsl,anatop = <&anatop>; }; regulator-vddcore at 140 {
@@ -437,6 +440,7 @@ anatop-min-bit-val = <1>; anatop-min-voltage = <725000>; anatop-max-voltage = <1450000>; + fsl,anatop = <&anatop>; }; regulator-vddpu at 140 {
@@ -451,6 +455,7 @@ anatop-min-bit-val = <1>; anatop-min-voltage = <725000>; anatop-max-voltage = <1450000>; + fsl,anatop = <&anatop>; }; regulator-vddsoc at 140 {
@@ -465,6 +470,7 @@ anatop-min-bit-val = <1>; anatop-min-voltage = <725000>; anatop-max-voltage = <1450000>; + fsl,anatop = <&anatop>; }; };
drivers/regulator/Kconfig +1 -1
@@ -112,7 +112,7 @@ config REGULATOR_DA9052 config REGULATOR_ANATOP tristate "Freescale i.MX on-chip ANATOP LDO regulators" - depends on MFD_ANATOP + depends on MFD_SYSCON help Say y here to support Freescale i.MX on-chip ANATOP LDOs regulators. It is recommended that this option be
drivers/regulator/anatop-regulator.c +15 -10
@@ -21,19 +21,20 @@#include <linux/slab.h> #include <linux/device.h> #include <linux/module.h> +#include <linux/mfd/syscon.h> #include <linux/err.h> #include <linux/io.h> #include <linux/platform_device.h> #include <linux/of.h> #include <linux/of_address.h> -#include <linux/mfd/anatop.h> +#include <linux/regmap.h> #include <linux/regulator/driver.h> #include <linux/regulator/of_regulator.h> struct anatop_regulator {const char *name;u32 control_reg; -struct anatop *mfd; +struct regmap *anatop;int vol_bit_shift;int vol_bit_width;int min_bit_val;
@@ -43,7 +44,7 @@ struct anatop_regulator {struct regulator_init_data *initdata; }; -static int anatop_set_voltage_sel (struct regulator_dev *reg,unsigned selector) +static int anatop_regmap_set_voltage_sel (struct regulator_dev *reg,unsigned selector) {struct anatop_regulator *anatop_reg =rdev_get_drvdata (reg);u32 val, mask;
@@ -56,12 +57,13 @@ static int anatop_set_voltage_sel(struct regulator_dev *reg, unsigned selector) mask = ((1 << anatop_reg->vol_bit_width) -1 ) << anatop_reg->vol_bit_shift; val <<= anatop_reg->vol_bit_shift; -anatop_write_reg (anatop_reg->mfd, anatop_reg->control_reg, val, mask); +regmap_update_bits (anatop_reg->anatop, anatop_reg->control_reg, + mask, val);return 0 ; } -static int anatop_get_voltage_sel (struct regulator_dev *reg) +static int anatop_regmap_get_voltage_sel (struct regulator_dev *reg) {struct anatop_regulator *anatop_reg =rdev_get_drvdata (reg);u32 val, mask;
@@ -69,7 +71,7 @@ static int anatop_get_voltage_sel(struct regulator_dev *reg)if (!anatop_reg->control_reg)return -ENOTSUPP ; - val =anatop_read_reg (anatop_reg->mfd, anatop_reg->control_reg); +regmap_read (anatop_reg->anatop, anatop_reg->control_reg, &val); mask = ((1 << anatop_reg->vol_bit_width) -1 ) << anatop_reg->vol_bit_shift; val = (val & mask) >> anatop_reg->vol_bit_shift;
@@ -78,8 +80,8 @@ static int anatop_get_voltage_sel(struct regulator_dev *reg) }static struct regulator_ops anatop_rops = { - .set_voltage_sel = anatop_set_voltage_sel, - .get_voltage_sel = anatop_get_voltage_sel, + .set_voltage_sel = anatop_regmap_set_voltage_sel, + .get_voltage_sel = anatop_regmap_get_voltage_sel, .list_voltage = regulator_list_voltage_linear, .map_voltage = regulator_map_voltage_linear, };
@@ -92,7 +94,6 @@ static int __devinit anatop_regulator_probe(struct platform_device *pdev)struct regulator_dev *rdev;struct anatop_regulator *sreg;struct regulator_init_data *initdata; -struct anatop *anatopmfd =dev_get_drvdata (pdev->dev.parent);struct regulator_config config = { };int ret =0 ;
@@ -109,7 +110,11 @@ static int __devinit anatop_regulator_probe(struct platform_device *pdev) rdesc->ops = &anatop_rops; rdesc->type =REGULATOR_VOLTAGE ; rdesc->owner =THIS_MODULE ; - sreg->mfd = anatopmfd; + + sreg->anatop =syscon_regmap_lookup_by_phandle (np,"fsl,anatop" ); +if (IS_ERR (sreg->anatop)) +return PTR_ERR (sreg->anatop); + ret =of_property_read_u32 (np,"anatop-reg-offset" , &sreg->control_reg);if (ret) {
Signature · 1 line
1.7.0.4
PATCH v2 5/7 ARM: imx6q: convert to use syscon to access anatop registers
In reply to Dong AishengFrom: Dong Aisheng <[email protected]>
Using syscon to access anatop registers.
---
ChangeLog v1->v2:
* update to use generic regmap api
--- arch/arm/mach-imx/Kconfig | 2 +- arch/arm/mach-imx/mach-imx6q.c | 43 ++++++++++++++++----------------------- 2 files changed, 19 insertions(+), 26 deletions(-)
arch/arm/mach-imx/Kconfig +1 -1
@@ -839,7 +839,7 @@ config SOC_IMX6Q select HAVE_IMX_MMDC select HAVE_IMX_SRC select HAVE_SMP - select MFD_ANATOP + select MFD_SYSCON select PINCTRL select PINCTRL_IMX6Q
arch/arm/mach-imx/mach-imx6q.c +18 -25
64 lines not on this page · raw message
Signature · 1 line
1.7.0.4
PATCH v2 6/7 ARM: dts: imx6q: add simple-bus compatible string for anatop
In reply to Dong AishengFrom: Dong Aisheng <[email protected]>
Originally the anatop regulator devices are populated by mfd anatop driver. Since mfd anatop driver will be deleted later, we change to populate the regulator devices by devicetree automatically.
This will cause some warning messages as follows during boot due to device
recreation: "vdd1p1: Failed to create debugfs directory"
But it does not break any function.
Later, we will remove mfd anatop driver which can get rid of this error message.
--- arch/arm/boot/dts/imx6q.dtsi | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/boot/dts/imx6q.dtsi +1 -1
@@ -379,7 +379,7 @@ }; anatop: anatop at 020c8000 { - compatible = "fsl,imx6q-anatop", "syscon"; + compatible = "fsl,imx6q-anatop", "syscon", "simple-bus"; reg = <0x020c8000 0x1000>; interrupts = <0 49 0x04 0 54 0x04 0 127 0x04>;
Signature · 1 line
1.7.0.4
PATCH v2 7/7 mfd: anatop-mfd: remove anatop driver
In reply to Dong AishengFrom: Dong Aisheng <[email protected]>
The anatop registers are accessed via syscon now, no one will use mfd anatop driver anymore, remove it.
--- drivers/mfd/Kconfig | 8 --- drivers/mfd/Makefile | 1 - drivers/mfd/anatop-mfd.c | 124 -------------------------------------------- include/linux/mfd/anatop.h | 40 -------------- 4 files changed, 0 insertions(+), 173 deletions(-)
drivers/mfd/Kconfig +0 -8
@@ -985,14 +985,6 @@ config MFD_STA2X11 depends on STA2X11 select MFD_CORE -config MFD_ANATOP - bool "Support for Freescale i.MX on-chip ANATOP controller" - depends on SOC_IMX6Q - help - Select this option to enable Freescale i.MX on-chip ANATOP - MFD controller. This controller embeds regulator and - thermal devices for Freescale i.MX platforms. - config MFD_SYSCON bool "System Controller Register R/W Based on Regmap" select REGMAP_MMIO
drivers/mfd/Makefile +0 -1
@@ -130,6 +130,5 @@ obj-$(CONFIG_MFD_INTEL_MSIC) += intel_msic.o obj-$(CONFIG_MFD_PALMAS) += palmas.o obj-$(CONFIG_MFD_RC5T583) += rc5t583.o rc5t583-irq.o obj-$(CONFIG_MFD_SEC_CORE) += sec-core.o sec-irq.o -obj-$(CONFIG_MFD_ANATOP) += anatop-mfd.o obj-$(CONFIG_MFD_SYSCON) += syscon.o obj-$(CONFIG_MFD_LM3533) += lm3533-core.o lm3533-ctrlbank.o
drivers/mfd/anatop-mfd.c deleted +0 -124
124 lines not on this page · raw message
include/linux/mfd/anatop.h deleted +0 -40
@@ -1,40 +0,0 @@ -/* -* anatop.h - Anatop MFD driver -* -* Copyright (C) 2012 Ying-Chun Liu (PaulLiu) <[email protected]> -* Copyright (C) 2012 Linaro -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -#ifndef __LINUX_MFD_ANATOP_H -#define __LINUX_MFD_ANATOP_H - -#include <linux/spinlock.h> - -/** -* anatop - MFD data -* @ioreg: ioremap register -* @reglock: spinlock for register read/write -*/ -struct anatop { -void *ioreg; -spinlock_t reglock; -}; - -extern u32 anatop_read_reg (struct anatop *,u32 ); -extern void anatop_write_reg (struct anatop *,u32 ,u32 ,u32 ); - -#endif /* __LINUX_MFD_ANATOP_H */
Signature · 1 line
1.7.0.4
Re: [PATCH v2 1/7] mfd: add syscon driver based on regmap
In reply to Dong AishengQuoted 10 lines · Dong Aisheng
From: Dong Aisheng <[email protected]>
Add regmap based syscon driver.
This is usually used for access misc bits in registers which does not belong to a specific module, for example, IMX IOMUXC GPR and ANATOP. With this driver, client can use generic regmap API to access registers which are registered into syscon.Reviwed-by Mark Brown <[email protected]>Signed-off-by Dong Aisheng <[email protected]>
Quoted 8 lines
---
ChangeLog:v1->v2:
* provide a way of retrieving the regmap, suggested by Mark Brown.
* delete imx-syscon io accessors and using generic regmap API for client drivers.
* change to a more generic name for other SoCs to use.--- .../devicetree/bindings/mfd/imx-syscon.txt | 11 ++
So, this file should be renamed as well.
Quoted 125 lines
drivers/mfd/Kconfig | 7 + drivers/mfd/Makefile | 1 + drivers/mfd/syscon.c | 169 ++++++++++++++++++++ include/linux/mfd/syscon.h | 22 +++ 5 files changed, 210 insertions(+), 0 deletions(-)Documentation/devicetree/bindings/mfd/imx-syscon.txt new file +11
-0@@ -0,0 +1,11 @@ +* System Controller Registers R/W driver + +Required properties: +- compatible: Should contain "syscon". +- reg: the register range can be access from syscon + +Examples: +gpr: iomuxc-gpr at 020e0000 { + compatible = "fsl,imx6q-iomuxc", "syscon"; + reg = <0x020e0000 0x38>; +};drivers/mfd/Kconfig +7
-0@@ -993,6 +993,13 @@ config MFD_ANATOP MFD controller. This controller embeds regulator and thermal devices for Freescale i.MX platforms. +config MFD_SYSCON + bool "System Controller Register R/W Based on Regmap" + select REGMAP_MMIO + help + Select this option to enable accessing system control registers + via regmap. + config MFD_PALMAS bool "Support for the TI Palmas series chips" select MFD_COREdrivers/mfd/Makefile +1
-0@@ -131,4 +131,5 @@ obj-$(CONFIG_MFD_PALMAS) += palmas.o obj-$(CONFIG_MFD_RC5T583) += rc5t583.o rc5t583-irq.o obj-$(CONFIG_MFD_SEC_CORE) += sec-core.o sec-irq.o obj-$(CONFIG_MFD_ANATOP) += anatop-mfd.o +obj-$(CONFIG_MFD_SYSCON) += syscon.o obj-$(CONFIG_MFD_LM3533) += lm3533-core.o lm3533-ctrlbank.odrivers/mfd/syscon.c new file +68
-0@@ -0,0 +1,169 @@ +/* +* System Control Driver +* +* Copyright (C) 2012 Freescale Semiconductor, Inc. +* Copyright (C) 2012 Linaro Ltd. +* +* Author: Dong Aisheng <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include <linux/err.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_platform.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +static struct platform_driver syscon_driver; + +struct syscon { +struct device *dev; +void __iomem *base; +struct regmap *regmap; +}; + +static int syscon_match (struct device *dev,void *data) +{ +struct syscon *syscon =dev_get_drvdata (dev); +struct device_node *dn = data; + +return (syscon->dev->of_node == dn) ?1 :0 ; +} + +static struct regmap *syscon_node_to_regmap (struct device_node *np) +{ +struct syscon *syscon; +struct device *dev; + + dev =driver_find_device (&syscon_driver.driver,NULL , np, + syscon_match); +of_node_put (np); + +if (!dev) +return ERR_PTR (-EPROBE_DEFER ); + + syscon =dev_get_drvdata (dev); + +return syscon->regmap; +} + +struct regmap *syscon_regmap_lookup_by_compatible (const char *s) +{ +struct device_node *syscon_np; + + syscon_np =of_find_compatible_node (NULL ,NULL , s); +if (!syscon_np) +return ERR_PTR (-ENODEV ); + +return syscon_node_to_regmap (syscon_np); +} + +struct regmap *syscon_regmap_lookup_by_phandle(struct device_node *np,
drivers/mfd/syscon.c line 78
Quoted 10 lines
drivers/mfd/syscon.c new file +10
-0+ const char *property) +{ +struct device_node *syscon_np; + + syscon_np =of_parse_phandle (np, property,0 ); +if (!syscon_np) +return ERR_PTR (-ENODEV ); + +return syscon_node_to_regmap (syscon_np); +}
The above two APIs are all about finding the device_node for syscon, and can be done by clients in whatever way that is easy for them. Then we can save these APIs and export syscon_node_to_regmap directly.
Quoted 73 lines
drivers/mfd/syscon.c new file +73
-0+ +static const struct of_device_id of_syscon_match[] = { + { .compatible ="syscon" , }, + { }, +}; + +static struct regmap_config syscon_regmap_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; + +static int __devinit syscon_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +struct syscon *syscon; +struct resource res; +int ret; + +if (!np) +return -ENOENT ; + + syscon =devm_kzalloc (&pdev->dev,sizeof (struct syscon ), +GFP_KERNEL ); +if (!syscon) +return -ENOMEM ; + + syscon->base =of_iomap (np,0 ); +if (!syscon->base) +return -EADDRNOTAVAIL ; + + ret =of_address_to_resource (np,0 , &res); +if (ret) +return ret; + + syscon_regmap_config.max_register = res.end - res.start -3 ; + syscon->regmap =devm_regmap_init_mmio (&pdev->dev, syscon->base, + &syscon_regmap_config); +if (IS_ERR (syscon->regmap)) { +dev_err (&pdev->dev,"regmap init failed\n" ); +return PTR_ERR (syscon->regmap); + } + +regcache_cache_only (syscon->regmap, false); + + syscon->dev = &pdev->dev; +platform_set_drvdata (pdev, syscon); + +dev_info (dev,"syscon regmap start 0x%x end 0x%x registered\n" , + res.start, res.end); + +return 0 ; +} + +static int __devexit syscon_remove(struct platform_device *pdev) +{ +struct syscon *syscon; + + syscon =platform_get_drvdata (pdev); +iounmap (syscon->base); +platform_set_drvdata (pdev,NULL ); + +return 0 ; +} + +static struct platform_driver syscon_driver = { + .driver = { + .name ="syscon" , + .owner =THIS_MODULE , + .of_match_table = of_syscon_match, + }, + .probe = syscon_probe,
drivers/mfd/syscon.c line 161
Quoted 10 lines
drivers/mfd/syscon.c new file +10
-0+ .remove = syscon_remove, +}; + +static int __init syscon_init (void ) +{ +return platform_driver_register (&syscon_driver); +} +postcore_initcall (syscon_init); + +static void __exit anatop_exit(void)
s/anatop_exit/syscon_exit
drivers/mfd/syscon.c line 165
Quoted 4 lines
drivers/mfd/syscon.c new file +4
-0+{ +platform_driver_unregister (&syscon_driver); +} +module_exit (anatop_exit);
Ditto.
Regards,
Shawn
Quoted 36 lines
drivers/mfd/syscon.c new file +4
-0+ +MODULE_AUTHOR ("Dong Aisheng <[email protected]>" ); +MODULE_DESCRIPTION ("System Control driver" ); +MODULE_LICENSE ("GPL v2" );include/linux/mfd/syscon.h new file +22
-0@@ -0,0 +1,22 @@ +/* +* System Control Driver +* +* Copyright (C) 2012 Freescale Semiconductor, Inc. +* Copyright (C) 2012 Linaro Ltd. +* +* Author: Dong Aisheng <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#ifndef __LINUX_MFD_SYSCON_H__ +#define __LINUX_MFD_SYSCON_H__ + +extern struct regmap *syscon_regmap_lookup_by_compatible (const char *s); +extern struct regmap *syscon_regmap_lookup_by_phandle ( +struct device_node *np, +const char *property); +#endif /* __LINUX_MFD_SYSCON_H__ */ Signature · 1 line
1.7.0.4
Re: [PATCH v2 4/7] regulator: anatop-regulator: convert to use syscon to access anatop register
In reply to Dong AishengQuoted 161 lines · Dong Aisheng
From: Dong Aisheng <[email protected]>
Using syscon to access anatop register.
Acked-by Mark Brown <[email protected]>Signed-off-by Dong Aisheng <[email protected]>---
ChangeLog v1-v2:
* update to use generic regmap api--- arch/arm/boot/dts/imx6q.dtsi | 6 ++++++ drivers/regulator/Kconfig | 2 +- drivers/regulator/anatop-regulator.c | 25 +++++++++++++++---------- 3 files changed, 22 insertions(+), 11 deletions(-)arch/arm/boot/dts/imx6q.dtsi +6
-0@@ -395,6 +395,7 @@ anatop-min-bit-val = <4>; anatop-min-voltage = <800000>; anatop-max-voltage = <1375000>; + fsl,anatop = <&anatop>; }; regulator-3p0 at 120 {@@ -409,6 +410,7 @@ anatop-min-bit-val = <0>; anatop-min-voltage = <2625000>; anatop-max-voltage = <3400000>; + fsl,anatop = <&anatop>; }; regulator-2p5 at 130 {@@ -423,6 +425,7 @@ anatop-min-bit-val = <0>; anatop-min-voltage = <2000000>; anatop-max-voltage = <2750000>; + fsl,anatop = <&anatop>; }; regulator-vddcore at 140 {@@ -437,6 +440,7 @@ anatop-min-bit-val = <1>; anatop-min-voltage = <725000>; anatop-max-voltage = <1450000>; + fsl,anatop = <&anatop>; }; regulator-vddpu at 140 {@@ -451,6 +455,7 @@ anatop-min-bit-val = <1>; anatop-min-voltage = <725000>; anatop-max-voltage = <1450000>; + fsl,anatop = <&anatop>; }; regulator-vddsoc at 140 {@@ -465,6 +470,7 @@ anatop-min-bit-val = <1>; anatop-min-voltage = <725000>; anatop-max-voltage = <1450000>; + fsl,anatop = <&anatop>; }; };drivers/regulator/Kconfig +1
-1@@ -112,7 +112,7 @@ config REGULATOR_DA9052 config REGULATOR_ANATOP tristate "Freescale i.MX on-chip ANATOP LDO regulators" - depends on MFD_ANATOP + depends on MFD_SYSCON help Say y here to support Freescale i.MX on-chip ANATOP LDOs regulators. It is recommended that this option bedrivers/regulator/anatop-regulator.c +10
-9@@ -21,19 +21,20 @@#include <linux/slab.h> #include <linux/device.h> #include <linux/module.h> +#include <linux/mfd/syscon.h> #include <linux/err.h> #include <linux/io.h> #include <linux/platform_device.h> #include <linux/of.h> #include <linux/of_address.h> -#include <linux/mfd/anatop.h> +#include <linux/regmap.h> #include <linux/regulator/driver.h> #include <linux/regulator/of_regulator.h> struct anatop_regulator {const char *name;u32 control_reg; -struct anatop *mfd; +struct regmap *anatop;int vol_bit_shift;int vol_bit_width;int min_bit_val;@@ -43,7 +44,7 @@ struct anatop_regulator {struct regulator_init_data *initdata; }; -static int anatop_set_voltage_sel (struct regulator_dev *reg,unsigned selector) +static int anatop_regmap_set_voltage_sel (struct regulator_dev *reg,unsigned selector) {struct anatop_regulator *anatop_reg =rdev_get_drvdata (reg);u32 val, mask;@@ -56,12 +57,13 @@ static int anatop_set_voltage_sel(struct regulator_dev *reg, unsigned selector) mask = ((1 << anatop_reg->vol_bit_width) -1 ) << anatop_reg->vol_bit_shift; val <<= anatop_reg->vol_bit_shift; -anatop_write_reg (anatop_reg->mfd, anatop_reg->control_reg, val, mask); +regmap_update_bits (anatop_reg->anatop, anatop_reg->control_reg, + mask, val);return 0 ; } -static int anatop_get_voltage_sel (struct regulator_dev *reg) +static int anatop_regmap_get_voltage_sel (struct regulator_dev *reg) {struct anatop_regulator *anatop_reg =rdev_get_drvdata (reg);u32 val, mask;@@ -69,7 +71,7 @@ static int anatop_get_voltage_sel(struct regulator_dev *reg)if (!anatop_reg->control_reg)return -ENOTSUPP ; - val =anatop_read_reg (anatop_reg->mfd, anatop_reg->control_reg); +regmap_read (anatop_reg->anatop, anatop_reg->control_reg, &val); mask = ((1 << anatop_reg->vol_bit_width) -1 ) << anatop_reg->vol_bit_shift; val = (val & mask) >> anatop_reg->vol_bit_shift;@@ -78,8 +80,8 @@ static int anatop_get_voltage_sel(struct regulator_dev *reg) }static struct regulator_ops anatop_rops = { - .set_voltage_sel = anatop_set_voltage_sel, - .get_voltage_sel = anatop_get_voltage_sel, + .set_voltage_sel = anatop_regmap_set_voltage_sel, + .get_voltage_sel = anatop_regmap_get_voltage_sel, .list_voltage = regulator_list_voltage_linear, .map_voltage = regulator_map_voltage_linear, };@@ -92,7 +94,6 @@ static int __devinit anatop_regulator_probe(struct platform_device *pdev)struct regulator_dev *rdev;struct anatop_regulator *sreg;struct regulator_init_data *initdata; -struct anatop *anatopmfd =dev_get_drvdata (pdev->dev.parent);struct regulator_config config = { };int ret =0 ;
drivers/regulator/anatop-regulator.c static int __devinit anatop_regulator_probe(struct platform_device *pdev) · line 117
Quoted 9 lines
drivers/regulator/anatop-regulator.c +5
-1@@ -109,7 +110,11 @@ static int __devinit anatop_regulator_probe(struct platform_device *pdev) rdesc->ops = &anatop_rops; rdesc->type =REGULATOR_VOLTAGE ; rdesc->owner =THIS_MODULE ; - sreg->mfd = anatopmfd; + + sreg->anatop =syscon_regmap_lookup_by_phandle (np,"fsl,anatop" ); +if (IS_ERR (sreg->anatop)) +return PTR_ERR (sreg->anatop); +
All the anatop regulators are child nodes of anatop. It looks a little odd to use phandle there. of_get_parent should just works.
Quoted 7 lines
drivers/regulator/anatop-regulator.c +0
-0ret =of_property_read_u32 (np,"anatop-reg-offset" , &sreg->control_reg);if (ret) {Signature · 1 line
1.7.0.4
Signature · 2 lines
Regards, Shawn
Re: [PATCH v2 1/7] mfd: add syscon driver based on regmap
In reply to Shawn GuoQuoted 20 lines · Shawn Guo
Quoted 10 lines · Dong Aisheng
From: Dong Aisheng <[email protected]>
Add regmap based syscon driver.
This is usually used for access misc bits in registers which does not belong to a specific module, for example, IMX IOMUXC GPR and ANATOP. With this driver, client can use generic regmap API to access registers which are registered into syscon.Reviwed-by Mark Brown <[email protected]>Signed-off-by Dong Aisheng <[email protected]>Quoted 8 lines
---
ChangeLog:v1->v2:
* provide a way of retrieving the regmap, suggested by Mark Brown.
* delete imx-syscon io accessors and using generic regmap API for client drivers.
* change to a more generic name for other SoCs to use.--- .../devicetree/bindings/mfd/imx-syscon.txt | 11 ++
Quoted 2 lines
So, this file should be renamed as well.
Correct.
I missed it, thanks for reminder.
Quoted 131 lines
Quoted 131 lines
drivers/mfd/Kconfig | 7 + drivers/mfd/Makefile | 1 + drivers/mfd/syscon.c | 169 ++++++++++++++++++++ include/linux/mfd/syscon.h | 22 +++ 5 files changed, 210 insertions(+), 0 deletions(-)Documentation/devicetree/bindings/mfd/imx-syscon.txt new file +11
-0@@ -0,0 +1,11 @@ +* System Controller Registers R/W driver + +Required properties: +- compatible: Should contain "syscon". +- reg: the register range can be access from syscon + +Examples: +gpr: iomuxc-gpr at 020e0000 { + compatible = "fsl,imx6q-iomuxc", "syscon"; + reg = <0x020e0000 0x38>; +};drivers/mfd/Kconfig +7
-0@@ -993,6 +993,13 @@ config MFD_ANATOP MFD controller. This controller embeds regulator and thermal devices for Freescale i.MX platforms. +config MFD_SYSCON + bool "System Controller Register R/W Based on Regmap" + select REGMAP_MMIO + help + Select this option to enable accessing system control registers + via regmap. + config MFD_PALMAS bool "Support for the TI Palmas series chips" select MFD_COREdrivers/mfd/Makefile +1
-0@@ -131,4 +131,5 @@ obj-$(CONFIG_MFD_PALMAS) += palmas.o obj-$(CONFIG_MFD_RC5T583) += rc5t583.o rc5t583-irq.o obj-$(CONFIG_MFD_SEC_CORE) += sec-core.o sec-irq.o obj-$(CONFIG_MFD_ANATOP) += anatop-mfd.o +obj-$(CONFIG_MFD_SYSCON) += syscon.o obj-$(CONFIG_MFD_LM3533) += lm3533-core.o lm3533-ctrlbank.odrivers/mfd/syscon.c new file +74
-0@@ -0,0 +1,169 @@ +/* +* System Control Driver +* +* Copyright (C) 2012 Freescale Semiconductor, Inc. +* Copyright (C) 2012 Linaro Ltd. +* +* Author: Dong Aisheng <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#include <linux/err.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/of_platform.h> +#include <linux/platform_device.h> +#include <linux/regmap.h> + +static struct platform_driver syscon_driver; + +struct syscon { +struct device *dev; +void __iomem *base; +struct regmap *regmap; +}; + +static int syscon_match (struct device *dev,void *data) +{ +struct syscon *syscon =dev_get_drvdata (dev); +struct device_node *dn = data; + +return (syscon->dev->of_node == dn) ?1 :0 ; +} + +static struct regmap *syscon_node_to_regmap (struct device_node *np) +{ +struct syscon *syscon; +struct device *dev; + + dev =driver_find_device (&syscon_driver.driver,NULL , np, + syscon_match); +of_node_put (np); + +if (!dev) +return ERR_PTR (-EPROBE_DEFER ); + + syscon =dev_get_drvdata (dev); + +return syscon->regmap; +} + +struct regmap *syscon_regmap_lookup_by_compatible (const char *s) +{ +struct device_node *syscon_np; + + syscon_np =of_find_compatible_node (NULL ,NULL , s); +if (!syscon_np) +return ERR_PTR (-ENODEV ); + +return syscon_node_to_regmap (syscon_np); +} + +struct regmap *syscon_regmap_lookup_by_phandle (struct device_node *np, +const char *property) +{ +struct device_node *syscon_np; + + syscon_np =of_parse_phandle (np, property,0 ); +if (!syscon_np)
Quoted 9 lines
drivers/mfd/syscon.c line 66
Quoted 4 lines
drivers/mfd/syscon.c new file +4
-0+return ERR_PTR (-ENODEV ); + +return syscon_node_to_regmap (syscon_np); +}The above two APIs are all about finding the
device_nodefor syscon, and can be done by clients in whatever way that is easy for them. Then we can save these APIs and exportsyscon_node_to_regmapdirectly.
Yes, we probably should also export syscon_node_to_regmap. For other two, since they're common to be used, i prefer to keep them too for user to choose to use, it saves client to write duplicate code.
Quoted 86 lines
Quoted 73 lines
drivers/mfd/syscon.c new file +73
-0+ +static const struct of_device_id of_syscon_match[] = { + { .compatible ="syscon" , }, + { }, +}; + +static struct regmap_config syscon_regmap_config = { + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , +}; + +static int __devinit syscon_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +struct syscon *syscon; +struct resource res; +int ret; + +if (!np) +return -ENOENT ; + + syscon =devm_kzalloc (&pdev->dev,sizeof (struct syscon ), +GFP_KERNEL ); +if (!syscon) +return -ENOMEM ; + + syscon->base =of_iomap (np,0 ); +if (!syscon->base) +return -EADDRNOTAVAIL ; + + ret =of_address_to_resource (np,0 , &res); +if (ret) +return ret; + + syscon_regmap_config.max_register = res.end - res.start -3 ; + syscon->regmap =devm_regmap_init_mmio (&pdev->dev, syscon->base, + &syscon_regmap_config); +if (IS_ERR (syscon->regmap)) { +dev_err (&pdev->dev,"regmap init failed\n" ); +return PTR_ERR (syscon->regmap); + } + +regcache_cache_only (syscon->regmap, false); + + syscon->dev = &pdev->dev; +platform_set_drvdata (pdev, syscon); + +dev_info (dev,"syscon regmap start 0x%x end 0x%x registered\n" , + res.start, res.end); + +return 0 ; +} + +static int __devexit syscon_remove(struct platform_device *pdev) +{ +struct syscon *syscon; + + syscon =platform_get_drvdata (pdev); +iounmap (syscon->base); +platform_set_drvdata (pdev,NULL ); + +return 0 ; +} + +static struct platform_driver syscon_driver = { + .driver = { + .name ="syscon" , + .owner =THIS_MODULE , + .of_match_table = of_syscon_match, + }, + .probe = syscon_probe,drivers/mfd/syscon.c line 161
Quoted 10 lines
drivers/mfd/syscon.c new file +10
-0+ .remove = syscon_remove, +}; + +static int __init syscon_init (void ) +{ +return platform_driver_register (&syscon_driver); +} +postcore_initcall (syscon_init); + +static void __exit anatop_exit(void)s/anatop_exit/syscon_exit
Quoted 7 lines
drivers/mfd/syscon.c line 165
Quoted 4 lines
drivers/mfd/syscon.c new file +4
-0+{ +platform_driver_unregister (&syscon_driver); +} +module_exit (anatop_exit);Ditto.
Correct, Thanks.
Will fix those typo in updated patches.
Regards
Dong Aisheng
Quoted 37 lines
Quoted 36 lines
drivers/mfd/syscon.c new file +4
-0+ +MODULE_AUTHOR ("Dong Aisheng <[email protected]>" ); +MODULE_DESCRIPTION ("System Control driver" ); +MODULE_LICENSE ("GPL v2" );include/linux/mfd/syscon.h new file +22
-0@@ -0,0 +1,22 @@ +/* +* System Control Driver +* +* Copyright (C) 2012 Freescale Semiconductor, Inc. +* Copyright (C) 2012 Linaro Ltd. +* +* Author: Dong Aisheng <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*/ + +#ifndef __LINUX_MFD_SYSCON_H__ +#define __LINUX_MFD_SYSCON_H__ + +extern struct regmap *syscon_regmap_lookup_by_compatible (const char *s); +extern struct regmap *syscon_regmap_lookup_by_phandle ( +struct device_node *np, +const char *property); +#endif /* __LINUX_MFD_SYSCON_H__ */ Signature · 1 line
1.7.0.4
Re: [PATCH v2 4/7] regulator: anatop-regulator: convert to use syscon to access anatop register
In reply to Shawn GuoOn Tue, Aug 28, 2012 at 06:15:35AM +0800, Shawn Guo wrote:
....
Quoted 8 lines
drivers/regulator/anatop-regulator.c static int __devinit anatop_regulator_probe(struct platform_device *pdev) · line 117
Quoted 4 lines
drivers/regulator/anatop-regulator.c +4
-0+ sreg->anatop =syscon_regmap_lookup_by_phandle (np,"fsl,anatop" ); +if (IS_ERR (sreg->anatop)) +return PTR_ERR (sreg->anatop); +All the anatop regulators are child nodes of anatop. It looks a little odd to use phandle there.
of_get_parentshould just works.
Yes, this is a special case.
It's also ok for me to use of_get_parent if you want. Will update it.
Regards
Dong Aisheng
Re: [PATCH v2 5/7] ARM: imx6q: convert to use syscon to access anatop registers
In reply to Dong AishengQuoted 42 lines · Dong Aisheng
From: Dong Aisheng <[email protected]>
Using syscon to access anatop registers.
Signed-off-by Dong Aisheng <[email protected]>---
ChangeLogv1->v2:
* update to use generic regmap api--- arch/arm/mach-imx/Kconfig | 2 +- arch/arm/mach-imx/mach-imx6q.c | 43 ++++++++++++++++----------------------- 2 files changed, 19 insertions(+), 26 deletions(-)arch/arm/mach-imx/Kconfig +1
-1@@ -839,7 +839,7 @@ config SOC_IMX6Q select HAVE_IMX_MMDC select HAVE_IMX_SRC select HAVE_SMP - select MFD_ANATOP + select MFD_SYSCON select PINCTRL select PINCTRL_IMX6Qarch/arm/mach-imx/mach-imx6q.c +2
-1@@ -24,8 +24,9 @@#include <linux/of_platform.h> #include <linux/pinctrl/machine.h> #include <linux/phy.h> +#include <linux/regmap.h> #include <linux/micrel_phy.h> -#include <linux/mfd/anatop.h> +#include <linux/mfd/syscon.h> #include <asm/cpuidle.h> #include <asm/smp_twd.h> #include <asm/hardware/cache-l2x0.h>
arch/arm/mach-imx/mach-imx6q.c static void __init imx6q_sabrelite_init(void) · line 127
Quoted 8 lines
arch/arm/mach-imx/mach-imx6q.c +1
-2@@ -121,38 +122,30 @@ static void __init imx6q_sabrelite_init(void)static void __init imx6q_usb_init (void ) {struct device_node *np; -struct platform_device *pdev =NULL ; -struct anatop *adata =NULL ; +struct regmap *anatop; np =of_find_compatible_node (NULL ,NULL ,"fsl,imx6q-anatop" );
np unused.
Quoted 35 lines
arch/arm/mach-imx/mach-imx6q.c +7
-22-if (np) - pdev =of_find_device_by_node (np); -if (pdev) - adata =platform_get_drvdata (pdev); -if (!adata) { -if (np) -of_node_put (np); -return ; - } -#define HW_ANADIG_USB1_CHRG_DETECT 0x000001b0#define HW_ANADIG_USB2_CHRG_DETECT 0x00000210#define BM_ANADIG_USB_CHRG_DETECT_EN_B 0x00100000#define BM_ANADIG_USB_CHRG_DETECT_CHK_CHRG_B 0x00080000 -/* -* The external charger detector needs to be disabled, -* or the signal at DP will be poor -*/ -anatop_write_reg (adata,HW_ANADIG_USB1_CHRG_DETECT , -BM_ANADIG_USB_CHRG_DETECT_EN_B - |BM_ANADIG_USB_CHRG_DETECT_CHK_CHRG_B , - ~0 ); -anatop_write_reg (adata,HW_ANADIG_USB2_CHRG_DETECT , -BM_ANADIG_USB_CHRG_DETECT_EN_B | -BM_ANADIG_USB_CHRG_DETECT_CHK_CHRG_B , - ~0 ); + anatop =syscon_regmap_lookup_by_compatible ("fsl,imx6q-anatop" ); +if (!IS_ERR (anatop)) { +/* +* The external charger detector needs to be disabled, +* or the signal at DP will be poor +*/ + regmap_write(anatop, HW_ANADIG_USB1_CHRG_DETECT,
arch/arm/mach-imx/mach-imx6q.c static void __init imx6q_sabrelite_init(void) · line 150
Quoted 10 lines
arch/arm/mach-imx/mach-imx6q.c +8
-0+BM_ANADIG_USB_CHRG_DETECT_EN_B + | BM_ANADIG_USB_CHRG_DETECT_CHK_CHRG_B); +regmap_write (anatop,HW_ANADIG_USB2_CHRG_DETECT , +BM_ANADIG_USB_CHRG_DETECT_EN_B | +BM_ANADIG_USB_CHRG_DETECT_CHK_CHRG_B ); + }else { +pr_warn ("failed to find fsl,imx6q-anatop regmap\n" ); + }of_node_put (np);
unneeded.
Thanks
Richard
Quoted 4 lines
arch/arm/mach-imx/mach-imx6q.c +0
-0}Signature · 1 line
1.7.0.4
Re: [PATCH v2 5/7] ARM: imx6q: convert to use syscon to access anatop registers
On Tue, Aug 28, 2012 at 11:23:10AM +0800, Zhao Richard-B20223 wrote:
...
Quoted 2 lines
Quoted 1 line
np =
of_find_compatible_node(NULL, NULL, "fsl,imx6q-anatop");np unused.
Correct.
Will drop it.
Regards
Dong Aisheng