x86: baytrail: Configure SPI BIOS parameters
PATCH 1/1 x86: baytrail: Configure SPI BIOS parameters
Without configuring these registers in the SPI controller, the Linux MTD device driver is not able to correctly read/write to the SPI NOR chip at all. In fact, the chip is not detected at all.
--- arch/x86/cpu/baytrail/cpu.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
arch/x86/cpu/baytrail/cpu.c +57 -0
@@ -16,6 +16,7 @@#include <asm/lapic.h> #include <asm/msr.h> #include <asm/turbo.h> +#include <asm/arch/iomap.h> #define BYT_PRV_CLK 0x800#define BYT_PRV_CLK_EN (1 << 0)
@@ -23,6 +24,44 @@#define BYT_PRV_CLK_N_VAL_SHIFT 16#define BYT_PRV_CLK_UPDATE (1 << 31) +/* SPI register offsets */ +#define OPTYPE 0x96 +#define OPMENU0 0x98 +#define OPMENU1 0x9c + +#define SPI_OPMENU_0 0x01/* WRSR: Write Status Register */ +#define SPI_OPTYPE_0 0x01/* Write, no address */ + +#define SPI_OPMENU_1 0x02/* BYPR: Byte Program */ +#define SPI_OPTYPE_1 0x03/* Write, address required */ + +#define SPI_OPMENU_2 0x03/* READ: Read Data */ +#define SPI_OPTYPE_2 0x02/* Read, address required */ + +#define SPI_OPMENU_3 0x05/* RDSR: Read Status Register */ +#define SPI_OPTYPE_3 0x00/* Read, no address */ + +#define SPI_OPMENU_4 0x20/* SE20: Sector Erase 0x20 */ +#define SPI_OPTYPE_4 0x03/* Write, address required */ + +#define SPI_OPMENU_5 0x9f/* RDID: Read ID */ +#define SPI_OPTYPE_5 0x00/* Read, no address */ + +#define SPI_OPMENU_6 0xd8/* BED8: Block Erase 0xd8 */ +#define SPI_OPTYPE_6 0x03/* Write, address required */ + +#define SPI_OPMENU_7 0x0b/* FAST: Fast Read */ +#define SPI_OPTYPE_7 0x02/* Read, address required */ + +#define SPI_OPTYPE ((SPI_OPTYPE_7 << 14) | (SPI_OPTYPE_6 << 12) | \ + (SPI_OPTYPE_5 << 10) | (SPI_OPTYPE_4 << 8) | \ + (SPI_OPTYPE_3 << 6) | (SPI_OPTYPE_2 << 4) | \ + (SPI_OPTYPE_1 << 2) | (SPI_OPTYPE_0 << 0)) +#define SPI_OPMENU_UPPER ((SPI_OPMENU_7 << 24) | (SPI_OPMENU_6 << 16) | \ + (SPI_OPMENU_5 << 8) | (SPI_OPMENU_4 << 0)) +#define SPI_OPMENU_LOWER ((SPI_OPMENU_3 << 24) | (SPI_OPMENU_2 << 16) | \ + (SPI_OPMENU_1 << 8) | (SPI_OPMENU_0 << 0)) +static void hsuart_clock_set (void *base) {u32 m, n, reg;
@@ -40,6 +79,17 @@ static void hsuart_clock_set(void *base) }/* +* Configure SPI controller so that the Linux MTD driver can fully +* access the SPI NOR chip +*/ +static void spi_controller_config (void *base) +{ +writew (SPI_OPTYPE , base +OPTYPE ); +writel (SPI_OPMENU_LOWER , base +OPMENU0 ); +writel (SPI_OPMENU_UPPER , base +OPMENU1 ); +} + +/* * Configure the internal clock of both SIO HS-UARTs, if they are enabled * via FSP */
@@ -60,6 +110,13 @@ int arch_cpu_init_dm(void) } } +/* +* Configure the SPI-NOR controller in a way that the Linux +* MTD SPI-NOR device driver has full read-write access to +* the SPI-NOR chips +*/ +spi_controller_config ((void *)SPI_BASE_ADDRESS ); +return 0 ; }
Signature · 1 line
2.11.0
PATCH 1/1 x86: baytrail: Configure SPI BIOS parameters
Hi Stefan,
Quoted 10 lines · Stefan Roese
Without configuring these registers in the SPI controller, the Linux MTD device driver is not able to correctly read/write to the SPI NOR chip at all. In fact, the chip is not detected at all.
Signed-off-by Stefan Roese <[email protected]>Cc Simon Glass <[email protected]>Cc Bin Meng <[email protected]>--- arch/x86/cpu/baytrail/cpu.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)
Can we do this in the SPI driver? It already has register definitions.
Regards,
Simon
PATCH 1/1 x86: baytrail: Configure SPI BIOS parameters
Hi Stefan,
Quoted 7 lines · Simon Glass
Hi Stefan,
Quoted 4 lines · Stefan Roese
Without configuring these registers in the SPI controller, the Linux MTD device driver is not able to correctly read/write to the SPI NOR chip at all. In fact, the chip is not detected at all.
Quoted 8 lines
Quoted 6 lines
Signed-off-by Stefan Roese <[email protected]>Cc Simon Glass <[email protected]>Cc Bin Meng <[email protected]>--- arch/x86/cpu/baytrail/cpu.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+)Can we do this in the SPI driver? It already has register definitions.
I would also do this in the SPI driver, unless it is not possible?
Regards,
Bin
PATCH v2 1/1 spi: ich: Configure SPI BIOS parameters
In reply to Stefan RoeseWithout configuring these registers in the SPI controller, the Linux MTD device driver is not able to correctly read/write to the SPI NOR chip at all. In fact, the chip is not detected at all.
---
v2:
- Moved code into the ICH SPI driver as suggested by Simon and Bin
drivers/spi/ich.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
drivers/spi/ich.c +51 -0
@@ -18,6 +18,39 @@#include "ich.h" +#define SPI_OPMENU_0 0x01/* WRSR: Write Status Register */ +#define SPI_OPTYPE_0 0x01/* Write, no address */ + +#define SPI_OPMENU_1 0x02/* BYPR: Byte Program */ +#define SPI_OPTYPE_1 0x03/* Write, address required */ + +#define SPI_OPMENU_2 0x03/* READ: Read Data */ +#define SPI_OPTYPE_2 0x02/* Read, address required */ + +#define SPI_OPMENU_3 0x05/* RDSR: Read Status Register */ +#define SPI_OPTYPE_3 0x00/* Read, no address */ + +#define SPI_OPMENU_4 0x20/* SE20: Sector Erase 0x20 */ +#define SPI_OPTYPE_4 0x03/* Write, address required */ + +#define SPI_OPMENU_5 0x9f/* RDID: Read ID */ +#define SPI_OPTYPE_5 0x00/* Read, no address */ + +#define SPI_OPMENU_6 0xd8/* BED8: Block Erase 0xd8 */ +#define SPI_OPTYPE_6 0x03/* Write, address required */ + +#define SPI_OPMENU_7 0x0b/* FAST: Fast Read */ +#define SPI_OPTYPE_7 0x02/* Read, address required */ + +#define SPI_OPTYPE ((SPI_OPTYPE_7 << 14) | (SPI_OPTYPE_6 << 12) | \ + (SPI_OPTYPE_5 << 10) | (SPI_OPTYPE_4 << 8) | \ + (SPI_OPTYPE_3 << 6) | (SPI_OPTYPE_2 << 4) | \ + (SPI_OPTYPE_1 << 2) | (SPI_OPTYPE_0 << 0)) +#define SPI_OPMENU_UPPER ((SPI_OPMENU_7 << 24) | (SPI_OPMENU_6 << 16) | \ + (SPI_OPMENU_5 << 8) | (SPI_OPMENU_4 << 0)) +#define SPI_OPMENU_LOWER ((SPI_OPMENU_3 << 24) | (SPI_OPMENU_2 << 16) | \ + (SPI_OPMENU_1 << 8) | (SPI_OPMENU_0 << 0)) +DECLARE_GLOBAL_DATA_PTR ;#ifdef DEBUG_TRACE
@@ -111,6 +144,17 @@ static int ich9_can_do_33mhz(struct udevice *dev)return speed ==1 ; } +/* +* Configure SPI controller so that the Linux MTD driver can fully +* access the SPI NOR chip +*/ +static void spi_controller_config (struct ich_spi_priv *ctlr) +{ +ich_writew (ctlr,SPI_OPTYPE , ctlr->optype); +ich_writel (ctlr,SPI_OPMENU_LOWER , ctlr->opmenu); +ich_writel (ctlr,SPI_OPMENU_UPPER , ctlr->opmenu +sizeof (u32)); +} +static int ich_init_controller (struct udevice *dev,struct ich_spi_platdata *plat,struct ich_spi_priv *ctlr)
@@ -172,6 +216,13 @@ static int ich_init_controller(struct udevice *dev,ich_set_bbar (ctlr,0 ); +/* +* Configure the SPI-NOR controller in a way that the Linux +* MTD SPI-NOR device driver has full read-write access to +* the SPI-NOR chips +*/ +spi_controller_config (ctlr); +return 0 ; }
Signature · 1 line
2.11.0
PATCH v2 1/1 spi: ich: Configure SPI BIOS parameters
Hi Stefan,
Quoted 37 lines · Stefan Roese
Without configuring these registers in the SPI controller, the Linux MTD device driver is not able to correctly read/write to the SPI NOR chip at all. In fact, the chip is not detected at all.
Signed-off-by Stefan Roese <[email protected]>Cc Bin Meng <[email protected]>Cc Simon Glass <[email protected]>Cc Jagan Teki <[email protected]>---
v2:
- Moved code into the ICH SPI driver as suggested by Simon and Bindrivers/spi/ich.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)drivers/spi/ich.c +14
-0@@ -18,6 +18,39 @@#include "ich.h" +#define SPI_OPMENU_0 0x01/* WRSR: Write Status Register */ +#define SPI_OPTYPE_0 0x01/* Write, no address */ + +#define SPI_OPMENU_1 0x02/* BYPR: Byte Program */ +#define SPI_OPTYPE_1 0x03/* Write, address required */ + +#define SPI_OPMENU_2 0x03/* READ: Read Data */ +#define SPI_OPTYPE_2 0x02/* Read, address required */ + +#define SPI_OPMENU_3 0x05/* RDSR: Read Status Register */ +#define SPI_OPTYPE_3 0x00/* Read, no address */ + +#define SPI_OPMENU_4 0x20/* SE20: Sector Erase 0x20 */ +#define SPI_OPTYPE_4 0x03/* Write, address required */
drivers/spi/ich.c line 44
Quoted 10 lines
drivers/spi/ich.c +10
-0+ +#define SPI_OPMENU_5 0x9f/* RDID: Read ID */ +#define SPI_OPTYPE_5 0x00/* Read, no address */ + +#define SPI_OPMENU_6 0xd8/* BED8: Block Erase 0xd8 */ +#define SPI_OPTYPE_6 0x03/* Write, address required */ + +#define SPI_OPMENU_7 0x0b/* FAST: Fast Read */ +#define SPI_OPTYPE_7 0x02/* Read, address required */ +
nits: can we move these defines to ich.h?
In ich.h, I see such macros are defined using enum, not sure the coding standard here, but I guess we may either follow the enum defines, or use a new patch to convert enum to #defines...
Quoted 35 lines
drivers/spi/ich.c +21
-0+#define SPI_OPTYPE ((SPI_OPTYPE_7 << 14) | (SPI_OPTYPE_6 << 12) | \ + (SPI_OPTYPE_5 << 10) | (SPI_OPTYPE_4 << 8) | \ + (SPI_OPTYPE_3 << 6) | (SPI_OPTYPE_2 << 4) | \ + (SPI_OPTYPE_1 << 2) | (SPI_OPTYPE_0 << 0)) +#define SPI_OPMENU_UPPER ((SPI_OPMENU_7 << 24) | (SPI_OPMENU_6 << 16) | \ + (SPI_OPMENU_5 << 8) | (SPI_OPMENU_4 << 0)) +#define SPI_OPMENU_LOWER ((SPI_OPMENU_3 << 24) | (SPI_OPMENU_2 << 16) | \ + (SPI_OPMENU_1 << 8) | (SPI_OPMENU_0 << 0)) +DECLARE_GLOBAL_DATA_PTR ;#ifdef DEBUG_TRACE @@ -111,6 +144,17 @@ static int ich9_can_do_33mhz(struct udevice *dev)return speed ==1 ; } +/* +* Configure SPI controller so that the Linux MTD driver can fully +* access the SPI NOR chip +*/ +static void spi_controller_config (struct ich_spi_priv *ctlr) +{ +ich_writew (ctlr,SPI_OPTYPE , ctlr->optype); +ich_writel (ctlr,SPI_OPMENU_LOWER , ctlr->opmenu); +ich_writel (ctlr,SPI_OPMENU_UPPER , ctlr->opmenu +sizeof (u32)); +} +static int ich_init_controller (struct udevice *dev,struct ich_spi_platdata *plat,struct ich_spi_priv *ctlr)@@ -172,6 +216,13 @@ static int ich_init_controller(struct udevice *dev,ich_set_bbar (ctlr,0 ); +/*
drivers/spi/ich.c static int ich_init_controller(struct udevice *dev,
Quoted 10 lines
drivers/spi/ich.c +6
-1+* Configure the SPI-NOR controller in a way that the Linux +* MTD SPI-NOR device driver has full read-write access to +* the SPI-NOR chips +*/ +spi_controller_config (ctlr); +return 0 ; } --
Regards,
Bin
PATCH v2 1/1 spi: ich: Configure SPI BIOS parameters
Hi Bin,
Quoted 42 lines · Bin Meng
Quoted 41 lines · Stefan Roese
Without configuring these registers in the SPI controller, the Linux MTD device driver is not able to correctly read/write to the SPI NOR chip at all. In fact, the chip is not detected at all.
Signed-off-by Stefan Roese <[email protected]>Cc Bin Meng <[email protected]>Cc Simon Glass <[email protected]>Cc Jagan Teki <[email protected]>---
v2:
- Moved code into the ICH SPI driver as suggested by Simon and Bindrivers/spi/ich.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)drivers/spi/ich.c +18
-0@@ -18,6 +18,39 @@#include "ich.h" +#define SPI_OPMENU_0 0x01/* WRSR: Write Status Register */ +#define SPI_OPTYPE_0 0x01/* Write, no address */ + +#define SPI_OPMENU_1 0x02/* BYPR: Byte Program */ +#define SPI_OPTYPE_1 0x03/* Write, address required */ + +#define SPI_OPMENU_2 0x03/* READ: Read Data */ +#define SPI_OPTYPE_2 0x02/* Read, address required */ + +#define SPI_OPMENU_3 0x05/* RDSR: Read Status Register */ +#define SPI_OPTYPE_3 0x00/* Read, no address */ + +#define SPI_OPMENU_4 0x20/* SE20: Sector Erase 0x20 */ +#define SPI_OPTYPE_4 0x03/* Write, address required */ + +#define SPI_OPMENU_5 0x9f/* RDID: Read ID */ +#define SPI_OPTYPE_5 0x00/* Read, no address */ +
Quoted 8 lines
drivers/spi/ich.c line 44
Quoted 6 lines
drivers/spi/ich.c +6
-0+#define SPI_OPMENU_6 0xd8/* BED8: Block Erase 0xd8 */ +#define SPI_OPTYPE_6 0x03/* Write, address required */ + +#define SPI_OPMENU_7 0x0b/* FAST: Fast Read */ +#define SPI_OPTYPE_7 0x02/* Read, address required */ +nits: can we move these defines to
ich.h?
Sure, no problem.
Quoted 1 line
In
ich.h, I see such macros are defined using enum,
You are referring to these here?
enum {
SPI_OPCODE_TYPE_READ_NO_ADDRESS = 0,
SPI_OPCODE_TYPE_WRITE_NO_ADDRESS = 1,
SPI_OPCODE_TYPE_READ_WITH_ADDRESS = 2,
SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS = 3
};
Quoted 3 lines
not sure the
coding standard here, but I guess we may either follow the enum defines, or use a new patch to convert enum to #defines...
I personally prefer #defines in such cases. So if nobody objects, I can send a patch to move those enums to defines.
Thanks,
Stefan
PATCH v2 1/1 spi: ich: Configure SPI BIOS parameters
Hi Stefan,
Quoted 65 lines · Stefan Roese
Hi Bin,
Quoted 46 lines · Bin Meng
Quoted 44 lines · Stefan Roese
Without configuring these registers in the SPI controller, the Linux MTD device driver is not able to correctly read/write to the SPI NOR chip at all. In fact, the chip is not detected at all.
Signed-off-by Stefan Roese <[email protected]>Cc Bin Meng <[email protected]>Cc Simon Glass <[email protected]>Cc Jagan Teki <[email protected]>---
v2:
- Moved code into the ICH SPI driver as suggested by Simon and Bindrivers/spi/ich.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)drivers/spi/ich.c +19
-0@@ -18,6 +18,39 @@#include "ich.h" +#define SPI_OPMENU_0 0x01/* WRSR: Write Status Register */ +#define SPI_OPTYPE_0 0x01/* Write, no address */ + +#define SPI_OPMENU_1 0x02/* BYPR: Byte Program */ +#define SPI_OPTYPE_1 0x03/* Write, address required */ + +#define SPI_OPMENU_2 0x03/* READ: Read Data */ +#define SPI_OPTYPE_2 0x02/* Read, address required */ + +#define SPI_OPMENU_3 0x05/* RDSR: Read Status Register */ +#define SPI_OPTYPE_3 0x00/* Read, no address */ + +#define SPI_OPMENU_4 0x20/* SE20: Sector Erase 0x20 */ +#define SPI_OPTYPE_4 0x03/* Write, address required */ + +#define SPI_OPMENU_5 0x9f/* RDID: Read ID */ +#define SPI_OPTYPE_5 0x00/* Read, no address */ + +#define SPI_OPMENU_6 0xd8/* BED8: Block Erase 0xd8 */ Quoted 8 lines
drivers/spi/ich.c line 44
Quoted 5 lines
drivers/spi/ich.c +5
-0+#define SPI_OPTYPE_6 0x03/* Write, address required */ + +#define SPI_OPMENU_7 0x0b/* FAST: Fast Read */ +#define SPI_OPTYPE_7 0x02/* Read, address required */ +nits: can we move these defines to
ich.h?Sure, no problem.
Quoted 1 line
In
ich.h, I see such macros are defined using enum,
Quoted 8 lines
You are referring to these here?
enum {
SPI_OPCODE_TYPE_READ_NO_ADDRESS = 0, SPI_OPCODE_TYPE_WRITE_NO_ADDRESS = 1, SPI_OPCODE_TYPE_READ_WITH_ADDRESS = 2, SPI_OPCODE_TYPE_WRITE_WITH_ADDRESS = 3};
Yep
Quoted 8 lines
Quoted 4 lines
not sure the
coding standard here, but I guess we may either follow the enum defines, or use a new patch to convert enum to #defines...I personally prefer #defines in such cases. So if nobody objects, I can send a patch to move those enums to defines.
Thanks!
Regards,
Bin