Skip to content

Commit

Permalink
aspeed: linux-6.0: add shutdown method for ast2500-spi
Browse files Browse the repository at this point in the history
Summary:
Originally the patch file #0520 (adding shutdown method for aspeed-spi)
is only applied to wedge400 to fix the reboot hang problem, but recently
we found the similar failure on minipack, thus we decide to move the
patch to meta-aspeed layer (applied to all platforms).

The original patch is "improved" to make sure it's no-op in AST24XX and
AST26XX, because:
  - ASPEED confirmed the patch was not needed on AST26XX.
  - We have never seen reboot hang problem on AST24XX, and we are not
    sure if it's safe to apply the logic to AST24XX, either.

Test Plan:
1) "bitbake wedge400-image" succeeded.
2) "bitbake minipack-image" succeeded.
3) "bitbake fuji-image" succceeded.
4) rebooted fuji image for a few times: no issue found.
5) rebooted minipack image for a few times: no issue found.

Reviewed By: williamspatrick

Differential Revision: D44658087

fbshipit-source-id: 943590cda5b421e3d7f49c59b7fc9363c26d7960
  • Loading branch information
tao-ren authored and facebook-github-bot committed Apr 4, 2023
1 parent 760263e commit dd34cee
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
From fd31e7de61b461797f7f1827fb227ed45e1314f1 Mon Sep 17 00:00:00 2001
From: dhineskumareswaran <dhineskumar.eswaran@celestica.com>
Date: Mon, 5 Dec 2022 12:17:20 +0000
Subject: [PATCH] spi: aspeed: add shutdown path for AST25XX SPI controller

Summary:
Restoring the register back to default state by adding shutdown
path in spi-aspeed-smc driver.

Problem statement:
On the AST25XX chip, sometimes the flash gets stuck during the
reset state (reboot).

Root Cause:
Some timing issues are happening in flash reset logic.

Solution:
In reset path, restoring all FMC related register back to default state.
---
drivers/spi/spi-aspeed-smc.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

diff --git a/drivers/spi/spi-aspeed-smc.c b/drivers/spi/spi-aspeed-smc.c
index faf877e52bfe..1bc9fd4382f0 100644
--- a/drivers/spi/spi-aspeed-smc.c
+++ b/drivers/spi/spi-aspeed-smc.c
@@ -46,6 +46,8 @@

/* CEx Address Decoding Range Register */
#define CE0_SEGMENT_ADDR_REG 0x30
+#define CE1_SEGMENT_ADDR_REG 0x34
+#define CE2_SEGMENT_ADDR_REG 0x38

/* CEx Read timing compensation register */
#define CE0_TIMING_COMPENSATION_REG 0x94
@@ -84,6 +86,7 @@ struct aspeed_spi_data {
u32 (*segment_reg)(struct aspeed_spi *aspi, u32 start, u32 end);
int (*calibrate)(struct aspeed_spi_chip *chip, u32 hdiv,
const u8 *golden_buf, u8 *test_buf);
+ void (*shutdown)(struct aspeed_spi *aspi);
};

#define ASPEED_SPI_MAX_NUM_CS 5
@@ -800,6 +803,14 @@ static int aspeed_spi_remove(struct platform_device *pdev)
return 0;
}

+static void aspeed_spi_shutdown(struct platform_device *pdev)
+{
+ struct aspeed_spi *aspi = platform_get_drvdata(pdev);
+
+ if (aspi->data->shutdown)
+ aspi->data->shutdown(aspi);
+}
+
/*
* AHB mappings
*/
@@ -1105,6 +1116,18 @@ static int aspeed_spi_ast2600_calibrate(struct aspeed_spi_chip *chip, u32 hdiv,
return -1;
}

+static void aspeed_spi_ast2500_shutdown(struct aspeed_spi *aspi)
+{
+ /* restoring the register which we used before to default*/
+ writel(0x8000002A, aspi->regs + CONFIG_REG);
+ writel(0x700, aspi->regs + CE_CTRL_REG);
+ writel(0x0, aspi->regs + CE0_CTRL_REG);
+ writel(0x50400000, aspi->regs + CE0_SEGMENT_ADDR_REG);
+ writel(0x54500000, aspi->regs + CE1_SEGMENT_ADDR_REG);
+ writel(0x58540000, aspi->regs + CE2_SEGMENT_ADDR_REG);
+ writel(0x0, aspi->regs + CE0_TIMING_COMPENSATION_REG);
+}
+
/*
* Platform definitions
*/
@@ -1146,6 +1169,7 @@ static const struct aspeed_spi_data ast2500_fmc_data = {
.segment_start = aspeed_spi_segment_start,
.segment_end = aspeed_spi_segment_end,
.segment_reg = aspeed_spi_segment_reg,
+ .shutdown = aspeed_spi_ast2500_shutdown,
};

static const struct aspeed_spi_data ast2500_spi_data = {
@@ -1160,6 +1184,7 @@ static const struct aspeed_spi_data ast2500_spi_data = {
.segment_start = aspeed_spi_segment_start,
.segment_end = aspeed_spi_segment_end,
.segment_reg = aspeed_spi_segment_reg,
+ .shutdown = aspeed_spi_ast2500_shutdown,
};

static const struct aspeed_spi_data ast2600_fmc_data = {
@@ -1206,6 +1231,7 @@ MODULE_DEVICE_TABLE(of, aspeed_spi_matches);
static struct platform_driver aspeed_spi_driver = {
.probe = aspeed_spi_probe,
.remove = aspeed_spi_remove,
+ .shutdown = aspeed_spi_shutdown,
.driver = {
.name = DEVICE_NAME,
.of_match_table = aspeed_spi_matches,
--
2.34.1

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ FILESEXTRAPATHS:prepend := "${THISDIR}/patches:"
SRC_URI += "file://patches/0501-i2c-add-a-slave-backend-to-receive-and-q.patch \
file://patches/0502-add-i2c-slave-inactive-timeout-support.patch \
file://patches/0510-driver-xdpe132g5c-pmbus.patch \
file://patches/0520-add-shutdown-path-in-spi-aspeed-smc-driver.patch \
"

#
Expand Down

0 comments on commit dd34cee

Please # to comment.