On Monday 02 June 2014 02:52 PM, Mohammad Merajul Islam Molla wrote:
Hello Sanjay,

One point  - should powerdebug unexport these free gpios when it exits?
Otherwise, all the entries will remain in /sys/class/gpio/* and
/sys/kernel/debug/gpio file until next reboot which user may not want.

I was thinking whether that is needed. But yes, i agree with you (that will be more proper). Thanks for bringing it.

--
Thanks,
- Meraj


On Mon, Jun 2, 2014 at 2:46 PM, Sanjay Singh Rawat
<sanjay.ra...@linaro.org <mailto:sanjay.ra...@linaro.org>> wrote:

    - GPIOs in the SoC will be free/used state, this patch make free gpios
    accessible to the user by exporting them.
    - bug 1229658

    Signed-off-by: Sanjay Singh Rawat <sanjay.ra...@linaro.org
    <mailto:sanjay.ra...@linaro.org>>
    ---
      gpio.c |   27 +++++++++++++++------------
      1 file changed, 15 insertions(+), 12 deletions(-)

    diff --git a/gpio.c b/gpio.c
    index 4a42cb7..39480b0 100644
    --- a/gpio.c
    +++ b/gpio.c
    @@ -320,10 +320,10 @@ static struct display_ops gpio_ops = {
             .change = gpio_change,
      };

    -void export_gpios(void)
    +void export_free_gpios(void)
      {
             FILE *fgpio, *fgpio_export;
    -       int gpio[256], num = 0;
    +       int i, gpio_max = 0;
             char *line = NULL;
             ssize_t read, len;

    @@ -340,15 +340,18 @@ void export_gpios(void)
             }

             /* export the gpios */
    -       while (read = getline(&line, &len, fgpio) != -1) {
    -               char *str;
    -
    -               if (strstr(line, "gpio-")) {
    -                       str = strtok(line, " ");
    -                       sscanf(str, "gpio-%d", &gpio[num]);
    -                       fprintf(fgpio_export, "%d", gpio[num]);
    -                       num++;
    -               }
    +       while ((read = getline(&line, &len, fgpio)) != -1) {
    +               if (strstr(line, "GPIOs"))
    +                       sscanf(line, "%*[^-]-%d%*", &gpio_max);
    +       }
    +
    +       printf("log: total gpios = %d\n", gpio_max);
    +       for (i = 0 ; i <= gpio_max ; i++) {
    +               char command[50] = "";
    +
    +               sprintf(command, "echo %d > /sys/class/gpio/export", i);
    +               if (system(command) < 0)
    +                       printf("error: failed to export gpio-%d\n", i);
             }
      out:
             return;
    @@ -368,7 +371,7 @@ int gpio_init(void)
             if (access(SYSFS_GPIO, F_OK))
                     gpio_error = true; /* set the flag */

    -       export_gpios();
    +       export_free_gpios();

             gpio_tree = tree_load(SYSFS_GPIO, gpio_filter_cb, false);
             if (!gpio_tree)
    --
    1.7.10.4


    _______________________________________________
    linaro-dev mailing list
    linaro-dev@lists.linaro.org <mailto:linaro-dev@lists.linaro.org>
    http://lists.linaro.org/mailman/listinfo/linaro-dev




--
sanjay

_______________________________________________
linaro-dev mailing list
linaro-dev@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-dev

Reply via email to