diff options
author | Grant Likely <grant.likely@secretlab.ca> | 2013-02-12 12:48:37 -0500 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2013-02-13 05:11:53 -0500 |
commit | e80beb27d2f81a1c3c8887e0e0a82d77bb392d28 (patch) | |
tree | 1f81c7ffb20b23d5f7a157e996fbb176779af88a /drivers/spi | |
parent | bd69f73f2c81eed9a398708b8c4bb3409ba1b0f9 (diff) |
gpio: Make of_count_named_gpios() use new of_count_phandle_with_args()
This patch replaces the horribly coded of_count_named_gpios() with a
call to of_count_phandle_with_args() which is far more efficient. This
also changes the return value of of_gpio_count() & of_gpio_named_count()
from 'unsigned int' to 'int' so that it can return an error code. All
the users of that function are fixed up to correctly handle a negative
return value.
v2: Split GPIO portion into a separate patch
Tested-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Rob Herring <rob.herring@calxeda.com>
Diffstat (limited to 'drivers/spi')
-rw-r--r-- | drivers/spi/spi-fsl-spi.c | 4 | ||||
-rw-r--r-- | drivers/spi/spi-oc-tiny.c | 8 | ||||
-rw-r--r-- | drivers/spi/spi-ppc4xx.c | 4 | ||||
-rw-r--r-- | drivers/spi/spi.c | 5 |
4 files changed, 10 insertions, 11 deletions
diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c index 1a7f6359d998..086a9eef2e05 100644 --- a/drivers/spi/spi-fsl-spi.c +++ b/drivers/spi/spi-fsl-spi.c | |||
@@ -947,12 +947,12 @@ static int of_fsl_spi_get_chipselects(struct device *dev) | |||
947 | struct device_node *np = dev->of_node; | 947 | struct device_node *np = dev->of_node; |
948 | struct fsl_spi_platform_data *pdata = dev->platform_data; | 948 | struct fsl_spi_platform_data *pdata = dev->platform_data; |
949 | struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(pdata); | 949 | struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(pdata); |
950 | unsigned int ngpios; | 950 | int ngpios; |
951 | int i = 0; | 951 | int i = 0; |
952 | int ret; | 952 | int ret; |
953 | 953 | ||
954 | ngpios = of_gpio_count(np); | 954 | ngpios = of_gpio_count(np); |
955 | if (!ngpios) { | 955 | if (ngpios <= 0) { |
956 | /* | 956 | /* |
957 | * SPI w/o chip-select line. One SPI device is still permitted | 957 | * SPI w/o chip-select line. One SPI device is still permitted |
958 | * though. | 958 | * though. |
diff --git a/drivers/spi/spi-oc-tiny.c b/drivers/spi/spi-oc-tiny.c index 432e66ec3088..cb2e284bd814 100644 --- a/drivers/spi/spi-oc-tiny.c +++ b/drivers/spi/spi-oc-tiny.c | |||
@@ -54,7 +54,7 @@ struct tiny_spi { | |||
54 | unsigned int txc, rxc; | 54 | unsigned int txc, rxc; |
55 | const u8 *txp; | 55 | const u8 *txp; |
56 | u8 *rxp; | 56 | u8 *rxp; |
57 | unsigned int gpio_cs_count; | 57 | int gpio_cs_count; |
58 | int *gpio_cs; | 58 | int *gpio_cs; |
59 | }; | 59 | }; |
60 | 60 | ||
@@ -74,7 +74,7 @@ static void tiny_spi_chipselect(struct spi_device *spi, int is_active) | |||
74 | { | 74 | { |
75 | struct tiny_spi *hw = tiny_spi_to_hw(spi); | 75 | struct tiny_spi *hw = tiny_spi_to_hw(spi); |
76 | 76 | ||
77 | if (hw->gpio_cs_count) { | 77 | if (hw->gpio_cs_count > 0) { |
78 | gpio_set_value(hw->gpio_cs[spi->chip_select], | 78 | gpio_set_value(hw->gpio_cs[spi->chip_select], |
79 | (spi->mode & SPI_CS_HIGH) ? is_active : !is_active); | 79 | (spi->mode & SPI_CS_HIGH) ? is_active : !is_active); |
80 | } | 80 | } |
@@ -254,7 +254,7 @@ static int tiny_spi_of_probe(struct platform_device *pdev) | |||
254 | if (!np) | 254 | if (!np) |
255 | return 0; | 255 | return 0; |
256 | hw->gpio_cs_count = of_gpio_count(np); | 256 | hw->gpio_cs_count = of_gpio_count(np); |
257 | if (hw->gpio_cs_count) { | 257 | if (hw->gpio_cs_count > 0) { |
258 | hw->gpio_cs = devm_kzalloc(&pdev->dev, | 258 | hw->gpio_cs = devm_kzalloc(&pdev->dev, |
259 | hw->gpio_cs_count * sizeof(unsigned int), | 259 | hw->gpio_cs_count * sizeof(unsigned int), |
260 | GFP_KERNEL); | 260 | GFP_KERNEL); |
@@ -352,7 +352,7 @@ static int tiny_spi_probe(struct platform_device *pdev) | |||
352 | goto exit_gpio; | 352 | goto exit_gpio; |
353 | gpio_direction_output(hw->gpio_cs[i], 1); | 353 | gpio_direction_output(hw->gpio_cs[i], 1); |
354 | } | 354 | } |
355 | hw->bitbang.master->num_chipselect = max(1U, hw->gpio_cs_count); | 355 | hw->bitbang.master->num_chipselect = max(1, hw->gpio_cs_count); |
356 | 356 | ||
357 | /* register our spi controller */ | 357 | /* register our spi controller */ |
358 | err = spi_bitbang_start(&hw->bitbang); | 358 | err = spi_bitbang_start(&hw->bitbang); |
diff --git a/drivers/spi/spi-ppc4xx.c b/drivers/spi/spi-ppc4xx.c index 7a85f22b6474..af3e6e756dc9 100644 --- a/drivers/spi/spi-ppc4xx.c +++ b/drivers/spi/spi-ppc4xx.c | |||
@@ -419,7 +419,7 @@ static int __init spi_ppc4xx_of_probe(struct platform_device *op) | |||
419 | * This includes both "null" gpio's and real ones. | 419 | * This includes both "null" gpio's and real ones. |
420 | */ | 420 | */ |
421 | num_gpios = of_gpio_count(np); | 421 | num_gpios = of_gpio_count(np); |
422 | if (num_gpios) { | 422 | if (num_gpios > 0) { |
423 | int i; | 423 | int i; |
424 | 424 | ||
425 | hw->gpios = kzalloc(sizeof(int) * num_gpios, GFP_KERNEL); | 425 | hw->gpios = kzalloc(sizeof(int) * num_gpios, GFP_KERNEL); |
@@ -471,7 +471,7 @@ static int __init spi_ppc4xx_of_probe(struct platform_device *op) | |||
471 | SPI_CPHA | SPI_CPOL | SPI_CS_HIGH | SPI_LSB_FIRST; | 471 | SPI_CPHA | SPI_CPOL | SPI_CS_HIGH | SPI_LSB_FIRST; |
472 | 472 | ||
473 | /* this many pins in all GPIO controllers */ | 473 | /* this many pins in all GPIO controllers */ |
474 | bbp->master->num_chipselect = num_gpios; | 474 | bbp->master->num_chipselect = num_gpios > 0 ? num_gpios : 0; |
475 | 475 | ||
476 | /* Get the clock for the OPB */ | 476 | /* Get the clock for the OPB */ |
477 | opbnp = of_find_compatible_node(NULL, NULL, "ibm,opb"); | 477 | opbnp = of_find_compatible_node(NULL, NULL, "ibm,opb"); |
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 19ee901577da..21c47482d9fd 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c | |||
@@ -1059,15 +1059,14 @@ EXPORT_SYMBOL_GPL(spi_alloc_master); | |||
1059 | #ifdef CONFIG_OF | 1059 | #ifdef CONFIG_OF |
1060 | static int of_spi_register_master(struct spi_master *master) | 1060 | static int of_spi_register_master(struct spi_master *master) |
1061 | { | 1061 | { |
1062 | u16 nb; | 1062 | int nb, i, *cs; |
1063 | int i, *cs; | ||
1064 | struct device_node *np = master->dev.of_node; | 1063 | struct device_node *np = master->dev.of_node; |
1065 | 1064 | ||
1066 | if (!np) | 1065 | if (!np) |
1067 | return 0; | 1066 | return 0; |
1068 | 1067 | ||
1069 | nb = of_gpio_named_count(np, "cs-gpios"); | 1068 | nb = of_gpio_named_count(np, "cs-gpios"); |
1070 | master->num_chipselect = max(nb, master->num_chipselect); | 1069 | master->num_chipselect = max(nb, (int)master->num_chipselect); |
1071 | 1070 | ||
1072 | if (nb < 1) | 1071 | if (nb < 1) |
1073 | return 0; | 1072 | return 0; |