aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Campbell <bradjc5@gmail.com>2015-03-17 16:25:46 -0400
committerMarcel Holtmann <marcel@holtmann.org>2015-03-18 12:50:25 -0400
commitf0b7d43c8a28155f50adb087a563cfc97566e477 (patch)
tree6659bbd58eed4e872cc300c64f932de9fd9ace83
parent0db055c934672bcbd9423cd5e729f602bec70a6e (diff)
cc2520: Add support for CC2591 amplifier.
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, 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: Brad Campbell <bradjc5@gmail.com> Acked-by: Varka Bhadram <varkabhadram@gmail.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r--Documentation/devicetree/bindings/net/ieee802154/cc2520.txt4
-rw-r--r--drivers/net/ieee802154/cc2520.c55
-rw-r--r--include/linux/spi/cc2520.h1
3 files changed, 52 insertions, 8 deletions
diff --git a/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt b/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt
index 0071883c08d8..fb6d49f184ed 100644
--- a/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt
+++ b/Documentation/devicetree/bindings/net/ieee802154/cc2520.txt
@@ -13,11 +13,15 @@ Required properties:
13 - cca-gpio: GPIO spec for the CCA pin 13 - cca-gpio: GPIO spec for the CCA pin
14 - vreg-gpio: GPIO spec for the VREG pin 14 - vreg-gpio: GPIO spec for the VREG pin
15 - reset-gpio: GPIO spec for the RESET pin 15 - reset-gpio: GPIO spec for the RESET pin
16Optional properties:
17 - amplified: include if the CC2520 is connected to a CC2591 amplifier
18
16Example: 19Example:
17 cc2520@0 { 20 cc2520@0 {
18 compatible = "ti,cc2520"; 21 compatible = "ti,cc2520";
19 reg = <0>; 22 reg = <0>;
20 spi-max-frequency = <4000000>; 23 spi-max-frequency = <4000000>;
24 amplified;
21 pinctrl-names = "default"; 25 pinctrl-names = "default";
22 pinctrl-0 = <&cc2520_cape_pins>; 26 pinctrl-0 = <&cc2520_cape_pins>;
23 fifo-gpio = <&gpio1 18 0>; 27 fifo-gpio = <&gpio1 18 0>;
diff --git a/drivers/net/ieee802154/cc2520.c b/drivers/net/ieee802154/cc2520.c
index 233b6c6017d4..f833b8bb6663 100644
--- a/drivers/net/ieee802154/cc2520.c
+++ b/drivers/net/ieee802154/cc2520.c
@@ -738,6 +738,8 @@ static int cc2520_get_platform_data(struct spi_device *spi,
738 pdata->vreg = of_get_named_gpio(np, "vreg-gpio", 0); 738 pdata->vreg = of_get_named_gpio(np, "vreg-gpio", 0);
739 pdata->reset = of_get_named_gpio(np, "reset-gpio", 0); 739 pdata->reset = of_get_named_gpio(np, "reset-gpio", 0);
740 740
741 pdata->amplified = of_property_read_bool(np, "amplified");
742
741 return 0; 743 return 0;
742} 744}
743 745
@@ -746,6 +748,11 @@ static int cc2520_hw_init(struct cc2520_private *priv)
746 u8 status = 0, state = 0xff; 748 u8 status = 0, state = 0xff;
747 int ret; 749 int ret;
748 int timeout = 100; 750 int timeout = 100;
751 struct cc2520_platform_data pdata;
752
753 ret = cc2520_get_platform_data(priv->spi, &pdata);
754 if (ret)
755 goto err_ret;
749 756
750 ret = cc2520_read_register(priv, CC2520_FSMSTAT1, &state); 757 ret = cc2520_read_register(priv, CC2520_FSMSTAT1, &state);
751 if (ret) 758 if (ret)
@@ -768,11 +775,47 @@ static int cc2520_hw_init(struct cc2520_private *priv)
768 775
769 dev_vdbg(&priv->spi->dev, "oscillator brought up\n"); 776 dev_vdbg(&priv->spi->dev, "oscillator brought up\n");
770 777
771 /* Registers default value: section 28.1 in Datasheet */ 778 /* If the CC2520 is connected to a CC2591 amplifier, we must both
772 ret = cc2520_write_register(priv, CC2520_TXPOWER, 0xF7); 779 * configure GPIOs on the CC2520 to correctly configure the CC2591
773 if (ret) 780 * and change a couple settings of the CC2520 to work with the
774 goto err_ret; 781 * amplifier. See section 8 page 17 of TI application note AN065.
782 * http://www.ti.com/lit/an/swra229a/swra229a.pdf
783 */
784 if (pdata.amplified) {
785 ret = cc2520_write_register(priv, CC2520_TXPOWER, 0xF9);
786 if (ret)
787 goto err_ret;
775 788
789 ret = cc2520_write_register(priv, CC2520_AGCCTRL1, 0x16);
790 if (ret)
791 goto err_ret;
792
793 ret = cc2520_write_register(priv, CC2520_GPIOCTRL0, 0x46);
794 if (ret)
795 goto err_ret;
796
797 ret = cc2520_write_register(priv, CC2520_GPIOCTRL5, 0x47);
798 if (ret)
799 goto err_ret;
800
801 ret = cc2520_write_register(priv, CC2520_GPIOPOLARITY, 0x1e);
802 if (ret)
803 goto err_ret;
804
805 ret = cc2520_write_register(priv, CC2520_TXCTRL, 0xc1);
806 if (ret)
807 goto err_ret;
808 } else {
809 ret = cc2520_write_register(priv, CC2520_TXPOWER, 0xF7);
810 if (ret)
811 goto err_ret;
812
813 ret = cc2520_write_register(priv, CC2520_AGCCTRL1, 0x11);
814 if (ret)
815 goto err_ret;
816 }
817
818 /* Registers default value: section 28.1 in Datasheet */
776 ret = cc2520_write_register(priv, CC2520_CCACTRL0, 0x1A); 819 ret = cc2520_write_register(priv, CC2520_CCACTRL0, 0x1A);
777 if (ret) 820 if (ret)
778 goto err_ret; 821 goto err_ret;
@@ -797,10 +840,6 @@ static int cc2520_hw_init(struct cc2520_private *priv)
797 if (ret) 840 if (ret)
798 goto err_ret; 841 goto err_ret;
799 842
800 ret = cc2520_write_register(priv, CC2520_AGCCTRL1, 0x11);
801 if (ret)
802 goto err_ret;
803
804 ret = cc2520_write_register(priv, CC2520_ADCTEST0, 0x10); 843 ret = cc2520_write_register(priv, CC2520_ADCTEST0, 0x10);
805 if (ret) 844 if (ret)
806 goto err_ret; 845 goto err_ret;
diff --git a/include/linux/spi/cc2520.h b/include/linux/spi/cc2520.h
index 85b8ee67e937..e741e8baad92 100644
--- a/include/linux/spi/cc2520.h
+++ b/include/linux/spi/cc2520.h
@@ -21,6 +21,7 @@ struct cc2520_platform_data {
21 int sfd; 21 int sfd;
22 int reset; 22 int reset;
23 int vreg; 23 int vreg;
24 bool amplified;
24}; 25};
25 26
26#endif 27#endif