LCOV - code coverage report
Current view: top level - drivers/base - pinctrl.c (source / functions) Hit Total Coverage
Test: gcov_data_raspi2_real_modules_combined.info Lines: 21 23 91.3 %
Date: 2020-09-30 20:25:40 Functions: 1 1 100.0 %
Branches: 11 16 68.8 %

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: GPL-2.0
       2                 :            : /*
       3                 :            :  * Driver core interface to the pinctrl subsystem.
       4                 :            :  *
       5                 :            :  * Copyright (C) 2012 ST-Ericsson SA
       6                 :            :  * Written on behalf of Linaro for ST-Ericsson
       7                 :            :  * Based on bits of regulator core, gpio core and clk core
       8                 :            :  *
       9                 :            :  * Author: Linus Walleij <linus.walleij@linaro.org>
      10                 :            :  */
      11                 :            : 
      12                 :            : #include <linux/device.h>
      13                 :            : #include <linux/pinctrl/devinfo.h>
      14                 :            : #include <linux/pinctrl/consumer.h>
      15                 :            : #include <linux/slab.h>
      16                 :            : 
      17                 :            : /**
      18                 :            :  * pinctrl_bind_pins() - called by the device core before probe
      19                 :            :  * @dev: the device that is just about to probe
      20                 :            :  */
      21                 :      11385 : int pinctrl_bind_pins(struct device *dev)
      22                 :            : {
      23                 :            :         int ret;
      24                 :            : 
      25         [ +  + ]:      11385 :         if (dev->of_node_reused)
      26                 :            :                 return 0;
      27                 :            : 
      28                 :      10764 :         dev->pins = devm_kzalloc(dev, sizeof(*(dev->pins)), GFP_KERNEL);
      29         [ +  - ]:      10764 :         if (!dev->pins)
      30                 :            :                 return -ENOMEM;
      31                 :            : 
      32                 :      10764 :         dev->pins->p = devm_pinctrl_get(dev);
      33         [ +  + ]:      21528 :         if (IS_ERR(dev->pins->p)) {
      34                 :            :                 dev_dbg(dev, "no pinctrl handle\n");
      35                 :            :                 ret = PTR_ERR(dev->pins->p);
      36                 :       5589 :                 goto cleanup_alloc;
      37                 :            :         }
      38                 :            : 
      39                 :       5175 :         dev->pins->default_state = pinctrl_lookup_state(dev->pins->p,
      40                 :            :                                         PINCTRL_STATE_DEFAULT);
      41         [ +  + ]:      10350 :         if (IS_ERR(dev->pins->default_state)) {
      42                 :            :                 dev_dbg(dev, "no default pinctrl state\n");
      43                 :            :                 ret = 0;
      44                 :            :                 goto cleanup_get;
      45                 :            :         }
      46                 :            : 
      47                 :        621 :         dev->pins->init_state = pinctrl_lookup_state(dev->pins->p,
      48                 :            :                                         PINCTRL_STATE_INIT);
      49         [ +  - ]:       1242 :         if (IS_ERR(dev->pins->init_state)) {
      50                 :            :                 /* Not supplying this state is perfectly legal */
      51                 :            :                 dev_dbg(dev, "no init pinctrl state\n");
      52                 :            : 
      53                 :        621 :                 ret = pinctrl_select_state(dev->pins->p,
      54                 :            :                                            dev->pins->default_state);
      55                 :            :         } else {
      56                 :          0 :                 ret = pinctrl_select_state(dev->pins->p, dev->pins->init_state);
      57                 :            :         }
      58                 :            : 
      59         [ +  - ]:        621 :         if (ret) {
      60                 :            :                 dev_dbg(dev, "failed to activate initial pinctrl state\n");
      61                 :            :                 goto cleanup_get;
      62                 :            :         }
      63                 :            : 
      64                 :            : #ifdef CONFIG_PM
      65                 :            :         /*
      66                 :            :          * If power management is enabled, we also look for the optional
      67                 :            :          * sleep and idle pin states, with semantics as defined in
      68                 :            :          * <linux/pinctrl/pinctrl-state.h>
      69                 :            :          */
      70                 :        621 :         dev->pins->sleep_state = pinctrl_lookup_state(dev->pins->p,
      71                 :            :                                         PINCTRL_STATE_SLEEP);
      72                 :            :         if (IS_ERR(dev->pins->sleep_state))
      73                 :            :                 /* Not supplying this state is perfectly legal */
      74                 :            :                 dev_dbg(dev, "no sleep pinctrl state\n");
      75                 :            : 
      76                 :        621 :         dev->pins->idle_state = pinctrl_lookup_state(dev->pins->p,
      77                 :            :                                         PINCTRL_STATE_IDLE);
      78                 :            :         if (IS_ERR(dev->pins->idle_state))
      79                 :            :                 /* Not supplying this state is perfectly legal */
      80                 :            :                 dev_dbg(dev, "no idle pinctrl state\n");
      81                 :            : #endif
      82                 :            : 
      83                 :        621 :         return 0;
      84                 :            : 
      85                 :            :         /*
      86                 :            :          * If no pinctrl handle or default state was found for this device,
      87                 :            :          * let's explicitly free the pin container in the device, there is
      88                 :            :          * no point in keeping it around.
      89                 :            :          */
      90                 :            : cleanup_get:
      91                 :       4554 :         devm_pinctrl_put(dev->pins->p);
      92                 :            : cleanup_alloc:
      93                 :      10143 :         devm_kfree(dev, dev->pins);
      94                 :      10143 :         dev->pins = NULL;
      95                 :            : 
      96                 :            :         /* Return deferrals */
      97         [ +  - ]:      10143 :         if (ret == -EPROBE_DEFER)
      98                 :            :                 return ret;
      99                 :            :         /* Return serious errors */
     100         [ -  + ]:      10143 :         if (ret == -EINVAL)
     101                 :          0 :                 return ret;
     102                 :            :         /* We ignore errors like -ENOENT meaning no pinctrl state */
     103                 :            : 
     104                 :            :         return 0;
     105                 :            : }

Generated by: LCOV version 1.14