Skip to contentSkip to conversation

ieee802154: ca8210: Sparse fix and GPIOd conversion

PATCH Superseded Andy Shevchenko 3 participants 7 messages Mar 4, 2025 – Mar 5, 2025

Subsystems (6)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover ieee802154: ca8210: Sparse fix and GPIOd conversion

The main part is the patch 3 that converts the driver to GPIO descriptor APIs, the first one is just an ad-hoc fix WRT sparse complains on the bitwise types misuse. The second one is a small cleanup that helps patch 3 to be nicer.

In v3:
- inverted polarity of the reset line in accordance with datasheet (Linus)
- added quirk for the out-of-tree admittedly wrong DTS implementations
- collected tags (Linus)

In v2:
- split and extended cleanup pieces into patch 2 (Miquel)
- updated kernel doc for changed members (Miquel)
- unfolded PTR_ERR_OR_ZERO() to the preferred pattern (Miquel)
- collected tags (Miquel)

Andy Shevchenko (3):
ieee802154: ca8210: Use proper setter and getters for bitwise types
ieee802154: ca8210: Get platform data via dev_get_platdata()
ieee802154: ca8210: Switch to using gpiod API

 .../bindings/net/ieee802154/ca8210.txt        |  2 +-
 drivers/gpio/gpiolib-of.c                     |  9 +++
 drivers/net/ieee802154/ca8210.c               | 78 ++++++++-----------
 3 files changed, 41 insertions(+), 48 deletions(-)
Signature · 1 line
2.47.2
#2 lore raw

PATCH v3 2/3 ieee802154: ca8210: Get platform data via dev_get_platdata()

Access to platform data via dev_get_platdata() getter to make code cleaner.

---
 drivers/net/ieee802154/ca8210.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/net/ieee802154/ca8210.c +8 -4
index a036910f6082..65f042c8734b 100644
@@ -627,7 +627,8 @@ static int ca8210_spi_transfer(
  */
 static void ca8210_reset_send(struct spi_device *spi, unsigned int ms)
 {
-	struct ca8210_platform_data *pdata = spi->dev.platform_data;
+	struct device *dev = &spi->dev;
+	struct ca8210_platform_data *pdata = dev_get_platdata(dev);
 	struct ca8210_priv *priv = spi_get_drvdata(spi);
 	long status;
 
@@ -2736,9 +2737,10 @@ static int ca8210_config_extern_clk(
  */
 static int ca8210_register_ext_clock(struct spi_device *spi)
 {
+	struct device *dev = &spi->dev;
+	struct ca8210_platform_data *pdata = dev_get_platdata(dev);
 	struct device_node *np = spi->dev.of_node;
 	struct ca8210_priv *priv = spi_get_drvdata(spi);
-	struct ca8210_platform_data *pdata = spi->dev.platform_data;
 
 	if (!np)
 		return -EFAULT;
@@ -2784,8 +2786,9 @@ static void ca8210_unregister_ext_clock(struct spi_device *spi)
  */
 static int ca8210_reset_init(struct spi_device *spi)
 {
+	struct device *dev = &spi->dev;
+	struct ca8210_platform_data *pdata = dev_get_platdata(dev);
 	int ret;
-	struct ca8210_platform_data *pdata = spi->dev.platform_data;
 
 	pdata->gpio_reset = of_get_named_gpio(
 		spi->dev.of_node,
@@ -2813,8 +2816,9 @@ static int ca8210_reset_init(struct spi_device *spi)
  */
 static int ca8210_interrupt_init(struct spi_device *spi)
 {
+	struct device *dev = &spi->dev;
+	struct ca8210_platform_data *pdata = dev_get_platdata(dev);
 	int ret;
-	struct ca8210_platform_data *pdata = spi->dev.platform_data;
 
 	pdata->gpio_irq = of_get_named_gpio(
 		spi->dev.of_node,
Signature · 1 line
2.47.2
#1 lore raw

PATCH v3 1/3 ieee802154: ca8210: Use proper setter and getters for bitwise types

In reply to Andy Shevchenko

Sparse complains that the driver doesn't respect the bitwise types:

drivers/net/ieee802154/ca8210.c:1796:27: warning: incorrect type in assignment (different base types)
drivers/net/ieee802154/ca8210.c:1796:27: expected restricted __le16 [addressable] [assigned] [usertype] pan_id
drivers/net/ieee802154/ca8210.c:1796:27: got unsigned short [usertype]
drivers/net/ieee802154/ca8210.c:1801:25: warning: incorrect type in assignment (different base types)
drivers/net/ieee802154/ca8210.c:1801:25: expected restricted __le16 [addressable] [assigned] [usertype] pan_id
drivers/net/ieee802154/ca8210.c:1801:25: got unsigned short [usertype]
drivers/net/ieee802154/ca8210.c:1928:28: warning: incorrect type in argument 3 (different base types)
drivers/net/ieee802154/ca8210.c:1928:28: expected unsigned short [usertype] dst_pan_id
drivers/net/ieee802154/ca8210.c:1928:28: got restricted __le16 [addressable] [usertype] pan_id

Use proper setter and getters for bitwise types.

Note, in accordance with [1] the protocol is little endian.

---
 drivers/net/ieee802154/ca8210.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/ieee802154/ca8210.c +4 -5
index 753215ebc67c..a036910f6082 100644
@@ -1446,8 +1446,7 @@ static u8 mcps_data_request(
 	command.pdata.data_req.src_addr_mode = src_addr_mode;
 	command.pdata.data_req.dst.mode = dst_address_mode;
 	if (dst_address_mode != MAC_MODE_NO_ADDR) {
-		command.pdata.data_req.dst.pan_id[0] = LS_BYTE(dst_pan_id);
-		command.pdata.data_req.dst.pan_id[1] = MS_BYTE(dst_pan_id);
+		put_unaligned_le16(dst_pan_id, command.pdata.data_req.dst.pan_id);
 		if (dst_address_mode == MAC_MODE_SHORT_ADDR) {
 			command.pdata.data_req.dst.address[0] = LS_BYTE(
 				dst_addr->short_address
@@ -1795,12 +1794,12 @@ static int ca8210_skb_rx(
 	}
 	hdr.source.mode = data_ind[0];
 	dev_dbg(&priv->spi->dev, "srcAddrMode: %#03x\n", hdr.source.mode);
-	hdr.source.pan_id = *(u16 *)&data_ind[1];
+	hdr.source.pan_id = cpu_to_le16(get_unaligned_le16(&data_ind[1]));
 	dev_dbg(&priv->spi->dev, "srcPanId: %#06x\n", hdr.source.pan_id);
 	memcpy(&hdr.source.extended_addr, &data_ind[3], 8);
 	hdr.dest.mode = data_ind[11];
 	dev_dbg(&priv->spi->dev, "dstAddrMode: %#03x\n", hdr.dest.mode);
-	hdr.dest.pan_id = *(u16 *)&data_ind[12];
+	hdr.dest.pan_id = cpu_to_le16(get_unaligned_le16(&data_ind[12]));
 	dev_dbg(&priv->spi->dev, "dstPanId: %#06x\n", hdr.dest.pan_id);
 	memcpy(&hdr.dest.extended_addr, &data_ind[14], 8);
 
@@ -1927,7 +1926,7 @@ static int ca8210_skb_tx(
 	status =  mcps_data_request(
 		header.source.mode,
 		header.dest.mode,
-		header.dest.pan_id,
+		le16_to_cpu(header.dest.pan_id),
 		(union macaddr *)&header.dest.extended_addr,
 		skb->len - mac_len,
 		&skb->data[mac_len],
Signature · 1 line
2.47.2
#3 lore raw

PATCH v3 3/3 ieee802154: ca8210: Switch to using gpiod API

In reply to Andy Shevchenko

This updates the driver to gpiod API, and removes yet another use of of_get_named_gpio().

With this, invert the logic of the reset pin which is active low and add a quirk for the legacy and incorrect device tree descriptions.

---
 .../bindings/net/ieee802154/ca8210.txt        |  2 +-
 drivers/gpio/gpiolib-of.c                     |  9 +++
 drivers/net/ieee802154/ca8210.c               | 57 +++++++------------
 3 files changed, 29 insertions(+), 39 deletions(-)
Documentation/devicetree/bindings/net/ieee802154/ca8210.txt +1 -1
index a1046e636fa1..f1bd07a0097d 100644
@@ -20,7 +20,7 @@ Example:
 		reg = <0>;
 		spi-max-frequency = <3000000>;
 		spi-cpol;
-		reset-gpio = <&gpio1 1 GPIO_ACTIVE_HIGH>;
+		reset-gpio = <&gpio1 1 GPIO_ACTIVE_LOW>;
 		irq-gpio = <&gpio1 2 GPIO_ACTIVE_HIGH>;
 		extclock-enable;
 		extclock-freq = 16000000;
drivers/gpio/gpiolib-of.c +9 -0
index df351b1d6628..54e916d4c03e 100644
@@ -203,6 +203,15 @@ static void of_gpio_try_fixup_polarity(const struct device_node *np,
 		 */
 		{ "qi,lb60",		"rb-gpios",	true },
 #endif
+#if IS_ENABLED(CONFIG_IEEE802154_CA8210)
+		/*
+		 * According to the datasheet, the NRST pin 27 is an active-low
+		 * signal. However, the device tree schema and admittedly
+		 * the out-of-tree implementations have been used for a long
+		 * time incorrectly by describing reset GPIO as active-high.
+		 */
+		{ "cascoda,ca8210",	"reset-gpio",	false },
+#endif
 #if IS_ENABLED(CONFIG_PCI_LANTIQ)
 		/*
 		 * According to the PCI specification, the RST# pin is an
drivers/net/ieee802154/ca8210.c +19 -38

111 lines not on this page · raw message

Signature · 1 line
2.47.2
maintainer Reviewed-by on v3 3/3
#4 lore raw

Re: [PATCH net-next v3 3/3] ieee802154: ca8210: Switch to using gpiod API

Quoted 8 lines · Andy Shevchenko

This updates the driver to gpiod API, and removes yet another use of of_get_named_gpio().

With this, invert the logic of the reset pin which is active low and add a quirk for the legacy and incorrect device tree descriptions.

Nice.

Thanks,
Miquèl

#5 lore raw

Re: [PATCH net-next v3 3/3] ieee802154: ca8210: Switch to using gpiod API

In reply to Andy Shevchenko
Quoted 10 lines · Andy Shevchenko

This updates the driver to gpiod API, and removes yet another use of of_get_named_gpio().

With this, invert the logic of the reset pin which is active low and add a quirk for the legacy and incorrect device tree descriptions.

---
 .../bindings/net/ieee802154/ca8210.txt        |  2 +-

Bindings are always separate patches.

Please run scripts/checkpatch.pl and fix reported warnings. After that, run also 'scripts/checkpatch.pl --strict' and (probably) fix more warnings. Some warnings can be ignored, especially from --strict run, but the code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.

Best regards,
Krzysztof

#6 lore raw

Re: [PATCH net-next v3 3/3] ieee802154: ca8210: Switch to using gpiod API

Quoted 7 lines · Krzysztof Kozlowski
Quoted 6 lines · Andy Shevchenko

This updates the driver to gpiod API, and removes yet another use of of_get_named_gpio().

With this, invert the logic of the reset pin which is active low and add a quirk for the legacy and incorrect device tree descriptions.

Quoted 6 lines
Quoted 4 lines
---
 .../bindings/net/ieee802154/ca8210.txt        |  2 +-

Bindings are always separate patches.

Okay.

Quoted 6 lines

Please run scripts/checkpatch.pl and fix reported warnings. After that,
run also 'scripts/checkpatch.pl --strict' and (probably) fix more warnings. Some warnings can be ignored, especially from --strict run, but the code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.

Signature · 2 lines
With Best Regards,
Andy Shevchenko