Skip to contentSkip to conversation

Fix eSDHC host version register bug

PATCH Superseded Yangbo Lu 4 participants 17 messages Sep 6, 2016 – Sep 13, 2016

Subsystems (15)

v11 of 16 Superseded Latest is v16 →

lore
Share & tools
lore

Yangbo Lu

author
#0 lore raw

v11 cover Fix eSDHC host version register bug

This patchset is used to fix a host version register bug in the T4240-R1.0-R2.0 eSDHC controller. To match the SoC version and revision, 10 previous version patchsets had tried many methods but all of them were rejected by reviewers. Such as
- dts compatible method
- syscon method
- ifdef PPC method
- GUTS driver getting SVR method
Anrd suggested a soc_device_match method in v10, and this is the only available method left now. This v11 patchset introduces the soc_device_match interface in soc driver.

The first six patches are to add the GUTS driver. This is used to register a soc device which contain soc version and revision information. The following two patches introduce the soc_device_match method in soc driver and apply it on esdhc driver to fix this bug.

Yangbo Lu (8):
dt: bindings: update Freescale DCFG compatible
ARM64: dts: ls2080a: add device configuration node
dt: bindings: move guts devicetree doc out of powerpc directory powerpc/fsl: move mpc85xx.h to include/linux/fsl
soc: fsl: add GUTS driver for QorIQ platforms
MAINTAINERS: add entry for Freescale SoC drivers
base: soc: introduce soc_device_match() interface
mmc: sdhci-of-esdhc: fix host version for T4240-R1.0-R2.0

 Documentation/devicetree/bindings/arm/fsl.txt      |   6 +-
 .../bindings/{powerpc => soc}/fsl/guts.txt         |   3 +
 MAINTAINERS                                        |  11 +-
 arch/arm64/boot/dts/freescale/fsl-ls2080a.dtsi     |   6 +
 arch/powerpc/kernel/cpu_setup_fsl_booke.S          |   2 +-
 arch/powerpc/sysdev/fsl_pci.c                      |   2 +-
 drivers/base/Kconfig                               |   1 +
 drivers/base/soc.c                                 |  61 +++
 drivers/clk/clk-qoriq.c                            |   3 +-
 drivers/i2c/busses/i2c-mpc.c                       |   2 +-
 drivers/iommu/fsl_pamu.c                           |   3 +-
 drivers/mmc/host/Kconfig                           |   1 +
 drivers/mmc/host/sdhci-of-esdhc.c                  |  20 +
 drivers/net/ethernet/freescale/gianfar.c           |   2 +-
 drivers/soc/Kconfig                                |   2 +-
 drivers/soc/fsl/Kconfig                            |  20 +
 drivers/soc/fsl/Makefile                           |   1 +
 drivers/soc/fsl/guts.c                             | 483 +++++++++++++++++++++
 include/linux/fsl/guts.h                           | 127 ++++--
 .../asm/mpc85xx.h => include/linux/fsl/svr.h       |   4 +-
 include/linux/sys_soc.h                            |   3 +
 21 files changed, 702 insertions(+), 61 deletions(-)
 rename Documentation/devicetree/bindings/{powerpc => soc}/fsl/guts.txt (91%)
 create mode 100644 drivers/soc/fsl/Kconfig
 create mode 100644 drivers/soc/fsl/guts.c
 rename arch/powerpc/include/asm/mpc85xx.h => include/linux/fsl/svr.h (97%)
Signature · 1 line
2.1.0.27.g96db324
author
#1 lore raw

PATCH v11 1/8 dt: bindings: update Freescale DCFG compatible

Update Freescale DCFG compatible with 'fsl,<chip>-dcfg' instead of 'fsl,ls1021a-dcfg' to include more chips such as ls1021a, ls1043a, and ls2080a.

---
Changes for v8:
- Added this patch
Changes for v9:
- Added a list for the possible compatibles
Changes for v10:
- None
Changes for v11:
- Added 'Acked-by: Rob Herring'
- Updated commit message by Scott

---
 Documentation/devicetree/bindings/arm/fsl.txt | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/arm/fsl.txt +5 -1
index dbbc095..713c1ae 100644
@@ -119,7 +119,11 @@ Freescale DCFG
 configuration and status for the device. Such as setting the secondary
 core start address and release the secondary core from holdoff and startup.
   Required properties:
-  - compatible: should be "fsl,ls1021a-dcfg"
+  - compatible: should be "fsl,<chip>-dcfg"
+    Possible compatibles:
+	"fsl,ls1021a-dcfg"
+	"fsl,ls1043a-dcfg"
+	"fsl,ls2080a-dcfg"
   - reg : should contain base address and length of DCFG memory-mapped registers
 
 Example:
Signature · 1 line
2.1.0.27.g96db324
author
#2 lore raw

PATCH v11 2/8 ARM64: dts: ls2080a: add device configuration node

In reply to Yangbo Lu

Add the dts node for device configuration unit that provides general purpose configuration and status for the device.

---
Changes for v5:
- Added this patch
Changes for v6:
- None
Changes for v7:
- None
Changes for v8:
- Added 'Acked-by: Scott Wood'
Changes for v9:
- None
Changes for v10:
- None
Changes for v11:
- None

---
 arch/arm64/boot/dts/freescale/fsl-ls2080a.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm64/boot/dts/freescale/fsl-ls2080a.dtsi +6 -0
index 21023a3..39f7743 100644
@@ -215,6 +215,12 @@
 			clocks = <&sysclk>;
 		};
 
+		dcfg: dcfg at 1e00000 {
+			compatible = "fsl,ls2080a-dcfg", "syscon";
+			reg = <0x0 0x1e00000 0x0 0x10000>;
+			little-endian;
+		};
+
 		serial0: serial at 21c0500 {
 			compatible = "fsl,ns16550", "ns16550a";
 			reg = <0x0 0x21c0500 0x0 0x100>;
Signature · 1 line
2.1.0.27.g96db324
author
#3 lore raw

PATCH v11 3/8 dt: bindings: move guts devicetree doc out of powerpc directory

In reply to Yangbo Lu

Move guts devicetree doc to Documentation/devicetree/bindings/soc/fsl/ since it's used by not only PowerPC but also ARM. And add a specification for 'little-endian' property.

---
Changes for v4:
- Added this patch
Changes for v5:
- Modified the description for little-endian property
Changes for v6:
- None
Changes for v7:
- None
Changes for v8:
- Added 'Acked-by: Scott Wood'
- Added 'Acked-by: Rob Herring'
Changes for v9:
- None
Changes for v10:
- None
Changes for v11:
- None

---
 Documentation/devicetree/bindings/{powerpc => soc}/fsl/guts.txt | 3 +++
 1 file changed, 3 insertions(+)
 rename Documentation/devicetree/bindings/{powerpc => soc}/fsl/guts.txt (91%)
Documentation/devicetree/bindings/soc/fsl/guts.txt renamed from Documentation/devicetree/bindings/powerpc/fsl/guts.txt +3 -0
similarity index 91%
rename from Documentation/devicetree/bindings/powerpc/fsl/guts.txt
rename to Documentation/devicetree/bindings/soc/fsl/guts.txt
index b71b203..07adca9 100644
@@ -25,6 +25,9 @@ Recommended properties:
  - fsl,liodn-bits : Indicates the number of defined bits in the LIODN
    registers, for those SOCs that have a PAMU device.
 
+ - little-endian : Indicates that the global utilities block is little
+   endian. The default is big endian.
+
 Examples:
 	global-utilities at e0000 {	/* global utilities block */
 		compatible = "fsl,mpc8548-guts";
Signature · 1 line
2.1.0.27.g96db324
author
#4 lore raw

PATCH v11 4/8 powerpc/fsl: move mpc85xx.h to include/linux/fsl

In reply to Yangbo Lu

Move mpc85xx.h to include/linux/fsl and rename it to svr.h as a common header file. This SVR numberspace is used on some ARM chips as well as PPC, and even to check for a PPC SVR multi-arch drivers would otherwise need to ifdef the header inclusion and all references to the SVR symbols.

---
Changes for v2:
- None
Changes for v3:
- None
Changes for v4:
- None
Changes for v5:
- Changed to Move mpc85xx.h to include/linux/fsl/
- Adjusted '#include <linux/fsl/svr.h>' position in file
Changes for v6:
- None
Changes for v7:
- Added 'Acked-by: Wolfram Sang' for I2C part
- Also applied to arch/powerpc/kernel/cpu_setup_fsl_booke.S
Changes for v8:
- Added 'Acked-by: Stephen Boyd' for clk part
- Added 'Acked-by: Scott Wood'
- Added 'Acked-by: Joerg Roedel' for iommu part
Changes for v9:
- None
Changes for v10:
- None
Changes for v11:
- Updated description by Scott

---
 arch/powerpc/kernel/cpu_setup_fsl_booke.S                     | 2 +-
 arch/powerpc/sysdev/fsl_pci.c                                 | 2 +-
 drivers/clk/clk-qoriq.c                                       | 3 +--
 drivers/i2c/busses/i2c-mpc.c                                  | 2 +-
 drivers/iommu/fsl_pamu.c                                      | 3 +--
 drivers/net/ethernet/freescale/gianfar.c                      | 2 +-
 arch/powerpc/include/asm/mpc85xx.h => include/linux/fsl/svr.h | 4 ++--
 7 files changed, 8 insertions(+), 10 deletions(-)
 rename arch/powerpc/include/asm/mpc85xx.h => include/linux/fsl/svr.h (97%)
arch/powerpc/kernel/cpu_setup_fsl_booke.S +1 -1
index 462aed9..2b0284e 100644
@@ -13,13 +13,13 @@
  *
  */
 
+#include <linux/fsl/svr.h>
 #include <asm/page.h>
 #include <asm/processor.h>
 #include <asm/cputable.h>
 #include <asm/ppc_asm.h>
 #include <asm/mmu-book3e.h>
 #include <asm/asm-offsets.h>
-#include <asm/mpc85xx.h>
 
 _GLOBAL(__e500_icache_setup)
 	mfspr	r0, SPRN_L1CSR1
arch/powerpc/sysdev/fsl_pci.c +1 -1
index 0ef9df4..0fd1895 100644
@@ -22,6 +22,7 @@
 #include <linux/delay.h>
 #include <linux/string.h>
 #include <linux/fsl/edac.h>
+#include <linux/fsl/svr.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/memblock.h>
@@ -37,7 +38,6 @@
 #include <asm/pci-bridge.h>
 #include <asm/ppc-pci.h>
 #include <asm/machdep.h>
-#include <asm/mpc85xx.h>
 #include <asm/disassemble.h>
 #include <asm/ppc-opcode.h>
 #include <sysdev/fsl_soc.h>
drivers/clk/clk-qoriq.c +1 -2
index 58566a17..4b6c438 100644
@@ -13,6 +13,7 @@
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
 #include <linux/fsl/guts.h>
+#include <linux/fsl/svr.h>
 #include <linux/io.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
@@ -1149,8 +1150,6 @@ bad_args:
 }
 
 #ifdef CONFIG_PPC
-#include <asm/mpc85xx.h>
-
 static const u32 a4510_svrs[] __initconst = {
 	(SVR_P2040 << 8) | 0x10,	/* P2040 1.0 */
 	(SVR_P2040 << 8) | 0x11,	/* P2040 1.1 */
drivers/i2c/busses/i2c-mpc.c +1 -1
index 48ecffe..600704c 100644
@@ -27,9 +27,9 @@
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
 #include <linux/delay.h>
+#include <linux/fsl/svr.h>
 
 #include <asm/mpc52xx.h>
-#include <asm/mpc85xx.h>
 #include <sysdev/fsl_soc.h>
 
 #define DRV_NAME "mpc-i2c"
drivers/iommu/fsl_pamu.c +1 -2
index a34355f..af8fb27 100644
@@ -21,11 +21,10 @@
 #include "fsl_pamu.h"
 
 #include <linux/fsl/guts.h>
+#include <linux/fsl/svr.h>
 #include <linux/interrupt.h>
 #include <linux/genalloc.h>
 
-#include <asm/mpc85xx.h>
-
 /* define indexes for each operation mapping scenario */
 #define OMI_QMAN        0x00
 #define OMI_FMAN        0x01
drivers/net/ethernet/freescale/gianfar.c +1 -1
index d20935d..b8dac84 100644
@@ -86,11 +86,11 @@
 #include <linux/udp.h>
 #include <linux/in.h>
 #include <linux/net_tstamp.h>
+#include <linux/fsl/svr.h>
 
 #include <asm/io.h>
 #ifdef CONFIG_PPC
 #include <asm/reg.h>
-#include <asm/mpc85xx.h>
 #endif
 #include <asm/irq.h>
 #include <asm/uaccess.h>
include/linux/fsl/svr.h renamed from arch/powerpc/include/asm/mpc85xx.h +2 -2
similarity index 97%
rename from arch/powerpc/include/asm/mpc85xx.h
rename to include/linux/fsl/svr.h
index 213f3a8..8d13836 100644
@@ -9,8 +9,8 @@
  * (at your option) any later version.
  */
 
-#ifndef __ASM_PPC_MPC85XX_H
-#define __ASM_PPC_MPC85XX_H
+#ifndef FSL_SVR_H
+#define FSL_SVR_H
 
 #define SVR_REV(svr)	((svr) & 0xFF)		/* SOC design resision */
 #define SVR_MAJ(svr)	(((svr) >>  4) & 0xF)	/* Major revision field*/
Signature · 1 line
2.1.0.27.g96db324
author
#5 lore raw

PATCH v11 5/8 soc: fsl: add GUTS driver for QorIQ platforms

In reply to Yangbo Lu

The global utilities block controls power management, I/O device enabling, power-onreset(POR) configuration monitoring, alternate function selection for multiplexed signals,and clock control.

This patch adds a driver to manage and access global utilities block. Initially only reading SVR and registering soc device are supported. Other guts accesses, such as reading RCW, should eventually be moved into this driver as well.

---
Changes for v4:
- Added this patch
Changes for v5:
- Modified copyright info
- Changed MODULE_LICENSE to GPL
- Changed EXPORT_SYMBOL_GPL to EXPORT_SYMBOL
- Made FSL_GUTS user-invisible
- Added a complete compatible list for GUTS
- Stored guts info in file-scope variable
- Added mfspr() getting SVR
- Redefined GUTS APIs
- Called fsl_guts_init rather than using platform driver
- Removed useless parentheses
- Removed useless 'extern' key words
Changes for v6:
- Made guts thread safe in fsl_guts_init
Changes for v7:
- Removed 'ifdef' for function declaration in guts.h
Changes for v8:
- Fixes lines longer than 80 characters checkpatch issue
- Added 'Acked-by: Scott Wood'
Changes for v9:
- None
Changes for v10:
- None
Changes for v11:
- Changed to platform driver
- Registered soc device

---
 drivers/soc/Kconfig      |   2 +-
 drivers/soc/fsl/Kconfig  |  20 ++
 drivers/soc/fsl/Makefile |   1 +
 drivers/soc/fsl/guts.c   | 483 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fsl/guts.h | 127 ++++++++-----
 5 files changed, 584 insertions(+), 49 deletions(-)
 create mode 100644 drivers/soc/fsl/Kconfig
 create mode 100644 drivers/soc/fsl/guts.c
drivers/soc/Kconfig +1 -1
index fe42a2f..f31bceb 100644
@@ -1,7 +1,7 @@
 menu "SOC (System On Chip) specific Drivers"
 
 source "drivers/soc/bcm/Kconfig"
-source "drivers/soc/fsl/qe/Kconfig"
+source "drivers/soc/fsl/Kconfig"
 source "drivers/soc/mediatek/Kconfig"
 source "drivers/soc/qcom/Kconfig"
 source "drivers/soc/rockchip/Kconfig"
drivers/soc/fsl/Kconfig new file +20 -0
new file mode 100644
index 0000000..439998d
@@ -0,0 +1,20 @@
+#
+# Freescale SOC drivers
+#
+
+source "drivers/soc/fsl/qe/Kconfig"
+
+config FSL_GUTS
+	bool "Freescale QorIQ GUTS driver"
+	select SOC_BUS
+	select GLOB
+	help
+	  The global utilities block controls power management, I/O device
+	  enabling, power-onreset(POR) configuration monitoring, alternate
+	  function selection for multiplexed signals,and clock control.
+	  This driver is to manage and access global utilities block.
+	  Initially only reading SVR and registering soc device are supported.
+	  Other guts accesses, such as reading RCW, should eventually be moved
+	  into this driver as well.
+
+	  If you want GUTS driver support, you should say Y here.
drivers/soc/fsl/Makefile +1 -0
index 203307f..02afb7f 100644
@@ -4,3 +4,4 @@
 
 obj-$(CONFIG_QUICC_ENGINE)		+= qe/
 obj-$(CONFIG_CPM)			+= qe/
+obj-$(CONFIG_FSL_GUTS)			+= guts.o
drivers/soc/fsl/guts.c new file +483 -0

483 lines not on this page · raw message

include/linux/fsl/guts.h +79 -48

162 lines not on this page · raw message

Signature · 1 line
2.1.0.27.g96db324
maintainer
#6 lore raw

Re: [v11, 5/8] soc: fsl: add GUTS driver for QorIQ platforms

Quoted 11 lines · Yangbo Lu

The global utilities block controls power management, I/O device enabling, power-onreset(POR) configuration monitoring, alternate function selection for multiplexed signals,and clock control.

This patch adds a driver to manage and access global utilities block. Initially only reading SVR and registering soc device are supported. Other guts accesses, such as reading RCW, should eventually be moved into this driver as well.

Don't put my signoff on patches that I didn't put it on myself. ?Definitely don't put mine *after* yours on patches that were last modified by you.

If you want to mention that the soc_id encoding was my suggestion, then do so explicitly.

Quoted 4 lines
drivers/soc/fsl/guts.c new file +4 -0
+/* SoC attribute definition for QorIQ platform */
+static const struct soc_device_attribute qoriq_soc[] = {
+#ifdef CONFIG_PPC
+	/*

drivers/soc/fsl/guts.c line 46

Quoted 10 lines
drivers/soc/fsl/guts.c new file +10 -0
+	?* Power Architecture-based SoCs T Series
+	?*/
+
+	/* SoC: T1024/T1014/T1023/T1013 Rev: 1.0 */
+	{ .soc_id	= "svr:0x85400010,name:T1024,die:T1024",
+	??.revision	= "1.0",
+	},
+	{ .soc_id	= "svr:0x85480010,name:T1024E,die:T1024",
+	??.revision	= "1.0",
+	},

Revision could be computed from the low 8 bits of SVR (just as you do for unknown SVRs).

We could move the die name into .family:

	{
		.soc_id = "svr:0x85490010,name:T1023E,",
		.family = "QorIQ T1024",
	}

I see you dropped svre (and the trailing comma), though I guess the vast majority of potential users will be looking at .family. ?In which case do we even need name? ?If we just make the soc_id be "svr:0xnnnnnnnn" then we could shrink the table to an svr+mask that identifies each die. ?I'd still want to keep the "svr:" even if we're giving up on the general tagging system, to make it clear what the number refers to, and to provide some defense against users who match only against soc_id rather than soc_id+family. ?Or we could go further and format soc_id as "QorIQ SVR 0xnnnnnnnn" so that soc_id-only matches are fully acceptable rather than just less dangerous.

drivers/soc/fsl/guts.c line 333

Quoted 7 lines
drivers/soc/fsl/guts.c new file +7 -0
+static const struct soc_device_attribute *fsl_soc_device_match(
+	unsigned int svr, const struct soc_device_attribute *matches)
+{
+	char svr_match[50];
+	int n;
+
+	n = sprintf(svr_match, "*%08x*", svr);

n = sprintf(svr_match, "svr:0x%08x,*", svr);

(according to the current encoding)

drivers/soc/fsl/guts.c line 340

Quoted 7 lines
drivers/soc/fsl/guts.c new file +7 -0
+
+	do {
+		if (!matches->soc_id)
+			return NULL;
+		if (glob_match(svr_match, matches->soc_id))
+			break;
+	} while (matches++);

Are you expecting "matches++" to ever evaluate as false?

drivers/soc/fsl/guts.c line 389

Quoted 6 lines
drivers/soc/fsl/guts.c new file +6 -0
+	/* Register soc device */
+	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+	if (!soc_dev_attr) {
+		ret = -ENOMEM;
+		goto out_unmap;
+	}

Couldn't this be statically allocated?

drivers/soc/fsl/guts.c

Quoted 13 lines
drivers/soc/fsl/guts.c new file +4 -0
+
+	machine = of_flat_dt_get_machine_name();
+	if (machine)
+		soc_dev_attr->machine = kasprintf(GFP_KERNEL, "%s",

machine);

drivers/soc/fsl/guts.c new file +8 -0
+
+	soc_dev_attr->family = kasprintf(GFP_KERNEL, "QorIQ");
+
+	svr = fsl_guts_get_svr();
+	fsl_soc = fsl_soc_device_match(svr, qoriq_soc);
+	if (fsl_soc) {
+		soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%s",
+						?fsl_soc->soc_id);

You can use kstrdup() if you're just copying the string as is.

Quoted 5 lines
drivers/soc/fsl/guts.c new file +4 -0
+		soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%s",
+						???fsl_soc->revision);
+	} else {
+		soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "0x%08x",

svr);

	kasprintf(GFP_KERNEL, "svr:0x%08x,", svr);

drivers/soc/fsl/guts.c line 412

Quoted 4 lines
drivers/soc/fsl/guts.c new file +4 -0
+
+	soc_dev = soc_device_register(soc_dev_attr);
+	if (IS_ERR(soc_dev)) {
+		ret = -ENODEV;

Why are you changing the error code?

drivers/soc/fsl/guts.c line 414

Quoted 2 lines
drivers/soc/fsl/guts.c new file +2 -0
+		goto out;
+	} else {

Unnecessary "else".

drivers/soc/fsl/guts.c line 415

Quoted 1 line
drivers/soc/fsl/guts.c new file +1 -0
+		pr_info("Detected: %s\n", soc_dev_attr->machine);

Machine: %s

drivers/soc/fsl/guts.c line 418

Quoted 3 lines
drivers/soc/fsl/guts.c new file +3 -0
+		pr_info("Detected SoC family: %s\n", soc_dev_attr->family);
+		pr_info("Detected SoC ID: %s, revision: %s\n",
+			soc_dev_attr->soc_id, soc_dev_attr->revision);

s/Detected //g

drivers/soc/fsl/guts.c line 430

Quoted 12 lines
drivers/soc/fsl/guts.c new file +12 -0
+	}
+	return 0;
+out:
+	kfree(soc_dev_attr->machine);
+	kfree(soc_dev_attr->family);
+	kfree(soc_dev_attr->soc_id);
+	kfree(soc_dev_attr->revision);
+	kfree(soc_dev_attr);
+out_unmap:
+	iounmap(guts->regs);
+out_free:
+	kfree(guts);

devm

drivers/soc/fsl/guts.c line 445

Quoted 12 lines
drivers/soc/fsl/guts.c new file +12 -0
+static int fsl_guts_remove(struct platform_device *dev)
+{
+	kfree(soc_dev_attr->machine);
+	kfree(soc_dev_attr->family);
+	kfree(soc_dev_attr->soc_id);
+	kfree(soc_dev_attr->revision);
+	kfree(soc_dev_attr);
+	soc_device_unregister(soc_dev);
+	iounmap(guts->regs);
+	kfree(guts);
+	return 0;
+}

Don't free the memory before you unregister the device that uses it (moot if you use devm).

include/linux/fsl/guts.h line 139

Quoted 4 lines

?

include/linux/fsl/guts.h +3 -0
+#ifdef CONFIG_FSL_GUTS
+unsigned int fsl_guts_get_svr(void);
+#endif

Don't ifdef prototypes (unless you're going to provide a stub alternative).

-Scott

author
#7 lore raw

RE: [v11, 5/8] soc: fsl: add GUTS driver for QorIQ platforms

Hi Scott,

Thanks for your review :)
See my comment inline.

Quoted 26 lines

-----Original Message-----
From: Scott Wood [mailto:oss at buserror.net]
Sent: Friday, September 09, 2016 11:47 AM
To: Y.B. Lu; linux-mmc at vger.kernel.org; ulf.hansson at linaro.org; Arnd Bergmann
Cc: linuxppc-dev at lists.ozlabs.org; devicetree at vger.kernel.org; linux-arm- kernel at lists.infradead.org; linux-kernel at vger.kernel.org; linux- clk at vger.kernel.org; linux-i2c at vger.kernel.org; iommu at lists.linux- foundation.org; netdev at vger.kernel.org; Mark Rutland; Rob Herring; Russell King; Jochen Friedrich; Joerg Roedel; Claudiu Manoil; Bhupesh Sharma; Qiang Zhao; Kumar Gala; Santosh Shilimkar; Leo Li; X.B. Xie
Subject: Re: [v11, 5/8] soc: fsl: add GUTS driver for QorIQ platforms

Quoted 11 lines · Yangbo Lu

The global utilities block controls power management, I/O device enabling, power-onreset(POR) configuration monitoring, alternate function selection for multiplexed signals,and clock control.

This patch adds a driver to manage and access global utilities block. Initially only reading SVR and registering soc device are supported. Other guts accesses, such as reading RCW, should eventually be moved into this driver as well.

Quoted 7 lines

Don't put my signoff on patches that I didn't put it on myself. ?Definitely don't put mine *after* yours on patches that were last modified by you.

If you want to mention that the soc_id encoding was my suggestion, then do so explicitly.

[Lu Yangbo-B47093] I found your 'signoff' on this patch at below link.
http://patchwork.ozlabs.org/patch/649211/

So, let me just change the order in next version ?

Quoted 8 lines
Quoted 8 lines
drivers/soc/fsl/guts.c new file +8 -0
+/* SoC attribute definition for QorIQ platform */ static const struct
+soc_device_attribute qoriq_soc[] = { #ifdef CONFIG_PPC
+	/*
+	?* Power Architecture-based SoCs T Series
+	?*/
+
+	/* SoC: T1024/T1014/T1023/T1013 Rev: 1.0 */
+	{ .soc_id	= "svr:0x85400010,name:T1024,die:T1024",
Quoted 9 lines

drivers/soc/fsl/guts.c line 46

Quoted 5 lines
drivers/soc/fsl/guts.c new file +5 -0
+	??.revision	= "1.0",
+	},
+	{ .soc_id	= "svr:0x85480010,name:T1024E,die:T1024",
+	??.revision	= "1.0",
+	},

Revision could be computed from the low 8 bits of SVR (just as you do for unknown SVRs).

[Lu Yangbo-B47093] Yes, you're right. Will remove it here.

Quoted 7 lines

We could move the die name into .family:

	{
		.soc_id = "svr:0x85490010,name:T1023E,",
		.family = "QorIQ T1024",
	}
Quoted 10 lines

I see you dropped svre (and the trailing comma), though I guess the vast majority of potential users will be looking at .family. ?In which case do we even need name? ?If we just make the soc_id be "svr:0xnnnnnnnn" then we could shrink the table to an svr+mask that identifies each die. ?I'd still want to keep the "svr:" even if we're giving up on the general tagging system, to make it clear what the number refers to, and to provide some defense against users who match only against soc_id rather than soc_id+family. ?Or we could go further and format soc_id as "QorIQ SVR 0xnnnnnnnn" so that soc_id-only matches are fully acceptable rather than just less dangerous.

[Lu Yangbo-B47093] It's a good idea to move die into .family I think.
In my opinion, it's better to keep svr and name in soc_id just like your suggestion above.

Quoted 4 lines
	{
		.soc_id = "svr:0x85490010,name:T1023E,",
		.family = "QorIQ T1024",
	}

The user probably don?t like to learn the svr value. What they want is just to match the soc they use. It's convenient to use name+rev for them to match a soc.

Regarding shrinking the table, I think it's hard to use svr+mask. Because I find many platforms use different masks. We couldn?t know the mask according svr value.

Quoted 10 lines

drivers/soc/fsl/guts.c line 333

Quoted 7 lines
drivers/soc/fsl/guts.c new file +6 -0
+static const struct soc_device_attribute *fsl_soc_device_match(
+	unsigned int svr, const struct soc_device_attribute *matches) {
+	char svr_match[50];
+	int n;
+
+	n = sprintf(svr_match, "*%08x*", svr);

n = sprintf(svr_match, "svr:0x%08x,*", svr);

Quoted 2 lines

(according to the current encoding)

[Lu Yangbo-B47093] Ok. Will do that.

Quoted 9 lines

drivers/soc/fsl/guts.c line 340

Quoted 7 lines
drivers/soc/fsl/guts.c new file +7 -0
+
+	do {
+		if (!matches->soc_id)
+			return NULL;
+		if (glob_match(svr_match, matches->soc_id))
+			break;
+	} while (matches++);

Are you expecting "matches++" to ever evaluate as false?

[Lu Yangbo-B47093] Yes, this is used to match the soc we use in qoriq_soc array until getting true. We need to get the name and die information defined in array.

Quoted 9 lines

drivers/soc/fsl/guts.c line 389

Quoted 7 lines
drivers/soc/fsl/guts.c new file +6 -0
+	/* Register soc device */
+	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+	if (!soc_dev_attr) {
+		ret = -ENOMEM;
+		goto out_unmap;
+	}

Couldn't this be statically allocated?

[Lu Yangbo-B47093] Do you mean we define this struct statically ?

static struct soc_device_attribute soc_dev_attr;

Quoted 16 lines
Quoted 6 lines
drivers/soc/fsl/guts.c new file +4 -0
+
+	machine = of_flat_dt_get_machine_name();
+	if (machine)
+		soc_dev_attr->machine = kasprintf(GFP_KERNEL, "%s",

machine);

drivers/soc/fsl/guts.c

Quoted 8 lines
drivers/soc/fsl/guts.c new file +8 -0
+
+	soc_dev_attr->family = kasprintf(GFP_KERNEL, "QorIQ");
+
+	svr = fsl_guts_get_svr();
+	fsl_soc = fsl_soc_device_match(svr, qoriq_soc);
+	if (fsl_soc) {
+		soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "%s",
+						?fsl_soc->soc_id);

You can use kstrdup() if you're just copying the string as is.

[Lu Yangbo-B47093] Ok. Will do that.

Quoted 8 lines
Quoted 6 lines
drivers/soc/fsl/guts.c new file +4 -0
+		soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%s",
+						???fsl_soc->revision);
+	} else {
+		soc_dev_attr->soc_id = kasprintf(GFP_KERNEL, "0x%08x",

svr);

	kasprintf(GFP_KERNEL, "svr:0x%08x,", svr);

[Lu Yangbo-B47093] Sorry, will add that.

Quoted 8 lines

drivers/soc/fsl/guts.c line 412

Quoted 6 lines
drivers/soc/fsl/guts.c new file +4 -0
+
+	soc_dev = soc_device_register(soc_dev_attr);
+	if (IS_ERR(soc_dev)) {
+		ret = -ENODEV;

Why are you changing the error code?

[Lu Yangbo-B47093] What error code should we use ? :)

Quoted 5 lines

drivers/soc/fsl/guts.c line 414

Quoted 3 lines
drivers/soc/fsl/guts.c new file +2 -0
+		goto out;
+	} else {

Unnecessary "else".

[Lu Yangbo-B47093] Oh.. Correct!

Quoted 4 lines

drivers/soc/fsl/guts.c line 415

Quoted 2 lines
drivers/soc/fsl/guts.c new file +1 -0
+		pr_info("Detected: %s\n", soc_dev_attr->machine);

Machine: %s

[Lu Yangbo-B47093] Ok. Will do that.

Quoted 6 lines

drivers/soc/fsl/guts.c line 418

Quoted 4 lines
drivers/soc/fsl/guts.c new file +3 -0
+		pr_info("Detected SoC family: %s\n", soc_dev_attr->family);
+		pr_info("Detected SoC ID: %s, revision: %s\n",
+			soc_dev_attr->soc_id, soc_dev_attr->revision);

s/Detected //g

[Lu Yangbo-B47093] Ok, will do that.

Quoted 16 lines
Quoted 4 lines
drivers/soc/fsl/guts.c new file +2 -0
+	}
+	return 0;

drivers/soc/fsl/guts.c line 430

Quoted 10 lines
drivers/soc/fsl/guts.c new file +10 -0
+out:
+	kfree(soc_dev_attr->machine);
+	kfree(soc_dev_attr->family);
+	kfree(soc_dev_attr->soc_id);
+	kfree(soc_dev_attr->revision);
+	kfree(soc_dev_attr);
+out_unmap:
+	iounmap(guts->regs);
+out_free:
+	kfree(guts);

devm

[Lu Yangbo-B47093] What's the devm meaning here :)

Quoted 15 lines

drivers/soc/fsl/guts.c line 445

Quoted 12 lines
drivers/soc/fsl/guts.c new file +11 -0
+static int fsl_guts_remove(struct platform_device *dev) {
+	kfree(soc_dev_attr->machine);
+	kfree(soc_dev_attr->family);
+	kfree(soc_dev_attr->soc_id);
+	kfree(soc_dev_attr->revision);
+	kfree(soc_dev_attr);
+	soc_device_unregister(soc_dev);
+	iounmap(guts->regs);
+	kfree(guts);
+	return 0;
+}

Don't free the memory before you unregister the device that uses it (moot if you use devm).

[Lu Yangbo-B47093] The soc.c driver mentions that.
Ensure soc_dev->attr is freed prior to calling soc_device_unregister.

Quoted 8 lines

include/linux/fsl/guts.h line 139

Quoted 5 lines
include/linux/fsl/guts.h +3 -0
+#ifdef CONFIG_FSL_GUTS
+unsigned int fsl_guts_get_svr(void);
+#endif

Don't ifdef prototypes (unless you're going to provide a stub alternative).

[Lu Yangbo-B47093] Ok, will remove ifdef.

Quoted 2 lines

-Scott

maintainer
#8 lore raw

Re: [v11, 5/8] soc: fsl: add GUTS driver for QorIQ platforms

Quoted 39 lines · Y.B. Lu

Hi Scott,

Thanks for your review :)
See my comment inline.

Quoted 25 lines

-----Original Message-----
From: Scott Wood [mailto:oss at buserror.net]
Sent: Friday, September 09, 2016 11:47 AM
To: Y.B. Lu; linux-mmc at vger.kernel.org; ulf.hansson at linaro.org; Arnd Bergmann
Cc: linuxppc-dev at lists.ozlabs.org; devicetree at vger.kernel.org; linux-arm- kernel at lists.infradead.org; linux-kernel at vger.kernel.org; linux- clk at vger.kernel.org; linux-i2c at vger.kernel.org; iommu at lists.linux- foundation.org; netdev at vger.kernel.org; Mark Rutland; Rob Herring; Russell King; Jochen Friedrich; Joerg Roedel; Claudiu Manoil; Bhupesh Sharma; Qiang Zhao; Kumar Gala; Santosh Shilimkar; Leo Li; X.B. Xie
Subject: Re: [v11, 5/8] soc: fsl: add GUTS driver for QorIQ platforms

Quoted 10 lines · Yangbo Lu

The global utilities block controls power management, I/O device enabling, power-onreset(POR) configuration monitoring, alternate function selection for multiplexed signals,and clock control.

This patch adds a driver to manage and access global utilities block. Initially only reading SVR and registering soc device are supported. Other guts accesses, such as reading RCW, should eventually be moved into this driver as well.

Quoted 9 lines
Quoted 2 lines

Don't put my signoff on patches that I didn't put it on myself. ?Definitely don't put mine *after* yours on patches that were last modified by you.

If you want to mention that the soc_id encoding was my suggestion, then do so explicitly.

Quoted 6 lines

[Lu Yangbo-B47093] I found your 'signoff' on this patch at below link.
http://patchwork.ozlabs.org/patch/649211/

So, let me just change the order in next version ?

No. ?This isn't my patch so my signoff shouldn't be on it.

Quoted 11 lines

[Lu Yangbo-B47093] It's a good idea to move die into .family I think. In my opinion, it's better to keep svr and name in soc_id just like your suggestion above.

Quoted 5 lines
	{
		.soc_id = "svr:0x85490010,name:T1023E,",
		.family = "QorIQ T1024",
	}

The user probably don?t like to learn the svr value. What they want is just to match the soc they use.
It's convenient to use name+rev for them to match a soc.

What the user should want 99% of the time is to match the die (plus revision), not the soc.

Quoted 3 lines

Regarding shrinking the table, I think it's hard to use svr+mask. Because I find many platforms use different masks.
We couldn?t know the mask according svr value.

The mask would be part of the table:

{
	{
		.die = "T1024",
		.svr = 0x85400000,
		.mask = 0xfff00000,
	},
	{
		.die = "T1040",
		.svr = 0x85200000,
		.mask = 0xfff00000,
	},
	{
		.die = "LS1088A",
		.svr = 0x87030000,
		.mask = 0xffff0000,
	},
	...
}

There's a small risk that we get the mask wrong and a different die is created that matches an existing table, but it doesn't seem too likely, and can easily be fixed with a kernel update if it happens.

BTW, aren't ls2080a and ls2085a the same die? ?And is there no non-E version of LS2080A/LS2040A?

Quoted 10 lines
Quoted 7 lines

drivers/soc/fsl/guts.c line 340

Quoted 6 lines
drivers/soc/fsl/guts.c new file +6 -0
+	do {
+		if (!matches->soc_id)
+			return NULL;
+		if (glob_match(svr_match, matches->soc_id))
+			break;
+	} while (matches++);

Are you expecting "matches++" to ever evaluate as false?

[Lu Yangbo-B47093] Yes, this is used to match the soc we use in qoriq_soc array until getting true.?
We need to get the name and die information defined in array.

I'm not asking whether the glob_match will ever return true. ?I'm saying that "matches++" will never become NULL.

Quoted 10 lines
Quoted 7 lines

drivers/soc/fsl/guts.c line 389

Quoted 6 lines
drivers/soc/fsl/guts.c new file +6 -0
+	/* Register soc device */
+	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+	if (!soc_dev_attr) {
+		ret = -ENOMEM;
+		goto out_unmap;
+	}

Couldn't this be statically allocated?

[Lu Yangbo-B47093] Do you mean we define this struct statically ?

static struct soc_device_attribute soc_dev_attr;

Yes.

Quoted 6 lines
Quoted 5 lines

drivers/soc/fsl/guts.c line 412

Quoted 4 lines
drivers/soc/fsl/guts.c new file +4 -0
+
+	soc_dev = soc_device_register(soc_dev_attr);
+	if (IS_ERR(soc_dev)) {
+		ret = -ENODEV;

Why are you changing the error code?

[Lu Yangbo-B47093] What error code should we use ? :)

ret = PTR_ERR(soc_dev);

+ }

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
drivers/soc/fsl/guts.c new file +4 -0
+	return 0;
+out:
+	kfree(soc_dev_attr->machine);
+	kfree(soc_dev_attr->family);
Quoted 8 lines

drivers/soc/fsl/guts.c line 430

Quoted 7 lines
drivers/soc/fsl/guts.c new file +7 -0
+	kfree(soc_dev_attr->soc_id);
+	kfree(soc_dev_attr->revision);
+	kfree(soc_dev_attr);
+out_unmap:
+	iounmap(guts->regs);
+out_free:
+	kfree(guts);

devm

Quoted 1 line

[Lu Yangbo-B47093] What's the devm meaning here :)

If you allocate these with devm_kzalloc(), devm_kasprintf(), devm_kstrdup(), etc. then they will be freed automatically when the device is unbound.

Quoted 17 lines

?

Quoted 16 lines
Quoted 4 lines
drivers/soc/fsl/guts.c new file +1 -0
+static int fsl_guts_remove(struct platform_device *dev) {

drivers/soc/fsl/guts.c line 445

Quoted 10 lines
drivers/soc/fsl/guts.c new file +10 -0
+	kfree(soc_dev_attr->machine);
+	kfree(soc_dev_attr->family);
+	kfree(soc_dev_attr->soc_id);
+	kfree(soc_dev_attr->revision);
+	kfree(soc_dev_attr);
+	soc_device_unregister(soc_dev);
+	iounmap(guts->regs);
+	kfree(guts);
+	return 0;
+}

Don't free the memory before you unregister the device that uses it (moot if you use devm).

Quoted 2 lines

[Lu Yangbo-B47093] The soc.c driver mentions that.
Ensure soc_dev->attr is freed prior to calling soc_device_unregister.

That comment is wrong. ?Freeing the memory first creates a race condition that could result in accessing freed memory, if something accesses the soc device in parallel with unbinding.

-Scott

author
#9 lore raw

RE: [v11, 5/8] soc: fsl: add GUTS driver for QorIQ platforms

Quoted 57 lines

-----Original Message-----
From: linux-mmc-owner at vger.kernel.org [mailto:linux-mmc-
owner at vger.kernel.org] On Behalf Of Scott Wood
Sent: Tuesday, September 13, 2016 7:25 AM
To: Y.B. Lu; linux-mmc at vger.kernel.org; ulf.hansson at linaro.org; Arnd Bergmann
Cc: linuxppc-dev at lists.ozlabs.org; devicetree at vger.kernel.org; linux-arm- kernel at lists.infradead.org; linux-kernel at vger.kernel.org; linux- clk at vger.kernel.org; linux-i2c at vger.kernel.org; iommu at lists.linux- foundation.org; netdev at vger.kernel.org; Mark Rutland; Rob Herring; Russell King; Jochen Friedrich; Joerg Roedel; Claudiu Manoil; Bhupesh Sharma; Qiang Zhao; Kumar Gala; Santosh Shilimkar; Leo Li; X.B. Xie
Subject: Re: [v11, 5/8] soc: fsl: add GUTS driver for QorIQ platforms

Quoted 28 lines · Y.B. Lu

Hi Scott,

Thanks for your review :)
See my comment inline.

Quoted 23 lines

-----Original Message-----
From: Scott Wood [mailto:oss at buserror.net]
Sent: Friday, September 09, 2016 11:47 AM
To: Y.B. Lu; linux-mmc at vger.kernel.org; ulf.hansson at linaro.org; Arnd Bergmann
Cc: linuxppc-dev at lists.ozlabs.org; devicetree at vger.kernel.org; linux-arm- kernel at lists.infradead.org; linux-kernel at vger.kernel.org; linux- clk at vger.kernel.org; linux-i2c at vger.kernel.org; iommu at lists.linux- foundation.org; netdev at vger.kernel.org; Mark Rutland; Rob Herring; Russell King; Jochen Friedrich; Joerg Roedel; Claudiu Manoil; Bhupesh Sharma; Qiang Zhao; Kumar Gala; Santosh Shilimkar; Leo Li; X.B. Xie
Subject: Re: [v11, 5/8] soc: fsl: add GUTS driver for QorIQ platforms

Quoted 6 lines · Yangbo Lu

The global utilities block controls power management, I/O device enabling, power-onreset(POR) configuration monitoring, alternate function selection for multiplexed signals,and clock control.

This patch adds a driver to manage and access global utilities

block.

Quoted 13 lines
Quoted 13 lines
Quoted 6 lines

Initially only reading SVR and registering soc device are supported. Other guts accesses, such as reading RCW, should eventually be moved into this driver as well.

Don't put my signoff on patches that I didn't put it on myself. Definitely don't put mine *after* yours on patches that were last modified by you.

If you want to mention that the soc_id encoding was my suggestion, then do so explicitly.

Quoted 8 lines
Quoted 6 lines

[Lu Yangbo-B47093] I found your 'signoff' on this patch at below link.
http://patchwork.ozlabs.org/patch/649211/

So, let me just change the order in next version ?

No. ?This isn't my patch so my signoff shouldn't be on it.

[Lu Yangbo-B47093] Ok, will remove it.

Quoted 41 lines
Quoted 5 lines

[Lu Yangbo-B47093] It's a good idea to move die into .family I think. In my opinion, it's better to keep svr and name in soc_id just like your suggestion above.

Quoted 1 line
Quoted 7 lines
Quoted 4 lines
	{
		.soc_id = "svr:0x85490010,name:T1023E,",
		.family = "QorIQ T1024",
	}

The user probably don?t like to learn the svr value. What they want is just to match the soc they use.
It's convenient to use name+rev for them to match a soc.

What the user should want 99% of the time is to match the die (plus revision), not the soc.

Quoted 3 lines

Regarding shrinking the table, I think it's hard to use svr+mask. Because I find many platforms use different masks.
We couldn?t know the mask according svr value.

The mask would be part of the table:

{
	{
		.die = "T1024",
		.svr = 0x85400000,
		.mask = 0xfff00000,
	},
	{
		.die = "T1040",
		.svr = 0x85200000,
		.mask = 0xfff00000,
	},
	{
		.die = "LS1088A",
		.svr = 0x87030000,
		.mask = 0xffff0000,
	},
	...
}
Quoted 4 lines

There's a small risk that we get the mask wrong and a different die is created that matches an existing table, but it doesn't seem too likely, and can easily be fixed with a kernel update if it happens.

[Lu Yangbo-B47093] You mean we will not define soc device attribute for each soc and we will define attribute for each die instead, right? If so, when we want to match a specific soc we need to use its svr value in code. If it's acceptable, I can try in next version.

Quoted 2 lines

BTW, aren't ls2080a and ls2085a the same die? ?And is there no non-E version of LS2080A/LS2040A?

[Lu Yangbo-B47093] I checked all the svr values in chip errata doc "Revision level to part marking cross-reference" table. I found ls2080a and ls2085a were in two separate doc. And I didn?t find non-E version of LS2080A/LS2040A in chip errata doc. Do you know is there any other doc we can confirm this?

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/soc/fsl/guts.c line 340

Quoted 7 lines
drivers/soc/fsl/guts.c new file +6 -0
+	do {
+		if (!matches->soc_id)
+			return NULL;
+		if (glob_match(svr_match, matches->soc_id))
+			break;
+	} while (matches++);

Are you expecting "matches++" to ever evaluate as false?

Quoted 6 lines
Quoted 3 lines

[Lu Yangbo-B47093] Yes, this is used to match the soc we use in qoriq_soc array until getting true.
We need to get the name and die information defined in array.

I'm not asking whether the glob_match will ever return true. ?I'm saying that "matches++" will never become NULL.

[Lu Yangbo-B47093] The matches++ will never become NULL while it will return NULL after matching for all the members in array.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/soc/fsl/guts.c line 389

Quoted 7 lines
drivers/soc/fsl/guts.c new file +6 -0
+	/* Register soc device */
+	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+	if (!soc_dev_attr) {
+		ret = -ENOMEM;
+		goto out_unmap;
+	}

Couldn't this be statically allocated?

Quoted 6 lines
Quoted 3 lines

[Lu Yangbo-B47093] Do you mean we define this struct statically ?

static struct soc_device_attribute soc_dev_attr;

Yes.

[Lu Yangbo-B47093] It's ok to define it statically. Is there any need to do that?

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines

drivers/soc/fsl/guts.c line 412

Quoted 4 lines
drivers/soc/fsl/guts.c new file +4 -0
+
+	soc_dev = soc_device_register(soc_dev_attr);
+	if (IS_ERR(soc_dev)) {
+		ret = -ENODEV;

Why are you changing the error code?

[Lu Yangbo-B47093] What error code should we use ? :)

ret = PTR_ERR(soc_dev);

[Lu Yangbo-B47093] Ok.. will do that.

Quoted 37 lines
(quoted diff) +1 -0
+	}
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
drivers/soc/fsl/guts.c new file +4 -0
+	return 0;
+out:
+	kfree(soc_dev_attr->machine);
+	kfree(soc_dev_attr->family);
Quoted 8 lines

drivers/soc/fsl/guts.c line 430

Quoted 7 lines
drivers/soc/fsl/guts.c new file +7 -0
+	kfree(soc_dev_attr->soc_id);
+	kfree(soc_dev_attr->revision);
+	kfree(soc_dev_attr);
+out_unmap:
+	iounmap(guts->regs);
+out_free:
+	kfree(guts);

devm

Quoted 1 line

[Lu Yangbo-B47093] What's the devm meaning here :)

If you allocate these with devm_kzalloc(), devm_kasprintf(), devm_kstrdup(), etc. then they will be freed automatically when the device is unbound.

Quoted 17 lines
Quoted 17 lines
Quoted 5 lines
drivers/soc/fsl/guts.c new file +1 -0
+static int fsl_guts_remove(struct platform_device *dev) {

drivers/soc/fsl/guts.c line 445

Quoted 10 lines
drivers/soc/fsl/guts.c new file +10 -0
+	kfree(soc_dev_attr->machine);
+	kfree(soc_dev_attr->family);
+	kfree(soc_dev_attr->soc_id);
+	kfree(soc_dev_attr->revision);
+	kfree(soc_dev_attr);
+	soc_device_unregister(soc_dev);
+	iounmap(guts->regs);
+	kfree(guts);
+	return 0;
+}

Don't free the memory before you unregister the device that uses it (moot if you use devm).

Quoted 7 lines
Quoted 2 lines

[Lu Yangbo-B47093] The soc.c driver mentions that.
Ensure soc_dev->attr is freed prior to calling soc_device_unregister.

That comment is wrong. ?Freeing the memory first creates a race condition that could result in accessing freed memory, if something accesses the soc device in parallel with unbinding.

[Lu Yangbo-B47093] Ok, will unregister the device first. Thanks.

Quoted 6 lines

-Scott

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo at vger.kernel.org More majordomo info at
http://vger.kernel.org/majordomo-info.html

maintainer
#10 lore raw

Re: [v11, 5/8] soc: fsl: add GUTS driver for QorIQ platforms

Quoted 18 lines · Y.B. Lu
Quoted 18 lines

-----Original Message-----
From: linux-mmc-owner at vger.kernel.org [mailto:linux-mmc-
owner at vger.kernel.org] On Behalf Of Scott Wood
Sent: Tuesday, September 13, 2016 7:25 AM
To: Y.B. Lu; linux-mmc at vger.kernel.org; ulf.hansson at linaro.org; Arnd Bergmann
Cc: linuxppc-dev at lists.ozlabs.org; devicetree at vger.kernel.org; linux-arm- kernel at lists.infradead.org; linux-kernel at vger.kernel.org; linux- clk at vger.kernel.org; linux-i2c at vger.kernel.org; iommu at lists.linux- foundation.org; netdev at vger.kernel.org; Mark Rutland; Rob Herring; Russell King; Jochen Friedrich; Joerg Roedel; Claudiu Manoil; Bhupesh Sharma; Qiang Zhao; Kumar Gala; Santosh Shilimkar; Leo Li; X.B. Xie
Subject: Re: [v11, 5/8] soc: fsl: add GUTS driver for QorIQ platforms

Quoted 7 lines
Quoted 2 lines

BTW, aren't ls2080a and ls2085a the same die? ?And is there no non-E version of LS2080A/LS2040A?

[Lu Yangbo-B47093] I checked all the svr values in chip errata doc "Revision level to part marking cross-reference" table.
I found ls2080a and ls2085a were in two separate doc. And I didn?t find non- E version of LS2080A/LS2040A in chip errata doc.
Do you know is there any other doc we can confirm this?

No. ?Traditionally we've always had E and non-E versions of each chip, but I have no knowledge of whether that has changed (I do note that the way that E- status is indicated in SVR has changed).

But please label LS2080A and LS2085A as the same die (or provide strong evidence that they are not).

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

drivers/soc/fsl/guts.c line 340

Quoted 11 lines
drivers/soc/fsl/guts.c new file +6 -0
+	do {
+		if (!matches->soc_id)
+			return NULL;
+		if (glob_match(svr_match, matches->soc_id))
+			break;
+	} while (matches++);

Are you expecting "matches++" to ever evaluate as false?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

[Lu Yangbo-B47093] Yes, this is used to match the soc we use in qoriq_soc array until getting true.
We need to get the name and die information defined in array.

I'm not asking whether the glob_match will ever return true. ?I'm saying that "matches++" will never become NULL.

[Lu Yangbo-B47093] The matches++ will never become NULL while it will return NULL after matching for all the members in array.

"matches++" will never "return NULL". ?It's just an incrementing address. ?It won't be null until you wrap around the address space, and even if the other loop terminators never kicked in you'd crash long before that happens.

Please rewrite the loop as something like:

	while (matches->soc_id) {
		if (glob_match(...))
			return matches;

		matches++;
	}

	return NULL;
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/soc/fsl/guts.c line 389

Quoted 6 lines
drivers/soc/fsl/guts.c new file +6 -0
+	/* Register soc device */
+	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+	if (!soc_dev_attr) {
+		ret = -ENOMEM;
+		goto out_unmap;
+	}

Couldn't this be statically allocated?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

[Lu Yangbo-B47093] Do you mean we define this struct statically ?

static struct soc_device_attribute soc_dev_attr;

Yes.

[Lu Yangbo-B47093] It's ok to define it statically. Is there any need to do that?

It's simpler.

-Scott

author
#11 lore raw

PATCH v11 6/8 MAINTAINERS: add entry for Freescale SoC drivers

In reply to Yangbo Lu

Add maintainer entry for Freescale SoC drivers including the QE library and the GUTS driver now. Also add maintainer for QE library.

---
Changes for v8:
- Added this patch
Changes for v9:
- Added linux-arm mail list
- Removed GUTS driver entry
Changes for v10:
- Changed 'DRIVER' to 'DRIVERS'
- Added 'Acked-by' of Scott and Qiang
Changes for v11:
- None

---
 MAINTAINERS | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
MAINTAINERS +10 -1
index 71aa5da..3954c0c 100644
@@ -4969,9 +4969,18 @@ F:	drivers/net/ethernet/freescale/fec_ptp.c
 F:	drivers/net/ethernet/freescale/fec.h
 F:	Documentation/devicetree/bindings/net/fsl-fec.txt
 
+FREESCALE SOC DRIVERS
+M:	Scott Wood <[email protected]>
+L:	linuxppc-dev at lists.ozlabs.org
+L:	linux-arm-kernel at lists.infradead.org
+S:	Maintained
+F:	drivers/soc/fsl/
+F:	include/linux/fsl/
+
 FREESCALE QUICC ENGINE LIBRARY
+M:	Qiang Zhao <[email protected]>
 L:	linuxppc-dev at lists.ozlabs.org
-S:	Orphan
+S:	Maintained
 F:	drivers/soc/fsl/qe/
 F:	include/soc/fsl/*qe*.h
 F:	include/soc/fsl/*ucc*.h
Signature · 1 line
2.1.0.27.g96db324
author
#12 lore raw

PATCH v11 7/8 base: soc: introduce soc_device_match() interface

In reply to Yangbo Lu

We keep running into cases where device drivers want to know the exact version of the a SoC they are currently running on. In the past, this has usually been done through a vendor specific API that can be called by a driver, or by directly accessing some kind of version register that is not part of the device itself but that belongs to a global register area of the chip.

Common reasons for doing this include:

- A machine is not using devicetree or similar for passing data about on-chip devices, but just announces their presence using boot-time platform devices, and the machine code itself does not care about the revision.

- There is existing firmware or boot loaders with existing DT binaries with generic compatible strings that do not identify the particular revision of each device, but the driver knows which SoC revisions include which part.

- A prerelease version of a chip has some quirks and we are using the same version of the bootloader and the DT blob on both the prerelease and the final version. An update of the DT binding seems inappropriate because that would involve maintaining multiple copies of the dts and/or bootloader.

This patch introduces the soc_device_match() interface that is meant to work like of_match_node() but instead of identifying the version of a device, it identifies the SoC itself using a vendor-agnostic interface.

Unlike of_match_node(), we do not do an exact string compare but instead use glob_match() to allow wildcards in strings.

---
Changes for v11:
- Added this patch for soc match

---
 drivers/base/Kconfig    |  1 +
 drivers/base/soc.c      | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/sys_soc.h |  3 +++
 3 files changed, 65 insertions(+)
drivers/base/Kconfig +1 -0
index 98504ec..f1591ad2 100644
@@ -225,6 +225,7 @@ config GENERIC_CPU_AUTOPROBE
 
 config SOC_BUS
 	bool
+	select GLOB
 
 source "drivers/base/regmap/Kconfig"
 
drivers/base/soc.c +61 -0

70 lines not on this page · raw message

include/linux/sys_soc.h +3 -0
index 2739ccb..9f5eb06 100644
@@ -13,6 +13,7 @@ struct soc_device_attribute {
 	const char *family;
 	const char *revision;
 	const char *soc_id;
+	const void *data;
 };
 
 /**
@@ -34,4 +35,6 @@ void soc_device_unregister(struct soc_device *soc_dev);
  */
 struct device *soc_device_to_device(struct soc_device *soc);
 
+const struct soc_device_attribute *soc_device_match(
+	const struct soc_device_attribute *matches);
 #endif /* __SOC_BUS_H */
Signature · 1 line
2.1.0.27.g96db324
#13 lore raw

Re: [v11, 7/8] base: soc: introduce soc_device_match() interface

Quoted 25 lines · Yangbo Lu

We keep running into cases where device drivers want to know the exact version of the a SoC they are currently running on. In the past, this has usually been done through a vendor specific API that can be called by a driver, or by directly accessing some kind of version register that is not part of the device itself but that belongs to a global register area of the chip.

Common reasons for doing this include:

- A machine is not using devicetree or similar for passing data about on-chip devices, but just announces their presence using boot-time platform devices, and the machine code itself does not care about the revision.

- There is existing firmware or boot loaders with existing DT binaries with generic compatible strings that do not identify the particular revision of each device, but the driver knows which SoC revisions include which part.

- A prerelease version of a chip has some quirks and we are using the same version of the bootloader and the DT blob on both the prerelease and the final version. An update of the DT binding seems inappropriate because that would involve maintaining multiple copies of the dts and/or bootloader.

Quoted 6 lines

This patch introduces the soc_device_match() interface that is meant to work like of_match_node() but instead of identifying the version of a device, it identifies the SoC itself using a vendor-agnostic interface.

Unlike of_match_node(), we do not do an exact string compare but instead use glob_match() to allow wildcards in strings.

Overall, this change make sense to me, although some minor comment below.

Quoted 58 lines

---
Changes for v11:
- Added this patch for soc match

---
 drivers/base/Kconfig    |  1 +
 drivers/base/soc.c      | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/sys_soc.h |  3 +++
 3 files changed, 65 insertions(+)
drivers/base/Kconfig +1 -0
index 98504ec..f1591ad2 100644
@@ -225,6 +225,7 @@ config GENERIC_CPU_AUTOPROBE
 
 config SOC_BUS
        bool
+       select GLOB
 
 source "drivers/base/regmap/Kconfig"
 
drivers/base/soc.c +19 -0
index 75b98aa..5c4e84a 100644
@@ -14,6 +14,7 @@
 #include <linux/spinlock.h>
 #include <linux/sys_soc.h>
 #include <linux/err.h>
+#include <linux/glob.h>
 
 static DEFINE_IDA(soc_ida);
 
@@ -168,3 +169,63 @@ static void __exit soc_bus_unregister(void)
        bus_unregister(&soc_bus_type);
 }
 module_exit(soc_bus_unregister);
+
+static int soc_device_match_one(struct device *dev, void *arg)
+{
+       struct soc_device *soc_dev = container_of(dev, struct soc_device, dev);
+       const struct soc_device_attribute *match = arg;
+
+       if (match->machine &&
+           !glob_match(match->machine, soc_dev->attr->machine))
+               return 0;
+
+       if (match->family &&
+           !glob_match(match->family, soc_dev->attr->family))
+               return 0;
+
+       if (match->revision &&
+           !glob_match(match->revision, soc_dev->attr->revision))
+               return 0;
+

drivers/base/soc.c static void __exit soc_bus_unregister(void) · line 199

Quoted 10 lines
drivers/base/soc.c +10 -0
+       if (match->soc_id &&
+           !glob_match(match->soc_id, soc_dev->attr->soc_id))
+               return 0;
+
+       return 1;
+}
+
+/*
+ * soc_device_match - identify the SoC in the machine
+ * @matches: zero-terminated array of possible matches

Perhaps also express the constraint on the matching entries. As you need at least one of the ->machine(), ->family(), ->revision() or ->soc_id() callbacks implemented, right!?

Quoted 4 lines
drivers/base/soc.c +4 -0
+ *
+ * returns the first matching entry of the argument array, or NULL
+ * if none of them match.
+ *

drivers/base/soc.c static void __exit soc_bus_unregister(void) · line 213

Quoted 10 lines
drivers/base/soc.c +10 -0
+ * This function is meant as a helper in place of of_match_node()
+ * in cases where either no device tree is available or the information
+ * in a device node is insufficient to identify a particular variant
+ * by its compatible strings or other properties. For new devices,
+ * the DT binding should always provide unique compatible strings
+ * that allow the use of of_match_node() instead.
+ *
+ * The calling function can use the .data entry of the
+ * soc_device_attribute to pass a structure or function pointer for
+ * each entry.

I don't get the use case behind this, could you elaborate?

Perhaps we should postpone adding the .data entry until we actually see a need for it?

drivers/base/soc.c static void __exit soc_bus_unregister(void) · line 221

Quoted 8 lines
drivers/base/soc.c +8 -0
+ */
+const struct soc_device_attribute *soc_device_match(
+       const struct soc_device_attribute *matches)
+{
+       struct device *dev;
+       int ret;
+
+       for (ret = 0; ret == 0; matches++) {

This loop looks a bit weird and unsafe.

1) Perhaps using a while loop makes this more readable?
2) As this is an exported API, I guess validation of the ->matches pointer needs to be done before accessing it.

drivers/base/soc.c static void __exit soc_bus_unregister(void) · line 225

Quoted 4 lines
drivers/base/soc.c +4 -0
+               if (!(matches->machine || matches->family ||
+                     matches->revision || matches->soc_id))
+                       return NULL;
+               dev = NULL;

There's no need to use a struct device just to assign it to NULL. Instead just provide the function below with NULL.

Quoted 26 lines
drivers/base/soc.c +6 -0
+               ret = bus_for_each_dev(&soc_bus_type, dev, (void *)matches,
+                                      soc_device_match_one);
+       }
+       return matches;
+}
+EXPORT_SYMBOL_GPL(soc_device_match);
include/linux/sys_soc.h +3 -1
index 2739ccb..9f5eb06 100644
@@ -13,6 +13,7 @@ struct soc_device_attribute {
        const char *family;
        const char *revision;
        const char *soc_id;
+       const void *data;
 };
 
 /**
@@ -34,4 +35,6 @@ void soc_device_unregister(struct soc_device *soc_dev);
  */
 struct device *soc_device_to_device(struct soc_device *soc);
 
+const struct soc_device_attribute *soc_device_match(
+       const struct soc_device_attribute *matches);
 #endif /* __SOC_BUS_H */
--
Quoted 2 lines

2.1.0.27.g96db324

Kind regards
Uffe

#14 lore raw

Re: [v11, 7/8] base: soc: introduce soc_device_match() interface

Quoted 7 lines · CEST Ulf Hansson
Quoted 6 lines · Yangbo Lu

We keep running into cases where device drivers want to know the exact version of the a SoC they are currently running on. In the past, this has usually been done through a vendor specific API that can be called by a driver, or by directly accessing some kind of version register that is not part of the device itself but that belongs to a global register area of the chip.

Please add "From: Arnd Bergmann <[email protected]>" as the first line, to preserve authorship. If you use "git send-email" or "git format-patch", that should happen automatically if the author field is set right (if not, use 'git commit --amend --author="Arnd Bergmann <[email protected]>"' to fix it).

Quoted 8 lines

drivers/base/soc.c static void __exit soc_bus_unregister(void) · line 199

Quoted 4 lines
drivers/base/soc.c +4 -0
+
+/*
+ * soc_device_match - identify the SoC in the machine
+ * @matches: zero-terminated array of possible matches

Perhaps also express the constraint on the matching entries. As you need at least one of the ->machine(), ->family(), ->revision() or ->soc_id() callbacks implemented, right!?

They are not callbacks, just strings. Having an empty entry indicates the end of the array, and this is not called.

Quoted 15 lines
Quoted 6 lines

+ *
+ * returns the first matching entry of the argument array, or NULL
+ * if none of them match.
+ *
+ * This function is meant as a helper in place of of_match_node()
+ * in cases where either no device tree is available or the information

Quoted 8 lines

+ * in a device node is insufficient to identify a particular variant
+ * by its compatible strings or other properties. For new devices,
+ * the DT binding should always provide unique compatible strings
+ * that allow the use of of_match_node() instead.
+ *
+ * The calling function can use the .data entry of the
+ * soc_device_attribute to pass a structure or function pointer for
+ * each entry.

Quoted 4 lines

I don't get the use case behind this, could you elaborate?

Perhaps we should postpone adding the .data entry until we actually see a need for it?

I think the interface is rather useless without a way to figure out which entry you got. Almost all users of of_match_node() actually use the returned ->data field, and I expect this to be the same here.

Quoted 10 lines

drivers/base/soc.c static void __exit soc_bus_unregister(void) · line 221

Quoted 8 lines

+ */

drivers/base/soc.c +7 -0
+const struct soc_device_attribute *soc_device_match(
+       const struct soc_device_attribute *matches)
+{
+       struct device *dev;
+       int ret;
+
+       for (ret = 0; ret == 0; matches++) {

This loop looks a bit weird and unsafe.

Ah, and I thought I was being clever ;-)

Quoted 3 lines

1) Perhaps using a while loop makes this more readable?
2) As this is an exported API, I guess validation of the ->matches pointer needs to be done before accessing it.

Sounds fine.

Quoted 10 lines

drivers/base/soc.c static void __exit soc_bus_unregister(void) · line 225

Quoted 4 lines
drivers/base/soc.c +4 -0
+               if (!(matches->machine || matches->family ||
+                     matches->revision || matches->soc_id))
+                       return NULL;
+               dev = NULL;

There's no need to use a struct device just to assign it to NULL. Instead just provide the function below with NULL.

Quoted 2 lines
drivers/base/soc.c +2 -0
+               ret = bus_for_each_dev(&soc_bus_type, dev, (void *)matches,
+                                      soc_device_match_one);

I don't remember what led to this, I think you are right, we should just pass NULL as most other callers.

Thanks for the review.

ARnd

author
#15 lore raw

RE: [v11, 7/8] base: soc: introduce soc_device_match() interface

Hi Anrd and Uffe,

Thank you for your comment.
Please see my comment inline.

Best regards,
Yangbo Lu

Quoted 22 lines

-----Original Message-----
From: Arnd Bergmann [mailto:arnd at arndb.de]
Sent: Tuesday, September 06, 2016 8:46 PM
To: Ulf Hansson
Cc: Y.B. Lu; linux-mmc; Scott Wood; linuxppc-dev at lists.ozlabs.org; devicetree at vger.kernel.org; linux-arm-kernel at lists.infradead.org; linux- kernel at vger.kernel.org; linux-clk; linux-i2c at vger.kernel.org; iommu at lists.linux-foundation.org; netdev at vger.kernel.org; Mark Rutland; Rob Herring; Russell King; Jochen Friedrich; Joerg Roedel; Claudiu Manoil; Bhupesh Sharma; Qiang Zhao; Kumar Gala; Santosh Shilimkar; Leo Li; X.B. Xie
Subject: Re: [v11, 7/8] base: soc: introduce soc_device_match() interface

Quoted 7 lines · CEST Ulf Hansson
Quoted 6 lines · Yangbo Lu

We keep running into cases where device drivers want to know the exact version of the a SoC they are currently running on. In the past, this has usually been done through a vendor specific API that can be called by a driver, or by directly accessing some kind of version register that is not part of the device itself but that belongs to a global register area of the chip.

Quoted 6 lines

Please add "From: Arnd Bergmann <[email protected]>" as the first line, to preserve authorship. If you use "git send-email" or "git format-patch", that should happen automatically if the author field is set right (if not, use 'git commit --amend --author="Arnd Bergmann <[email protected]>"' to fix it).

[Lu Yangbo-B47093] Oh, I'm sorry for my careless. Will correct it in next version.

Quoted 48 lines
Quoted 8 lines

drivers/base/soc.c static void __exit soc_bus_unregister(void) · line 199

Quoted 4 lines
drivers/base/soc.c +4 -0
+
+/*
+ * soc_device_match - identify the SoC in the machine
+ * @matches: zero-terminated array of possible matches

Perhaps also express the constraint on the matching entries. As you need at least one of the ->machine(), ->family(), ->revision() or ->soc_id() callbacks implemented, right!?

They are not callbacks, just strings. Having an empty entry indicates the end of the array, and this is not called.

Quoted 17 lines
Quoted 8 lines

+ *
+ * returns the first matching entry of the argument array, or NULL
+ * if none of them match.
+ *
+ * This function is meant as a helper in place of of_match_node()
+ * in cases where either no device tree is available or the
+ information
+ * in a device node is insufficient to identify a particular

Quoted 8 lines

+ variant
+ * by its compatible strings or other properties. For new devices,
+ * the DT binding should always provide unique compatible strings
+ * that allow the use of of_match_node() instead.
+ *
+ * The calling function can use the .data entry of the
+ * soc_device_attribute to pass a structure or function pointer for
+ * each entry.

Quoted 4 lines

I don't get the use case behind this, could you elaborate?

Perhaps we should postpone adding the .data entry until we actually see a need for it?

I think the interface is rather useless without a way to figure out which entry you got. Almost all users of of_match_node() actually use the returned ->data field, and I expect this to be the same here.

Quoted 9 lines

drivers/base/soc.c static void __exit soc_bus_unregister(void) · line 221

Quoted 7 lines

+ */

drivers/base/soc.c +6 -0
+const struct soc_device_attribute *soc_device_match(
+       const struct soc_device_attribute *matches) {
+       struct device *dev;
+       int ret;
+
+       for (ret = 0; ret == 0; matches++) {

This loop looks a bit weird and unsafe.

Quoted 7 lines

Ah, and I thought I was being clever ;-)

Quoted 3 lines

1) Perhaps using a while loop makes this more readable?
2) As this is an exported API, I guess validation of the ->matches pointer needs to be done before accessing it.

Sounds fine.

[Lu Yangbo-B47093] Ok, Will change this according to Uffe.
And actually there is issue with this for() when I verified it again this morning. We will get matches++ rather than matches which is correct finally :)

Quoted 9 lines
Quoted 9 lines

drivers/base/soc.c static void __exit soc_bus_unregister(void) · line 225

Quoted 5 lines
drivers/base/soc.c +4 -0
+               if (!(matches->machine || matches->family ||
+                     matches->revision || matches->soc_id))
+                       return NULL;
+               dev = NULL;

There's no need to use a struct device just to assign it to NULL. Instead just provide the function below with NULL.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

+ ret = bus_for_each_dev(&soc_bus_type, dev, (void

*)matches,

Quoted 1 line
Quoted 1 line

+ soc_device_match_one);

I don't remember what led to this, I think you are right, we should just pass NULL as most other callers.

[Lu Yangbo-B47093] Will correct it. Thanks. :)

Quoted 4 lines

Thanks for the review.

ARnd

author
#16 lore raw

PATCH v11 8/8 mmc: sdhci-of-esdhc: fix host version for T4240-R1.0-R2.0

In reply to Yangbo Lu

The eSDHC of T4240-R1.0-R2.0 has incorrect vender version and spec version. Acturally the right version numbers should be VVN=0x13 and SVN = 0x1. This patch adds the GUTS driver support for eSDHC driver to match SoC. And fix host version to avoid that incorrect version numbers break down the ADMA data transfer.

---
Changes for v2:
- Got SVR through iomap instead of dts
Changes for v3:
- Managed GUTS through syscon instead of iomap in eSDHC driver
Changes for v4:
- Got SVR by GUTS driver instead of SYSCON
Changes for v5:
- Changed to get SVR through API fsl_guts_get_svr()
- Combined patch 4, patch 5 and patch 6 into one
Changes for v6:
- Added 'Acked-by: Ulf Hansson'
Changes for v7:
- None
Changes for v8:
- Added 'Acked-by: Scott Wood'
Changes for v9:
- None
Changes for v10:
- None
Changes for v11:
- Changed to use soc_device_match

---
 drivers/mmc/host/Kconfig          |  1 +
 drivers/mmc/host/sdhci-of-esdhc.c | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)
drivers/mmc/host/Kconfig +1 -0
index 5274f50..a1135a9 100644
@@ -144,6 +144,7 @@ config MMC_SDHCI_OF_ESDHC
 	depends on MMC_SDHCI_PLTFM
 	depends on PPC || ARCH_MXC || ARCH_LAYERSCAPE
 	select MMC_SDHCI_IO_ACCESSORS
+	select FSL_GUTS
 	help
 	  This selects the Freescale eSDHC controller support.
 
drivers/mmc/host/sdhci-of-esdhc.c +20 -0
index fb71c86..0a31aa5 100644
@@ -18,6 +18,7 @@
 #include <linux/of.h>
 #include <linux/delay.h>
 #include <linux/module.h>
+#include <linux/sys_soc.h>
 #include <linux/mmc/host.h>
 #include "sdhci-pltfm.h"
 #include "sdhci-esdhc.h"
@@ -28,6 +29,7 @@
 struct sdhci_esdhc {
 	u8 vendor_ver;
 	u8 spec_ver;
+	bool quirk_incorrect_hostver;
 };
 
 /**
@@ -73,6 +75,8 @@ static u32 esdhc_readl_fixup(struct sdhci_host *host,
 static u16 esdhc_readw_fixup(struct sdhci_host *host,
 				     int spec_reg, u32 value)
 {
+	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+	struct sdhci_esdhc *esdhc = sdhci_pltfm_priv(pltfm_host);
 	u16 ret;
 	int shift = (spec_reg & 0x2) * 8;
 
@@ -80,6 +84,12 @@ static u16 esdhc_readw_fixup(struct sdhci_host *host,
 		ret = value & 0xffff;
 	else
 		ret = (value >> shift) & 0xffff;
+	/* Workaround for T4240-R1.0-R2.0 eSDHC which has incorrect
+	 * vendor version and spec version information.
+	 */
+	if ((spec_reg == SDHCI_HOST_VERSION) &&
+	    (esdhc->quirk_incorrect_hostver))
+		ret = (VENDOR_V_23 << SDHCI_VENDOR_VER_SHIFT) | SDHCI_SPEC_200;
 	return ret;
 }
 
@@ -558,6 +568,12 @@ static const struct sdhci_pltfm_data sdhci_esdhc_le_pdata = {
 	.ops = &sdhci_esdhc_le_ops,
 };
 
+static struct soc_device_attribute soc_incorrect_hostver[] = {
+	{ .soc_id = "*name:T4240*", .revision = "1.0", },
+	{ .soc_id = "*name:T4240*", .revision = "2.0", },
+	{ },
+};
+
 static void esdhc_init(struct platform_device *pdev, struct sdhci_host *host)
 {
 	struct sdhci_pltfm_host *pltfm_host;
@@ -571,6 +587,10 @@ static void esdhc_init(struct platform_device *pdev, struct sdhci_host *host)
 	esdhc->vendor_ver = (host_ver & SDHCI_VENDOR_VER_MASK) >>
 			     SDHCI_VENDOR_VER_SHIFT;
 	esdhc->spec_ver = host_ver & SDHCI_SPEC_VER_MASK;
+	if (soc_device_match(soc_incorrect_hostver))
+		esdhc->quirk_incorrect_hostver = true;
+	else
+		esdhc->quirk_incorrect_hostver = false;
 }
 
 static int sdhci_esdhc_probe(struct platform_device *pdev)
Signature · 1 line
2.1.0.27.g96db324