LCOV - code coverage report
Current view: top level - drivers/gpio - gpiolib-legacy.c (source / functions) Hit Total Coverage
Test: Real Lines: 0 39 0.0 %
Date: 2020-10-17 15:46:16 Functions: 0 5 0.0 %
Legend: Neither, QEMU, Real, Both Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: GPL-2.0
       2                 :            : #include <linux/gpio/consumer.h>
       3                 :            : #include <linux/gpio/driver.h>
       4                 :            : 
       5                 :            : #include <linux/gpio.h>
       6                 :            : 
       7                 :            : #include "gpiolib.h"
       8                 :            : 
       9                 :          0 : void gpio_free(unsigned gpio)
      10                 :            : {
      11                 :          0 :         gpiod_free(gpio_to_desc(gpio));
      12                 :          0 : }
      13                 :            : EXPORT_SYMBOL_GPL(gpio_free);
      14                 :            : 
      15                 :            : /**
      16                 :            :  * gpio_request_one - request a single GPIO with initial configuration
      17                 :            :  * @gpio:       the GPIO number
      18                 :            :  * @flags:      GPIO configuration as specified by GPIOF_*
      19                 :            :  * @label:      a literal description string of this GPIO
      20                 :            :  */
      21                 :          0 : int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
      22                 :            : {
      23                 :            :         struct gpio_desc *desc;
      24                 :            :         int err;
      25                 :            : 
      26                 :          0 :         desc = gpio_to_desc(gpio);
      27                 :            : 
      28                 :            :         /* Compatibility: assume unavailable "valid" GPIOs will appear later */
      29                 :          0 :         if (!desc && gpio_is_valid(gpio))
      30                 :            :                 return -EPROBE_DEFER;
      31                 :            : 
      32                 :          0 :         err = gpiod_request(desc, label);
      33                 :          0 :         if (err)
      34                 :            :                 return err;
      35                 :            : 
      36                 :          0 :         if (flags & GPIOF_OPEN_DRAIN)
      37                 :          0 :                 set_bit(FLAG_OPEN_DRAIN, &desc->flags);
      38                 :            : 
      39                 :          0 :         if (flags & GPIOF_OPEN_SOURCE)
      40                 :          0 :                 set_bit(FLAG_OPEN_SOURCE, &desc->flags);
      41                 :            : 
      42                 :          0 :         if (flags & GPIOF_ACTIVE_LOW)
      43                 :          0 :                 set_bit(FLAG_ACTIVE_LOW, &desc->flags);
      44                 :            : 
      45                 :          0 :         if (flags & GPIOF_DIR_IN)
      46                 :          0 :                 err = gpiod_direction_input(desc);
      47                 :            :         else
      48                 :          0 :                 err = gpiod_direction_output_raw(desc,
      49                 :          0 :                                 (flags & GPIOF_INIT_HIGH) ? 1 : 0);
      50                 :            : 
      51                 :          0 :         if (err)
      52                 :            :                 goto free_gpio;
      53                 :            : 
      54                 :          0 :         if (flags & GPIOF_EXPORT) {
      55                 :          0 :                 err = gpiod_export(desc, flags & GPIOF_EXPORT_CHANGEABLE);
      56                 :          0 :                 if (err)
      57                 :            :                         goto free_gpio;
      58                 :            :         }
      59                 :            : 
      60                 :            :         return 0;
      61                 :            : 
      62                 :            :  free_gpio:
      63                 :          0 :         gpiod_free(desc);
      64                 :          0 :         return err;
      65                 :            : }
      66                 :            : EXPORT_SYMBOL_GPL(gpio_request_one);
      67                 :            : 
      68                 :          0 : int gpio_request(unsigned gpio, const char *label)
      69                 :            : {
      70                 :          0 :         struct gpio_desc *desc = gpio_to_desc(gpio);
      71                 :            : 
      72                 :            :         /* Compatibility: assume unavailable "valid" GPIOs will appear later */
      73                 :          0 :         if (!desc && gpio_is_valid(gpio))
      74                 :            :                 return -EPROBE_DEFER;
      75                 :            : 
      76                 :          0 :         return gpiod_request(desc, label);
      77                 :            : }
      78                 :            : EXPORT_SYMBOL_GPL(gpio_request);
      79                 :            : 
      80                 :            : /**
      81                 :            :  * gpio_request_array - request multiple GPIOs in a single call
      82                 :            :  * @array:      array of the 'struct gpio'
      83                 :            :  * @num:        how many GPIOs in the array
      84                 :            :  */
      85                 :          0 : int gpio_request_array(const struct gpio *array, size_t num)
      86                 :            : {
      87                 :            :         int i, err;
      88                 :            : 
      89                 :          0 :         for (i = 0; i < num; i++, array++) {
      90                 :          0 :                 err = gpio_request_one(array->gpio, array->flags, array->label);
      91                 :          0 :                 if (err)
      92                 :            :                         goto err_free;
      93                 :            :         }
      94                 :            :         return 0;
      95                 :            : 
      96                 :            : err_free:
      97                 :          0 :         while (i--)
      98                 :          0 :                 gpio_free((--array)->gpio);
      99                 :          0 :         return err;
     100                 :            : }
     101                 :            : EXPORT_SYMBOL_GPL(gpio_request_array);
     102                 :            : 
     103                 :            : /**
     104                 :            :  * gpio_free_array - release multiple GPIOs in a single call
     105                 :            :  * @array:      array of the 'struct gpio'
     106                 :            :  * @num:        how many GPIOs in the array
     107                 :            :  */
     108                 :          0 : void gpio_free_array(const struct gpio *array, size_t num)
     109                 :            : {
     110                 :          0 :         while (num--)
     111                 :          0 :                 gpio_free((array++)->gpio);
     112                 :          0 : }
     113                 :            : EXPORT_SYMBOL_GPL(gpio_free_array);
    

Generated by: LCOV version 1.14