aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpio/gpiolib-of.c35
-rw-r--r--drivers/hwmon/gpio-fan.c4
-rw-r--r--drivers/input/keyboard/matrix_keypad.c8
-rw-r--r--drivers/net/phy/mdio-mux-gpio.c4
-rw-r--r--drivers/spi/spi-fsl-spi.c4
-rw-r--r--drivers/spi/spi-oc-tiny.c8
-rw-r--r--drivers/spi/spi-ppc4xx.c4
-rw-r--r--drivers/spi/spi.c5
8 files changed, 18 insertions, 54 deletions
diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index d542a141811a..dd8a2129222f 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -89,41 +89,6 @@ int of_get_named_gpio_flags(struct device_node *np, const char *propname,
89EXPORT_SYMBOL(of_get_named_gpio_flags); 89EXPORT_SYMBOL(of_get_named_gpio_flags);
90 90
91/** 91/**
92 * of_gpio_named_count - Count GPIOs for a device
93 * @np: device node to count GPIOs for
94 * @propname: property name containing gpio specifier(s)
95 *
96 * The function returns the count of GPIOs specified for a node.
97 *
98 * Note that the empty GPIO specifiers counts too. For example,
99 *
100 * gpios = <0
101 * &pio1 1 2
102 * 0
103 * &pio2 3 4>;
104 *
105 * defines four GPIOs (so this function will return 4), two of which
106 * are not specified.
107 */
108unsigned int of_gpio_named_count(struct device_node *np, const char* propname)
109{
110 unsigned int cnt = 0;
111
112 do {
113 int ret;
114
115 ret = of_parse_phandle_with_args(np, propname, "#gpio-cells",
116 cnt, NULL);
117 /* A hole in the gpios = <> counts anyway. */
118 if (ret < 0 && ret != -EEXIST)
119 break;
120 } while (++cnt);
121
122 return cnt;
123}
124EXPORT_SYMBOL(of_gpio_named_count);
125
126/**
127 * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags 92 * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags
128 * @gc: pointer to the gpio_chip structure 93 * @gc: pointer to the gpio_chip structure
129 * @np: device node of the GPIO chip 94 * @np: device node of the GPIO chip
diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c
index 4e04c1228e51..39781945a5d2 100644
--- a/drivers/hwmon/gpio-fan.c
+++ b/drivers/hwmon/gpio-fan.c
@@ -422,7 +422,7 @@ static int gpio_fan_get_of_pdata(struct device *dev,
422 422
423 /* Fill GPIO pin array */ 423 /* Fill GPIO pin array */
424 pdata->num_ctrl = of_gpio_count(node); 424 pdata->num_ctrl = of_gpio_count(node);
425 if (!pdata->num_ctrl) { 425 if (pdata->num_ctrl <= 0) {
426 dev_err(dev, "gpios DT property empty / missing"); 426 dev_err(dev, "gpios DT property empty / missing");
427 return -ENODEV; 427 return -ENODEV;
428 } 428 }
@@ -477,7 +477,7 @@ static int gpio_fan_get_of_pdata(struct device *dev,
477 pdata->speed = speed; 477 pdata->speed = speed;
478 478
479 /* Alarm GPIO if one exists */ 479 /* Alarm GPIO if one exists */
480 if (of_gpio_named_count(node, "alarm-gpios")) { 480 if (of_gpio_named_count(node, "alarm-gpios") > 0) {
481 struct gpio_fan_alarm *alarm; 481 struct gpio_fan_alarm *alarm;
482 int val; 482 int val;
483 enum of_gpio_flags flags; 483 enum of_gpio_flags flags;
diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c
index f4ff0dda7597..71d77192ac1e 100644
--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -403,7 +403,7 @@ matrix_keypad_parse_dt(struct device *dev)
403 struct matrix_keypad_platform_data *pdata; 403 struct matrix_keypad_platform_data *pdata;
404 struct device_node *np = dev->of_node; 404 struct device_node *np = dev->of_node;
405 unsigned int *gpios; 405 unsigned int *gpios;
406 int i; 406 int i, nrow, ncol;
407 407
408 if (!np) { 408 if (!np) {
409 dev_err(dev, "device lacks DT data\n"); 409 dev_err(dev, "device lacks DT data\n");
@@ -416,9 +416,9 @@ matrix_keypad_parse_dt(struct device *dev)
416 return ERR_PTR(-ENOMEM); 416 return ERR_PTR(-ENOMEM);
417 } 417 }
418 418
419 pdata->num_row_gpios = of_gpio_named_count(np, "row-gpios"); 419 pdata->num_row_gpios = nrow = of_gpio_named_count(np, "row-gpios");
420 pdata->num_col_gpios = of_gpio_named_count(np, "col-gpios"); 420 pdata->num_col_gpios = ncol = of_gpio_named_count(np, "col-gpios");
421 if (!pdata->num_row_gpios || !pdata->num_col_gpios) { 421 if (nrow <= 0 || ncol <= 0) {
422 dev_err(dev, "number of keypad rows/columns not specified\n"); 422 dev_err(dev, "number of keypad rows/columns not specified\n");
423 return ERR_PTR(-EINVAL); 423 return ERR_PTR(-EINVAL);
424 } 424 }
diff --git a/drivers/net/phy/mdio-mux-gpio.c b/drivers/net/phy/mdio-mux-gpio.c
index 0c9accb1c14f..e91d7d736ae2 100644
--- a/drivers/net/phy/mdio-mux-gpio.c
+++ b/drivers/net/phy/mdio-mux-gpio.c
@@ -53,7 +53,7 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
53{ 53{
54 enum of_gpio_flags f; 54 enum of_gpio_flags f;
55 struct mdio_mux_gpio_state *s; 55 struct mdio_mux_gpio_state *s;
56 unsigned int num_gpios; 56 int num_gpios;
57 unsigned int n; 57 unsigned int n;
58 int r; 58 int r;
59 59
@@ -61,7 +61,7 @@ static int mdio_mux_gpio_probe(struct platform_device *pdev)
61 return -ENODEV; 61 return -ENODEV;
62 62
63 num_gpios = of_gpio_count(pdev->dev.of_node); 63 num_gpios = of_gpio_count(pdev->dev.of_node);
64 if (num_gpios == 0 || num_gpios > MDIO_MUX_GPIO_MAX_BITS) 64 if (num_gpios <= 0 || num_gpios > MDIO_MUX_GPIO_MAX_BITS)
65 return -ENODEV; 65 return -ENODEV;
66 66
67 s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL); 67 s = devm_kzalloc(&pdev->dev, sizeof(*s), GFP_KERNEL);
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
1060static int of_spi_register_master(struct spi_master *master) 1060static 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;