Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bus: imx-weim: support CS GPR configuration

For imx50-weim and imx6q-weim type of devices, there might a WEIM CS
space configuration register in General Purpose Register controller,
e.g. IOMUXC_GPR1 on i.MX6Q.

Depending on which configuration of the following 4 is chosen for given
system, IOMUXC_GPR1[11:0] should be set up as 05, 033, 0113 or 01111
correspondingly.

CS0(128M) CS1(0M) CS2(0M) CS3(0M)
CS0(64M) CS1(64M) CS2(0M) CS3(0M)
CS0(64M) CS1(32M) CS2(32M) CS3(0M)
CS0(32M) CS1(32M) CS2(32M) CS3(32M)

The patch creates a function for such type of devices, which scans
'ranges' property of WEIM node and build the GPR value incrementally.
Thus the WEIM CS GPR can be set up automatically at boot time.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Reviewed-by: Philippe De Muyter <phdm@macqel.be>
Tested-by: Philippe De Muyter <phdm@macqel.be>

Shawn Guo 8d9ee21e 7899d7d5

+85 -1
+27 -1
Documentation/devicetree/bindings/bus/imx-weim.txt
··· 8 8 9 9 Required properties: 10 10 11 - - compatible: Should be set to "fsl,<soc>-weim" 11 + - compatible: Should contain one of the following: 12 + "fsl,imx1-weim" 13 + "fsl,imx27-weim" 14 + "fsl,imx51-weim" 15 + "fsl,imx50-weim" 16 + "fsl,imx6q-weim" 12 17 - reg: A resource specifier for the register space 13 18 (see the example below) 14 19 - clocks: the clock, see the example below. ··· 23 18 integer values for each chip-select line in use: 24 19 25 20 <cs-number> 0 <physical address of mapping> <size> 21 + 22 + Optional properties: 23 + 24 + - fsl,weim-cs-gpr: For "fsl,imx50-weim" and "fsl,imx6q-weim" type of 25 + devices, it should be the phandle to the system General 26 + Purpose Register controller that contains WEIM CS GPR 27 + register, e.g. IOMUXC_GPR1 on i.MX6Q. IOMUXC_GPR1[11:0] 28 + should be set up as one of the following 4 possible 29 + values depending on the CS space configuration. 30 + 31 + IOMUXC_GPR1[11:0] CS0 CS1 CS2 CS3 32 + --------------------------------------------- 33 + 05 128M 0M 0M 0M 34 + 033 64M 64M 0M 0M 35 + 0113 64M 32M 32M 0M 36 + 01111 32M 32M 32M 32M 37 + 38 + In case that the property is absent, the reset value or 39 + what bootloader sets up in IOMUXC_GPR1[11:0] will be 40 + used. 26 41 27 42 Timing property for child nodes. It is mandatory, not optional. 28 43 ··· 68 43 #address-cells = <2>; 69 44 #size-cells = <1>; 70 45 ranges = <0 0 0x08000000 0x08000000>; 46 + fsl,weim-cs-gpr = <&gpr>; 71 47 72 48 nor@0,0 { 73 49 compatible = "cfi-flash";
+58
drivers/bus/imx-weim.c
··· 11 11 #include <linux/clk.h> 12 12 #include <linux/io.h> 13 13 #include <linux/of_device.h> 14 + #include <linux/mfd/syscon.h> 15 + #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h> 16 + #include <linux/regmap.h> 14 17 15 18 struct imx_weim_devtype { 16 19 unsigned int cs_count; ··· 59 56 }; 60 57 MODULE_DEVICE_TABLE(of, weim_id_table); 61 58 59 + static int __init imx_weim_gpr_setup(struct platform_device *pdev) 60 + { 61 + struct device_node *np = pdev->dev.of_node; 62 + struct property *prop; 63 + const __be32 *p; 64 + struct regmap *gpr; 65 + u32 gprvals[4] = { 66 + 05, /* CS0(128M) CS1(0M) CS2(0M) CS3(0M) */ 67 + 033, /* CS0(64M) CS1(64M) CS2(0M) CS3(0M) */ 68 + 0113, /* CS0(64M) CS1(32M) CS2(32M) CS3(0M) */ 69 + 01111, /* CS0(32M) CS1(32M) CS2(32M) CS3(32M) */ 70 + }; 71 + u32 gprval = 0; 72 + u32 val; 73 + int cs = 0; 74 + int i = 0; 75 + 76 + gpr = syscon_regmap_lookup_by_phandle(np, "fsl,weim-cs-gpr"); 77 + if (IS_ERR(gpr)) { 78 + dev_dbg(&pdev->dev, "failed to find weim-cs-gpr\n"); 79 + return 0; 80 + } 81 + 82 + of_property_for_each_u32(np, "ranges", prop, p, val) { 83 + if (i % 4 == 0) { 84 + cs = val; 85 + } else if (i % 4 == 3 && val) { 86 + val = (val / SZ_32M) | 1; 87 + gprval |= val << cs * 3; 88 + } 89 + i++; 90 + } 91 + 92 + if (i == 0 || i % 4) 93 + goto err; 94 + 95 + for (i = 0; i < ARRAY_SIZE(gprvals); i++) { 96 + if (gprval == gprvals[i]) { 97 + /* Found it. Set up IOMUXC_GPR1[11:0] with it. */ 98 + regmap_update_bits(gpr, IOMUXC_GPR1, 0xfff, gprval); 99 + return 0; 100 + } 101 + } 102 + 103 + err: 104 + dev_err(&pdev->dev, "Invalid 'ranges' configuration\n"); 105 + return -EINVAL; 106 + } 107 + 62 108 /* Parse and set the timing for this device. */ 63 109 static int __init weim_timing_setup(struct device_node *np, void __iomem *base, 64 110 const struct imx_weim_devtype *devtype) ··· 143 91 const struct imx_weim_devtype *devtype = of_id->data; 144 92 struct device_node *child; 145 93 int ret; 94 + 95 + if (devtype == &imx50_weim_devtype) { 96 + ret = imx_weim_gpr_setup(pdev); 97 + if (ret) 98 + return ret; 99 + } 146 100 147 101 for_each_child_of_node(pdev->dev.of_node, child) { 148 102 if (!child->name)