Aspeed SMC enhancements
Subsystems (4)
cover Aspeed SMC enhancements
Hi,
Here is a series providing a couple of fixes and enhancements on the SMC driver, among which :
- support of the segment registers which are needed to set the mapping windows of the chips on the AHB bus.
- command mode support
- detection of the best HCLK settings for reads (adapted from pflash)
The full tree can be found here:
https://github.com/legoater/linux/commits/openbmc-4.10
Tested on the palmetto, ast2500 evb and witherspoon platforms.
Thanks,
C.
Cédric Le Goater (6):
mtd: spi-nor: aspeed: fix the AST2400 SMC window size
mtd: spi-nor: aspeed: fix physical base address of chip
mtd: spi-nor: aspeed: configure chip window on AHB bus
mtd: spi-nor: aspeed: use command mode for reads
mtd: spi-nor: aspeed: link controller with the ahb clock
mtd: spi-nor: aspeed: optimize read mode
arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts | 4 + arch/arm/boot/dts/aspeed-g5.dtsi | 6 + drivers/mtd/spi-nor/aspeed-smc.c | 362 +++++++++++++++++++++++++- 3 files changed, 358 insertions(+), 14 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/6 mtd: spi-nor: aspeed: fix the AST2400 SMC window size
The window of the Aspeed AST2400 SMC Controller to map chips on the AHB Bus has a 256MB size. 64MB is the default size for the first chip select and not the full window range: [ 0x20000000 - 0x2FFFFFFF ].
--- drivers/mtd/spi-nor/aspeed-smc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/spi-nor/aspeed-smc.c +1 -1
@@ -51,7 +51,7 @@ static void aspeed_smc_chip_set_4b_spi_2400(struct aspeed_smc_chip *chip);static void aspeed_smc_chip_set_4b (struct aspeed_smc_chip *chip);static const struct aspeed_smc_info fmc_2400_info = { - .maxsize =64 *1024 *1024 , + .maxsize =256 *1024 *1024 , .nce =5 , .hastype = true, .we0 =16 ,
Signature · 1 line
2.7.4
PATCH 2/6 mtd: spi-nor: aspeed: fix physical base address of chip
In reply to Cédric Le GoaterThe phys_base address is used to trigger DMAs on a chip and to address the correct CS, it should take into account the offset of the chip in the AHB bus window.
--- drivers/mtd/spi-nor/aspeed-smc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/spi-nor/aspeed-smc.c +1 -1
@@ -693,7 +693,7 @@ static int aspeed_smc_chip_setup_init(struct aspeed_smc_chip *chip,return -EINVAL ; } - chip->phys_base = res->start; + chip->phys_base = res->start + (chip->ahb_base - controller->ahb_base);/* * Get value of the inherited control register. U-Boot usually
Signature · 1 line
2.7.4
PATCH 3/6 mtd: spi-nor: aspeed: configure chip window on AHB bus
In reply to Cédric Le GoaterThe segment registers of the SMC controller provide a way to configure the mapping windows of the chips on the AHB bus. The settings are required to be correct when the controller operates in Command mode, which is the case for DMAs and the LPC mapping.
This tries to set the segment registers of each chip depending on the size of the flash device and depending on the previous segment settings, in order to have a contiguous window across multiple chip.
Unfortunately, the AST2500 SPI controller has a bug and it is not possible to configure a full 128MB window for a chip of the same size. The window size needs to be restricted to 120MB. This issue only applies to CE0.
Sample kernel dmesg on a Witherspoon :
aspeed-smc 1e620000.flash-controller: Using IRQ 17
aspeed-smc 1e620000.flash-controller: DMA support disabled.
aspeed-smc 1e620000.flash-controller: mx25l25635e (32768 Kbytes) aspeed-smc 1e620000.flash-controller: CE0 window [ 0x20000000- 0x22000000 ] 32MB aspeed-smc 1e620000.flash-controller: CE1 window [ 0x22000000- 0x2a000000 ] 128MB 5 ofpart partitions found on MTD device bmc
Creating 5 MTD partitions on "bmc":
0x000000000000-0x000000060000 : "u-boot"
0x000000060000-0x000000080000 : "u-boot-env" 0x000000080000-0x0000004c0000 : "kernel"
0x0000004c0000-0x000001c00000 : "rofs"
0x000001c00000-0x000002000000 : "rwfs"
aspeed-smc 1e620000.flash-controller: mx25l25635e (32768 Kbytes) aspeed-smc 1e620000.flash-controller: CE1 window [ 0x22000000- 0x24000000 ] 32MB aspeed-smc 1e620000.flash-controller: CE2 window [ 0x24000000- 0x2c000000 ] 128MB aspeed-smc 1e630000.flash-controller: mx66l1g45g (131072 Kbytes) aspeed-smc 1e630000.flash-controller: CE0 window resized to 120MB (AST2500 HW quirk) aspeed-smc 1e630000.flash-controller: CE0 window [ 0x30000000- 0x37800000 ] 120MB aspeed-smc 1e630000.flash-controller: CE0 window too small for chip 128MB aspeed-smc 1e630000.flash-controller: CE1 window [ 0x37800000- 0x38000000 ] 8MB
---
Changes since initial version :
- fixed SEGMENT_ADDR_REG()
- added some extra comments
drivers/mtd/spi-nor/aspeed-smc.c | 124 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 3 deletions(-)
drivers/mtd/spi-nor/aspeed-smc.c +121 -3
@@ -104,6 +104,7 @@ struct aspeed_smc_chip {struct aspeed_smc_controller *controller;void __iomem *ctl;/* control register */ void __iomem *ahb_base;/* base of chip window */ +u32 ahb_window_size;/* chip window size */ unsigned long phys_base;/* physical address of window */ u32 ctl_val[smc_max];/* control settings */ enum aspeed_smc_flash_type type;/* what type of flash */
@@ -218,6 +219,10 @@ struct aspeed_smc_controller {#define SEGMENT_ADDR_REG0 0x30#define SEGMENT_ADDR_START (_r) ((((_r) >> 16) & 0xFF) << 23)#define SEGMENT_ADDR_END (_r) ((((_r) >> 24) & 0xFF) << 23) +#define SEGMENT_ADDR_VALUE (start, end) \ + (((((start) >> 23) & 0xFF) << 16) | ((((end) >> 23) & 0xFF) << 24)) +#define SEGMENT_ADDR_REG (controller, cs) \ + ((controller)->regs + SEGMENT_ADDR_REG0 + (cs) * 4)/* DMA Registers */ #define DMA_CONTROL_REG 0x80
@@ -604,8 +609,7 @@ static void __iomem *aspeed_smc_chip_base(struct aspeed_smc_chip *chip,u32 reg;if (controller->info->nce >1 ) { - reg =readl (controller->regs +SEGMENT_ADDR_REG0 + - chip->cs *4 ); + reg =readl (SEGMENT_ADDR_REG (controller, chip->cs));if (SEGMENT_ADDR_START (reg) >=SEGMENT_ADDR_END (reg))return NULL ;
@@ -616,6 +620,111 @@ static void __iomem *aspeed_smc_chip_base(struct aspeed_smc_chip *chip,return controller->ahb_base + offset; } +static u32 chip_set_segment (struct aspeed_smc_chip *chip,u32 cs,u32 start, +u32 size) +{ +struct aspeed_smc_controller *controller = chip->controller; +void __iomem *seg_reg; +u32 oldval, newval, val0, start0, end; + + val0 =readl (SEGMENT_ADDR_REG (controller,0 )); + start0 =SEGMENT_ADDR_START (val0); + + seg_reg =SEGMENT_ADDR_REG (controller, cs); + oldval =readl (seg_reg); + +/* If the chip size is not specified, use the default segment +* size, but take into account the possible overlap with the +* previous segment +*/ +if (!size) + size =SEGMENT_ADDR_END (oldval) - start; + +/* The segment cannot exceed the maximum window size of the +* controller. +*/ +if (start + size > start0 + controller->info->maxsize) { + size = start0 + controller->info->maxsize - start; +dev_warn (chip->nor.dev,"CE%d window resized to %dMB" , + cs, size >>20 ); + } + + end = start + size; + newval =SEGMENT_ADDR_VALUE (start, end); +writel (newval, seg_reg); + +/* Restore default value if something goes wrong. The chip +* might have set some bogus value and we would loose access +* to the chip. +*/ +if (newval !=readl (seg_reg)) { +dev_err (chip->nor.dev,"CE%d window invalid" , cs); +writel (oldval, seg_reg); + start =SEGMENT_ADDR_START (oldval); + end =SEGMENT_ADDR_END (oldval); + size = end - start; + } + +dev_info (chip->nor.dev,"CE%d window [ 0x%.8x- 0x%.8x ] %dMB" , + cs, start, end, size >>20 ); + +return size; +} + +/* +* This is expected to be called in increasing CE order +*/ +static u32 aspeed_smc_chip_set_segment (struct aspeed_smc_chip *chip) +{ +struct aspeed_smc_controller *controller = chip->controller; +u32 val0, start0, start; +u32 size = chip->nor.mtd.size; + +/* The AST2500 SPI controller has a bug when the CE0 chip size +* exceeds 120MB. +*/ +if (chip->cs ==0 && controller->info == &spi_2500_info && + size == (128 <<20 )) { + size =120 <<20 ; +dev_info (chip->nor.dev, +"CE%d window resized to %dMB (AST2500 HW quirk)" , + chip->cs, size >>20 ); + } + + val0 =readl (SEGMENT_ADDR_REG (controller,0 )); + start0 =SEGMENT_ADDR_START (val0); + +/* As a start address for the current segment, use the default +* start address if we are handling CE0 or use the previous +* segment ending address +*/ +if (chip->cs) { +u32 prev =readl (SEGMENT_ADDR_REG (controller, chip->cs -1 )); + + start =SEGMENT_ADDR_END (prev); + }else + start = start0; + + size =chip_set_segment (chip, chip->cs, start, size); + +/* Update chip base address on the AHB bus */ + chip->ahb_base = controller->ahb_base + (start - start0); + +if (size < chip->nor.mtd.size) +dev_warn (chip->nor.dev, +"CE%d window too small for chip %dMB" , + chip->cs, (u32 ) chip->nor.mtd.size >>20 ); + +/* Make sure the next segment does not overlap with the +* current one we just configured even if there is no +* available chip. That could break access in Command Mode. +*/ +if (chip->cs < controller->info->nce -1 ) +chip_set_segment (chip, chip->cs +1 , start + size,0 ); + +return size; +} +static void aspeed_smc_chip_enable_write (struct aspeed_smc_chip *chip) {struct aspeed_smc_controller *controller = chip->controller;
@@ -689,7 +798,7 @@ static int aspeed_smc_chip_setup_init(struct aspeed_smc_chip *chip,*/ chip->ahb_base =aspeed_smc_chip_base (chip, res);if (!chip->ahb_base) { -dev_warn (chip->nor.dev,"CE segment window closed.\n" ); +dev_warn (chip->nor.dev,"CE%d window closed" , chip->cs);return -EINVAL ; }
@@ -738,6 +847,15 @@ static int aspeed_smc_chip_setup_finish(struct aspeed_smc_chip *chip)if (chip->nor.addr_width ==4 && info->set_4b) info->set_4b (chip); +/* This is for direct AHB access when using Command Mode. For +* the AST2400 SPI controller which only handles one chip, +* let's use the full window. +*/ +if (controller->info->nce ==1 ) + chip->ahb_window_size = info->maxsize; +else + chip->ahb_window_size =aspeed_smc_chip_set_segment (chip); +/* * base mode has not been optimized yet. use it for writes. */
Signature · 1 line
2.7.4
PATCH 4/6 mtd: spi-nor: aspeed: use command mode for reads
In reply to Cédric Le GoaterWhen reading flash contents, try to use the "command mode" if the AHB window configured for the flash module is big enough. Else, just fall back to the "user mode" to perform the read.
---
memcpy_fromio() works perfectly fine. I wonder if they were some changes in the kernel that fixed the issues reported in the very early version of this driver. See the comment before aspeed_smc_read_from_ahb()
drivers/mtd/spi-nor/aspeed-smc.c | 42 +++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-)
drivers/mtd/spi-nor/aspeed-smc.c +33 -9
@@ -516,16 +516,8 @@ static ssize_t aspeed_smc_read_user(struct spi_nor *nor, loff_t from,struct aspeed_smc_chip *chip = nor->priv;int i;u8 dummy =0xFF ; -int ret;u32 ctl; -if (aspeed_smc_dma_check (chip, from, len)) { - ret =aspeed_smc_dma_start (chip, from, read_buf, len,0 ); -if (!ret) - goto out; -dev_err (chip->nor.dev,"DMA read failed: %d" , ret); - } -aspeed_smc_start_user (nor);aspeed_smc_send_cmd_addr (nor, nor->read_opcode, from);for (i =0 ; i < chip->nor.read_dummy /8 ; i++)
@@ -540,6 +532,38 @@ static ssize_t aspeed_smc_read_user(struct spi_nor *nor, loff_t from,aspeed_smc_read_from_ahb (read_buf, chip->ahb_base, len);aspeed_smc_stop_user (nor); +return 0 ; +} + +static ssize_t aspeed_smc_read (struct spi_nor *nor,loff_t from,size_t len, +u_char *read_buf) +{ +struct aspeed_smc_chip *chip = nor->priv; +int ret; + +/* The segment window configured for the chip is too small for +* the read offset. Use the "User mode" of the controller to +* perform the read. +*/ +if (from >= chip->ahb_window_size) { +aspeed_smc_read_user (nor, from, len, read_buf); + goto out; + } + +/* Then, try DMA if the driver allows them. */ +if (aspeed_smc_dma_check (chip, from, len)) { + ret =aspeed_smc_dma_start (chip, from, read_buf, len,0 ); +if (!ret) + goto out; +dev_err (chip->nor.dev,"DMA read failed: %d" , ret); + } + +/* Last, and this should be the default, use the "Command +* mode" of the controller which does the read from the +* segment window configured for the chip on the AHB bus. +*/ +memcpy_fromio (read_buf, chip->ahb_base + from, len); + out:return len; }
@@ -948,7 +972,7 @@ static int aspeed_smc_setup_flash(struct aspeed_smc_controller *controller, nor->dev = dev; nor->priv = chip;spi_nor_set_flash_node (nor, child); - nor->read = aspeed_smc_read_user; + nor->read = aspeed_smc_read; nor->write = aspeed_smc_write_user; nor->read_reg = aspeed_smc_read_reg; nor->write_reg = aspeed_smc_write_reg;
Signature · 1 line
2.7.4
PATCH 5/6 mtd: spi-nor: aspeed: link controller with the ahb clock
In reply to Cédric Le GoaterWe will need the AHB frequency to set the HCLK settings in the SMC controller to optimize the reads.
--- arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts | 4 ++++ arch/arm/boot/dts/aspeed-g5.dtsi | 6 ++++++ drivers/mtd/spi-nor/aspeed-smc.c | 7 +++++++ 3 files changed, 17 insertions(+)
arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts +4 -0
@@ -56,6 +56,8 @@ compatible = "aspeed,ast2400-fmc"; aspeed,fmc-has-dma; interrupts = <19>; + clocks = <&clk_ahb>; + clock-names = "ahb"; flash@0 { reg = < 0 >; compatible = "jedec,spi-nor" ;
@@ -70,6 +72,8 @@ #address-cells = <1>; #size-cells = <0>; compatible = "aspeed,ast2400-spi"; + clocks = <&clk_ahb>; + clock-names = "ahb"; flash { reg = < 0 >; compatible = "jedec,spi-nor" ;
arch/arm/boot/dts/aspeed-g5.dtsi +6 -0
@@ -33,6 +33,8 @@ status = "disabled"; aspeed,fmc-has-dma; interrupts = <19>; + clocks = <&clk_ahb>; + clock-names = "ahb"; flash@0 { reg = < 0 >; compatible = "jedec,spi-nor";
@@ -58,6 +60,8 @@ #size-cells = <0>; compatible = "aspeed,ast2500-spi"; status = "disabled"; + clocks = <&clk_ahb>; + clock-names = "ahb"; flash@0 { reg = < 0 >; compatible = "jedec,spi-nor";
@@ -77,6 +81,8 @@ #size-cells = <0>; compatible = "aspeed,ast2500-spi"; status = "disabled"; + clocks = <&clk_ahb>; + clock-names = "ahb"; flash@0 { reg = < 0 >; compatible = "jedec,spi-nor";
drivers/mtd/spi-nor/aspeed-smc.c +7 -0
@@ -10,6 +10,7 @@*/ #include <linux/bug.h> +#include <linux/clk.h> #include <linux/device.h> #include <linux/dma-direction.h> #include <linux/dma-mapping.h>
@@ -119,6 +120,8 @@ struct aspeed_smc_controller {void __iomem *regs;/* controller registers */ void __iomem *ahb_base;/* per-chip windows resource */ +struct clk *ahb_clk; +/* interrupt handling */ int irq;
@@ -1107,6 +1110,10 @@ static int aspeed_smc_probe(struct platform_device *pdev)if (IS_ERR (controller->ahb_base))return PTR_ERR (controller->ahb_base); + controller->ahb_clk =devm_clk_get (&pdev->dev,"ahb" ); +if (IS_ERR (controller->ahb_clk)) +return PTR_ERR (controller->ahb_clk); +aspeed_smc_dma_setup (controller, pdev); ret =aspeed_smc_setup_flash (controller, np, res);
Signature · 1 line
2.7.4
PATCH 6/6 mtd: spi-nor: aspeed: optimize read mode
In reply to Cédric Le GoaterOnly for SPI controllers as U-Boot should have done it already for the FMC controller using DMAs.
The algo first reads a golden buffer at low speed and then performs reads with different clocks and delay cycles settings to find the fastest configuration for the chip.
Based on the pflash tool.
---
TODO: may be add a chicken switch ?
drivers/mtd/spi-nor/aspeed-smc.c | 185 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+)
drivers/mtd/spi-nor/aspeed-smc.c +185 -0
@@ -22,6 +22,7 @@#include <linux/mtd/spi-nor.h> #include <linux/of.h> #include <linux/of_platform.h> +#include <linux/slab.h> #include <linux/sysfs.h> #define DEVICE_NAME "aspeed-smc"
@@ -43,13 +44,17 @@ struct aspeed_smc_info {bool hastype;/* flash type field exists in config reg */ u8 we0;/* shift for write enable bit for CE0 */ u8 ctl0;/* offset in regs of ctl for CE0 */ +u8 timing;/* offset in regs of timing */ bool has_dma;void (*set_4b)(struct aspeed_smc_chip *chip); +int (*optimize_reads)(struct aspeed_smc_chip *chip,u32 max_freq); };static void aspeed_smc_chip_set_4b_spi_2400 (struct aspeed_smc_chip *chip);static void aspeed_smc_chip_set_4b (struct aspeed_smc_chip *chip); +static int aspeed_smc_optimize_reads (struct aspeed_smc_chip *chip, +u32 max_freq);static const struct aspeed_smc_info fmc_2400_info = { .maxsize =256 *1024 *1024 ,
@@ -57,6 +62,7 @@ static const struct aspeed_smc_info fmc_2400_info = { .hastype = true, .we0 = 16, .ctl0 = 0x10, + .timing = 0x94, .has_dma = true, .set_4b = aspeed_smc_chip_set_4b, };
@@ -67,8 +73,10 @@ static const struct aspeed_smc_info spi_2400_info = { .hastype = false, .we0 = 0, .ctl0 = 0x04, + .timing = 0x94, .has_dma = false, .set_4b = aspeed_smc_chip_set_4b_spi_2400, + .optimize_reads = aspeed_smc_optimize_reads, };static const struct aspeed_smc_info fmc_2500_info = {
@@ -77,6 +85,7 @@ static const struct aspeed_smc_info fmc_2500_info = { .hastype = true, .we0 = 16, .ctl0 = 0x10, + .timing = 0x94, .has_dma = true, .set_4b = aspeed_smc_chip_set_4b, };
@@ -87,8 +96,10 @@ static const struct aspeed_smc_info spi_2500_info = { .hastype = false, .we0 = 16, .ctl0 = 0x10, + .timing = 0x94, .has_dma = false, .set_4b = aspeed_smc_chip_set_4b, + .optimize_reads = aspeed_smc_optimize_reads, };enum aspeed_smc_ctl_reg_value {
@@ -865,6 +876,174 @@ static int aspeed_smc_chip_setup_init(struct aspeed_smc_chip *chip,return 0 ; } + +#define CALIBRATE_BUF_SIZE 16384 + +static bool aspeed_smc_check_reads (struct aspeed_smc_chip *chip, +const u8 *golden_buf,u8 *test_buf) +{ +int i; + +for (i =0 ; i <10 ; i++) { +aspeed_smc_read_from_ahb (test_buf, chip->ahb_base, +CALIBRATE_BUF_SIZE ); +if (memcmp (test_buf, golden_buf,CALIBRATE_BUF_SIZE ) !=0 ) +return false; + } +return true; +} + +static int aspeed_smc_calibrate_reads (struct aspeed_smc_chip *chip,u32 hdiv, +const u8 *golden_buf,u8 *test_buf) +{ +struct aspeed_smc_controller *controller = chip->controller; +const struct aspeed_smc_info *info = controller->info; +int i; +int good_pass =-1 , pass_count =0 ; +u32 shift = (hdiv -1 ) <<2 ; +u32 mask = ~(0xfu << shift); +u32 fread_timing_val =0 ; + +#define FREAD_TPASS (i) (((i) / 2) | (((i) & 1) ? 0 : 8)) + +/* Try HCLK delay 0..5, each one with/without delay and look for a +* good pair. +*/ +for (i =0 ; i <12 ; i++) { +bool pass; + + fread_timing_val &= mask; + fread_timing_val |=FREAD_TPASS (i) << shift; + +writel (fread_timing_val, controller->regs + info->timing); + pass =aspeed_smc_check_reads (chip, golden_buf, test_buf); +dev_dbg (chip->nor.dev, +" * [%08x] %d HCLK delay, %dns DI delay : %s" , + fread_timing_val, i/2 , (i &1 ) ?0 :4 , + pass ?"PASS" :"FAIL" ); +if (pass) { + pass_count++; +if (pass_count ==3 ) { + good_pass = i -1 ; +break ; + } + }else + pass_count =0 ; + } + +/* No good setting for this frequency */ +if (good_pass <0 ) +return -1 ; + +/* We have at least one pass of margin, let's use first pass */ + fread_timing_val &= mask; + fread_timing_val |=FREAD_TPASS (good_pass) << shift; +writel (fread_timing_val, controller->regs + info->timing); +dev_dbg (chip->nor.dev," * -> good is pass %d [0x%08x]" , + good_pass, fread_timing_val); +return 0 ; +} + +static bool aspeed_smc_check_calib_data (const u8 *test_buf,u32 size) +{ +const u32 *tb32 = (const u32 *) test_buf; +u32 i, cnt =0 ; + +/* We check if we have enough words that are neither all 0 +* nor all 1's so the calibration can be considered valid. +* +* I use an arbitrary threshold for now of 64 +*/ + size >>=2 ; +for (i =0 ; i < size; i++) { +if (tb32[i] !=0 && tb32[i] !=0xffffffff ) + cnt++; + } +return cnt >=64 ; +} + +static const uint32_t aspeed_smc_hclk_divs[] = { +0xf ,/* HCLK */ +0x7 ,/* HCLK/2 */ +0xe ,/* HCLK/3 */ +0x6 ,/* HCLK/4 */ +0xd ,/* HCLK/5 */ +}; +#define ASPEED_SMC_HCLK_DIV (i) (aspeed_smc_hclk_divs[(i) - 1] << 8) + +static int aspeed_smc_optimize_reads (struct aspeed_smc_chip *chip, +u32 max_freq) +{ +u8 *golden_buf, *test_buf; +int i, rc, best_div =-1 ; +u32 save_read_val = chip->ctl_val[smc_read]; +u32 ahb_freq =clk_get_rate (chip->controller->ahb_clk); + +dev_dbg (chip->nor.dev,"AHB frequency: %d MHz" , ahb_freq /1000000 ); + + test_buf =kmalloc (CALIBRATE_BUF_SIZE *2 ,GFP_KERNEL ); + golden_buf = test_buf +CALIBRATE_BUF_SIZE ; + +/* We start with the dumbest setting (keep 4Byte bit) and read +* some data +*/ + chip->ctl_val[smc_read] = (chip->ctl_val[smc_read] &0x2000 ) | + (0x00 <<28 ) |/* Single bit */ + (0x00 <<24 ) |/* CE# max */ + (0x03 <<16 ) |/* use normal reads */ + (0x00 <<8 ) |/* HCLK/16 */ + (0x00 <<6 ) |/* no dummy cycle */ + (0x00 );/* normal read */ + +writel (chip->ctl_val[smc_read], chip->ctl); + +aspeed_smc_read_from_ahb (golden_buf, chip->ahb_base, +CALIBRATE_BUF_SIZE ); + +/* Establish our read mode with freq field set to 0 (HCLK/16) */ + chip->ctl_val[smc_read] = save_read_val &0xfffff0ff ; + +/* Check if calibration data is suitable */ +if (!aspeed_smc_check_calib_data (golden_buf,CALIBRATE_BUF_SIZE )) { +dev_info (chip->nor.dev, +"Calibration area too uniform, using low speed" ); +writel (chip->ctl_val[smc_read], chip->ctl); +kfree (test_buf); +return 0 ; + } + +/* Now we iterate the HCLK dividers until we find our breaking point */ +for (i =ARRAY_SIZE (aspeed_smc_hclk_divs); i >0 ; i--) { +u32 tv, freq; + +/* Compare timing to max */ + freq = ahb_freq / i; +if (freq >= max_freq) +continue ; + +/* Set the timing */ + tv = chip->ctl_val[smc_read] |ASPEED_SMC_HCLK_DIV (i); +writel (tv, chip->ctl); +dev_dbg (chip->nor.dev,"Trying HCLK/%d..." , i); + rc =aspeed_smc_calibrate_reads (chip, i, golden_buf, test_buf); +if (rc ==0 ) + best_div = i; + } +kfree (test_buf); + +/* Nothing found ? */ +if (best_div <0 ) +dev_warn (chip->nor.dev,"No good frequency, using dumb slow" ); +else { +dev_dbg (chip->nor.dev,"Found good read timings at HCLK/%d" , + best_div); + chip->ctl_val[smc_read] |=ASPEED_SMC_HCLK_DIV (best_div); + } + +writel (chip->ctl_val[smc_read], chip->ctl); +return 0 ; +} +static int aspeed_smc_chip_setup_finish (struct aspeed_smc_chip *chip) {struct aspeed_smc_controller *controller = chip->controller;
@@ -918,6 +1097,12 @@ static int aspeed_smc_chip_setup_finish(struct aspeed_smc_chip *chip)dev_dbg (controller->dev,"read control register: %08x\n" , chip->ctl_val[smc_read]); + +/* +* TODO: get max freq from chip +*/ +if (info->optimize_reads) + info->optimize_reads (chip,104000000 );return 0 ; }
Signature · 1 line
2.7.4
Re: [PATCH linux dev-4.10 6/6] mtd: spi-nor: aspeed: optimize read mode
Quoted 8 lines · Cédric Le Goater
Only for SPI controllers as U-Boot should have done it already for the
FMC controller using DMAs.The algo first reads a golden buffer at low speed and then performs reads with different clocks and delay cycles settings to find the fastest configuration for the chip.
Quoted 6 lines
Based on the pflash tool.
Signed-off-by Cédric Le Goater <[email protected]>---
TODO: may be add a chicken switch ?
A module parameter (which can also be passed as a kernel command line arg) to disable it, yes.
Cheers,
Ben.
Re: [PATCH linux dev-4.10 6/6] mtd: spi-nor: aspeed: optimize read mode
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 10 lines · Cédric Le Goater
Only for SPI controllers as U-Boot should have done it already for the
FMC controller using DMAs.The algo first reads a golden buffer at low speed and then performs reads with different clocks and delay cycles settings to find the fastest configuration for the chip.
Based on the pflash tool.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Cédric Le Goater <[email protected]>---
TODO: may be add a chicken switch ?
A module parameter (which can also be passed as a kernel command line arg) to disable it, yes.
I have added a kernel parameter in my branch :
https://github.com/legoater/linux/commits/openbmc-4.10
Cheers,
C.
Joel Stanley
maintainerQuoted 10 lines · Cédric Le Goater
Hi,
Here is a series providing a couple of fixes and enhancements on the SMC driver, among which :
- support of the segment registers which are needed to set the mapping windows of the chips on the AHB bus.
- command mode support
- detection of the best HCLK settings for reads (adapted from pflash)
Quoted 5 lines
The full tree can be found here:
https://github.com/legoater/linux/commits/openbmc-4.10
Tested on the palmetto, ast2500 evb and witherspoon platforms.
Great work Cedric. I merged this series into dev-4.10.
In my simple test where I read off the PNOR, I get the following improvement on the Romulus board I looked at:
$ time dd if=/dev/mtd6 of=/dev/null bs=64k
v4.7.10-294-gec62e5e4b9bb 0m35.483s
v4.10.5-60-g5e4185ecf0cf 0m7.450s
Cheers,
Joel