* [PATCH] cc2520: Add support for CC2591 amplifier.
@ 2015-03-14 22:32 Brad Campbell
2015-03-16 3:44 ` Varka Bhadram
2015-03-16 13:57 ` Alexander Aring
0 siblings, 2 replies; 3+ messages in thread
From: Brad Campbell @ 2015-03-14 22:32 UTC (permalink / raw)
To: linux-wpan; +Cc: alex.aring, Brad Campbell
The TI CC2521 is an RF power amplifier that is designed to interface
with the CC2520. Conveniently, it directly interfaces with the CC2520
and does not require any pins to be connected to a
microcontroller/processor. Adding a CC2591 increases the CC2520's range,
which is useful for border router and other wall-powered applications.
Using the CC2591 with the CC2520 requires configuring the CC2520 GPIOs
that are connected to the CC2591 to correctly set the CC2591 into TX and
RX modes. Further, TI recommends that the CC2520_TXPOWER and
CC2520_AGCCTRL1 registers are set differently to maximize the CC2591's
performance. These settings are covered in TI Application Note AN065.
This patch adds an optional `amplified` field to the cc2520 entry in the
device tree. If present and set to `1` the CC2520 will be configured to
operate with a CC2591.
The expected pin mapping is:
CC2520 GPIO0 --> CC2591 EN
CC2520 GPIO5 --> CC2591 PAEN
---
.../devicetree/bindings/net/ieee802154/cc2520.txt | 4 ++
drivers/net/ieee802154/cc2520.c | 53 ++++++++++++++++++----
include/linux/spi/cc2520.h | 1 +
3 files changed, 50 insertions(+), 8 deletions(-)
diff --git a/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt b/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt
index 0071883..c6682f9 100644
--- a/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt
+++ b/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt
@@ -13,11 +13,15 @@ Required properties:
- cca-gpio: GPIO spec for the CCA pin
- vreg-gpio: GPIO spec for the VREG pin
- reset-gpio: GPIO spec for the RESET pin
+Optional properties:
+ - amplified: set to 1 if the CC2520 is connected to a CC2591 amplifier
+
Example:
cc2520@0 {
compatible = "ti,cc2520";
reg = <0>;
spi-max-frequency = <4000000>;
+ amplified = <1>;
pinctrl-names = "default";
pinctrl-0 = <&cc2520_cape_pins>;
fifo-gpio = <&gpio1 18 0>;
diff --git a/drivers/net/ieee802154/cc2520.c b/drivers/net/ieee802154/cc2520.c
index 181b349..37c7e00 100644
--- a/drivers/net/ieee802154/cc2520.c
+++ b/drivers/net/ieee802154/cc2520.c
@@ -719,6 +719,7 @@ static int cc2520_hw_init(struct cc2520_private *priv)
u8 status = 0, state = 0xff;
int ret;
int timeout = 100;
+ struct cc2520_platform_data *pdata = priv->spi->dev.platform_data;
ret = cc2520_read_register(priv, CC2520_FSMSTAT1, &state);
if (ret)
@@ -741,11 +742,46 @@ static int cc2520_hw_init(struct cc2520_private *priv)
dev_vdbg(&priv->spi->dev, "oscillator brought up\n");
- /* Registers default value: section 28.1 in Datasheet */
- ret = cc2520_write_register(priv, CC2520_TXPOWER, 0xF7);
- if (ret)
- goto err_ret;
+ /* If the CC2520 is connected to a CC2591 amplifier, we must both
+ * configure GPIOs on the CC2520 to correctly configure the CC2591
+ * and change a couple settings of the CC2520 to work with the
+ * amplifier. See section 8 page 17 of TI application note AN065.
+ */
+ if (pdata->amplified == 1) {
+ ret = cc2520_write_register(priv, CC2520_TXPOWER, 0xF9);
+ if (ret)
+ goto err_ret;
+
+ ret = cc2520_write_register(priv, CC2520_AGCCTRL1, 0x16);
+ if (ret)
+ goto err_ret;
+
+ ret = cc2520_write_register(priv, CC2520_GPIOCTRL0, 0x46);
+ if (ret)
+ goto err_ret;
+
+ ret = cc2520_write_register(priv, CC2520_GPIOCTRL5, 0x47);
+ if (ret)
+ goto err_ret;
+
+ ret = cc2520_write_register(priv, CC2520_GPIOPOLARITY, 0x1e);
+ if (ret)
+ goto err_ret;
+ ret = cc2520_write_register(priv, CC2520_TXCTRL, 0xc1);
+ if (ret)
+ goto err_ret;
+ } else {
+ ret = cc2520_write_register(priv, CC2520_TXPOWER, 0xF7);
+ if (ret)
+ goto err_ret;
+
+ ret = cc2520_write_register(priv, CC2520_AGCCTRL1, 0x11);
+ if (ret)
+ goto err_ret;
+ }
+
+ /* Registers default value: section 28.1 in Datasheet */
ret = cc2520_write_register(priv, CC2520_CCACTRL0, 0x1A);
if (ret)
goto err_ret;
@@ -770,10 +806,6 @@ static int cc2520_hw_init(struct cc2520_private *priv)
if (ret)
goto err_ret;
- ret = cc2520_write_register(priv, CC2520_AGCCTRL1, 0x11);
- if (ret)
- goto err_ret;
-
ret = cc2520_write_register(priv, CC2520_ADCTEST0, 0x10);
if (ret)
goto err_ret;
@@ -814,6 +846,7 @@ cc2520_get_platform_data(struct spi_device *spi)
struct cc2520_platform_data *pdata;
struct device_node *np = spi->dev.of_node;
struct cc2520_private *priv = spi_get_drvdata(spi);
+ int ret;
if (!np)
return spi->dev.platform_data;
@@ -832,6 +865,10 @@ cc2520_get_platform_data(struct spi_device *spi)
pdata->vreg = of_get_named_gpio(np, "vreg-gpio", 0);
pdata->reset = of_get_named_gpio(np, "reset-gpio", 0);
+ ret = of_property_read_s32(np, "amplified", &pdata->amplified);
+ if (ret < 0)
+ pdata->amplified = 0;
+
spi->dev.platform_data = pdata;
done:
diff --git a/include/linux/spi/cc2520.h b/include/linux/spi/cc2520.h
index 85b8ee6..1810cd0 100644
--- a/include/linux/spi/cc2520.h
+++ b/include/linux/spi/cc2520.h
@@ -21,6 +21,7 @@ struct cc2520_platform_data {
int sfd;
int reset;
int vreg;
+ int amplified;
};
#endif
--
2.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] cc2520: Add support for CC2591 amplifier.
2015-03-14 22:32 [PATCH] cc2520: Add support for CC2591 amplifier Brad Campbell
@ 2015-03-16 3:44 ` Varka Bhadram
2015-03-16 13:57 ` Alexander Aring
1 sibling, 0 replies; 3+ messages in thread
From: Varka Bhadram @ 2015-03-16 3:44 UTC (permalink / raw)
To: Brad Campbell, linux-wpan - ML; +Cc: Alexander Aring
Hi Brad Campbell,
On 03/15/2015 04:02 AM, Brad Campbell wrote:
> The TI CC2521 is an RF power amplifier that is designed to interface
> with the CC2520. Conveniently, it directly interfaces with the CC2520
> and does not require any pins to be connected to a
> microcontroller/processor. Adding a CC2591 increases the CC2520's range,
> which is useful for border router and other wall-powered applications.
>
> Using the CC2591 with the CC2520 requires configuring the CC2520 GPIOs
> that are connected to the CC2591 to correctly set the CC2591 into TX and
> RX modes. Further, TI recommends that the CC2520_TXPOWER and
> CC2520_AGCCTRL1 registers are set differently to maximize the CC2591's
> performance. These settings are covered in TI Application Note AN065.
Please provide the link to Application note..
> This patch adds an optional `amplified` field to the cc2520 entry in the
> device tree. If present and set to `1` the CC2520 will be configured to
> operate with a CC2591.
>
> The expected pin mapping is:
> CC2520 GPIO0 --> CC2591 EN
> CC2520 GPIO5 --> CC2591 PAEN
> ---
> .../devicetree/bindings/net/ieee802154/cc2520.txt | 4 ++
> drivers/net/ieee802154/cc2520.c | 53 ++++++++++++++++++----
> include/linux/spi/cc2520.h | 1 +
> 3 files changed, 50 insertions(+), 8 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt b/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt
> index 0071883..c6682f9 100644
> --- a/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt
> +++ b/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt
> @@ -13,11 +13,15 @@ Required properties:
> - cca-gpio: GPIO spec for the CCA pin
> - vreg-gpio: GPIO spec for the VREG pin
> - reset-gpio: GPIO spec for the RESET pin
> +Optional properties:
> + - amplified: set to 1 if the CC2520 is connected to a CC2591 amplifier
> +
> Example:
> cc2520@0 {
> compatible = "ti,cc2520";
> reg = <0>;
> spi-max-frequency = <4000000>;
> + amplified = <1>;
> pinctrl-names = "default";
> pinctrl-0 = <&cc2520_cape_pins>;
> fifo-gpio = <&gpio1 18 0>;
> diff --git a/drivers/net/ieee802154/cc2520.c b/drivers/net/ieee802154/cc2520.c
> index 181b349..37c7e00 100644
> --- a/drivers/net/ieee802154/cc2520.c
> +++ b/drivers/net/ieee802154/cc2520.c
> @@ -719,6 +719,7 @@ static int cc2520_hw_init(struct cc2520_private *priv)
> u8 status = 0, state = 0xff;
> int ret;
> int timeout = 100;
> + struct cc2520_platform_data *pdata = priv->spi->dev.platform_data;
>
> ret = cc2520_read_register(priv, CC2520_FSMSTAT1, &state);
> if (ret)
> @@ -741,11 +742,46 @@ static int cc2520_hw_init(struct cc2520_private *priv)
>
> dev_vdbg(&priv->spi->dev, "oscillator brought up\n");
>
> - /* Registers default value: section 28.1 in Datasheet */
> - ret = cc2520_write_register(priv, CC2520_TXPOWER, 0xF7);
> - if (ret)
> - goto err_ret;
> + /* If the CC2520 is connected to a CC2591 amplifier, we must both
> + * configure GPIOs on the CC2520 to correctly configure the CC2591
> + * and change a couple settings of the CC2520 to work with the
> + * amplifier. See section 8 page 17 of TI application note AN065.
> + */
> + if (pdata->amplified == 1) {
> + ret = cc2520_write_register(priv, CC2520_TXPOWER, 0xF9);
> + if (ret)
> + goto err_ret;
> +
> + ret = cc2520_write_register(priv, CC2520_AGCCTRL1, 0x16);
> + if (ret)
> + goto err_ret;
> +
> + ret = cc2520_write_register(priv, CC2520_GPIOCTRL0, 0x46);
> + if (ret)
> + goto err_ret;
> +
> + ret = cc2520_write_register(priv, CC2520_GPIOCTRL5, 0x47);
> + if (ret)
> + goto err_ret;
> +
> + ret = cc2520_write_register(priv, CC2520_GPIOPOLARITY, 0x1e);
> + if (ret)
> + goto err_ret;
>
> + ret = cc2520_write_register(priv, CC2520_TXCTRL, 0xc1);
> + if (ret)
> + goto err_ret;
> + } else {
> + ret = cc2520_write_register(priv, CC2520_TXPOWER, 0xF7);
> + if (ret)
> + goto err_ret;
> +
> + ret = cc2520_write_register(priv, CC2520_AGCCTRL1, 0x11);
> + if (ret)
> + goto err_ret;
> + }
> +
> + /* Registers default value: section 28.1 in Datasheet */
> ret = cc2520_write_register(priv, CC2520_CCACTRL0, 0x1A);
> if (ret)
> goto err_ret;
> @@ -770,10 +806,6 @@ static int cc2520_hw_init(struct cc2520_private *priv)
> if (ret)
> goto err_ret;
>
> - ret = cc2520_write_register(priv, CC2520_AGCCTRL1, 0x11);
> - if (ret)
> - goto err_ret;
> -
> ret = cc2520_write_register(priv, CC2520_ADCTEST0, 0x10);
> if (ret)
> goto err_ret;
> @@ -814,6 +846,7 @@ cc2520_get_platform_data(struct spi_device *spi)
> struct cc2520_platform_data *pdata;
> struct device_node *np = spi->dev.of_node;
> struct cc2520_private *priv = spi_get_drvdata(spi);
> + int ret;
>
> if (!np)
> return spi->dev.platform_data;
> @@ -832,6 +865,10 @@ cc2520_get_platform_data(struct spi_device *spi)
> pdata->vreg = of_get_named_gpio(np, "vreg-gpio", 0);
> pdata->reset = of_get_named_gpio(np, "reset-gpio", 0);
>
> + ret = of_property_read_s32(np, "amplified", &pdata->amplified);
> + if (ret < 0)
> + pdata->amplified = 0;
> +
> spi->dev.platform_data = pdata;
>
> done:
> diff --git a/include/linux/spi/cc2520.h b/include/linux/spi/cc2520.h
> index 85b8ee6..1810cd0 100644
> --- a/include/linux/spi/cc2520.h
> +++ b/include/linux/spi/cc2520.h
> @@ -21,6 +21,7 @@ struct cc2520_platform_data {
> int sfd;
> int reset;
> int vreg;
> + int amplified;
This is just a flag ... So why don't we use bool instead of int.
> };
>
> #endif
Have you tested these changes along with cc2591..? Because i don't
have cc2591 to test these changes.
--
Varka Bhadram
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] cc2520: Add support for CC2591 amplifier.
2015-03-14 22:32 [PATCH] cc2520: Add support for CC2591 amplifier Brad Campbell
2015-03-16 3:44 ` Varka Bhadram
@ 2015-03-16 13:57 ` Alexander Aring
1 sibling, 0 replies; 3+ messages in thread
From: Alexander Aring @ 2015-03-16 13:57 UTC (permalink / raw)
To: Brad Campbell; +Cc: linux-wpan
Hi,
I want to note something here, if it's technical correct according the
CC2520 - Varka Bhadram needs to decide that.
On Sat, Mar 14, 2015 at 06:32:03PM -0400, Brad Campbell wrote:
> The TI CC2521 is an RF power amplifier that is designed to interface
> with the CC2520. Conveniently, it directly interfaces with the CC2520
> and does not require any pins to be connected to a
> microcontroller/processor. Adding a CC2591 increases the CC2520's range,
> which is useful for border router and other wall-powered applications.
>
> Using the CC2591 with the CC2520 requires configuring the CC2520 GPIOs
> that are connected to the CC2591 to correctly set the CC2591 into TX and
> RX modes. Further, TI recommends that the CC2520_TXPOWER and
> CC2520_AGCCTRL1 registers are set differently to maximize the CC2591's
> performance. These settings are covered in TI Application Note AN065.
>
> This patch adds an optional `amplified` field to the cc2520 entry in the
> device tree. If present and set to `1` the CC2520 will be configured to
> operate with a CC2591.
>
> The expected pin mapping is:
> CC2520 GPIO0 --> CC2591 EN
> CC2520 GPIO5 --> CC2591 PAEN
Signed-off-by is missing here. Create your patches with "fomat-patch -s"
or add a signed-off bt adding "-s" add your "git commit" commands.
> ---
> .../devicetree/bindings/net/ieee802154/cc2520.txt | 4 ++
> drivers/net/ieee802154/cc2520.c | 53 ++++++++++++++++++----
> include/linux/spi/cc2520.h | 1 +
> 3 files changed, 50 insertions(+), 8 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt b/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt
> index 0071883..c6682f9 100644
> --- a/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt
> +++ b/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt
> @@ -13,11 +13,15 @@ Required properties:
> - cca-gpio: GPIO spec for the CCA pin
> - vreg-gpio: GPIO spec for the VREG pin
> - reset-gpio: GPIO spec for the RESET pin
> +Optional properties:
> + - amplified: set to 1 if the CC2520 is connected to a CC2591 amplifier
> +
Which Varka already mentioned this should be a bool.
> Example:
> cc2520@0 {
> compatible = "ti,cc2520";
> reg = <0>;
> spi-max-frequency = <4000000>;
> + amplified = <1>;
> pinctrl-names = "default";
> pinctrl-0 = <&cc2520_cape_pins>;
> fifo-gpio = <&gpio1 18 0>;
> diff --git a/drivers/net/ieee802154/cc2520.c b/drivers/net/ieee802154/cc2520.c
> index 181b349..37c7e00 100644
> --- a/drivers/net/ieee802154/cc2520.c
> +++ b/drivers/net/ieee802154/cc2520.c
> @@ -719,6 +719,7 @@ static int cc2520_hw_init(struct cc2520_private *priv)
> u8 status = 0, state = 0xff;
> int ret;
> int timeout = 100;
> + struct cc2520_platform_data *pdata = priv->spi->dev.platform_data;
>
Normal processing now is to have "read only" access on platform_data.
Look for commit:
aaa1c4d226e4cd730075d3dac99a6d599a0190c7 ("at86rf230: copy pdata to
driver allocated space")
for a similar issue and solution.
> ret = cc2520_read_register(priv, CC2520_FSMSTAT1, &state);
> if (ret)
> @@ -741,11 +742,46 @@ static int cc2520_hw_init(struct cc2520_private *priv)
>
> dev_vdbg(&priv->spi->dev, "oscillator brought up\n");
>
...
>
> + ret = of_property_read_s32(np, "amplified", &pdata->amplified);
> + if (ret < 0)
note: if you using "of_property_read_bool" then checking on failure isn't
required here.
I mentioned here because checking (ret < 0) is wrong for an optional
attribute. Correct would be if (ret < 0 && ret != -EINVAL). See [0].
"... -EINVAL if the property does not exist".
- Alex
[0] http://lxr.free-electrons.com/source/drivers/of/base.c#L1231
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-03-16 13:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-14 22:32 [PATCH] cc2520: Add support for CC2591 amplifier Brad Campbell
2015-03-16 3:44 ` Varka Bhadram
2015-03-16 13:57 ` Alexander Aring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox