Skip to contentSkip to conversation

at86rf230: add support for setting external xtal

PATCH In review Alexander Aring 2 participants 6 messages Feb 23, 2015

Subsystems (4)
lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

PATCH 1/1 at86rf230: add support for setting external xtal

This patch adds support for setting external xtal. This is recommended by the at86rf230 transceivers to reduce power consuming and for a better clock source.

---
 .../bindings/net/ieee802154/at86rf230.txt          |  6 ++++++
 drivers/net/ieee802154/at86rf230.c                 | 25 ++++++++++++++++++++--
 include/linux/spi/at86rf230.h                      |  2 ++
 3 files changed, 31 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt +6 -0
index d3bbdded..4d47c2e 100644
@@ -11,6 +11,10 @@ Required properties:
 Optional properties:
   - reset-gpio:		GPIO spec for the rstn pin
   - sleep-gpio:		GPIO spec for the slp_tr pin
+  - external-xtal:	boolean to use external xtal if present
+  - xtal-trim:		u8 value to fine tuning the internal capacitance
+			arrays of xtal pins. This value should not above 0x0F
+			and only present when external-xtal is enabled
 
 Example:
 
@@ -20,4 +24,6 @@ Example:
 		reg = <0>;
 		interrupts = <19 1>;
 		interrupt-parent = <&gpio3>;
+		external-xtal;
+		xtal-trim = /bits/ 8 <0x06>;
 	};
drivers/net/ieee802154/at86rf230.c +23 -2
index cbfc8c5..1a95520 100644
@@ -1315,7 +1315,8 @@ static struct at86rf2xx_chip_data at86rf212_data = {
 	.get_desense_steps = at86rf212_get_desens_steps
 };
 
-static int at86rf230_hw_init(struct at86rf230_local *lp)
+static int at86rf230_hw_init(struct at86rf230_local *lp,
+			     const struct at86rf230_platform_data *pdata)
 {
 	int rc, irq_type, irq_pol = IRQ_ACTIVE_HIGH;
 	unsigned int dvdd;
@@ -1362,6 +1363,16 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)
 	usleep_range(lp->data->t_sleep_cycle,
 		     lp->data->t_sleep_cycle + 100);
 
+	if (pdata->xtal) {
+		rc = at86rf230_write_subreg(lp, SR_XTAL_TRIM, pdata->xtal_trim);
+		if (rc)
+			return rc;
+
+		rc = at86rf230_write_subreg(lp, SR_XTAL_MODE, 0x5);
+		if (rc)
+			return rc;
+	}
+
 	rc = at86rf230_read_subreg(lp, SR_DVDD_OK, &dvdd);
 	if (rc)
 		return rc;
@@ -1392,6 +1403,16 @@ at86rf230_get_pdata(struct spi_device *spi)
 	pdata->rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0);
 	pdata->slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0);
 
+	pdata->xtal = of_property_read_bool(spi->dev.of_node, "external-xtal");
+	if (pdata->xtal) {
+		int ret;
+
+		ret = of_property_read_u8(spi->dev.of_node, "xtal-trim",
+					  &pdata->xtal_trim);
+		if (ret < 0 || pdata->xtal_trim > 0xF)
+			return NULL;
+	}
+
 	spi->dev.platform_data = pdata;
 done:
 	return pdata;
@@ -1571,7 +1592,7 @@ static int at86rf230_probe(struct spi_device *spi)
 
 	spi_set_drvdata(spi, lp);
 
-	rc = at86rf230_hw_init(lp);
+	rc = at86rf230_hw_init(lp, pdata);
 	if (rc)
 		goto free_dev;
 
include/linux/spi/at86rf230.h +2 -0
index cd519a1..632ad90 100644
@@ -22,6 +22,8 @@ struct at86rf230_platform_data {
 	int rstn;
 	int slp_tr;
 	int dig2;
+	bool xtal;
+	u8 xtal_trim;
 };
 
 #endif
Signature · 1 line
2.3.0
#1 lore raw
Quoted 65 lines · Alexander Aring

This patch adds support for setting external xtal. This is recommended by the at86rf230 transceivers to reduce power consuming and for a better clock source.

---
 .../bindings/net/ieee802154/at86rf230.txt          |  6 ++++++
 drivers/net/ieee802154/at86rf230.c                 | 25 ++++++++++++++++++++--
 include/linux/spi/at86rf230.h                      |  2 ++
 3 files changed, 31 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt +6 -0
index d3bbdded..4d47c2e 100644
@@ -11,6 +11,10 @@ Required properties:
 Optional properties:
   - reset-gpio:		GPIO spec for the rstn pin
   - sleep-gpio:		GPIO spec for the slp_tr pin
+  - external-xtal:	boolean to use external xtal if present
+  - xtal-trim:		u8 value to fine tuning the internal capacitance
+			arrays of xtal pins. This value should not above 0x0F
+			and only present when external-xtal is enabled
 
 Example:
 
@@ -20,4 +24,6 @@ Example:
 		reg = <0>;
 		interrupts = <19 1>;
 		interrupt-parent = <&gpio3>;
+		external-xtal;
+		xtal-trim = /bits/ 8 <0x06>;
 	};
drivers/net/ieee802154/at86rf230.c +12 -1
index cbfc8c5..1a95520 100644
@@ -1315,7 +1315,8 @@ static struct at86rf2xx_chip_data at86rf212_data = {
 	.get_desense_steps = at86rf212_get_desens_steps
 };
 
-static int at86rf230_hw_init(struct at86rf230_local *lp)
+static int at86rf230_hw_init(struct at86rf230_local *lp,
+			     const struct at86rf230_platform_data *pdata)
 {
 	int rc, irq_type, irq_pol = IRQ_ACTIVE_HIGH;
 	unsigned int dvdd;
@@ -1362,6 +1363,16 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)
 	usleep_range(lp->data->t_sleep_cycle,
 		     lp->data->t_sleep_cycle + 100);
 
+	if (pdata->xtal) {
+		rc = at86rf230_write_subreg(lp, SR_XTAL_TRIM, pdata->xtal_trim);
+		if (rc)
+			return rc;
+
+		rc = at86rf230_write_subreg(lp, SR_XTAL_MODE, 0x5);
+		if (rc)
+			return rc;
+	}
+
 	rc = at86rf230_read_subreg(lp, SR_DVDD_OK, &dvdd);
 	if (rc)
 		return rc;

drivers/net/ieee802154/at86rf230.c at86rf230_get_pdata(struct spi_device *spi) · line 1406

Quoted 4 lines
drivers/net/ieee802154/at86rf230.c +1 -0
@@ -1392,6 +1403,16 @@ at86rf230_get_pdata(struct spi_device *spi)
 	pdata->rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0);
 	pdata->slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0);
 
+	pdata->xtal = of_property_read_bool(spi->dev.of_node, "external-xtal");

The platform data should be considered read only by the driver. Better put the information into your per-driver private data struct.

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
author maintainer
#2 lore raw
Quoted 69 lines · Marc Kleine-Budde
Quoted 68 lines · Alexander Aring

This patch adds support for setting external xtal. This is recommended by the at86rf230 transceivers to reduce power consuming and for a better clock source.

---
 .../bindings/net/ieee802154/at86rf230.txt          |  6 ++++++
 drivers/net/ieee802154/at86rf230.c                 | 25 ++++++++++++++++++++--
 include/linux/spi/at86rf230.h                      |  2 ++
 3 files changed, 31 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt +6 -0
index d3bbdded..4d47c2e 100644
@@ -11,6 +11,10 @@ Required properties:
 Optional properties:
   - reset-gpio:		GPIO spec for the rstn pin
   - sleep-gpio:		GPIO spec for the slp_tr pin
+  - external-xtal:	boolean to use external xtal if present
+  - xtal-trim:		u8 value to fine tuning the internal capacitance
+			arrays of xtal pins. This value should not above 0x0F
+			and only present when external-xtal is enabled
 
 Example:
 
@@ -20,4 +24,6 @@ Example:
 		reg = <0>;
 		interrupts = <19 1>;
 		interrupt-parent = <&gpio3>;
+		external-xtal;
+		xtal-trim = /bits/ 8 <0x06>;
 	};
drivers/net/ieee802154/at86rf230.c +12 -1
index cbfc8c5..1a95520 100644
@@ -1315,7 +1315,8 @@ static struct at86rf2xx_chip_data at86rf212_data = {
 	.get_desense_steps = at86rf212_get_desens_steps
 };
 
-static int at86rf230_hw_init(struct at86rf230_local *lp)
+static int at86rf230_hw_init(struct at86rf230_local *lp,
+			     const struct at86rf230_platform_data *pdata)
 {
 	int rc, irq_type, irq_pol = IRQ_ACTIVE_HIGH;
 	unsigned int dvdd;
@@ -1362,6 +1363,16 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)
 	usleep_range(lp->data->t_sleep_cycle,
 		     lp->data->t_sleep_cycle + 100);
 
+	if (pdata->xtal) {
+		rc = at86rf230_write_subreg(lp, SR_XTAL_TRIM, pdata->xtal_trim);
+		if (rc)
+			return rc;
+
+		rc = at86rf230_write_subreg(lp, SR_XTAL_MODE, 0x5);
+		if (rc)
+			return rc;
+	}
+
 	rc = at86rf230_read_subreg(lp, SR_DVDD_OK, &dvdd);
 	if (rc)
 		return rc;
@@ -1392,6 +1403,16 @@ at86rf230_get_pdata(struct spi_device *spi)
 	pdata->rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0);
 	pdata->slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0);
 
Quoted 5 lines

drivers/net/ieee802154/at86rf230.c at86rf230_get_pdata(struct spi_device *spi) · line 1406

Quoted 1 line
drivers/net/ieee802154/at86rf230.c +1 -0
+	pdata->xtal = of_property_read_bool(spi->dev.of_node, "external-xtal");

The platform data should be considered read only by the driver. Better put the information into your per-driver private data struct.

ah, yes you are completely right here. Sorry :)

- Alex

author maintainer
#3 lore raw

Marc,

Quoted 3 lines · Alexander Aring
Quoted 2 lines · Marc Kleine-Budde
Quoted 1 line · Alexander Aring

This patch adds support for setting external xtal. This is recommended

...

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/ieee802154/at86rf230.c +0 -0
 	rc = at86rf230_read_subreg(lp, SR_DVDD_OK, &dvdd);
 	if (rc)
 		return rc;
@@ -1392,6 +1403,16 @@ at86rf230_get_pdata(struct spi_device *spi)
 	pdata->rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0);
 	pdata->slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0);
 
Quoted 8 lines
Quoted 5 lines

drivers/net/ieee802154/at86rf230.c at86rf230_get_pdata(struct spi_device *spi) · line 1406

Quoted 1 line
drivers/net/ieee802154/at86rf230.c +1 -0
+	pdata->xtal = of_property_read_bool(spi->dev.of_node, "external-xtal");

The platform data should be considered read only by the driver. Better put the information into your per-driver private data struct.

ah, yes you are completely right here. Sorry :)

I am not sure if this is okay here in that case. For non devicetree this code will never touched and I grab this code from some i2c driver like [0].

They also use the platform-data for setting the devicetree properties.

The only thing which I can see now is the check if (xtal > 0xF) which is not available on non devicetree settings... but I can also remove this check, somebody should make something complete wrong if this value is above 0xF and regmap should mask this value.

- Alex

[0] http://lxr.free-electrons.com/source/drivers/media/i2c/adv7343.c#L404

#4 lore raw
Quoted 20 lines · Alexander Aring

Marc,

Quoted 3 lines · Alexander Aring
Quoted 2 lines · Marc Kleine-Budde
Quoted 1 line · Alexander Aring

This patch adds support for setting external xtal. This is recommended

...

Quoted 13 lines
Quoted 12 lines

drivers/net/ieee802154/at86rf230.c at86rf230_get_pdata(struct spi_device *spi) · line 1406

Quoted 8 lines
drivers/net/ieee802154/at86rf230.c +1 -0
 	rc = at86rf230_read_subreg(lp, SR_DVDD_OK, &dvdd);
 	if (rc)
 		return rc;
@@ -1392,6 +1403,16 @@ at86rf230_get_pdata(struct spi_device *spi)
 	pdata->rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0);
 	pdata->slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0);
 
+	pdata->xtal = of_property_read_bool(spi->dev.of_node, "external-xtal");

The platform data should be considered read only by the driver. Better put the information into your per-driver private data struct.

Quoted 8 lines
Quoted 2 lines

ah, yes you are completely right here. Sorry :)

I am not sure if this is okay here in that case. For non devicetree this code will never touched and I grab this code from some i2c driver like [0].

They also use the platform-data for setting the devicetree properties.

That doesn't make it better.

Quoted 4 lines

The only thing which I can see now is the check if (xtal > 0xF) which is not available on non devicetree settings... but I can also remove this check, somebody should make something complete wrong if this value is above 0xF and regmap should mask this value.

IMHO this driver has been poorly converted to DT. The usual way would be to add data to at86rf230_local.

Marc

Signature · 4 lines
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |
author maintainer
#5 lore raw
Quoted 32 lines · Marc Kleine-Budde
Quoted 20 lines · Alexander Aring

Marc,

Quoted 3 lines · Alexander Aring
Quoted 2 lines · Marc Kleine-Budde
Quoted 1 line · Alexander Aring

This patch adds support for setting external xtal. This is recommended

...

Quoted 13 lines
Quoted 12 lines

drivers/net/ieee802154/at86rf230.c at86rf230_get_pdata(struct spi_device *spi) · line 1406

Quoted 8 lines
drivers/net/ieee802154/at86rf230.c +1 -0
 	rc = at86rf230_read_subreg(lp, SR_DVDD_OK, &dvdd);
 	if (rc)
 		return rc;
@@ -1392,6 +1403,16 @@ at86rf230_get_pdata(struct spi_device *spi)
 	pdata->rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0);
 	pdata->slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0);
 
+	pdata->xtal = of_property_read_bool(spi->dev.of_node, "external-xtal");

The platform data should be considered read only by the driver. Better put the information into your per-driver private data struct.

Quoted 8 lines
Quoted 2 lines

ah, yes you are completely right here. Sorry :)

I am not sure if this is okay here in that case. For non devicetree this code will never touched and I grab this code from some i2c driver like [0].

They also use the platform-data for setting the devicetree properties.

That doesn't make it better.

Quoted 7 lines
Quoted 4 lines

The only thing which I can see now is the check if (xtal > 0xF) which is not available on non devicetree settings... but I can also remove this check, somebody should make something complete wrong if this value is above 0xF and regmap should mask this value.

IMHO this driver has been poorly converted to DT. The usual way would be to add data to at86rf230_local.

Okay, then I will do that and fix the other things and never use another code for an example. (except the can branch) ;-)

- Alex