aspeed-smc: add support for AST2500 and DMA transfers
Subsystems (4)
cover aspeed-smc: add support for AST2500 and DMA transfers
Hello,
This patchset adds to the current aspeed SMC driver the register settings enabling support for the AST2500. Some initial work is done on the segment registers to provide a better configuration of the mapping windows on the flash modules but this area clearly needs more work to be solid.
Also, a first version of DMA read/write is provided. But the speed results are not very satisfying so they are disabled by default. You
Thanks,
C.
Cédric Le Goater (7):
ARM: dts: aspeed-g5: update ast2500 evb with new spi-nor binding
mtd: spi-nor: aspeed: make locking more explicit
mtd: spi-nor: aspeed: introduce a device under aspeed_smc_controller
mtd: spi-nor: aspeed: add DMA support to smc controller
ARM: dts: aspeed: update SMC controller nodes supporting DMAs
mtd: spi-nor: aspeed: use property "aspeed,fmc-has-dma"
mtd: spi-nor: aspeed: use fast read when doing DMAs
Milton Miller (5):
mtd: spi-nor: support for Aspeed AST2500 SoC
mtd: spi-nor: aspeed: Manage the segment address registers
mtd: spi-nor: Add Micronix mx66l1g45g spi flash
ARM: dts: aspeed-g5: update for new spi-nor binding
ARM: dts: aspeed-g5: update witherspoon for new spi-nor binding
.../devicetree/bindings/mtd/aspeed-smc.txt | 32 +- arch/arm/boot/dts/aspeed-ast2500-evb.dts | 28 +- arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts | 2 + arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 28 +- arch/arm/boot/dts/aspeed-g5.dtsi | 65 +++ drivers/mtd/spi-nor/aspeed-smc.c | 449 +++++++++++++++++---- drivers/mtd/spi-nor/spi-nor.c | 1 + 7 files changed, 499 insertions(+), 106 deletions(-)
Signature · 1 line
2.7.4
PATCH 4/12 ARM: dts: aspeed-g5: update for new spi-nor binding
From: Milton Miller <[email protected]>
--- arch/arm/boot/dts/aspeed-g5.dtsi | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
arch/arm/boot/dts/aspeed-g5.dtsi +63 -0
@@ -24,6 +24,69 @@ #size-cells = <1>; ranges; + fmc: flash-controller@1e620000 { + reg = < 0x1e620000 0xc4 + 0x20000000 0x10000000 >; + #address-cells = <1>; + #size-cells = <0>; + compatible = "aspeed,ast2500-fmc"; + status = "disabled"; + flash@0 { + reg = < 0 >; + compatible = "jedec,spi-nor"; + status = "disabled"; + }; + flash@1 { + reg = < 1 >; + compatible = "jedec,spi-nor"; + status = "disabled"; + }; + flash@2 { + reg = < 2 >; + compatible = "jedec,spi-nor"; + // compatible = "cfi,flash", "jedec,flash"; + status = "disabled"; + }; + }; + + spi1: flash-controller@1e630000 { + reg = < 0x1e630000 0xc4 + 0x30000000 0x08000000 >; + #address-cells = <1>; + #size-cells = <0>; + compatible = "aspeed,ast2500-smc"; + status = "disabled"; + flash@0 { + reg = < 0 >; + compatible = "jedec,spi-nor"; + status = "disabled"; + }; + flash@1 { + reg = < 1 >; + compatible = "jedec,spi-nor"; + status = "disabled"; + }; + }; + + spi2: flash-controller@1e631000 { + reg = < 0x1e631000 0xc4 + 0x38000000 0x08000000 >; + #address-cells = <1>; + #size-cells = <0>; + compatible = "aspeed,ast2500-smc"; + status = "disabled"; + flash@0 { + reg = < 0 >; + compatible = "jedec,spi-nor"; + status = "disabled"; + }; + flash@1 { + reg = < 1 >; + compatible = "jedec,spi-nor"; + status = "disabled"; + }; + }; + vic: interrupt-controller@1e6c0080 { compatible = "aspeed,ast2400-vic"; interrupt-controller;
Signature · 1 line
2.7.4
PATCH 5/12 ARM: dts: aspeed-g5: update witherspoon for new spi-nor binding
In reply to Cédric Le GoaterFrom: Milton Miller <[email protected]>
Witherspoon has two flash modules for the BMC firmware and one for the host.
--- arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 28 ++++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-)
arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts +16 -12
@@ -19,20 +19,24 @@ memory { reg = <0x80000000 0x40000000>; }; +}; - ahb { - bmc_pnor: fmc@1e620000 { - reg = < 0x1e620000 0x94 - 0x20000000 0x02000000 >; - #address-cells = <1>; - #size-cells = <0>; - compatible = "aspeed,ast2500-fmc"; - flash@0 { - reg = < 0 >; - compatible = "jedec,spi-nor" ; +&fmc { + status = "okay"; + flash@0 { + status = "okay"; #include "aspeed-bmc-opp-flash-layout.dtsi" - }; - }; + }; + flash@1 { + status = "okay"; + label = "alt"; + }; +}; + +&spi1 { + status = "okay"; + flash@0 { + status = "okay"; }; };
Signature · 1 line
2.7.4
PATCH 6/12 ARM: dts: aspeed-g5: update ast2500 evb with new spi-nor binding
In reply to Cédric Le GoaterThe ast2500 evb has one flash module for the BMC firmware and one for the host.
--- arch/arm/boot/dts/aspeed-ast2500-evb.dts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
arch/arm/boot/dts/aspeed-ast2500-evb.dts +16 -12
@@ -18,23 +18,27 @@ memory { reg = <0x80000000 0x20000000>; }; +}; - ahb { - bmc_pnor: fmc@1e620000 { - reg = < 0x1e620000 0x94 - 0x20000000 0x02000000 >; - #address-cells = <1>; - #size-cells = <0>; - compatible = "aspeed,ast2500-fmc"; - flash@0 { - reg = < 0 >; - compatible = "jedec,spi-nor" ; +&fmc { + status = "okay"; + flash@0 { + status = "okay"; #include "aspeed-bmc-opp-flash-layout.dtsi" - }; - }; }; }; +&spi1 { + status = "okay"; + flash@0 { + status = "okay"; + }; +}; + +&spi2 { + status = "okay"; +}; + &uart5 { status = "okay"; };
Signature · 1 line
2.7.4
PATCH 8/12 mtd: spi-nor: aspeed: introduce a device under aspeed_smc_controller
In reply to Cédric Le GoaterThis will be useful for readability and also logging.
--- drivers/mtd/spi-nor/aspeed-smc.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
drivers/mtd/spi-nor/aspeed-smc.c +18 -12
@@ -214,6 +214,8 @@ struct aspeed_smc_per_chip { };struct aspeed_smc_controller { +struct device *dev; +struct mutex mutex;/* controller access mutex */ const struct aspeed_smc_info *info;/* type info of controller */ void __iomem *regs;/* controller registers */
@@ -436,7 +438,7 @@ static void __iomem *window_start(struct aspeed_smc_controller *controller,return controller->windows + offset; } -static int aspeed_smc_probe (struct platform_device *dev) +static int aspeed_smc_probe (struct platform_device *pdev) {struct aspeed_smc_controller *controller;const struct of_device_id *match;
@@ -446,29 +448,31 @@ static int aspeed_smc_probe(struct platform_device *dev)int err =0 ;unsigned int n; - match =of_match_device (aspeed_smc_matches, &dev->dev); + match =of_match_device (aspeed_smc_matches, &pdev->dev);if (!match || !match->data)return -ENODEV ; info = match->data; - controller =devm_kzalloc (&dev->dev,sizeof (*controller) + + controller =devm_kzalloc (&pdev->dev,sizeof (*controller) + info->nce *sizeof (controller->chips[0 ]),GFP_KERNEL );if (!controller)return -ENOMEM ; controller->info = info;mutex_init (&controller->mutex); -platform_set_drvdata (dev, controller); +platform_set_drvdata (pdev, controller); - r =platform_get_resource (dev,IORESOURCE_MEM ,0 ); - controller->regs =devm_ioremap_resource (&dev->dev, r); + r =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + controller->regs =devm_ioremap_resource (&pdev->dev, r);if (IS_ERR (controller->regs))return PTR_ERR (controller->regs); - r =platform_get_resource (dev,IORESOURCE_MEM ,1 ); - controller->windows =devm_ioremap_resource (&dev->dev, r); + r =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); + controller->windows =devm_ioremap_resource (&pdev->dev, r);if (IS_ERR (controller->windows))return PTR_ERR (controller->windows); + controller->dev = &pdev->dev; +/* The pinmux or bootloader will disable legacy mode. */ /*
@@ -476,7 +480,7 @@ static int aspeed_smc_probe(struct platform_device *dev)* is shared by the host. */ -for_each_available_child_of_node (dev->dev.of_node, child) { +for_each_available_child_of_node (controller->dev->of_node, child) {struct platform_device *cdev;struct aspeed_smc_per_chip *chip;u32 reg;
@@ -494,7 +498,8 @@ static int aspeed_smc_probe(struct platform_device *dev)* The creating the device node for the child here allows its * use for error reporting via dev_err below. */ - cdev =of_platform_device_create_or_find (child, &dev->dev); + cdev =of_platform_device_create_or_find (child, + controller->dev);if (!cdev)continue ;
@@ -509,7 +514,7 @@ static int aspeed_smc_probe(struct platform_device *dev) n, dev_name(controller->chips[n]->nor.dev));continue ; } - chip =devm_kzalloc (&dev->dev,sizeof (*chip),GFP_KERNEL ); + chip =devm_kzalloc (controller->dev,sizeof (*chip),GFP_KERNEL );if (!chip)continue ;
@@ -533,7 +538,8 @@ static int aspeed_smc_probe(struct platform_device *dev)*/ mutex_lock (&controller->mutex); reg =readl (controller->regs +TYPE_SETTING_REG ); -dev_dbg (&dev->dev,"flash type and setting was %08x\n" , reg); +dev_dbg (controller->dev,"flash type and setting was %08x\n" , + reg); reg |=1 << (info->we0 + n);/* WEn */ if (info->hastype) { reg &= ~(3 << (n *2 ));
Signature · 1 line
2.7.4
PATCH 9/12 mtd: spi-nor: aspeed: add DMA support to smc controller
In reply to Cédric Le GoaterThe Aspeed FMC controller can handle transfers to the flash modules using DMAs. A couple of registers first need to be programmed with the DRAM and flash addresses and the length of the transfer. The transfer is then initiated using a DMA control register and an interrupt notifies the completion.
Such transfers can replace the current IO mode in the read/write ops when some conditions are met on the size and the alignment. In case of failure, a timeout for instance, the operation is restarted using the IO mode.
DMA support does not seem to be that efficient. So we provide some sysfs files for tuning and to switch it on and off (default is off)
--- drivers/mtd/spi-nor/aspeed-smc.c | 246 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 243 insertions(+), 3 deletions(-)
drivers/mtd/spi-nor/aspeed-smc.c +243 -3
@@ -19,6 +19,23 @@#include <linux/of.h> #include <linux/of_platform.h> #include <linux/sysfs.h> +#include <linux/dma-direction.h> +#include <linux/dma-mapping.h> + +#define DEVICE_NAME "aspeed-smc" + +/* +* DMAs do not seem to be that fast, so disable by default +*/ +static bool use_dma; +module_param (use_dma, bool,0644 ); + +static unsigned int min_dma_size =256 ; +module_param (min_dma_size, uint,0644 ); + +/* with 100ms we had a couple of timeouts */ +static unsigned int dma_timeout =200 ; +module_param (dma_timeout, uint,0644 );/* * In user mode all data bytes read or written to the chip decode address
@@ -209,6 +226,7 @@ struct aspeed_smc_per_chip {__le32 __iomem *ctl;/* control register */ void __iomem *base;/* base of chip window */ __le32 ctl_val[smc_num_ctl_reg_values];/* controls with timing */ +unsigned long phys_base;enum smc_flash_type type;/* what type of flash */ struct spi_nor nor; };
@@ -220,6 +238,19 @@ struct aspeed_smc_controller {const struct aspeed_smc_info *info;/* type info of controller */ void __iomem *regs;/* controller registers */ void __iomem *windows;/* per-chip windows resource */ + +/* interrupt handling */ +int irq; + +/* dma */ +bool has_dma; +struct completion dma_done; + +/* dma logging */ +size_t dma_length; +dma_addr_t dma_addr;/* bus address of buffer */ +dma_addr_t flash_addr;/* flash address */ +struct aspeed_smc_per_chip *chips[0 ];/* pointers to attached chips */ };
@@ -267,6 +298,116 @@ struct aspeed_smc_controller { CONTROL_SPI_IO_DUMMY_CYCLES_MASK | CONTROL_SPI_CLOCK_FREQ_SEL_MASK | \ CONTROL_SPI_LSB_FIRST | CONTROL_SPI_CLOCK_MODE_3) +/* Interrupt Control and Status Register */ +#define INTERRUPT_STATUS_REG 0x08 +#define INTERRUPT_DMA_ENABLE BIT(3) +#define INTERRUPT_DMA_STATUS BIT(11) + +/* DMA Registers */ +#define DMA_CONTROL_REG 0x80 +#define DMA_ENABLE BIT(0) +#define DMA_WRITE BIT(1) + +#define DMA_FLASH_BASE_REG 0x84 +#define DMA_DRAM_BASE_REG 0x88 +#define DMA_LENGTH_REG 0x8c + +static void aspeed_smc_dma_done (struct aspeed_smc_controller *controller) +{ +writel (0 , controller->regs +INTERRUPT_STATUS_REG ); +writel (0 , controller->regs +DMA_CONTROL_REG ); +} + +static int aspeed_smc_dma_wait (struct aspeed_smc_per_chip *chip) +{ +struct aspeed_smc_controller *controller = chip->controller; + +if (!wait_for_completion_timeout (&controller->dma_done, +msecs_to_jiffies (dma_timeout))) { +dev_err (chip->nor.dev,"timeout waiting for DMA interrupt " +"addr@%.8x faddr@%.8x size=%x " +"dram@%.8x flash@%.8x done=%x\n" , + controller->dma_addr, + controller->flash_addr, + controller->dma_length, +readl (controller->regs +DMA_DRAM_BASE_REG ), +readl (controller->regs +DMA_FLASH_BASE_REG ), +readl (controller->regs +DMA_LENGTH_REG )); +return -ETIMEDOUT ; + } + +return 0 ; +} + +#define DMA_LENGTH (x) (((x) - 4) & ~0xFE000003) +#define DMA_ADDR (x) ((x) & ~0xE0000003) + +static inline void aspeed_smc_chip_configure (struct aspeed_smc_per_chip *chip, +u32 ctl) +{ + ctl |=CONTROL_SPI_CE_STOP_ACTIVE_CONTROL ; +writel (ctl, chip->ctl); + + ctl &= ~CONTROL_SPI_CE_STOP_ACTIVE_CONTROL ; +writel (ctl, chip->ctl); +} + +/* +* TODO: configure FREAD mode +*/ +static int aspeed_smc_dma_start (struct aspeed_smc_per_chip *chip, +u32 offset,void *buf,size_t length, +int is_write) +{ +struct aspeed_smc_controller *controller = chip->controller; +dma_addr_t dma_addr, flash_addr; +int ret; + +aspeed_smc_chip_configure (chip, is_write ? chip->ctl_val[smc_write] : + chip->ctl_val[smc_base]); + +dev_dbg (chip->nor.dev,"DMA %s to=0x%08x len=0x%08x\n" , + is_write ?"write" :"read" , offset, length); + + dma_addr =dma_map_single (chip->nor.dev, buf, length, + (is_write ?DMA_TO_DEVICE :DMA_FROM_DEVICE )); + +if (unlikely (dma_mapping_error (chip->nor.dev, dma_addr))) { +dev_err (chip->nor.dev,"Failed to dma_map_single()\n" ); + ret = -ENOMEM ; + goto out; + } + flash_addr = chip->phys_base + offset; + + controller->dma_length = length; + controller->dma_addr = dma_addr; + controller->flash_addr = flash_addr; + +reinit_completion (&controller->dma_done); + +writel (0 , controller->regs +DMA_CONTROL_REG ); +writel (DMA_ADDR (flash_addr), controller->regs + +DMA_FLASH_BASE_REG ); +writel (DMA_ADDR (dma_addr), controller->regs +DMA_DRAM_BASE_REG ); +writel (DMA_LENGTH (length), controller->regs +DMA_LENGTH_REG ); + +writel (INTERRUPT_DMA_ENABLE , + controller->regs +INTERRUPT_STATUS_REG ); + +writel (DMA_ENABLE | (is_write <<1 ), + controller->regs +DMA_CONTROL_REG ); + + ret =aspeed_smc_dma_wait (chip); +if (ret) +aspeed_smc_dma_done (controller); + +dma_unmap_single (chip->nor.dev, + controller->dma_addr, controller->dma_length, + (is_write ?DMA_TO_DEVICE :DMA_FROM_DEVICE )); +out: +aspeed_smc_chip_configure (chip, chip->ctl_val[smc_base]); +return ret; +}static u32 spi_control_fill_opcode (u8 opcode) {
@@ -362,13 +503,30 @@ static int aspeed_smc_read_user(struct spi_nor *nor, loff_t from, size_t len, size_t *retlen, u_char *read_buf) { struct aspeed_smc_per_chip *chip = nor->priv; +int ret; + +mutex_lock (&chip->controller->mutex); + +/* +* Try DMA transfer when size and alignment are correct. In case +* of failure, just restart using the IO mode. +*/ +if (!(from &0x3 ) && !(len &0x3 ) && (len >= min_dma_size) && + chip->controller->has_dma && use_dma) { + 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);aspeed_smc_from_fifo (read_buf, chip->base, len); - *retlen += len;aspeed_smc_stop_user (nor); +out: +mutex_unlock (&chip->controller->mutex); + *retlen += len;return 0 ; }
@@ -376,12 +534,30 @@ static void aspeed_smc_write_user(struct spi_nor *nor, loff_t to, size_t len, size_t *retlen, const u_char *write_buf) { struct aspeed_smc_per_chip *chip = nor->priv; +int ret; + +mutex_lock (&chip->controller->mutex); + +/* +* Try DMA transfer when size and alignment are correct. In case +* of failure, just restart using the IO mode. +*/ +if (!(to &0x3 ) && !(len &0x3 ) && (len >= min_dma_size) && + chip->controller->has_dma && use_dma) { + ret =aspeed_smc_dma_start (chip, to, (void *)write_buf, + len,1 ); +if (!ret) + goto out; +dev_err (chip->nor.dev,"DMA write failed: %d" , ret); + }aspeed_smc_start_user (nor);aspeed_smc_send_cmd_addr (nor, nor->program_opcode, to);aspeed_smc_to_fifo (chip->base, write_buf, len); - *retlen += len;aspeed_smc_stop_user (nor); +out: +mutex_unlock (&chip->controller->mutex); + *retlen += len; }static int aspeed_smc_remove (struct platform_device *dev)
@@ -438,6 +614,57 @@ static void __iomem *window_start(struct aspeed_smc_controller *controller,return controller->windows + offset; } +static irqreturn_t aspeed_smc_irq (int irq,void *arg) +{ +struct aspeed_smc_controller *controller = arg; +struct device *dev = controller->dev; +irqreturn_t ret =IRQ_NONE ; +u32 dma_ctl =readl (controller->regs +DMA_CONTROL_REG ); +u32 status =readl (controller->regs +INTERRUPT_STATUS_REG ); + +dev_dbg (dev,"received IRQ. status: %x" , status); + +if (!(status &INTERRUPT_DMA_ENABLE ) || !(dma_ctl &DMA_ENABLE )) { +dev_err (dev,"No DMA. bad IRQ status: %x" , status); + goto out; + } + +if (!(status &INTERRUPT_DMA_STATUS )) { +dev_err (dev,"DMA still in progress. length %d\n" , +readl (controller->regs +DMA_LENGTH_REG )); + goto out; + } + + ret =IRQ_HANDLED ; +aspeed_smc_dma_done (controller); +complete (&controller->dma_done); + +out: +return ret; +} + +static int aspeed_smc_config_irq (struct aspeed_smc_controller *controller, +struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +int rc; + + controller->irq =platform_get_irq (pdev,0 ); +if (!controller->irq) +return -ENODEV ; + + rc =devm_request_irq (dev, controller->irq, aspeed_smc_irq,IRQF_SHARED , +DEVICE_NAME , controller); +if (rc <0 ) { +dev_warn (dev,"Unable to request IRQ %d\n" , controller->irq); + controller->irq =0 ; +return rc; + } + +dev_info (dev,"Using IRQ %d\n" , controller->irq); +return 0 ; +} +static int aspeed_smc_probe (struct platform_device *pdev) {struct aspeed_smc_controller *controller;
@@ -473,6 +700,18 @@ static int aspeed_smc_probe(struct platform_device *pdev) controller->dev = &pdev->dev; +init_completion (&controller->dma_done); + + controller->has_dma = false; +if (info->hasdma) + controller->has_dma = !aspeed_smc_config_irq (controller, pdev); + +if (controller->has_dma) +dev_info (controller->dev,"DMA support %sactivated.\n" , + use_dma ?"" :"de" ); +else +dev_info (controller->dev,"no DMA support.\n" ); +/* The pinmux or bootloader will disable legacy mode. */ /*
@@ -530,6 +769,7 @@ static int aspeed_smc_probe(struct platform_device *pdev)continue ; } + chip->phys_base = r->start;/* * Always turn on the write enable bit in the type and settings * or flash configuration register to allow opcodes to be sent
@@ -621,7 +861,7 @@ static struct platform_driver aspeed_smc_driver = { .probe = aspeed_smc_probe, .remove = aspeed_smc_remove, .driver = { - .name = KBUILD_MODNAME, + .name = DEVICE_NAME, .of_match_table = aspeed_smc_matches, } };
Signature · 1 line
2.7.4
PATCH 10/12 ARM: dts: aspeed: update SMC controller nodes supporting DMAs
In reply to Cédric Le Goater--- Documentation/devicetree/bindings/mtd/aspeed-smc.txt | 4 +++- arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts | 2 ++ arch/arm/boot/dts/aspeed-g5.dtsi | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/mtd/aspeed-smc.txt +3 -1
@@ -17,11 +17,13 @@ Required properties: "aspeed,ast2500-smc" for the AST2500 SPI Flash Controllers - reg : the first contains the control register location and length, the second contains the memory window mapping address and length - - interrupts : Should contain the interrupt for the dma device if an fmc - clocks : The APB clock input to the controller - #address-cells : must be 1 corresponding to chip select child binding - #size-cells : must be 0 corresponding to chip select child binding +Optional properties: + - aspeed,fmc-has-dma : controller supports DMA transfers + - interrupts : Should contain the interrupt for the dma device if an fmc Child node required properties: - reg : must contain chip select number in first cell of address, must
arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts +2 -0
@@ -43,6 +43,8 @@ #address-cells = <1>; #size-cells = <0>; compatible = "aspeed,ast2400-fmc"; + aspeed,fmc-has-dma; + interrupts = <19>; flash@0 { reg = < 0 >; compatible = "jedec,spi-nor" ;
arch/arm/boot/dts/aspeed-g5.dtsi +2 -0
@@ -31,6 +31,8 @@ #size-cells = <0>; compatible = "aspeed,ast2500-fmc"; status = "disabled"; + aspeed,fmc-has-dma; + interrupts = <19>; flash@0 { reg = < 0 >; compatible = "jedec,spi-nor";
Signature · 1 line
2.7.4
PATCH 12/12 mtd: spi-nor: aspeed: use fast read when doing DMAs
In reply to Cédric Le GoaterTry to improve the speed of transfers when doing DMAs
--- drivers/mtd/spi-nor/aspeed-smc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/mtd/spi-nor/aspeed-smc.c +7 -4
@@ -211,6 +211,7 @@ enum smc_ctl_reg_value { smc_base,/* base value without mode for other commands */ smc_read,/* command reg for (maybe fast) reads */ smc_write,/* command reg for writes with timings */ + smc_fread,/* command reg for (maybe faster?) reads */ smc_num_ctl_reg_values /* last value to get count of commands */ };
@@ -347,9 +348,6 @@ static inline void aspeed_smc_chip_configure(struct aspeed_smc_per_chip *chip,writel (ctl, chip->ctl); } -/* -* TODO: configure FREAD mode -*/ static int aspeed_smc_dma_start (struct aspeed_smc_per_chip *chip,u32 offset,void *buf,size_t length,int is_write)
@@ -359,7 +357,7 @@ static int aspeed_smc_dma_start(struct aspeed_smc_per_chip *chip,int ret;aspeed_smc_chip_configure (chip, is_write ? chip->ctl_val[smc_write] : - chip->ctl_val[smc_base]); + chip->ctl_val[smc_fread]);dev_dbg (chip->nor.dev,"DMA %s to=0x%08x len=0x%08x\n" , is_write ?"write" :"read" , offset, length);
@@ -823,6 +821,11 @@ static int aspeed_smc_probe(struct platform_device *pdev)if (err)continue ; + chip->ctl_val[smc_fread] = chip->ctl_val[smc_base] | +/* Not sure this is that fast */ +spi_control_fill_opcode (SPINOR_OP_READ_FAST ) | +CONTROL_SPI_COMMAND_MODE_FREAD ; + chip->ctl_val[smc_write] = chip->ctl_val[smc_base] |spi_control_fill_opcode (chip->nor.program_opcode) |CONTROL_SPI_COMMAND_MODE_WRITE ;
Signature · 1 line
2.7.4
PATCH 3/12 mtd: spi-nor: Add Micronix mx66l1g45g spi flash
In reply to Cédric Le GoaterFrom: Milton Miller <[email protected]>
These modules are used on the OpenPOWER Witherspoon systems to hold the POWER9 host firmware image.
--- drivers/mtd/spi-nor/spi-nor.c | 1 + 1 file changed, 1 insertion(+)
drivers/mtd/spi-nor/spi-nor.c +1 -0
@@ -858,6 +858,7 @@ static const struct flash_info spi_nor_ids[] = { { "mx25l25635e", INFO(0xc22019, 0, 64 * 1024, 512, 0) }, { "mx25l25655e", INFO(0xc22619, 0, 64 * 1024, 512, 0) }, { "mx66l51235l", INFO(0xc2201a, 0, 64 * 1024, 1024, SPI_NOR_QUAD_READ) }, + { "mx66l1g45g", INFO(0xc2201b, 0, 64 * 1024, 2048, SECT_4K | SPI_NOR_QUAD_READ) }, { "mx66l1g55g", INFO(0xc2261b, 0, 64 * 1024, 2048, SPI_NOR_QUAD_READ) }, /* Micron */
Signature · 1 line
2.7.4
PATCH 11/12 mtd: spi-nor: aspeed: use property "aspeed, fmc-has-dma"
In reply to Cédric Le Goater--- drivers/mtd/spi-nor/aspeed-smc.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/mtd/spi-nor/aspeed-smc.c +2 -6
@@ -156,7 +156,6 @@ struct aspeed_smc_info {u32 maxsize;/* maximum size of 1 chip window */ u8 nce;/* number of chip enables */ u8 maxwidth;/* max width of spi bus */ -bool hasdma;/* has dma engine */ bool hastype;/* flash type field exists in cfg reg */ u8 we0;/* shift for write enable bit for ce 0 */ u8 ctl0;/* offset in regs of ctl for ce 0 */
@@ -168,7 +167,6 @@ static struct aspeed_smc_info fmc_2400_info = { .maxsize = 64 * 1024 * 1024, .nce = 5, .maxwidth = 4, - .hasdma = true, .hastype = true, .we0 = 16, .ctl0 = 0x10,
@@ -180,7 +178,6 @@ static struct aspeed_smc_info smc_2400_info = { .maxsize = 64 * 1024 * 1024, .nce = 1, .maxwidth = 2, - .hasdma = false, .hastype = false, .we0 = 0, .ctl0 = 0x04,
@@ -192,7 +189,6 @@ static struct aspeed_smc_info fmc_2500_info = { .maxsize = 256 * 1024 * 1024, .nce = 3, .maxwidth = 2, - .hasdma = true, .hastype = true, .we0 = 16, .ctl0 = 0x10,
@@ -204,7 +200,6 @@ static struct aspeed_smc_info smc_2500_info = { .maxsize = 128 * 1024 * 1024, .nce = 2, .maxwidth = 2, - .hasdma = false, .hastype = false, .we0 = 16, .ctl0 = 0x10,
@@ -703,7 +698,8 @@ static int aspeed_smc_probe(struct platform_device *pdev)init_completion (&controller->dma_done); controller->has_dma = false; -if (info->hasdma) +if (of_get_property (controller->dev->of_node,"aspeed,fmc-has-dma" , +NULL )) controller->has_dma = !aspeed_smc_config_irq (controller, pdev);if (controller->has_dma)
Signature · 1 line
2.7.4
PATCH 1/12 mtd: spi-nor: support for Aspeed AST2500 SoC
In reply to Cédric Le GoaterFrom: Milton Miller <[email protected]>
The SMC controllers on the Aspeed AST2500 SoC are very similar to the ones found on the AST2400. The differences are on the number of supported flash modules and their default mappings in the SoC address space.
The Aspeed AST2500 has one SPI controller for the BMC firmware and two for the host firmware. All controllers have now the same set of registers compatible with the AST2400 FMC controller and the legacy 'SMC' controller is fully gone.
--- .../devicetree/bindings/mtd/aspeed-smc.txt | 30 ++++-- drivers/mtd/spi-nor/aspeed-smc.c | 112 ++++++++++++--------- 2 files changed, 87 insertions(+), 55 deletions(-)
Documentation/devicetree/bindings/mtd/aspeed-smc.txt +20 -10
@@ -1,15 +1,23 @@ -* Aspeed Static Memory controller in SPI mode +* Aspeed Static Memory controller * Aspeed SPI Flash Controller +The Static memory controller in the ast2400 supports 5 chip selects each +can be attached to NAND, parallel NOR, or SPI NOR attached flash. The +Firmware Memory Controller in the ast2500 supports 3 chip selects, two of +which are always in SPI-NOR mode and the third can be SPI-NOR or parallel +flash. The SPI flash controller in the ast2400 supports one of 2 chip +selects selected by pinmux. The two SPI flash controllers in the ast2500 +each support two chip selects. + Required properties: - compatible : Should be one of "aspeed,ast2400-fmc" for the AST2400 Static Memory Controller - "aspeed,ast2500-fmc" for the AST2500 Static Memory Controller - "aspeed,ast2400-smc" for the AST2400 SPI flash controller - - reg : the first contains the register location and length, - the second through nth contains the memory mapping address and length - for the access window for each chips select - - interrupts : Should contain the interrupt for the dma device if fmc + "aspeed,ast2400-smc" for the AST2400 SPI Flash Controller + "aspeed,ast2500-fmc" for the AST2500 Firmware SPI Memory Controller + "aspeed,ast2500-smc" for the AST2500 SPI Flash Controllers + - reg : the first contains the control register location and length, + the second contains the memory window mapping address and length + - interrupts : Should contain the interrupt for the dma device if an fmc - clocks : The APB clock input to the controller - #address-cells : must be 1 corresponding to chip select child binding - #size-cells : must be 0 corresponding to chip select child binding
@@ -19,11 +27,13 @@ Child node required properties: - reg : must contain chip select number in first cell of address, must be 1 tuple long - compatible : may contain "vendor,part", must include "jedec,spi-nor" - (see spi-nor.txt binding). + when attached to SPI flash (see spi-nor.txt binding). Child node optional properties: - label - (optional) name to assign to mtd, default os assigned - - spi-max-frequency - (optional) max frequency of spi bus (XXX max if missing) + +Child node optional properties for SPI mode (may be ignored): + - spi-max-frequency - (optional) max frequency of spi bus - spi-cpol - (optional) Empty property indicating device requires inverse clock polarity (CPOL) mode (boolean) - spi-cpha - (optional) Empty property indicating device requires
@@ -33,7 +43,7 @@ Child node optional properties: - spi-rx-bus-width - (optional) The bus width(number of data wires) that used for MOSI. Defaults to 1 if not present. -Child node optional properties: +Grandchild node optional properties: - see mtd/partiton.txt for partitioning bindings and mtd naming
drivers/mtd/spi-nor/aspeed-smc.c +67 -45
268 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 7/12 mtd: spi-nor: aspeed: make locking more explicit
In reply to Cédric Le GoaterThe routine aspeed_smc_stop_user() and aspeed_smc_start_user() hide the fact that they lock an unlock the controller. Change that to make it obvious in the code.
--- drivers/mtd/spi-nor/aspeed-smc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/mtd/spi-nor/aspeed-smc.c +8 -4
@@ -276,8 +276,6 @@ static void aspeed_smc_start_user(struct spi_nor *nor)struct aspeed_smc_per_chip *chip = nor->priv;u32 ctl = chip->ctl_val[smc_base]; -mutex_lock (&chip->controller->mutex); - ctl |=CONTROL_SPI_COMMAND_MODE_USER |CONTROL_SPI_CE_STOP_ACTIVE_CONTROL ;writel (ctl, chip->ctl);
@@ -296,19 +294,21 @@ static void aspeed_smc_stop_user(struct spi_nor *nor)writel (ctl2, chip->ctl);/* stop user CE control */ writel (ctl, chip->ctl);/* default to fread or read */ - -mutex_unlock (&chip->controller->mutex); }static int aspeed_smc_read_reg (struct spi_nor *nor,u8 opcode,u8 *buf,int len) {struct aspeed_smc_per_chip *chip = nor->priv; +mutex_lock (&chip->controller->mutex); +aspeed_smc_start_user (nor);aspeed_smc_to_fifo (chip->base, &opcode,1 );aspeed_smc_from_fifo (buf, chip->base, len);aspeed_smc_stop_user (nor); +mutex_unlock (&chip->controller->mutex); +return 0 ; }
@@ -317,11 +317,15 @@ static int aspeed_smc_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, {struct aspeed_smc_per_chip *chip = nor->priv; +mutex_lock (&chip->controller->mutex); +aspeed_smc_start_user (nor);aspeed_smc_to_fifo (chip->base, &opcode,1 );aspeed_smc_to_fifo (chip->base, buf, len);aspeed_smc_stop_user (nor); +mutex_unlock (&chip->controller->mutex); +return 0 ; }
Signature · 1 line
2.7.4
PATCH 2/12 mtd: spi-nor: aspeed: Manage the segment address registers
In reply to Cédric Le GoaterFrom: Milton Miller <[email protected]>
This changes the aspeed mtd driver to use the segment address registers from the driver, this eliminating a source of mismatch and placing the kernel in control using its knowledge instead of relying on hardware defaults or bootloaders to choose good values for the windows based on the attached chips.
The initial commit factors out discovering the current window in which the flash module is mapped by the controller. The intent is to adjust the windows to the required size of the attached flash. Also planned is to enable direct memory mapped access and dma access, at least for read accesses when the flash size is supported by the hardware.
The spi-nor layer already trusts its database of jedec ids over any information in the device tree, this continues that philosophy by using the knowledge to optimize the programming of the hardware. The device tree may be used in the future to limit the choices, for example specifying a max clock rate based on board wiring.
This does not have any locking around sanitizing the segments or copying the new addresses back to the per-chip base address. In the present code registers are updated before the devices are probed.
We may want to cache the offsets in the per-chip structure to when we support DMA.
[clg : removed the calculation on the segment registers to check
overlaps and kept only the reading of the segment base address. It needs more work ]
--- drivers/mtd/spi-nor/aspeed-smc.c | 58 +++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 12 deletions(-)
drivers/mtd/spi-nor/aspeed-smc.c +46 -12
@@ -136,6 +136,7 @@ enum smc_flash_type { };struct aspeed_smc_info { +u32 maxsize;/* maximum size of 1 chip window */ u8 nce;/* number of chip enables */ u8 maxwidth;/* max width of spi bus */ bool hasdma;/* has dma engine */
@@ -147,6 +148,7 @@ struct aspeed_smc_info { };static struct aspeed_smc_info fmc_2400_info = { + .maxsize =64 *1024 *1024 , .nce =5 , .maxwidth =4 , .hasdma = true,
@@ -158,6 +160,7 @@ static struct aspeed_smc_info fmc_2400_info = { };static struct aspeed_smc_info smc_2400_info = { + .maxsize =64 *1024 *1024 , .nce =1 , .maxwidth =2 , .hasdma = false,
@@ -169,6 +172,7 @@ static struct aspeed_smc_info smc_2400_info = { };static struct aspeed_smc_info fmc_2500_info = { + .maxsize =256 *1024 *1024 , .nce =3 , .maxwidth =2 , .hasdma = true,
@@ -180,6 +184,7 @@ static struct aspeed_smc_info fmc_2500_info = { };static struct aspeed_smc_info smc_2500_info = { + .maxsize =128 *1024 *1024 , .nce =2 , .maxwidth =2 , .hasdma = false,
@@ -212,11 +217,17 @@ struct aspeed_smc_controller {struct mutex mutex;/* controller access mutex */ const struct aspeed_smc_info *info;/* type info of controller */ void __iomem *regs;/* controller registers */ +void __iomem *windows;/* per-chip windows resource */ struct aspeed_smc_per_chip *chips[0 ];/* pointers to attached chips */ };#define TYPE_SETTING_REG 0x0 +#define LOG_8MB (23)/* log(2)(8 * 1024 * 1024) */ +#define SEGMENT_ADDR_REG0 0x30 +#define SEGMENT_ADDR_START (_r) ((((_r) >> 16) & 0xFF) << LOG_8MB) +#define SEGMENT_ADDR_END (_r) ((((_r) >> 24) & 0xFF) << LOG_8MB) +#define CONTROL_SPI_AAF_MODE BIT(31)#define CONTROL_SPI_IO_MODE_MASK GENMASK(30, 28)#define CONTROL_SPI_IO_DUAL_DATA BIT(29)
@@ -403,13 +414,30 @@ of_platform_device_create_or_find(struct device_node *child,return cdev; } +static void __iomem *window_start (struct aspeed_smc_controller *controller, +struct resource *r,unsigned int n) +{ +u32 offset =0 ; +u32 reg; + +if (controller->info->nce >1 ) { + reg =readl (controller->regs +SEGMENT_ADDR_REG0 + n *4 ); + +if (SEGMENT_ADDR_START (reg) >=SEGMENT_ADDR_END (reg)) +return NULL ; + + offset =SEGMENT_ADDR_START (reg) - r->start; + } + +return controller->windows + offset; +} +static int aspeed_smc_probe (struct platform_device *dev) {struct aspeed_smc_controller *controller;const struct of_device_id *match;const struct aspeed_smc_info *info;struct resource *r; -void __iomem *regs;struct device_node *child;int err =0 ;unsigned int n;
@@ -418,19 +446,24 @@ static int aspeed_smc_probe(struct platform_device *dev)if (!match || !match->data)return -ENODEV ; info = match->data; - r =platform_get_resource (dev,IORESOURCE_MEM ,0 ); - regs =devm_ioremap_resource (&dev->dev, r); -if (IS_ERR (regs)) -return PTR_ERR (regs); controller =devm_kzalloc (&dev->dev,sizeof (*controller) + info->nce *sizeof (controller->chips[0 ]),GFP_KERNEL );if (!controller)return -ENOMEM ; -platform_set_drvdata (dev, controller); - controller->regs = regs; controller->info = info;mutex_init (&controller->mutex); +platform_set_drvdata (dev, controller); + + r =platform_get_resource (dev,IORESOURCE_MEM ,0 ); + controller->regs =devm_ioremap_resource (&dev->dev, r); +if (IS_ERR (controller->regs)) +return PTR_ERR (controller->regs); + + r =platform_get_resource (dev,IORESOURCE_MEM ,1 ); + controller->windows =devm_ioremap_resource (&dev->dev, r); +if (IS_ERR (controller->windows)) +return PTR_ERR (controller->windows);/* The pinmux or bootloader will disable legacy mode. */
@@ -476,17 +509,18 @@ static int aspeed_smc_probe(struct platform_device *dev)if (!chip)continue ; - r =platform_get_resource (dev,IORESOURCE_MEM , n +1 ); - chip->base =devm_ioremap_resource (&dev->dev, r); -if (!chip->base) -continue ; - chip->controller = controller; chip->ctl = controller->regs + info->ctl0 + n *4 ;/* The device tree said the chip is spi. */ chip->type = smc_type_spi; + chip->base =window_start (controller, r, n); +if (!chip->base) { +dev_warn (&cdev->dev,"CE segment window closed.\n" ); +continue ; + } +/* * Always turn on the write enable bit in the type and settings * or flash configuration register to allow opcodes to be sent
Signature · 1 line
2.7.4
Joel Stanley
maintainerRe: [PATCH linux dev-4.7 01/12] mtd: spi-nor: support for Aspeed AST2500 SoC
In reply to Cédric Le GoaterQuoted 1 line · Cédric Le Goater
From: Milton Miller <[email protected]>
I realise that Milton wrote this, but as it's the first time I've had a chance to review it I'll comment as though you are the author.
Quoted 5 lines
The SMC controllers on the Aspeed AST2500 SoC are very similar to the ones found on the AST2400. The differences are on the number of supported flash modules and their default mappings in the SoC address space.
Quoted 7 lines
The Aspeed AST2500 has one SPI controller for the BMC firmware and two for the host firmware. All controllers have now the same set of registers compatible with the AST2400 FMC controller and the legacy 'SMC' controller is fully gone.
Signed-off-by Milton Miller <[email protected]>[clg: couple of cleanups ]
You could probably have done these cleanups as a few different patches to make it easier to review. Not a big deal though. When we upstream this will all squash down. I've a few questions below, but nothing that will stop this going in the tree for now.
Quoted 11 lines
Signed-off-by Cédric Le Goater <[email protected]>--- .../devicetree/bindings/mtd/aspeed-smc.txt | 30 ++++-- drivers/mtd/spi-nor/aspeed-smc.c | 112 ++++++++++++--------- 2 files changed, 87 insertions(+), 55 deletions(-)drivers/mtd/spi-nor/aspeed-smc.c +0
-0@@ -140,37 +140,56 @@ struct aspeed_smc_info {u8 maxwidth;/* max width of spi bus */ bool hasdma;/* has dma engine */ bool hastype;/* flash type field exists in cfg reg */
drivers/mtd/spi-nor/aspeed-smc.c struct aspeed_smc_info { · line 149
Quoted 10 lines
drivers/mtd/spi-nor/aspeed-smc.c +2
-3-u8 we0;/* we shift for ce 0 in cfg reg */ +u8 we0;/* shift for write enable bit for ce 0 */ u8 ctl0;/* offset in regs of ctl for ce 0 */ -u8 cfg;/* offset in regs of cfg */ u8 time;/* offset in regs of timing */ u8 misc;/* offset in regs of misc settings */ }; -static struct aspeed_smc_info fmc_info = { +static struct aspeed_smc_info fmc_2400_info = {
Can these be const?
Quoted 52 lines
drivers/mtd/spi-nor/aspeed-smc.c +25
-5.nce = 5, .maxwidth = 4, .hasdma = true, .hastype = true, .we0 = 16, .ctl0 = 0x10, - .cfg = 0x00, - .time = 0x54, - .misc = 0x50, + .time = 0x94, + .misc = 0x54, }; -static struct aspeed_smc_info smc_info = { +static struct aspeed_smc_info smc_2400_info = { .nce =1 , .maxwidth =2 , .hasdma = false, .hastype = false, .we0 =0 , .ctl0 =0x04 , - .cfg =0x00 , .time =0x14 , .misc =0x10 , }; +static struct aspeed_smc_info fmc_2500_info = { + .nce =3 , + .maxwidth =2 , + .hasdma = true, + .hastype = true, + .we0 =16 , + .ctl0 =0x10 , + .time =0x94 , + .misc =0x54 , +}; + +static struct aspeed_smc_info smc_2500_info = { + .nce =2 , + .maxwidth =2 , + .hasdma = false, + .hastype = false, + .we0 =16 , + .ctl0 =0x10 , + .time =0x94 , + .misc =0x54 , +}; +enum smc_ctl_reg_value { smc_base,/* base value without mode for other commands */ smc_read,/* command reg for (maybe fast) reads */
drivers/mtd/spi-nor/aspeed-smc.c enum smc_ctl_reg_value { · line 202
Quoted 5 lines
drivers/mtd/spi-nor/aspeed-smc.c +1
-1@@ -180,7 +199,7 @@ enum smc_ctl_reg_value {struct aspeed_smc_controller ; -struct aspeed_smc_chip { +struct aspeed_smc_per_chip {
Can you explain the rename here? I don't follow.
Quoted 29 lines
drivers/mtd/spi-nor/aspeed-smc.c +3
-7struct aspeed_smc_controller *controller;__le32 __iomem *ctl;/* control register */ void __iomem *base;/* base of chip window */ @@ -193,9 +212,11 @@ struct aspeed_smc_controller {struct mutex mutex;/* controller access mutex */ const struct aspeed_smc_info *info;/* type info of controller */ void __iomem *regs;/* controller registers */ -struct aspeed_smc_chip *chips[0 ];/* pointers to attached chips */ +struct aspeed_smc_per_chip *chips[0 ];/* pointers to attached chips */ };@@ -456,36 +478,36 @@ static int aspeed_smc_probe(struct platform_device *dev) r =platform_get_resource (dev,IORESOURCE_MEM , n +1 ); chip->base =devm_ioremap_resource (&dev->dev, r); -if (!chip->base)continue ; + chip->controller = controller; chip->ctl = controller->regs + info->ctl0 + n *4 ; -/* -* The device tree said the chip is spi. -* XXX Need to set it in controller if has_type says the -* type is programmable. -*/ +/* The device tree said the chip is spi. */ chip->type = smc_type_spi;
drivers/mtd/spi-nor/aspeed-smc.c static int aspeed_smc_probe(struct platform_device *dev) · line 496
Quoted 10 lines
drivers/mtd/spi-nor/aspeed-smc.c +4
-2/* -* Always turn on the write enable bit in the config register -* to allow opcodes to be sent in user mode. +* Always turn on the write enable bit in the type and settings +* or flash configuration register to allow opcodes to be sent +* in user mode. Set the attached chip type for this chip +* select if the bits exist. */ mutex_lock (&controller->mutex);
Do we need to be taking locks in the drivers probe function?
drivers/mtd/spi-nor/aspeed-smc.c static int aspeed_smc_probe(struct platform_device *dev) · line 504
Quoted 11 lines
drivers/mtd/spi-nor/aspeed-smc.c +7
-3- reg =readl (controller->regs + info->cfg); -dev_dbg (&dev->dev,"flash config was %08x\n" , reg); + reg =readl (controller->regs +TYPE_SETTING_REG ); +dev_dbg (&dev->dev,"flash type and setting was %08x\n" , reg); reg |=1 << (info->we0 + n);/* WEn */ -writel (reg, controller->regs + info->cfg); +if (info->hastype) { + reg &= ~(3 << (n *2 )); + reg |= chip->type << (n *2 ); + } +writel (reg, controller->regs +TYPE_SETTING_REG );
This is a bit hard to follow. Worked it out in the end though.
Quoted 22 lines
drivers/mtd/spi-nor/aspeed-smc.c +1
-4mutex_unlock (&controller->mutex);/* * Read the existing control register to get basic values. * * XXX This register probably needs more sanitation. -* XXX Do we trust the bootloader or the device tree? -* spi-nor.c trusts jtag id over passed ids. * * Do we need support for mode 3 vs mode 0 clock phasing? */ @@ -531,7 +553,7 @@ static int aspeed_smc_probe(struct platform_device *dev)* Adjust clocks if fast read and write are supported. * Interpret spi-nor flags to adjust controller settings. * Check if resource size big enough for detected chip and -* add support assisted (normal or fast-) read. +* add support assisted (normal or fast-) read and dma. */ err =mtd_device_register (&chip->nor.mtd,NULL ,0 ); --2.7.4
Re: [PATCH linux dev-4.7 03/12] mtd: spi-nor: Add Micronix mx66l1g45g spi flash
In reply to Cédric Le GoaterQuoted 7 lines · Cédric Le Goater
From: Milton Miller <[email protected]>
These modules are used on the OpenPOWER Witherspoon systems to hold the POWER9 host firmware image.
Signed-off-by Milton Miller <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>
Quoted 3 lines
--- drivers/mtd/spi-nor/spi-nor.c | 1 + 1 file changed, 1 insertion(+)
Re: [PATCH linux dev-4.7 04/12] ARM: dts: aspeed-g5: update for new spi-nor binding
In reply to Cédric Le GoaterQuoted 4 lines · Cédric Le Goater
From: Milton Miller <[email protected]>
Signed-off-by Milton Miller <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>
Quoted 3 lines
--- arch/arm/boot/dts/aspeed-g5.dtsi | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+)
Re: [PATCH linux dev-4.7 05/12] ARM: dts: aspeed-g5: update witherspoon for new spi-nor binding
In reply to Cédric Le GoaterQuoted 7 lines · Cédric Le Goater
From: Milton Miller <[email protected]>
Witherspoon has two flash modules for the BMC firmware and one for the host.
Signed-off-by Milton Miller <[email protected]>Signed-off-by Cédric Le Goater <[email protected]>
Quoted 3 lines
--- arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 28 ++++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-)
Re: [PATCH linux dev-4.7 06/12] ARM: dts: aspeed-g5: update ast2500 evb with new spi-nor binding
In reply to Cédric Le GoaterQuoted 4 lines · Cédric Le Goater
The ast2500 evb has one flash module for the BMC firmware and one for the host.
Signed-off-by Cédric Le Goater <[email protected]>
Quoted 3 lines
--- arch/arm/boot/dts/aspeed-ast2500-evb.dts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
Re: [PATCH linux dev-4.7 08/12] mtd: spi-nor: aspeed: introduce a device under aspeed_smc_controller
In reply to Cédric Le GoaterQuoted 3 lines · Cédric Le Goater
This will be useful for readability and also logging.
Signed-off-by Cédric Le Goater <[email protected]>
Quoted 3 lines
--- drivers/mtd/spi-nor/aspeed-smc.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
Re: [PATCH linux dev-4.7 09/12] mtd: spi-nor: aspeed: add DMA support to smc controller
In reply to Cédric Le GoaterQuoted 6 lines · Cédric Le Goater
The Aspeed FMC controller can handle transfers to the flash modules using DMAs. A couple of registers first need to be programmed with the DRAM and flash addresses and the length of the transfer. The transfer is then initiated using a DMA control register and an interrupt notifies the completion.
Quoted 7 lines
Such transfers can replace the current IO mode in the read/write ops when some conditions are met on the size and the alignment. In case of failure, a timeout for instance, the operation is restarted using the IO mode.
DMA support does not seem to be that efficient. So we provide some sysfs files for tuning and to switch it on and off (default is off)
It looks like this version only has a module parameter, and not the sysfs files.
Quoted 2 lines
Signed-off-by Cédric Le Goater <[email protected]>
Quoted 15 lines
--- drivers/mtd/spi-nor/aspeed-smc.c | 246 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 243 insertions(+), 3 deletions(-)/*drivers/mtd/spi-nor/aspeed-smc.c +1
-0@@ -530,6 +769,7 @@ static int aspeed_smc_probe(struct platform_device *pdev)continue ; } + chip->phys_base = r->start;/* * Always turn on the write enable bit in the type and settings * or flash configuration register to allow opcodes to be sent
drivers/mtd/spi-nor/aspeed-smc.c static struct platform_driver aspeed_smc_driver = { · line 864
Quoted 5 lines
drivers/mtd/spi-nor/aspeed-smc.c +1
-1@@ -621,7 +861,7 @@ static struct platform_driver aspeed_smc_driver = { .probe = aspeed_smc_probe, .remove = aspeed_smc_remove, .driver = { - .name = KBUILD_MODNAME, + .name = DEVICE_NAME,
This should be in a different commit.
Quoted 6 lines
drivers/mtd/spi-nor/aspeed-smc.c +0
-1.of_match_table = aspeed_smc_matches, } }; --2.7.4
Re: [PATCH linux dev-4.7 10/12] ARM: dts: aspeed: update SMC controller nodes supporting DMAs
In reply to Cédric Le GoaterQuoted 1 line · Cédric Le Goater
Signed-off-by Cédric Le Goater <[email protected]>
Quoted 5 lines
--- Documentation/devicetree/bindings/mtd/aspeed-smc.txt | 4 +++- arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts | 2 ++ arch/arm/boot/dts/aspeed-g5.dtsi | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-)
Re: [PATCH linux dev-4.7 11/12] mtd: spi-nor: aspeed: use property "aspeed, fmc-has-dma"
In reply to Cédric Le GoaterQuoted 1 line · Cédric Le Goater
Signed-off-by Cédric Le Goater <[email protected]>
Quoted 3 lines
--- drivers/mtd/spi-nor/aspeed-smc.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
Re: [PATCH linux dev-4.7 12/12] mtd: spi-nor: aspeed: use fast read when doing DMAs
In reply to Cédric Le GoaterQuoted 1 line · Cédric Le Goater
Try to improve the speed of transfers when doing DMAs
This could get squashed into the DMA adding patch I think.
Quoted 2 lines
Signed-off-by Cédric Le Goater <[email protected]>
Quoted 3 lines
--- drivers/mtd/spi-nor/aspeed-smc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
Joel Stanley
maintainerRe: [PATCH linux dev-4.7 07/12] mtd: spi-nor: aspeed: make locking more explicit
In reply to Cédric Le GoaterQuoted 14 lines · Cédric Le Goater
The routine
aspeed_smc_stop_user()andaspeed_smc_start_user()hide the fact that they lock an unlock the controller. Change that to make it obvious in the code.Signed-off-by Cédric Le Goater <[email protected]>--- drivers/mtd/spi-nor/aspeed-smc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)drivers/mtd/spi-nor/aspeed-smc.c +0
-0
drivers/mtd/spi-nor/aspeed-smc.c static void aspeed_smc_start_user(struct spi_nor *nor) · line 280
Quoted 5 lines
drivers/mtd/spi-nor/aspeed-smc.c +0
-2@@ -276,8 +276,6 @@ static void aspeed_smc_start_user(struct spi_nor *nor)struct aspeed_smc_per_chip *chip = nor->priv;u32 ctl = chip->ctl_val[smc_base]; -mutex_lock (&chip->controller->mutex); -
This removes all locking from start_user and stop_user. There are some accesses and register writes in both of these functions, is that okay?
What is the lock (supposed to be) protecting?
(I note that you effectively add it back in patch 9 where you introduce DMA, by putting locks in aspeed_smc_read_user and write_user that then calls start_user.)
Quoted 46 lines
drivers/mtd/spi-nor/aspeed-smc.c +8
-3ctl |=CONTROL_SPI_COMMAND_MODE_USER |CONTROL_SPI_CE_STOP_ACTIVE_CONTROL ;writel (ctl, chip->ctl);@@ -296,19 +294,21 @@ static void aspeed_smc_stop_user(struct spi_nor *nor)writel (ctl2, chip->ctl);/* stop user CE control */ writel (ctl, chip->ctl);/* default to fread or read */ - -mutex_unlock (&chip->controller->mutex); }static int aspeed_smc_read_reg (struct spi_nor *nor,u8 opcode,u8 *buf,int len) {struct aspeed_smc_per_chip *chip = nor->priv; +mutex_lock (&chip->controller->mutex); +aspeed_smc_start_user (nor);aspeed_smc_to_fifo (chip->base, &opcode,1 );aspeed_smc_from_fifo (buf, chip->base, len);aspeed_smc_stop_user (nor); +mutex_unlock (&chip->controller->mutex); +return 0 ; }@@ -317,11 +317,15 @@ static int aspeed_smc_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, {struct aspeed_smc_per_chip *chip = nor->priv; +mutex_lock (&chip->controller->mutex); +aspeed_smc_start_user (nor);aspeed_smc_to_fifo (chip->base, &opcode,1 );aspeed_smc_to_fifo (chip->base, buf, len);aspeed_smc_stop_user (nor); +mutex_unlock (&chip->controller->mutex); +return 0 ; } --2.7.4
Joel Stanley
maintainerRe: [PATCH linux dev-4.7 02/12] mtd: spi-nor: aspeed: Manage the segment address registers
In reply to Cédric Le GoaterQuoted 42 lines · Cédric Le Goater
From: Milton Miller <[email protected]>
This changes the aspeed mtd driver to use the segment address registers from the driver, this eliminating a source of mismatch and placing the kernel in control using its knowledge instead of relying on hardware defaults or bootloaders to choose good values for the windows based on the attached chips.
The initial commit factors out discovering the current window in which the flash module is mapped by the controller. The intent is to adjust the windows to the required size of the attached flash. Also planned is to enable direct memory mapped access and dma access, at least for read accesses when the flash size is supported by the hardware.
The spi-nor layer already trusts its database of jedec ids over any information in the device tree, this continues that philosophy by using the knowledge to optimize the programming of the hardware. The device tree may be used in the future to limit the choices, for example specifying a max clock rate based on board wiring.
This does not have any locking around sanitizing the segments or copying the new addresses back to the per-chip base address. In the present code registers are updated before the devices are probed.
We may want to cache the offsets in the per-chip structure to when we support DMA.
Signed-off-by Milton Miller <[email protected]>[clg : removed the calculation on the segment registers to check
overlaps and kept only the reading of the segment base address. It needs more work ]Signed-off-by Cédric Le Goater <[email protected]>--- drivers/mtd/spi-nor/aspeed-smc.c | 58 +++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 12 deletions(-)drivers/mtd/spi-nor/aspeed-smc.c +0
-0
drivers/mtd/spi-nor/aspeed-smc.c enum smc_flash_type { · line 139
Quoted 4 lines
drivers/mtd/spi-nor/aspeed-smc.c +1
-0@@ -136,6 +136,7 @@ enum smc_flash_type { };struct aspeed_smc_info { +u32 maxsize;/* maximum size of 1 chip window */
It doesn't look like you use maxsize at all.
Quoted 143 lines
drivers/mtd/spi-nor/aspeed-smc.c +45
-13u8 nce;/* number of chip enables */ u8 maxwidth;/* max width of spi bus */ bool hasdma;/* has dma engine */ @@ -147,6 +148,7 @@ struct aspeed_smc_info { };static struct aspeed_smc_info fmc_2400_info = { + .maxsize =64 *1024 *1024 , .nce =5 , .maxwidth =4 , .hasdma = true,@@ -158,6 +160,7 @@ static struct aspeed_smc_info fmc_2400_info = { };static struct aspeed_smc_info smc_2400_info = { + .maxsize =64 *1024 *1024 , .nce =1 , .maxwidth =2 , .hasdma = false,@@ -169,6 +172,7 @@ static struct aspeed_smc_info smc_2400_info = { };static struct aspeed_smc_info fmc_2500_info = { + .maxsize =256 *1024 *1024 , .nce =3 , .maxwidth =2 , .hasdma = true,@@ -180,6 +184,7 @@ static struct aspeed_smc_info fmc_2500_info = { };static struct aspeed_smc_info smc_2500_info = { + .maxsize =128 *1024 *1024 , .nce =2 , .maxwidth =2 , .hasdma = false,@@ -212,11 +217,17 @@ struct aspeed_smc_controller {struct mutex mutex;/* controller access mutex */ const struct aspeed_smc_info *info;/* type info of controller */ void __iomem *regs;/* controller registers */ +void __iomem *windows;/* per-chip windows resource */ struct aspeed_smc_per_chip *chips[0 ];/* pointers to attached chips */ };#define TYPE_SETTING_REG 0x0 +#define LOG_8MB (23)/* log(2)(8 * 1024 * 1024) */ +#define SEGMENT_ADDR_REG0 0x30 +#define SEGMENT_ADDR_START (_r) ((((_r) >> 16) & 0xFF) << LOG_8MB) +#define SEGMENT_ADDR_END (_r) ((((_r) >> 24) & 0xFF) << LOG_8MB) +#define CONTROL_SPI_AAF_MODE BIT(31)#define CONTROL_SPI_IO_MODE_MASK GENMASK(30, 28)#define CONTROL_SPI_IO_DUAL_DATA BIT(29)@@ -403,13 +414,30 @@ of_platform_device_create_or_find(struct device_node *child,return cdev; } +static void __iomem *window_start (struct aspeed_smc_controller *controller, +struct resource *r,unsigned int n) +{ +u32 offset =0 ; +u32 reg; + +if (controller->info->nce >1 ) { + reg =readl (controller->regs +SEGMENT_ADDR_REG0 + n *4 ); + +if (SEGMENT_ADDR_START (reg) >=SEGMENT_ADDR_END (reg)) +return NULL ; + + offset =SEGMENT_ADDR_START (reg) - r->start; + } + +return controller->windows + offset; +} +static int aspeed_smc_probe (struct platform_device *dev) {struct aspeed_smc_controller *controller;const struct of_device_id *match;const struct aspeed_smc_info *info;struct resource *r; -void __iomem *regs;struct device_node *child;int err =0 ;unsigned int n;@@ -418,19 +446,24 @@ static int aspeed_smc_probe(struct platform_device *dev)if (!match || !match->data)return -ENODEV ; info = match->data; - r =platform_get_resource (dev,IORESOURCE_MEM ,0 ); - regs =devm_ioremap_resource (&dev->dev, r); -if (IS_ERR (regs)) -return PTR_ERR (regs); controller =devm_kzalloc (&dev->dev,sizeof (*controller) + info->nce *sizeof (controller->chips[0 ]),GFP_KERNEL );if (!controller)return -ENOMEM ; -platform_set_drvdata (dev, controller); - controller->regs = regs; controller->info = info;mutex_init (&controller->mutex); +platform_set_drvdata (dev, controller); + + r =platform_get_resource (dev,IORESOURCE_MEM ,0 ); + controller->regs =devm_ioremap_resource (&dev->dev, r); +if (IS_ERR (controller->regs)) +return PTR_ERR (controller->regs); + + r =platform_get_resource (dev,IORESOURCE_MEM ,1 ); + controller->windows =devm_ioremap_resource (&dev->dev, r); +if (IS_ERR (controller->windows)) +return PTR_ERR (controller->windows);/* The pinmux or bootloader will disable legacy mode. */ @@ -476,17 +509,18 @@ static int aspeed_smc_probe(struct platform_device *dev)if (!chip)continue ; - r =platform_get_resource (dev,IORESOURCE_MEM , n +1 ); - chip->base =devm_ioremap_resource (&dev->dev, r); -if (!chip->base) -continue ; - chip->controller = controller; chip->ctl = controller->regs + info->ctl0 + n *4 ;/* The device tree said the chip is spi. */ chip->type = smc_type_spi; + chip->base =window_start (controller, r, n); +if (!chip->base) { +dev_warn (&cdev->dev,"CE segment window closed.\n" ); +continue ; + } +/* * Always turn on the write enable bit in the type and settings * or flash configuration register to allow opcodes to be sent -- 2.7.4
Joel Stanley
maintainerQuoted 7 lines · Cédric Le Goater
Hello,
This patchset adds to the current aspeed SMC driver the register settings enabling support for the AST2500. Some initial work is done on the segment registers to provide a better configuration of the mapping windows on the flash modules but this area clearly needs more work to be solid.
Thanks for sending these out. I have a few comments that I'll give you a chance to respond to, but then we will apply this to dev-4.7 so teams who require flash support have it ready to go.
At that point, I suggest we send it upstream for comment in it's current state.
Cheers,
Joel
Quoted 36 lines
Also, a first version of DMA read/write is provided. But the speed results are not very satisfying so they are disabled by default. You
Thanks,
C.
Cédric Le Goater (7):
ARM: dts: aspeed-g5: update ast2500 evb with new spi-nor binding
mtd: spi-nor: aspeed: make locking more explicit
mtd: spi-nor: aspeed: introduce a device underaspeed_smc_controller
mtd: spi-nor: aspeed: add DMA support to smc controller
ARM: dts: aspeed: update SMC controller nodes supporting DMAs
mtd: spi-nor: aspeed: use property "aspeed,fmc-has-dma"
mtd: spi-nor: aspeed: use fast read when doing DMAsMilton Miller (5):
mtd: spi-nor: support for Aspeed AST2500 SoC
mtd: spi-nor: aspeed: Manage the segment address registers
mtd: spi-nor: Add Micronix mx66l1g45g spi flash
ARM: dts: aspeed-g5: update for new spi-nor binding
ARM: dts: aspeed-g5: update witherspoon for new spi-nor binding.../devicetree/bindings/mtd/aspeed-smc.txt | 32 +- arch/arm/boot/dts/aspeed-ast2500-evb.dts | 28 +- arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts | 2 + arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 28 +- arch/arm/boot/dts/aspeed-g5.dtsi | 65 +++ drivers/mtd/spi-nor/aspeed-smc.c | 449 +++++++++++++++++---- drivers/mtd/spi-nor/spi-nor.c | 1 + 7 files changed, 499 insertions(+), 106 deletions(-)--
2.7.4
Re: [PATCH linux dev-4.7 12/12] mtd: spi-nor: aspeed: use fast read when doing DMAs
In reply to Joel StanleyHello Joel,
Quoted 4 lines · Joel Stanley
Quoted 1 line · Cédric Le Goater
Try to improve the speed of transfers when doing DMAs
This could get squashed into the DMA adding patch I think.
If you haven't pushed yet, you can drop this one, it does not change anything in fact.
I am currently looking at introducing some timing support to speed up reading on the SPI, like pflash does and I am shuffling the code quite a lot to isolate the different settings.
Just to say they are more changes to come to cleanup the driver.
Thanks for the review,
C.
Quoted 9 lines
Quoted 3 lines
Signed-off-by Cédric Le Goater <[email protected]>Reviewed-by Joel Stanley <[email protected]>Quoted 3 lines
--- drivers/mtd/spi-nor/aspeed-smc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
Quoted 9 lines · Joel Stanley
Quoted 7 lines · Cédric Le Goater
Hello,
This patchset adds to the current aspeed SMC driver the register settings enabling support for the AST2500. Some initial work is done on the segment registers to provide a better configuration of the mapping windows on the flash modules but this area clearly needs more work to be solid.
Quoted 5 lines
Thanks for sending these out. I have a few comments that I'll give you a chance to respond to, but then we will apply this to dev-4.7 so teams who require flash support have it ready to go.
At that point, I suggest we send it upstream for comment in it's current state.
As a big one patch I suppose ?
I would like to cleanup the probe function first before. This is just code shuffling so I will send something soon making sure that the result passes checkpatch --strict at least.
Thanks,
C.
Quoted 40 lines
Cheers,
Joel
Quoted 36 lines
Also, a first version of DMA read/write is provided. But the speed results are not very satisfying so they are disabled by default. You
Thanks,
C.
Cédric Le Goater (7):
ARM: dts: aspeed-g5: update ast2500 evb with new spi-nor binding
mtd: spi-nor: aspeed: make locking more explicit
mtd: spi-nor: aspeed: introduce a device underaspeed_smc_controller
mtd: spi-nor: aspeed: add DMA support to smc controller
ARM: dts: aspeed: update SMC controller nodes supporting DMAs
mtd: spi-nor: aspeed: use property "aspeed,fmc-has-dma"
mtd: spi-nor: aspeed: use fast read when doing DMAsMilton Miller (5):
mtd: spi-nor: support for Aspeed AST2500 SoC
mtd: spi-nor: aspeed: Manage the segment address registers
mtd: spi-nor: Add Micronix mx66l1g45g spi flash
ARM: dts: aspeed-g5: update for new spi-nor binding
ARM: dts: aspeed-g5: update witherspoon for new spi-nor binding.../devicetree/bindings/mtd/aspeed-smc.txt | 32 +- arch/arm/boot/dts/aspeed-ast2500-evb.dts | 28 +- arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts | 2 + arch/arm/boot/dts/aspeed-bmc-opp-witherspoon.dts | 28 +- arch/arm/boot/dts/aspeed-g5.dtsi | 65 +++ drivers/mtd/spi-nor/aspeed-smc.c | 449 +++++++++++++++++---- drivers/mtd/spi-nor/spi-nor.c | 1 + 7 files changed, 499 insertions(+), 106 deletions(-)--
2.7.4
Re: [PATCH linux dev-4.7 01/12] mtd: spi-nor: support for Aspeed AST2500 SoC
In reply to Joel StanleyQuoted 43 lines · Joel Stanley
Quoted 1 line · Cédric Le Goater
From: Milton Miller <[email protected]>
I realise that Milton wrote this, but as it's the first time I've had a chance to review it I'll comment as though you are the author.
Quoted 5 lines
The SMC controllers on the Aspeed AST2500 SoC are very similar to the ones found on the AST2400. The differences are on the number of supported flash modules and their default mappings in the SoC address space.
Quoted 7 lines
The Aspeed AST2500 has one SPI controller for the BMC firmware and two for the host firmware. All controllers have now the same set of registers compatible with the AST2400 FMC controller and the legacy 'SMC' controller is fully gone.
Signed-off-by Milton Miller <[email protected]>[clg: couple of cleanups ]You could probably have done these cleanups as a few different patches to make it easier to review. Not a big deal though. When we upstream this will all squash down. I've a few questions below, but nothing that will stop this going in the tree for now.
Quoted 19 lines
Signed-off-by Cédric Le Goater <[email protected]>--- .../devicetree/bindings/mtd/aspeed-smc.txt | 30 ++++-- drivers/mtd/spi-nor/aspeed-smc.c | 112 ++++++++++++--------- 2 files changed, 87 insertions(+), 55 deletions(-)drivers/mtd/spi-nor/aspeed-smc.c +1
-2@@ -140,37 +140,56 @@ struct aspeed_smc_info {u8 maxwidth;/* max width of spi bus */ bool hasdma;/* has dma engine */ bool hastype;/* flash type field exists in cfg reg */ -u8 we0;/* we shift for ce 0 in cfg reg */ +u8 we0;/* shift for write enable bit for ce 0 */ u8 ctl0;/* offset in regs of ctl for ce 0 */ -u8 cfg;/* offset in regs of cfg */ u8 time;/* offset in regs of timing */ u8 misc;/* offset in regs of misc settings */ };
Quoted 4 lines
drivers/mtd/spi-nor/aspeed-smc.c struct aspeed_smc_info { · line 149
Quoted 2 lines
drivers/mtd/spi-nor/aspeed-smc.c +1
-1-static struct aspeed_smc_info fmc_info = { +static struct aspeed_smc_info fmc_2400_info = {Can these be const?
They should.
Quoted 54 lines
Quoted 54 lines
drivers/mtd/spi-nor/aspeed-smc.c +25
-5.nce = 5, .maxwidth = 4, .hasdma = true, .hastype = true, .we0 = 16, .ctl0 = 0x10, - .cfg = 0x00, - .time = 0x54, - .misc = 0x50, + .time = 0x94, + .misc = 0x54, }; -static struct aspeed_smc_info smc_info = { +static struct aspeed_smc_info smc_2400_info = { .nce =1 , .maxwidth =2 , .hasdma = false, .hastype = false, .we0 =0 , .ctl0 =0x04 , - .cfg =0x00 , .time =0x14 , .misc =0x10 , }; +static struct aspeed_smc_info fmc_2500_info = { + .nce =3 , + .maxwidth =2 , + .hasdma = true, + .hastype = true, + .we0 =16 , + .ctl0 =0x10 , + .time =0x94 , + .misc =0x54 , +}; + +static struct aspeed_smc_info smc_2500_info = { + .nce =2 , + .maxwidth =2 , + .hasdma = false, + .hastype = false, + .we0 =16 , + .ctl0 =0x10 , + .time =0x94 , + .misc =0x54 , +}; +enum smc_ctl_reg_value { smc_base,/* base value without mode for other commands */ smc_read,/* command reg for (maybe fast) reads */ @@ -180,7 +199,7 @@ enum smc_ctl_reg_value {
Quoted 6 lines
drivers/mtd/spi-nor/aspeed-smc.c enum smc_ctl_reg_value { · line 202
Quoted 4 lines
drivers/mtd/spi-nor/aspeed-smc.c +1
-1struct aspeed_smc_controller ; -struct aspeed_smc_chip { +struct aspeed_smc_per_chip {Can you explain the rename here? I don't follow.
I don't think it is useful. I will change that.
Quoted 31 lines
Quoted 31 lines
drivers/mtd/spi-nor/aspeed-smc.c +3
-7struct aspeed_smc_controller *controller;__le32 __iomem *ctl;/* control register */ void __iomem *base;/* base of chip window */ @@ -193,9 +212,11 @@ struct aspeed_smc_controller {struct mutex mutex;/* controller access mutex */ const struct aspeed_smc_info *info;/* type info of controller */ void __iomem *regs;/* controller registers */ -struct aspeed_smc_chip *chips[0 ];/* pointers to attached chips */ +struct aspeed_smc_per_chip *chips[0 ];/* pointers to attached chips */ };@@ -456,36 +478,36 @@ static int aspeed_smc_probe(struct platform_device *dev) r =platform_get_resource (dev,IORESOURCE_MEM , n +1 ); chip->base =devm_ioremap_resource (&dev->dev, r); -if (!chip->base)continue ; + chip->controller = controller; chip->ctl = controller->regs + info->ctl0 + n *4 ; -/* -* The device tree said the chip is spi. -* XXX Need to set it in controller if has_type says the -* type is programmable. -*/ +/* The device tree said the chip is spi. */ chip->type = smc_type_spi;
Quoted 11 lines
drivers/mtd/spi-nor/aspeed-smc.c static int aspeed_smc_probe(struct platform_device *dev) · line 496
Quoted 9 lines
drivers/mtd/spi-nor/aspeed-smc.c +4
-2/* -* Always turn on the write enable bit in the config register -* to allow opcodes to be sent in user mode. +* Always turn on the write enable bit in the type and settings +* or flash configuration register to allow opcodes to be sent +* in user mode. Set the attached chip type for this chip +* select if the bits exist. */ mutex_lock (&controller->mutex);Do we need to be taking locks in the drivers probe function?
nah.
Quoted 13 lines
drivers/mtd/spi-nor/aspeed-smc.c static int aspeed_smc_probe(struct platform_device *dev) · line 504
Quoted 12 lines
drivers/mtd/spi-nor/aspeed-smc.c +7
-3- reg =readl (controller->regs + info->cfg); -dev_dbg (&dev->dev,"flash config was %08x\n" , reg); + reg =readl (controller->regs +TYPE_SETTING_REG ); +dev_dbg (&dev->dev,"flash type and setting was %08x\n" , reg); reg |=1 << (info->we0 + n);/* WEn */ -writel (reg, controller->regs + info->cfg); +if (info->hastype) { + reg &= ~(3 << (n *2 )); + reg |= chip->type << (n *2 ); + } +writel (reg, controller->regs +TYPE_SETTING_REG );
Quoted 1 line
This is a bit hard to follow. Worked it out in the end though.
Yes. In a cleanup patch, I am introducing functions to differentiate the settings we are doing. Due to the extreme creativeness of the smc interface, it is really easy to fall into a trap and use the wrong register/bit ...
The AST2500 SPI flash controller misses a setting for instance. I need to send a fix for that.
C.
Quoted 23 lines
Quoted 23 lines
drivers/mtd/spi-nor/aspeed-smc.c +1
-4mutex_unlock (&controller->mutex);/* * Read the existing control register to get basic values. * * XXX This register probably needs more sanitation. -* XXX Do we trust the bootloader or the device tree? -* spi-nor.c trusts jtag id over passed ids. * * Do we need support for mode 3 vs mode 0 clock phasing? */ @@ -531,7 +553,7 @@ static int aspeed_smc_probe(struct platform_device *dev)* Adjust clocks if fast read and write are supported. * Interpret spi-nor flags to adjust controller settings. * Check if resource size big enough for detected chip and -* add support assisted (normal or fast-) read. +* add support assisted (normal or fast-) read and dma. */ err =mtd_device_register (&chip->nor.mtd,NULL ,0 ); --2.7.4
Re: [PATCH linux dev-4.7 02/12] mtd: spi-nor: aspeed: Manage the segment address registers
In reply to Joel StanleyQuoted 45 lines · Joel Stanley
Quoted 44 lines · Cédric Le Goater
From: Milton Miller <[email protected]>
This changes the aspeed mtd driver to use the segment address registers from the driver, this eliminating a source of mismatch and placing the kernel in control using its knowledge instead of relying on hardware defaults or bootloaders to choose good values for the windows based on the attached chips.
The initial commit factors out discovering the current window in which the flash module is mapped by the controller. The intent is to adjust the windows to the required size of the attached flash. Also planned is to enable direct memory mapped access and dma access, at least for read accesses when the flash size is supported by the hardware.
The spi-nor layer already trusts its database of jedec ids over any information in the device tree, this continues that philosophy by using the knowledge to optimize the programming of the hardware. The device tree may be used in the future to limit the choices, for example specifying a max clock rate based on board wiring.
This does not have any locking around sanitizing the segments or copying the new addresses back to the per-chip base address. In the present code registers are updated before the devices are probed.
We may want to cache the offsets in the per-chip structure to when we support DMA.
Signed-off-by Milton Miller <[email protected]>[clg : removed the calculation on the segment registers to check
overlaps and kept only the reading of the segment base address. It needs more work ]Signed-off-by Cédric Le Goater <[email protected]>--- drivers/mtd/spi-nor/aspeed-smc.c | 58 +++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 12 deletions(-)drivers/mtd/spi-nor/aspeed-smc.c +0
-0@@ -136,6 +136,7 @@ enum smc_flash_type { };
Quoted 4 lines
drivers/mtd/spi-nor/aspeed-smc.c enum smc_flash_type { · line 139
Quoted 2 lines
drivers/mtd/spi-nor/aspeed-smc.c +1
-0struct aspeed_smc_info { +u32 maxsize;/* maximum size of 1 chip window */ It doesn't look like you use maxsize at all.
Indeed. I removed its use in this patch but I will be useful for the overall check at the end. We could have a window size smaller than the sum of the size of the chip.
I am still uncertain how these flash windows work as I could read/write the 128MB chip on the witherspoon with a 8MB window ... So I don't want to do too much in this area.
C.
Quoted 145 lines
Quoted 145 lines
drivers/mtd/spi-nor/aspeed-smc.c +45
-13u8 nce;/* number of chip enables */ u8 maxwidth;/* max width of spi bus */ bool hasdma;/* has dma engine */ @@ -147,6 +148,7 @@ struct aspeed_smc_info { };static struct aspeed_smc_info fmc_2400_info = { + .maxsize =64 *1024 *1024 , .nce =5 , .maxwidth =4 , .hasdma = true,@@ -158,6 +160,7 @@ static struct aspeed_smc_info fmc_2400_info = { };static struct aspeed_smc_info smc_2400_info = { + .maxsize =64 *1024 *1024 , .nce =1 , .maxwidth =2 , .hasdma = false,@@ -169,6 +172,7 @@ static struct aspeed_smc_info smc_2400_info = { };static struct aspeed_smc_info fmc_2500_info = { + .maxsize =256 *1024 *1024 , .nce =3 , .maxwidth =2 , .hasdma = true,@@ -180,6 +184,7 @@ static struct aspeed_smc_info fmc_2500_info = { };static struct aspeed_smc_info smc_2500_info = { + .maxsize =128 *1024 *1024 , .nce =2 , .maxwidth =2 , .hasdma = false,@@ -212,11 +217,17 @@ struct aspeed_smc_controller {struct mutex mutex;/* controller access mutex */ const struct aspeed_smc_info *info;/* type info of controller */ void __iomem *regs;/* controller registers */ +void __iomem *windows;/* per-chip windows resource */ struct aspeed_smc_per_chip *chips[0 ];/* pointers to attached chips */ };#define TYPE_SETTING_REG 0x0 +#define LOG_8MB (23)/* log(2)(8 * 1024 * 1024) */ +#define SEGMENT_ADDR_REG0 0x30 +#define SEGMENT_ADDR_START (_r) ((((_r) >> 16) & 0xFF) << LOG_8MB) +#define SEGMENT_ADDR_END (_r) ((((_r) >> 24) & 0xFF) << LOG_8MB) +#define CONTROL_SPI_AAF_MODE BIT(31)#define CONTROL_SPI_IO_MODE_MASK GENMASK(30, 28)#define CONTROL_SPI_IO_DUAL_DATA BIT(29)@@ -403,13 +414,30 @@ of_platform_device_create_or_find(struct device_node *child,return cdev; } +static void __iomem *window_start (struct aspeed_smc_controller *controller, +struct resource *r,unsigned int n) +{ +u32 offset =0 ; +u32 reg; + +if (controller->info->nce >1 ) { + reg =readl (controller->regs +SEGMENT_ADDR_REG0 + n *4 ); + +if (SEGMENT_ADDR_START (reg) >=SEGMENT_ADDR_END (reg)) +return NULL ; + + offset =SEGMENT_ADDR_START (reg) - r->start; + } + +return controller->windows + offset; +} +static int aspeed_smc_probe (struct platform_device *dev) {struct aspeed_smc_controller *controller;const struct of_device_id *match;const struct aspeed_smc_info *info;struct resource *r; -void __iomem *regs;struct device_node *child;int err =0 ;unsigned int n;@@ -418,19 +446,24 @@ static int aspeed_smc_probe(struct platform_device *dev)if (!match || !match->data)return -ENODEV ; info = match->data; - r =platform_get_resource (dev,IORESOURCE_MEM ,0 ); - regs =devm_ioremap_resource (&dev->dev, r); -if (IS_ERR (regs)) -return PTR_ERR (regs); controller =devm_kzalloc (&dev->dev,sizeof (*controller) + info->nce *sizeof (controller->chips[0 ]),GFP_KERNEL );if (!controller)return -ENOMEM ; -platform_set_drvdata (dev, controller); - controller->regs = regs; controller->info = info;mutex_init (&controller->mutex); +platform_set_drvdata (dev, controller); + + r =platform_get_resource (dev,IORESOURCE_MEM ,0 ); + controller->regs =devm_ioremap_resource (&dev->dev, r); +if (IS_ERR (controller->regs)) +return PTR_ERR (controller->regs); + + r =platform_get_resource (dev,IORESOURCE_MEM ,1 ); + controller->windows =devm_ioremap_resource (&dev->dev, r); +if (IS_ERR (controller->windows)) +return PTR_ERR (controller->windows);/* The pinmux or bootloader will disable legacy mode. */ @@ -476,17 +509,18 @@ static int aspeed_smc_probe(struct platform_device *dev)if (!chip)continue ; - r =platform_get_resource (dev,IORESOURCE_MEM , n +1 ); - chip->base =devm_ioremap_resource (&dev->dev, r); -if (!chip->base) -continue ; - chip->controller = controller; chip->ctl = controller->regs + info->ctl0 + n *4 ;/* The device tree said the chip is spi. */ chip->type = smc_type_spi; + chip->base =window_start (controller, r, n); +if (!chip->base) { +dev_warn (&cdev->dev,"CE segment window closed.\n" ); +continue ; + } +/* * Always turn on the write enable bit in the type and settings * or flash configuration register to allow opcodes to be sent -- 2.7.4
Joel Stanley
maintainerRe: [PATCH linux dev-4.7 12/12] mtd: spi-nor: aspeed: use fast read when doing DMAs
In reply to Cédric Le GoaterQuoted 11 lines · Cédric Le Goater
Hello Joel,
Quoted 4 lines · Joel Stanley
Quoted 1 line · Cédric Le Goater
Try to improve the speed of transfers when doing DMAs
This could get squashed into the DMA adding patch I think.
If you haven't pushed yet, you can drop this one, it does not change anything in fact.
Quoted 6 lines
I am currently looking at introducing some timing support to speed up reading on the SPI, like pflash does and I am shuffling the code quite a lot to isolate the different settings.
Just to say they are more changes to come to cleanup the driver.
Okay, great.
I will hold off merging the patches for a little white. We will need to commit them some time this week though. If they are not the final version then that is okay.
Once you have something ready for upstream, we should cc Ben H (who as you know wrote pflash) for his thoughts. We need to do that this week as he won't have much time next week.
Cheers,
Joel
Re: [PATCH linux dev-4.7 07/12] mtd: spi-nor: aspeed: make locking more explicit
In reply to Joel StanleyQuoted 18 lines · Joel Stanley
Quoted 17 lines · Cédric Le Goater
The routine
aspeed_smc_stop_user()andaspeed_smc_start_user()hide the fact that they lock an unlock the controller. Change that to make it obvious in the code.Signed-off-by Cédric Le Goater <[email protected]>--- drivers/mtd/spi-nor/aspeed-smc.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)drivers/mtd/spi-nor/aspeed-smc.c +0
-0@@ -276,8 +276,6 @@ static void aspeed_smc_start_user(struct spi_nor *nor)struct aspeed_smc_per_chip *chip = nor->priv;u32 ctl = chip->ctl_val[smc_base];
Quoted 5 lines
drivers/mtd/spi-nor/aspeed-smc.c static void aspeed_smc_start_user(struct spi_nor *nor) · line 280
Quoted 2 lines
drivers/mtd/spi-nor/aspeed-smc.c +0
-2-mutex_lock (&chip->controller->mutex); -This removes all locking from
start_userandstop_user. There are some accesses and register writes in both of these functions, is that okay?
ah. Indeed, I did half of the job in this patch. Probably when I tried to split the changes :/
Currently, the driver only support User mode, in which the parameters of an operation on the chip are passed by writing to the address where the flash is mapped. So start_user() is always called to start a read or a write transaction, if it is to access a flash register or if it is to access its data.
It is completed by calling stop_user(). The flash then goes back to a Command mode where operations are driven differently.
The current flow is not correct from the spi-nor API perspective. I think we should be using the prepare() and unprepare() ops instead. I might give that a try before mainline. I am pretty sure it will be spotted.
Quoted 1 line
What is the lock (supposed to be) protecting?
read/write ops which change the controller configuration. The nor has its own locking so we might not need this lock if we use the prepare() and unprepare() ops.
Quoted 3 lines
(I note that you effectively add it back in patch 9 where you introduce DMA, by putting locks in
aspeed_smc_read_userandwrite_userthat then callsstart_user.)
I made one big patch with all the changes for mainline. We should be fine now.
Thanks,
C.
Quoted 47 lines
Quoted 47 lines
drivers/mtd/spi-nor/aspeed-smc.c +8
-3ctl |=CONTROL_SPI_COMMAND_MODE_USER |CONTROL_SPI_CE_STOP_ACTIVE_CONTROL ;writel (ctl, chip->ctl);@@ -296,19 +294,21 @@ static void aspeed_smc_stop_user(struct spi_nor *nor)writel (ctl2, chip->ctl);/* stop user CE control */ writel (ctl, chip->ctl);/* default to fread or read */ - -mutex_unlock (&chip->controller->mutex); }static int aspeed_smc_read_reg (struct spi_nor *nor,u8 opcode,u8 *buf,int len) {struct aspeed_smc_per_chip *chip = nor->priv; +mutex_lock (&chip->controller->mutex); +aspeed_smc_start_user (nor);aspeed_smc_to_fifo (chip->base, &opcode,1 );aspeed_smc_from_fifo (buf, chip->base, len);aspeed_smc_stop_user (nor); +mutex_unlock (&chip->controller->mutex); +return 0 ; }@@ -317,11 +317,15 @@ static int aspeed_smc_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, {struct aspeed_smc_per_chip *chip = nor->priv; +mutex_lock (&chip->controller->mutex); +aspeed_smc_start_user (nor);aspeed_smc_to_fifo (chip->base, &opcode,1 );aspeed_smc_to_fifo (chip->base, buf, len);aspeed_smc_stop_user (nor); +mutex_unlock (&chip->controller->mutex); +return 0 ; } --2.7.4
Re: [PATCH linux dev-4.7 09/12] mtd: spi-nor: aspeed: add DMA support to smc controller
In reply to Joel StanleyQuoted 12 lines · Joel Stanley
Quoted 11 lines · Cédric Le Goater
The Aspeed FMC controller can handle transfers to the flash modules using DMAs. A couple of registers first need to be programmed with the DRAM and flash addresses and the length of the transfer. The transfer is then initiated using a DMA control register and an interrupt notifies the completion.
Such transfers can replace the current IO mode in the read/write ops when some conditions are met on the size and the alignment. In case of failure, a timeout for instance, the operation is restarted using the IO mode.
Quoted 4 lines
Quoted 2 lines
DMA support does not seem to be that efficient. So we provide some sysfs files for tuning and to switch it on and off (default is off)
It looks like this version only has a module parameter, and not the sysfs files.
Ah ? I have these :
/sys/module/aspeed_smc/parameters/dma_timeout /sys/module/aspeed_smc/parameters/min_dma_size /sys/module/aspeed_smc/parameters/use_dma
which we can control with the kernel command line at boot :
"aspeed_smc.use_dma=1"
Is there an other API ?
Thanks,
C.
Re: [PATCH linux dev-4.7 12/12] mtd: spi-nor: aspeed: use fast read when doing DMAs
In reply to Joel StanleyQuoted 17 lines · Joel Stanley
Quoted 16 lines · Cédric Le Goater
Hello Joel,
Quoted 4 lines · Joel Stanley
Quoted 1 line · Cédric Le Goater
Try to improve the speed of transfers when doing DMAs
This could get squashed into the DMA adding patch I think.
If you haven't pushed yet, you can drop this one, it does not change anything in fact.
I am currently looking at introducing some timing support to speed up reading on the SPI, like pflash does and I am shuffling the code quite a lot to isolate the different settings.
Quoted 7 lines
Quoted 1 line
Just to say they are more changes to come to cleanup the driver.
Okay, great.
I will hold off merging the patches for a little white. We will need to commit them some time this week though. If they are not the final version then that is okay.
I am tired of the little fixes so I will make one big patch for the aspeed smc, AST2400 and AST2500, then a couple more for the dts, plus one for the dma (as I am not sure it is useful). I have another one pending for timing optimizations but that is too drafty for the moment.
Hopefully, I can make the patchset common with mainline with a first revert of what we have today in openbmc and some API fixes for 4.8.
Quoted 3 lines
Once you have something ready for upstream, we should cc Ben H (who as you know wrote pflash) for his thoughts. We need to do that this week as he won't have much time next week.
Sure. I have questions on the default settings. Some are strapped by hardware, like the Div 2, depending on the controller type, some are not but we would like that to work in all cases. I have started to maintain a static table per chip jedec for these in the driver. I am not sure of the approach, but first, let's get a clean common base to work with.
Thanks,
C.