Blame view

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

eb4ec68ac   Deepak   driver: base: pin...
104
  	return 0;
ab78029ec   Linus Walleij   drivers/pinctrl: ...
105
  }