Re: [PATCH v3 5/5] gpio: Make of_count_named_gpios() use new of_count_phandle_with_args()
On 2013-02-13 00:06, Grant Likely wrote: 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 Signed-off-by: Grant Likely Cc: Linus Walleij Cc: Rob Herring Cc: Andreas Larsson For gpiolib-of.c, of_gpio.h and spi.c: Tested-by: Andreas Larsson Cheers, Andreas Larsson -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v3 5/5] gpio: Make of_count_named_gpios() use new of_count_phandle_with_args()
On 2013-02-13 00:06, Grant Likely wrote: 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 Signed-off-by: Grant Likely grant.lik...@secretlab.ca Cc: Linus Walleij linus.wall...@linaro.org Cc: Rob Herring rob.herr...@calxeda.com Cc: Andreas Larsson andr...@gaisler.com For gpiolib-of.c, of_gpio.h and spi.c: Tested-by: Andreas Larsson andr...@gaisler.com Cheers, Andreas Larsson -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH v3 5/5] 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 Signed-off-by: Grant Likely Cc: Linus Walleij Cc: Rob Herring Cc: Andreas Larsson --- drivers/gpio/gpiolib-of.c | 35 drivers/hwmon/gpio-fan.c |4 ++-- drivers/input/keyboard/matrix_keypad.c |8 +++ drivers/net/phy/mdio-mux-gpio.c|4 ++-- drivers/spi/spi-fsl-spi.c |4 ++-- drivers/spi/spi-oc-tiny.c |8 +++ drivers/spi/spi-ppc4xx.c |4 ++-- drivers/spi/spi.c |5 ++-- include/linux/of_gpio.h| 40 ++-- 9 files changed, 41 insertions(+), 71 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index d542a14..dd8a212 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, EXPORT_SYMBOL(of_get_named_gpio_flags); /** - * of_gpio_named_count - Count GPIOs for a device - * @np:device node to count GPIOs for - * @propname: property name containing gpio specifier(s) - * - * The function returns the count of GPIOs specified for a node. - * - * Note that the empty GPIO specifiers counts too. For example, - * - * gpios = <0 - * 1 2 - * 0 - * 3 4>; - * - * defines four GPIOs (so this function will return 4), two of which - * are not specified. - */ -unsigned int of_gpio_named_count(struct device_node *np, const char* propname) -{ - unsigned int cnt = 0; - - do { - int ret; - - ret = of_parse_phandle_with_args(np, propname, "#gpio-cells", -cnt, NULL); - /* A hole in the gpios = <> counts anyway. */ - if (ret < 0 && ret != -EEXIST) - break; - } while (++cnt); - - return cnt; -} -EXPORT_SYMBOL(of_gpio_named_count); - -/** * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags * @gc:pointer to the gpio_chip structure * @np:device node of the GPIO chip diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c index 4e04c12..3978194 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, /* Fill GPIO pin array */ pdata->num_ctrl = of_gpio_count(node); - if (!pdata->num_ctrl) { + if (pdata->num_ctrl <= 0) { dev_err(dev, "gpios DT property empty / missing"); return -ENODEV; } @@ -477,7 +477,7 @@ static int gpio_fan_get_of_pdata(struct device *dev, pdata->speed = speed; /* Alarm GPIO if one exists */ - if (of_gpio_named_count(node, "alarm-gpios")) { + if (of_gpio_named_count(node, "alarm-gpios") > 0) { struct gpio_fan_alarm *alarm; int val; enum of_gpio_flags flags; diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index f4ff0dd..71d7719 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) struct matrix_keypad_platform_data *pdata; struct device_node *np = dev->of_node; unsigned int *gpios; - int i; + int i, nrow, ncol; if (!np) { dev_err(dev, "device lacks DT data\n"); @@ -416,9 +416,9 @@ matrix_keypad_parse_dt(struct device *dev) return ERR_PTR(-ENOMEM); } - pdata->num_row_gpios = of_gpio_named_count(np, "row-gpios"); - pdata->num_col_gpios = of_gpio_named_count(np, "col-gpios"); - if (!pdata->num_row_gpios || !pdata->num_col_gpios) { + pdata->num_row_gpios = nrow = of_gpio_named_count(np, "row-gpios"); + pdata->num_col_gpios = ncol = of_gpio_named_count(np, "col-gpios"); + if (nrow <= 0 || ncol <= 0) { dev_err(dev, "number of keypad rows/columns not specified\n"); return ERR_PTR(-EINVAL); } diff --git a/drivers/net/phy/mdio-mux-gpio.c b/drivers/net/phy/mdio-mux-gpio.c index 0c9accb..e91d7d7 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) { enum of_gpio_flags f; struct mdio_mux_gpio_state *s; - unsigned int num_gpios; + int num_gpios;
[PATCH v3 5/5] 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 Signed-off-by: Grant Likely grant.lik...@secretlab.ca Cc: Linus Walleij linus.wall...@linaro.org Cc: Rob Herring rob.herr...@calxeda.com Cc: Andreas Larsson andr...@gaisler.com --- drivers/gpio/gpiolib-of.c | 35 drivers/hwmon/gpio-fan.c |4 ++-- drivers/input/keyboard/matrix_keypad.c |8 +++ drivers/net/phy/mdio-mux-gpio.c|4 ++-- drivers/spi/spi-fsl-spi.c |4 ++-- drivers/spi/spi-oc-tiny.c |8 +++ drivers/spi/spi-ppc4xx.c |4 ++-- drivers/spi/spi.c |5 ++-- include/linux/of_gpio.h| 40 ++-- 9 files changed, 41 insertions(+), 71 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index d542a14..dd8a212 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, EXPORT_SYMBOL(of_get_named_gpio_flags); /** - * of_gpio_named_count - Count GPIOs for a device - * @np:device node to count GPIOs for - * @propname: property name containing gpio specifier(s) - * - * The function returns the count of GPIOs specified for a node. - * - * Note that the empty GPIO specifiers counts too. For example, - * - * gpios = 0 - * pio1 1 2 - * 0 - * pio2 3 4; - * - * defines four GPIOs (so this function will return 4), two of which - * are not specified. - */ -unsigned int of_gpio_named_count(struct device_node *np, const char* propname) -{ - unsigned int cnt = 0; - - do { - int ret; - - ret = of_parse_phandle_with_args(np, propname, #gpio-cells, -cnt, NULL); - /* A hole in the gpios = counts anyway. */ - if (ret 0 ret != -EEXIST) - break; - } while (++cnt); - - return cnt; -} -EXPORT_SYMBOL(of_gpio_named_count); - -/** * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags * @gc:pointer to the gpio_chip structure * @np:device node of the GPIO chip diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c index 4e04c12..3978194 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, /* Fill GPIO pin array */ pdata-num_ctrl = of_gpio_count(node); - if (!pdata-num_ctrl) { + if (pdata-num_ctrl = 0) { dev_err(dev, gpios DT property empty / missing); return -ENODEV; } @@ -477,7 +477,7 @@ static int gpio_fan_get_of_pdata(struct device *dev, pdata-speed = speed; /* Alarm GPIO if one exists */ - if (of_gpio_named_count(node, alarm-gpios)) { + if (of_gpio_named_count(node, alarm-gpios) 0) { struct gpio_fan_alarm *alarm; int val; enum of_gpio_flags flags; diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index f4ff0dd..71d7719 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) struct matrix_keypad_platform_data *pdata; struct device_node *np = dev-of_node; unsigned int *gpios; - int i; + int i, nrow, ncol; if (!np) { dev_err(dev, device lacks DT data\n); @@ -416,9 +416,9 @@ matrix_keypad_parse_dt(struct device *dev) return ERR_PTR(-ENOMEM); } - pdata-num_row_gpios = of_gpio_named_count(np, row-gpios); - pdata-num_col_gpios = of_gpio_named_count(np, col-gpios); - if (!pdata-num_row_gpios || !pdata-num_col_gpios) { + pdata-num_row_gpios = nrow = of_gpio_named_count(np, row-gpios); + pdata-num_col_gpios = ncol = of_gpio_named_count(np, col-gpios); + if (nrow = 0 || ncol = 0) { dev_err(dev, number of keypad rows/columns not specified\n); return ERR_PTR(-EINVAL); } diff --git a/drivers/net/phy/mdio-mux-gpio.c b/drivers/net/phy/mdio-mux-gpio.c index 0c9accb..e91d7d7 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) { enum of_gpio_flags f; struct mdio_mux_gpio_state *s; -