Skip to contentSkip to conversation

spi: designware: add support for bits-per-word DT binding

PATCH In review Boon Khai Ng 3 participants 12 messages Feb 27 – Mar 13 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: designware: add support for bits-per-word DT binding

Add support for the bits-per-word device tree binding.

---
 drivers/spi/designware_spi.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/spi/designware_spi.c +14 -2
index b520c727900..c41436a1dfb 100644
@@ -359,6 +359,7 @@ static int dw_spi_probe(struct udevice *bus)
 	dw_spi_init_t init = (dw_spi_init_t)dev_get_driver_data(bus);
 	struct dw_spi_plat *plat = dev_get_plat(bus);
 	struct dw_spi_priv *priv = dev_get_priv(bus);
+	u32 bits_per_word = 8;
 	int ret;
 	u32 version;
 
@@ -384,8 +385,19 @@ static int dw_spi_probe(struct udevice *bus)
 		version >> 24, version >> 16, version >> 8, version,
 		priv->max_xfer);
 
-	/* Currently only bits_per_word == 8 supported */
-	priv->bits_per_word = 8;
+	ret = ofnode_read_u32(dev_ofnode(bus), "bits-per-word", &bits_per_word);
+	if (ret) {
+		debug("%s no bits-per-word not found\n", __func__);
+	} else {
+		if (bits_per_word >= 4 && bits_per_word <= priv->max_xfer) {
+			debug("%s %d bits-per-word found\n", __func__, bits_per_word);
+		} else {
+			printf("ignoring invalid bits-per-word %d\n", bits_per_word);
+			bits_per_word = 8;
+		}
+	}
+
+	priv->bits_per_word = bits_per_word;
 
 	priv->tmode = 0; /* Tx & Rx */
 
Signature · 1 line
2.43.7
#1 lore raw
Quoted 31 lines · Boon Khai Ng

Add support for the bits-per-word device tree binding.

---
 drivers/spi/designware_spi.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/spi/designware_spi.c +7 -2
index b520c727900..c41436a1dfb 100644
@@ -359,6 +359,7 @@ static int dw_spi_probe(struct udevice *bus)
 	dw_spi_init_t init = (dw_spi_init_t)dev_get_driver_data(bus);
 	struct dw_spi_plat *plat = dev_get_plat(bus);
 	struct dw_spi_priv *priv = dev_get_priv(bus);
+	u32 bits_per_word = 8;
 	int ret;
 	u32 version;
 
@@ -384,8 +385,19 @@ static int dw_spi_probe(struct udevice *bus)
 		version >> 24, version >> 16, version >> 8, version,
 		priv->max_xfer);
 
-	/* Currently only bits_per_word == 8 supported */
-	priv->bits_per_word = 8;
+	ret = ofnode_read_u32(dev_ofnode(bus), "bits-per-word", &bits_per_word);
+	if (ret) {
+		debug("%s no bits-per-word not found\n", __func__);
+	} else {
+		if (bits_per_word >= 4 && bits_per_word <= priv->max_xfer) {
+			debug("%s %d bits-per-word found\n", __func__, bits_per_word);

drivers/spi/designware_spi.c static int dw_spi_probe(struct udevice *bus) · line 403

Quoted 10 lines
drivers/spi/designware_spi.c +7 -0
+		} else {
+			printf("ignoring invalid bits-per-word %d\n", bits_per_word);
+			bits_per_word = 8;
+		}
+	}
+
+	priv->bits_per_word = bits_per_word;
 
 	priv->tmode = 0; /* Tx & Rx */
 

I don't see this binding in v7.0-rc1, did I miss it? Thanks.

Signature · 1 line
Tom
#2 lore raw

Hi Tom,

Quoted 2 lines

I don't see this binding in v7.0-rc1, did I miss it? Thanks.

This binding was not introduce in Linux. This is a per-requisite commit
to support the Agilex Smart NIC 60xx board https://www.silicom-usa.com/wp-content/uploads/2024/02/FPGA-SmartNIC-N6010-AgileX-Based.pdf

During the initialization stage, this board require a spi communication to configure the chip's PLL and also to check the chip's status.

and it require the specific spi bits-per-word=16 setting.

Can i add the binding at U-Boot?
https://github.com/u-boot/u-boot/blob/master/doc/device-tree-bindings/spi/snps%2Cdw-apb-ssi.txt

Regards
Boon Khai.

#3 lore raw
Quoted 8 lines · Boon Khai

Hi Tom,

Quoted 2 lines

I don't see this binding in v7.0-rc1, did I miss it? Thanks.

This binding was not introduce in Linux. This is a per-requisite commit
to support the Agilex Smart NIC 60xx board https://www.silicom-usa.com/wp-content/uploads/2024/02/FPGA-SmartNIC-N6010-AgileX-Based.pdf

Quoted 7 lines

During the initialization stage, this board require a spi communication to configure the chip's PLL and also to check the chip's status.

and it require the specific spi bits-per-word=16 setting.

Can i add the binding at U-Boot?
https://github.com/u-boot/u-boot/blob/master/doc/device-tree-bindings/spi/snps%2Cdw-apb-ssi.txt

Why would this be inappropraite for the Linux kernel, once the system is fully supported in Linux is the first question to answer. Thanks.

Signature · 1 line
Tom
#4 lore raw
Quoted 12 lines · Tom Rini
Quoted 11 lines · Boon Khai

Hi Tom,

Quoted 2 lines

I don't see this binding in v7.0-rc1, did I miss it? Thanks.

This binding was not introduce in Linux. This is a per-requisite commit
to support the Agilex Smart NIC 60xx board https://www.silicom-usa.com/wp-content/uploads/2024/02/FPGA-SmartNIC-N6010-AgileX-Based.pdf

During the initialization stage, this board require a spi communication to configure the chip's PLL and also to check the chip's status.

Quoted 6 lines
Quoted 4 lines

and it require the specific spi bits-per-word=16 setting.

Can i add the binding at U-Boot?
https://github.com/u-boot/u-boot/blob/master/doc/device-tree-bindings/spi/snps%2Cdw-apb-ssi.txt

Why would this be inappropraite for the Linux kernel, once the system is

Did you mean "inappropraite", or actually appropriate? Guess it doesn't really matter to me, since the former would be asking "why would linux not want this" and the latter would be "why would linux want this". And I guess, as U-Boot maintainer the former is more important so inappropriate is actually what you meant. I, of course, always approach things with the latter mindset ;)

Quoted 1 line

fully supported in Linux is the first question to answer. Thanks.

The property doesn't make sense to me in a linux context. bits_per_word as explained here is a device setting should be set in the device driver, and is almost always per-compatible so doesn't even need to come from dt at all. What a controller can support is also effectively always determinable from the compatible of the controller, and is often a range.

Looking at the linux driver, all dw spi controllers appear to be able to support 4-16 bits per word with select devices also supporting 32. The check is done at runtime, it has no need for a property at all. The device driver effectively decides what is done for the transfer, within the range of supported values by the controller, based on what it sets in its spi_device struct. I don't know if u-boot has similar functionality in its code, but looking at dm_spi_slave_plat which I think is your version of spi_device, that information is not there.

Were this submitted to linux with the current explanation, the feedback would be to set bits_per_word in the driver for whatever this "chip" that's being talked about is, presumably that means setting it in some sort of clock driver given that it controls a PLL?

Cheers,
Conor.

#5 lore raw

Hi Conor, Tom,

Quoted 2 lines
Quoted 2 lines

Why would this be inappropraite for the Linux kernel, once the system is fully supported in Linux is the first question to answer. Thanks.

As Conor mentioned, the bits_per_word setting is obtained from the controller and validated at runtime.

Additionally, bits_per_word can also be sourced from ACPI, as shown in the Linux SPI driver code

https://github.com/torvalds/linux/blob/af4e9ef3d78420feb8fe58cd9a1ab80c501b3c08/drivers/spi/spi.c#L2739C7-L2739C20

Quoted 4 lines

in its spi_device struct. I don't know if u-boot has similar functionality in its code, but looking at dm_spi_slave_plat which I think is your version of spi_device, that information is not there.

Currently, U-Boot only supports an hardcoded 8-bit bits_per_word configuration.

Quoted 5 lines

Were this submitted to linux with the current explanation, the feedback would be to set bits_per_word in the driver for whatever this "chip" that's being talked about is, presumably that means setting it in some sort of clock driver given that it controls a PLL?

No, this isn't required by Linux, as the PLL only needs to be configured during the initial stage. This commit is specifically necessary for supporting the Agilex Smart NIC board, and I'm currently preparing patches for upstream submission. More details on the chip can be found, https://www.microchip.com/en-us/product/zl30793

Below is the link to the Smart NIC board:
https://www.silicom-usa.com/pr/4g-5g-products/4g-5g-adapters/fpga-smartnic-n6010-intel-based/

Below is the link to the patches I am preparing for upstream submission:
https://github.com/altera-fpga/u-boot-socfpga/blob/socfpga_v2025.10/board/intel/agilex-n6010/plldata.c

Quoted 1 line
#6 lore raw
Quoted 11 lines · Boon Khai

Hi Conor, Tom,

Quoted 2 lines
Quoted 2 lines

Why would this be inappropraite for the Linux kernel, once the system is fully supported in Linux is the first question to answer. Thanks.

As Conor mentioned, the bits_per_word setting is obtained from the controller and validated at runtime.

Additionally, bits_per_word can also be sourced from ACPI, as shown in the Linux SPI driver code

Quoted 8 lines

https://github.com/torvalds/linux/blob/af4e9ef3d78420feb8fe58cd9a1ab80c501b3c08/drivers/spi/spi.c#L2739C7-L2739C20

Quoted 4 lines

in its spi_device struct. I don't know if u-boot has similar functionality in its code, but looking at dm_spi_slave_plat which I think is your version of spi_device, that information is not there.

Currently, U-Boot only supports an hardcoded 8-bit bits_per_word configuration.

Thanks. And can we reasonably follow what Linux does here instead?

Signature · 1 line
Tom
#7 lore raw
Quoted 4 lines

Thanks. And can we reasonably follow what Linux does here instead?

We don't have ACPI in our devices, instead, i think that can be replaced with DTS.

Quoted 1 line
#8 lore raw
Quoted 7 lines · Boon Khai
Quoted 4 lines

Thanks. And can we reasonably follow what Linux does here instead?

We don't have ACPI in our devices, instead, i think that can be replaced with DTS.

I thought Conor said it could be auto-detected still, without ACPI, in Linux?

Signature · 1 line
Tom
#9 lore raw
Quoted 11 lines · Tom Rini
Quoted 7 lines · Boon Khai
Quoted 4 lines

Thanks. And can we reasonably follow what Linux does here instead?

We don't have ACPI in our devices, instead, i think that can be replaced with DTS.

I thought Conor said it could be auto-detected still, without ACPI, in Linux?

The controller capabilities are auto-detected. This has nothing to do with ACPI AFAICT, I don't know why that was brought up. What it detects is not an exact value though, the detected capability is the max of a range. On Linux, the spi controller driver advertises the range it supports. The spi device struct carries the bits_per_word that it wants to use, and the controller driver looks into that struct to figure out what supported bits_per_word setting to use in the transfer function. It's not as simple as just reading the register in the controller and setting the U-Boot drivers bits_per_word to the value, but I don't see why U-Boot couldn't do what Linux does here.

If you search in spi-dw-core for bits_per_word, you should be able to get a grasp of how it works.

#10 lore raw
In reply to Tom Rini

Hi, Tom, Conor,

Quoted 4 lines
Quoted 1 line

configuration.

Thanks. And can we reasonably follow what Linux does here instead?

After study the linux code, the bits_per_word value can be set at the higher level stack for example the touch screen driver ad7877.c at line https://github.com/torvalds/linux/blob/1f318b96cc84d7c2ab792fcc0bfd42a7ca890681/drivers/input/touchscreen/ad7877.c#L694

will implement something like that in U-Boot too as follow:
1) Add the bits_per_word in the spi_slave struct
2) at the dw_spi_xfer function to resolve for the slave->bits_per_word value and store into the priv->bits_per_word, default to 8 otherwise

Regards,
Boon Khai

Quoted 1 line