aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrent Piepho <tpiepho@gmail.com>2013-09-27 08:37:25 -0400
committerMark Brown <broonie@linaro.org>2013-09-27 09:53:59 -0400
commit89da4293a7bb29ac42b7dd2c2573c8a5ebb0b6c7 (patch)
treeaa3aa31c37fdfef8c4d5b9aed4a4e72eeaa896d1
parent70fac17cec347c4013cb8f380c6fe6554a13d884 (diff)
spi: Use of_property_read_u32
Instead of getting the raw property, checking the length, and doing endian conversion each time, use the OF function of_property_read_u32() that does all that. Error messages are slightly improved with error codes from of_property_read_u32() for different ways the property may be invalid (missing, too short, etc.) Signed-off-by: Trent Piepho <tpiepho@gmail.com> Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r--drivers/spi/spi.c49
1 files changed, 23 insertions, 26 deletions
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 74a526ce8c04..1cd491f79422 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -838,9 +838,8 @@ static void of_register_spi_devices(struct spi_master *master)
838{ 838{
839 struct spi_device *spi; 839 struct spi_device *spi;
840 struct device_node *nc; 840 struct device_node *nc;
841 const __be32 *prop;
842 int rc; 841 int rc;
843 int len; 842 u32 value;
844 843
845 if (!master->dev.of_node) 844 if (!master->dev.of_node)
846 return; 845 return;
@@ -865,14 +864,14 @@ static void of_register_spi_devices(struct spi_master *master)
865 } 864 }
866 865
867 /* Device address */ 866 /* Device address */
868 prop = of_get_property(nc, "reg", &len); 867 rc = of_property_read_u32(nc, "reg", &value);
869 if (!prop || len < sizeof(*prop)) { 868 if (rc) {
870 dev_err(&master->dev, "%s has no 'reg' property\n", 869 dev_err(&master->dev, "%s has no valid 'reg' property (%d)\n",
871 nc->full_name); 870 nc->full_name, rc);
872 spi_dev_put(spi); 871 spi_dev_put(spi);
873 continue; 872 continue;
874 } 873 }
875 spi->chip_select = be32_to_cpup(prop); 874 spi->chip_select = value;
876 875
877 /* Mode (clock phase/polarity/etc.) */ 876 /* Mode (clock phase/polarity/etc.) */
878 if (of_find_property(nc, "spi-cpha", NULL)) 877 if (of_find_property(nc, "spi-cpha", NULL))
@@ -885,55 +884,53 @@ static void of_register_spi_devices(struct spi_master *master)
885 spi->mode |= SPI_3WIRE; 884 spi->mode |= SPI_3WIRE;
886 885
887 /* Device DUAL/QUAD mode */ 886 /* Device DUAL/QUAD mode */
888 prop = of_get_property(nc, "spi-tx-bus-width", &len); 887 if (!of_property_read_u32(nc, "spi-tx-bus-width", &value)) {
889 if (prop && len == sizeof(*prop)) { 888 switch (value) {
890 switch (be32_to_cpup(prop)) { 889 case 1:
891 case SPI_NBITS_SINGLE:
892 break; 890 break;
893 case SPI_NBITS_DUAL: 891 case 2:
894 spi->mode |= SPI_TX_DUAL; 892 spi->mode |= SPI_TX_DUAL;
895 break; 893 break;
896 case SPI_NBITS_QUAD: 894 case 4:
897 spi->mode |= SPI_TX_QUAD; 895 spi->mode |= SPI_TX_QUAD;
898 break; 896 break;
899 default: 897 default:
900 dev_err(&master->dev, 898 dev_err(&master->dev,
901 "spi-tx-bus-width %d not supported\n", 899 "spi-tx-bus-width %d not supported\n",
902 be32_to_cpup(prop)); 900 value);
903 spi_dev_put(spi); 901 spi_dev_put(spi);
904 continue; 902 continue;
905 } 903 }
906 } 904 }
907 905
908 prop = of_get_property(nc, "spi-rx-bus-width", &len); 906 if (!of_property_read_u32(nc, "spi-rx-bus-width", &value)) {
909 if (prop && len == sizeof(*prop)) { 907 switch (value) {
910 switch (be32_to_cpup(prop)) { 908 case 1:
911 case SPI_NBITS_SINGLE:
912 break; 909 break;
913 case SPI_NBITS_DUAL: 910 case 2:
914 spi->mode |= SPI_RX_DUAL; 911 spi->mode |= SPI_RX_DUAL;
915 break; 912 break;
916 case SPI_NBITS_QUAD: 913 case 4:
917 spi->mode |= SPI_RX_QUAD; 914 spi->mode |= SPI_RX_QUAD;
918 break; 915 break;
919 default: 916 default:
920 dev_err(&master->dev, 917 dev_err(&master->dev,
921 "spi-rx-bus-width %d not supported\n", 918 "spi-rx-bus-width %d not supported\n",
922 be32_to_cpup(prop)); 919 value);
923 spi_dev_put(spi); 920 spi_dev_put(spi);
924 continue; 921 continue;
925 } 922 }
926 } 923 }
927 924
928 /* Device speed */ 925 /* Device speed */
929 prop = of_get_property(nc, "spi-max-frequency", &len); 926 rc = of_property_read_u32(nc, "spi-max-frequency", &value);
930 if (!prop || len < sizeof(*prop)) { 927 if (rc) {
931 dev_err(&master->dev, "%s has no 'spi-max-frequency' property\n", 928 dev_err(&master->dev, "%s has no valid 'spi-max-frequency' property (%d)\n",
932 nc->full_name); 929 nc->full_name, rc);
933 spi_dev_put(spi); 930 spi_dev_put(spi);
934 continue; 931 continue;
935 } 932 }
936 spi->max_speed_hz = be32_to_cpup(prop); 933 spi->max_speed_hz = value;
937 934
938 /* IRQ */ 935 /* IRQ */
939 spi->irq = irq_of_parse_and_map(nc, 0); 936 spi->irq = irq_of_parse_and_map(nc, 0);