spi: Add support for stacked/parallel memories
Subsystems (5)
v8 cover spi: Add support for stacked/parallel memories
This patch is in the continuation to the discussions which happened on 'commit f89504300e94 ("spi: Stacked/parallel memories bindings")' for adding dt-binding support for stacked/parallel memories.
This patch series updated the spi-nor, spi core and the AMD-Xilinx GQSPI driver to add stacked and parallel memories support.
The first nine patches
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/
of the previous series got applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next But the rest of the patches in the series did not get applied as failure was reported for spi driver with GPIO CS, so send the remaining patches in the series after rebasing it on top of for-next branch and fixing the issue.
CS GPIO is not tested on our hardware, but it has been tested by @Stefan
https://lore.kernel.org/all/[email protected]/
Stefan, could you please provide your Tested-by tag for 1/7 patch.
---
BRANCH: for-next
Changes in v8:
- Updated __spi_add_device() and spi_set_cs() to fix spi driver failure with GPIO CS.
- Rebased the patch series on top of latest for-next branch and fixed merge conflicts.
- Updated cover letter description to add information regarding GPIO CS testing and request Stefan to provide his Tested-by tag for 1/7 patch.
- Updated 1/7 patch description.
Changes in v7:
- Updated spi_dev_check() to avoid failures for spi driver GPIO CS and moved the error message from __spi_add_device() to spi_dev_check().
- Resolved code indentation issue in spi_set_cs().
- In spi_set_cs() call spi_delay_exec( ) once if the controller supports multi cs with both the CS backed by GPIO.
- Updated __spi_validate()to add checks for both the GPIO CS.
- Replaced cs_index_mask bit mask with SPI_CS_CNT_MAX.
- Updated struct spi_controller to represent multi CS capability of the spi controller through a flag bit SPI_CONTROLLER_MULTI_CS instead of a boolen structure member "multi_cs_cap".
- Updated 1/7 patch description .
Changes in v6:
- Rebased on top of latest v6.3-rc1 and fixed merge conflicts in spi-mpc512x-psc.c, sfdp.c, spansion.c files and removed spi-omap-100k.c.
- Updated spi_dev_check( ) to reject new devices if any one of the chipselect is used by another device.
Changes in v5:
- Rebased the patches on top of v6.3-rc1 and fixed the merge conflicts.
- Fixed compilation warnings in spi-sh-msiof.c with shmobile_defconfig
Changes in v4:
- Fixed build error in spi-pl022.c file - reported by Mark.
- Fixed build error in spi-sn-f-ospi.c file.
- Added Reviewed-by: Serge Semin <[email protected]> tag.
- Added two more patches to replace spi->chip_select with API calls in mpc832x_rdb.c & cs35l41_hda_spi.c files.
Changes in v3:
- Rebased the patches on top of
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
- Added a patch to convert spi_nor_otp_region_len(nor) & spi_nor_otp_n_regions(nor) macros into inline functions
- Added Reviewed-by & Acked-by tags
Changes in v2:
- Rebased the patches on top of v6.2-rc1
- Created separate patch to add get & set APIs for spi->chip_select & spi->cs_gpiod, and replaced all spi->chip_select and spi->cs_gpiod references with the API calls.
- Created separate patch to add get & set APIs for nor->params.
---
Amit Kumar Mahapatra (7):
spi: Add stacked and parallel memories support in SPI core
mtd: spi-nor: Convert macros with inline functions
mtd: spi-nor: Add APIs to set/get nor->params
mtd: spi-nor: Add stacked memories support in spi-nor
spi: spi-zynqmp-gqspi: Add stacked memories support in GQSPI driver
mtd: spi-nor: Add parallel memories support in spi-nor
spi: spi-zynqmp-gqspi: Add parallel memories support in GQSPI driver
drivers/mtd/spi-nor/atmel.c | 17 +- drivers/mtd/spi-nor/core.c | 702 +++++++++++++++++++++++++------ drivers/mtd/spi-nor/core.h | 8 + drivers/mtd/spi-nor/debugfs.c | 4 +- drivers/mtd/spi-nor/gigadevice.c | 4 +- drivers/mtd/spi-nor/issi.c | 11 +- drivers/mtd/spi-nor/macronix.c | 10 +- drivers/mtd/spi-nor/micron-st.c | 35 +- drivers/mtd/spi-nor/otp.c | 48 ++- drivers/mtd/spi-nor/sfdp.c | 33 +- drivers/mtd/spi-nor/spansion.c | 80 ++-- drivers/mtd/spi-nor/sst.c | 7 +- drivers/mtd/spi-nor/swp.c | 22 +- drivers/mtd/spi-nor/winbond.c | 2 +- drivers/mtd/spi-nor/xilinx.c | 18 +- drivers/spi/spi-zynqmp-gqspi.c | 58 ++- drivers/spi/spi.c | 231 +++++++--- include/linux/mtd/spi-nor.h | 18 +- include/linux/spi/spi.h | 32 +- 19 files changed, 1044 insertions(+), 296 deletions(-)
Signature · 1 line
2.17.1
PATCH v8 1/7 spi: Add stacked and parallel memories support in SPI core
For supporting multiple CS the SPI device need to be aware of all the CS values. So, the "chip_select" member in the spi_device structure is now an array that holds all the CS values.
spi_device structure now has a "cs_index_mask" member. This acts as an index to the chip_select array. If nth bit of spi->cs_index_mask is set then the driver would assert spi->chip_select[n].
In parallel mode all the chip selects are asserted/de-asserted simultaneously and each byte of data is stored in both devices, the even bits in one, the odd bits in the other. The split is automatically handled by the GQSPI controller. The GQSPI controller supports a maximum of two flashes connected in parallel mode. A SPI_CONTROLLER_MULTI_CS flag bit is added in the spi controntroller flags, through ctlr->flags the spi core will make sure that the controller is capable of handling multiple chip selects at once.
For supporting multiple CS via GPIO the cs_gpiod member of the spi_device structure is now an array that holds the gpio descriptor for each chipselect.
---
CS GPIO is not tested on our hardware but it has been tested by @Stefan
https://lore.kernel.org/all/[email protected]/
Stefan, could you please provide your Tested-by tag for this patch
--- drivers/spi/spi.c | 231 ++++++++++++++++++++++++++++------------ include/linux/spi/spi.h | 32 ++++-- 2 files changed, 189 insertions(+), 74 deletions(-)
drivers/spi/spi.c +163 -68
@@ -612,10 +612,24 @@ static int spi_dev_check(struct device *dev, void *data) {struct spi_device *spi =to_spi_device (dev);struct spi_device *new_spi = data; +int idx, nw_idx; -if (spi->controller == new_spi->controller && -spi_get_chipselect (spi,0 ) ==spi_get_chipselect (new_spi,0 )) -return -EBUSY ; +if (spi->controller == new_spi->controller) { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +for (nw_idx =0 ; nw_idx <SPI_CS_CNT_MAX ; nw_idx++) { +if ((idx !=0 && !spi_get_chipselect (spi, idx)) || + (nw_idx !=0 && !spi_get_chipselect (spi, nw_idx))) { +continue ; + }else if (spi_get_chipselect (spi, idx) == +spi_get_chipselect (new_spi, nw_idx)) { +dev_err (dev, +"chipselect %d already in use\n" , +spi_get_chipselect (new_spi, nw_idx)); +return -EBUSY ; + } + } + } + }return 0 ; }
@@ -629,7 +643,7 @@ static int __spi_add_device(struct spi_device *spi) {struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; -int status; +int status, idx;/* * We need to make sure there's no other device with this
@@ -638,8 +652,6 @@ static int __spi_add_device(struct spi_device *spi)*/ status =bus_for_each_dev (&spi_bus_type,NULL , spi, spi_dev_check);if (status) { -dev_err (dev,"chipselect %d already in use\n" , -spi_get_chipselect (spi,0 ));return status; }
@@ -649,8 +661,13 @@ static int __spi_add_device(struct spi_device *spi)return -ENODEV ; } -if (ctlr->cs_gpiods) -spi_set_csgpiod (spi,0 , ctlr->cs_gpiods[spi_get_chipselect (spi,0 )]); +if (ctlr->cs_gpiods) { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +if (!(idx !=0 && !spi_get_chipselect (spi, idx))) +spi_set_csgpiod (spi, idx, + ctlr->cs_gpiods[spi_get_chipselect (spi, idx)]); + } + }/* * Drivers may modify this initial i/o setup, but will
@@ -690,13 +707,15 @@ int spi_add_device(struct spi_device *spi) {struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; -int status; +int status, idx; -/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { -dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +/* Chipselects are numbered 0..max; validate. */ +if (spi_get_chipselect (spi, idx) >= ctlr->num_chipselect) { +dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi, idx), + ctlr->num_chipselect); +return -EINVAL ; + } }/* Set the bus ID string */
@@ -713,12 +732,15 @@ static int spi_add_device_locked(struct spi_device *spi) {struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; +int idx; -/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { -dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +/* Chipselects are numbered 0..max; validate. */ +if (spi_get_chipselect (spi, idx) >= ctlr->num_chipselect) { +dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi, idx), + ctlr->num_chipselect); +return -EINVAL ; + } }/* Set the bus ID string */
@@ -966,58 +988,122 @@ static void spi_res_release(struct spi_controller *ctlr, struct spi_message *messtatic void spi_set_cs (struct spi_device *spi,bool enable,bool force) {bool activate = enable; +u32 cs_num =0 ; +int idx;/* -* Avoid calling into the driver (or doing delays) if the chip select -* isn't actually changing from the last time this was called. +* In parallel mode all the chip selects are asserted/de-asserted +* at once */ -if (!force && ((enable && spi->controller->last_cs ==spi_get_chipselect (spi,0 )) || - (!enable && spi->controller->last_cs !=spi_get_chipselect (spi,0 ))) && - (spi->controller->last_cs_mode_high == (spi->mode &SPI_CS_HIGH ))) -return ; - -trace_spi_set_cs (spi, activate); +if ((spi->cs_index_mask &SPI_PARALLEL_CS_MASK ) ==SPI_PARALLEL_CS_MASK ) { + spi->controller->last_cs_mode_high = spi->mode &SPI_CS_HIGH ; + +if ((spi_get_csgpiod (spi,0 ) || !spi->controller->set_cs_timing) && !activate) +spi_delay_exec (&spi->cs_hold,NULL ); + +if (spi->mode &SPI_CS_HIGH ) + enable = !enable; + +if (spi_get_csgpiod (spi,0 ) &&spi_get_csgpiod (spi,1 )) { +if (!(spi->mode &SPI_NO_CS )) { +/* +* Historically ACPI has no means of the GPIO polarity and +* thus the SPISerialBus() resource defines it on the per-chip +* basis. In order to avoid a chain of negations, the GPIO +* polarity is considered being Active High. Even for the cases +* when _DSD() is involved (in the updated versions of ACPI) +* the GPIO CS polarity must be defined Active High to avoid +* ambiguity. That's why we use enable, that takes SPI_CS_HIGH +* into account. +*/ +if (has_acpi_companion (&spi->dev)) { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) +gpiod_set_value_cansleep (spi_get_csgpiod (spi, idx), + !enable); + }else { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) +/* Polarity handled by GPIO library */ +gpiod_set_value_cansleep (spi_get_csgpiod (spi, idx), + activate); + } + } +/* Some SPI masters need both GPIO CS & slave_select */ +if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && + spi->controller->set_cs) + spi->controller->set_cs (spi, !enable); + }else if (spi->controller->set_cs) { + spi->controller->set_cs (spi, !enable); + } - spi->controller->last_cs = enable ?spi_get_chipselect (spi,0 ) :-1 ; - spi->controller->last_cs_mode_high = spi->mode &SPI_CS_HIGH ; +if (spi_get_csgpiod (spi,0 ) ||spi_get_csgpiod (spi,1 ) || + !spi->controller->set_cs_timing) { +if (activate) +spi_delay_exec (&spi->cs_setup,NULL ); +else +spi_delay_exec (&spi->cs_inactive,NULL ); + } + }else { -if ((spi_get_csgpiod (spi,0 ) || !spi->controller->set_cs_timing) && !activate) -spi_delay_exec (&spi->cs_hold,NULL ); +if (spi->cs_index_mask) + cs_num =ffs (spi->cs_index_mask) -1 ; -if (spi->mode &SPI_CS_HIGH ) - enable = !enable; +/* +* Avoid calling into the driver (or doing delays) if the chip select +* isn't actually changing from the last time this was called. +*/ +if (!force && ((enable && spi->controller->last_cs == +spi_get_chipselect (spi, cs_num)) || + (!enable && spi->controller->last_cs != +spi_get_chipselect (spi, cs_num))) && + (spi->controller->last_cs_mode_high == + (spi->mode &SPI_CS_HIGH ))) +return ; + +trace_spi_set_cs (spi, activate); + + spi->controller->last_cs = enable ?spi_get_chipselect (spi, cs_num) :-1 ; + spi->controller->last_cs_mode_high = spi->mode &SPI_CS_HIGH ; + +if ((spi_get_csgpiod (spi, cs_num) || !spi->controller->set_cs_timing) && !activate) +spi_delay_exec (&spi->cs_hold,NULL ); + +if (spi->mode &SPI_CS_HIGH ) + enable = !enable; + +if (spi_get_csgpiod (spi, cs_num)) { +if (!(spi->mode &SPI_NO_CS )) { +/* +* Historically ACPI has no means of the GPIO polarity and +* thus the SPISerialBus() resource defines it on the per-chip +* basis. In order to avoid a chain of negations, the GPIO +* polarity is considered being Active High. Even for the cases +* when _DSD() is involved (in the updated versions of ACPI) +* the GPIO CS polarity must be defined Active High to avoid +* ambiguity. That's why we use enable, that takes SPI_CS_HIGH +* into account. +*/ +if (has_acpi_companion (&spi->dev)) +gpiod_set_value_cansleep (spi_get_csgpiod (spi, cs_num), + !enable); +else +/* Polarity handled by GPIO library */ +gpiod_set_value_cansleep (spi_get_csgpiod (spi, cs_num), + activate); + } +/* Some SPI masters need both GPIO CS & slave_select */ +if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && + spi->controller->set_cs) + spi->controller->set_cs (spi, !enable); + }else if (spi->controller->set_cs) { + spi->controller->set_cs (spi, !enable); + } -if (spi_get_csgpiod (spi,0 )) { -if (!(spi->mode &SPI_NO_CS )) { -/* -* Historically ACPI has no means of the GPIO polarity and -* thus the SPISerialBus() resource defines it on the per-chip -* basis. In order to avoid a chain of negations, the GPIO -* polarity is considered being Active High. Even for the cases -* when _DSD() is involved (in the updated versions of ACPI) -* the GPIO CS polarity must be defined Active High to avoid -* ambiguity. That's why we use enable, that takes SPI_CS_HIGH -* into account. -*/ -if (has_acpi_companion (&spi->dev)) -gpiod_set_value_cansleep (spi_get_csgpiod (spi,0 ), !enable); +if (spi_get_csgpiod (spi, cs_num) || !spi->controller->set_cs_timing) { +if (activate) +spi_delay_exec (&spi->cs_setup,NULL );else -/* Polarity handled by GPIO library */ -gpiod_set_value_cansleep (spi_get_csgpiod (spi,0 ), activate); +spi_delay_exec (&spi->cs_inactive,NULL ); } -/* Some SPI masters need both GPIO CS & slave_select */ -if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && - spi->controller->set_cs) - spi->controller->set_cs (spi, !enable); - }else if (spi->controller->set_cs) { - spi->controller->set_cs (spi, !enable); - } - -if (spi_get_csgpiod (spi,0 ) || !spi->controller->set_cs_timing) { -if (activate) -spi_delay_exec (&spi->cs_setup,NULL ); -else -spi_delay_exec (&spi->cs_inactive,NULL ); } }
@@ -2246,8 +2332,8 @@ static void of_spi_parse_dt_cs_delay(struct device_node *nc,static int of_spi_parse_dt (struct spi_controller *ctlr,struct spi_device *spi,struct device_node *nc) { -u32 value; -int rc; +u32 value, cs[SPI_CS_CNT_MAX ] = {0 }; +int rc, idx;/* Mode (clock phase/polarity/etc.) */ if (of_property_read_bool (nc,"spi-cpha" ))
@@ -2320,13 +2406,21 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, }/* Device address */ - rc =of_property_read_u32 (nc,"reg" , &value); -if (rc) { + rc =of_property_read_variable_u32_array (nc,"reg" , &cs[0 ],1 , +SPI_CS_CNT_MAX ); +if (rc <0 || rc > ctlr->num_chipselect) {dev_err (&ctlr->dev,"%pOF has no valid 'reg' property (%d)\n" , nc, rc);return rc; + }else if ((of_property_read_bool (nc,"parallel-memories" )) && + (!(ctlr->flags &SPI_CONTROLLER_MULTI_CS ))) { +dev_err (&ctlr->dev,"SPI controller doesn't support multi CS\n" ); +return -EINVAL ; } -spi_set_chipselect (spi,0 , value); +for (idx =0 ; idx < rc; idx++) +spi_set_chipselect (spi, idx, cs[idx]); +/* By default set the spi->cs_index_mask as 1 */ + spi->cs_index_mask =0x01 ;/* Device speed */ if (!of_property_read_u32 (nc,"spi-max-frequency" , &value))
@@ -3905,7 +3999,8 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)* cs_change is set for each transfer. */ if ((spi->mode &SPI_CS_WORD ) && (!(ctlr->mode_bits &SPI_CS_WORD ) || -spi_get_csgpiod (spi,0 ))) { +spi_get_csgpiod (spi,0 ) || +spi_get_csgpiod (spi,1 ))) {size_t maxsize;int ret;
include/linux/spi/spi.h +26 -6
@@ -19,6 +19,11 @@#include <linux/acpi.h> #include <linux/u64_stats_sync.h> +/* Max no. of CS supported per spi device */ +#define SPI_CS_CNT_MAX 2 + +/* chip select mask */ +#define SPI_PARALLEL_CS_MASK (BIT(0) | BIT(1))struct dma_chan ;struct software_node ;struct ptp_system_timestamp ;
@@ -166,6 +171,7 @@ extern void spi_transfer_cs_change_delay_exec(struct spi_message *msg,* deasserted. If @cs_change_delay is used from @spi_transfer, then the * two delays will be added up. * @pcpu_statistics: statistics for the spi_device +* @cs_index_mask: Bit mask of the active chipselect(s) in the chipselect array * * A @spi_device is used to interchange data between an SPI slave * (usually a discrete chip) and CPU memory.
@@ -181,7 +187,7 @@ struct spi_device {struct spi_controller *controller;struct spi_controller *master;/* Compatibility layer */ u32 max_speed_hz; -u8 chip_select; +u8 chip_select[SPI_CS_CNT_MAX ];u8 bits_per_word;bool rt;#define SPI_NO_TX BIT(31)/* No transmit wire */
@@ -212,7 +218,7 @@ struct spi_device {void *controller_data;char modalias[SPI_NAME_SIZE ];const char *driver_override; -struct gpio_desc *cs_gpiod;/* Chip select gpio desc */ +struct gpio_desc *cs_gpiod[SPI_CS_CNT_MAX ];/* Chip select gpio desc */ struct spi_delay word_delay;/* Inter-word delay */ /* CS delays */ struct spi_delay cs_setup;
@@ -222,6 +228,13 @@ struct spi_device {/* The statistics */ struct spi_statistics __percpu *pcpu_statistics; +/* Bit mask of the chipselect(s) that the driver need to use from +* the chipselect array.When the controller is capable to handle +* multiple chip selects & memories are connected in parallel +* then more than one bit need to be set in cs_index_mask. +*/ + u32 cs_index_mask : SPI_CS_CNT_MAX; +/* * likely need more hooks for more protocol options affecting how * the controller talks to each chip, like:
@@ -278,22 +291,22 @@ static inline void *spi_get_drvdata(const struct spi_device *spi)static inline u8 spi_get_chipselect (const struct spi_device *spi,u8 idx) { -return spi->chip_select; +return spi->chip_select[idx]; }static inline void spi_set_chipselect (struct spi_device *spi,u8 idx,u8 chipselect) { - spi->chip_select = chipselect; + spi->chip_select[idx] = chipselect; }static inline struct gpio_desc *spi_get_csgpiod (const struct spi_device *spi,u8 idx) { -return spi->cs_gpiod; +return spi->cs_gpiod[idx]; }static inline void spi_set_csgpiod (struct spi_device *spi,u8 idx,struct gpio_desc *csgpiod) { - spi->cs_gpiod = csgpiod; + spi->cs_gpiod[idx] = csgpiod; }/**
@@ -398,6 +411,8 @@ extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 ch* @bus_lock_spinlock: spinlock for SPI bus locking * @bus_lock_mutex: mutex for exclusion of multiple callers * @bus_lock_flag: indicates that the SPI bus is locked for exclusive use +* @multi_cs_cap: indicates that the SPI Controller can assert/de-assert +* more than one chip select at once. * @setup: updates the device mode and clocking records used by a * device's SPI controller; protocol code may call this. This * must fail if an unrecognized or unsupported mode is requested.
@@ -564,6 +579,11 @@ struct spi_controller {#define SPI_CONTROLLER_MUST_TX BIT(4)/* Requires tx */ #define SPI_MASTER_GPIO_SS BIT(5)/* GPIO CS must select slave */ +/* +* The spi-controller has multi chip select capability and can +* assert/de-assert more than one chip select at once. +*/ +#define SPI_CONTROLLER_MULTI_CS BIT(6)/* Flag indicating if the allocation of this struct is devres-managed */ bool devm_allocated;
Signature · 1 line
2.17.1
Re: [PATCH V8 1/7] spi: Add stacked and parallel memories support in SPI core
Hi,
Quoted 21 lines · Amit Kumar Mahapatra
For supporting multiple CS the SPI device need to be aware of all the CS values. So, the "
chip_select" member in thespi_devicestructure is now an array that holds all the CS values.
spi_devicestructure now has a "cs_index_mask" member. This acts as an index to thechip_selectarray. If nth bit ofspi->cs_index_maskis set then the driver would assert spi->chip_select[n].In parallel mode all the chip selects are asserted/de-asserted simultaneously and each byte of data is stored in both devices, the even bits in one, the odd bits in the other. The split is automatically handled by the GQSPI controller. The GQSPI controller supports a maximum of two flashes connected in parallel mode. A
SPI_CONTROLLER_MULTI_CSflag bit is added in the spi controntroller flags, throughctlr->flagsthe spi core will make sure that the controller is capable of handling multiple chip selects at once.For supporting multiple CS via GPIO the
cs_gpiodmember of thespi_devicestructure is now an array that holds the gpio descriptor for each chipselect.
Quoted 5 lines
Signed-off-by Amit Kumar Mahapatra <[email protected]>---
CS GPIO is not tested on our hardware but it has been tested by @Stefan
https://lore.kernel.org/all/[email protected]/
Stefan, could you please provide your Tested-by tag for this patch
I tried testing this patch, but I got a build failure in drivers/spi/spi-dw-mmio.c when I use this patch on the spi for-next branch.
(If I disable this driver, the patch works fine)
Thanks,
Stefan
Quoted 430 lines
--- drivers/spi/spi.c | 231 ++++++++++++++++++++++++++++------------ include/linux/spi/spi.h | 32 ++++-- 2 files changed, 189 insertions(+), 74 deletions(-)drivers/spi/spi.c +163
-68@@ -612,10 +612,24 @@ static int spi_dev_check(struct device *dev, void *data) {struct spi_device *spi =to_spi_device (dev);struct spi_device *new_spi = data; +int idx, nw_idx; -if (spi->controller == new_spi->controller && -spi_get_chipselect (spi,0 ) ==spi_get_chipselect (new_spi,0 )) -return -EBUSY ; +if (spi->controller == new_spi->controller) { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +for (nw_idx =0 ; nw_idx <SPI_CS_CNT_MAX ; nw_idx++) { +if ((idx !=0 && !spi_get_chipselect (spi, idx)) || + (nw_idx !=0 && !spi_get_chipselect (spi, nw_idx))) { +continue ; + }else if (spi_get_chipselect (spi, idx) == +spi_get_chipselect (new_spi, nw_idx)) { +dev_err (dev, +"chipselect %d already in use\n" , +spi_get_chipselect (new_spi, nw_idx)); +return -EBUSY ; + } + } + } + }return 0 ; }@@ -629,7 +643,7 @@ static int __spi_add_device(struct spi_device *spi) {struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; -int status; +int status, idx;/* * We need to make sure there's no other device with this @@ -638,8 +652,6 @@ static int __spi_add_device(struct spi_device *spi)*/ status =bus_for_each_dev (&spi_bus_type,NULL , spi, spi_dev_check);if (status) { -dev_err (dev,"chipselect %d already in use\n" , -spi_get_chipselect (spi,0 ));return status; }@@ -649,8 +661,13 @@ static int __spi_add_device(struct spi_device *spi)return -ENODEV ; } -if (ctlr->cs_gpiods) -spi_set_csgpiod (spi,0 , ctlr->cs_gpiods[spi_get_chipselect (spi,0 )]); +if (ctlr->cs_gpiods) { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +if (!(idx !=0 && !spi_get_chipselect (spi, idx))) +spi_set_csgpiod (spi, idx, + ctlr->cs_gpiods[spi_get_chipselect (spi, idx)]); + } + }/* * Drivers may modify this initial i/o setup, but will @@ -690,13 +707,15 @@ int spi_add_device(struct spi_device *spi) {struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; -int status; +int status, idx; -/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { -dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +/* Chipselects are numbered 0..max; validate. */ +if (spi_get_chipselect (spi, idx) >= ctlr->num_chipselect) { +dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi, idx), + ctlr->num_chipselect); +return -EINVAL ; + } }/* Set the bus ID string */ @@ -713,12 +732,15 @@ static int spi_add_device_locked(struct spi_device *spi) {struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; +int idx; -/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { -dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +/* Chipselects are numbered 0..max; validate. */ +if (spi_get_chipselect (spi, idx) >= ctlr->num_chipselect) { +dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi, idx), + ctlr->num_chipselect); +return -EINVAL ; + } }/* Set the bus ID string */ @@ -966,58 +988,122 @@ static void spi_res_release(struct spi_controller *ctlr, struct spi_message *messtatic void spi_set_cs (struct spi_device *spi,bool enable,bool force) {bool activate = enable; +u32 cs_num =0 ; +int idx;/* -* Avoid calling into the driver (or doing delays) if the chip select -* isn't actually changing from the last time this was called. +* In parallel mode all the chip selects are asserted/de-asserted +* at once */ -if (!force && ((enable && spi->controller->last_cs ==spi_get_chipselect (spi,0 )) || - (!enable && spi->controller->last_cs !=spi_get_chipselect (spi,0 ))) && - (spi->controller->last_cs_mode_high == (spi->mode &SPI_CS_HIGH ))) -return ; - -trace_spi_set_cs (spi, activate); +if ((spi->cs_index_mask &SPI_PARALLEL_CS_MASK ) ==SPI_PARALLEL_CS_MASK ) { + spi->controller->last_cs_mode_high = spi->mode &SPI_CS_HIGH ; + +if ((spi_get_csgpiod (spi,0 ) || !spi->controller->set_cs_timing) && !activate) +spi_delay_exec (&spi->cs_hold,NULL ); + +if (spi->mode &SPI_CS_HIGH ) + enable = !enable; + +if (spi_get_csgpiod (spi,0 ) &&spi_get_csgpiod (spi,1 )) { +if (!(spi->mode &SPI_NO_CS )) { +/* +* Historically ACPI has no means of the GPIO polarity and +* thus the SPISerialBus() resource defines it on the per-chip +* basis. In order to avoid a chain of negations, the GPIO +* polarity is considered being Active High. Even for the cases +* when _DSD() is involved (in the updated versions of ACPI) +* the GPIO CS polarity must be defined Active High to avoid +* ambiguity. That's why we use enable, that takes SPI_CS_HIGH +* into account. +*/ +if (has_acpi_companion (&spi->dev)) { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) +gpiod_set_value_cansleep (spi_get_csgpiod (spi, idx), + !enable); + }else { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) +/* Polarity handled by GPIO library */ +gpiod_set_value_cansleep (spi_get_csgpiod (spi, idx), + activate); + } + } +/* Some SPI masters need both GPIO CS & slave_select */ +if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && + spi->controller->set_cs) + spi->controller->set_cs (spi, !enable); + }else if (spi->controller->set_cs) { + spi->controller->set_cs (spi, !enable); + } - spi->controller->last_cs = enable ?spi_get_chipselect (spi,0 ) :-1 ; - spi->controller->last_cs_mode_high = spi->mode &SPI_CS_HIGH ; +if (spi_get_csgpiod (spi,0 ) ||spi_get_csgpiod (spi,1 ) || + !spi->controller->set_cs_timing) { +if (activate) +spi_delay_exec (&spi->cs_setup,NULL ); +else +spi_delay_exec (&spi->cs_inactive,NULL ); + } + }else { -if ((spi_get_csgpiod (spi,0 ) || !spi->controller->set_cs_timing) && !activate) -spi_delay_exec (&spi->cs_hold,NULL ); +if (spi->cs_index_mask) + cs_num =ffs (spi->cs_index_mask) -1 ; -if (spi->mode &SPI_CS_HIGH ) - enable = !enable; +/* +* Avoid calling into the driver (or doing delays) if the chip select +* isn't actually changing from the last time this was called. +*/ +if (!force && ((enable && spi->controller->last_cs == +spi_get_chipselect (spi, cs_num)) || + (!enable && spi->controller->last_cs != +spi_get_chipselect (spi, cs_num))) && + (spi->controller->last_cs_mode_high == + (spi->mode &SPI_CS_HIGH ))) +return ; + +trace_spi_set_cs (spi, activate); + + spi->controller->last_cs = enable ?spi_get_chipselect (spi, cs_num) :-1 ; + spi->controller->last_cs_mode_high = spi->mode &SPI_CS_HIGH ; + +if ((spi_get_csgpiod (spi, cs_num) || !spi->controller->set_cs_timing) && !activate) +spi_delay_exec (&spi->cs_hold,NULL ); + +if (spi->mode &SPI_CS_HIGH ) + enable = !enable; + +if (spi_get_csgpiod (spi, cs_num)) { +if (!(spi->mode &SPI_NO_CS )) { +/* +* Historically ACPI has no means of the GPIO polarity and +* thus the SPISerialBus() resource defines it on the per-chip +* basis. In order to avoid a chain of negations, the GPIO +* polarity is considered being Active High. Even for the cases +* when _DSD() is involved (in the updated versions of ACPI) +* the GPIO CS polarity must be defined Active High to avoid +* ambiguity. That's why we use enable, that takes SPI_CS_HIGH +* into account. +*/ +if (has_acpi_companion (&spi->dev)) +gpiod_set_value_cansleep (spi_get_csgpiod (spi, cs_num), + !enable); +else +/* Polarity handled by GPIO library */ +gpiod_set_value_cansleep (spi_get_csgpiod (spi, cs_num), + activate); + } +/* Some SPI masters need both GPIO CS & slave_select */ +if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && + spi->controller->set_cs) + spi->controller->set_cs (spi, !enable); + }else if (spi->controller->set_cs) { + spi->controller->set_cs (spi, !enable); + } -if (spi_get_csgpiod (spi,0 )) { -if (!(spi->mode &SPI_NO_CS )) { -/* -* Historically ACPI has no means of the GPIO polarity and -* thus the SPISerialBus() resource defines it on the per-chip -* basis. In order to avoid a chain of negations, the GPIO -* polarity is considered being Active High. Even for the cases -* when _DSD() is involved (in the updated versions of ACPI) -* the GPIO CS polarity must be defined Active High to avoid -* ambiguity. That's why we use enable, that takes SPI_CS_HIGH -* into account. -*/ -if (has_acpi_companion (&spi->dev)) -gpiod_set_value_cansleep (spi_get_csgpiod (spi,0 ), !enable); +if (spi_get_csgpiod (spi, cs_num) || !spi->controller->set_cs_timing) { +if (activate) +spi_delay_exec (&spi->cs_setup,NULL );else -/* Polarity handled by GPIO library */ -gpiod_set_value_cansleep (spi_get_csgpiod (spi,0 ), activate); +spi_delay_exec (&spi->cs_inactive,NULL ); } -/* Some SPI masters need both GPIO CS & slave_select */ -if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && - spi->controller->set_cs) - spi->controller->set_cs (spi, !enable); - }else if (spi->controller->set_cs) { - spi->controller->set_cs (spi, !enable); - } - -if (spi_get_csgpiod (spi,0 ) || !spi->controller->set_cs_timing) { -if (activate) -spi_delay_exec (&spi->cs_setup,NULL ); -else -spi_delay_exec (&spi->cs_inactive,NULL ); } }@@ -2246,8 +2332,8 @@ static void of_spi_parse_dt_cs_delay(struct device_node *nc,static int of_spi_parse_dt (struct spi_controller *ctlr,struct spi_device *spi,struct device_node *nc) { -u32 value; -int rc; +u32 value, cs[SPI_CS_CNT_MAX ] = {0 }; +int rc, idx;/* Mode (clock phase/polarity/etc.) */ if (of_property_read_bool (nc,"spi-cpha" ))@@ -2320,13 +2406,21 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, }/* Device address */ - rc =of_property_read_u32 (nc,"reg" , &value); -if (rc) { + rc =of_property_read_variable_u32_array (nc,"reg" , &cs[0 ],1 , +SPI_CS_CNT_MAX ); +if (rc <0 || rc > ctlr->num_chipselect) {dev_err (&ctlr->dev,"%pOF has no valid 'reg' property (%d)\n" , nc, rc);return rc; + }else if ((of_property_read_bool (nc,"parallel-memories" )) && + (!(ctlr->flags &SPI_CONTROLLER_MULTI_CS ))) { +dev_err (&ctlr->dev,"SPI controller doesn't support multi CS\n" ); +return -EINVAL ; } -spi_set_chipselect (spi,0 , value); +for (idx =0 ; idx < rc; idx++) +spi_set_chipselect (spi, idx, cs[idx]); +/* By default set the spi->cs_index_mask as 1 */ + spi->cs_index_mask =0x01 ;/* Device speed */ if (!of_property_read_u32 (nc,"spi-max-frequency" , &value))@@ -3905,7 +3999,8 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)* cs_change is set for each transfer. */ if ((spi->mode &SPI_CS_WORD ) && (!(ctlr->mode_bits &SPI_CS_WORD ) || -spi_get_csgpiod (spi,0 ))) { +spi_get_csgpiod (spi,0 ) || +spi_get_csgpiod (spi,1 ))) {size_t maxsize;int ret;include/linux/spi/spi.h +26
-6@@ -19,6 +19,11 @@#include <linux/acpi.h> #include <linux/u64_stats_sync.h> +/* Max no. of CS supported per spi device */ +#define SPI_CS_CNT_MAX 2 + +/* chip select mask */ +#define SPI_PARALLEL_CS_MASK (BIT(0) | BIT(1))struct dma_chan ;struct software_node ;struct ptp_system_timestamp ;@@ -166,6 +171,7 @@ extern void spi_transfer_cs_change_delay_exec(struct spi_message *msg,* deasserted. If @cs_change_delay is used from @spi_transfer, then the * two delays will be added up. * @pcpu_statistics: statistics for the spi_device +* @cs_index_mask: Bit mask of the active chipselect(s) in the chipselect array * * A @spi_device is used to interchange data between an SPI slave * (usually a discrete chip) and CPU memory. @@ -181,7 +187,7 @@ struct spi_device {struct spi_controller *controller;struct spi_controller *master;/* Compatibility layer */ u32 max_speed_hz; -u8 chip_select; +u8 chip_select[SPI_CS_CNT_MAX ];u8 bits_per_word;bool rt;#define SPI_NO_TX BIT(31)/* No transmit wire */ @@ -212,7 +218,7 @@ struct spi_device {void *controller_data;char modalias[SPI_NAME_SIZE ];const char *driver_override; -struct gpio_desc *cs_gpiod;/* Chip select gpio desc */ +struct gpio_desc *cs_gpiod[SPI_CS_CNT_MAX ];/* Chip select gpio desc */ struct spi_delay word_delay;/* Inter-word delay */ /* CS delays */ struct spi_delay cs_setup;@@ -222,6 +228,13 @@ struct spi_device {/* The statistics */ struct spi_statistics __percpu *pcpu_statistics; +/* Bit mask of the chipselect(s) that the driver need to use from +* the chipselect array.When the controller is capable to handle +* multiple chip selects & memories are connected in parallel +* then more than one bit need to be set in cs_index_mask. +*/ + u32 cs_index_mask : SPI_CS_CNT_MAX; +/* * likely need more hooks for more protocol options affecting how * the controller talks to each chip, like: @@ -278,22 +291,22 @@ static inline void *spi_get_drvdata(const struct spi_device *spi)static inline u8 spi_get_chipselect (const struct spi_device *spi,u8 idx) { -return spi->chip_select; +return spi->chip_select[idx]; }static inline void spi_set_chipselect (struct spi_device *spi,u8 idx,u8 chipselect) { - spi->chip_select = chipselect; + spi->chip_select[idx] = chipselect; }static inline struct gpio_desc *spi_get_csgpiod (const struct spi_device *spi,u8 idx) { -return spi->cs_gpiod; +return spi->cs_gpiod[idx]; }static inline void spi_set_csgpiod (struct spi_device *spi,u8 idx,struct gpio_desc *csgpiod) { - spi->cs_gpiod = csgpiod; + spi->cs_gpiod[idx] = csgpiod; }/** @@ -398,6 +411,8 @@ extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 ch* @bus_lock_spinlock: spinlock for SPI bus locking * @bus_lock_mutex: mutex for exclusion of multiple callers * @bus_lock_flag: indicates that the SPI bus is locked for exclusive use +* @multi_cs_cap: indicates that the SPI Controller can assert/de-assert +* more than one chip select at once. * @setup: updates the device mode and clocking records used by a * device's SPI controller; protocol code may call this. This * must fail if an unrecognized or unsupported mode is requested. @@ -564,6 +579,11 @@ struct spi_controller {#define SPI_CONTROLLER_MUST_TX BIT(4)/* Requires tx */ #define SPI_MASTER_GPIO_SS BIT(5)/* GPIO CS must select slave */ +/* +* The spi-controller has multi chip select capability and can +* assert/de-assert more than one chip select at once. +*/ +#define SPI_CONTROLLER_MULTI_CS BIT(6)/* Flag indicating if the allocation of this struct is devres-managed */ bool devm_allocated;
RE: [PATCH V8 1/7] spi: Add stacked and parallel memories support in SPI core
Hello Stefan,
Quoted 47 lines
-----Original Message-----
From: Stefan Binding <[email protected]>
Sent: Thursday, May 11, 2023 10:20 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: git (AMD-Xilinx) <[email protected]>; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V8 1/7] spi: Add stacked and parallel memories support in SPI coreHi,
Quoted 21 lines · Amit Kumar Mahapatra
For supporting multiple CS the SPI device need to be aware of all the CS values. So, the "
chip_select" member in thespi_devicestructure is now an array that holds all the CS values.
spi_devicestructure now has a "cs_index_mask" member. This acts as an index to thechip_selectarray. If nth bit ofspi->cs_index_maskis set then the driver would assert spi->chip_select[n].In parallel mode all the chip selects are asserted/de-asserted simultaneously and each byte of data is stored in both devices, the even bits in one, the odd bits in the other. The split is automatically handled by the GQSPI controller. The GQSPI controller supports a maximum of two flashes connected in parallel mode. A
SPI_CONTROLLER_MULTI_CSflag bit is added in the spi controntroller flags, throughctlr->flagsthe spi core will make sure that the controller is capable of handling multiple chip selects at once.For supporting multiple CS via GPIO the
cs_gpiodmember of thespi_devicestructure is now an array that holds the gpio descriptor for each chipselect.Quoted 7 lines
Signed-off-by Amit Kumar Mahapatra <[email protected]>---
CS GPIO is not tested on our hardware but it has been tested by @Stefan
https://lore.kernel.org/all/3f148a0c-8885-0425-28f4-2a53937a388f@opens
ource.cirrus.com/ Stefan, could you please provide your Tested-by tag for this patch
Quoted 8 lines
I tried testing this patch, but I got a build failure in
drivers/spi/spi-dw-mmio.cwhen I use this patch on the spi for-next branch.(If I disable this driver, the patch works fine)
Thanks,
Stefan
Thank you for testing.
https://github.com/torvalds/linux/commit/2c8606040a808aa01d2d9e4f5b9332e87bb66377
this patch is causing build failure. As this patch is using the old interface( i.e., spi->chip_select) for accessing the chip_select variable so, build failure is observed on applying my patch series on top of this. I have already sent the below patch to fix this issue by replacing the spi->chip_select references with new set/get APIs & it's been acked as well.
https://lore.kernel.org/all/20230515133553.46mownenmclcauec@mobilestation/
If possible, could please retest by first applying the fix patch
https://lore.kernel.org/all/20230515133553.46mownenmclcauec@mobilestation/
on spi for-next branch followed by this patch series.
If it works fine, then please provide your Tested-by tag for this patch.
Regards,
Amit
Quoted 501 lines
drivers/spi/spi.c static int spi_dev_check(struct device *dev, void
Quoted 11 lines
--- drivers/spi/spi.c | 231 ++++++++++++++++++++++++++++------------ include/linux/spi/spi.h | 32 ++++-- 2 files changed, 189 insertions(+), 74 deletions(-)drivers/spi/spi.c index renamed from drivers/spi/spi.c +0
-0
9291b2a0e887..a793e56f6a21100644drivers/spi/spi.c +0
-0@@ -612,10 +612,24 @@ static int spi_dev_check(struct device *dev, void*data)
drivers/spi/spi.c static int spi_dev_check(struct device *dev, void *data)
Quoted 11 lines
drivers/spi/spi.c +4
-3{struct spi_device *spi =to_spi_device (dev);struct spi_device *new_spi = data; +int idx, nw_idx; -if (spi->controller == new_spi->controller && -spi_get_chipselect (spi,0 ) ==spi_get_chipselect (new_spi,0 )) -return -EBUSY ; +if (spi->controller == new_spi->controller) { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { + for (nw_idx = 0; nw_idx < SPI_CS_CNT_MAX;nw_idx++) {
drivers/spi/spi.c static int spi_dev_check(struct device *dev, void · line 621
Quoted 2 lines
drivers/spi/spi.c +2
-0+ if ((idx != 0 && !spi_get_chipselect(spi, idx)) || + (nw_idx != 0 && !spi_get_chipselect(spi,
nw_idx))) {drivers/spi/spi.c static int spi_dev_check(struct device *dev, void *data)
Quoted 5 lines
drivers/spi/spi.c +5
-0+continue ; + }else if (spi_get_chipselect (spi, idx) == +spi_get_chipselect (new_spi, nw_idx)) { + dev_err(dev, + "chipselect %d already inuse\n",
drivers/spi/spi.c static int spi_dev_check(struct device *dev, void · line 627
Quoted 1 line
drivers/spi/spi.c +1
-0+ spi_get_chipselect(new_spi,
nw_idx));Quoted 27 lines
drivers/spi/spi.c +7
-3+return -EBUSY ; + } + } + } + }return 0 ; }@@ -629,7 +643,7 @@ static int __spi_add_device(struct spi_device *spi) {struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; -int status; +int status, idx;/* * We need to make sure there's no other device with this @@ -638,8 +652,6 @@ static int __spi_add_device(struct spi_device *spi) */ status =bus_for_each_dev (&spi_bus_type,NULL , spi, spi_dev_check);if (status) { -dev_err (dev,"chipselect %d already in use\n" , -spi_get_chipselect (spi,0 ));return status; }drivers/spi/spi.c static int __spi_add_device(struct spi_device *spi) · line 653
Quoted 5 lines
drivers/spi/spi.c +0
-2@@ -649,8 +661,13 @@ static int __spi_add_device(struct spi_device *spi)return -ENODEV ; } -if (ctlr->cs_gpiods) - spi_set_csgpiod(spi, 0, ctlr->cs_gpiods[spi_get_chipselect(spi,0)]);
Quoted 17 lines
drivers/spi/spi.c +7
-0+if (ctlr->cs_gpiods) { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +if (!(idx !=0 && !spi_get_chipselect (spi, idx))) +spi_set_csgpiod (spi, idx, + ctlr- cs_gpiods[spi_get_chipselect (spi, idx)]); + } + }/* * Drivers may modify this initial i/o setup, but will @@ -690,13
+707,15 @@ intspi_add_device(struct spi_device *spi)
{
structspi_controller*ctlr =spi->controller;
struct device *dev =ctlr->dev.parent;drivers/spi/spi.c +1
-1-int status; +int status, idx;drivers/spi/spi.c int spi_add_device(struct spi_device *spi)
Quoted 10 lines
drivers/spi/spi.c +4
-5-/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { -dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +/* Chipselects are numbered 0..max; validate. */ +if (spi_get_chipselect (spi, idx) >= ctlr->num_chipselect) { + dev_err(dev, "cs%d >= max %d\n",
spi_get_chipselect(spi, idx),drivers/spi/spi.c static int spi_add_device_locked(struct spi_device
Quoted 7 lines
drivers/spi/spi.c +3
-0+ ctlr->num_chipselect); +return -EINVAL ; + } }/* Set the bus ID string */ @@ -713,12 +732,15 @@ static int spi_add_device_locked(struct spi_device*spi)
Quoted 4 lines
drivers/spi/spi.c +1
-0{struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; +int idx;drivers/spi/spi.c static int spi_add_device_locked(struct spi_device *spi)
Quoted 10 lines
drivers/spi/spi.c +4
-5-/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { -dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +/* Chipselects are numbered 0..max; validate. */ +if (spi_get_chipselect (spi, idx) >= ctlr->num_chipselect) { + dev_err(dev, "cs%d >= max %d\n",
spi_get_chipselect(spi, idx),drivers/spi/spi.c static void spi_res_release(struct spi_controller
Quoted 7 lines
drivers/spi/spi.c +3
-0+ ctlr->num_chipselect); +return -EINVAL ; + } }/* Set the bus ID string */ @@ -966,58 +988,122 @@ static void spi_res_release(struct spi_controller*ctlr, struct
spi_message*mesdrivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 13 lines
drivers/spi/spi.c +4
-3static void spi_set_cs (struct spi_device *spi,bool enable,bool force) {bool activate = enable; +u32 cs_num =0 ; +int idx;/* - * Avoid calling into the driver (or doing delays) if the chip select - * isn't actually changing from the last time this was called. +* In parallel mode all the chip selects are asserted/de-asserted +* at once */ - if (!force && ((enable && spi->controller->last_cs ==
spi_get_chipselect(spi, 0)) ||drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 975
Quoted 1 line
drivers/spi/spi.c +0
-1- (!enable && spi->controller->last_cs !=
spi_get_chipselect(spi, 0))) &&drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 976
Quoted 1 line
drivers/spi/spi.c +0
-1- (spi->controller->last_cs_mode_high == (spi->mode &
SPI_CS_HIGH)))drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 4 lines
drivers/spi/spi.c +1
-3-return ; - -trace_spi_set_cs (spi, activate); + if ((spi->cs_index_mask & SPI_PARALLEL_CS_MASK) ==
SPI_PARALLEL_CS_MASK) {drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 999
Quoted 1 line
drivers/spi/spi.c +1
-0+ spi->controller->last_cs_mode_high = spi->mode &
SPI_CS_HIGH;drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1001
Quoted 2 lines
drivers/spi/spi.c +2
-0+ + if ((spi_get_csgpiod(spi, 0) || !spi->controller->set_cs_timing)&& !activate)
drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 9 lines
drivers/spi/spi.c +9
-0+spi_delay_exec (&spi->cs_hold,NULL ); + +if (spi->mode &SPI_CS_HIGH ) + enable = !enable; + +if (spi_get_csgpiod (spi,0 ) &&spi_get_csgpiod (spi,1 )) { +if (!(spi->mode &SPI_NO_CS )) { +/* +* Historically ACPI has no means of the GPIO polarity and
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1011
Quoted 1 line
drivers/spi/spi.c +1
-0+* thus the SPISerialBus() resource defines it on the per-chip
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1012
Quoted 1 line
drivers/spi/spi.c +1
-0+* basis. In order to avoid a chain of negations, the GPIO
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1013
Quoted 1 line
drivers/spi/spi.c +1
-0+* polarity is considered being Active High. Even for the cases
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1014
Quoted 1 line
drivers/spi/spi.c +1
-0+* when _DSD() is involved (in the updated versions of ACPI)
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1015
Quoted 1 line
drivers/spi/spi.c +1
-0+* the GPIO CS polarity must be defined Active High to avoid
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1016
Quoted 1 line
drivers/spi/spi.c +1
-0+* ambiguity. That's why we use enable, that takes
SPI_CS_HIGHdrivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 4 lines
drivers/spi/spi.c +4
-0+* into account. +*/ +if (has_acpi_companion (&spi->dev)) { + for (idx = 0; idx < SPI_CS_CNT_MAX;idx++)
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1021
Quoted 1 line
drivers/spi/spi.c +1
-0+gpiod_set_value_cansleep(spi_get_csgpiod(spi, idx),
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1022
Quoted 1 line
drivers/spi/spi.c +1
-0+!enable);
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1024
Quoted 2 lines
drivers/spi/spi.c +2
-0+ }else { + for (idx = 0; idx < SPI_CS_CNT_MAX;idx++)
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1025
Quoted 1 line
drivers/spi/spi.c +1
-0+/* Polarity handled by GPIO library */
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1026
Quoted 1 line
drivers/spi/spi.c +1
-0+gpiod_set_value_cansleep(spi_get_csgpiod(spi, idx),
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1027
Quoted 1 line
drivers/spi/spi.c +1
-0+activate);
drivers/spi/spi.c static int spi_dev_check(struct device *dev, void *data)
Quoted 3 lines
drivers/spi/spi.c +3
-0+ } + } +/* Some SPI masters need both GPIO CS &
slave_select*/Quoted 9 lines
drivers/spi/spi.c +6
-2+if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && + spi->controller->set_cs) + spi->controller->set_cs (spi, !enable); + }else if (spi->controller->set_cs) { + spi->controller->set_cs (spi, !enable); + } - spi->controller->last_cs = enable ?spi_get_chipselect (spi,0 ) :-1 ; - spi->controller->last_cs_mode_high = spi->mode &SPI_CS_HIGH ;drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 10 lines
drivers/spi/spi.c +8
-1+if (spi_get_csgpiod (spi,0 ) ||spi_get_csgpiod (spi,1 ) || + !spi->controller->set_cs_timing) { +if (activate) +spi_delay_exec (&spi->cs_setup,NULL ); +else +spi_delay_exec (&spi->cs_inactive,NULL ); + } + }else { - if ((spi_get_csgpiod(spi, 0) || !spi->controller->set_cs_timing) &&!activate)
drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 8 lines
drivers/spi/spi.c +4
-3-spi_delay_exec (&spi->cs_hold,NULL ); +if (spi->cs_index_mask) + cs_num =ffs (spi->cs_index_mask) -1 ; -if (spi->mode &SPI_CS_HIGH ) - enable = !enable; +/* +* Avoid calling into the driver (or doing delays) if the chip select
drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 13 lines
drivers/spi/spi.c +13
-0+* isn't actually changing from the last time this was called. +*/ +if (!force && ((enable && spi->controller->last_cs == +spi_get_chipselect (spi, cs_num)) || + (!enable && spi->controller->last_cs != +spi_get_chipselect (spi, cs_num))) && + (spi->controller->last_cs_mode_high == + (spi->mode &SPI_CS_HIGH ))) +return ; + +trace_spi_set_cs (spi, activate); + + spi->controller->last_cs = enable ? spi_get_chipselect(spi,
cs_num) : -1;drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1065
Quoted 1 line
drivers/spi/spi.c +1
-0+ spi->controller->last_cs_mode_high = spi->mode &
SPI_CS_HIGH;drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 12 lines
drivers/spi/spi.c +11
-0+ +if ((spi_get_csgpiod (spi, cs_num) || !spi->controller- set_cs_timing) && !activate) +spi_delay_exec (&spi->cs_hold,NULL ); + +if (spi->mode &SPI_CS_HIGH ) + enable = !enable; + +if (spi_get_csgpiod (spi, cs_num)) { +if (!(spi->mode &SPI_NO_CS )) { +/* +* Historically ACPI has no means of the GPIO polarity and
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1078
Quoted 1 line
drivers/spi/spi.c +1
-0+* thus the SPISerialBus() resource defines it on the per-chip
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1079
Quoted 1 line
drivers/spi/spi.c +1
-0+* basis. In order to avoid a chain of negations, the GPIO
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1080
Quoted 1 line
drivers/spi/spi.c +1
-0+* polarity is considered being Active High. Even for the cases
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1081
Quoted 1 line
drivers/spi/spi.c +1
-0+* when _DSD() is involved (in the updated versions of ACPI)
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1082
Quoted 1 line
drivers/spi/spi.c +1
-0+* the GPIO CS polarity must be defined Active High to avoid
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1083
Quoted 1 line
drivers/spi/spi.c +1
-0+* ambiguity. That's why we use enable, that takes
SPI_CS_HIGHdrivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 4 lines
drivers/spi/spi.c +4
-0+* into account. +*/ +if (has_acpi_companion (&spi->dev)) +gpiod_set_value_cansleep(spi_get_csgpiod(spi,
cs_num),drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 4 lines
drivers/spi/spi.c +4
-0+ !enable); + else +/* Polarity handled by GPIO library */ +gpiod_set_value_cansleep(spi_get_csgpiod(spi,
cs_num),drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 3 lines
drivers/spi/spi.c +3
-0+ activate); + } +/* Some SPI masters need both GPIO CS &
slave_select*/drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 11 lines
drivers/spi/spi.c +6
-4+if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && + spi->controller->set_cs) + spi->controller->set_cs (spi, !enable); + }else if (spi->controller->set_cs) { + spi->controller->set_cs (spi, !enable); + } -if (spi_get_csgpiod (spi,0 )) { -if (!(spi->mode &SPI_NO_CS )) { -/* -* Historically ACPI has no means of the GPIO polarity and
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 995
Quoted 1 line
drivers/spi/spi.c +0
-1-* thus the SPISerialBus() resource defines it on the per-chip
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 996
Quoted 1 line
drivers/spi/spi.c +0
-1-* basis. In order to avoid a chain of negations, the GPIO
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 997
Quoted 1 line
drivers/spi/spi.c +0
-1-* polarity is considered being Active High. Even for the cases
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 998
Quoted 1 line
drivers/spi/spi.c +0
-1-* when _DSD() is involved (in the updated versions of ACPI)
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 999
Quoted 1 line
drivers/spi/spi.c +0
-1-* the GPIO CS polarity must be defined Active High to avoid
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1000
Quoted 1 line
drivers/spi/spi.c +0
-1-* ambiguity. That's why we use enable, that takes
SPI_CS_HIGHdrivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes · line 1015
Quoted 4 lines
drivers/spi/spi.c +0
-4-* into account. -*/ -if (has_acpi_companion (&spi->dev)) -gpiod_set_value_cansleep(spi_get_csgpiod(spi, 0), !enable);drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes · line 1015
Quoted 7 lines
drivers/spi/spi.c +3
-2+if (spi_get_csgpiod (spi, cs_num) || !spi->controller- set_cs_timing) { +if (activate) +spi_delay_exec (&spi->cs_setup,NULL );else -/* Polarity handled by GPIO library */ -gpiod_set_value_cansleep(spi_get_csgpiod(spi, 0), activate);drivers/spi/spi.c static void of_spi_parse_dt_cs_delay(struct
Quoted 19 lines
drivers/spi/spi.c +1
-13+spi_delay_exec (&spi->cs_inactive,NULL ); } -/* Some SPI masters need both GPIO CS & slave_select */ -if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && - spi->controller->set_cs) - spi->controller->set_cs (spi, !enable); - }else if (spi->controller->set_cs) { - spi->controller->set_cs (spi, !enable); - } - -if (spi_get_csgpiod (spi,0 ) || !spi->controller->set_cs_timing) { -if (activate) -spi_delay_exec (&spi->cs_setup,NULL ); -else -spi_delay_exec (&spi->cs_inactive,NULL ); }}drivers/spi/spi.c +0
-0@@ -2246,8 +2332,8 @@ static void of_spi_parse_dt_cs_delay(struct
device_node*nc,Quoted 15 lines
drivers/spi/spi.c +2
-2static int of_spi_parse_dt (struct spi_controller *ctlr,struct spi_device *spi,struct device_node *nc) { -u32 value; -int rc; +u32 value, cs[SPI_CS_CNT_MAX ] = {0 }; +int rc, idx;/* Mode (clock phase/polarity/etc.) */ if (of_property_read_bool(nc, "spi-cpha")) @@ -2320,13 +2406,21 @@static int of_spi_parse_dt(struct
spi_controller*ctlr, structspi_device*spi,
}/* Device address */
drivers/spi/spi.c +0
-1- rc =of_property_read_u32 (nc,"reg" , &value);drivers/spi/spi.c static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
Quoted 10 lines
drivers/spi/spi.c +6
-1-if (rc) { + rc =of_property_read_variable_u32_array (nc,"reg" , &cs[0 ],1 , +SPI_CS_CNT_MAX ); +if (rc <0 || rc > ctlr->num_chipselect) {dev_err (&ctlr->dev,"%pOF has no valid 'reg' property (%d)\n" , nc, rc);return rc; + }else if ((of_property_read_bool (nc,"parallel-memories" )) && + (!(ctlr->flags &SPI_CONTROLLER_MULTI_CS ))) { + dev_err(&ctlr->dev, "SPI controller doesn't support multiCS\n");
drivers/spi/spi.c static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
Quoted 11 lines
drivers/spi/spi.c +5
-2+return -EINVAL ; } -spi_set_chipselect (spi,0 , value); +for (idx =0 ; idx < rc; idx++) +spi_set_chipselect (spi, idx, cs[idx]); +/* By default set the spi->cs_index_mask as 1 */ + spi->cs_index_mask =0x01 ;/* Device speed */ if (!of_property_read_u32(nc, "spi-max-frequency", &value)) @@ -3905,7 +3999,8 @@ static int __spi_validate(struct spi_device *spi, struct
spi_message*message)Quoted 3 lines
*
cs_changeis set for each transfer.
*/
if ((spi->mode&SPI_CS_WORD) && (!(ctlr->mode_bits &
SPI_CS_WORD) ||include/linux/spi/spi.h extern void
Quoted 22 lines
drivers/spi/spi.c +2
-1- spi_get_csgpiod(spi, 0))) { + spi_get_csgpiod(spi, 0) || + spi_get_csgpiod(spi, 1))) {size_t maxsize;int ret;include/linux/spi/spi.h index renamed from include/linux/spi/spi.h +0
-0
cfe42f8cd7a4..d0f9a9a8b6d8100644include/linux/spi/spi.h +4
-0@@ -19,6 +19,11 @@#include <linux/acpi.h> #include <linux/u64_stats_sync.h> +/* Max no. of CS supported per spi device */ #define SPI_CS_CNT_MAX 2 + +/* chip select mask */ +#define SPI_PARALLEL_CS_MASK (BIT(0) | BIT(1))struct dma_chan ;struct software_node ;struct ptp_system_timestamp ;@@ -166,6 +171,7 @@ extern voidspi_transfer_cs_change_delay_exec(struct
spi_message*msg,Quoted 18 lines
include/linux/spi/spi.h +3
-1* deasserted. If @cs_change_delay is used from @spi_transfer, then the * two delays will be added up. * @pcpu_statistics: statistics for the spi_device +* @cs_index_mask: Bit mask of the active chipselect(s) in the +chipselect array * * A @spi_device is used to interchange data between an SPI slave * (usually a discrete chip) and CPU memory. @@ -181,7 +187,7 @@ struct spi_device {struct spi_controller *controller;struct spi_controller *master;/* Compatibility layer */ u32 max_speed_hz; -u8 chip_select; +u8 chip_select[SPI_CS_CNT_MAX ];u8 bits_per_word;bool rt;#define SPI_NO_TX BIT(31)/* No transmit wire */ include/linux/spi/spi.h struct spi_device { · line 221
Quoted 5 lines
include/linux/spi/spi.h +1
-1@@ -212,7 +218,7 @@ struct spi_device {void *controller_data;char modalias[SPI_NAME_SIZE ];const char *driver_override; -struct gpio_desc *cs_gpiod;/* Chip select gpio desc */ +struct gpio_desc *cs_gpiod[SPI_CS_CNT_MAX ];/* Chip select gpio desc */
Quoted 18 lines
include/linux/spi/spi.h +7
-0struct spi_delay word_delay;/* Inter-word delay */ /* CS delays */ struct spi_delay cs_setup;@@ -222,6 +228,13 @@ struct spi_device {/* The statistics */ struct spi_statistics __percpu *pcpu_statistics; +/* Bit mask of the chipselect(s) that the driver need to use from +* the chipselect array.When the controller is capable to handle +* multiple chip selects & memories are connected in parallel +* then more than one bit need to be set in cs_index_mask. +*/ + u32 cs_index_mask : SPI_CS_CNT_MAX; +/* * likely need more hooks for more protocol options affecting how * the controller talks to each chip, like: include/linux/spi/spi.h static inline void *spi_get_drvdata(const struct · line 298
Quoted 9 lines
include/linux/spi/spi.h +1
-1@@ -278,22 +291,22 @@ static inline void *spi_get_drvdata(const struct spi_device *spi)static inline u8 spi_get_chipselect (const struct spi_device *spi,u8 idx) { -return spi->chip_select; +return spi->chip_select[idx]; } static inline void spi_set_chipselect(struct spi_device *spi, u8 idx, u8chipselect)
include/linux/spi/spi.h static inline void *spi_get_drvdata(const struct spi_device *spi)
Quoted 6 lines
include/linux/spi/spi.h +1
-1{ - spi->chip_select = chipselect; + spi->chip_select[idx] = chipselect; } static inline struct gpio_desc *spi_get_csgpiod(const struct spi_device *spi,u8 idx)
include/linux/spi/spi.h static inline void *spi_get_drvdata(const struct spi_device *spi)
Quoted 6 lines
include/linux/spi/spi.h +1
-1{ -return spi->cs_gpiod; +return spi->cs_gpiod[idx]; } static inline void spi_set_csgpiod(struct spi_device *spi, u8 idx, struct
gpio_desc*csgpiod)include/linux/spi/spi.h extern struct spi_device
Quoted 7 lines
include/linux/spi/spi.h +1
-1{ - spi->cs_gpiod = csgpiod; + spi->cs_gpiod[idx] = csgpiod; }/**
include/linux/spi/spi.h +0
-0@@ -398,6 +411,8 @@ extern struct spi_device*spi_new_ancillary_device(struct
spi_device*spi, u8 chinclude/linux/spi/spi.h struct spi_controller { · line 581
Quoted 13 lines
include/linux/spi/spi.h +0
-0* @bus_lock_spinlock: spinlock for SPI bus locking * @bus_lock_mutex: mutex for exclusion of multiple callers * @bus_lock_flag: indicates that the SPI bus is locked for exclusive use
+ * @multi_cs_cap: indicates that the SPI Controller can assert/de-assert
+ * more than one chip select at once.
* @setup: updates the device mode and clocking records used by a
* device's SPI controller; protocol code may call this. This
* must fail if an unrecognized or unsupported mode is requested.include/linux/spi/spi.h +0
-0@@ -564,6 +579,11 @@ struct spi_controller {#define SPI_CONTROLLER_MUST_TX BIT(4)/* Requires tx */ #define SPI_MASTER_GPIO_SS BIT(5)/* GPIO CS must select slave */
Quoted 8 lines
include/linux/spi/spi.h +5
-0+/* +* The spi-controller has multi chip select capability and can +* assert/de-assert more than one chip select at once. +*/ +#define SPI_CONTROLLER_MULTI_CS BIT(6)/* Flag indicating if the allocation of this struct is devres-managed */ bool devm_allocated;
Stefan Binding
Tested-byRe: [PATCH V8 1/7] spi: Add stacked and parallel memories support in SPI core
Quoted 64 lines · Amit Kumar
Hello Stefan,
Quoted 46 lines
-----Original Message-----
From: Stefan Binding <[email protected]>
Sent: Thursday, May 11, 2023 10:20 PM
To: Mahapatra, Amit Kumar <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: git (AMD-Xilinx) <[email protected]>; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V8 1/7] spi: Add stacked and parallel memories support in SPI coreHi,
Quoted 21 lines · Amit Kumar Mahapatra
For supporting multiple CS the SPI device need to be aware of all the CS values. So, the "
chip_select" member in thespi_devicestructure is now an array that holds all the CS values.
spi_devicestructure now has a "cs_index_mask" member. This acts as an index to thechip_selectarray. If nth bit ofspi->cs_index_maskis set then the driver would assert spi->chip_select[n].In parallel mode all the chip selects are asserted/de-asserted simultaneously and each byte of data is stored in both devices, the even bits in one, the odd bits in the other. The split is automatically handled by the GQSPI controller. The GQSPI controller supports a maximum of two flashes connected in parallel mode. A
SPI_CONTROLLER_MULTI_CSflag bit is added in the spi controntroller flags, throughctlr->flagsthe spi core will make sure that the controller is capable of handling multiple chip selects at once.For supporting multiple CS via GPIO the
cs_gpiodmember of thespi_devicestructure is now an array that holds the gpio descriptor for each chipselect.Quoted 7 lines
Signed-off-by Amit Kumar Mahapatra <[email protected]>---
CS GPIO is not tested on our hardware but it has been tested by @Stefan
https://lore.kernel.org/all/3f148a0c-8885-0425-28f4-2a53937a388f@opens
ource.cirrus.com/ Stefan, could you please provide your Tested-by tag for this patchQuoted 8 lines
I tried testing this patch, but I got a build failure in
drivers/spi/spi-dw-mmio.cwhen I use this patch on the spi for-next branch.(If I disable this driver, the patch works fine)
Thanks,
Stefan
Thank you for testing.
https://github.com/torvalds/linux/commit/2c8606040a808aa01d2d9e4f5b9332e87bb66377
this patch is causing build failure. As this patch is using the oldinterface( i.e., spi->chip_select)for accessing thechip_selectvariable so, build failure is observed on applying my patch series on top of this. I have already sent the below patch to fix this issue by replacing thespi->chip_selectreferences with new set/get APIs & it's been acked as well.
https://lore.kernel.org/all/20230515133553.46mownenmclcauec@mobilestation/
Quoted 8 lines
If possible, could please retest by first applying the fix patch
https://lore.kernel.org/all/20230515133553.46mownenmclcauec@mobilestation/
on spi for-next branch followed by this patch series.If it works fine, then please provide your Tested-by tag for this patch.
Regards,
Amit
Quoted 500 lines
Quoted 500 lines
drivers/spi/spi.c static int spi_dev_check(struct device *dev, void
Quoted 10 lines
--- drivers/spi/spi.c | 231 ++++++++++++++++++++++++++++------------ include/linux/spi/spi.h | 32 ++++-- 2 files changed, 189 insertions(+), 74 deletions(-)drivers/spi/spi.c index renamed from drivers/spi/spi.c +0
-0
9291b2a0e887..a793e56f6a21100644drivers/spi/spi.c +0
-0@@ -612,10 +612,24 @@ static int spi_dev_check(struct device *dev, void*data)
drivers/spi/spi.c static int spi_dev_check(struct device *dev, void *data)
Quoted 11 lines
drivers/spi/spi.c +4
-3{struct spi_device *spi =to_spi_device (dev);struct spi_device *new_spi = data; +int idx, nw_idx; -if (spi->controller == new_spi->controller && -spi_get_chipselect (spi,0 ) ==spi_get_chipselect (new_spi,0 )) -return -EBUSY ; +if (spi->controller == new_spi->controller) { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { + for (nw_idx = 0; nw_idx < SPI_CS_CNT_MAX;nw_idx++) {
drivers/spi/spi.c static int spi_dev_check(struct device *dev, void · line 621
Quoted 2 lines
drivers/spi/spi.c +2
-0+ if ((idx != 0 && !spi_get_chipselect(spi, idx)) || + (nw_idx != 0 && !spi_get_chipselect(spi,
nw_idx))) {drivers/spi/spi.c static int spi_dev_check(struct device *dev, void *data)
Quoted 5 lines
drivers/spi/spi.c +5
-0+continue ; + }else if (spi_get_chipselect (spi, idx) == +spi_get_chipselect (new_spi, nw_idx)) { + dev_err(dev, + "chipselect %d already inuse\n",
drivers/spi/spi.c static int spi_dev_check(struct device *dev, void · line 627
Quoted 1 line
drivers/spi/spi.c +1
-0+ spi_get_chipselect(new_spi,
nw_idx));Quoted 27 lines
drivers/spi/spi.c +7
-3+return -EBUSY ; + } + } + } + }return 0 ; }@@ -629,7 +643,7 @@ static int __spi_add_device(struct spi_device *spi) {struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; -int status; +int status, idx;/* * We need to make sure there's no other device with this @@ -638,8 +652,6 @@ static int __spi_add_device(struct spi_device *spi) */ status =bus_for_each_dev (&spi_bus_type,NULL , spi, spi_dev_check);if (status) { -dev_err (dev,"chipselect %d already in use\n" , -spi_get_chipselect (spi,0 ));return status; }drivers/spi/spi.c static int __spi_add_device(struct spi_device *spi) · line 653
Quoted 5 lines
drivers/spi/spi.c +0
-2@@ -649,8 +661,13 @@ static int __spi_add_device(struct spi_device *spi)return -ENODEV ; } -if (ctlr->cs_gpiods) - spi_set_csgpiod(spi, 0, ctlr->cs_gpiods[spi_get_chipselect(spi,0)]);
Quoted 17 lines
drivers/spi/spi.c +7
-0+if (ctlr->cs_gpiods) { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +if (!(idx !=0 && !spi_get_chipselect (spi, idx))) +spi_set_csgpiod (spi, idx, + ctlr- cs_gpiods[spi_get_chipselect (spi, idx)]); + } + }/* * Drivers may modify this initial i/o setup, but will @@ -690,13
+707,15 @@ intspi_add_device(struct spi_device *spi){ struct spi_controller *ctlr = spi->controller; struct device *dev = ctlr->dev.parent;drivers/spi/spi.c +1
-1-int status; +int status, idx;drivers/spi/spi.c int spi_add_device(struct spi_device *spi)
Quoted 10 lines
drivers/spi/spi.c +4
-5-/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { -dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +/* Chipselects are numbered 0..max; validate. */ +if (spi_get_chipselect (spi, idx) >= ctlr->num_chipselect) { + dev_err(dev, "cs%d >= max %d\n",
spi_get_chipselect(spi, idx),drivers/spi/spi.c static int spi_add_device_locked(struct spi_device
Quoted 7 lines
drivers/spi/spi.c +3
-0+ ctlr->num_chipselect); +return -EINVAL ; + } }/* Set the bus ID string */ @@ -713,12 +732,15 @@ static int spi_add_device_locked(struct spi_device*spi)
Quoted 4 lines
drivers/spi/spi.c +1
-0{struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; +int idx;drivers/spi/spi.c static int spi_add_device_locked(struct spi_device *spi)
Quoted 10 lines
drivers/spi/spi.c +4
-5-/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { -dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +/* Chipselects are numbered 0..max; validate. */ +if (spi_get_chipselect (spi, idx) >= ctlr->num_chipselect) { + dev_err(dev, "cs%d >= max %d\n",
spi_get_chipselect(spi, idx),drivers/spi/spi.c static void spi_res_release(struct spi_controller
Quoted 7 lines
drivers/spi/spi.c +3
-0+ ctlr->num_chipselect); +return -EINVAL ; + } }/* Set the bus ID string */ @@ -966,58 +988,122 @@ static void spi_res_release(struct spi_controller*ctlr, struct
spi_message*mesdrivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 13 lines
drivers/spi/spi.c +4
-3static void spi_set_cs (struct spi_device *spi,bool enable,bool force) {bool activate = enable; +u32 cs_num =0 ; +int idx;/* - * Avoid calling into the driver (or doing delays) if the chip select - * isn't actually changing from the last time this was called. +* In parallel mode all the chip selects are asserted/de-asserted +* at once */ - if (!force && ((enable && spi->controller->last_cs ==
spi_get_chipselect(spi, 0)) ||drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 975
Quoted 1 line
drivers/spi/spi.c +0
-1- (!enable && spi->controller->last_cs !=
spi_get_chipselect(spi, 0))) &&drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 976
Quoted 1 line
drivers/spi/spi.c +0
-1- (spi->controller->last_cs_mode_high == (spi->mode &
SPI_CS_HIGH)))drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 4 lines
drivers/spi/spi.c +1
-3-return ; - -trace_spi_set_cs (spi, activate); + if ((spi->cs_index_mask & SPI_PARALLEL_CS_MASK) ==
SPI_PARALLEL_CS_MASK) {drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 999
Quoted 1 line
drivers/spi/spi.c +1
-0+ spi->controller->last_cs_mode_high = spi->mode &
SPI_CS_HIGH;drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1001
Quoted 2 lines
drivers/spi/spi.c +2
-0+ + if ((spi_get_csgpiod(spi, 0) || !spi->controller->set_cs_timing)&& !activate)
drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 9 lines
drivers/spi/spi.c +9
-0+spi_delay_exec (&spi->cs_hold,NULL ); + +if (spi->mode &SPI_CS_HIGH ) + enable = !enable; + +if (spi_get_csgpiod (spi,0 ) &&spi_get_csgpiod (spi,1 )) { +if (!(spi->mode &SPI_NO_CS )) { +/* +* Historically ACPI has no means of the GPIO polarity and
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1011
Quoted 1 line
drivers/spi/spi.c +1
-0+* thus the SPISerialBus() resource defines it on the per-chip
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1012
Quoted 1 line
drivers/spi/spi.c +1
-0+* basis. In order to avoid a chain of negations, the GPIO
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1013
Quoted 1 line
drivers/spi/spi.c +1
-0+* polarity is considered being Active High. Even for the cases
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1014
Quoted 1 line
drivers/spi/spi.c +1
-0+* when _DSD() is involved (in the updated versions of ACPI)
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1015
Quoted 1 line
drivers/spi/spi.c +1
-0+* the GPIO CS polarity must be defined Active High to avoid
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1016
Quoted 1 line
drivers/spi/spi.c +1
-0+* ambiguity. That's why we use enable, that takes
SPI_CS_HIGHdrivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 4 lines
drivers/spi/spi.c +4
-0+* into account. +*/ +if (has_acpi_companion (&spi->dev)) { + for (idx = 0; idx < SPI_CS_CNT_MAX;idx++)
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1021
Quoted 1 line
drivers/spi/spi.c +1
-0+gpiod_set_value_cansleep(spi_get_csgpiod(spi, idx),
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1022
Quoted 1 line
drivers/spi/spi.c +1
-0+!enable);
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1024
Quoted 2 lines
drivers/spi/spi.c +2
-0+ }else { + for (idx = 0; idx < SPI_CS_CNT_MAX;idx++)
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1025
Quoted 1 line
drivers/spi/spi.c +1
-0+/* Polarity handled by GPIO library */
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1026
Quoted 1 line
drivers/spi/spi.c +1
-0+gpiod_set_value_cansleep(spi_get_csgpiod(spi, idx),
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1027
Quoted 1 line
drivers/spi/spi.c +1
-0+activate);
drivers/spi/spi.c static int spi_dev_check(struct device *dev, void *data)
Quoted 3 lines
drivers/spi/spi.c +3
-0+ } + } +/* Some SPI masters need both GPIO CS &
slave_select*/Quoted 9 lines
drivers/spi/spi.c +6
-2+if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && + spi->controller->set_cs) + spi->controller->set_cs (spi, !enable); + }else if (spi->controller->set_cs) { + spi->controller->set_cs (spi, !enable); + } - spi->controller->last_cs = enable ?spi_get_chipselect (spi,0 ) :-1 ; - spi->controller->last_cs_mode_high = spi->mode &SPI_CS_HIGH ;drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 10 lines
drivers/spi/spi.c +8
-1+if (spi_get_csgpiod (spi,0 ) ||spi_get_csgpiod (spi,1 ) || + !spi->controller->set_cs_timing) { +if (activate) +spi_delay_exec (&spi->cs_setup,NULL ); +else +spi_delay_exec (&spi->cs_inactive,NULL ); + } + }else { - if ((spi_get_csgpiod(spi, 0) || !spi->controller->set_cs_timing) &&!activate)
drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 8 lines
drivers/spi/spi.c +4
-3-spi_delay_exec (&spi->cs_hold,NULL ); +if (spi->cs_index_mask) + cs_num =ffs (spi->cs_index_mask) -1 ; -if (spi->mode &SPI_CS_HIGH ) - enable = !enable; +/* +* Avoid calling into the driver (or doing delays) if the chip select
drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 13 lines
drivers/spi/spi.c +13
-0+* isn't actually changing from the last time this was called. +*/ +if (!force && ((enable && spi->controller->last_cs == +spi_get_chipselect (spi, cs_num)) || + (!enable && spi->controller->last_cs != +spi_get_chipselect (spi, cs_num))) && + (spi->controller->last_cs_mode_high == + (spi->mode &SPI_CS_HIGH ))) +return ; + +trace_spi_set_cs (spi, activate); + + spi->controller->last_cs = enable ? spi_get_chipselect(spi,
cs_num) : -1;drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1065
Quoted 1 line
drivers/spi/spi.c +1
-0+ spi->controller->last_cs_mode_high = spi->mode &
SPI_CS_HIGH;drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 12 lines
drivers/spi/spi.c +11
-0+ +if ((spi_get_csgpiod (spi, cs_num) || !spi->controller- set_cs_timing) && !activate) +spi_delay_exec (&spi->cs_hold,NULL ); + +if (spi->mode &SPI_CS_HIGH ) + enable = !enable; + +if (spi_get_csgpiod (spi, cs_num)) { +if (!(spi->mode &SPI_NO_CS )) { +/* +* Historically ACPI has no means of the GPIO polarity and
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1078
Quoted 1 line
drivers/spi/spi.c +1
-0+* thus the SPISerialBus() resource defines it on the per-chip
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1079
Quoted 1 line
drivers/spi/spi.c +1
-0+* basis. In order to avoid a chain of negations, the GPIO
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1080
Quoted 1 line
drivers/spi/spi.c +1
-0+* polarity is considered being Active High. Even for the cases
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1081
Quoted 1 line
drivers/spi/spi.c +1
-0+* when _DSD() is involved (in the updated versions of ACPI)
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1082
Quoted 1 line
drivers/spi/spi.c +1
-0+* the GPIO CS polarity must be defined Active High to avoid
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1083
Quoted 1 line
drivers/spi/spi.c +1
-0+* ambiguity. That's why we use enable, that takes
SPI_CS_HIGHdrivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 4 lines
drivers/spi/spi.c +4
-0+* into account. +*/ +if (has_acpi_companion (&spi->dev)) +gpiod_set_value_cansleep(spi_get_csgpiod(spi,
cs_num),drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 4 lines
drivers/spi/spi.c +4
-0+ !enable); + else +/* Polarity handled by GPIO library */ +gpiod_set_value_cansleep(spi_get_csgpiod(spi,
cs_num),drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 3 lines
drivers/spi/spi.c +3
-0+ activate); + } +/* Some SPI masters need both GPIO CS &
slave_select*/drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 11 lines
drivers/spi/spi.c +6
-4+if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && + spi->controller->set_cs) + spi->controller->set_cs (spi, !enable); + }else if (spi->controller->set_cs) { + spi->controller->set_cs (spi, !enable); + } -if (spi_get_csgpiod (spi,0 )) { -if (!(spi->mode &SPI_NO_CS )) { -/* -* Historically ACPI has no means of the GPIO polarity and
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 995
Quoted 1 line
drivers/spi/spi.c +0
-1-* thus the SPISerialBus() resource defines it on the per-chip
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 996
Quoted 1 line
drivers/spi/spi.c +0
-1-* basis. In order to avoid a chain of negations, the GPIO
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 997
Quoted 1 line
drivers/spi/spi.c +0
-1-* polarity is considered being Active High. Even for the cases
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 998
Quoted 1 line
drivers/spi/spi.c +0
-1-* when _DSD() is involved (in the updated versions of ACPI)
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 999
Quoted 1 line
drivers/spi/spi.c +0
-1-* the GPIO CS polarity must be defined Active High to avoid
drivers/spi/spi.c static void spi_res_release(struct spi_controller · line 1000
Quoted 1 line
drivers/spi/spi.c +0
-1-* ambiguity. That's why we use enable, that takes
SPI_CS_HIGHdrivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes · line 1015
Quoted 4 lines
drivers/spi/spi.c +0
-4-* into account. -*/ -if (has_acpi_companion (&spi->dev)) -gpiod_set_value_cansleep(spi_get_csgpiod(spi, 0), !enable);drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes · line 1015
Quoted 7 lines
drivers/spi/spi.c +3
-2+if (spi_get_csgpiod (spi, cs_num) || !spi->controller- set_cs_timing) { +if (activate) +spi_delay_exec (&spi->cs_setup,NULL );else -/* Polarity handled by GPIO library */ -gpiod_set_value_cansleep(spi_get_csgpiod(spi, 0), activate);drivers/spi/spi.c static void of_spi_parse_dt_cs_delay(struct
Quoted 19 lines
drivers/spi/spi.c +1
-13+spi_delay_exec (&spi->cs_inactive,NULL ); } -/* Some SPI masters need both GPIO CS & slave_select */ -if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && - spi->controller->set_cs) - spi->controller->set_cs (spi, !enable); - }else if (spi->controller->set_cs) { - spi->controller->set_cs (spi, !enable); - } - -if (spi_get_csgpiod (spi,0 ) || !spi->controller->set_cs_timing) { -if (activate) -spi_delay_exec (&spi->cs_setup,NULL ); -else -spi_delay_exec (&spi->cs_inactive,NULL ); }}drivers/spi/spi.c +0
-0@@ -2246,8 +2332,8 @@ static void of_spi_parse_dt_cs_delay(struct
device_node*nc,Quoted 15 lines
drivers/spi/spi.c +2
-2static int of_spi_parse_dt (struct spi_controller *ctlr,struct spi_device *spi,struct device_node *nc) { -u32 value; -int rc; +u32 value, cs[SPI_CS_CNT_MAX ] = {0 }; +int rc, idx;/* Mode (clock phase/polarity/etc.) */ if (of_property_read_bool(nc, "spi-cpha")) @@ -2320,13 +2406,21 @@static int of_spi_parse_dt(struct
spi_controller*ctlr, structspi_device*spi,
}/* Device address */drivers/spi/spi.c +0
-1- rc =of_property_read_u32 (nc,"reg" , &value);drivers/spi/spi.c static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
Quoted 10 lines
drivers/spi/spi.c +6
-1-if (rc) { + rc =of_property_read_variable_u32_array (nc,"reg" , &cs[0 ],1 , +SPI_CS_CNT_MAX ); +if (rc <0 || rc > ctlr->num_chipselect) {dev_err (&ctlr->dev,"%pOF has no valid 'reg' property (%d)\n" , nc, rc);return rc; + }else if ((of_property_read_bool (nc,"parallel-memories" )) && + (!(ctlr->flags &SPI_CONTROLLER_MULTI_CS ))) { + dev_err(&ctlr->dev, "SPI controller doesn't support multiCS\n");
drivers/spi/spi.c static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
Quoted 11 lines
drivers/spi/spi.c +5
-2+return -EINVAL ; } -spi_set_chipselect (spi,0 , value); +for (idx =0 ; idx < rc; idx++) +spi_set_chipselect (spi, idx, cs[idx]); +/* By default set the spi->cs_index_mask as 1 */ + spi->cs_index_mask =0x01 ;/* Device speed */ if (!of_property_read_u32(nc, "spi-max-frequency", &value)) @@ -3905,7 +3999,8 @@ static int __spi_validate(struct spi_device *spi, struct
spi_message*message)Quoted 3 lines
* cs_change is set for each transfer. */ if ((spi->mode & SPI_CS_WORD) && (!(ctlr->mode_bits &
SPI_CS_WORD) ||include/linux/spi/spi.h extern void
Quoted 22 lines
drivers/spi/spi.c +2
-1- spi_get_csgpiod(spi, 0))) { + spi_get_csgpiod(spi, 0) || + spi_get_csgpiod(spi, 1))) {size_t maxsize;int ret;include/linux/spi/spi.h index renamed from include/linux/spi/spi.h +0
-0
cfe42f8cd7a4..d0f9a9a8b6d8100644include/linux/spi/spi.h +4
-0@@ -19,6 +19,11 @@#include <linux/acpi.h> #include <linux/u64_stats_sync.h> +/* Max no. of CS supported per spi device */ #define SPI_CS_CNT_MAX 2 + +/* chip select mask */ +#define SPI_PARALLEL_CS_MASK (BIT(0) | BIT(1))struct dma_chan ;struct software_node ;struct ptp_system_timestamp ;@@ -166,6 +171,7 @@ extern voidspi_transfer_cs_change_delay_exec(struct
spi_message*msg,Quoted 18 lines
include/linux/spi/spi.h +3
-1* deasserted. If @cs_change_delay is used from @spi_transfer, then the * two delays will be added up. * @pcpu_statistics: statistics for the spi_device +* @cs_index_mask: Bit mask of the active chipselect(s) in the +chipselect array * * A @spi_device is used to interchange data between an SPI slave * (usually a discrete chip) and CPU memory. @@ -181,7 +187,7 @@ struct spi_device {struct spi_controller *controller;struct spi_controller *master;/* Compatibility layer */ u32 max_speed_hz; -u8 chip_select; +u8 chip_select[SPI_CS_CNT_MAX ];u8 bits_per_word;bool rt;#define SPI_NO_TX BIT(31)/* No transmit wire */ include/linux/spi/spi.h struct spi_device { · line 221
Quoted 5 lines
include/linux/spi/spi.h +1
-1@@ -212,7 +218,7 @@ struct spi_device {void *controller_data;char modalias[SPI_NAME_SIZE ];const char *driver_override; -struct gpio_desc *cs_gpiod;/* Chip select gpio desc */ +struct gpio_desc *cs_gpiod[SPI_CS_CNT_MAX ];/* Chip select gpio desc */
Quoted 18 lines
include/linux/spi/spi.h +7
-0struct spi_delay word_delay;/* Inter-word delay */ /* CS delays */ struct spi_delay cs_setup;@@ -222,6 +228,13 @@ struct spi_device {/* The statistics */ struct spi_statistics __percpu *pcpu_statistics; +/* Bit mask of the chipselect(s) that the driver need to use from +* the chipselect array.When the controller is capable to handle +* multiple chip selects & memories are connected in parallel +* then more than one bit need to be set in cs_index_mask. +*/ + u32 cs_index_mask : SPI_CS_CNT_MAX; +/* * likely need more hooks for more protocol options affecting how * the controller talks to each chip, like: include/linux/spi/spi.h static inline void *spi_get_drvdata(const struct · line 298
Quoted 9 lines
include/linux/spi/spi.h +1
-1@@ -278,22 +291,22 @@ static inline void *spi_get_drvdata(const struct spi_device *spi)static inline u8 spi_get_chipselect (const struct spi_device *spi,u8 idx) { -return spi->chip_select; +return spi->chip_select[idx]; } static inline void spi_set_chipselect(struct spi_device *spi, u8 idx, u8chipselect)
include/linux/spi/spi.h static inline void *spi_get_drvdata(const struct spi_device *spi)
Quoted 6 lines
include/linux/spi/spi.h +1
-1{ - spi->chip_select = chipselect; + spi->chip_select[idx] = chipselect; } static inline struct gpio_desc *spi_get_csgpiod(const struct spi_device *spi,u8 idx)
include/linux/spi/spi.h static inline void *spi_get_drvdata(const struct spi_device *spi)
Quoted 6 lines
include/linux/spi/spi.h +1
-1{ -return spi->cs_gpiod; +return spi->cs_gpiod[idx]; } static inline void spi_set_csgpiod(struct spi_device *spi, u8 idx, struct
gpio_desc*csgpiod)include/linux/spi/spi.h extern struct spi_device
Quoted 7 lines
include/linux/spi/spi.h +1
-1{ - spi->cs_gpiod = csgpiod; + spi->cs_gpiod[idx] = csgpiod; }/**include/linux/spi/spi.h +0
-0@@ -398,6 +411,8 @@ extern struct spi_device*spi_new_ancillary_device(struct
spi_device*spi, u8 chinclude/linux/spi/spi.h struct spi_controller { · line 581
Quoted 13 lines
include/linux/spi/spi.h +0
-0* @bus_lock_spinlock: spinlock for SPI bus locking * @bus_lock_mutex: mutex for exclusion of multiple callers * @bus_lock_flag: indicates that the SPI bus is locked for exclusive use
+ * @multi_cs_cap: indicates that the SPI Controller can assert/de-assert
+ * more than one chip select at once.
* @setup: updates the device mode and clocking records used by a
* device's SPI controller; protocol code may call this. This
* must fail if an unrecognized or unsupported mode is requested.include/linux/spi/spi.h +0
-0@@ -564,6 +579,11 @@ struct spi_controller {#define SPI_CONTROLLER_MUST_TX BIT(4)/* Requires tx */ #define SPI_MASTER_GPIO_SS BIT(5)/* GPIO CS must select slave */
Quoted 8 lines
include/linux/spi/spi.h +5
-0+/* +* The spi-controller has multi chip select capability and can +* assert/de-assert more than one chip select at once. +*/ +#define SPI_CONTROLLER_MULTI_CS BIT(6)/* Flag indicating if the allocation of this struct is devres-managed */ bool devm_allocated;
Pratyush Yadav
maintainerRe: [PATCH V8 1/7] spi: Add stacked and parallel memories support in SPI core
In reply to Amit Kumar MahapatraHi Amit,
I did not get a chance to look at all the old comments in the previous versions. So apologies in advance if I comment something that has already been mentioned before.
Quoted 8 lines · Amit Kumar Mahapatra
For supporting multiple CS the SPI device need to be aware of all the CS values. So, the "
chip_select" member in thespi_devicestructure is now an array that holds all the CS values.
spi_devicestructure now has a "cs_index_mask" member. This acts as an index to thechip_selectarray. If nth bit ofspi->cs_index_maskis set then the driver would assert spi->chip_select[n].
Quoted 6 lines
In parallel mode all the chip selects are asserted/de-asserted simultaneously and each byte of data is stored in both devices, the even bits in one, the odd bits in the other. The split is automatically handled by the GQSPI controller. The GQSPI controller supports a maximum of two flashes connected in parallel mode. A
SPI_CONTROLLER_MULTI_CSflag bit is added in the spi controntroller flags, throughctlr->flagsthe spi core
Typo: s/controntroller/controller/
Quoted 6 lines
will make sure that the controller is capable of handling multiple chip selects at once.
For supporting multiple CS via GPIO the
cs_gpiodmember of thespi_devicestructure is now an array that holds the gpio descriptor for each chipselect.
General comment: For large changes, it is useful to describe a high-level overview of your new design so reviewers and future readers can get a mental model of what is going on. I did not see anything of that sort in this series.
Quoted 20 lines
Signed-off-by Amit Kumar Mahapatra <[email protected]>---
CS GPIO is not tested on our hardware but it has been tested by @Stefan
https://lore.kernel.org/all/[email protected]/
Stefan, could you please provide your Tested-by tag for this patch--- drivers/spi/spi.c | 231 ++++++++++++++++++++++++++++------------ include/linux/spi/spi.h | 32 ++++-- 2 files changed, 189 insertions(+), 74 deletions(-)drivers/spi/spi.c +0
-0index
9291b2a0e887..a793e56f6a21100644drivers/spi/spi.c +0
-0@@ -612,10 +612,24 @@ static int spi_dev_check(struct device *dev, void *data) {struct spi_device *spi =to_spi_device (dev);struct spi_device *new_spi = data;
drivers/spi/spi.c static int spi_dev_check(struct device *dev, void *data) · line 621
Quoted 10 lines
drivers/spi/spi.c +6
-3+int idx, nw_idx; -if (spi->controller == new_spi->controller && -spi_get_chipselect (spi,0 ) ==spi_get_chipselect (new_spi,0 )) -return -EBUSY ; +if (spi->controller == new_spi->controller) { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +for (nw_idx =0 ; nw_idx <SPI_CS_CNT_MAX ; nw_idx++) { +if ((idx !=0 && !spi_get_chipselect (spi, idx)) || + (nw_idx !=0 && !spi_get_chipselect (spi, nw_idx))) {
Hmm, from what I can understand, spi->chipselect[i] gives the corresponding physical CS for logical CS i. So for example, if both old and new devices map logical CS 1 to physical CS 0, this would not detect the conflict.
What exactly are you trying to do here?
Quoted 24 lines
drivers/spi/spi.c +12
-1+continue ; + }else if (spi_get_chipselect (spi, idx) == +spi_get_chipselect (new_spi, nw_idx)) { +dev_err (dev, +"chipselect %d already in use\n" , +spi_get_chipselect (new_spi, nw_idx)); +return -EBUSY ; + } + } + } + }return 0 ; }@@ -629,7 +643,7 @@ static int __spi_add_device(struct spi_device *spi) {struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; -int status; +int status, idx;/* * We need to make sure there's no other device with this
drivers/spi/spi.c static int __spi_add_device(struct spi_device *spi) · line 642
Quoted 5 lines
drivers/spi/spi.c +0
-2@@ -638,8 +652,6 @@ static int __spi_add_device(struct spi_device *spi)*/ status =bus_for_each_dev (&spi_bus_type,NULL , spi, spi_dev_check);if (status) { -dev_err (dev,"chipselect %d already in use\n" , -spi_get_chipselect (spi,0 ));
Nitpick: No need for the braces around if anymore.
drivers/spi/spi.c static int __spi_add_device(struct spi_device *spi) · line 666
Quoted 12 lines
drivers/spi/spi.c +3
-2return status; }@@ -649,8 +661,13 @@ static int __spi_add_device(struct spi_device *spi)return -ENODEV ; } -if (ctlr->cs_gpiods) -spi_set_csgpiod (spi,0 , ctlr->cs_gpiods[spi_get_chipselect (spi,0 )]); +if (ctlr->cs_gpiods) { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +if (!(idx !=0 && !spi_get_chipselect (spi, idx)))
Again, I don't get why you do this. This would simply fail for any device that maps logical CS 1 to physical CS 0.
Quoted 16 lines
drivers/spi/spi.c +5
-3+spi_set_csgpiod (spi, idx, + ctlr->cs_gpiods[spi_get_chipselect (spi, idx)]); + } + }/* * Drivers may modify this initial i/o setup, but will @@ -690,13 +707,15 @@ int spi_add_device(struct spi_device *spi) {struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; -int status; +int status, idx; -/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) {
drivers/spi/spi.c int spi_add_device(struct spi_device *spi) · line 718
Quoted 10 lines
drivers/spi/spi.c +7
-3-dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +/* Chipselects are numbered 0..max; validate. */ +if (spi_get_chipselect (spi, idx) >= ctlr->num_chipselect) { +dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi, idx), + ctlr->num_chipselect); +return -EINVAL ; + }
Since this function is doing a bunch of sanity checks, I think you should also make sure multiple logical CS don't map to the same physical CS. For example, make sure that spi->chip_select[0] != spi->chip_select[1] and so on.
Quoted 11 lines
drivers/spi/spi.c +1
-2}/* Set the bus ID string */ @@ -713,12 +732,15 @@ static int spi_add_device_locked(struct spi_device *spi) {struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; +int idx; -/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) {
drivers/spi/spi.c static int spi_add_device_locked(struct spi_device *spi) · line 743
Quoted 10 lines
drivers/spi/spi.c +7
-3-dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +/* Chipselects are numbered 0..max; validate. */ +if (spi_get_chipselect (spi, idx) >= ctlr->num_chipselect) { +dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi, idx), + ctlr->num_chipselect); +return -EINVAL ; + }
As adding a new device gets more complex, we should stop duplicating code between here and spi_add_device(). So you should either move this code to another function and call it from both places or add a new parameter called "locked" and merge spi_add_device() and spi_add_device_locked(). I do not have string preferences for either, but I do like the latter a bit more.
Quoted 13 lines
drivers/spi/spi.c +2
-2}/* Set the bus ID string */ @@ -966,58 +988,122 @@ static void spi_res_release(struct spi_controller *ctlr, struct spi_message *messtatic void spi_set_cs (struct spi_device *spi,bool enable,bool force) {bool activate = enable; +u32 cs_num =0 ; +int idx;/* -* Avoid calling into the driver (or doing delays) if the chip select -* isn't actually changing from the last time this was called.
drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes · line 998
Quoted 10 lines
drivers/spi/spi.c +3
-6+* In parallel mode all the chip selects are asserted/de-asserted +* at once */ -if (!force && ((enable && spi->controller->last_cs ==spi_get_chipselect (spi,0 )) || - (!enable && spi->controller->last_cs !=spi_get_chipselect (spi,0 ))) && - (spi->controller->last_cs_mode_high == (spi->mode &SPI_CS_HIGH ))) -return ; - -trace_spi_set_cs (spi, activate); +if ((spi->cs_index_mask &SPI_PARALLEL_CS_MASK ) ==SPI_PARALLEL_CS_MASK ) {
This check only works if you support a maximum of 2 CS in parallel. If you support up to, say, 4 then a chip which sets only CS 0 and 2 would not fall under this check.
I think your code in general should treat SPI_CS_CNT_MAX as an arbitrary value and should be able to handle changing it to any reasonable value.
Quoted 133 lines
drivers/spi/spi.c +102
-25+ spi->controller->last_cs_mode_high = spi->mode &SPI_CS_HIGH ; + +if ((spi_get_csgpiod (spi,0 ) || !spi->controller->set_cs_timing) && !activate) +spi_delay_exec (&spi->cs_hold,NULL ); + +if (spi->mode &SPI_CS_HIGH ) + enable = !enable; + +if (spi_get_csgpiod (spi,0 ) &&spi_get_csgpiod (spi,1 )) { +if (!(spi->mode &SPI_NO_CS )) { +/* +* Historically ACPI has no means of the GPIO polarity and +* thus the SPISerialBus() resource defines it on the per-chip +* basis. In order to avoid a chain of negations, the GPIO +* polarity is considered being Active High. Even for the cases +* when _DSD() is involved (in the updated versions of ACPI) +* the GPIO CS polarity must be defined Active High to avoid +* ambiguity. That's why we use enable, that takes SPI_CS_HIGH +* into account. +*/ +if (has_acpi_companion (&spi->dev)) { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) +gpiod_set_value_cansleep (spi_get_csgpiod (spi, idx), + !enable); + }else { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) +/* Polarity handled by GPIO library */ +gpiod_set_value_cansleep (spi_get_csgpiod (spi, idx), + activate); + } + } +/* Some SPI masters need both GPIO CS & slave_select */ +if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && + spi->controller->set_cs) + spi->controller->set_cs (spi, !enable); + }else if (spi->controller->set_cs) { + spi->controller->set_cs (spi, !enable); + } - spi->controller->last_cs = enable ?spi_get_chipselect (spi,0 ) :-1 ; - spi->controller->last_cs_mode_high = spi->mode &SPI_CS_HIGH ; +if (spi_get_csgpiod (spi,0 ) ||spi_get_csgpiod (spi,1 ) || + !spi->controller->set_cs_timing) { +if (activate) +spi_delay_exec (&spi->cs_setup,NULL ); +else +spi_delay_exec (&spi->cs_inactive,NULL ); + } + }else { -if ((spi_get_csgpiod (spi,0 ) || !spi->controller->set_cs_timing) && !activate) -spi_delay_exec (&spi->cs_hold,NULL ); +if (spi->cs_index_mask) + cs_num =ffs (spi->cs_index_mask) -1 ; -if (spi->mode &SPI_CS_HIGH ) - enable = !enable; +/* +* Avoid calling into the driver (or doing delays) if the chip select +* isn't actually changing from the last time this was called. +*/ +if (!force && ((enable && spi->controller->last_cs == +spi_get_chipselect (spi, cs_num)) || + (!enable && spi->controller->last_cs != +spi_get_chipselect (spi, cs_num))) && + (spi->controller->last_cs_mode_high == + (spi->mode &SPI_CS_HIGH ))) +return ; + +trace_spi_set_cs (spi, activate); + + spi->controller->last_cs = enable ?spi_get_chipselect (spi, cs_num) :-1 ; + spi->controller->last_cs_mode_high = spi->mode &SPI_CS_HIGH ; + +if ((spi_get_csgpiod (spi, cs_num) || !spi->controller->set_cs_timing) && !activate) +spi_delay_exec (&spi->cs_hold,NULL ); + +if (spi->mode &SPI_CS_HIGH ) + enable = !enable; + +if (spi_get_csgpiod (spi, cs_num)) { +if (!(spi->mode &SPI_NO_CS )) { +/* +* Historically ACPI has no means of the GPIO polarity and +* thus the SPISerialBus() resource defines it on the per-chip +* basis. In order to avoid a chain of negations, the GPIO +* polarity is considered being Active High. Even for the cases +* when _DSD() is involved (in the updated versions of ACPI) +* the GPIO CS polarity must be defined Active High to avoid +* ambiguity. That's why we use enable, that takes SPI_CS_HIGH +* into account. +*/ +if (has_acpi_companion (&spi->dev)) +gpiod_set_value_cansleep (spi_get_csgpiod (spi, cs_num), + !enable); +else +/* Polarity handled by GPIO library */ +gpiod_set_value_cansleep (spi_get_csgpiod (spi, cs_num), + activate); + } +/* Some SPI masters need both GPIO CS & slave_select */ +if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && + spi->controller->set_cs) + spi->controller->set_cs (spi, !enable); + }else if (spi->controller->set_cs) { + spi->controller->set_cs (spi, !enable); + } -if (spi_get_csgpiod (spi,0 )) { -if (!(spi->mode &SPI_NO_CS )) { -/* -* Historically ACPI has no means of the GPIO polarity and -* thus the SPISerialBus() resource defines it on the per-chip -* basis. In order to avoid a chain of negations, the GPIO -* polarity is considered being Active High. Even for the cases -* when _DSD() is involved (in the updated versions of ACPI) -* the GPIO CS polarity must be defined Active High to avoid -* ambiguity. That's why we use enable, that takes SPI_CS_HIGH -* into account. -*/ -if (has_acpi_companion (&spi->dev)) -gpiod_set_value_cansleep (spi_get_csgpiod (spi,0 ), !enable); +if (spi_get_csgpiod (spi, cs_num) || !spi->controller->set_cs_timing) { +if (activate) +spi_delay_exec (&spi->cs_setup,NULL );else -/* Polarity handled by GPIO library */ -gpiod_set_value_cansleep (spi_get_csgpiod (spi,0 ), activate); +spi_delay_exec (&spi->cs_inactive,NULL ); } -/* Some SPI masters need both GPIO CS & slave_select */ -if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && - spi->controller->set_cs)
drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes · line 1020
Quoted 10 lines
drivers/spi/spi.c +0
-10- spi->controller->set_cs (spi, !enable); - }else if (spi->controller->set_cs) { - spi->controller->set_cs (spi, !enable); - } - -if (spi_get_csgpiod (spi,0 ) || !spi->controller->set_cs_timing) { -if (activate) -spi_delay_exec (&spi->cs_setup,NULL ); -else -spi_delay_exec (&spi->cs_inactive,NULL );
I did not read this blob of code in detail yet. A couple of general comments though. You seem to be special-casing the multi-CS path. I do not think that is a good idea in general. Can you refactor it in such a way that the same bit of code handles an arbitrary number of chip selects being asserted at the same time?
Quoted 15 lines
drivers/spi/spi.c +2
-2} }@@ -2246,8 +2332,8 @@ static void of_spi_parse_dt_cs_delay(struct device_node *nc,static int of_spi_parse_dt (struct spi_controller *ctlr,struct spi_device *spi,struct device_node *nc) { -u32 value; -int rc; +u32 value, cs[SPI_CS_CNT_MAX ] = {0 }; +int rc, idx;/* Mode (clock phase/polarity/etc.) */ if (of_property_read_bool (nc,"spi-cpha" ))
drivers/spi/spi.c static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, · line 2413
Quoted 10 lines
drivers/spi/spi.c +3
-2@@ -2320,13 +2406,21 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, }/* Device address */ - rc =of_property_read_u32 (nc,"reg" , &value); -if (rc) { + rc =of_property_read_variable_u32_array (nc,"reg" , &cs[0 ],1 , +SPI_CS_CNT_MAX ); +if (rc <0 || rc > ctlr->num_chipselect) {dev_err (&ctlr->dev,"%pOF has no valid 'reg' property (%d)\n" , nc, rc);
This error message is not very helpful for the rc > ctlr->num_chipselect case. I think you should make them separate checks and error messages.
drivers/spi/spi.c static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, · line 2415
Quoted 2 lines
drivers/spi/spi.c +1
-0return rc; + } else if ((of_property_read_bool(nc, "parallel-memories")) &&
Nitpick: Why make it an else-if chain? Independent if statements would be better since these are not directly related.
drivers/spi/spi.c static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, · line 2419
Quoted 4 lines
drivers/spi/spi.c +3
-0+ (!(ctlr->flags & SPI_CONTROLLER_MULTI_CS))) { +dev_err (&ctlr->dev,"SPI controller doesn't support multi CS\n" ); +return -EINVAL ; }
You should also make sure that no cs[idx] is greater than ctlr->num_chipselect. Perhaps also check for multple cs[idx] pointing to the same physical CS? It might be better to check that in spi_add_device() though. Not sure...
drivers/spi/spi.c static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, · line 2422
Quoted 4 lines
drivers/spi/spi.c +3
-1-spi_set_chipselect (spi,0 , value); +for (idx =0 ; idx < rc; idx++) +spi_set_chipselect (spi, idx, cs[idx]); +/* By default set the spi->cs_index_mask as 1 */
Nitpick: We can infer this fact quite easily by reading the code. The comment should instead explain _why_ it is doing so.
drivers/spi/spi.c static int __spi_validate(struct spi_device *spi, struct spi_message *message) · line 4003
Quoted 11 lines
drivers/spi/spi.c +3
-1+ spi->cs_index_mask =0x01 ;/* Device speed */ if (!of_property_read_u32 (nc,"spi-max-frequency" , &value))@@ -3905,7 +3999,8 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)* cs_change is set for each transfer. */ if ((spi->mode &SPI_CS_WORD ) && (!(ctlr->mode_bits &SPI_CS_WORD ) || -spi_get_csgpiod (spi,0 ))) { +spi_get_csgpiod (spi,0 ) || +spi_get_csgpiod (spi,1 ))) {
Again, you hard-code this to only ever supporting 2 CS in parallel. Please make it generic.
include/linux/spi/spi.h line 23
Quoted 13 lines
drivers/spi/spi.c +0
-0size_t maxsize;int ret;include/linux/spi/spi.h +2
-0@@ -19,6 +19,11 @@#include <linux/acpi.h> #include <linux/u64_stats_sync.h> +/* Max no. of CS supported per spi device */ +#define SPI_CS_CNT_MAX 2
This is fine, but...
include/linux/spi/spi.h line 26
Quoted 3 lines
include/linux/spi/spi.h +3
-0+ +/* chip select mask */ +#define SPI_PARALLEL_CS_MASK (BIT(0) | BIT(1))
... as I mentioned above, the way you write this patch you makes it difficult to change the limit in the future. Please refactor it so that if you just change SPI_CS_CNT_MAX to any arbitrary value, the core is able to handle it.
I also think calling it "parallel" can be a bit confusing. Perhaps use "Multi CS" everywhere?
Quoted 12 lines
include/linux/spi/spi.h +1
-0struct dma_chan ;struct software_node ;struct ptp_system_timestamp ;@@ -166,6 +171,7 @@ extern void spi_transfer_cs_change_delay_exec(struct spi_message *msg,* deasserted. If @cs_change_delay is used from @spi_transfer, then the * two delays will be added up. * @pcpu_statistics: statistics for the spi_device +* @cs_index_mask: Bit mask of the active chipselect(s) in the chipselect array * * A @spi_device is used to interchange data between an SPI slave * (usually a discrete chip) and CPU memory.
include/linux/spi/spi.h struct spi_device { · line 190
Quoted 5 lines
include/linux/spi/spi.h +1
-1@@ -181,7 +187,7 @@ struct spi_device {struct spi_controller *controller;struct spi_controller *master;/* Compatibility layer */ u32 max_speed_hz; -u8 chip_select; +u8 chip_select[SPI_CS_CNT_MAX ];
Should also update documentation for chip_select.
Quoted 64 lines
include/linux/spi/spi.h +14
-5u8 bits_per_word;bool rt;#define SPI_NO_TX BIT(31)/* No transmit wire */ @@ -212,7 +218,7 @@ struct spi_device {void *controller_data;char modalias[SPI_NAME_SIZE ];const char *driver_override; -struct gpio_desc *cs_gpiod;/* Chip select gpio desc */ +struct gpio_desc *cs_gpiod[SPI_CS_CNT_MAX ];/* Chip select gpio desc */ struct spi_delay word_delay;/* Inter-word delay */ /* CS delays */ struct spi_delay cs_setup;@@ -222,6 +228,13 @@ struct spi_device {/* The statistics */ struct spi_statistics __percpu *pcpu_statistics; +/* Bit mask of the chipselect(s) that the driver need to use from +* the chipselect array.When the controller is capable to handle +* multiple chip selects & memories are connected in parallel +* then more than one bit need to be set in cs_index_mask. +*/ + u32 cs_index_mask : SPI_CS_CNT_MAX; +/* * likely need more hooks for more protocol options affecting how * the controller talks to each chip, like: @@ -278,22 +291,22 @@ static inline void *spi_get_drvdata(const struct spi_device *spi)static inline u8 spi_get_chipselect (const struct spi_device *spi,u8 idx) { -return spi->chip_select; +return spi->chip_select[idx]; }static inline void spi_set_chipselect (struct spi_device *spi,u8 idx,u8 chipselect) { - spi->chip_select = chipselect; + spi->chip_select[idx] = chipselect; }static inline struct gpio_desc *spi_get_csgpiod (const struct spi_device *spi,u8 idx) { -return spi->cs_gpiod; +return spi->cs_gpiod[idx]; }static inline void spi_set_csgpiod (struct spi_device *spi,u8 idx,struct gpio_desc *csgpiod) { - spi->cs_gpiod = csgpiod; + spi->cs_gpiod[idx] = csgpiod; }/** @@ -398,6 +411,8 @@ extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 ch* @bus_lock_spinlock: spinlock for SPI bus locking * @bus_lock_mutex: mutex for exclusion of multiple callers * @bus_lock_flag: indicates that the SPI bus is locked for exclusive use +* @multi_cs_cap: indicates that the SPI Controller can assert/de-assert +* more than one chip select at once. * @setup: updates the device mode and clocking records used by a * device's SPI controller; protocol code may call this. This * must fail if an unrecognized or unsupported mode is requested. @@ -564,6 +579,11 @@ struct spi_controller {#define SPI_CONTROLLER_MUST_TX BIT(4)/* Requires tx */
include/linux/spi/spi.h struct spi_controller { · line 589
Quoted 10 lines
include/linux/spi/spi.h +5
-0#define SPI_MASTER_GPIO_SS BIT(5)/* GPIO CS must select slave */ +/* +* The spi-controller has multi chip select capability and can +* assert/de-assert more than one chip select at once. +*/ +#define SPI_CONTROLLER_MULTI_CS BIT(6)/* Flag indicating if the allocation of this struct is devres-managed */ bool devm_allocated;
I only took a high level overview of this patch and I think it needs some reworking. I will take another look later when it gets in better shape. I am especially worried about interactions with SPI MEM (not sure if there need to be any, but still I should take a look) and ACPI support. But I think you have your work cut out for you for the next version :-)
I also want to look at the SPI NOR parts, let's see if I can find some more time this week.
--
Regards,
Pratyush Yadav
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
RE: [PATCH V8 1/7] spi: Add stacked and parallel memories support in SPI core
Hello Pratyush,
Quoted 39 lines
-----Original Message-----
From: Pratyush Yadav <[email protected]>
Sent: Tuesday, May 30, 2023 9:56 PM
To: Mahapatra, Amit Kumar <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; git (AMD-Xilinx) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Simek, Michal <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH V8 1/7] spi: Add stacked and parallel memories support in SPI coreHi Amit,
I did not get a chance to look at all the old comments in the previous versions. So apologies in advance if I comment something that has already been mentioned before.
Quoted 8 lines · Amit Kumar Mahapatra
For supporting multiple CS the SPI device need to be aware of all the CS values. So, the "
chip_select" member in thespi_devicestructure is now an array that holds all the CS values.
spi_devicestructure now has a "cs_index_mask" member. This acts as an index to thechip_selectarray. If nth bit ofspi->cs_index_maskis set then the driver would assert spi->chip_select[n].Quoted 7 lines
In parallel mode all the chip selects are asserted/de-asserted simultaneously and each byte of data is stored in both devices, the even bits in one, the odd bits in the other. The split is automatically handled by the GQSPI controller. The GQSPI controller supports a maximum of two flashes connected in parallel mode. A
SPI_CONTROLLER_MULTI_CSflag bit is added in the spi controntroller flags, throughctlr->flagsthe spi core
Quoted 1 line
Typo: s/controntroller/controller/
I will fix it.
Quoted 4 lines
Quoted 4 lines
will make sure that the controller is capable of handling multiple chip selects at once.
Quoted 8 lines
Quoted 3 lines
For supporting multiple CS via GPIO the
cs_gpiodmember of thespi_devicestructure is now an array that holds the gpio descriptor for each chipselect.General comment: For large changes, it is useful to describe a high-level overview of your new design so reviewers and future readers can get a mental model of what is going on. I did not see anything of that sort in this series.
I will add a high-level overview of multi-cs and stacked connection mode.
Quoted 32 lines
Quoted 21 lines
Signed-off-by Amit Kumar Mahapatra <[email protected]>---
CS GPIO is not tested on our hardware but it has been tested by @Stefan
https://lore.kernel.org/all/3f148a0c-8885-0425-28f4-2a53937a388f@opens
ource.cirrus.com/ Stefan, could you please provide your Tested-by tag for this patch--- drivers/spi/spi.c | 231 ++++++++++++++++++++++++++++------------ include/linux/spi/spi.h | 32 ++++-- 2 files changed, 189 insertions(+), 74 deletions(-)drivers/spi/spi.c +0
-0index
9291b2a0e887..a793e56f6a21100644drivers/spi/spi.c +0
-0@@ -612,10 +612,24 @@ static int spi_dev_check(struct device *dev, void *data) {drivers/spi/spi.c static int spi_dev_check(struct device *dev, · line 619
Quoted 10 lines
drivers/spi/spi.c +4
-3struct spi_device *spi =to_spi_device (dev);struct spi_device *new_spi = data; +int idx, nw_idx; -if (spi->controller == new_spi->controller && -spi_get_chipselect (spi,0 ) ==spi_get_chipselect (new_spi,0 )) -return -EBUSY ; +if (spi->controller == new_spi->controller) { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { + for (nw_idx = 0; nw_idx < SPI_CS_CNT_MAX;nw_idx++) {
Quoted 8 lines
drivers/spi/spi.c static int spi_dev_check(struct device *dev, · line 620
Quoted 1 line
drivers/spi/spi.c +1
-0+ if ((idx != 0 && !spi_get_chipselect(spi, idx))|| > + (nw_idx != 0 && !spi_get_chipselect(spi,
nw_idx))) {Hmm, from what I can understand, spi->chipselect[i] gives the corresponding physical CS for logical CS i. So for example, if both old and new devices map logical CS 1 to physical CS 0, this would not detect the conflict.
Yes that's correct.
Quoted 2 lines
What exactly are you trying to do here?
Initially by default all the spi->chip_select[i] are initialized to 0.
If a single slave device is connected to the physical CS 1 of the controller, then the spi->chip_select[0] will hold 1 and spi->chip_select[0] will hold 0 (the default value).
So, both the old and new devices spi->chip_select[1] holds the default value 0 and spi_dev_check() will error out by saying that
physical CS 0 (i.e., spi->chip_select[1]) is already in use, which is not actually true as spi->chip_select[1] doesn't contain any valid CS number.
To avoid this false trigger, we have this check in which we assume that except logical CS 0(i.e., spi->chip_select[0]) if any other logical CS holds 0 then it's not a valid physical CS but rather the default value. This logic though has the downside as mentioned in your previous comment.
As an alternate solution we can initialize all the unused spi->chip_select[i] to FF, in that case we can remove this check and any combination of logical CS to physical CS can be covered. But if some controller has FF (which is unlikely but still a possibility) as a valid physical CS then this logic might not work.
please provide your thoughts on the same.
Quoted 24 lines
drivers/spi/spi.c static int spi_dev_check(struct device *dev, void *data)
Quoted 6 lines
drivers/spi/spi.c +5
-0+continue ; + }else if (spi_get_chipselect (spi, idx) == +spi_get_chipselect (new_spi, nw_idx)) { + dev_err(dev, + "chipselect %d already inuse\n",
drivers/spi/spi.c static int spi_dev_check(struct device *dev, · line 626
Quoted 1 line
drivers/spi/spi.c +1
-0+ spi_get_chipselect(new_spi,
nw_idx));Quoted 15 lines
drivers/spi/spi.c +6
-1+return -EBUSY ; + } + } + } + }return 0 ; }@@ -629,7 +643,7 @@ static int __spi_add_device(struct spi_device *spi) {struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; -int status; +int status, idx;
Quoted 10 lines
drivers/spi/spi.c static int __spi_add_device(struct spi_device *spi) · line 642
Quoted 8 lines
drivers/spi/spi.c +1
-2/* * We need to make sure there's no other device with this @@ -638,8 +652,6 @@ static int __spi_add_device(struct spi_device *spi) */ status =bus_for_each_dev (&spi_bus_type,NULL , spi, spi_dev_check);if (status) { -dev_err (dev,"chipselect %d already in use\n" , -spi_get_chipselect (spi,0 ));Nitpick: No need for the braces around if anymore.
Will fix it in next version.
Quoted 11 lines
drivers/spi/spi.c static int __spi_add_device(struct spi_device *spi) · line 653
Quoted 10 lines
drivers/spi/spi.c +0
-2return status; }@@ -649,8 +661,13 @@ static int __spi_add_device(struct spi_device *spi)return -ENODEV ; } -if (ctlr->cs_gpiods) - spi_set_csgpiod(spi, 0, ctlr->cs_gpiods[spi_get_chipselect(spi,0)]);
Quoted 6 lines
drivers/spi/spi.c static int __spi_add_device(struct spi_device *spi) · line 666
Quoted 3 lines
drivers/spi/spi.c +3
-0+if (ctlr->cs_gpiods) { +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +if (!(idx !=0 && !spi_get_chipselect (spi, idx)))Again, I don't get why you do this. This would simply fail for any device that maps logical CS 1 to physical CS 0.
I have explained the reason above.
Quoted 25 lines
Quoted 14 lines
drivers/spi/spi.c +4
-0+spi_set_csgpiod (spi, idx, + ctlr- cs_gpiods[spi_get_chipselect (spi, idx)]); + } + }/* drivers/spi/spi.c +2
-1* Drivers may modify this initial i/o setup, but will @@ -690,13 +707,15 @@ int spi_add_device(struct spi_device *spi) { struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; -int status; +int status, idx;drivers/spi/spi.c int spi_add_device(struct spi_device *spi)
Quoted 10 lines
drivers/spi/spi.c +4
-5-/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { -dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +/* Chipselects are numbered 0..max; validate. */ +if (spi_get_chipselect (spi, idx) >= ctlr->num_chipselect) { + dev_err(dev, "cs%d >= max %d\n",
spi_get_chipselect(spi, idx),
Quoted 8 lines
drivers/spi/spi.c int spi_add_device(struct spi_device *spi) · line 718
Quoted 3 lines
drivers/spi/spi.c +3
-0+ ctlr->num_chipselect); +return -EINVAL ; + }Since this function is doing a bunch of sanity checks, I think you should also make sure multiple logical CS don't map to the same physical CS. For example, make sure that spi->chip_select[0] != spi->chip_select[1] and so on.
I will add the check.
Quoted 20 lines
Quoted 9 lines
drivers/spi/spi.c +1
-0}/* Set the bus ID string */ @@ -713,12 +732,15 @@ static int spi_add_device_locked(struct spi_device *spi) {struct spi_controller *ctlr = spi->controller;struct device *dev = ctlr->dev.parent; +int idx;drivers/spi/spi.c static int spi_add_device_locked(struct · line 740
Quoted 10 lines
drivers/spi/spi.c +4
-5-/* Chipselects are numbered 0..max; validate. */ -if (spi_get_chipselect (spi,0 ) >= ctlr->num_chipselect) { -dev_err (dev,"cs%d >= max %d\n" ,spi_get_chipselect (spi,0 ), - ctlr->num_chipselect); -return -EINVAL ; +for (idx =0 ; idx <SPI_CS_CNT_MAX ; idx++) { +/* Chipselects are numbered 0..max; validate. */ +if (spi_get_chipselect (spi, idx) >= ctlr->num_chipselect) { + dev_err(dev, "cs%d >= max %d\n",
spi_get_chipselect(spi, idx),
Quoted 9 lines
drivers/spi/spi.c int spi_add_device(struct spi_device *spi) · line 718
Quoted 3 lines
drivers/spi/spi.c +3
-0+ ctlr->num_chipselect); +return -EINVAL ; + }As adding a new device gets more complex, we should stop duplicating code between here and
spi_add_device(). So you should either move this code to another function and call it from both places or add a new parameter called "locked" and mergespi_add_device()andspi_add_device_locked(). I do not have string preferences for either, but I do like the latter a bit more.
Agreed, will try to merge the functions into one.
Quoted 23 lines
Quoted 8 lines
drivers/spi/spi.c +0
-0}/* Set the bus ID string */ @@ -966,58 +988,122 @@ static void spi_res_release(struct
spi_controller*ctlr, structspi_message*mes static voidspi_set_cs(struct spi_device *spi, bool enable, bool force){drivers/spi/spi.c +0
-0bool activate = enable;drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 10 lines
drivers/spi/spi.c +4
-3+u32 cs_num =0 ; +int idx;/* -* Avoid calling into the driver (or doing delays) if the chip select -* isn't actually changing from the last time this was called. +* In parallel mode all the chip selects are asserted/de-asserted +* at once */ - if (!force && ((enable && spi->controller->last_cs ==
spi_get_chipselect(spi, 0)) ||drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +0
-1- (!enable && spi->controller->last_cs !=
spi_get_chipselect(spi, 0))) &&drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +0
-1- (spi->controller->last_cs_mode_high == (spi->mode &
SPI_CS_HIGH)))
Quoted 9 lines
drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 5 lines
drivers/spi/spi.c +2
-3-return ; - -trace_spi_set_cs (spi, activate); +if ((spi->cs_index_mask &SPI_PARALLEL_CS_MASK ) == +SPI_PARALLEL_CS_MASK ) {This check only works if you support a maximum of 2 CS in parallel. If you support up to, say, 4 then a chip which sets only CS 0 and 2 would not fall under this check.
Yes correct, this support is not added.
Quoted 3 lines
I think your code in general should treat
SPI_CS_CNT_MAXas an arbitrary value and should be able to handle changing it to any reasonable value.
I will rework on the logic.
Quoted 186 lines
drivers/spi/spi.c
Quoted 2 lines
drivers/spi/spi.c +1
-0+ spi->controller->last_cs_mode_high = spi->mode &
SPI_CS_HIGH;drivers/spi/spi.c
Quoted 2 lines
drivers/spi/spi.c +2
-0+ + if ((spi_get_csgpiod(spi, 0) || !spi->controller->set_cs_timing)&& !activate)
drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 9 lines
drivers/spi/spi.c +9
-0+spi_delay_exec (&spi->cs_hold,NULL ); + +if (spi->mode &SPI_CS_HIGH ) + enable = !enable; + +if (spi_get_csgpiod (spi,0 ) &&spi_get_csgpiod (spi,1 )) { +if (!(spi->mode &SPI_NO_CS )) { +/* +* Historically ACPI has no means of the GPIO polarity and
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+* thus the SPISerialBus() resource defines it on the per-chip
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+* basis. In order to avoid a chain of negations, the GPIO
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+* polarity is considered being Active High. Even for the cases
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+* when _DSD() is involved (in the updated versions of ACPI)
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+* the GPIO CS polarity must be defined Active High to avoid
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+* ambiguity. That's why we use enable, that takes
SPI_CS_HIGHdrivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 4 lines
drivers/spi/spi.c +4
-0+* into account. +*/ +if (has_acpi_companion (&spi->dev)) { + for (idx = 0; idx < SPI_CS_CNT_MAX;idx++)
Quoted 1 line
+
gpiod_set_value_cansleep(spi_get_csgpiod(spi, idx),
Quoted 1 line
+
!enable);
drivers/spi/spi.c
Quoted 2 lines
drivers/spi/spi.c +2
-0+ }else { + for (idx = 0; idx < SPI_CS_CNT_MAX;idx++)
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+/* Polarity handled by GPIO library */
Quoted 1 line
+
gpiod_set_value_cansleep(spi_get_csgpiod(spi, idx),
Quoted 1 line
+
activate);
drivers/spi/spi.c static int spi_dev_check(struct device *dev, void *data)
Quoted 3 lines
drivers/spi/spi.c +3
-0+ } + } +/* Some SPI masters need both GPIO CS &
slave_select*/drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+ if ((spi->controller->flags & SPI_MASTER_GPIO_SS)&&
Quoted 8 lines
drivers/spi/spi.c +5
-2+ spi->controller->set_cs) + spi->controller->set_cs (spi, !enable); + }else if (spi->controller->set_cs) { + spi->controller->set_cs (spi, !enable); + } - spi->controller->last_cs = enable ?spi_get_chipselect (spi,0 ) :-1 ; - spi->controller->last_cs_mode_high = spi->mode &SPI_CS_HIGH ;drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 10 lines
drivers/spi/spi.c +8
-1+if (spi_get_csgpiod (spi,0 ) ||spi_get_csgpiod (spi,1 ) || + !spi->controller->set_cs_timing) { +if (activate) +spi_delay_exec (&spi->cs_setup,NULL ); +else +spi_delay_exec (&spi->cs_inactive,NULL ); + } + }else { - if ((spi_get_csgpiod(spi, 0) || !spi->controller->set_cs_timing) &&!activate)
drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 8 lines
drivers/spi/spi.c +4
-3-spi_delay_exec (&spi->cs_hold,NULL ); +if (spi->cs_index_mask) + cs_num =ffs (spi->cs_index_mask) -1 ; -if (spi->mode &SPI_CS_HIGH ) - enable = !enable; +/* +* Avoid calling into the driver (or doing delays) if the chip select
drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 13 lines
drivers/spi/spi.c +13
-0+* isn't actually changing from the last time this was called. +*/ +if (!force && ((enable && spi->controller->last_cs == +spi_get_chipselect (spi, cs_num)) || + (!enable && spi->controller->last_cs != +spi_get_chipselect (spi, cs_num))) && + (spi->controller->last_cs_mode_high == + (spi->mode &SPI_CS_HIGH ))) +return ; + +trace_spi_set_cs (spi, activate); + + spi->controller->last_cs = enable ? spi_get_chipselect(spi,
cs_num) : -1;drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+ spi->controller->last_cs_mode_high = spi->mode &
SPI_CS_HIGH;drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 12 lines
drivers/spi/spi.c +2
-0+ + if ((spi_get_csgpiod(spi, cs_num) || !spi->controller-
set_cs_timing) && !activate)drivers/spi/spi.c +9
-0+spi_delay_exec (&spi->cs_hold,NULL ); + +if (spi->mode &SPI_CS_HIGH ) + enable = !enable; + +if (spi_get_csgpiod (spi, cs_num)) { +if (!(spi->mode &SPI_NO_CS )) { +/* +* Historically ACPI has no means of the GPIO polarity and
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+* thus the SPISerialBus() resource defines it on the per-chip
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+* basis. In order to avoid a chain of negations, the GPIO
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+* polarity is considered being Active High. Even for the cases
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+* when _DSD() is involved (in the updated versions of ACPI)
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+* the GPIO CS polarity must be defined Active High to avoid
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+* ambiguity. That's why we use enable, that takes
SPI_CS_HIGHdrivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 4 lines
drivers/spi/spi.c +4
-0+* into account. +*/ +if (has_acpi_companion (&spi->dev)) +gpiod_set_value_cansleep(spi_get_csgpiod(spi,
cs_num),drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 4 lines
drivers/spi/spi.c +4
-0+ !enable); + else +/* Polarity handled by GPIO library */ +gpiod_set_value_cansleep(spi_get_csgpiod(spi,
cs_num),drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 3 lines
drivers/spi/spi.c +3
-0+ activate); + } +/* Some SPI masters need both GPIO CS &
slave_select*/drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +1
-0+ if ((spi->controller->flags & SPI_MASTER_GPIO_SS)&&
drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes
Quoted 10 lines
drivers/spi/spi.c +5
-4+ spi->controller->set_cs) + spi->controller->set_cs (spi, !enable); + }else if (spi->controller->set_cs) { + spi->controller->set_cs (spi, !enable); + } -if (spi_get_csgpiod (spi,0 )) { -if (!(spi->mode &SPI_NO_CS )) { -/* -* Historically ACPI has no means of the GPIO polarity and
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +0
-1-* thus the SPISerialBus() resource defines it on the per-chip
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +0
-1-* basis. In order to avoid a chain of negations, the GPIO
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +0
-1-* polarity is considered being Active High. Even for the cases
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +0
-1-* when _DSD() is involved (in the updated versions of ACPI)
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +0
-1-* the GPIO CS polarity must be defined Active High to avoid
drivers/spi/spi.c
Quoted 1 line
drivers/spi/spi.c +0
-1-* ambiguity. That's why we use enable, that takes
SPI_CS_HIGHdrivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes · line 1015
Quoted 4 lines
drivers/spi/spi.c +0
-4-* into account. -*/ -if (has_acpi_companion (&spi->dev)) -gpiod_set_value_cansleep(spi_get_csgpiod(spi, 0), !enable);drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes · line 1015
Quoted 7 lines
drivers/spi/spi.c +1
-0+ if (spi_get_csgpiod(spi, cs_num) || !spi->controller-
set_cs_timing) {drivers/spi/spi.c +2
-2+if (activate) +spi_delay_exec (&spi->cs_setup,NULL );else -/* Polarity handled by GPIO library */ -gpiod_set_value_cansleep(spi_get_csgpiod(spi, 0), activate);Quoted 13 lines
drivers/spi/spi.c +1
-11+spi_delay_exec (&spi->cs_inactive,NULL ); } -/* Some SPI masters need both GPIO CS & slave_select */ -if ((spi->controller->flags &SPI_MASTER_GPIO_SS ) && - spi->controller->set_cs) - spi->controller->set_cs (spi, !enable); - }else if (spi->controller->set_cs) { - spi->controller->set_cs (spi, !enable); - } - -if (spi_get_csgpiod (spi,0 ) || !spi->controller->set_cs_timing) { -if (activate) -spi_delay_exec (&spi->cs_setup,NULL );
Quoted 8 lines
drivers/spi/spi.c static void spi_res_release(struct spi_controller *ctlr, struct spi_message *mes · line 1020
Quoted 2 lines
drivers/spi/spi.c +0
-2-else -spi_delay_exec (&spi->cs_inactive,NULL );I did not read this blob of code in detail yet. A couple of general comments though. You seem to be special-casing the multi-CS path. I do not think that is a good idea in general. Can you refactor it in such a way that the same bit of code handles an arbitrary number of chip selects being asserted at the same time?
Ok, I will rework to make a common code for asserting an arbitrary number of chip selects.
Quoted 28 lines
Quoted 6 lines
drivers/spi/spi.c +0
-0} }@@ -2246,8 +2332,8 @@ static void of_spi_parse_dt_cs_delay(struct
device_node*nc, static int of_spi_parse_dt(structspi_controller*ctlr, struct
spi_device*spi,drivers/spi/spi.c static void of_spi_parse_dt_cs_delay(struct device_node *nc,
Quoted 9 lines
drivers/spi/spi.c +2
-2struct device_node *nc) { -u32 value; -int rc; +u32 value, cs[SPI_CS_CNT_MAX ] = {0 }; +int rc, idx;/* Mode (clock phase/polarity/etc.) */ if (of_property_read_bool(nc, "spi-cpha")) @@ -2320,13 +2406,21@@
drivers/spi/spi.c static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
Quoted 10 lines
static int of_spi_parse_dt(struct
spi_controller*ctlr, structspi_device*spi,drivers/spi/spi.c +3
-2}/* Device address */ - rc =of_property_read_u32 (nc,"reg" , &value); -if (rc) { + rc =of_property_read_variable_u32_array (nc,"reg" , &cs[0 ],1 , +SPI_CS_CNT_MAX ); +if (rc <0 || rc > ctlr->num_chipselect) { dev_err(&ctlr->dev, "%pOF has no valid 'reg' property(%d)\n",
Quoted 4 lines
Quoted 1 line
nc, rc);
This error message is not very helpful for the rc >
ctlr->num_chipselectcase. I think you should make them separate checks and error messages.
Ok, will separate the error checks.
Quoted 6 lines
drivers/spi/spi.c static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, · line 2415
Quoted 3 lines
drivers/spi/spi.c +1
-0return rc; + } else if ((of_property_read_bool(nc, "parallel-memories")) &&Nitpick: Why make it an else-if chain? Independent if statements would be better since these are not directly related.
Agreed.
Quoted 8 lines
drivers/spi/spi.c
Quoted 3 lines
drivers/spi/spi.c +2
-0+ (!(ctlr->flags & SPI_CONTROLLER_MULTI_CS))) { + dev_err(&ctlr->dev, "SPI controller doesn't support multiCS\n");
drivers/spi/spi.c
Quoted 2 lines
drivers/spi/spi.c +1
-0+return -EINVAL ; }You should also make sure that no cs[idx] is greater than
Agreed, I will add the check.
Quoted 5 lines
ctlr->num_chipselect. Perhaps also check for multple cs[idx] pointing toctlr->the
same physical CS? It might be better to check that inspi_add_device()though. Not sure...
Quoted 7 lines
drivers/spi/spi.c static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, · line 2422
Quoted 4 lines
drivers/spi/spi.c +3
-1-spi_set_chipselect (spi,0 , value); +for (idx =0 ; idx < rc; idx++) +spi_set_chipselect (spi, idx, cs[idx]); +/* By default set the spi->cs_index_mask as 1 */ Nitpick: We can infer this fact quite easily by reading the code. The comment should instead explain _why_ it is doing so.
I will add the explanation in comment.
Quoted 10 lines
drivers/spi/spi.c static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
Quoted 6 lines
drivers/spi/spi.c +1
-1+ spi->cs_index_mask =0x01 ;/* Device speed */ if (!of_property_read_u32(nc, "spi-max-frequency", &value)) @@ -3905,7 +3999,8 @@ static int __spi_validate(struct spi_device *spi, struct
spi_message*message)drivers/spi/spi.c static int __spi_validate(struct spi_device *spi, struct spi_message *message)
Quoted 3 lines
drivers/spi/spi.c +0
-0* cs_change is set for each transfer. */ if ((spi->mode & SPI_CS_WORD) && (!(ctlr->mode_bits &
Quoted 7 lines
SPI_CS_WORD) ||drivers/spi/spi.c static int __spi_validate(struct spi_device *spi, struct spi_message *message) · line 4003
Quoted 3 lines
drivers/spi/spi.c +2
-1- spi_get_csgpiod(spi, 0))) { + spi_get_csgpiod(spi, 0) || + spi_get_csgpiod(spi, 1))) {Again, you hard-code this to only ever supporting 2 CS in parallel. Please make it generic.
Ok, will make it generic.
Quoted 24 lines
include/linux/spi/spi.h line 22
Quoted 13 lines
drivers/spi/spi.c +0
-0size_t maxsize;int ret;include/linux/spi/spi.h index renamed from include/linux/spi/spi.h +0
-0
cfe42f8cd7a4..d0f9a9a8b6d8100644include/linux/spi/spi.h +1
-0@@ -19,6 +19,11 @@#include <linux/acpi.h> #include <linux/u64_stats_sync.h> +/* Max no. of CS supported per spi device */ #define SPI_CS_CNT_MAX 2This is fine, but...
include/linux/spi/spi.h line 26
Quoted 3 lines
include/linux/spi/spi.h +3
-0+ +/* chip select mask */ +#define SPI_PARALLEL_CS_MASK (BIT(0) | BIT(1))... as I mentioned above, the way you write this patch you makes it difficult to change the limit in the future. Please refactor it so that if you just change
SPI_CS_CNT_MAXto any arbitrary value, the core is able to handle it.
Quoted 2 lines
I also think calling it "parallel" can be a bit confusing. Perhaps use "Multi CS" everywhere?
I named it parallel to align it with the DT property "parallel-memories"?
Quoted 8 lines
include/linux/spi/spi.h extern void
Quoted 5 lines
include/linux/spi/spi.h +0
-0struct dma_chan ;struct software_node ;struct ptp_system_timestamp ;@@ -166,6 +171,7 @@ extern voidspi_transfer_cs_change_delay_exec(struct
spi_message*msg,include/linux/spi/spi.h extern void · line 171
Quoted 1 line
include/linux/spi/spi.h +0
-0* deasserted. If @cs_change_delay is used from @spi_transfer, then the
Quoted 15 lines
include/linux/spi/spi.h struct spi_device { · line 190
Quoted 13 lines
include/linux/spi/spi.h +3
-1* two delays will be added up. * @pcpu_statistics: statistics for the spi_device +* @cs_index_mask: Bit mask of the active chipselect(s) in the +chipselect array * * A @spi_device is used to interchange data between an SPI slave * (usually a discrete chip) and CPU memory. @@ -181,7 +187,7 @@ struct spi_device {struct spi_controller *controller;struct spi_controller *master;/* Compatibility layer */ u32 max_speed_hz; -u8 chip_select; +u8 chip_select[SPI_CS_CNT_MAX ];Should also update documentation for
chip_select.
Will update it.
Regards,
Amit
Quoted 87 lines
include/linux/spi/spi.h struct spi_device { · line 221
Quoted 10 lines
include/linux/spi/spi.h +1
-1u8 bits_per_word;bool rt;#define SPI_NO_TX BIT(31)/* No transmit wire */ @@ -212,7 +218,7 @@ struct spi_device {void *controller_data;char modalias[SPI_NAME_SIZE ];const char *driver_override; -struct gpio_desc *cs_gpiod;/* Chip select gpio desc */ +struct gpio_desc *cs_gpiod[SPI_CS_CNT_MAX ];/* Chip select gpio desc */
include/linux/spi/spi.h extern struct spi_device
Quoted 46 lines
include/linux/spi/spi.h +11
-4struct spi_delay word_delay;/* Inter-word delay */ /* CS delays */ struct spi_delay cs_setup;@@ -222,6 +228,13 @@ struct spi_device {/* The statistics */ struct spi_statistics __percpu *pcpu_statistics; +/* Bit mask of the chipselect(s) that the driver need to use from +* the chipselect array.When the controller is capable to handle +* multiple chip selects & memories are connected in parallel +* then more than one bit need to be set in cs_index_mask. +*/ + u32 cs_index_mask : SPI_CS_CNT_MAX; +/* * likely need more hooks for more protocol options affecting how * the controller talks to each chip, like: @@ -278,22 +291,22 @@ static inline void *spi_get_drvdata(const struct spi_device *spi)static inline u8 spi_get_chipselect (const struct spi_device *spi,u8 idx) { -return spi->chip_select; +return spi->chip_select[idx]; }static inline void spi_set_chipselect (struct spi_device *spi,u8 idx,u8 chipselect) { - spi->chip_select = chipselect; + spi->chip_select[idx] = chipselect; }static inline struct gpio_desc *spi_get_csgpiod (const struct spi_device *spi,u8 idx) { -return spi->cs_gpiod; +return spi->cs_gpiod[idx]; }static inline void spi_set_csgpiod (struct spi_device *spi,u8 idx,struct gpio_desc *csgpiod) { - spi->cs_gpiod = csgpiod; + spi->cs_gpiod[idx] = csgpiod; }/**
include/linux/spi/spi.h +0
-0@@ -398,6 +411,8 @@ extern struct spi_device*spi_new_ancillary_device(struct
spi_device*spi, u8 chinclude/linux/spi/spi.h struct spi_controller { · line 581
Quoted 13 lines
include/linux/spi/spi.h +0
-0* @bus_lock_spinlock: spinlock for SPI bus locking * @bus_lock_mutex: mutex for exclusion of multiple callers * @bus_lock_flag: indicates that the SPI bus is locked for exclusive use
+ * @multi_cs_cap: indicates that the SPI Controller can assert/de-assert
+ * more than one chip select at once.
* @setup: updates the device mode and clocking records used by a
* device's SPI controller; protocol code may call this. This
* must fail if an unrecognized or unsupported mode is requested.include/linux/spi/spi.h +0
-0@@ -564,6 +579,11 @@ struct spi_controller {#define SPI_CONTROLLER_MUST_TX BIT(4)/* Requires tx */ #define SPI_MASTER_GPIO_SS BIT(5)/* GPIO CS must select slave */
include/linux/spi/spi.h struct spi_controller { · line 589
Quoted 8 lines
include/linux/spi/spi.h +5
-0+/* +* The spi-controller has multi chip select capability and can +* assert/de-assert more than one chip select at once. +*/ +#define SPI_CONTROLLER_MULTI_CS BIT(6)/* Flag indicating if the allocation of this struct is devres-managed */ bool devm_allocated;I only took a high level overview of this patch and I think it needs some reworking. I will take another look later when it gets in better shape. I am especially worried about interactions with SPI MEM (not sure if there need to be any, but still I should take a look) and ACPI support. But I think you have your work cut out for you for the next version :-)
Quoted 6 lines
I also want to look at the SPI NOR parts, let's see if I can find some more time this week.
--
Regards,
Pratyush Yadav
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v8 2/7 mtd: spi-nor: Convert macros with inline functions
In reply to Amit Kumar MahapatraIn further patches the nor->params references in spi_nor_otp_region_len(nor) & spi_nor_otp_n_regions(nor) macros will be replaced with spi_nor_get_params() API. To make the transition smoother, first converting the macros into static inline functions.
--- drivers/mtd/spi-nor/otp.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/mtd/spi-nor/otp.c +21 -2
@@ -11,8 +11,27 @@#include "core.h" -#define spi_nor_otp_region_len (nor) ((nor)->params->otp.org->len) -#define spi_nor_otp_n_regions (nor) ((nor)->params->otp.org->n_regions) +/** +* spi_nor_otp_region_len() - get size of one OTP region in bytes +* @nor: pointer to 'struct spi_nor' +* +* Return: size of one OTP region in bytes +*/ +static inline unsigned int spi_nor_otp_region_len (struct spi_nor *nor) +{ +return nor->params->otp.org->len; +} + +/** +* spi_nor_otp_n_regions() - get number of individual OTP regions +* @nor: pointer to 'struct spi_nor' +* +* Return: number of individual OTP regions +*/ +static inline unsigned int spi_nor_otp_n_regions (struct spi_nor *nor) +{ +return nor->params->otp.org->n_regions; +}/** * spi_nor_otp_read_secr() - read security register
Signature · 1 line
2.17.1
PATCH v8 3/7 mtd: spi-nor: Add APIs to set/get nor->params
In reply to Amit Kumar MahapatraSupporting multi-cs in spi-nor would require the *params member of struct spi_nor to be an array. To make the transition smoother introduced spi_nor_get_params() & spi_nor_set_params() APIs to get & set nor->params, added a new local variable (struct spi_nor_flash_parameter *params) to hold the return value of the spi_nor_get_params() function call and replaced all nor->params references with the "params".
While adding multi-cs support in further patches the *params member of the spi_nor structure would be converted to arrays & the "idx" parameter of the APIs would be used as array index i.e., nor->params[idx].
--- drivers/mtd/spi-nor/atmel.c | 17 ++-- drivers/mtd/spi-nor/core.c | 137 ++++++++++++++++++++----------- drivers/mtd/spi-nor/debugfs.c | 4 +- drivers/mtd/spi-nor/gigadevice.c | 4 +- drivers/mtd/spi-nor/issi.c | 11 ++- drivers/mtd/spi-nor/macronix.c | 10 ++- drivers/mtd/spi-nor/micron-st.c | 30 ++++--- drivers/mtd/spi-nor/otp.c | 29 +++++-- drivers/mtd/spi-nor/sfdp.c | 33 ++++---- drivers/mtd/spi-nor/spansion.c | 80 +++++++++++------- drivers/mtd/spi-nor/sst.c | 7 +- drivers/mtd/spi-nor/swp.c | 22 +++-- drivers/mtd/spi-nor/winbond.c | 2 +- drivers/mtd/spi-nor/xilinx.c | 18 ++-- include/linux/mtd/spi-nor.h | 10 +++ 15 files changed, 271 insertions(+), 143 deletions(-)
drivers/mtd/spi-nor/atmel.c +12 -5
@@ -23,10 +23,11 @@ static int at25fs_nor_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)static int at25fs_nor_unlock (struct spi_nor *nor,loff_t ofs,uint64_t len) { +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );int ret;/* We only support unlocking the whole flash array */ -if (ofs || len != nor->params->size) +if (ofs || len != params->size)return -EINVAL ;/* Write 0x00 to the status register to disable write protection */
@@ -50,7 +51,9 @@ static const struct spi_nor_locking_ops at25fs_nor_locking_ops = {static void at25fs_nor_late_init (struct spi_nor *nor) { - nor->params->locking_ops = &at25fs_nor_locking_ops; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); + + params->locking_ops = &at25fs_nor_locking_ops; }static const struct spi_nor_fixups at25fs_nor_fixups = {
@@ -69,11 +72,12 @@ static const struct spi_nor_fixups at25fs_nor_fixups = {static int atmel_nor_set_global_protection (struct spi_nor *nor,loff_t ofs,uint64_t len,bool is_protect) { +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );int ret;u8 sr;/* We only support locking the whole flash array */ -if (ofs || len != nor->params->size) +if (ofs || len != params->size)return -EINVAL ; ret =spi_nor_read_sr (nor, nor->bouncebuf);
@@ -131,9 +135,10 @@ static int atmel_nor_global_unprotect(struct spi_nor *nor, loff_t ofs,static int atmel_nor_is_global_protected (struct spi_nor *nor,loff_t ofs,uint64_t len) { +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );int ret; -if (ofs >= nor->params->size || (ofs + len) > nor->params->size) +if (ofs >= params->size || (ofs + len) > params->size)return -EINVAL ; ret =spi_nor_read_sr (nor, nor->bouncebuf);
@@ -151,7 +156,9 @@ static const struct spi_nor_locking_ops atmel_nor_global_protection_ops = {static void atmel_nor_global_protection_late_init (struct spi_nor *nor) { - nor->params->locking_ops = &atmel_nor_global_protection_ops; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); + + params->locking_ops = &atmel_nor_global_protection_ops; }static const struct spi_nor_fixups atmel_nor_global_protection_fixups = {
drivers/mtd/spi-nor/core.c +88 -49
481 lines not on this page · raw message
drivers/mtd/spi-nor/debugfs.c +2 -2
@@ -75,7 +75,7 @@ static void spi_nor_print_flags(struct seq_file *s, unsigned long flags,static int spi_nor_params_show (struct seq_file *s,void *data) {struct spi_nor *nor = s->private; -struct spi_nor_flash_parameter *params = nor->params; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );struct spi_nor_erase_map *erase_map = ¶ms->erase_map;struct spi_nor_erase_region *region;const struct flash_info *info = nor->info;
@@ -183,7 +183,7 @@ static void spi_nor_print_pp_cmd(struct seq_file *s,static int spi_nor_capabilities_show (struct seq_file *s,void *data) {struct spi_nor *nor = s->private; -struct spi_nor_flash_parameter *params = nor->params; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );u32 hwcaps = params->hwcaps.mask;int i, cmd;
drivers/mtd/spi-nor/gigadevice.c +3 -1
@@ -13,6 +13,8 @@ gd25q256_post_bfpt(struct spi_nor *nor,const struct sfdp_parameter_header *bfpt_header, const struct sfdp_bfpt *bfpt) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); +/* * GD25Q256C supports the first version of JESD216 which does not define * the Quad Enable methods. Overwrite the default Quad Enable method.
@@ -24,7 +26,7 @@ gd25q256_post_bfpt(struct spi_nor *nor,*/ if (bfpt_header->major ==SFDP_JESD216_MAJOR && bfpt_header->minor ==SFDP_JESD216_MINOR ) - nor->params->quad_enable = spi_nor_sr1_bit6_quad_enable; + params->quad_enable = spi_nor_sr1_bit6_quad_enable;return 0 ; }
drivers/mtd/spi-nor/issi.c +8 -3
@@ -13,6 +13,8 @@ is25lp256_post_bfpt_fixups(struct spi_nor *nor,const struct sfdp_parameter_header *bfpt_header, const struct sfdp_bfpt *bfpt) { + struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0); +/* * IS25LP256 supports 4B opcodes, but the BFPT advertises * BFPT_DWORD1_ADDRESS_BYTES_3_ONLY.
@@ -20,7 +22,7 @@ is25lp256_post_bfpt_fixups(struct spi_nor *nor,*/ if ((bfpt->dwords[SFDP_DWORD (1 )] &BFPT_DWORD1_ADDRESS_BYTES_MASK ) ==BFPT_DWORD1_ADDRESS_BYTES_3_ONLY ) - nor->params->addr_nbytes =4 ; + params->addr_nbytes =4 ;return 0 ; }
@@ -31,7 +33,8 @@ static const struct spi_nor_fixups is25lp256_fixups = {static void pm25lv_nor_late_init (struct spi_nor *nor) { -struct spi_nor_erase_map *map = &nor->params->erase_map; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); +struct spi_nor_erase_map *map = ¶ms->erase_map;int i;/* The PM25LV series has a different 4k sector erase opcode */
@@ -91,7 +94,9 @@ static const struct flash_info issi_nor_parts[] = {static void issi_nor_default_init (struct spi_nor *nor) { - nor->params->quad_enable = spi_nor_sr1_bit6_quad_enable; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); + + params->quad_enable = spi_nor_sr1_bit6_quad_enable; }static const struct spi_nor_fixups issi_fixups = {
drivers/mtd/spi-nor/macronix.c +7 -3
@@ -107,13 +107,17 @@ static const struct flash_info macronix_nor_parts[] = {static void macronix_nor_default_init (struct spi_nor *nor) { - nor->params->quad_enable = spi_nor_sr1_bit6_quad_enable; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); + + params->quad_enable = spi_nor_sr1_bit6_quad_enable; }static void macronix_nor_late_init (struct spi_nor *nor) { -if (!nor->params->set_4byte_addr_mode) - nor->params->set_4byte_addr_mode = spi_nor_set_4byte_addr_mode_en4b_ex4b; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); + +if (!params->set_4byte_addr_mode) + params->set_4byte_addr_mode = spi_nor_set_4byte_addr_mode_en4b_ex4b; }static const struct spi_nor_fixups macronix_nor_fixups = {
drivers/mtd/spi-nor/micron-st.c +19 -11
@@ -49,10 +49,11 @@static int micron_st_nor_octal_dtr_en (struct spi_nor *nor) { +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );struct spi_mem_op op;u8 *buf = nor->bouncebuf;int ret; -u8 addr_mode_nbytes = nor->params->addr_mode_nbytes; +u8 addr_mode_nbytes = params->addr_mode_nbytes;/* Use 20 dummy cycles for memory array reads. */ *buf =20 ;
@@ -128,27 +129,31 @@ static int micron_st_nor_octal_dtr_enable(struct spi_nor *nor, bool enable)static void mt35xu512aba_default_init (struct spi_nor *nor) { - nor->params->octal_dtr_enable = micron_st_nor_octal_dtr_enable; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); + + params->octal_dtr_enable = micron_st_nor_octal_dtr_enable; }static int mt35xu512aba_post_sfdp_fixup (struct spi_nor *nor) { +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); +/* Set the Fast Read settings. */ - nor->params->hwcaps.mask |=SNOR_HWCAPS_READ_8_8_8_DTR ; -spi_nor_set_read_settings (&nor->params->reads[SNOR_CMD_READ_8_8_8_DTR ], + params->hwcaps.mask |=SNOR_HWCAPS_READ_8_8_8_DTR ; +spi_nor_set_read_settings (¶ms->reads[SNOR_CMD_READ_8_8_8_DTR ],0 ,20 ,SPINOR_OP_MT_DTR_RD ,SNOR_PROTO_8_8_8_DTR ); nor->cmd_ext_type =SPI_NOR_EXT_REPEAT ; - nor->params->rdsr_dummy =8 ; - nor->params->rdsr_addr_nbytes =0 ; + params->rdsr_dummy =8 ; + params->rdsr_addr_nbytes =0 ;/* * The BFPT quad enable field is set to a reserved value so the quad * enable function is ignored by spi_nor_parse_bfpt(). Make sure we * disable it. */ - nor->params->quad_enable =NULL ; + params->quad_enable =NULL ;return 0 ; }
@@ -314,14 +319,15 @@ static const struct flash_info st_nor_parts[] = {*/ static int micron_st_nor_read_fsr (struct spi_nor *nor,u8 *fsr) { +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );int ret;if (nor->spimem) {struct spi_mem_op op =MICRON_ST_RDFSR_OP (fsr);if (nor->reg_proto ==SNOR_PROTO_8_8_8_DTR ) { - op.addr.nbytes = nor->params->rdsr_addr_nbytes; - op.dummy.nbytes = nor->params->rdsr_dummy; + op.addr.nbytes = params->rdsr_addr_nbytes; + op.dummy.nbytes = params->rdsr_dummy;/* * We don't want to read only one byte in DTR mode. So, * read 2 and then discard the second byte.
@@ -424,14 +430,16 @@ static int micron_st_nor_ready(struct spi_nor *nor)static void micron_st_nor_default_init (struct spi_nor *nor) { +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); + nor->flags |=SNOR_F_HAS_LOCK ; nor->flags &= ~SNOR_F_HAS_16BIT_SR ; - nor->params->quad_enable =NULL ; + params->quad_enable =NULL ; }static void micron_st_nor_late_init (struct spi_nor *nor) { -struct spi_nor_flash_parameter *params = nor->params; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );if (nor->info->mfr_flags &USE_FSR ) params->ready = micron_st_nor_ready;
drivers/mtd/spi-nor/otp.c +20 -9
@@ -19,7 +19,9 @@*/ static inline unsigned int spi_nor_otp_region_len (struct spi_nor *nor) { -return nor->params->otp.org->len; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); + +return params->otp.org->len; }/**
@@ -30,7 +32,9 @@ static inline unsigned int spi_nor_otp_region_len(struct spi_nor *nor)*/ static inline unsigned int spi_nor_otp_n_regions (struct spi_nor *nor) { -return nor->params->otp.org->n_regions; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); + +return params->otp.org->n_regions; }/**
@@ -241,7 +245,8 @@ int spi_nor_otp_is_locked_sr2(struct spi_nor *nor, unsigned int region)static loff_t spi_nor_otp_region_start (const struct spi_nor *nor,unsigned int region) { -const struct spi_nor_otp_organization *org = nor->params->otp.org; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); +const struct spi_nor_otp_organization *org = params->otp.org;return org->base + region * org->offset; }
@@ -266,7 +271,8 @@ static int spi_nor_mtd_otp_info(struct mtd_info *mtd, size_t len, size_t *retlen, struct otp_info *buf) { struct spi_nor *nor = mtd_to_spi_nor(mtd); -const struct spi_nor_otp_ops *ops = nor->params->otp.ops; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); +const struct spi_nor_otp_ops *ops = params->otp.ops;unsigned int n_regions =spi_nor_otp_n_regions (nor);unsigned int i;int ret, locked;
@@ -303,7 +309,8 @@ static int spi_nor_mtd_otp_info(struct mtd_info *mtd, size_t len,static int spi_nor_mtd_otp_range_is_locked (struct spi_nor *nor,loff_t ofs,size_t len) { -const struct spi_nor_otp_ops *ops = nor->params->otp.ops; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); +const struct spi_nor_otp_ops *ops = params->otp.ops;unsigned int region;int locked;
@@ -328,7 +335,8 @@ static int spi_nor_mtd_otp_read_write(struct mtd_info *mtd, loff_t ofs, const u8 *buf, bool is_write) {struct spi_nor *nor =mtd_to_spi_nor (mtd); -const struct spi_nor_otp_ops *ops = nor->params->otp.ops; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); +const struct spi_nor_otp_ops *ops = params->otp.ops;const size_t rlen =spi_nor_otp_region_len (nor);loff_t rstart, rofs;unsigned int region;
@@ -414,7 +422,8 @@ static int spi_nor_mtd_otp_write(struct mtd_info *mtd, loff_t to, size_t len,static int spi_nor_mtd_otp_erase (struct mtd_info *mtd,loff_t from,size_t len) {struct spi_nor *nor =mtd_to_spi_nor (mtd); -const struct spi_nor_otp_ops *ops = nor->params->otp.ops; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); +const struct spi_nor_otp_ops *ops = params->otp.ops;const size_t rlen =spi_nor_otp_region_len (nor);unsigned int region;loff_t rstart;
@@ -467,7 +476,8 @@ static int spi_nor_mtd_otp_erase(struct mtd_info *mtd, loff_t from, size_t len)static int spi_nor_mtd_otp_lock (struct mtd_info *mtd,loff_t from,size_t len) {struct spi_nor *nor =mtd_to_spi_nor (mtd); -const struct spi_nor_otp_ops *ops = nor->params->otp.ops; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); +const struct spi_nor_otp_ops *ops = params->otp.ops;const size_t rlen =spi_nor_otp_region_len (nor);unsigned int region;int ret;
@@ -501,9 +511,10 @@ static int spi_nor_mtd_otp_lock(struct mtd_info *mtd, loff_t from, size_t len)void spi_nor_set_mtd_otp_ops (struct spi_nor *nor) { +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );struct mtd_info *mtd = &nor->mtd; -if (!nor->params->otp.ops) +if (!params->otp.ops)return ;if (WARN_ON (!is_power_of_2 (spi_nor_otp_region_len (nor))))
drivers/mtd/spi-nor/sfdp.c +19 -14
@@ -436,7 +436,7 @@ static void spi_nor_regions_sort_erase_types(struct spi_nor_erase_map *map)static int spi_nor_parse_bfpt (struct spi_nor *nor,const struct sfdp_parameter_header *bfpt_header) { -struct spi_nor_flash_parameter *params = nor->params; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );struct spi_nor_erase_map *map = ¶ms->erase_map;struct spi_nor_erase_type *erase_type = map->erase_type;struct sfdp_bfpt bfpt;
@@ -661,6 +661,8 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,*/ static u8 spi_nor_smpt_addr_nbytes (const struct spi_nor *nor,const u32 settings) { +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); +switch (settings &SMPT_CMD_ADDRESS_LEN_MASK ) {case SMPT_CMD_ADDRESS_LEN_0 :return 0 ;
@@ -670,7 +672,7 @@ static u8 spi_nor_smpt_addr_nbytes(const struct spi_nor *nor, const u32 settingsreturn 4 ;case SMPT_CMD_ADDRESS_LEN_USE_CURRENT :default : -return nor->params->addr_mode_nbytes; +return params->addr_mode_nbytes; } }
@@ -822,7 +824,8 @@ spi_nor_region_check_overlay(struct spi_nor_erase_region *region,static int spi_nor_init_non_uniform_erase_map (struct spi_nor *nor,const u32 *smpt) { -struct spi_nor_erase_map *map = &nor->params->erase_map; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); +struct spi_nor_erase_map *map = ¶ms->erase_map;struct spi_nor_erase_type *erase = map->erase_type;struct spi_nor_erase_region *region;u64 offset;
@@ -910,6 +913,7 @@ static int spi_nor_init_non_uniform_erase_map(struct spi_nor *nor,static int spi_nor_parse_smpt (struct spi_nor *nor,const struct sfdp_parameter_header *smpt_header) { +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );const u32 *sector_map;u32 *smpt;size_t len;
@@ -940,7 +944,7 @@ static int spi_nor_parse_smpt(struct spi_nor *nor,if (ret) goto out; -spi_nor_regions_sort_erase_types (&nor->params->erase_map); +spi_nor_regions_sort_erase_types (¶ms->erase_map);/* fall through */ out:kfree (smpt);
@@ -980,7 +984,7 @@ static int spi_nor_parse_4bait(struct spi_nor *nor, { 0u /* not used */, BIT(11) }, { 0u /* not used */, BIT(12) }, }; -struct spi_nor_flash_parameter *params = nor->params; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );struct spi_nor_pp_command *params_pp = params->page_programs;struct spi_nor_erase_map *map = ¶ms->erase_map;struct spi_nor_erase_type *erase_type = map->erase_type;
@@ -1143,6 +1147,7 @@ static int spi_nor_parse_4bait(struct spi_nor *nor,static int spi_nor_parse_profile1 (struct spi_nor *nor,const struct sfdp_parameter_header *profile1_header) { +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );u32 *dwords, addr;size_t len;int ret;
@@ -1165,14 +1170,14 @@ static int spi_nor_parse_profile1(struct spi_nor *nor,/* Set the Read Status Register dummy cycles and dummy address bytes. */ if (dwords[SFDP_DWORD (1 )] &PROFILE1_DWORD1_RDSR_DUMMY ) - nor->params->rdsr_dummy =8 ; + params->rdsr_dummy =8 ;else - nor->params->rdsr_dummy =4 ; + params->rdsr_dummy =4 ;if (dwords[SFDP_DWORD (1 )] &PROFILE1_DWORD1_RDSR_ADDR_BYTES ) - nor->params->rdsr_addr_nbytes =4 ; + params->rdsr_addr_nbytes =4 ;else - nor->params->rdsr_addr_nbytes =0 ; + params->rdsr_addr_nbytes =0 ;/* * We don't know what speed the controller is running at. Find the
@@ -1201,8 +1206,8 @@ static int spi_nor_parse_profile1(struct spi_nor *nor, dummy =round_up (dummy,2 );/* Update the fast read settings. */ - nor->params->hwcaps.mask |=SNOR_HWCAPS_READ_8_8_8_DTR ; -spi_nor_set_read_settings (&nor->params->reads[SNOR_CMD_READ_8_8_8_DTR ], + params->hwcaps.mask |=SNOR_HWCAPS_READ_8_8_8_DTR ; +spi_nor_set_read_settings (¶ms->reads[SNOR_CMD_READ_8_8_8_DTR ],0 , dummy, opcode,SNOR_PROTO_8_8_8_DTR );
@@ -1210,7 +1215,7 @@ static int spi_nor_parse_profile1(struct spi_nor *nor,* Page Program is "Required Command" in the xSPI Profile 1.0. Update * the params->hwcaps.mask here. */ - nor->params->hwcaps.mask |=SNOR_HWCAPS_PP_8_8_8_DTR ; + params->hwcaps.mask |=SNOR_HWCAPS_PP_8_8_8_DTR ; out:kfree (dwords);
@@ -1231,7 +1236,7 @@ static int spi_nor_parse_profile1(struct spi_nor *nor,static int spi_nor_parse_sccr (struct spi_nor *nor,const struct sfdp_parameter_header *sccr_header) { -struct spi_nor_flash_parameter *params = nor->params; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );u32 *dwords, addr;size_t len;int ret;
@@ -1282,7 +1287,7 @@ static int spi_nor_parse_sccr(struct spi_nor *nor,static int spi_nor_parse_sccr_mc (struct spi_nor *nor,const struct sfdp_parameter_header *sccr_mc_header) { -struct spi_nor_flash_parameter *params = nor->params; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );u32 *dwords, addr;u8 i, n_dice;size_t len;
drivers/mtd/spi-nor/spansion.c +50 -30
269 lines not on this page · raw message
drivers/mtd/spi-nor/sst.c +5 -2
@@ -20,10 +20,11 @@ static int sst26vf_nor_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)static int sst26vf_nor_unlock (struct spi_nor *nor,loff_t ofs,uint64_t len) { +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );int ret;/* We only support unlocking the entire flash array. */ -if (ofs !=0 || len != nor->params->size) +if (ofs !=0 || len != params->size)return -EINVAL ; ret =spi_nor_read_cr (nor, nor->bouncebuf);
@@ -51,7 +52,9 @@ static const struct spi_nor_locking_ops sst26vf_nor_locking_ops = {static void sst26vf_nor_late_init (struct spi_nor *nor) { - nor->params->locking_ops = &sst26vf_nor_locking_ops; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); + + params->locking_ops = &sst26vf_nor_locking_ops; }static const struct spi_nor_fixups sst26vf_nor_fixups = {
drivers/mtd/spi-nor/swp.c +16 -6
@@ -340,11 +340,14 @@ static const struct spi_nor_locking_ops spi_nor_sr_locking_ops = {void spi_nor_init_default_locking_ops (struct spi_nor *nor) { - nor->params->locking_ops = &spi_nor_sr_locking_ops; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); + + params->locking_ops = &spi_nor_sr_locking_ops; }static int spi_nor_lock (struct mtd_info *mtd,loff_t ofs,uint64_t len) { +struct spi_nor_flash_parameter *params;struct spi_nor *nor =mtd_to_spi_nor (mtd);int ret;
@@ -352,7 +355,8 @@ static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)if (ret)return ret; - ret = nor->params->locking_ops->lock (nor, ofs, len); + params =spi_nor_get_params (nor,0 ); + ret = params->locking_ops->lock (nor, ofs, len);spi_nor_unlock_and_unprep (nor);return ret;
@@ -360,6 +364,7 @@ static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)static int spi_nor_unlock (struct mtd_info *mtd,loff_t ofs,uint64_t len) { +struct spi_nor_flash_parameter *params;struct spi_nor *nor =mtd_to_spi_nor (mtd);int ret;
@@ -367,7 +372,8 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)if (ret)return ret; - ret = nor->params->locking_ops->unlock (nor, ofs, len); + params =spi_nor_get_params (nor,0 ); + ret = params->locking_ops->unlock (nor, ofs, len);spi_nor_unlock_and_unprep (nor);return ret;
@@ -375,6 +381,7 @@ static int spi_nor_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)static int spi_nor_is_locked (struct mtd_info *mtd,loff_t ofs,uint64_t len) { +struct spi_nor_flash_parameter *params;struct spi_nor *nor =mtd_to_spi_nor (mtd);int ret;
@@ -382,7 +389,8 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)if (ret)return ret; - ret = nor->params->locking_ops->is_locked (nor, ofs, len); + params =spi_nor_get_params (nor,0 ); + ret = params->locking_ops->is_locked (nor, ofs, len);spi_nor_unlock_and_unprep (nor);return ret;
@@ -402,6 +410,7 @@ static int spi_nor_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len)*/ void spi_nor_try_unlock_all (struct spi_nor *nor) { +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );int ret;if (!(nor->flags &SNOR_F_HAS_LOCK ))
@@ -409,16 +418,17 @@ void spi_nor_try_unlock_all(struct spi_nor *nor)dev_dbg (nor->dev,"Unprotecting entire flash array\n" ); - ret =spi_nor_unlock (&nor->mtd,0 , nor->params->size); + ret =spi_nor_unlock (&nor->mtd,0 , params->size);if (ret)dev_dbg (nor->dev,"Failed to unlock the entire flash memory array\n" ); }void spi_nor_set_mtd_locking_ops (struct spi_nor *nor) { +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );struct mtd_info *mtd = &nor->mtd; -if (!nor->params->locking_ops) +if (!params->locking_ops)return ; mtd->_lock = spi_nor_lock;
drivers/mtd/spi-nor/winbond.c +1 -1
@@ -218,7 +218,7 @@ static const struct spi_nor_otp_ops winbond_nor_otp_ops = {static void winbond_nor_late_init (struct spi_nor *nor) { -struct spi_nor_flash_parameter *params = nor->params; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );if (params->otp.org->n_regions) params->otp.ops = &winbond_nor_otp_ops;
drivers/mtd/spi-nor/xilinx.c +11 -7
@@ -56,7 +56,8 @@ static const struct flash_info xilinx_nor_parts[] = {*/ static u32 s3an_nor_convert_addr (struct spi_nor *nor,u32 addr) { -u32 page_size = nor->params->page_size; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); +u32 page_size = params->page_size;u32 offset, page; offset = addr % page_size;
@@ -116,6 +117,7 @@ static int xilinx_nor_sr_ready(struct spi_nor *nor)static int xilinx_nor_setup (struct spi_nor *nor,const struct spi_nor_hwcaps *hwcaps) { +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );u32 page_size;int ret;
@@ -141,14 +143,14 @@ static int xilinx_nor_setup(struct spi_nor *nor,*/ if (nor->bouncebuf[0 ] &XSR_PAGESIZE ) {/* Flash in Power of 2 mode */ - page_size = (nor->params->page_size ==264 ) ?256 :512 ; - nor->params->page_size = page_size; + page_size = (params->page_size ==264 ) ?256 :512 ; + params->page_size = page_size; nor->mtd.writebufsize = page_size; - nor->params->size =8 * page_size * nor->info->n_sectors; + params->size =8 * page_size * nor->info->n_sectors; nor->mtd.erasesize =8 * page_size; }else {/* Flash in Default addressing mode */ - nor->params->convert_addr = s3an_nor_convert_addr; + params->convert_addr = s3an_nor_convert_addr; nor->mtd.erasesize = nor->info->sector_size; }
@@ -157,8 +159,10 @@ static int xilinx_nor_setup(struct spi_nor *nor,static void xilinx_nor_late_init (struct spi_nor *nor) { - nor->params->setup = xilinx_nor_setup; - nor->params->ready = xilinx_nor_sr_ready; +struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); + + params->setup = xilinx_nor_setup; + params->ready = xilinx_nor_sr_ready; }static const struct spi_nor_fixups xilinx_nor_fixups = {
include/linux/mtd/spi-nor.h +10 -0
@@ -433,6 +433,16 @@ static inline struct device_node *spi_nor_get_flash_node(struct spi_nor *nor)return mtd_get_of_node (&nor->mtd); } +static inline struct spi_nor_flash_parameter *spi_nor_get_params (const struct spi_nor *nor,u8 idx) +{ +return nor->params; +} + +static inline void spi_nor_set_params (struct spi_nor *nor,u8 idx, +struct spi_nor_flash_parameter *params) +{ + nor->params = params; +}/** * spi_nor_scan() - scan the SPI NOR * @nor: the spi_nor structure
Signature · 1 line
2.17.1
PATCH v8 4/7 mtd: spi-nor: Add stacked memories support in spi-nor
In reply to Amit Kumar MahapatraEach flash that is connected in stacked mode should have a separate parameter structure. So, the flash parameter member(*params) of the spi_nor structure is changed to an array (*params[2]). The array is used to store the parameters of each flash connected in stacked configuration.
The current implementation assumes that a maximum of two flashes are connected in stacked mode and both the flashes are of same make but can differ in sizes. So, except the sizes all other flash parameters of both the flashes are identical.
SPI-NOR is not aware of the chip_select values, for any incoming request SPI-NOR will decide the flash index with the help of individual flash size and the configuration type (single/stacked). SPI-NOR will pass on the flash index information to the SPI core & SPI driver by setting the appropriate bit in nor->spimem->spi->cs_index_mask. For example, if nth bit of nor->spimem->spi->cs_index_mask is set then the driver would assert/de-assert spi->chip_slect[n].
--- drivers/mtd/spi-nor/core.c | 282 +++++++++++++++++++++++++++++------- drivers/mtd/spi-nor/core.h | 4 + include/linux/mtd/spi-nor.h | 12 +- 3 files changed, 242 insertions(+), 56 deletions(-)
drivers/mtd/spi-nor/core.c +229 -53
@@ -1812,13 +1812,18 @@ static int spi_nor_erase_multi_sectors(struct spi_nor *nor, u64 addr, u32 len)static int spi_nor_erase (struct mtd_info *mtd,struct erase_info *instr) {struct spi_nor *nor =mtd_to_spi_nor (mtd); -u32 addr, len; +struct spi_nor_flash_parameter *params; +u32 addr, len, offset, cur_cs_num =0 ;uint32_t rem;int ret; +u64 sz;dev_dbg (nor->dev,"at 0x%llx, len %lld\n" , (long long )instr->addr, (long long )instr->len); + params =spi_nor_get_params (nor,0 ); + sz = params->size; +if (spi_nor_has_uniform_erase (nor)) {div_u64_rem (instr->len, mtd->erasesize, &rem);if (rem)
@@ -1840,29 +1845,32 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)if (ret) goto erase_err; - ret =spi_nor_write_enable (nor); -if (ret) { +while (cur_cs_num <SNOR_FLASH_CNT_MAX && params) { + nor->spimem->spi->cs_index_mask =0x01 << cur_cs_num; + ret =spi_nor_write_enable (nor); +if (ret) { +spi_nor_unlock_device (nor); + goto erase_err; + } + ret =spi_nor_erase_chip (nor);spi_nor_unlock_device (nor); - goto erase_err; - } - - ret =spi_nor_erase_chip (nor); -spi_nor_unlock_device (nor); -if (ret) - goto erase_err; +if (ret) + goto erase_err; -/* -* Scale the timeout linearly with the size of the flash, with -* a minimum calibrated to an old 2MB flash. We could try to -* pull these from CFI/SFDP, but these values should be good -* enough for now. -*/ - timeout =max (CHIP_ERASE_2MB_READY_WAIT_JIFFIES , -CHIP_ERASE_2MB_READY_WAIT_JIFFIES * - (unsigned long )(mtd->size /SZ_2M )); - ret =spi_nor_wait_till_ready_with_timeout (nor, timeout); -if (ret) - goto erase_err; +/* +* Scale the timeout linearly with the size of the flash, with +* a minimum calibrated to an old 2MB flash. We could try to +* pull these from CFI/SFDP, but these values should be good +* enough for now. +*/ + timeout =max (CHIP_ERASE_2MB_READY_WAIT_JIFFIES , +CHIP_ERASE_2MB_READY_WAIT_JIFFIES * + (unsigned long )(params->size /SZ_2M )); + ret =spi_nor_wait_till_ready_with_timeout (nor, timeout); +if (ret) + goto erase_err; + cur_cs_num++; + }/* REVISIT in some cases we could speed up erasing large regions * by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K. We may have set up
@@ -1871,18 +1879,31 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)/* "sector"-at-a-time erase */ }else if (spi_nor_has_uniform_erase (nor)) { +/* Determine the flash from which the operation need to start */ +while ((cur_cs_num <SNOR_FLASH_CNT_MAX ) && (addr > sz -1 ) && params) { + cur_cs_num++; + params =spi_nor_get_params (nor, cur_cs_num); + sz += params->size; + } +while (len) { ret =spi_nor_lock_device (nor);if (ret) goto erase_err; + nor->spimem->spi->cs_index_mask =0x01 << cur_cs_num; ret =spi_nor_write_enable (nor);if (ret) {spi_nor_unlock_device (nor); goto erase_err; } + offset = addr; +if (nor->flags &SNOR_F_HAS_STACKED ) { + params =spi_nor_get_params (nor, cur_cs_num); + offset -= (sz - params->size); + } - ret =spi_nor_erase_sector (nor, addr); + ret =spi_nor_erase_sector (nor, offset);spi_nor_unlock_device (nor);if (ret) goto erase_err;
@@ -1893,13 +1914,45 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) addr += mtd->erasesize; len -= mtd->erasesize; + +/* +* Flash cross over condition in stacked mode. +*/ +if ((nor->flags &SNOR_F_HAS_STACKED ) && (addr > sz -1 )) { + cur_cs_num++; + params =spi_nor_get_params (nor, cur_cs_num); + sz += params->size; + } }/* erase multiple sectors */ }else { - ret =spi_nor_erase_multi_sectors (nor, addr, len); -if (ret) - goto erase_err; +u64 erase_len =0 ; + +/* Determine the flash from which the operation need to start */ +while ((cur_cs_num <SNOR_FLASH_CNT_MAX ) && (addr > sz -1 ) && params) { + cur_cs_num++; + params =spi_nor_get_params (nor, cur_cs_num); + sz += params->size; + } +/* perform multi sector erase onec per Flash*/ +while (len) { + erase_len = (len > (sz - addr)) ? (sz - addr) : len; + offset = addr; + nor->spimem->spi->cs_index_mask =0x01 << cur_cs_num; +if (nor->flags &SNOR_F_HAS_STACKED ) { + params =spi_nor_get_params (nor, cur_cs_num); + offset -= (sz - params->size); + } + ret =spi_nor_erase_multi_sectors (nor, offset, erase_len); +if (ret) + goto erase_err; + len -= erase_len; + addr += erase_len; + cur_cs_num++; + params =spi_nor_get_params (nor, cur_cs_num); + sz += params->size; + } } ret =spi_nor_write_disable (nor);
@@ -2098,9 +2151,11 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { struct spi_nor *nor = mtd_to_spi_nor(mtd); +struct spi_nor_flash_parameter *params; +ssize_t ret, read_len, len_lock = len;loff_t from_lock = from; -size_t len_lock = len; -ssize_t ret; +u32 cur_cs_num =0 ; +u64 sz;dev_dbg (nor->dev,"from 0x%08x, len %zd\n" , (u32 )from, len);
@@ -2108,9 +2163,23 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,if (ret)return ret; + params =spi_nor_get_params (nor,0 ); + sz = params->size; + +/* Determine the flash from which the operation need to start */ +while ((cur_cs_num <SNOR_FLASH_CNT_MAX ) && (from > sz -1 ) && params) { + cur_cs_num++; + params =spi_nor_get_params (nor, cur_cs_num); + sz += params->size; + }while (len) {loff_t addr = from; + nor->spimem->spi->cs_index_mask =0x01 << cur_cs_num; + read_len = (len > (sz - addr)) ? (sz - addr) : len; + params =spi_nor_get_params (nor, cur_cs_num); + addr -= (sz - params->size); + addr =spi_nor_convert_addr (nor, addr); ret =spi_nor_read_data (nor, addr, len, buf);
@@ -2122,11 +2191,22 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,if (ret <0 ) goto read_err; -WARN_ON (ret > len); +WARN_ON (ret > read_len); *retlen += ret; buf += ret; from += ret; len -= ret; + +/* +* Flash cross over condition in stacked mode. +* +*/ +if ((nor->flags &SNOR_F_HAS_STACKED ) && (from > sz -1 )) { + cur_cs_num++; + params =spi_nor_get_params (nor, cur_cs_num); + sz += params->size; + } + } ret =0 ;
@@ -2147,8 +2227,9 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,struct spi_nor *nor =mtd_to_spi_nor (mtd);struct spi_nor_flash_parameter *params;size_t page_offset, page_remain, i; +u32 page_size, cur_cs_num =0 ;ssize_t ret; -u32 page_size; +u64 sz;dev_dbg (nor->dev,"to 0x%08x, len %zd\n" , (u32 )to, len);
@@ -2158,6 +2239,14 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, params =spi_nor_get_params (nor,0 ); page_size = params->page_size; + sz = params->size; + +/* Determine the flash from which the operation need to start */ +while ((cur_cs_num <SNOR_FLASH_CNT_MAX ) && (to > sz -1 ) && params) { + cur_cs_num++; + params =spi_nor_get_params (nor, cur_cs_num); + sz += params->size; + }for (i =0 ; i < len; ) {ssize_t written;
@@ -2178,6 +2267,10 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,/* the size of data remaining on the first page */ page_remain =min_t (size_t, page_size - page_offset, len - i); + nor->spimem->spi->cs_index_mask =0x01 << cur_cs_num; + params =spi_nor_get_params (nor, cur_cs_num); + addr -= (sz - params->size); + addr =spi_nor_convert_addr (nor, addr); ret =spi_nor_lock_device (nor);
@@ -2201,6 +2294,15 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, goto write_err; *retlen += written; i += written; + +/* +* Flash cross over condition in stacked mode. +*/ +if ((nor->flags &SNOR_F_HAS_STACKED ) && ((to + i) > sz -1 )) { + cur_cs_num++; + params =spi_nor_get_params (nor, cur_cs_num); + sz += params->size; + } } write_err:
@@ -2314,8 +2416,6 @@ int spi_nor_hwcaps_pp2cmd(u32 hwcaps)static int spi_nor_spimem_check_op (struct spi_nor *nor,struct spi_mem_op *op) { -struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); -/* * First test with 4 address bytes. The opcode itself might * be a 3B addressing opcode but we don't care, because
@@ -2324,7 +2424,7 @@ static int spi_nor_spimem_check_op(struct spi_nor *nor,*/ op->addr.nbytes =4 ;if (!spi_mem_supports_op (nor->spimem, op)) { -if (params->size >SZ_16M ) +if (nor->mtd.size >SZ_16M )return -EOPNOTSUPP ;/* If flash size <= 16MB, 3 address bytes are sufficient */
@@ -2925,6 +3025,10 @@ static void spi_nor_init_fixup_flags(struct spi_nor *nor)static void spi_nor_late_init_params (struct spi_nor *nor) {struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); +struct device_node *np =spi_nor_get_flash_node (nor); +u64 flash_size[SNOR_FLASH_CNT_MAX ]; +u32 idx =0 , i =0 ; +int rc;if (nor->manufacturer && nor->manufacturer->fixups && nor->manufacturer->fixups->late_init)
@@ -2948,6 +3052,36 @@ static void spi_nor_late_init_params(struct spi_nor *nor)spi_nor_init_default_locking_ops (nor); params->bank_size =div64_u64 (params->size, nor->info->n_banks); +/* +* The flashes that are connected in stacked mode should be of same make. +* Except the flash size all other properties are identical for all the +* flashes connected in stacked mode. +* The flashes that are connected in parallel mode should be identical. +*/ +while (i <SNOR_FLASH_CNT_MAX ) { + rc =of_property_read_u64_index (np,"stacked-memories" , idx, &flash_size[i]); +if (rc == -EINVAL ) { +break ; + }else if (rc == -EOVERFLOW ) { + idx++; + }else { + idx++; + i++; +if (!(nor->flags &SNOR_F_HAS_STACKED )) + nor->flags |=SNOR_F_HAS_STACKED ; + } + } +if (nor->flags &SNOR_F_HAS_STACKED ) { +for (idx =1 ; idx <SNOR_FLASH_CNT_MAX ; idx++) { + params =spi_nor_get_params (nor, idx); + params =devm_kzalloc (nor->dev,sizeof (*params),GFP_KERNEL ); +if (params) { +memcpy (params,spi_nor_get_params (nor,0 ),sizeof (*params)); + params->size = flash_size[idx]; +spi_nor_set_params (nor, idx, params); + } + } + } }/**
@@ -3155,16 +3289,30 @@ static int spi_nor_octal_dtr_enable(struct spi_nor *nor, bool enable)*/ static int spi_nor_quad_enable (struct spi_nor *nor) { -struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 ); +struct spi_nor_flash_parameter *params; +int err, idx; -if (!params->quad_enable) -return 0 ; +for (idx =0 ; idx <SNOR_FLASH_CNT_MAX ; idx++) { + params =spi_nor_get_params (nor, idx); +if (params) { +if (!params->quad_enable) +return 0 ; -if (!(spi_nor_get_protocol_width (nor->read_proto) ==4 || -spi_nor_get_protocol_width (nor->write_proto) ==4 )) -return 0 ; +if (!(spi_nor_get_protocol_width (nor->read_proto) ==4 || +spi_nor_get_protocol_width (nor->write_proto) ==4 )) +return 0 ; +/* +* Set the appropriate CS index before +* issuing the command. +*/ + nor->spimem->spi->cs_index_mask =0x01 << idx; -return params->quad_enable (nor); + err = params->quad_enable (nor); +if (err) +return err; + } + } +return err; }/**
@@ -3196,7 +3344,7 @@ int spi_nor_set_4byte_addr_mode(struct spi_nor *nor, bool enable)static int spi_nor_init (struct spi_nor *nor) { -int err; +int err, idx; err =spi_nor_octal_dtr_enable (nor, true);if (err) {
@@ -3237,9 +3385,18 @@ static int spi_nor_init(struct spi_nor *nor)*/ WARN_ONCE (nor->flags &SNOR_F_BROKEN_RESET ,"enabling reset hack; may not recover from unexpected reboots\n" ); - err =spi_nor_set_4byte_addr_mode (nor, true); -if (err) -return err; +for (idx =0 ; idx <SNOR_FLASH_CNT_MAX ; idx++) { +if (spi_nor_get_params (nor, idx)) { +/* +* Select the appropriate CS index before +* issuing the command. +*/ + nor->spimem->spi->cs_index_mask =0x01 << idx; + err =spi_nor_set_4byte_addr_mode (nor, true); +if (err) +return err; + } + } }return 0 ;
@@ -3354,18 +3511,30 @@ static void spi_nor_put_device(struct mtd_info *mtd)static void spi_nor_restore (struct spi_nor *nor) {int ret; +int idx;/* restore the addressing mode */ if (nor->addr_nbytes ==4 && !(nor->flags &SNOR_F_4B_OPCODES ) && nor->flags &SNOR_F_BROKEN_RESET ) { - ret =spi_nor_set_4byte_addr_mode (nor, false); -if (ret) -/* -* Do not stop the execution in the hope that the flash -* will default to the 3-byte address mode after the -* software reset. -*/ -dev_err (nor->dev,"Failed to exit 4-byte address mode, err = %d\n" , ret); +for (idx =0 ; idx <SNOR_FLASH_CNT_MAX ; idx++) { +if (spi_nor_get_params (nor, idx)) { +/* +* Select the appropriate CS index before +* issuing the command. +*/ + nor->spimem->spi->cs_index_mask =1 << idx; + ret =spi_nor_set_4byte_addr_mode (nor, false); +if (ret) +/* +* Do not stop the execution in the hope that the flash +* will default to the 3-byte address mode after the +* software reset. +*/ +dev_err (nor->dev, +"Failed to exit 4-byte address mode, err = %d\n" , + ret); + } + } }if (nor->flags &SNOR_F_SOFT_RESET )
@@ -3432,6 +3601,8 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor)struct spi_nor_flash_parameter *params =spi_nor_get_params (nor,0 );struct mtd_info *mtd = &nor->mtd;struct device *dev = nor->dev; +u64 total_sz =0 ; +int idx;spi_nor_set_mtd_locking_ops (nor);spi_nor_set_mtd_otp_ops (nor);
@@ -3450,7 +3621,12 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor) mtd->_erase = spi_nor_erase; mtd->writesize = params->writesize; mtd->writebufsize = params->page_size; - mtd->size = params->size; +for (idx =0 ; idx <SNOR_FLASH_CNT_MAX ; idx++) { + params =spi_nor_get_params (nor, idx); +if (params) + total_sz += params->size; + } + mtd->size = total_sz; mtd->_read = spi_nor_read;/* Might be already set by some SST flashes. */ if (!mtd->_write)
drivers/mtd/spi-nor/core.h +4 -0
@@ -11,6 +11,9 @@#define SPI_NOR_MAX_ID_LEN 6 +/* In single configuration enable CS0 */ +#define SPI_NOR_ENABLE_CS0 BIT(0) +/* Standard SPI NOR flash operations. */ #define SPI_NOR_READID_OP (naddr, ndummy, buf, len) \ SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RDID, 0), \
@@ -132,6 +135,7 @@ enum spi_nor_option_flags {SNOR_F_SWP_IS_VOLATILE =BIT (13 ),SNOR_F_RWW =BIT (14 ),SNOR_F_ECC =BIT (15 ), + SNOR_F_HAS_STACKED = BIT(16), }; struct spi_nor_read_command {
include/linux/mtd/spi-nor.h +9 -3
@@ -127,6 +127,12 @@#define SR2_LB3 BIT(5)/* Security Register Lock Bit 3 */ #define SR2_QUAD_EN_BIT7 BIT(7) +/* +* Maximum number of flashes that can be connected +* in stacked/parallel configuration +*/ +#define SNOR_FLASH_CNT_MAX 2 +/* Supported SPI protocols */ #define SNOR_PROTO_INST_MASK GENMASK(23, 16)#define SNOR_PROTO_INST_SHIFT 16
@@ -412,7 +418,7 @@ struct spi_nor {const struct spi_nor_controller_ops *controller_ops; -struct spi_nor_flash_parameter *params; +struct spi_nor_flash_parameter *params[SNOR_FLASH_CNT_MAX ];struct {struct spi_mem_dirmap_desc *rdesc;
@@ -435,13 +441,13 @@ static inline struct device_node *spi_nor_get_flash_node(struct spi_nor *nor)static inline struct spi_nor_flash_parameter *spi_nor_get_params (const struct spi_nor *nor,u8 idx) { -return nor->params; +return nor->params[idx]; }static inline void spi_nor_set_params (struct spi_nor *nor,u8 idx,struct spi_nor_flash_parameter *params) { - nor->params = params; + nor->params[idx] = params; }/** * spi_nor_scan() - scan the SPI NOR
Signature · 1 line
2.17.1
PATCH v8 5/7 spi: spi-zynqmp-gqspi: Add stacked memories support in GQSPI driver
In reply to Amit Kumar MahapatraGQSPI supports two chip select CS0 & CS1. Update the driver to assert/de-assert the appropriate chip select as per the bits set in qspi->cs_index_mask.
--- drivers/spi/spi-zynqmp-gqspi.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/spi/spi-zynqmp-gqspi.c +13 -8
@@ -156,6 +156,9 @@#define GQSPI_FREQ_100MHZ 100000000#define GQSPI_FREQ_150MHZ 150000000 +#define GQSPI_SELECT_LOWER_CS BIT(0) +#define GQSPI_SELECT_UPPER_CS BIT(1) +#define SPI_AUTOSUSPEND_TIMEOUT 3000enum mode_type {GQSPI_MODE_IO ,GQSPI_MODE_DMA };
@@ -467,15 +470,17 @@ static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool is_high) genfifoentry |=GQSPI_GENFIFO_MODE_SPI ; +if (qspi->cs_index_mask &GQSPI_SELECT_UPPER_CS ) { +zynqmp_gqspi_selectslave (xqspi, +GQSPI_SELECT_FLASH_CS_UPPER , +GQSPI_SELECT_FLASH_BUS_LOWER ); + }else if (qspi->cs_index_mask &GQSPI_SELECT_LOWER_CS ) { +zynqmp_gqspi_selectslave (xqspi, +GQSPI_SELECT_FLASH_CS_LOWER , +GQSPI_SELECT_FLASH_BUS_LOWER ); + } + genfifoentry |= xqspi->genfifobus;if (!is_high) { -if (!spi_get_chipselect (qspi,0 )) { - xqspi->genfifobus =GQSPI_GENFIFO_BUS_LOWER ; - xqspi->genfifocs =GQSPI_GENFIFO_CS_LOWER ; - }else { - xqspi->genfifobus =GQSPI_GENFIFO_BUS_UPPER ; - xqspi->genfifocs =GQSPI_GENFIFO_CS_UPPER ; - } - genfifoentry |= xqspi->genfifobus; genfifoentry |= xqspi->genfifocs; genfifoentry |=GQSPI_GENFIFO_CS_SETUP ; }else {
Signature · 6 lines
2.17.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v8 6/7 mtd: spi-nor: Add parallel memories support in spi-nor
In reply to Amit Kumar MahapatraThe current implementation assumes that a maximum of two flashes are connected in parallel mode. The QSPI controller splits the data evenly between both the flashes so, both the flashes that are connected in parallel mode should be identical.
During each operation SPI-NOR sets 0th bit for CS0 & 1st bit for CS1 in nor->spimem->spi->cs_index_mask. The QSPI driver will then assert/de-assert CS0 & CS1.
Write operation in parallel mode are performed in page size * 2 chunks as each write operation results in writing both the flashes. For doubling the address space each operation is performed at addr/2 flash offset, where addr is the address specified by the user.
--- drivers/mtd/spi-nor/core.c | 545 +++++++++++++++++++++++--------- drivers/mtd/spi-nor/core.h | 4 + drivers/mtd/spi-nor/micron-st.c | 5 + 3 files changed, 406 insertions(+), 148 deletions(-)
drivers/mtd/spi-nor/core.c +397 -148
@@ -464,17 +464,29 @@ int spi_nor_read_sr(struct spi_nor *nor, u8 *sr) op.data.nbytes =2 ; } +if (nor->flags &SNOR_F_HAS_PARALLEL ) + op.data.nbytes =2 ; +spi_nor_spimem_setup_op (nor, &op, nor->reg_proto); ret =spi_mem_exec_op (nor->spimem, &op); }else { - ret =spi_nor_controller_ops_read_reg (nor,SPINOR_OP_RDSR , sr, -1 ); +if (nor->flags &SNOR_F_HAS_PARALLEL ) + ret =spi_nor_controller_ops_read_reg (nor, +SPINOR_OP_RDSR , + sr,2 ); +else + ret =spi_nor_controller_ops_read_reg (nor, +SPINOR_OP_RDSR , + sr,1 ); }if (ret)dev_dbg (nor->dev,"error %d reading SR\n" , ret); +if (nor->flags &SNOR_F_HAS_PARALLEL ) + sr[0 ] |= sr[1 ]; +return ret; }
@@ -1837,16 +1849,140 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)if (ret)return ret; -/* whole-chip erase? */ -if (len == mtd->size && !(nor->flags &SNOR_F_NO_OP_CHIP_ERASE )) { -unsigned long timeout; +if (!(nor->flags &SNOR_F_HAS_PARALLEL )) { +/* whole-chip erase? */ +if (len == mtd->size && !(nor->flags &SNOR_F_NO_OP_CHIP_ERASE )) { +unsigned long timeout; - ret =spi_nor_lock_device (nor); -if (ret) - goto erase_err; + ret =spi_nor_lock_device (nor); +if (ret) + goto erase_err; + +while ((cur_cs_num <SNOR_FLASH_CNT_MAX ) && params) { + nor->spimem->spi->cs_index_mask =1 << cur_cs_num; + ret =spi_nor_write_enable (nor); +if (ret) { +spi_nor_unlock_device (nor); + goto erase_err; + } + + ret =spi_nor_erase_chip (nor); +spi_nor_unlock_device (nor); +if (ret) + goto erase_err; + +/* +* Scale the timeout linearly with the size of the flash, with +* a minimum calibrated to an old 2MB flash. We could try to +* pull these from CFI/SFDP, but these values should be good +* enough for now. +*/ + timeout =max (CHIP_ERASE_2MB_READY_WAIT_JIFFIES , +CHIP_ERASE_2MB_READY_WAIT_JIFFIES * + (unsigned long )(params->size / +SZ_2M )); + ret =spi_nor_wait_till_ready_with_timeout (nor, timeout); +if (ret) + goto erase_err; + + cur_cs_num++; + params =spi_nor_get_params (nor, cur_cs_num); + } + +/* REVISIT in some cases we could speed up erasing large regions +* by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K. We may have set up +* to use "small sector erase", but that's not always optimal. +*/ + +/* "sector"-at-a-time erase */ + }else if (spi_nor_has_uniform_erase (nor)) { +/* Determine the flash from which the operation need to start */ +while ((cur_cs_num <SNOR_FLASH_CNT_MAX ) && + (addr > sz -1 ) && params) { + cur_cs_num++; + params =spi_nor_get_params (nor, cur_cs_num); + sz += params->size; + } +while (len) { + ret =spi_nor_lock_device (nor); +if (ret) + goto erase_err; + + nor->spimem->spi->cs_index_mask =1 << cur_cs_num; + ret =spi_nor_write_enable (nor); +if (ret) { +spi_nor_unlock_device (nor); + goto erase_err; + } + + offset = addr; +if (nor->flags &SNOR_F_HAS_STACKED ) { + params =spi_nor_get_params (nor, cur_cs_num); + offset -= (sz - params->size); + } + ret =spi_nor_erase_sector (nor, offset); +spi_nor_unlock_device (nor); +if (ret) + goto erase_err; + + ret =spi_nor_wait_till_ready (nor); +if (ret) + goto erase_err; + + addr += mtd->erasesize; + len -= mtd->erasesize; + +/* +* Flash cross over condition in stacked mode. +*/ +if ((nor->flags &SNOR_F_HAS_STACKED ) && (addr > sz -1 )) { + cur_cs_num++; + params =spi_nor_get_params (nor, cur_cs_num); + sz += params->size; + } + } + +/* erase multiple sectors */ + }else { +u64 erase_len =0 ; + +/* Determine the flash from which the operation need to start */ +while ((cur_cs_num <SNOR_FLASH_CNT_MAX ) && + (addr > sz -1 ) && params) { + cur_cs_num++; + params =spi_nor_get_params (nor, cur_cs_num); + sz += params->size; + } +/* perform multi sector erase onec per Flash*/ +while (len) { + erase_len = (len > (sz - addr)) ? (sz - addr) : len; + offset = addr; + nor->spimem->spi->cs_index_mask =1 << cur_cs_num; +if (nor->flags &SNOR_F_HAS_STACKED ) { + params =spi_nor_get_params (nor, cur_cs_num); + offset -= (sz - params->size); + } + ret =spi_nor_erase_multi_sectors (nor, offset, erase_len); +if (ret) + goto erase_err; + len -= erase_len; + addr += erase_len; + params =spi_nor_get_params (nor, cur_cs_num); + sz += params->size; + } + } + }else { + nor->spimem->spi->cs_index_mask =SPI_NOR_ENABLE_MULTI_CS ; + +/* whole-chip erase? */ +if (len == mtd->size && !(nor->flags & +SNOR_F_NO_OP_CHIP_ERASE )) { +unsigned long timeout; + + ret =spi_nor_lock_device (nor); +if (ret) + goto erase_err; -while (cur_cs_num <SNOR_FLASH_CNT_MAX && params) { - nor->spimem->spi->cs_index_mask =0x01 << cur_cs_num; ret =spi_nor_write_enable (nor);if (ret) {spi_nor_unlock_device (nor);
@@ -1865,96 +2001,51 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)*/ timeout =max (CHIP_ERASE_2MB_READY_WAIT_JIFFIES ,CHIP_ERASE_2MB_READY_WAIT_JIFFIES * - (unsigned long )(params->size /SZ_2M )); + (unsigned long )(mtd->size /SZ_2M )); ret =spi_nor_wait_till_ready_with_timeout (nor, timeout);if (ret) goto erase_err; - cur_cs_num++; - } -/* REVISIT in some cases we could speed up erasing large regions -* by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K. We may have set up -* to use "small sector erase", but that's not always optimal. -*/ +/* REVISIT in some cases we could speed up erasing large regions +* by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K. We may have set up +* to use "small sector erase", but that's not always optimal. +*/ -/* "sector"-at-a-time erase */ - }else if (spi_nor_has_uniform_erase (nor)) { -/* Determine the flash from which the operation need to start */ -while ((cur_cs_num <SNOR_FLASH_CNT_MAX ) && (addr > sz -1 ) && params) { - cur_cs_num++; - params =spi_nor_get_params (nor, cur_cs_num); - sz += params->size; - } +/* "sector"-at-a-time erase */ + }else if (spi_nor_has_uniform_erase (nor)) { +while (len) { + ret =spi_nor_lock_device (nor); +if (ret) + goto erase_err; + ret =spi_nor_write_enable (nor); +if (ret) { +spi_nor_unlock_device (nor); + goto erase_err; + } -while (len) { - ret =spi_nor_lock_device (nor); -if (ret) - goto erase_err; + offset = addr /2 ; - nor->spimem->spi->cs_index_mask =0x01 << cur_cs_num; - ret =spi_nor_write_enable (nor); -if (ret) { + ret =spi_nor_erase_sector (nor, offset);spi_nor_unlock_device (nor); - goto erase_err; - } - offset = addr; -if (nor->flags &SNOR_F_HAS_STACKED ) { - params =spi_nor_get_params (nor, cur_cs_num); - offset -= (sz - params->size); - } - - ret =spi_nor_erase_sector (nor, offset); -spi_nor_unlock_device (nor); -if (ret) - goto erase_err; - - ret =spi_nor_wait_till_ready (nor); -if (ret) - goto erase_err; +if (ret) + goto erase_err; - addr += mtd->erasesize; - len -= mtd->erasesize; + ret =spi_nor_wait_till_ready (nor); +if (ret) + goto erase_err; -/* -* Flash cross over condition in stacked mode. -*/ -if ((nor->flags &SNOR_F_HAS_STACKED ) && (addr > sz -1 )) { - cur_cs_num++; - params =spi_nor_get_params (nor, cur_cs_num); - sz += params->size; + addr += mtd->erasesize; + len -= mtd->erasesize; } - } -/* erase multiple sectors */ - }else { -u64 erase_len =0 ; - -/* Determine the flash from which the operation need to start */ -while ((cur_cs_num <SNOR_FLASH_CNT_MAX ) && (addr > sz -1 ) && params) { - cur_cs_num++; - params =spi_nor_get_params (nor, cur_cs_num); - sz += params->size; - } -/* perform multi sector erase onec per Flash*/ -while (len) { - erase_len = (len > (sz - addr)) ? (sz - addr) : len; - offset = addr; - nor->spimem->spi->cs_index_mask =0x01 << cur_cs_num; -if (nor->flags &SNOR_F_HAS_STACKED ) { - params =spi_nor_get_params (nor, cur_cs_num); - offset -= (sz - params->size); - } - ret =spi_nor_erase_multi_sectors (nor, offset, erase_len); +/* erase multiple sectors */ + }else { + offset = addr /2 ; + ret =spi_nor_erase_multi_sectors (nor, offset, len);if (ret) goto erase_err; - len -= erase_len; - addr += erase_len; - cur_cs_num++; - params =spi_nor_get_params (nor, cur_cs_num); - sz += params->size; } } - ret =spi_nor_write_disable (nor); erase_err:
@@ -2155,7 +2246,9 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,ssize_t ret, read_len, len_lock = len;loff_t from_lock = from;u32 cur_cs_num =0 ; -u64 sz; +u_char *readbuf; +bool is_ofst_odd = false; +u64 sz =0 ;dev_dbg (nor->dev,"from 0x%08x, len %zd\n" , (u32 )from, len);
@@ -2166,23 +2259,47 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, params =spi_nor_get_params (nor,0 ); sz = params->size; -/* Determine the flash from which the operation need to start */ -while ((cur_cs_num <SNOR_FLASH_CNT_MAX ) && (from > sz -1 ) && params) { - cur_cs_num++; - params =spi_nor_get_params (nor, cur_cs_num); - sz += params->size; +/* +* Cannot read from odd offset in parallel mode, so read +* len + 1 from offset + 1 and ignore offset[0] data. +*/ +if ((nor->flags &SNOR_F_HAS_PARALLEL ) && (from &0x01 )) { + from = (loff_t)(from -1 ); + len = (size_t )(len +1 ); + is_ofst_odd = true; + readbuf =kmalloc (len,GFP_KERNEL ); +if (!readbuf) +return -ENOMEM ; + }else { + readbuf = buf; + } + +if (!(nor->flags &SNOR_F_HAS_PARALLEL )) { +/* Determine the flash from which the operation need to start */ +while ((cur_cs_num <SNOR_FLASH_CNT_MAX ) && (from > sz -1 ) && params) { + cur_cs_num++; + params =spi_nor_get_params (nor, cur_cs_num); + sz += params->size; + } } +while (len) {loff_t addr = from; - nor->spimem->spi->cs_index_mask =0x01 << cur_cs_num; - read_len = (len > (sz - addr)) ? (sz - addr) : len; - params =spi_nor_get_params (nor, cur_cs_num); - addr -= (sz - params->size); +if (nor->flags &SNOR_F_HAS_PARALLEL ) { + nor->spimem->spi->cs_index_mask =SPI_NOR_ENABLE_MULTI_CS ; + read_len = len; + addr /=2 ; + }else { + nor->spimem->spi->cs_index_mask =1 << cur_cs_num; + read_len = (len > (sz - addr)) ? (sz - addr) : len; + params =spi_nor_get_params (nor, cur_cs_num); + addr -= (sz - params->size); + } addr =spi_nor_convert_addr (nor, addr); - ret =spi_nor_read_data (nor, addr, len, buf); + ret =spi_nor_read_data (nor, addr, read_len, readbuf);if (ret ==0 ) {/* We shouldn't see 0-length reads */ ret = -EIO ;
@@ -2192,8 +2309,20 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, goto read_err;WARN_ON (ret > read_len); - *retlen += ret; +if (is_ofst_odd) { +/* +* Cannot read from odd offset in parallel mode. +* So read len + 1 from offset + 1 from the flash +* and copy len data from readbuf[1]. +*/ +memcpy (buf, (readbuf +1 ), (len -1 )); + *retlen += (ret -1 ); + }else { + *retlen += ret; + } buf += ret; +if (!is_ofst_odd) + readbuf += ret; from += ret; len -= ret;
@@ -2211,8 +2340,10 @@ static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len, ret =0 ; read_err: -spi_nor_unlock_and_unprep_rd (nor, from_lock, len_lock); +if (is_ofst_odd) +kfree (readbuf); +spi_nor_unlock_and_unprep_rd (nor, from_lock, len_lock);return ret; }
@@ -2241,11 +2372,37 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len, page_size = params->page_size; sz = params->size; -/* Determine the flash from which the operation need to start */ -while ((cur_cs_num <SNOR_FLASH_CNT_MAX ) && (to > sz -1 ) && params) { - cur_cs_num++; - params =spi_nor_get_params (nor, cur_cs_num); - sz += params->size; +if (nor->flags &SNOR_F_HAS_PARALLEL ) { +/* +* Cannot write to odd offset in parallel mode, +* so write 2 byte first. +*/ +if (to &0x01 ) { +u8 two[2 ] = {0xff , buf[0 ]}; +size_t written_len; + + ret =spi_nor_write (mtd, to & ~1 ,2 , &written_len, two); +if (ret <0 ) +return ret; + *retlen +=1 ;/* We've written only one actual byte */ + ++buf; + --len; + ++to; + } +/* +* Write operation are performed in page size chunks and in +* parallel memories both the flashes are written simultaneously, +* hence doubled the page_size. +*/ + page_size <<=1 ; + + }else { +/* Determine the flash from which the operation need to start */ +while ((cur_cs_num <SNOR_FLASH_CNT_MAX ) && (to > sz -1 ) && params) { + cur_cs_num++; + params =spi_nor_get_params (nor, cur_cs_num); + sz += params->size; + } }for (i =0 ; i < len; ) {
@@ -2267,9 +2424,14 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,/* the size of data remaining on the first page */ page_remain =min_t (size_t, page_size - page_offset, len - i); - nor->spimem->spi->cs_index_mask =0x01 << cur_cs_num; - params =spi_nor_get_params (nor, cur_cs_num); - addr -= (sz - params->size); +if (nor->flags &SNOR_F_HAS_PARALLEL ) { + nor->spimem->spi->cs_index_mask =SPI_NOR_ENABLE_MULTI_CS ; + addr /=2 ; + }else { + nor->spimem->spi->cs_index_mask =1 << cur_cs_num; + params =spi_nor_get_params (nor, cur_cs_num); + addr -= (sz - params->size); + } addr =spi_nor_convert_addr (nor, addr);
@@ -2725,7 +2887,15 @@ static int spi_nor_select_erase(struct spi_nor *nor)if (!erase)return -EINVAL ; nor->erase_opcode = erase->opcode; - mtd->erasesize = erase->size; +/* +* In parallel-memories the erase operation is +* performed on both the flashes simultaneously +* so, double the erasesize. +*/ +if (nor->flags &SNOR_F_HAS_PARALLEL ) + mtd->erasesize = erase->size *2 ; +else + mtd->erasesize = erase->size;return 0 ; }
@@ -2743,7 +2913,15 @@ static int spi_nor_select_erase(struct spi_nor *nor)if (!erase)return -EINVAL ; - mtd->erasesize = erase->size; +/* +* In parallel-memories the erase operation is +* performed on both the flashes simultaneously +* so, double the erasesize. +*/ +if (nor->flags &SNOR_F_HAS_PARALLEL ) + mtd->erasesize = erase->size *2 ; +else + mtd->erasesize = erase->size;return 0 ; }
@@ -3071,7 +3249,22 @@ static void spi_nor_late_init_params(struct spi_nor *nor) nor->flags |=SNOR_F_HAS_STACKED ; } } -if (nor->flags &SNOR_F_HAS_STACKED ) { + i =0 ; + idx =0 ; +while (i <SNOR_FLASH_CNT_MAX ) { + rc =of_property_read_u64_index (np,"parallel-memories" , idx, &flash_size[i]); +if (rc == -EINVAL ) { +break ; + }else if (rc == -EOVERFLOW ) { + idx++; + }else { + idx++; + i++; +if (!(nor->flags &SNOR_F_HAS_PARALLEL )) + nor->flags |=SNOR_F_HAS_PARALLEL ; + } + } +if (nor->flags & (SNOR_F_HAS_STACKED |SNOR_F_HAS_PARALLEL )) {for (idx =1 ; idx <SNOR_FLASH_CNT_MAX ; idx++) { params =spi_nor_get_params (nor, idx); params =devm_kzalloc (nor->dev,sizeof (*params),GFP_KERNEL );
@@ -3292,24 +3485,42 @@ static int spi_nor_quad_enable(struct spi_nor *nor)struct spi_nor_flash_parameter *params;int err, idx; -for (idx =0 ; idx <SNOR_FLASH_CNT_MAX ; idx++) { - params =spi_nor_get_params (nor, idx); -if (params) { -if (!params->quad_enable) -return 0 ; +if (nor->flags &SNOR_F_HAS_PARALLEL ) { + params =spi_nor_get_params (nor,0 ); +if (!params->quad_enable) +return 0 ; -if (!(spi_nor_get_protocol_width (nor->read_proto) ==4 || -spi_nor_get_protocol_width (nor->write_proto) ==4 )) -return 0 ; -/* -* Set the appropriate CS index before -* issuing the command. -*/ - nor->spimem->spi->cs_index_mask =0x01 << idx; +if (!(spi_nor_get_protocol_width (nor->read_proto) ==4 || +spi_nor_get_protocol_width (nor->write_proto) ==4 )) +return 0 ; +/* +* In parallel mode both chip selects i.e., CS0 & +* CS1 need to be asserted simulatneously. +*/ + nor->spimem->spi->cs_index_mask =SPI_NOR_ENABLE_MULTI_CS ; + err = params->quad_enable (nor); +if (err) +return err; + }else { +for (idx =0 ; idx <SNOR_FLASH_CNT_MAX ; idx++) { + params =spi_nor_get_params (nor, idx); +if (params) { +if (!params->quad_enable) +return 0 ; - err = params->quad_enable (nor); -if (err) -return err; +if (!(spi_nor_get_protocol_width (nor->read_proto) ==4 || +spi_nor_get_protocol_width (nor->write_proto) ==4 )) +return 0 ; +/* +* Set the appropriate CS index before +* issuing the command. +*/ + nor->spimem->spi->cs_index_mask =1 << idx; + + err = params->quad_enable (nor); +if (err) +return err; + } } }return err;
@@ -3385,16 +3596,27 @@ static int spi_nor_init(struct spi_nor *nor)*/ WARN_ONCE (nor->flags &SNOR_F_BROKEN_RESET ,"enabling reset hack; may not recover from unexpected reboots\n" ); -for (idx =0 ; idx <SNOR_FLASH_CNT_MAX ; idx++) { -if (spi_nor_get_params (nor, idx)) { -/* -* Select the appropriate CS index before -* issuing the command. -*/ - nor->spimem->spi->cs_index_mask =0x01 << idx; - err =spi_nor_set_4byte_addr_mode (nor, true); -if (err) -return err; +if (nor->flags &SNOR_F_HAS_PARALLEL ) { +/* +* In parallel mode both chip selects i.e., CS0 & +* CS1 need to be asserted simulatneously. +*/ + nor->spimem->spi->cs_index_mask =SPI_NOR_ENABLE_MULTI_CS ; + err =spi_nor_set_4byte_addr_mode (nor, true); +if (err) +return err; + }else { +for (idx =0 ; idx <SNOR_FLASH_CNT_MAX ; idx++) { +if (spi_nor_get_params (nor, idx)) { +/* +* Select the appropriate CS index before +* issuing the command. +*/ + nor->spimem->spi->cs_index_mask =1 << idx; + err =spi_nor_set_4byte_addr_mode (nor, true); +if (err) +return err; + } } } }
@@ -3516,23 +3738,41 @@ static void spi_nor_restore(struct spi_nor *nor)/* restore the addressing mode */ if (nor->addr_nbytes ==4 && !(nor->flags &SNOR_F_4B_OPCODES ) && nor->flags &SNOR_F_BROKEN_RESET ) { -for (idx =0 ; idx <SNOR_FLASH_CNT_MAX ; idx++) { -if (spi_nor_get_params (nor, idx)) { +if (nor->flags &SNOR_F_HAS_PARALLEL ) { +/* +* In parallel mode both chip selects i.e., CS0 & +* CS1 need to be asserted simulatneously. +*/ + nor->spimem->spi->cs_index_mask =SPI_NOR_ENABLE_MULTI_CS ; +spi_nor_set_4byte_addr_mode (nor, false); +if (ret)/* -* Select the appropriate CS index before -* issuing the command. +* Do not stop the execution in the hope that the flash +* will default to the 3-byte address mode after the +* software reset. */ - nor->spimem->spi->cs_index_mask =1 << idx; - ret =spi_nor_set_4byte_addr_mode (nor, false); -if (ret) +dev_err (nor->dev, +"Failed to exit 4-byte address mode, err = %d\n" , + ret); + }else { +for (idx =0 ; idx <SNOR_FLASH_CNT_MAX ; idx++) { +if (spi_nor_get_params (nor, idx)) {/* -* Do not stop the execution in the hope that the flash -* will default to the 3-byte address mode after the -* software reset. +* Select the appropriate CS index before +* issuing the command. */ -dev_err (nor->dev, -"Failed to exit 4-byte address mode, err = %d\n" , - ret); + nor->spimem->spi->cs_index_mask =1 << idx; + ret =spi_nor_set_4byte_addr_mode (nor, false); +if (ret) +/* +* Do not stop the execution in the hope that the +* flash will default to the 3-byte address mode +* after the software reset. +*/ +dev_err (nor->dev, +"Failed to exit 4-byte address mode, err = %d\n" , + ret); + } } } }
@@ -3620,7 +3860,16 @@ static void spi_nor_set_mtd_info(struct spi_nor *nor)else mtd->_erase = spi_nor_erase; mtd->writesize = params->writesize; - mtd->writebufsize = params->page_size; +/* +* In parallel-memories the write operation is +* performed on both the flashes simultaneously +* one page per flash, so double the writebufsize. +*/ +if (nor->flags &SNOR_F_HAS_PARALLEL ) + mtd->writebufsize = params->page_size <<1 ; +else + mtd->writebufsize = params->page_size; +for (idx =0 ; idx <SNOR_FLASH_CNT_MAX ; idx++) { params =spi_nor_get_params (nor, idx);if (params)
drivers/mtd/spi-nor/core.h +4 -0
@@ -14,6 +14,9 @@/* In single configuration enable CS0 */ #define SPI_NOR_ENABLE_CS0 BIT(0) +/* In parallel configuration enable multiple CS */ +#define SPI_NOR_ENABLE_MULTI_CS (BIT(0) | BIT(1)) +/* Standard SPI NOR flash operations. */ #define SPI_NOR_READID_OP (naddr, ndummy, buf, len) \ SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_RDID, 0), \
@@ -136,6 +139,7 @@ enum spi_nor_option_flags {SNOR_F_RWW =BIT (14 ),SNOR_F_ECC =BIT (15 ),SNOR_F_HAS_STACKED =BIT (16 ), + SNOR_F_HAS_PARALLEL = BIT(17), }; struct spi_nor_read_command {
drivers/mtd/spi-nor/micron-st.c +5 -0
@@ -335,6 +335,9 @@ static int micron_st_nor_read_fsr(struct spi_nor *nor, u8 *fsr) op.data.nbytes =2 ; } +if (nor->flags &SNOR_F_HAS_PARALLEL ) + op.data.nbytes =2 ; +spi_nor_spimem_setup_op (nor, &op, nor->reg_proto); ret =spi_mem_exec_op (nor->spimem, &op);
@@ -346,6 +349,8 @@ static int micron_st_nor_read_fsr(struct spi_nor *nor, u8 *fsr)if (ret)dev_dbg (nor->dev,"error %d reading FSR\n" , ret); +if (nor->flags &SNOR_F_HAS_PARALLEL ) + fsr[0 ] &= fsr[1 ];return ret; }
Signature · 6 lines
2.17.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
PATCH v8 7/7 spi: spi-zynqmp-gqspi: Add parallel memories support in GQSPI driver
In reply to Amit Kumar MahapatraDuring probe GQSPI driver sets SPI_CONTROLLER_MULTI_CS bit in ctlr->flags for notifying SPI core about multi CS capability of the controller. In parallel mode the controller can either split the data between both the flash or can send the same data to both the flashes, this is determined by the STRIPE bit. While sending commands to the flashes the GQSPI driver send the same command to both the flashes by resetting the STRIPE bit, but while writing/reading data to & from the flash the GQSPI driver splits the data evenly between both the flashes by setting the STRIPE bit.
--- drivers/spi/spi-zynqmp-gqspi.c | 39 +++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)
drivers/spi/spi-zynqmp-gqspi.c +38 -1
@@ -23,6 +23,7 @@#include <linux/spinlock.h> #include <linux/workqueue.h> #include <linux/spi/spi-mem.h> +#include <linux/mtd/spi-nor.h> /* Generic QSPI register offsets */ #define GQSPI_CONFIG_OFST 0x00000100
@@ -192,6 +193,7 @@ struct qspi_platform_data {* @op_lock: Operational lock * @speed_hz: Current SPI bus clock speed in hz * @has_tapdelay: Used for tapdelay register available in qspi +* @is_parallel: Used for multi CS support */ struct zynqmp_qspi {struct spi_controller *ctlr;
@@ -214,8 +216,33 @@ struct zynqmp_qspi {struct mutex op_lock;u32 speed_hz;bool has_tapdelay; +bool is_parallel; }; +/** +* zynqmp_gqspi_update_stripe - For GQSPI controller data stripe capabilities +* @op: Pointer to mem ops +* Return: Status of the data stripe +* +* Returns true if data stripe need to be enabled, else returns false +*/ +bool zynqmp_gqspi_update_stripe (const struct spi_mem_op *op) +{ +if (op->cmd.opcode ==SPINOR_OP_BE_4K || + op->cmd.opcode ==SPINOR_OP_BE_32K || + op->cmd.opcode ==SPINOR_OP_CHIP_ERASE || + op->cmd.opcode ==SPINOR_OP_SE || + op->cmd.opcode ==SPINOR_OP_BE_32K_4B || + op->cmd.opcode ==SPINOR_OP_SE_4B || + op->cmd.opcode ==SPINOR_OP_BE_4K_4B || + op->cmd.opcode ==SPINOR_OP_WRSR || + op->cmd.opcode ==SPINOR_OP_BRWR || + (op->cmd.opcode ==SPINOR_OP_WRSR2 && !op->addr.nbytes)) +return false; + +return true; +} +/** * zynqmp_gqspi_read - For GQSPI controller read operation * @xqspi: Pointer to the zynqmp_qspi structure
@@ -470,7 +497,14 @@ static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool is_high) genfifoentry |=GQSPI_GENFIFO_MODE_SPI ; -if (qspi->cs_index_mask &GQSPI_SELECT_UPPER_CS ) { +if ((qspi->cs_index_mask &GQSPI_SELECT_LOWER_CS ) && + (qspi->cs_index_mask &GQSPI_SELECT_UPPER_CS )) { +zynqmp_gqspi_selectslave (xqspi, +GQSPI_SELECT_FLASH_CS_BOTH , +GQSPI_SELECT_FLASH_BUS_BOTH ); +if (!xqspi->is_parallel) + xqspi->is_parallel = true; + }else if (qspi->cs_index_mask &GQSPI_SELECT_UPPER_CS ) {zynqmp_gqspi_selectslave (xqspi,GQSPI_SELECT_FLASH_CS_UPPER ,GQSPI_SELECT_FLASH_BUS_LOWER );
@@ -1139,6 +1173,8 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem, }if (op->data.nbytes) { +if (xqspi->is_parallel &&zynqmp_gqspi_update_stripe (op)) + genfifoentry |=GQSPI_GENFIFO_STRIPE ;reinit_completion (&xqspi->data_completion);if (op->data.dir ==SPI_MEM_DATA_OUT ) { xqspi->txbuf = (u8 *)op->data.buf.out;
@@ -1334,6 +1370,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev) ctlr->bits_per_word_mask =SPI_BPW_MASK (8 ); ctlr->dev.of_node = np; ctlr->auto_runtime_pm = true; + ctlr->flags |=SPI_CONTROLLER_MULTI_CS ; ret =devm_spi_register_controller (&pdev->dev, ctlr);if (ret) {
Signature · 6 lines
2.17.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/