diff options
author | Brad Campbell <bradjc5@gmail.com> | 2015-03-17 16:25:45 -0400 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2015-03-18 12:50:25 -0400 |
commit | 0db055c934672bcbd9423cd5e729f602bec70a6e (patch) | |
tree | 78bc65cba11a0cd6c4e8200243685eb794f116bc /drivers/net/ieee802154 | |
parent | 63511f6d5ba0c20850448991be297751ddb6798c (diff) |
cc2520: Do not store platform_data in spi_device
Storing the `platform_data` struct inside of the SPI struct when using
the device tree allows for a later function to edit the content of that
struct. This patch refactors the `cc2520_get_platformat_data` function
to accept a pointer to a `cc2520_platform_data` struct and populates
the fields inside of it.
This change mirrors commit aaa1c4d226e4cd730075d3dac99a6d599a0190c7
("at86rf230: copy pdata to driver allocated space").
Signed-off-by: Brad Campbell <bradjc5@gmail.com>
Acked-by: Varka Bhadram <varkabhadram@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'drivers/net/ieee802154')
-rw-r--r-- | drivers/net/ieee802154/cc2520.c | 95 |
1 files changed, 46 insertions, 49 deletions
diff --git a/drivers/net/ieee802154/cc2520.c b/drivers/net/ieee802154/cc2520.c index 181b349b060e..233b6c6017d4 100644 --- a/drivers/net/ieee802154/cc2520.c +++ b/drivers/net/ieee802154/cc2520.c | |||
@@ -714,6 +714,33 @@ static irqreturn_t cc2520_sfd_isr(int irq, void *data) | |||
714 | return IRQ_HANDLED; | 714 | return IRQ_HANDLED; |
715 | } | 715 | } |
716 | 716 | ||
717 | static int cc2520_get_platform_data(struct spi_device *spi, | ||
718 | struct cc2520_platform_data *pdata) | ||
719 | { | ||
720 | struct device_node *np = spi->dev.of_node; | ||
721 | struct cc2520_private *priv = spi_get_drvdata(spi); | ||
722 | |||
723 | if (!np) { | ||
724 | struct cc2520_platform_data *spi_pdata = spi->dev.platform_data; | ||
725 | if (!spi_pdata) | ||
726 | return -ENOENT; | ||
727 | *pdata = *spi_pdata; | ||
728 | return 0; | ||
729 | } | ||
730 | |||
731 | pdata->fifo = of_get_named_gpio(np, "fifo-gpio", 0); | ||
732 | priv->fifo_pin = pdata->fifo; | ||
733 | |||
734 | pdata->fifop = of_get_named_gpio(np, "fifop-gpio", 0); | ||
735 | |||
736 | pdata->sfd = of_get_named_gpio(np, "sfd-gpio", 0); | ||
737 | pdata->cca = of_get_named_gpio(np, "cca-gpio", 0); | ||
738 | pdata->vreg = of_get_named_gpio(np, "vreg-gpio", 0); | ||
739 | pdata->reset = of_get_named_gpio(np, "reset-gpio", 0); | ||
740 | |||
741 | return 0; | ||
742 | } | ||
743 | |||
717 | static int cc2520_hw_init(struct cc2520_private *priv) | 744 | static int cc2520_hw_init(struct cc2520_private *priv) |
718 | { | 745 | { |
719 | u8 status = 0, state = 0xff; | 746 | u8 status = 0, state = 0xff; |
@@ -808,40 +835,10 @@ err_ret: | |||
808 | return ret; | 835 | return ret; |
809 | } | 836 | } |
810 | 837 | ||
811 | static struct cc2520_platform_data * | ||
812 | cc2520_get_platform_data(struct spi_device *spi) | ||
813 | { | ||
814 | struct cc2520_platform_data *pdata; | ||
815 | struct device_node *np = spi->dev.of_node; | ||
816 | struct cc2520_private *priv = spi_get_drvdata(spi); | ||
817 | |||
818 | if (!np) | ||
819 | return spi->dev.platform_data; | ||
820 | |||
821 | pdata = devm_kzalloc(&spi->dev, sizeof(*pdata), GFP_KERNEL); | ||
822 | if (!pdata) | ||
823 | goto done; | ||
824 | |||
825 | pdata->fifo = of_get_named_gpio(np, "fifo-gpio", 0); | ||
826 | priv->fifo_pin = pdata->fifo; | ||
827 | |||
828 | pdata->fifop = of_get_named_gpio(np, "fifop-gpio", 0); | ||
829 | |||
830 | pdata->sfd = of_get_named_gpio(np, "sfd-gpio", 0); | ||
831 | pdata->cca = of_get_named_gpio(np, "cca-gpio", 0); | ||
832 | pdata->vreg = of_get_named_gpio(np, "vreg-gpio", 0); | ||
833 | pdata->reset = of_get_named_gpio(np, "reset-gpio", 0); | ||
834 | |||
835 | spi->dev.platform_data = pdata; | ||
836 | |||
837 | done: | ||
838 | return pdata; | ||
839 | } | ||
840 | |||
841 | static int cc2520_probe(struct spi_device *spi) | 838 | static int cc2520_probe(struct spi_device *spi) |
842 | { | 839 | { |
843 | struct cc2520_private *priv; | 840 | struct cc2520_private *priv; |
844 | struct cc2520_platform_data *pdata; | 841 | struct cc2520_platform_data pdata; |
845 | int ret; | 842 | int ret; |
846 | 843 | ||
847 | priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL); | 844 | priv = devm_kzalloc(&spi->dev, sizeof(*priv), GFP_KERNEL); |
@@ -850,8 +847,8 @@ static int cc2520_probe(struct spi_device *spi) | |||
850 | 847 | ||
851 | spi_set_drvdata(spi, priv); | 848 | spi_set_drvdata(spi, priv); |
852 | 849 | ||
853 | pdata = cc2520_get_platform_data(spi); | 850 | ret = cc2520_get_platform_data(spi, &pdata); |
854 | if (!pdata) { | 851 | if (ret < 0) { |
855 | dev_err(&spi->dev, "no platform data\n"); | 852 | dev_err(&spi->dev, "no platform data\n"); |
856 | return -EINVAL; | 853 | return -EINVAL; |
857 | } | 854 | } |
@@ -869,76 +866,76 @@ static int cc2520_probe(struct spi_device *spi) | |||
869 | init_completion(&priv->tx_complete); | 866 | init_completion(&priv->tx_complete); |
870 | 867 | ||
871 | /* Request all the gpio's */ | 868 | /* Request all the gpio's */ |
872 | if (!gpio_is_valid(pdata->fifo)) { | 869 | if (!gpio_is_valid(pdata.fifo)) { |
873 | dev_err(&spi->dev, "fifo gpio is not valid\n"); | 870 | dev_err(&spi->dev, "fifo gpio is not valid\n"); |
874 | ret = -EINVAL; | 871 | ret = -EINVAL; |
875 | goto err_hw_init; | 872 | goto err_hw_init; |
876 | } | 873 | } |
877 | 874 | ||
878 | ret = devm_gpio_request_one(&spi->dev, pdata->fifo, | 875 | ret = devm_gpio_request_one(&spi->dev, pdata.fifo, |
879 | GPIOF_IN, "fifo"); | 876 | GPIOF_IN, "fifo"); |
880 | if (ret) | 877 | if (ret) |
881 | goto err_hw_init; | 878 | goto err_hw_init; |
882 | 879 | ||
883 | if (!gpio_is_valid(pdata->cca)) { | 880 | if (!gpio_is_valid(pdata.cca)) { |
884 | dev_err(&spi->dev, "cca gpio is not valid\n"); | 881 | dev_err(&spi->dev, "cca gpio is not valid\n"); |
885 | ret = -EINVAL; | 882 | ret = -EINVAL; |
886 | goto err_hw_init; | 883 | goto err_hw_init; |
887 | } | 884 | } |
888 | 885 | ||
889 | ret = devm_gpio_request_one(&spi->dev, pdata->cca, | 886 | ret = devm_gpio_request_one(&spi->dev, pdata.cca, |
890 | GPIOF_IN, "cca"); | 887 | GPIOF_IN, "cca"); |
891 | if (ret) | 888 | if (ret) |
892 | goto err_hw_init; | 889 | goto err_hw_init; |
893 | 890 | ||
894 | if (!gpio_is_valid(pdata->fifop)) { | 891 | if (!gpio_is_valid(pdata.fifop)) { |
895 | dev_err(&spi->dev, "fifop gpio is not valid\n"); | 892 | dev_err(&spi->dev, "fifop gpio is not valid\n"); |
896 | ret = -EINVAL; | 893 | ret = -EINVAL; |
897 | goto err_hw_init; | 894 | goto err_hw_init; |
898 | } | 895 | } |
899 | 896 | ||
900 | ret = devm_gpio_request_one(&spi->dev, pdata->fifop, | 897 | ret = devm_gpio_request_one(&spi->dev, pdata.fifop, |
901 | GPIOF_IN, "fifop"); | 898 | GPIOF_IN, "fifop"); |
902 | if (ret) | 899 | if (ret) |
903 | goto err_hw_init; | 900 | goto err_hw_init; |
904 | 901 | ||
905 | if (!gpio_is_valid(pdata->sfd)) { | 902 | if (!gpio_is_valid(pdata.sfd)) { |
906 | dev_err(&spi->dev, "sfd gpio is not valid\n"); | 903 | dev_err(&spi->dev, "sfd gpio is not valid\n"); |
907 | ret = -EINVAL; | 904 | ret = -EINVAL; |
908 | goto err_hw_init; | 905 | goto err_hw_init; |
909 | } | 906 | } |
910 | 907 | ||
911 | ret = devm_gpio_request_one(&spi->dev, pdata->sfd, | 908 | ret = devm_gpio_request_one(&spi->dev, pdata.sfd, |
912 | GPIOF_IN, "sfd"); | 909 | GPIOF_IN, "sfd"); |
913 | if (ret) | 910 | if (ret) |
914 | goto err_hw_init; | 911 | goto err_hw_init; |
915 | 912 | ||
916 | if (!gpio_is_valid(pdata->reset)) { | 913 | if (!gpio_is_valid(pdata.reset)) { |
917 | dev_err(&spi->dev, "reset gpio is not valid\n"); | 914 | dev_err(&spi->dev, "reset gpio is not valid\n"); |
918 | ret = -EINVAL; | 915 | ret = -EINVAL; |
919 | goto err_hw_init; | 916 | goto err_hw_init; |
920 | } | 917 | } |
921 | 918 | ||
922 | ret = devm_gpio_request_one(&spi->dev, pdata->reset, | 919 | ret = devm_gpio_request_one(&spi->dev, pdata.reset, |
923 | GPIOF_OUT_INIT_LOW, "reset"); | 920 | GPIOF_OUT_INIT_LOW, "reset"); |
924 | if (ret) | 921 | if (ret) |
925 | goto err_hw_init; | 922 | goto err_hw_init; |
926 | 923 | ||
927 | if (!gpio_is_valid(pdata->vreg)) { | 924 | if (!gpio_is_valid(pdata.vreg)) { |
928 | dev_err(&spi->dev, "vreg gpio is not valid\n"); | 925 | dev_err(&spi->dev, "vreg gpio is not valid\n"); |
929 | ret = -EINVAL; | 926 | ret = -EINVAL; |
930 | goto err_hw_init; | 927 | goto err_hw_init; |
931 | } | 928 | } |
932 | 929 | ||
933 | ret = devm_gpio_request_one(&spi->dev, pdata->vreg, | 930 | ret = devm_gpio_request_one(&spi->dev, pdata.vreg, |
934 | GPIOF_OUT_INIT_LOW, "vreg"); | 931 | GPIOF_OUT_INIT_LOW, "vreg"); |
935 | if (ret) | 932 | if (ret) |
936 | goto err_hw_init; | 933 | goto err_hw_init; |
937 | 934 | ||
938 | gpio_set_value(pdata->vreg, HIGH); | 935 | gpio_set_value(pdata.vreg, HIGH); |
939 | usleep_range(100, 150); | 936 | usleep_range(100, 150); |
940 | 937 | ||
941 | gpio_set_value(pdata->reset, HIGH); | 938 | gpio_set_value(pdata.reset, HIGH); |
942 | usleep_range(200, 250); | 939 | usleep_range(200, 250); |
943 | 940 | ||
944 | ret = cc2520_hw_init(priv); | 941 | ret = cc2520_hw_init(priv); |
@@ -947,7 +944,7 @@ static int cc2520_probe(struct spi_device *spi) | |||
947 | 944 | ||
948 | /* Set up fifop interrupt */ | 945 | /* Set up fifop interrupt */ |
949 | ret = devm_request_irq(&spi->dev, | 946 | ret = devm_request_irq(&spi->dev, |
950 | gpio_to_irq(pdata->fifop), | 947 | gpio_to_irq(pdata.fifop), |
951 | cc2520_fifop_isr, | 948 | cc2520_fifop_isr, |
952 | IRQF_TRIGGER_RISING, | 949 | IRQF_TRIGGER_RISING, |
953 | dev_name(&spi->dev), | 950 | dev_name(&spi->dev), |
@@ -959,7 +956,7 @@ static int cc2520_probe(struct spi_device *spi) | |||
959 | 956 | ||
960 | /* Set up sfd interrupt */ | 957 | /* Set up sfd interrupt */ |
961 | ret = devm_request_irq(&spi->dev, | 958 | ret = devm_request_irq(&spi->dev, |
962 | gpio_to_irq(pdata->sfd), | 959 | gpio_to_irq(pdata.sfd), |
963 | cc2520_sfd_isr, | 960 | cc2520_sfd_isr, |
964 | IRQF_TRIGGER_FALLING, | 961 | IRQF_TRIGGER_FALLING, |
965 | dev_name(&spi->dev), | 962 | dev_name(&spi->dev), |