Subject: [PATCH 0/9] ARM: SAMSUNG: add Exynos chipid driver

Hi,

This patchset adds Exynos chipid driver and converts Exynos platform
code to use it. It is heavily based on "[PATCH v9 00/12] Introducing
Exynos ChipId driver" patchset [1] so most credits go to Pankaj Dubey.
The main difference in the current patchset is in taking simpler
approach to converting existing Exynos platform code to use the new
chipid driver. This results in much less code duplication.

The diffstat for "[PATCH v9 00/12] Introducing Exynos ChipId driver":

14 files changed, 587 insertions(+), 255 deletions(-)

for the current patchset it is:

14 files changed, 193 insertions(+), 195 deletions(-)

This patchset has been tested on Exynos4210 (including rev0),
Exynos3250, Exynos4412 & Exynos5422 SoCs.

[1] https://marc.info/?l=linux-arm-kernel&m=149087972213359&w=2

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics


Bartlomiej Zolnierkiewicz (5):
ARM: EXYNOS: use chipid driver
ARM: EXYNOS: remove soc_is_exynos*() macros
ARM: SAMSUNG: remove samsung_rev()
ARM: SAMSUNG: remove s5p_init_cpu()
ARM: EXYNOS: remove <mach/map.h> include

Pankaj Dubey (4):
ARM: EXYNOS: remove secondary startup initialization from
smp_prepare_cpus
soc: samsung: add exynos chipid driver support
ARM: EXYNOS: enable exynos_chipid for ARCH_EXYNOS
ARM64: EXYNOS: enable exynos_chipid for ARCH_EXYNOS

arch/arm/mach-exynos/Kconfig | 1 +
arch/arm/mach-exynos/common.h | 81 ++-----------------
arch/arm/mach-exynos/exynos.c | 75 ++++++++++--------
arch/arm/mach-exynos/firmware.c | 8 +-
arch/arm/mach-exynos/include/mach/map.h | 18 -----
arch/arm/mach-exynos/platsmp.c | 40 ++--------
arch/arm/mach-exynos/pm.c | 25 +++---
arch/arm/plat-samsung/cpu.c | 17 ----
arch/arm/plat-samsung/include/plat/cpu.h | 3 -
arch/arm/plat-samsung/include/plat/map-s5p.h | 2 -
arch/arm64/Kconfig.platforms | 1 +
drivers/soc/samsung/Kconfig | 5 ++
drivers/soc/samsung/Makefile | 1 +
drivers/soc/samsung/exynos-chipid.c | 111 +++++++++++++++++++++++++++
14 files changed, 193 insertions(+), 195 deletions(-)
delete mode 100644 arch/arm/mach-exynos/include/mach/map.h
create mode 100644 drivers/soc/samsung/exynos-chipid.c

--
1.9.1



Subject: [PATCH 1/9] ARM: EXYNOS: remove secondary startup initialization from smp_prepare_cpus

From: Pankaj Dubey <[email protected]>

We are taking care of setting secondary cpu boot address in
exynos_boot_secondary just before sending ipi to secondary CPUs,
so we can safely remove this setting from smp_prepare_cpus.

Signed-off-by: Pankaj Dubey <[email protected]>
Reviewed-by: Krzysztof Kozlowski <[email protected]>
Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
---
arch/arm/mach-exynos/platsmp.c | 26 --------------------------
1 file changed, 26 deletions(-)

diff --git a/arch/arm/mach-exynos/platsmp.c b/arch/arm/mach-exynos/platsmp.c
index 6a1e682..c39ffd2 100644
--- a/arch/arm/mach-exynos/platsmp.c
+++ b/arch/arm/mach-exynos/platsmp.c
@@ -397,38 +397,12 @@ static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)

static void __init exynos_smp_prepare_cpus(unsigned int max_cpus)
{
- int i;
-
exynos_sysram_init();

exynos_set_delayed_reset_assertion(true);

if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
exynos_scu_enable();
-
- /*
- * Write the address of secondary startup into the
- * system-wide flags register. The boot monitor waits
- * until it receives a soft interrupt, and then the
- * secondary CPU branches to this address.
- *
- * Try using firmware operation first and fall back to
- * boot register if it fails.
- */
- for (i = 1; i < max_cpus; ++i) {
- unsigned long boot_addr;
- u32 mpidr;
- u32 core_id;
- int ret;
-
- mpidr = cpu_logical_map(i);
- core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
- boot_addr = __pa_symbol(exynos4_secondary_startup);
-
- ret = exynos_set_boot_addr(core_id, boot_addr);
- if (ret)
- break;
- }
}

#ifdef CONFIG_HOTPLUG_CPU
--
1.9.1


Subject: [PATCH 4/9] ARM64: EXYNOS: enable exynos_chipid for ARCH_EXYNOS

From: Pankaj Dubey <[email protected]>

This patch enables exynos_chipid driver for ARCH_EXYNOS
based SoC.

Signed-off-by: Pankaj Dubey <[email protected]>
Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
---
arch/arm64/Kconfig.platforms | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/arm64/Kconfig.platforms b/arch/arm64/Kconfig.platforms
index 51bc479..84b88ab7 100644
--- a/arch/arm64/Kconfig.platforms
+++ b/arch/arm64/Kconfig.platforms
@@ -62,6 +62,7 @@ config ARCH_BRCMSTB
config ARCH_EXYNOS
bool "ARMv8 based Samsung Exynos SoC family"
select COMMON_CLK_SAMSUNG
+ select EXYNOS_CHIPID
select EXYNOS_PM_DOMAINS if PM_GENERIC_DOMAINS
select EXYNOS_PMU
select HAVE_S3C2410_WATCHDOG if WATCHDOG
--
1.9.1


Subject: [PATCH 7/9] ARM: SAMSUNG: remove samsung_rev()

* Add soc_dev_is_exynos4210_rev11() helper.

* Convert exynos_boot_vector_{addr,flag}() to use chipid driver.

* Remove no longer needed samsung_rev() & co.

Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
---
arch/arm/mach-exynos/common.h | 6 +-----
arch/arm/mach-exynos/exynos.c | 6 ++++++
arch/arm/mach-exynos/pm.c | 8 ++++----
arch/arm/plat-samsung/cpu.c | 10 ----------
arch/arm/plat-samsung/include/plat/cpu.h | 2 --
5 files changed, 11 insertions(+), 21 deletions(-)

diff --git a/arch/arm/mach-exynos/common.h b/arch/arm/mach-exynos/common.h
index 1dfd434..322d6eb 100644
--- a/arch/arm/mach-exynos/common.h
+++ b/arch/arm/mach-exynos/common.h
@@ -13,14 +13,11 @@
#include <linux/platform_data/cpuidle-exynos.h>

extern bool soc_dev_is_exynos3250(void);
+extern bool soc_dev_is_exynos4210_rev10(void);
extern bool soc_dev_is_exynos4210_rev11(void);
extern bool soc_dev_is_exynos4412(void);
extern bool soc_dev_is_exynos542x(void);

-#define EXYNOS4210_REV_0 (0x0)
-#define EXYNOS4210_REV_1_0 (0x10)
-#define EXYNOS4210_REV_1_1 (0x11)
-
extern u32 cp15_save_diag;
extern u32 cp15_save_power;

@@ -81,7 +78,6 @@ static inline void exynos_scu_enable(void) { }

extern void exynos_set_delayed_reset_assertion(bool enable);

-extern unsigned int samsung_rev(void);
extern void exynos_core_restart(u32 core_id);
extern int exynos_set_boot_addr(u32 core_id, unsigned long boot_addr);
extern int exynos_get_boot_addr(u32 core_id, unsigned long *boot_addr);
diff --git a/arch/arm/mach-exynos/exynos.c b/arch/arm/mach-exynos/exynos.c
index 463e457..ca367b7 100644
--- a/arch/arm/mach-exynos/exynos.c
+++ b/arch/arm/mach-exynos/exynos.c
@@ -29,6 +29,11 @@
{ /* sentinel */ }
};

+static const struct soc_device_attribute exynos4210_rev10_soc_id[] = {
+ { .soc_id = "EXYNOS4210", .revision = "10" },
+ { /* sentinel */ }
+};
+
static const struct soc_device_attribute exynos4210_rev11_soc_id[] = {
{ .soc_id = "EXYNOS4210", .revision = "11" },
{ /* sentinel */ }
@@ -59,6 +64,7 @@
}

SOC_DEV_IS_EXYNOS(3250);
+SOC_DEV_IS_EXYNOS(4210_rev10);
SOC_DEV_IS_EXYNOS(4210_rev11);
SOC_DEV_IS_EXYNOS(4412);
SOC_DEV_IS_EXYNOS(542x);
diff --git a/arch/arm/mach-exynos/pm.c b/arch/arm/mach-exynos/pm.c
index 88c1bce..0109dc4 100644
--- a/arch/arm/mach-exynos/pm.c
+++ b/arch/arm/mach-exynos/pm.c
@@ -26,18 +26,18 @@

static inline void __iomem *exynos_boot_vector_addr(void)
{
- if (samsung_rev() == EXYNOS4210_REV_1_1)
+ if (soc_dev_is_exynos4210_rev11())
return pmu_base_addr + S5P_INFORM7;
- else if (samsung_rev() == EXYNOS4210_REV_1_0)
+ else if (soc_dev_is_exynos4210_rev10())
return sysram_base_addr + 0x24;
return pmu_base_addr + S5P_INFORM0;
}

static inline void __iomem *exynos_boot_vector_flag(void)
{
- if (samsung_rev() == EXYNOS4210_REV_1_1)
+ if (soc_dev_is_exynos4210_rev11())
return pmu_base_addr + S5P_INFORM6;
- else if (samsung_rev() == EXYNOS4210_REV_1_0)
+ else if (soc_dev_is_exynos4210_rev10())
return sysram_base_addr + 0x20;
return pmu_base_addr + S5P_INFORM1;
}
diff --git a/arch/arm/plat-samsung/cpu.c b/arch/arm/plat-samsung/cpu.c
index e1ba88b..c633a24 100644
--- a/arch/arm/plat-samsung/cpu.c
+++ b/arch/arm/plat-samsung/cpu.c
@@ -14,13 +14,6 @@
#include <plat/cpu.h>

unsigned long samsung_cpu_id;
-static unsigned int samsung_cpu_rev;
-
-unsigned int samsung_rev(void)
-{
- return samsung_cpu_rev;
-}
-EXPORT_SYMBOL(samsung_rev);

void __init s3c64xx_init_cpu(void)
{
@@ -34,15 +27,12 @@ void __init s3c64xx_init_cpu(void)
samsung_cpu_id = readl_relaxed(S3C_VA_SYS + 0xA1C);
}

- samsung_cpu_rev = 0;
-
pr_info("Samsung CPU ID: 0x%08lx\n", samsung_cpu_id);
}

void __init s5p_init_cpu(const void __iomem *cpuid_addr)
{
samsung_cpu_id = readl_relaxed(cpuid_addr);
- samsung_cpu_rev = samsung_cpu_id & 0xFF;

pr_info("Samsung CPU ID: 0x%08lx\n", samsung_cpu_id);
}
diff --git a/arch/arm/plat-samsung/include/plat/cpu.h b/arch/arm/plat-samsung/include/plat/cpu.h
index fadcddb..02d7f99 100644
--- a/arch/arm/plat-samsung/include/plat/cpu.h
+++ b/arch/arm/plat-samsung/include/plat/cpu.h
@@ -111,8 +111,6 @@ extern void s3c_init_cpu(unsigned long idcode,
extern void s3c64xx_init_cpu(void);
extern void s5p_init_cpu(const void __iomem *cpuid_addr);

-extern unsigned int samsung_rev(void);
-
extern void s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no);

extern void s3c24xx_init_clocks(int xtal);
--
1.9.1


Subject: [PATCH 8/9] ARM: SAMSUNG: remove s5p_init_cpu()

Remove no longer needed s5p_init_cpu() & co.

Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
---
arch/arm/mach-exynos/exynos.c | 28 ----------------------------
arch/arm/plat-samsung/cpu.c | 7 -------
arch/arm/plat-samsung/include/plat/cpu.h | 1 -
arch/arm/plat-samsung/include/plat/map-s5p.h | 2 --
4 files changed, 38 deletions(-)

diff --git a/arch/arm/mach-exynos/exynos.c b/arch/arm/mach-exynos/exynos.c
index ca367b7..d98574c 100644
--- a/arch/arm/mach-exynos/exynos.c
+++ b/arch/arm/mach-exynos/exynos.c
@@ -20,7 +20,6 @@
#include <asm/mach/map.h>

#include <mach/map.h>
-#include <plat/cpu.h>

#include "common.h"

@@ -99,36 +98,9 @@ void __init exynos_sysram_init(void)
}
}

-static int __init exynos_fdt_map_chipid(unsigned long node, const char *uname,
- int depth, void *data)
-{
- struct map_desc iodesc;
- const __be32 *reg;
- int len;
-
- if (!of_flat_dt_is_compatible(node, "samsung,exynos4210-chipid"))
- return 0;
-
- reg = of_get_flat_dt_prop(node, "reg", &len);
- if (reg == NULL || len != (sizeof(unsigned long) * 2))
- return 0;
-
- iodesc.pfn = __phys_to_pfn(be32_to_cpu(reg[0]));
- iodesc.length = be32_to_cpu(reg[1]) - 1;
- iodesc.virtual = (unsigned long)S5P_VA_CHIPID;
- iodesc.type = MT_DEVICE;
- iotable_init(&iodesc, 1);
- return 1;
-}
-
static void __init exynos_init_io(void)
{
debug_ll_io_init();
-
- of_scan_flat_dt(exynos_fdt_map_chipid, NULL);
-
- /* detect cpu id and rev. */
- s5p_init_cpu(S5P_VA_CHIPID);
}

/*
diff --git a/arch/arm/plat-samsung/cpu.c b/arch/arm/plat-samsung/cpu.c
index c633a24..8acba21 100644
--- a/arch/arm/plat-samsung/cpu.c
+++ b/arch/arm/plat-samsung/cpu.c
@@ -29,10 +29,3 @@ void __init s3c64xx_init_cpu(void)

pr_info("Samsung CPU ID: 0x%08lx\n", samsung_cpu_id);
}
-
-void __init s5p_init_cpu(const void __iomem *cpuid_addr)
-{
- samsung_cpu_id = readl_relaxed(cpuid_addr);
-
- pr_info("Samsung CPU ID: 0x%08lx\n", samsung_cpu_id);
-}
diff --git a/arch/arm/plat-samsung/include/plat/cpu.h b/arch/arm/plat-samsung/include/plat/cpu.h
index 02d7f99..93ecd71 100644
--- a/arch/arm/plat-samsung/include/plat/cpu.h
+++ b/arch/arm/plat-samsung/include/plat/cpu.h
@@ -109,7 +109,6 @@ extern void s3c_init_cpu(unsigned long idcode,
extern void s3c24xx_init_io(struct map_desc *mach_desc, int size);

extern void s3c64xx_init_cpu(void);
-extern void s5p_init_cpu(const void __iomem *cpuid_addr);

extern void s3c24xx_init_uarts(struct s3c2410_uartcfg *cfg, int no);

diff --git a/arch/arm/plat-samsung/include/plat/map-s5p.h b/arch/arm/plat-samsung/include/plat/map-s5p.h
index d69a0ca..3812085 100644
--- a/arch/arm/plat-samsung/include/plat/map-s5p.h
+++ b/arch/arm/plat-samsung/include/plat/map-s5p.h
@@ -9,8 +9,6 @@
#ifndef __ASM_PLAT_MAP_S5P_H
#define __ASM_PLAT_MAP_S5P_H __FILE__

-#define S5P_VA_CHIPID S3C_ADDR(0x02000000)
-
#define VA_VIC(x) (S3C_VA_IRQ + ((x) * 0x10000))
#define VA_VIC0 VA_VIC(0)
#define VA_VIC1 VA_VIC(1)
--
1.9.1


Subject: [PATCH 5/9] ARM: EXYNOS: use chipid driver

Add soc_dev_is_exynos*() helpers and use them instead of
soc_is_exynos*() ones.

Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
---
arch/arm/mach-exynos/common.h | 6 ++++++
arch/arm/mach-exynos/exynos.c | 39 +++++++++++++++++++++++++++++++++++++++
arch/arm/mach-exynos/firmware.c | 8 ++++----
arch/arm/mach-exynos/platsmp.c | 12 ++++++------
arch/arm/mach-exynos/pm.c | 17 +++++++++--------
5 files changed, 64 insertions(+), 18 deletions(-)

diff --git a/arch/arm/mach-exynos/common.h b/arch/arm/mach-exynos/common.h
index 1b8699e..20d205e 100644
--- a/arch/arm/mach-exynos/common.h
+++ b/arch/arm/mach-exynos/common.h
@@ -9,8 +9,14 @@
#ifndef __ARCH_ARM_MACH_EXYNOS_COMMON_H
#define __ARCH_ARM_MACH_EXYNOS_COMMON_H

+#include <linux/sys_soc.h>
#include <linux/platform_data/cpuidle-exynos.h>

+extern bool soc_dev_is_exynos3250(void);
+extern bool soc_dev_is_exynos4210_rev11(void);
+extern bool soc_dev_is_exynos4412(void);
+extern bool soc_dev_is_exynos542x(void);
+
#define EXYNOS3250_SOC_ID 0xE3472000
#define EXYNOS3_SOC_MASK 0xFFFFF000

diff --git a/arch/arm/mach-exynos/exynos.c b/arch/arm/mach-exynos/exynos.c
index 865dcc4..463e457 100644
--- a/arch/arm/mach-exynos/exynos.c
+++ b/arch/arm/mach-exynos/exynos.c
@@ -24,6 +24,45 @@

#include "common.h"

+static const struct soc_device_attribute exynos3250_soc_id[] = {
+ { .soc_id = "EXYNOS3250" },
+ { /* sentinel */ }
+};
+
+static const struct soc_device_attribute exynos4210_rev11_soc_id[] = {
+ { .soc_id = "EXYNOS4210", .revision = "11" },
+ { /* sentinel */ }
+};
+
+static const struct soc_device_attribute exynos4412_soc_id[] = {
+ { .soc_id = "EXYNOS4412" },
+ { /* sentinel */ }
+};
+
+static const struct soc_device_attribute exynos542x_soc_id[] = {
+ { .soc_id = "EXYNOS5420" },
+ { .soc_id = "EXYNOS5800" },
+ { /* sentinel */ }
+};
+
+#define SOC_DEV_IS_EXYNOS(ver) \
+bool soc_dev_is_exynos##ver(void) \
+{ \
+ static bool init_done, is_exynos##ver; \
+ \
+ if (!init_done) { \
+ is_exynos##ver = !!soc_device_match(exynos##ver##_soc_id); \
+ init_done = true; \
+ } \
+ \
+ return is_exynos##ver; \
+}
+
+SOC_DEV_IS_EXYNOS(3250);
+SOC_DEV_IS_EXYNOS(4210_rev11);
+SOC_DEV_IS_EXYNOS(4412);
+SOC_DEV_IS_EXYNOS(542x);
+
static struct platform_device exynos_cpuidle = {
.name = "exynos_cpuidle",
#ifdef CONFIG_ARM_EXYNOS_CPUIDLE
diff --git a/arch/arm/mach-exynos/firmware.c b/arch/arm/mach-exynos/firmware.c
index d602e3b..d526d5e 100644
--- a/arch/arm/mach-exynos/firmware.c
+++ b/arch/arm/mach-exynos/firmware.c
@@ -40,7 +40,7 @@ static int exynos_do_idle(unsigned long mode)
writel_relaxed(__pa_symbol(exynos_cpu_resume_ns),
sysram_ns_base_addr + 0x24);
writel_relaxed(EXYNOS_AFTR_MAGIC, sysram_ns_base_addr + 0x20);
- if (soc_is_exynos3250()) {
+ if (soc_dev_is_exynos3250()) {
flush_cache_all();
exynos_smc(SMC_CMD_SAVE, OP_TYPE_CORE,
SMC_POWERSTATE_IDLE, 0);
@@ -61,7 +61,7 @@ static int exynos_cpu_boot(int cpu)
* Exynos3250 doesn't need to send smc command for secondary CPU boot
* because Exynos3250 removes WFE in secure mode.
*/
- if (soc_is_exynos3250())
+ if (soc_dev_is_exynos3250())
return 0;

/*
@@ -85,7 +85,7 @@ static int exynos_set_cpu_boot_addr(int cpu, unsigned long boot_addr)
* additional offset for every CPU, with Exynos4412 being the only
* exception.
*/
- if (soc_is_exynos4412())
+ if (soc_dev_is_exynos4412())
boot_reg += 4 * cpu;

writel_relaxed(boot_addr, boot_reg);
@@ -101,7 +101,7 @@ static int exynos_get_cpu_boot_addr(int cpu, unsigned long *boot_addr)

boot_reg = sysram_ns_base_addr + 0x1c;

- if (soc_is_exynos4412())
+ if (soc_dev_is_exynos4412())
boot_reg += 4 * cpu;

*boot_addr = readl_relaxed(boot_reg);
diff --git a/arch/arm/mach-exynos/platsmp.c b/arch/arm/mach-exynos/platsmp.c
index c39ffd2..e2ba70f 100644
--- a/arch/arm/mach-exynos/platsmp.c
+++ b/arch/arm/mach-exynos/platsmp.c
@@ -88,7 +88,7 @@ void exynos_cpu_power_down(int cpu)
{
u32 core_conf;

- if (cpu == 0 && (soc_is_exynos5420() || soc_is_exynos5800())) {
+ if (cpu == 0 && soc_dev_is_exynos542x()) {
/*
* Bypass power down for CPU0 during suspend. Check for
* the SYS_PWR_REG value to decide if we are suspending
@@ -115,7 +115,7 @@ void exynos_cpu_power_up(int cpu)
{
u32 core_conf = S5P_CORE_LOCAL_PWR_EN;

- if (soc_is_exynos3250())
+ if (soc_dev_is_exynos3250())
core_conf |= S5P_CORE_AUTOWAKEUP_EN;

pmu_raw_writel(core_conf,
@@ -185,7 +185,7 @@ void exynos_scu_enable(void)

static void __iomem *cpu_boot_reg_base(void)
{
- if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_1_1)
+ if (soc_dev_is_exynos4210_rev11())
return pmu_base_addr + S5P_INFORM5;
return sysram_base_addr;
}
@@ -197,9 +197,9 @@ static inline void __iomem *cpu_boot_reg(int cpu)
boot_reg = cpu_boot_reg_base();
if (!boot_reg)
return IOMEM_ERR_PTR(-ENODEV);
- if (soc_is_exynos4412())
+ if (soc_dev_is_exynos4412())
boot_reg += 4*cpu;
- else if (soc_is_exynos5420() || soc_is_exynos5800())
+ else if (soc_dev_is_exynos542x())
boot_reg += 4;
return boot_reg;
}
@@ -371,7 +371,7 @@ static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)

call_firmware_op(cpu_boot, core_id);

- if (soc_is_exynos3250())
+ if (soc_dev_is_exynos3250())
dsb_sev();
else
arch_send_wakeup_ipi_mask(cpumask_of(cpu));
diff --git a/arch/arm/mach-exynos/pm.c b/arch/arm/mach-exynos/pm.c
index 48e7fb3..88c1bce 100644
--- a/arch/arm/mach-exynos/pm.c
+++ b/arch/arm/mach-exynos/pm.c
@@ -120,7 +120,7 @@ int exynos_pm_central_resume(void)
static void exynos_set_wakeupmask(long mask)
{
pmu_raw_writel(mask, S5P_WAKEUP_MASK);
- if (soc_is_exynos3250())
+ if (soc_dev_is_exynos3250())
pmu_raw_writel(0x0, S5P_WAKEUP_MASK2);
}

@@ -135,7 +135,8 @@ static int exynos_aftr_finisher(unsigned long flags)
{
int ret;

- exynos_set_wakeupmask(soc_is_exynos3250() ? 0x40003ffe : 0x0000ff3e);
+ exynos_set_wakeupmask(soc_dev_is_exynos3250() ? 0x40003ffe
+ : 0x0000ff3e);
/* Set value of power down register for aftr mode */
exynos_sys_powerdown_conf(SYS_AFTR);

@@ -156,12 +157,12 @@ void exynos_enter_aftr(void)

cpu_pm_enter();

- if (soc_is_exynos3250())
+ if (soc_dev_is_exynos3250())
exynos_set_boot_flag(cpuid, C2_STATE);

exynos_pm_central_suspend();

- if (soc_is_exynos4412()) {
+ if (soc_dev_is_exynos4412()) {
/* Setting SEQ_OPTION register */
pmu_raw_writel(S5P_USE_STANDBY_WFI0 | S5P_USE_STANDBY_WFE0,
S5P_CENTRAL_SEQ_OPTION);
@@ -177,7 +178,7 @@ void exynos_enter_aftr(void)

exynos_pm_central_resume();

- if (soc_is_exynos3250())
+ if (soc_dev_is_exynos3250())
exynos_clear_boot_flag(cpuid, C2_STATE);

cpu_pm_exit();
@@ -248,7 +249,7 @@ static int exynos_cpu0_enter_aftr(void)
while (exynos_cpu_power_state(1) != S5P_CORE_LOCAL_PWR_EN)
cpu_relax();

- if (soc_is_exynos3250()) {
+ if (soc_dev_is_exynos3250()) {
while (!pmu_raw_readl(S5P_PMU_SPARE2) &&
!atomic_read(&cpu1_wakeup))
cpu_relax();
@@ -278,7 +279,7 @@ static int exynos_cpu0_enter_aftr(void)

static int exynos_wfi_finisher(unsigned long flags)
{
- if (soc_is_exynos3250())
+ if (soc_dev_is_exynos3250())
flush_cache_all();
cpu_do_idle();

@@ -300,7 +301,7 @@ static int exynos_cpu1_powerdown(void)
*/
exynos_cpu_power_down(1);

- if (soc_is_exynos3250())
+ if (soc_dev_is_exynos3250())
pmu_raw_writel(0, S5P_PMU_SPARE2);

ret = cpu_suspend(0, exynos_wfi_finisher);
--
1.9.1


Subject: [PATCH 2/9] soc: samsung: add exynos chipid driver support

From: Pankaj Dubey <[email protected]>

Exynos SoCs have Chipid, for identification of product IDs and SoC
revisions. This patch intends to provide initialization code for all
these functionalities, at the same time it provides some sysfs entries
for accessing these information to user-space.

This driver uses existing binding for exynos-chipid.

Changes by Bartlomiej:
- fixed return values on errors
- removed bogus kfree_const()
- added missing Exynos4210 EVT0 id
- converted code to use EXYNOS_MASK define
- fixed np use after of_node_put()
- fixed too early use of dev_info()
- made driver fail for unknown SoC-s
- added SPDX tag
- updated Copyrights

Cc: Grant Likely <[email protected]>
Cc: Rob Herring <[email protected]>
Cc: Linus Walleij <[email protected]>
Signed-off-by: Pankaj Dubey <[email protected]>
[m.szyprowski: for suggestion and code snippet of product_id_to_soc_id]
Signed-off-by: Marek Szyprowski <[email protected]>
Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
---
drivers/soc/samsung/Kconfig | 5 ++
drivers/soc/samsung/Makefile | 1 +
drivers/soc/samsung/exynos-chipid.c | 111 ++++++++++++++++++++++++++++++++++++
3 files changed, 117 insertions(+)
create mode 100644 drivers/soc/samsung/exynos-chipid.c

diff --git a/drivers/soc/samsung/Kconfig b/drivers/soc/samsung/Kconfig
index 2186285..2905f52 100644
--- a/drivers/soc/samsung/Kconfig
+++ b/drivers/soc/samsung/Kconfig
@@ -7,6 +7,11 @@ menuconfig SOC_SAMSUNG

if SOC_SAMSUNG

+config EXYNOS_CHIPID
+ bool "Exynos Chipid controller driver" if COMPILE_TEST
+ depends on ARCH_EXYNOS || COMPILE_TEST
+ select SOC_BUS
+
config EXYNOS_PMU
bool "Exynos PMU controller driver" if COMPILE_TEST
depends on ARCH_EXYNOS || ((ARM || ARM64) && COMPILE_TEST)
diff --git a/drivers/soc/samsung/Makefile b/drivers/soc/samsung/Makefile
index 29f294b..c2a8fbc 100644
--- a/drivers/soc/samsung/Makefile
+++ b/drivers/soc/samsung/Makefile
@@ -1,4 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_EXYNOS_CHIPID) += exynos-chipid.o
obj-$(CONFIG_EXYNOS_PMU) += exynos-pmu.o

obj-$(CONFIG_EXYNOS_PMU_ARM_DRIVERS) += exynos3250-pmu.o exynos4-pmu.o \
diff --git a/drivers/soc/samsung/exynos-chipid.c b/drivers/soc/samsung/exynos-chipid.c
new file mode 100644
index 0000000..5cb0188
--- /dev/null
+++ b/drivers/soc/samsung/exynos-chipid.c
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * http://www.samsung.com/
+ *
+ * EXYNOS - CHIP ID support
+ * Author: Pankaj Dubey <[email protected]>
+ * Author: Bartlomiej Zolnierkiewicz <[email protected]>
+ */
+
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/sys_soc.h>
+
+#define EXYNOS_SUBREV_MASK (0xF << 4)
+#define EXYNOS_MAINREV_MASK (0xF << 0)
+#define EXYNOS_REV_MASK (EXYNOS_SUBREV_MASK | EXYNOS_MAINREV_MASK)
+#define EXYNOS_MASK 0xFFFFF000
+
+static const struct exynos_soc_id {
+ const char *name;
+ unsigned int id;
+} soc_ids[] = {
+ { "EXYNOS3250", 0xE3472000 },
+ { "EXYNOS4210", 0x43200000 }, /* EVT0 revision */
+ { "EXYNOS4210", 0x43210000 },
+ { "EXYNOS4212", 0x43220000 },
+ { "EXYNOS4412", 0xE4412000 },
+ { "EXYNOS5250", 0x43520000 },
+ { "EXYNOS5260", 0xE5260000 },
+ { "EXYNOS5410", 0xE5410000 },
+ { "EXYNOS5420", 0xE5420000 },
+ { "EXYNOS5440", 0xE5440000 },
+ { "EXYNOS5800", 0xE5422000 },
+ { "EXYNOS7420", 0xE7420000 },
+ { "EXYNOS5433", 0xE5433000 },
+};
+
+static const char * __init product_id_to_soc_id(unsigned int product_id)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(soc_ids); i++)
+ if ((product_id & EXYNOS_MASK) == soc_ids[i].id)
+ return soc_ids[i].name;
+ return NULL;
+}
+
+int __init exynos_chipid_early_init(void)
+{
+ struct soc_device_attribute *soc_dev_attr;
+ void __iomem *exynos_chipid_base;
+ struct soc_device *soc_dev;
+ struct device_node *root;
+ struct device_node *np;
+ u32 product_id;
+ u32 revision;
+
+ /* look up for chipid node */
+ np = of_find_compatible_node(NULL, NULL, "samsung,exynos4210-chipid");
+ if (!np)
+ return -ENODEV;
+
+ exynos_chipid_base = of_iomap(np, 0);
+ of_node_put(np);
+
+ if (!exynos_chipid_base) {
+ pr_err("Failed to map SoC chipid\n");
+ return -ENXIO;
+ }
+
+ product_id = readl_relaxed(exynos_chipid_base);
+ revision = product_id & EXYNOS_REV_MASK;
+ iounmap(exynos_chipid_base);
+
+ soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
+ if (!soc_dev_attr)
+ return -ENOMEM;
+
+ soc_dev_attr->family = "Samsung Exynos";
+
+ root = of_find_node_by_path("/");
+ of_property_read_string(root, "model", &soc_dev_attr->machine);
+ of_node_put(root);
+
+ soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%x", revision);
+ soc_dev_attr->soc_id = product_id_to_soc_id(product_id);
+ if (!soc_dev_attr->soc_id) {
+ pr_err("Unknown SoC\n");
+ return -ENODEV;
+ }
+
+ /* please note that the actual registration will be deferred */
+ soc_dev = soc_device_register(soc_dev_attr);
+ if (IS_ERR(soc_dev)) {
+ kfree(soc_dev_attr->revision);
+ kfree(soc_dev_attr);
+ return PTR_ERR(soc_dev);
+ }
+
+ /* it is too early to use dev_info() here (soc_dev is NULL) */
+ pr_info("soc soc0: Exynos: CPU[%s] PRO_ID[0x%x] REV[0x%x] Detected\n",
+ soc_dev_attr->soc_id, product_id, revision);
+
+ return 0;
+}
+early_initcall(exynos_chipid_early_init);
--
1.9.1


Subject: [PATCH 3/9] ARM: EXYNOS: enable exynos_chipid for ARCH_EXYNOS

From: Pankaj Dubey <[email protected]>

As now we have chipid driver to initialize SoC related information
let's include it in build by default.

Signed-off-by: Pankaj Dubey <[email protected]>
Reviewed-by: Krzysztof Kozlowski <[email protected]>
Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
---
arch/arm/mach-exynos/Kconfig | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-exynos/Kconfig b/arch/arm/mach-exynos/Kconfig
index b40963c..e3e63aa 100644
--- a/arch/arm/mach-exynos/Kconfig
+++ b/arch/arm/mach-exynos/Kconfig
@@ -13,6 +13,7 @@ menuconfig ARCH_EXYNOS
select ARM_AMBA
select ARM_GIC
select COMMON_CLK_SAMSUNG
+ select EXYNOS_CHIPID
select EXYNOS_THERMAL
select EXYNOS_PMU
select EXYNOS_SROM
--
1.9.1


Subject: [PATCH 6/9] ARM: EXYNOS: remove soc_is_exynos*() macros

Remove no longer needed soc_is_exynos*() macros & co.

Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
---
arch/arm/mach-exynos/common.h | 71 -------------------------------------------
1 file changed, 71 deletions(-)

diff --git a/arch/arm/mach-exynos/common.h b/arch/arm/mach-exynos/common.h
index 20d205e..1dfd434 100644
--- a/arch/arm/mach-exynos/common.h
+++ b/arch/arm/mach-exynos/common.h
@@ -17,81 +17,10 @@
extern bool soc_dev_is_exynos4412(void);
extern bool soc_dev_is_exynos542x(void);

-#define EXYNOS3250_SOC_ID 0xE3472000
-#define EXYNOS3_SOC_MASK 0xFFFFF000
-
-#define EXYNOS4210_CPU_ID 0x43210000
-#define EXYNOS4412_CPU_ID 0xE4412200
-#define EXYNOS4_CPU_MASK 0xFFFE0000
-
-#define EXYNOS5250_SOC_ID 0x43520000
-#define EXYNOS5410_SOC_ID 0xE5410000
-#define EXYNOS5420_SOC_ID 0xE5420000
-#define EXYNOS5800_SOC_ID 0xE5422000
-#define EXYNOS5_SOC_MASK 0xFFFFF000
-
-extern unsigned long samsung_cpu_id;
-
-#define IS_SAMSUNG_CPU(name, id, mask) \
-static inline int is_samsung_##name(void) \
-{ \
- return ((samsung_cpu_id & mask) == (id & mask)); \
-}
-
-IS_SAMSUNG_CPU(exynos3250, EXYNOS3250_SOC_ID, EXYNOS3_SOC_MASK)
-IS_SAMSUNG_CPU(exynos4210, EXYNOS4210_CPU_ID, EXYNOS4_CPU_MASK)
-IS_SAMSUNG_CPU(exynos4412, EXYNOS4412_CPU_ID, EXYNOS4_CPU_MASK)
-IS_SAMSUNG_CPU(exynos5250, EXYNOS5250_SOC_ID, EXYNOS5_SOC_MASK)
-IS_SAMSUNG_CPU(exynos5410, EXYNOS5410_SOC_ID, EXYNOS5_SOC_MASK)
-IS_SAMSUNG_CPU(exynos5420, EXYNOS5420_SOC_ID, EXYNOS5_SOC_MASK)
-IS_SAMSUNG_CPU(exynos5800, EXYNOS5800_SOC_ID, EXYNOS5_SOC_MASK)
-
-#if defined(CONFIG_SOC_EXYNOS3250)
-# define soc_is_exynos3250() is_samsung_exynos3250()
-#else
-# define soc_is_exynos3250() 0
-#endif
-
-#if defined(CONFIG_CPU_EXYNOS4210)
-# define soc_is_exynos4210() is_samsung_exynos4210()
-#else
-# define soc_is_exynos4210() 0
-#endif
-
-#if defined(CONFIG_SOC_EXYNOS4412)
-# define soc_is_exynos4412() is_samsung_exynos4412()
-#else
-# define soc_is_exynos4412() 0
-#endif
-
#define EXYNOS4210_REV_0 (0x0)
#define EXYNOS4210_REV_1_0 (0x10)
#define EXYNOS4210_REV_1_1 (0x11)

-#if defined(CONFIG_SOC_EXYNOS5250)
-# define soc_is_exynos5250() is_samsung_exynos5250()
-#else
-# define soc_is_exynos5250() 0
-#endif
-
-#if defined(CONFIG_SOC_EXYNOS5410)
-# define soc_is_exynos5410() is_samsung_exynos5410()
-#else
-# define soc_is_exynos5410() 0
-#endif
-
-#if defined(CONFIG_SOC_EXYNOS5420)
-# define soc_is_exynos5420() is_samsung_exynos5420()
-#else
-# define soc_is_exynos5420() 0
-#endif
-
-#if defined(CONFIG_SOC_EXYNOS5800)
-# define soc_is_exynos5800() is_samsung_exynos5800()
-#else
-# define soc_is_exynos5800() 0
-#endif
-
extern u32 cp15_save_diag;
extern u32 cp15_save_power;

--
1.9.1


Subject: [PATCH 9/9] ARM: EXYNOS: remove <mach/map.h> include

Remove no longer needed <mach/map.h> include.

Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
---
arch/arm/mach-exynos/exynos.c | 2 --
arch/arm/mach-exynos/include/mach/map.h | 18 ------------------
arch/arm/mach-exynos/platsmp.c | 2 --
3 files changed, 22 deletions(-)
delete mode 100644 arch/arm/mach-exynos/include/mach/map.h

diff --git a/arch/arm/mach-exynos/exynos.c b/arch/arm/mach-exynos/exynos.c
index d98574c..d29f241 100644
--- a/arch/arm/mach-exynos/exynos.c
+++ b/arch/arm/mach-exynos/exynos.c
@@ -19,8 +19,6 @@
#include <asm/mach/arch.h>
#include <asm/mach/map.h>

-#include <mach/map.h>
-
#include "common.h"

static const struct soc_device_attribute exynos3250_soc_id[] = {
diff --git a/arch/arm/mach-exynos/include/mach/map.h b/arch/arm/mach-exynos/include/mach/map.h
deleted file mode 100644
index 22ebe36..0000000
--- a/arch/arm/mach-exynos/include/mach/map.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0 */
-/*
- * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
- * http://www.samsung.com/
- *
- * EXYNOS - Memory map definitions
- */
-
-#ifndef __ASM_ARCH_MAP_H
-#define __ASM_ARCH_MAP_H __FILE__
-
-#include <plat/map-base.h>
-
-#include <plat/map-s5p.h>
-
-#define EXYNOS_PA_CHIPID 0x10000000
-
-#endif /* __ASM_ARCH_MAP_H */
diff --git a/arch/arm/mach-exynos/platsmp.c b/arch/arm/mach-exynos/platsmp.c
index e2ba70f..56e2554 100644
--- a/arch/arm/mach-exynos/platsmp.c
+++ b/arch/arm/mach-exynos/platsmp.c
@@ -22,8 +22,6 @@
#include <asm/smp_scu.h>
#include <asm/firmware.h>

-#include <mach/map.h>
-
#include "common.h"

extern void exynos4_secondary_startup(void);
--
1.9.1


2018-11-16 09:25:00

by Markus Reichl

[permalink] [raw]
Subject: Re: [PATCH 0/9] ARM: SAMSUNG: add Exynos chipid driver

Hi Bartlomiej,


Am 15.11.18 um 16:11 schrieb Bartlomiej Zolnierkiewicz:
> Hi,
>
> This patchset adds Exynos chipid driver and converts Exynos platform
> code to use it. It is heavily based on "[PATCH v9 00/12] Introducing
> Exynos ChipId driver" patchset [1] so most credits go to Pankaj Dubey.
> The main difference in the current patchset is in taking simpler
> approach to converting existing Exynos platform code to use the new
> chipid driver. This results in much less code duplication.
>
> The diffstat for "[PATCH v9 00/12] Introducing Exynos ChipId driver":
>
> 14 files changed, 587 insertions(+), 255 deletions(-)
>
> for the current patchset it is:
>
> 14 files changed, 193 insertions(+), 195 deletions(-)
>
> This patchset has been tested on Exynos4210 (including rev0),
> Exynos3250, Exynos4412 & Exynos5422 SoCs.
>
> [1] https://marc.info/?l=linux-arm-kernel&m=149087972213359&w=2
>
> Best regards,
> --
> Bartlomiej Zolnierkiewicz
> Samsung R&D Institute Poland
> Samsung Electronics
>

tested on Odroid-XU4:
[ 0.022888] soc soc0: Exynos: CPU[EXYNOS5800] PRO_ID[0xe5422001] REV[0x1] Detected

Tested-by: Markus Reichl <[email protected]>

Gruß,
--
Markus Reichl
>
> Bartlomiej Zolnierkiewicz (5):
> ARM: EXYNOS: use chipid driver
> ARM: EXYNOS: remove soc_is_exynos*() macros
> ARM: SAMSUNG: remove samsung_rev()
> ARM: SAMSUNG: remove s5p_init_cpu()
> ARM: EXYNOS: remove <mach/map.h> include
>
> Pankaj Dubey (4):
> ARM: EXYNOS: remove secondary startup initialization from
> smp_prepare_cpus
> soc: samsung: add exynos chipid driver support
> ARM: EXYNOS: enable exynos_chipid for ARCH_EXYNOS
> ARM64: EXYNOS: enable exynos_chipid for ARCH_EXYNOS
>
> arch/arm/mach-exynos/Kconfig | 1 +
> arch/arm/mach-exynos/common.h | 81 ++-----------------
> arch/arm/mach-exynos/exynos.c | 75 ++++++++++--------
> arch/arm/mach-exynos/firmware.c | 8 +-
> arch/arm/mach-exynos/include/mach/map.h | 18 -----
> arch/arm/mach-exynos/platsmp.c | 40 ++--------
> arch/arm/mach-exynos/pm.c | 25 +++---
> arch/arm/plat-samsung/cpu.c | 17 ----
> arch/arm/plat-samsung/include/plat/cpu.h | 3 -
> arch/arm/plat-samsung/include/plat/map-s5p.h | 2 -
> arch/arm64/Kconfig.platforms | 1 +
> drivers/soc/samsung/Kconfig | 5 ++
> drivers/soc/samsung/Makefile | 1 +
> drivers/soc/samsung/exynos-chipid.c | 111 +++++++++++++++++++++++++++
> 14 files changed, 193 insertions(+), 195 deletions(-)
> delete mode 100644 arch/arm/mach-exynos/include/mach/map.h
> create mode 100644 drivers/soc/samsung/exynos-chipid.c
>


Attachments:
signature.asc (673.00 B)
OpenPGP digital signature

2018-11-16 12:25:24

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH 5/9] ARM: EXYNOS: use chipid driver

On Thu, 15 Nov 2018 at 16:12, Bartlomiej Zolnierkiewicz
<[email protected]> wrote:
>
> Add soc_dev_is_exynos*() helpers and use them instead of
> soc_is_exynos*() ones.
>
> Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
> ---
> arch/arm/mach-exynos/common.h | 6 ++++++
> arch/arm/mach-exynos/exynos.c | 39 +++++++++++++++++++++++++++++++++++++++
> arch/arm/mach-exynos/firmware.c | 8 ++++----
> arch/arm/mach-exynos/platsmp.c | 12 ++++++------
> arch/arm/mach-exynos/pm.c | 17 +++++++++--------
> 5 files changed, 64 insertions(+), 18 deletions(-)
>
> diff --git a/arch/arm/mach-exynos/common.h b/arch/arm/mach-exynos/common.h
> index 1b8699e..20d205e 100644
> --- a/arch/arm/mach-exynos/common.h
> +++ b/arch/arm/mach-exynos/common.h
> @@ -9,8 +9,14 @@
> #ifndef __ARCH_ARM_MACH_EXYNOS_COMMON_H
> #define __ARCH_ARM_MACH_EXYNOS_COMMON_H
>
> +#include <linux/sys_soc.h>
> #include <linux/platform_data/cpuidle-exynos.h>
>
> +extern bool soc_dev_is_exynos3250(void);
> +extern bool soc_dev_is_exynos4210_rev11(void);
> +extern bool soc_dev_is_exynos4412(void);
> +extern bool soc_dev_is_exynos542x(void);
> +
> #define EXYNOS3250_SOC_ID 0xE3472000
> #define EXYNOS3_SOC_MASK 0xFFFFF000
>
> diff --git a/arch/arm/mach-exynos/exynos.c b/arch/arm/mach-exynos/exynos.c
> index 865dcc4..463e457 100644
> --- a/arch/arm/mach-exynos/exynos.c
> +++ b/arch/arm/mach-exynos/exynos.c
> @@ -24,6 +24,45 @@
>
> #include "common.h"
>
> +static const struct soc_device_attribute exynos3250_soc_id[] = {
> + { .soc_id = "EXYNOS3250" },
> + { /* sentinel */ }
> +};
> +
> +static const struct soc_device_attribute exynos4210_rev11_soc_id[] = {
> + { .soc_id = "EXYNOS4210", .revision = "11" },
> + { /* sentinel */ }
> +};
> +
> +static const struct soc_device_attribute exynos4412_soc_id[] = {
> + { .soc_id = "EXYNOS4412" },
> + { /* sentinel */ }
> +};
> +
> +static const struct soc_device_attribute exynos542x_soc_id[] = {
> + { .soc_id = "EXYNOS5420" },
> + { .soc_id = "EXYNOS5800" },
> + { /* sentinel */ }
> +};
> +
> +#define SOC_DEV_IS_EXYNOS(ver) \
> +bool soc_dev_is_exynos##ver(void) \
> +{ \
> + static bool init_done, is_exynos##ver; \
> + \
> + if (!init_done) { \
> + is_exynos##ver = !!soc_device_match(exynos##ver##_soc_id); \
> + init_done = true; \
> + } \
> + \
> + return is_exynos##ver; \
> +}
> +
> +SOC_DEV_IS_EXYNOS(3250);
> +SOC_DEV_IS_EXYNOS(4210_rev11);
> +SOC_DEV_IS_EXYNOS(4412);
> +SOC_DEV_IS_EXYNOS(542x);

Nicely compacted definition but:
1. You blow real code (4 functions doing exactly the same),
2. You break jumping to definitions in IDE (searching/indexing symbols).

Currently this can be executed on only one, specific Exynos chip. This
means that you can have only one static variable holding current soc
revision and compare against it. This might require adding some enums
and code would look like:
enum soc_exynos {
SOC_EXYNOS_3250,
SOC_EXYNOS_542X,
...
};

bool soc_dev_is_exynos(soc) {
static bool init_done;
enum soc_exynos exynos_type;

if (!init_done) {
match = soc_device_match(exynos_soc_id);
exynos_type = match.data;
}
return soc == exynos_type;
}

and the callers would be:
if (soc_dev_is_exynos(EXYNOS_542x))

Other point is comment in soc_device_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..."
and
"For new devices, the DT binding .. that allow the use of
of_match_node() instead."

so of_match_node() is preferred instead.

> +
> static struct platform_device exynos_cpuidle = {
> .name = "exynos_cpuidle",
> #ifdef CONFIG_ARM_EXYNOS_CPUIDLE
> diff --git a/arch/arm/mach-exynos/firmware.c b/arch/arm/mach-exynos/firmware.c
> index d602e3b..d526d5e 100644
> --- a/arch/arm/mach-exynos/firmware.c
> +++ b/arch/arm/mach-exynos/firmware.c
> @@ -40,7 +40,7 @@ static int exynos_do_idle(unsigned long mode)
> writel_relaxed(__pa_symbol(exynos_cpu_resume_ns),
> sysram_ns_base_addr + 0x24);
> writel_relaxed(EXYNOS_AFTR_MAGIC, sysram_ns_base_addr + 0x20);
> - if (soc_is_exynos3250()) {
> + if (soc_dev_is_exynos3250()) {
> flush_cache_all();
> exynos_smc(SMC_CMD_SAVE, OP_TYPE_CORE,
> SMC_POWERSTATE_IDLE, 0);
> @@ -61,7 +61,7 @@ static int exynos_cpu_boot(int cpu)
> * Exynos3250 doesn't need to send smc command for secondary CPU boot
> * because Exynos3250 removes WFE in secure mode.
> */
> - if (soc_is_exynos3250())
> + if (soc_dev_is_exynos3250())
> return 0;
>
> /*
> @@ -85,7 +85,7 @@ static int exynos_set_cpu_boot_addr(int cpu, unsigned long boot_addr)
> * additional offset for every CPU, with Exynos4412 being the only
> * exception.
> */
> - if (soc_is_exynos4412())
> + if (soc_dev_is_exynos4412())
> boot_reg += 4 * cpu;
>
> writel_relaxed(boot_addr, boot_reg);
> @@ -101,7 +101,7 @@ static int exynos_get_cpu_boot_addr(int cpu, unsigned long *boot_addr)
>
> boot_reg = sysram_ns_base_addr + 0x1c;
>
> - if (soc_is_exynos4412())
> + if (soc_dev_is_exynos4412())
> boot_reg += 4 * cpu;
>
> *boot_addr = readl_relaxed(boot_reg);
> diff --git a/arch/arm/mach-exynos/platsmp.c b/arch/arm/mach-exynos/platsmp.c
> index c39ffd2..e2ba70f 100644
> --- a/arch/arm/mach-exynos/platsmp.c
> +++ b/arch/arm/mach-exynos/platsmp.c
> @@ -88,7 +88,7 @@ void exynos_cpu_power_down(int cpu)
> {
> u32 core_conf;
>
> - if (cpu == 0 && (soc_is_exynos5420() || soc_is_exynos5800())) {
> + if (cpu == 0 && soc_dev_is_exynos542x()) {

With new implementation you might hit again LDREX and STREX here (see
commit ca489c58ef0b ("ARM: EXYNOS: Don't use LDREX and STREX after
disabling cache coherency")) because:
soc_device_match -> bus_for_each_dev -> klist_iter_init_node ->
kref_get_unless_zero -> refcount_inc_not_zero_checked
According to previous comments and
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dht0008a/CJABEHDA.html
this is not allowed with cache coherency disabled.

I think calling here soc_device_match() is unlikely because it should
be initialized before. However please check if this is really the case
and comment it in the code in both places:
1. the first place which effectively initializes
soc_dev_is_exynos542x():init_done (to be sure that no one removes this
first call)
2. here that it depends on previous call of soc_dev_is_exynos542x().

It is getting slightly error prone - usage of one function is safe
here only if it was called somewhere else before... so I am not sure
if it is worth to remove soc_is_exynos() here.

Please also check other places without cache coherency where
soc_is_exynos() is being replaced to new method.

Best regards,
Krzysztof

2018-11-16 12:43:56

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH 2/9] soc: samsung: add exynos chipid driver support

On Thu, 15 Nov 2018 at 16:12, Bartlomiej Zolnierkiewicz
<[email protected]> wrote:
>
> From: Pankaj Dubey <[email protected]>
>
> Exynos SoCs have Chipid, for identification of product IDs and SoC
> revisions. This patch intends to provide initialization code for all
> these functionalities, at the same time it provides some sysfs entries
> for accessing these information to user-space.
>
> This driver uses existing binding for exynos-chipid.
>
> Changes by Bartlomiej:
> - fixed return values on errors
> - removed bogus kfree_const()
> - added missing Exynos4210 EVT0 id
> - converted code to use EXYNOS_MASK define
> - fixed np use after of_node_put()
> - fixed too early use of dev_info()
> - made driver fail for unknown SoC-s
> - added SPDX tag
> - updated Copyrights
>
> Cc: Grant Likely <[email protected]>
> Cc: Rob Herring <[email protected]>
> Cc: Linus Walleij <[email protected]>
> Signed-off-by: Pankaj Dubey <[email protected]>
> [m.szyprowski: for suggestion and code snippet of product_id_to_soc_id]
> Signed-off-by: Marek Szyprowski <[email protected]>
> Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
> ---
> drivers/soc/samsung/Kconfig | 5 ++
> drivers/soc/samsung/Makefile | 1 +
> drivers/soc/samsung/exynos-chipid.c | 111 ++++++++++++++++++++++++++++++++++++
> 3 files changed, 117 insertions(+)
> create mode 100644 drivers/soc/samsung/exynos-chipid.c
>
> diff --git a/drivers/soc/samsung/Kconfig b/drivers/soc/samsung/Kconfig
> index 2186285..2905f52 100644
> --- a/drivers/soc/samsung/Kconfig
> +++ b/drivers/soc/samsung/Kconfig
> @@ -7,6 +7,11 @@ menuconfig SOC_SAMSUNG
>
> if SOC_SAMSUNG
>
> +config EXYNOS_CHIPID
> + bool "Exynos Chipid controller driver" if COMPILE_TEST
> + depends on ARCH_EXYNOS || COMPILE_TEST
> + select SOC_BUS
> +
> config EXYNOS_PMU
> bool "Exynos PMU controller driver" if COMPILE_TEST
> depends on ARCH_EXYNOS || ((ARM || ARM64) && COMPILE_TEST)
> diff --git a/drivers/soc/samsung/Makefile b/drivers/soc/samsung/Makefile
> index 29f294b..c2a8fbc 100644
> --- a/drivers/soc/samsung/Makefile
> +++ b/drivers/soc/samsung/Makefile
> @@ -1,4 +1,5 @@
> # SPDX-License-Identifier: GPL-2.0
> +obj-$(CONFIG_EXYNOS_CHIPID) += exynos-chipid.o
> obj-$(CONFIG_EXYNOS_PMU) += exynos-pmu.o
>
> obj-$(CONFIG_EXYNOS_PMU_ARM_DRIVERS) += exynos3250-pmu.o exynos4-pmu.o \
> diff --git a/drivers/soc/samsung/exynos-chipid.c b/drivers/soc/samsung/exynos-chipid.c
> new file mode 100644
> index 0000000..5cb0188
> --- /dev/null
> +++ b/drivers/soc/samsung/exynos-chipid.c
> @@ -0,0 +1,111 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2018 Samsung Electronics Co., Ltd.
> + * http://www.samsung.com/
> + *
> + * EXYNOS - CHIP ID support
> + * Author: Pankaj Dubey <[email protected]>
> + * Author: Bartlomiej Zolnierkiewicz <[email protected]>
> + */
> +
> +#include <linux/io.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/of_platform.h>
> +#include <linux/platform_device.h>

I think both platform headers are not used here.

Best regards,
Krzysztof

> +#include <linux/slab.h>
> +#include <linux/sys_soc.h>
> +
> +#define EXYNOS_SUBREV_MASK (0xF << 4)
> +#define EXYNOS_MAINREV_MASK (0xF << 0)
> +#define EXYNOS_REV_MASK (EXYNOS_SUBREV_MASK | EXYNOS_MAINREV_MASK)
> +#define EXYNOS_MASK 0xFFFFF000
> +
> +static const struct exynos_soc_id {
> + const char *name;
> + unsigned int id;
> +} soc_ids[] = {
> + { "EXYNOS3250", 0xE3472000 },
> + { "EXYNOS4210", 0x43200000 }, /* EVT0 revision */
> + { "EXYNOS4210", 0x43210000 },
> + { "EXYNOS4212", 0x43220000 },
> + { "EXYNOS4412", 0xE4412000 },
> + { "EXYNOS5250", 0x43520000 },
> + { "EXYNOS5260", 0xE5260000 },
> + { "EXYNOS5410", 0xE5410000 },
> + { "EXYNOS5420", 0xE5420000 },
> + { "EXYNOS5440", 0xE5440000 },
> + { "EXYNOS5800", 0xE5422000 },
> + { "EXYNOS7420", 0xE7420000 },
> + { "EXYNOS5433", 0xE5433000 },
> +};
> +
> +static const char * __init product_id_to_soc_id(unsigned int product_id)
> +{
> + int i;
> +
> + for (i = 0; i < ARRAY_SIZE(soc_ids); i++)
> + if ((product_id & EXYNOS_MASK) == soc_ids[i].id)
> + return soc_ids[i].name;
> + return NULL;
> +}
> +
> +int __init exynos_chipid_early_init(void)
> +{
> + struct soc_device_attribute *soc_dev_attr;
> + void __iomem *exynos_chipid_base;
> + struct soc_device *soc_dev;
> + struct device_node *root;
> + struct device_node *np;
> + u32 product_id;
> + u32 revision;
> +
> + /* look up for chipid node */
> + np = of_find_compatible_node(NULL, NULL, "samsung,exynos4210-chipid");
> + if (!np)
> + return -ENODEV;
> +
> + exynos_chipid_base = of_iomap(np, 0);
> + of_node_put(np);
> +
> + if (!exynos_chipid_base) {
> + pr_err("Failed to map SoC chipid\n");
> + return -ENXIO;
> + }
> +
> + product_id = readl_relaxed(exynos_chipid_base);
> + revision = product_id & EXYNOS_REV_MASK;
> + iounmap(exynos_chipid_base);
> +
> + soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
> + if (!soc_dev_attr)
> + return -ENOMEM;
> +
> + soc_dev_attr->family = "Samsung Exynos";
> +
> + root = of_find_node_by_path("/");
> + of_property_read_string(root, "model", &soc_dev_attr->machine);
> + of_node_put(root);
> +
> + soc_dev_attr->revision = kasprintf(GFP_KERNEL, "%x", revision);
> + soc_dev_attr->soc_id = product_id_to_soc_id(product_id);
> + if (!soc_dev_attr->soc_id) {
> + pr_err("Unknown SoC\n");
> + return -ENODEV;
> + }
> +
> + /* please note that the actual registration will be deferred */
> + soc_dev = soc_device_register(soc_dev_attr);
> + if (IS_ERR(soc_dev)) {
> + kfree(soc_dev_attr->revision);
> + kfree(soc_dev_attr);
> + return PTR_ERR(soc_dev);
> + }
> +
> + /* it is too early to use dev_info() here (soc_dev is NULL) */
> + pr_info("soc soc0: Exynos: CPU[%s] PRO_ID[0x%x] REV[0x%x] Detected\n",
> + soc_dev_attr->soc_id, product_id, revision);
> +
> + return 0;
> +}
> +early_initcall(exynos_chipid_early_init);
> --
> 1.9.1
>

2018-11-16 12:51:20

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH 9/9] ARM: EXYNOS: remove <mach/map.h> include

On Thu, 15 Nov 2018 at 16:12, Bartlomiej Zolnierkiewicz
<[email protected]> wrote:
>
> Remove no longer needed <mach/map.h> include.

If I understand correctly, header is not needed because of previous
commit so it should be squashed there.

Best regards,
Krzysztof

2018-11-18 14:15:43

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH 1/9] ARM: EXYNOS: remove secondary startup initialization from smp_prepare_cpus

On Thu, Nov 15, 2018 at 04:11:30PM +0100, Bartlomiej Zolnierkiewicz wrote:
> From: Pankaj Dubey <[email protected]>
>
> We are taking care of setting secondary cpu boot address in
> exynos_boot_secondary just before sending ipi to secondary CPUs,
> so we can safely remove this setting from smp_prepare_cpus.
>
> Signed-off-by: Pankaj Dubey <[email protected]>
> Reviewed-by: Krzysztof Kozlowski <[email protected]>
> Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]>
> ---
> arch/arm/mach-exynos/platsmp.c | 26 --------------------------

Thanks, applied.

Best regards,
Krzysztof