aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib.c
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2013-02-02 11:29:27 -0500
committerGrant Likely <grant.likely@secretlab.ca>2013-02-09 04:30:17 -0500
commitcb1650d4e0da27e88c1a1bd8fe98c40ae1a5d313 (patch)
tree576d50b4561c435bb0ffaeac2e49570482fe5111 /drivers/gpio/gpiolib.c
parent125eef96f6cfadddbac8f6b9fccc9848988e7c6e (diff)
gpiolib: use gpio_chips list in sysfs ops
This makes the code both simpler and faster compared to parsing the GPIO number space. Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r--drivers/gpio/gpiolib.c37
1 files changed, 10 insertions, 27 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 5a79cb955d9f..585d7c3ce12e 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1890,45 +1890,28 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip)
1890static void *gpiolib_seq_start(struct seq_file *s, loff_t *pos) 1890static void *gpiolib_seq_start(struct seq_file *s, loff_t *pos)
1891{ 1891{
1892 struct gpio_chip *chip = NULL; 1892 struct gpio_chip *chip = NULL;
1893 unsigned int gpio; 1893 loff_t index = *pos;
1894 void *ret = NULL;
1895 loff_t index = 0;
1896 1894
1897 /* REVISIT this isn't locked against gpio_chip removal ... */ 1895 /* REVISIT this isn't locked against gpio_chip removal ... */
1898 1896
1899 for (gpio = 0; gpio_is_valid(gpio); gpio++) {
1900 if (gpio_desc[gpio].chip == chip)
1901 continue;
1902
1903 chip = gpio_desc[gpio].chip;
1904 if (!chip)
1905 continue;
1906
1907 if (index++ >= *pos) {
1908 ret = chip;
1909 break;
1910 }
1911 }
1912
1913 s->private = ""; 1897 s->private = "";
1914 1898
1915 return ret; 1899 list_for_each_entry(chip, &gpio_chips, list)
1900 if (index-- == 0)
1901 return chip;
1902
1903 return NULL;
1916} 1904}
1917 1905
1918static void *gpiolib_seq_next(struct seq_file *s, void *v, loff_t *pos) 1906static void *gpiolib_seq_next(struct seq_file *s, void *v, loff_t *pos)
1919{ 1907{
1920 struct gpio_chip *chip = v; 1908 struct gpio_chip *chip = v;
1921 unsigned int gpio;
1922 void *ret = NULL; 1909 void *ret = NULL;
1923 1910
1924 /* skip GPIOs provided by the current chip */ 1911 if (list_is_last(&chip->list, &gpio_chips))
1925 for (gpio = chip->base + chip->ngpio; gpio_is_valid(gpio); gpio++) { 1912 ret = NULL;
1926 chip = gpio_desc[gpio].chip; 1913 else
1927 if (chip) { 1914 ret = list_entry(chip->list.next, struct gpio_chip, list);
1928 ret = chip;
1929 break;
1930 }
1931 }
1932 1915
1933 s->private = "\n"; 1916 s->private = "\n";
1934 ++*pos; 1917 ++*pos;