2014-10-21 21:56:10

by Alexandre Belloni

[permalink] [raw]
Subject: [PATCH 0/8] ARM: at91: Remove mach/ includes from the reset driver

This series removes the mach/ headers dependency from the reset driver. It is
also laying some groundwork for the necessary power management support rework.

The first patch adds and export a function to shutdown the sdram from the sdramc
driver.

The second patch makes the sdramc driver usable from the board files.

The third patch actually registers the sdramc driver from the boards files.
The fourth patch does the same, only for sam9g45 and sam9rl to simplify future
merging as the board files have been removed. Simply drop that patch.

The fifth patch makes the at91-reset driver use the newly created
at91_ramc_shutdown() function and removes the mach/ headers inclusion.

Then the sixth and seven patch do some cleanup. Again, you can simply drop patch
7 when merging.

The last patch adds myself a the maintainer for those drivers.

Alexandre Belloni (8):
memory: atmel-sdramc: export a shutdown function
memory: atmel-sdramc: allow probing from pdata
ARM: at91: sam9: probe the RAMC driver from pdata
ARM: at91: sam9g45/sam9rl: probe the ramc driver
power: reset: at91-reset: use at91_ramc_shutdown
ARM: at91: sam9: remove useless resource for rstc
ARM: at91: sam9g45/sam9rl: remove useless resources for rstc
MAINTAINERS: add at91 power and memory entries

MAINTAINERS | 19 ++++++
arch/arm/mach-at91/Kconfig | 2 +-
arch/arm/mach-at91/at91sam9260.c | 20 ++++--
arch/arm/mach-at91/at91sam9261.c | 20 ++++--
arch/arm/mach-at91/at91sam9263.c | 20 ++++--
arch/arm/mach-at91/at91sam9g45.c | 20 ++++--
arch/arm/mach-at91/at91sam9rl.c | 20 ++++--
drivers/memory/atmel-sdramc.c | 134 ++++++++++++++++++++++++++++++++++++++-
drivers/power/reset/at91-reset.c | 116 ++++-----------------------------
include/soc/atmel/memory.h | 6 ++
10 files changed, 248 insertions(+), 129 deletions(-)
create mode 100644 include/soc/atmel/memory.h

--
1.9.1


2014-10-21 21:56:14

by Alexandre Belloni

[permalink] [raw]
Subject: [PATCH 5/8] power: reset: at91-reset: use at91_ramc_shutdown

Now that all SoCs are registering the atmel-sdramc driver, use the
at91_ramc_shutdown() function to shutdown the sdram.

Signed-off-by: Alexandre Belloni <[email protected]>
---
drivers/power/reset/at91-reset.c | 116 +++++----------------------------------
1 file changed, 14 insertions(+), 102 deletions(-)

diff --git a/drivers/power/reset/at91-reset.c b/drivers/power/reset/at91-reset.c
index 3cb36693343a..ec1ef9b113d4 100644
--- a/drivers/power/reset/at91-reset.c
+++ b/drivers/power/reset/at91-reset.c
@@ -19,8 +19,7 @@

#include <asm/system_misc.h>

-#include <mach/at91sam9_ddrsdr.h>
-#include <mach/at91sam9_sdramc.h>
+#include <soc/atmel/memory.h>

#define AT91_RSTC_CR 0x00 /* Reset Controller Control Register */
#define AT91_RSTC_PROCRST BIT(0) /* Processor Reset */
@@ -47,78 +46,28 @@ enum reset_type {
RESET_TYPE_USER = 4,
};

-static void __iomem *at91_ramc_base[2], *at91_rstc_base;
+static void __iomem *at91_rstc_base;

/*
* unless the SDRAM is cleanly shutdown before we hit the
* reset register it can be left driving the data bus and
* killing the chance of a subsequent boot from NAND
*/
-static void at91sam9260_restart(enum reboot_mode mode, const char *cmd)
+static void at91_restart(enum reboot_mode mode, const char *cmd)
{
- asm volatile(
- /* Align to cache lines */
- ".balign 32\n\t"
-
- /* Disable SDRAM accesses */
- "str %2, [%0, #" __stringify(AT91_SDRAMC_TR) "]\n\t"
-
- /* Power down SDRAM */
- "str %3, [%0, #" __stringify(AT91_SDRAMC_LPR) "]\n\t"
+ if (at91_ramc_shutdown)
+ at91_ramc_shutdown();

+ asm volatile(
/* Reset CPU */
- "str %4, [%1, #" __stringify(AT91_RSTC_CR) "]\n\t"
+ "str %1, [%0, #" __stringify(AT91_RSTC_CR) "]\n\t"

"b .\n\t"
:
- : "r" (at91_ramc_base[0]),
- "r" (at91_rstc_base),
- "r" (1),
- "r" (AT91_SDRAMC_LPCB_POWER_DOWN),
+ : "r" (at91_rstc_base),
"r" (AT91_RSTC_KEY | AT91_RSTC_PERRST | AT91_RSTC_PROCRST));
}

-static void at91sam9g45_restart(enum reboot_mode mode, const char *cmd)
-{
- asm volatile(
- /*
- * Test wether we have a second RAM controller to care
- * about.
- *
- * First, test that we can dereference the virtual address.
- */
- "cmp %1, #0\n\t"
- "beq 1f\n\t"
-
- /* Then, test that the RAM controller is enabled */
- "ldr r0, [%1]\n\t"
- "cmp r0, #0\n\t"
-
- /* Align to cache lines */
- ".balign 32\n\t"
-
- /* Disable SDRAM0 accesses */
- "1: str %3, [%0, #" __stringify(AT91_DDRSDRC_RTR) "]\n\t"
- /* Power down SDRAM0 */
- " str %4, [%0, #" __stringify(AT91_DDRSDRC_LPR) "]\n\t"
- /* Disable SDRAM1 accesses */
- " strne %3, [%1, #" __stringify(AT91_DDRSDRC_RTR) "]\n\t"
- /* Power down SDRAM1 */
- " strne %4, [%1, #" __stringify(AT91_DDRSDRC_LPR) "]\n\t"
- /* Reset CPU */
- " str %5, [%2, #" __stringify(AT91_RSTC_CR) "]\n\t"
-
- " b .\n\t"
- :
- : "r" (at91_ramc_base[0]),
- "r" (at91_ramc_base[1]),
- "r" (at91_rstc_base),
- "r" (1),
- "r" (AT91_DDRSDRC_LPCB_POWER_DOWN),
- "r" (AT91_RSTC_KEY | AT91_RSTC_PERRST | AT91_RSTC_PROCRST)
- : "r0");
-}
-
static void __init at91_reset_status(struct platform_device *pdev)
{
u32 reg = readl(at91_rstc_base + AT91_RSTC_SR);
@@ -148,51 +97,27 @@ static void __init at91_reset_status(struct platform_device *pdev)
pr_info("AT91: Starting after %s\n", reason);
}

-static struct of_device_id at91_ramc_of_match[] = {
- { .compatible = "atmel,at91sam9260-sdramc", },
- { .compatible = "atmel,at91sam9g45-ddramc", },
- { .compatible = "atmel,sama5d3-ddramc", },
- { /* sentinel */ }
-};
-
static struct of_device_id at91_reset_of_match[] = {
- { .compatible = "atmel,at91sam9260-rstc", .data = at91sam9260_restart },
- { .compatible = "atmel,at91sam9g45-rstc", .data = at91sam9g45_restart },
+ { .compatible = "atmel,at91sam9260-rstc", },
+ { .compatible = "atmel,at91sam9g45-rstc", },
{ /* sentinel */ }
};

static int at91_reset_of_probe(struct platform_device *pdev)
{
- const struct of_device_id *match;
- struct device_node *np;
- int idx = 0;
-
at91_rstc_base = of_iomap(pdev->dev.of_node, 0);
if (!at91_rstc_base) {
dev_err(&pdev->dev, "Could not map reset controller address\n");
return -ENODEV;
}

- for_each_matching_node(np, at91_ramc_of_match) {
- at91_ramc_base[idx] = of_iomap(np, 0);
- if (!at91_ramc_base[idx]) {
- dev_err(&pdev->dev, "Could not map ram controller address\n");
- return -ENODEV;
- }
- idx++;
- }
-
- match = of_match_node(at91_reset_of_match, pdev->dev.of_node);
- arm_pm_restart = match->data;
-
return 0;
}

+
static int at91_reset_platform_probe(struct platform_device *pdev)
{
- const struct platform_device_id *match;
struct resource *res;
- int idx = 0;

res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
at91_rstc_base = devm_ioremap_resource(&pdev->dev, res);
@@ -201,20 +126,6 @@ static int at91_reset_platform_probe(struct platform_device *pdev)
return PTR_ERR(at91_rstc_base);
}

- for (idx = 0; idx < 2; idx++) {
- res = platform_get_resource(pdev, IORESOURCE_MEM, idx + 1 );
- at91_ramc_base[idx] = devm_ioremap(&pdev->dev, res->start,
- resource_size(res));
- if (IS_ERR(at91_ramc_base[idx])) {
- dev_err(&pdev->dev, "Could not map ram controller address\n");
- return PTR_ERR(at91_ramc_base[idx]);
- }
- }
-
- match = platform_get_device_id(pdev);
- arm_pm_restart = (void (*)(enum reboot_mode, const char*))
- match->driver_data;
-
return 0;
}

@@ -230,14 +141,15 @@ static int at91_reset_probe(struct platform_device *pdev)
if (ret)
return ret;

+ arm_pm_restart = at91_restart;
at91_reset_status(pdev);

return 0;
}

static struct platform_device_id at91_reset_plat_match[] = {
- { "at91-sam9260-reset", (unsigned long)at91sam9260_restart },
- { "at91-sam9g45-reset", (unsigned long)at91sam9g45_restart },
+ { "at91-sam9260-reset", },
+ { "at91-sam9g45-reset", },
{ /* sentinel */ }
};

--
1.9.1

2014-10-21 21:56:28

by Alexandre Belloni

[permalink] [raw]
Subject: [PATCH 8/8] MAINTAINERS: add at91 power and memory entries

Signed-off-by: Alexandre Belloni <[email protected]>
---
MAINTAINERS | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index a20df9bf8ab0..e325c81ee2fa 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -871,6 +871,25 @@ M: Boris Brezillon <[email protected]>
S: Maintained
F: drivers/clk/at91

+ARM/ATMEL AT91 Poweroff driver
+M: Alexandre Belloni <[email protected]>
+L: [email protected] (moderated for non-subscribers)
+S: Maintained
+F: drivers/power/reset/at91-poweroff.c
+
+ARM/ATMEL AT91 Reset driver
+M: Alexandre Belloni <[email protected]>
+L: [email protected] (moderated for non-subscribers)
+S: Maintained
+F: drivers/power/reset/at91-reset.c
+
+ARM/ATMEL AT91 SDRAM Controlller driver
+M: Alexandre Belloni <[email protected]>
+L: [email protected] (moderated for non-subscribers)
+S: Maintained
+F: drivers/memory/atmel-sdramc.c
+F: include/soc/atmel/memory.h
+
ARM/CALXEDA HIGHBANK ARCHITECTURE
M: Rob Herring <[email protected]>
L: [email protected] (moderated for non-subscribers)
--
1.9.1

2014-10-21 21:56:13

by Alexandre Belloni

[permalink] [raw]
Subject: [PATCH 1/8] memory: atmel-sdramc: export a shutdown function

It is necessary to shutdown the SDRAM before resetting the SoC to avoid having
issue with NAND boot.

Export a function that does exactly that.

Signed-off-by: Alexandre Belloni <[email protected]>
---
drivers/memory/atmel-sdramc.c | 90 +++++++++++++++++++++++++++++++++++++++++++
include/soc/atmel/memory.h | 6 +++
2 files changed, 96 insertions(+)
create mode 100644 include/soc/atmel/memory.h

diff --git a/drivers/memory/atmel-sdramc.c b/drivers/memory/atmel-sdramc.c
index fed04e8efe75..148906dabe55 100644
--- a/drivers/memory/atmel-sdramc.c
+++ b/drivers/memory/atmel-sdramc.c
@@ -21,24 +21,101 @@
#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/of_address.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>

+#include <soc/atmel/memory.h>
+
+#define AT91_SDRAMC_TR 0x04 /* SDRAM Controller Refresh Timer Register */
+#define AT91_SDRAMC_LPR 0x10 /* SDRAM Controller Low Power Register */
+#define AT91_SDRAMC_LPCB_POWER_DOWN 2
+
+#define AT91_DDRSDRC_RTR 0x04 /* Refresh Timer Register */
+#define AT91_DDRSDRC_LPR 0x1C /* Low Power Register */
+#define AT91_DDRSDRC_LPCB_POWER_DOWN 2
+
+static void __iomem *at91_ramc_base[2];
+
+void (*at91_ramc_shutdown)(void);
+
struct at91_ramc_caps {
bool has_ddrck;
bool has_mpddr_clk;
+ void (*shutdown)(void);
};

+void at91sam9260_shutdown(void)
+{
+ pr_err("%s +%d %s\n", __FILE__, __LINE__, __func__);
+ asm volatile(
+ /* Align to cache lines */
+ ".balign 32\n\t"
+
+ /* Disable SDRAM accesses */
+ "str %1, [%0, #" __stringify(AT91_SDRAMC_TR) "]\n\t"
+
+ /* Power down SDRAM */
+ "str %2, [%0, #" __stringify(AT91_SDRAMC_LPR) "]\n\t"
+
+ :
+ : "r" (at91_ramc_base[0]),
+ "r" (1),
+ "r" (AT91_SDRAMC_LPCB_POWER_DOWN));
+}
+
+void at91sam9g45_shutdown(void)
+{
+ asm volatile(
+ /*
+ * Test wether we have a second RAM controller to care
+ * about.
+ *
+ * First, test that we can dereference the virtual address.
+ */
+ "cmp %1, #0\n\t"
+ "beq 1f\n\t"
+
+ /* Then, test that the RAM controller is enabled */
+ "ldr r0, [%1]\n\t"
+ "cmp r0, #0\n\t"
+
+ /* Align to cache lines */
+ ".balign 32\n\t"
+
+ /* Disable SDRAM0 accesses */
+ "1: str %2, [%0, #" __stringify(AT91_DDRSDRC_RTR) "]\n\t"
+ /* Power down SDRAM0 */
+ " str %3, [%0, #" __stringify(AT91_DDRSDRC_LPR) "]\n\t"
+ /* Disable SDRAM1 accesses */
+ " strne %2, [%1, #" __stringify(AT91_DDRSDRC_RTR) "]\n\t"
+ /* Power down SDRAM1 */
+ " strne %3, [%1, #" __stringify(AT91_DDRSDRC_LPR) "]\n\t"
+
+ :
+ : "r" (at91_ramc_base[0]),
+ "r" (at91_ramc_base[1]),
+ "r" (1),
+ "r" (AT91_DDRSDRC_LPCB_POWER_DOWN)
+ : "r0");
+}
+
static const struct at91_ramc_caps at91rm9200_caps = { };

+static const struct at91_ramc_caps at91sam9260_caps = {
+ .shutdown = at91sam9260_shutdown,
+};
+
static const struct at91_ramc_caps at91sam9g45_caps = {
.has_ddrck = 1,
.has_mpddr_clk = 0,
+ .shutdown = at91sam9g45_shutdown,
};

static const struct at91_ramc_caps sama5d3_caps = {
.has_ddrck = 1,
.has_mpddr_clk = 1,
+ .shutdown = at91sam9g45_shutdown,
};

static const struct of_device_id atmel_ramc_of_match[] = {
@@ -54,7 +131,9 @@ static int atmel_ramc_probe(struct platform_device *pdev)
{
const struct of_device_id *match;
const struct at91_ramc_caps *caps;
+ struct device_node *np;
struct clk *clk;
+ int idx = 0;

match = of_match_device(atmel_ramc_of_match, &pdev->dev);
caps = match->data;
@@ -75,6 +154,17 @@ static int atmel_ramc_probe(struct platform_device *pdev)
clk_prepare_enable(clk);
}

+ for_each_matching_node(np, atmel_ramc_of_match) {
+ at91_ramc_base[idx] = of_iomap(np, 0);
+ if (!at91_ramc_base[idx]) {
+ dev_err(&pdev->dev, "Could not map ram controller address\n");
+ return -ENODEV;
+ }
+ idx++;
+ }
+
+ at91_ramc_shutdown = caps->shutdown;
+
return 0;
}

diff --git a/include/soc/atmel/memory.h b/include/soc/atmel/memory.h
new file mode 100644
index 000000000000..04cc1261e636
--- /dev/null
+++ b/include/soc/atmel/memory.h
@@ -0,0 +1,6 @@
+#ifndef __INCLUDE_ATMEL_MEMORY_H
+#define __INCLUDE_ATMEL_MEMORY_H
+
+extern void (*at91_ramc_shutdown)(void);
+
+#endif /* __INCLUDE_ATMEL_MEMORY_H */
--
1.9.1

2014-10-21 21:56:59

by Alexandre Belloni

[permalink] [raw]
Subject: [PATCH 7/8] ARM: at91: sam9g45/sam9rl: remove useless resources for rstc

The RAMC resources are now unnecessary in the reset driver, remove them.

Signed-off-by: Alexandre Belloni <[email protected]>
---
arch/arm/mach-at91/at91sam9g45.c | 10 ----------
arch/arm/mach-at91/at91sam9rl.c | 5 -----
2 files changed, 15 deletions(-)

diff --git a/arch/arm/mach-at91/at91sam9g45.c b/arch/arm/mach-at91/at91sam9g45.c
index 202d9438e1d9..2e1aae8152b7 100644
--- a/arch/arm/mach-at91/at91sam9g45.c
+++ b/arch/arm/mach-at91/at91sam9g45.c
@@ -397,16 +397,6 @@ static struct resource rstc_resources[] = {
.end = AT91SAM9G45_BASE_RSTC + SZ_16 - 1,
.flags = IORESOURCE_MEM,
},
- [1] = {
- .start = AT91SAM9G45_BASE_DDRSDRC1,
- .end = AT91SAM9G45_BASE_DDRSDRC1 + SZ_512 - 1,
- .flags = IORESOURCE_MEM,
- },
- [2] = {
- .start = AT91SAM9G45_BASE_DDRSDRC0,
- .end = AT91SAM9G45_BASE_DDRSDRC0 + SZ_512 - 1,
- .flags = IORESOURCE_MEM,
- },
};

static struct platform_device rstc_device = {
diff --git a/arch/arm/mach-at91/at91sam9rl.c b/arch/arm/mach-at91/at91sam9rl.c
index 0e2cb3361b15..0b00b9c7bd82 100644
--- a/arch/arm/mach-at91/at91sam9rl.c
+++ b/arch/arm/mach-at91/at91sam9rl.c
@@ -335,11 +335,6 @@ static struct resource rstc_resources[] = {
.end = AT91SAM9RL_BASE_RSTC + SZ_16 - 1,
.flags = IORESOURCE_MEM,
},
- [1] = {
- .start = AT91SAM9RL_BASE_SDRAMC,
- .end = AT91SAM9RL_BASE_SDRAMC + SZ_512 - 1,
- .flags = IORESOURCE_MEM,
- },
};

static struct platform_device rstc_device = {
--
1.9.1

2014-10-21 21:57:28

by Alexandre Belloni

[permalink] [raw]
Subject: [PATCH 6/8] ARM: at91: sam9: remove useless resource for rstc

The RAMC resources are now unnecessary in the reset driver, remove them.

Signed-off-by: Alexandre Belloni <[email protected]>
---
arch/arm/mach-at91/at91sam9260.c | 5 -----
arch/arm/mach-at91/at91sam9261.c | 5 -----
arch/arm/mach-at91/at91sam9263.c | 5 -----
3 files changed, 15 deletions(-)

diff --git a/arch/arm/mach-at91/at91sam9260.c b/arch/arm/mach-at91/at91sam9260.c
index d5a6df9ce570..d1c97e025483 100644
--- a/arch/arm/mach-at91/at91sam9260.c
+++ b/arch/arm/mach-at91/at91sam9260.c
@@ -365,11 +365,6 @@ static struct resource rstc_resources[] = {
.end = AT91SAM9260_BASE_RSTC + SZ_16 - 1,
.flags = IORESOURCE_MEM,
},
- [1] = {
- .start = AT91SAM9260_BASE_SDRAMC,
- .end = AT91SAM9260_BASE_SDRAMC + SZ_512 - 1,
- .flags = IORESOURCE_MEM,
- },
};

static struct platform_device rstc_device = {
diff --git a/arch/arm/mach-at91/at91sam9261.c b/arch/arm/mach-at91/at91sam9261.c
index 1b23a023cca6..7a354d5a3d4c 100644
--- a/arch/arm/mach-at91/at91sam9261.c
+++ b/arch/arm/mach-at91/at91sam9261.c
@@ -324,11 +324,6 @@ static struct resource rstc_resources[] = {
.end = AT91SAM9261_BASE_RSTC + SZ_16 - 1,
.flags = IORESOURCE_MEM,
},
- [1] = {
- .start = AT91SAM9261_BASE_SDRAMC,
- .end = AT91SAM9261_BASE_SDRAMC + SZ_512 - 1,
- .flags = IORESOURCE_MEM,
- },
};

static struct platform_device rstc_device = {
diff --git a/arch/arm/mach-at91/at91sam9263.c b/arch/arm/mach-at91/at91sam9263.c
index 55c0c212fde1..1f7e7021ae83 100644
--- a/arch/arm/mach-at91/at91sam9263.c
+++ b/arch/arm/mach-at91/at91sam9263.c
@@ -347,11 +347,6 @@ static struct resource rstc_resources[] = {
.end = AT91SAM9263_BASE_RSTC + SZ_16 - 1,
.flags = IORESOURCE_MEM,
},
- [1] = {
- .start = AT91SAM9263_BASE_SDRAMC0,
- .end = AT91SAM9263_BASE_SDRAMC0 + SZ_512 - 1,
- .flags = IORESOURCE_MEM,
- },
};

static struct platform_device rstc_device = {
--
1.9.1

2014-10-21 21:58:14

by Alexandre Belloni

[permalink] [raw]
Subject: [PATCH 4/8] ARM: at91: sam9g45/sam9rl: probe the ramc driver

Probe the atmel-sdramc driver from the board files, using platform_data.

Signed-off-by: Alexandre Belloni <[email protected]>
---
arch/arm/mach-at91/at91sam9g45.c | 20 ++++++++++++++++++++
arch/arm/mach-at91/at91sam9rl.c | 15 +++++++++++++++
2 files changed, 35 insertions(+)

diff --git a/arch/arm/mach-at91/at91sam9g45.c b/arch/arm/mach-at91/at91sam9g45.c
index 405427ec05f8..202d9438e1d9 100644
--- a/arch/arm/mach-at91/at91sam9g45.c
+++ b/arch/arm/mach-at91/at91sam9g45.c
@@ -415,6 +415,25 @@ static struct platform_device rstc_device = {
.num_resources = ARRAY_SIZE(rstc_resources),
};

+static struct resource ramc_resources[] = {
+ [0] = {
+ .start = AT91SAM9G45_BASE_DDRSDRC1,
+ .end = AT91SAM9G45_BASE_DDRSDRC1 + SZ_512 - 1,
+ .flags = IORESOURCE_MEM,
+ },
+ [1] = {
+ .start = AT91SAM9G45_BASE_DDRSDRC0,
+ .end = AT91SAM9G45_BASE_DDRSDRC0 + SZ_512 - 1,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static struct platform_device rstc_device = {
+ .name = "at91-sam9g45-ramc",
+ .resource = ramc_resources,
+ .num_resources = ARRAY_SIZE(ramc_resources),
+};
+
static struct resource shdwc_resources[] = {
[0] = {
.start = AT91SAM9G45_BASE_SHDWC,
@@ -431,6 +450,7 @@ static struct platform_device shdwc_device = {

static void __init at91sam9g45_register_devices(void)
{
+ platform_device_register(&ramc_device);
platform_device_register(&rstc_device);
platform_device_register(&shdwc_device);
}
diff --git a/arch/arm/mach-at91/at91sam9rl.c b/arch/arm/mach-at91/at91sam9rl.c
index f553e4ea034b..0e2cb3361b15 100644
--- a/arch/arm/mach-at91/at91sam9rl.c
+++ b/arch/arm/mach-at91/at91sam9rl.c
@@ -348,6 +348,20 @@ static struct platform_device rstc_device = {
.num_resources = ARRAY_SIZE(rstc_resources),
};

+static struct resource ramc_resources[] = {
+ [0] = {
+ .start = AT91SAM9RL_BASE_SDRAMC,
+ .end = AT91SAM9RL_BASE_SDRAMC + SZ_512 - 1,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static struct platform_device ramc_device = {
+ .name = "at91-sam9260-ramc",
+ .resource = ramc_resources,
+ .num_resources = ARRAY_SIZE(ramc_resources),
+};
+
static struct resource shdwc_resources[] = {
[0] = {
.start = AT91SAM9RL_BASE_SHDWC,
@@ -364,6 +378,7 @@ static struct platform_device shdwc_device = {

static void __init at91sam9rl_register_devices(void)
{
+ platform_device_register(&ramc_device);
platform_device_register(&rstc_device);
platform_device_register(&shdwc_device);
}
--
1.9.1

2014-10-21 21:58:34

by Alexandre Belloni

[permalink] [raw]
Subject: [PATCH 2/8] memory: atmel-sdramc: allow probing from pdata

Allow probing the atmel-sdramc from platform_data.

Signed-off-by: Alexandre Belloni <[email protected]>
---
drivers/memory/atmel-sdramc.c | 44 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/drivers/memory/atmel-sdramc.c b/drivers/memory/atmel-sdramc.c
index 148906dabe55..e1222557dc9d 100644
--- a/drivers/memory/atmel-sdramc.c
+++ b/drivers/memory/atmel-sdramc.c
@@ -19,6 +19,7 @@

#include <linux/clk.h>
#include <linux/err.h>
+#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of_address.h>
@@ -127,7 +128,7 @@ static const struct of_device_id atmel_ramc_of_match[] = {
};
MODULE_DEVICE_TABLE(of, atmel_ramc_of_match);

-static int atmel_ramc_probe(struct platform_device *pdev)
+static int atmel_ramc_of_probe(struct platform_device *pdev)
{
const struct of_device_id *match;
const struct at91_ramc_caps *caps;
@@ -168,6 +169,46 @@ static int atmel_ramc_probe(struct platform_device *pdev)
return 0;
}

+static int atmel_ramc_platform_probe(struct platform_device *pdev)
+{
+ struct resource *res;
+ const struct platform_device_id *match;
+ int idx = 0;
+
+ for (idx = 0; idx < 2; idx++) {
+ res = platform_get_resource(pdev, IORESOURCE_MEM, idx + 1);
+ at91_ramc_base[idx] = devm_ioremap(&pdev->dev, res->start,
+ resource_size(res));
+ if (IS_ERR(at91_ramc_base[idx])) {
+ dev_err(&pdev->dev, "Could not map ram controller address\n");
+ return PTR_ERR(at91_ramc_base[idx]);
+ }
+ }
+
+ match = platform_get_device_id(pdev);
+ at91_ramc_shutdown = (void (*)(void))match->driver_data;
+
+ return 0;
+};
+
+static int atmel_ramc_probe(struct platform_device *pdev)
+{
+ int ret;
+
+ if (pdev->dev.of_node)
+ ret = atmel_ramc_of_probe(pdev);
+ else
+ ret = atmel_ramc_platform_probe(pdev);
+
+ return ret;
+}
+
+static struct platform_device_id atmel_ramc_plat_match[] = {
+ { "at91sam9260-sdramc", (unsigned long)at91sam9260_shutdown, },
+ { "at91sam9g45-ddramc", (unsigned long)at91sam9g45_shutdown, },
+ { /* sentinel */ }
+};
+
static struct platform_driver atmel_ramc_driver = {
.probe = atmel_ramc_probe,
.driver = {
@@ -175,6 +216,7 @@ static struct platform_driver atmel_ramc_driver = {
.owner = THIS_MODULE,
.of_match_table = atmel_ramc_of_match,
},
+ .id_table = atmel_ramc_plat_match,
};

static int __init atmel_ramc_init(void)
--
1.9.1

2014-10-21 21:58:33

by Alexandre Belloni

[permalink] [raw]
Subject: [PATCH 3/8] ARM: at91: sam9: probe the RAMC driver from pdata

Probe the atmel-sdramc driver from the board files, using platform_data.

Signed-off-by: Alexandre Belloni <[email protected]>
---
arch/arm/mach-at91/Kconfig | 2 +-
arch/arm/mach-at91/at91sam9260.c | 15 +++++++++++++++
arch/arm/mach-at91/at91sam9261.c | 15 +++++++++++++++
arch/arm/mach-at91/at91sam9263.c | 15 +++++++++++++++
4 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-at91/Kconfig b/arch/arm/mach-at91/Kconfig
index 0e6d548b70d9..db38e1d4b4fa 100644
--- a/arch/arm/mach-at91/Kconfig
+++ b/arch/arm/mach-at91/Kconfig
@@ -48,7 +48,7 @@ config SOC_AT91SAM9
select CPU_ARM926T
select GENERIC_CLOCKEVENTS
select MEMORY if USE_OF
- select ATMEL_SDRAMC if USE_OF
+ select ATMEL_SDRAMC

config SOC_SAMA5
bool
diff --git a/arch/arm/mach-at91/at91sam9260.c b/arch/arm/mach-at91/at91sam9260.c
index aab1f969a7c3..d5a6df9ce570 100644
--- a/arch/arm/mach-at91/at91sam9260.c
+++ b/arch/arm/mach-at91/at91sam9260.c
@@ -378,6 +378,20 @@ static struct platform_device rstc_device = {
.num_resources = ARRAY_SIZE(rstc_resources),
};

+static struct resource ramc_resources[] = {
+ [0] = {
+ .start = AT91SAM9260_BASE_SDRAMC,
+ .end = AT91SAM9260_BASE_SDRAMC + SZ_512 - 1,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static struct platform_device ramc_device = {
+ .name = "at91-sam9260-ramc",
+ .resource = ramc_resources,
+ .num_resources = ARRAY_SIZE(ramc_resources),
+};
+
static struct resource shdwc_resources[] = {
[0] = {
.start = AT91SAM9260_BASE_SHDWC,
@@ -394,6 +408,7 @@ static struct platform_device shdwc_device = {

static void __init at91sam9260_register_devices(void)
{
+ platform_device_register(&ramc_device);
platform_device_register(&rstc_device);
platform_device_register(&shdwc_device);
}
diff --git a/arch/arm/mach-at91/at91sam9261.c b/arch/arm/mach-at91/at91sam9261.c
index a8bd35963332..1b23a023cca6 100644
--- a/arch/arm/mach-at91/at91sam9261.c
+++ b/arch/arm/mach-at91/at91sam9261.c
@@ -337,6 +337,20 @@ static struct platform_device rstc_device = {
.num_resources = ARRAY_SIZE(rstc_resources),
};

+static struct resource ramc_resources[] = {
+ [0] = {
+ .start = AT91SAM9261_BASE_SDRAMC,
+ .end = AT91SAM9261_BASE_SDRAMC + SZ_512 - 1,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static struct platform_device ramc_device = {
+ .name = "at91-sam9260-ramc",
+ .resource = ramc_resources,
+ .num_resources = ARRAY_SIZE(ramc_resources),
+};
+
static struct resource shdwc_resources[] = {
[0] = {
.start = AT91SAM9261_BASE_SHDWC,
@@ -353,6 +367,7 @@ static struct platform_device shdwc_device = {

static void __init at91sam9261_register_devices(void)
{
+ platform_device_register(&ramc_device);
platform_device_register(&rstc_device);
platform_device_register(&shdwc_device);
}
diff --git a/arch/arm/mach-at91/at91sam9263.c b/arch/arm/mach-at91/at91sam9263.c
index fbff228cc63e..55c0c212fde1 100644
--- a/arch/arm/mach-at91/at91sam9263.c
+++ b/arch/arm/mach-at91/at91sam9263.c
@@ -360,6 +360,20 @@ static struct platform_device rstc_device = {
.num_resources = ARRAY_SIZE(rstc_resources),
};

+static struct resource ramc_resources[] = {
+ [0] = {
+ .start = AT91SAM9263_BASE_SDRAMC0,
+ .end = AT91SAM9263_BASE_SDRAMC0 + SZ_512 - 1,
+ .flags = IORESOURCE_MEM,
+ },
+};
+
+static struct platform_device ramc_device = {
+ .name = "at91-sam9260-ramc",
+ .resource = ramc_resources,
+ .num_resources = ARRAY_SIZE(ramc_resources),
+};
+
static struct resource shdwc_resources[] = {
[0] = {
.start = AT91SAM9263_BASE_SHDWC,
@@ -376,6 +390,7 @@ static struct platform_device shdwc_device = {

static void __init at91sam9263_register_devices(void)
{
+ platform_device_register(&ramc_device);
platform_device_register(&rstc_device);
platform_device_register(&shdwc_device);
}
--
1.9.1

2014-10-22 06:56:28

by Ludovic Desroches

[permalink] [raw]
Subject: Re: [PATCH 8/8] MAINTAINERS: add at91 power and memory entries

On Tue, Oct 21, 2014 at 11:55:40PM +0200, Alexandre Belloni wrote:
> Signed-off-by: Alexandre Belloni <[email protected]>
> ---
> MAINTAINERS | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index a20df9bf8ab0..e325c81ee2fa 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -871,6 +871,25 @@ M: Boris Brezillon <[email protected]>
> S: Maintained
> F: drivers/clk/at91
>
> +ARM/ATMEL AT91 Poweroff driver
> +M: Alexandre Belloni <[email protected]>
> +L: [email protected] (moderated for non-subscribers)
> +S: Maintained
> +F: drivers/power/reset/at91-poweroff.c
> +
> +ARM/ATMEL AT91 Reset driver
> +M: Alexandre Belloni <[email protected]>
> +L: [email protected] (moderated for non-subscribers)
> +S: Maintained
> +F: drivers/power/reset/at91-reset.c
> +
> +ARM/ATMEL AT91 SDRAM Controlller driver

Controller

> +M: Alexandre Belloni <[email protected]>
> +L: [email protected] (moderated for non-subscribers)
> +S: Maintained
> +F: drivers/memory/atmel-sdramc.c
> +F: include/soc/atmel/memory.h
> +
> ARM/CALXEDA HIGHBANK ARCHITECTURE
> M: Rob Herring <[email protected]>
> L: [email protected] (moderated for non-subscribers)
> --
> 1.9.1
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

2014-10-22 07:08:15

by Thomas Petazzoni

[permalink] [raw]
Subject: Re: [PATCH 5/8] power: reset: at91-reset: use at91_ramc_shutdown

Dear Alexandre Belloni,

On Tue, 21 Oct 2014 23:55:37 +0200, Alexandre Belloni wrote:

> /*
> * unless the SDRAM is cleanly shutdown before we hit the
> * reset register it can be left driving the data bus and
> * killing the chance of a subsequent boot from NAND
> */
> -static void at91sam9260_restart(enum reboot_mode mode, const char *cmd)
> +static void at91_restart(enum reboot_mode mode, const char *cmd)
> {
> - asm volatile(
> - /* Align to cache lines */
> - ".balign 32\n\t"
> -
> - /* Disable SDRAM accesses */
> - "str %2, [%0, #" __stringify(AT91_SDRAMC_TR) "]\n\t"
> -
> - /* Power down SDRAM */
> - "str %3, [%0, #" __stringify(AT91_SDRAMC_LPR) "]\n\t"
> + if (at91_ramc_shutdown)
> + at91_ramc_shutdown();
>
> + asm volatile(
> /* Reset CPU */
> - "str %4, [%1, #" __stringify(AT91_RSTC_CR) "]\n\t"
> + "str %1, [%0, #" __stringify(AT91_RSTC_CR) "]\n\t"
>
> "b .\n\t"

Are you sure this is working properly? There was a reason to have the
SDRAM controller shutdown right before resetting the CPU: the code was
ensuring that all those assembly instructions fitted in one cache line,
so that even if the SDRAM controller gets shutdown, the rest of the
code can properly execute until resetting the CPU. Now, the SDRAM
controller shutdown code and the code resetting the CPU are in
completely separate places, which break this assumption.

And also, you forgot to Cc: Maxime Ripard who did the initial work on
this at91-reset controller.

Thanks,

Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

2014-10-22 07:18:50

by Alexandre Belloni

[permalink] [raw]
Subject: Re: [PATCH 5/8] power: reset: at91-reset: use at91_ramc_shutdown

On 22/10/2014 at 09:08:10 +0200, Thomas Petazzoni wrote :
> Dear Alexandre Belloni,
>
> On Tue, 21 Oct 2014 23:55:37 +0200, Alexandre Belloni wrote:
>
> > /*
> > * unless the SDRAM is cleanly shutdown before we hit the
> > * reset register it can be left driving the data bus and
> > * killing the chance of a subsequent boot from NAND
> > */
> > -static void at91sam9260_restart(enum reboot_mode mode, const char *cmd)
> > +static void at91_restart(enum reboot_mode mode, const char *cmd)
> > {
> > - asm volatile(
> > - /* Align to cache lines */
> > - ".balign 32\n\t"
> > -
> > - /* Disable SDRAM accesses */
> > - "str %2, [%0, #" __stringify(AT91_SDRAMC_TR) "]\n\t"
> > -
> > - /* Power down SDRAM */
> > - "str %3, [%0, #" __stringify(AT91_SDRAMC_LPR) "]\n\t"
> > + if (at91_ramc_shutdown)
> > + at91_ramc_shutdown();
> >
> > + asm volatile(
> > /* Reset CPU */
> > - "str %4, [%1, #" __stringify(AT91_RSTC_CR) "]\n\t"
> > + "str %1, [%0, #" __stringify(AT91_RSTC_CR) "]\n\t"
> >
> > "b .\n\t"
>
> Are you sure this is working properly? There was a reason to have the
> SDRAM controller shutdown right before resetting the CPU: the code was
> ensuring that all those assembly instructions fitted in one cache line,
> so that even if the SDRAM controller gets shutdown, the rest of the
> code can properly execute until resetting the CPU. Now, the SDRAM
> controller shutdown code and the code resetting the CPU are in
> completely separate places, which break this assumption.
>

It it still working properly, I believe it is still fitting the cache
line.

> And also, you forgot to Cc: Maxime Ripard who did the initial work on
> this at91-reset controller.
>

Yeah, I realized after sending the patches.

--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com