All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2 bluetooth-next 1/2] at86rf230: copy pdata to driver allocated space
@ 2015-02-23 19:29 Alexander Aring
  2015-02-23 19:29 ` [PATCHv2 bluetooth-next 2/2] at86rf230: add support for external xtal Alexander Aring
  2015-02-23 22:11 ` [PATCHv2 bluetooth-next 1/2] at86rf230: copy pdata to driver allocated space Alexander Aring
  0 siblings, 2 replies; 3+ messages in thread
From: Alexander Aring @ 2015-02-23 19:29 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, mkl, Alexander Aring

This patch copies the platform data in driver allocated space at first.
With this change we ensure that we access the allocated platform data as
readonly space.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Reported-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/ieee802154/at86rf230.c | 49 ++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 26 deletions(-)

diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index cbfc8c5..c495f23 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -1377,24 +1377,21 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)
 	return at86rf230_write_subreg(lp, SR_SLOTTED_OPERATION, 0);
 }
 
-static struct at86rf230_platform_data *
-at86rf230_get_pdata(struct spi_device *spi)
+static int at86rf230_get_pdata(struct spi_device *spi,
+			       struct at86rf230_platform_data *cfg)
 {
-	struct at86rf230_platform_data *pdata;
+	if (!IS_ENABLED(CONFIG_OF) || !spi->dev.of_node) {
+		if (!spi->dev.platform_data)
+			return -ENOENT;
 
-	if (!IS_ENABLED(CONFIG_OF) || !spi->dev.of_node)
-		return spi->dev.platform_data;
-
-	pdata = devm_kzalloc(&spi->dev, sizeof(*pdata), GFP_KERNEL);
-	if (!pdata)
-		goto done;
+		memcpy(cfg, spi->dev.platform_data, sizeof(*cfg));
+		return 0;
+	}
 
-	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);
+	cfg->rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0);
+	cfg->slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0);
 
-	spi->dev.platform_data = pdata;
-done:
-	return pdata;
+	return 0;
 }
 
 static int
@@ -1501,7 +1498,7 @@ at86rf230_setup_spi_messages(struct at86rf230_local *lp)
 
 static int at86rf230_probe(struct spi_device *spi)
 {
-	struct at86rf230_platform_data *pdata;
+	struct at86rf230_platform_data cfg;
 	struct ieee802154_hw *hw;
 	struct at86rf230_local *lp;
 	unsigned int status;
@@ -1512,32 +1509,32 @@ static int at86rf230_probe(struct spi_device *spi)
 		return -EINVAL;
 	}
 
-	pdata = at86rf230_get_pdata(spi);
-	if (!pdata) {
-		dev_err(&spi->dev, "no platform_data\n");
-		return -EINVAL;
+	rc = at86rf230_get_pdata(spi, &cfg);
+	if (rc < 0) {
+		dev_err(&spi->dev, "failed to parse platform_data: %d\n", rc);
+		return rc;
 	}
 
-	if (gpio_is_valid(pdata->rstn)) {
-		rc = devm_gpio_request_one(&spi->dev, pdata->rstn,
+	if (gpio_is_valid(cfg.rstn)) {
+		rc = devm_gpio_request_one(&spi->dev, cfg.rstn,
 					   GPIOF_OUT_INIT_HIGH, "rstn");
 		if (rc)
 			return rc;
 	}
 
-	if (gpio_is_valid(pdata->slp_tr)) {
-		rc = devm_gpio_request_one(&spi->dev, pdata->slp_tr,
+	if (gpio_is_valid(cfg.slp_tr)) {
+		rc = devm_gpio_request_one(&spi->dev, cfg.slp_tr,
 					   GPIOF_OUT_INIT_LOW, "slp_tr");
 		if (rc)
 			return rc;
 	}
 
 	/* Reset */
-	if (gpio_is_valid(pdata->rstn)) {
+	if (gpio_is_valid(cfg.rstn)) {
 		udelay(1);
-		gpio_set_value(pdata->rstn, 0);
+		gpio_set_value(cfg.rstn, 0);
 		udelay(1);
-		gpio_set_value(pdata->rstn, 1);
+		gpio_set_value(cfg.rstn, 1);
 		usleep_range(120, 240);
 	}
 
-- 
2.3.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCHv2 bluetooth-next 2/2] at86rf230: add support for external xtal
  2015-02-23 19:29 [PATCHv2 bluetooth-next 1/2] at86rf230: copy pdata to driver allocated space Alexander Aring
@ 2015-02-23 19:29 ` Alexander Aring
  2015-02-23 22:11 ` [PATCHv2 bluetooth-next 1/2] at86rf230: copy pdata to driver allocated space Alexander Aring
  1 sibling, 0 replies; 3+ messages in thread
From: Alexander Aring @ 2015-02-23 19:29 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, mkl, 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.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 .../bindings/net/ieee802154/at86rf230.txt          |  6 ++++++
 drivers/net/ieee802154/at86rf230.c                 | 23 ++++++++++++++++++++--
 include/linux/spi/at86rf230.h                      |  2 ++
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt b/Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt
index d3bbdded..4d47c2e 100644
--- a/Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt
+++ b/Documentation/devicetree/bindings/net/ieee802154/at86rf230.txt
@@ -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>;
 	};
diff --git a/drivers/net/ieee802154/at86rf230.c b/drivers/net/ieee802154/at86rf230.c
index c495f23..1853f1e 100644
--- a/drivers/net/ieee802154/at86rf230.c
+++ b/drivers/net/ieee802154/at86rf230.c
@@ -72,6 +72,7 @@ struct at86rf230_state_change {
 
 struct at86rf230_local {
 	struct spi_device *spi;
+	struct at86rf230_platform_data cfg;
 
 	struct ieee802154_hw *hw;
 	struct at86rf2xx_chip_data *data;
@@ -1362,6 +1363,17 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)
 	usleep_range(lp->data->t_sleep_cycle,
 		     lp->data->t_sleep_cycle + 100);
 
+	if (lp->cfg.xtal) {
+		rc = at86rf230_write_subreg(lp, SR_XTAL_TRIM,
+					    lp->cfg.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;
@@ -1380,18 +1392,24 @@ static int at86rf230_hw_init(struct at86rf230_local *lp)
 static int at86rf230_get_pdata(struct spi_device *spi,
 			       struct at86rf230_platform_data *cfg)
 {
+	int ret = 0;
+
 	if (!IS_ENABLED(CONFIG_OF) || !spi->dev.of_node) {
 		if (!spi->dev.platform_data)
 			return -ENOENT;
 
 		memcpy(cfg, spi->dev.platform_data, sizeof(*cfg));
-		return 0;
+		return ret;
 	}
 
 	cfg->rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0);
 	cfg->slp_tr = of_get_named_gpio(spi->dev.of_node, "sleep-gpio", 0);
+	cfg->xtal = of_property_read_bool(spi->dev.of_node, "external-xtal");
+	if (cfg->xtal)
+		ret = of_property_read_u8(spi->dev.of_node, "xtal-trim",
+					  &cfg->xtal_trim);
 
-	return 0;
+	return ret;
 }
 
 static int
@@ -1545,6 +1563,7 @@ static int at86rf230_probe(struct spi_device *spi)
 	lp = hw->priv;
 	lp->hw = hw;
 	lp->spi = spi;
+	lp->cfg = cfg;
 	hw->parent = &spi->dev;
 	hw->vif_data_size = sizeof(*lp);
 	ieee802154_random_extended_addr(&hw->phy->perm_extended_addr);
diff --git a/include/linux/spi/at86rf230.h b/include/linux/spi/at86rf230.h
index cd519a1..632ad90 100644
--- a/include/linux/spi/at86rf230.h
+++ b/include/linux/spi/at86rf230.h
@@ -22,6 +22,8 @@ struct at86rf230_platform_data {
 	int rstn;
 	int slp_tr;
 	int dig2;
+	bool xtal;
+	u8 xtal_trim;
 };
 
 #endif
-- 
2.3.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCHv2 bluetooth-next 1/2] at86rf230: copy pdata to driver allocated space
  2015-02-23 19:29 [PATCHv2 bluetooth-next 1/2] at86rf230: copy pdata to driver allocated space Alexander Aring
  2015-02-23 19:29 ` [PATCHv2 bluetooth-next 2/2] at86rf230: add support for external xtal Alexander Aring
@ 2015-02-23 22:11 ` Alexander Aring
  1 sibling, 0 replies; 3+ messages in thread
From: Alexander Aring @ 2015-02-23 22:11 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, mkl

Marcel,

please drop this serie. I misunderstood the xtal settings.

XTAL_MODE = 0x5 means an external "digital" frequency as souce.

XTAL_TRIM makes sense only, when XTAL_MODE = 0xF, which means doing
"analog" frequency over some crystal.

Sorry about that and thanks to Werner Almesberger for explaining!

I will send a new series to setting the XTAL_TRIM register only, which
makes sense on the most at86rf2xx boards which I have here.

- Alex

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-23 22:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-23 19:29 [PATCHv2 bluetooth-next 1/2] at86rf230: copy pdata to driver allocated space Alexander Aring
2015-02-23 19:29 ` [PATCHv2 bluetooth-next 2/2] at86rf230: add support for external xtal Alexander Aring
2015-02-23 22:11 ` [PATCHv2 bluetooth-next 1/2] at86rf230: copy pdata to driver allocated space Alexander Aring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.