blob: 3c523ab23b00503148d7a8fd27188e75481a214c [file] [log] [blame]
Michael Bohan0ba63b82012-02-06 13:42:34 -08001/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
Michael Bohane25e15f2012-04-12 17:28:26 -070013#define QPNP_GPIO_DIR_IN 0
Michael Bohan0ba63b82012-02-06 13:42:34 -080014#define QPNP_GPIO_DIR_OUT 1
Michael Bohane25e15f2012-04-12 17:28:26 -070015#define QPNP_GPIO_DIR_BOTH 2
Michael Bohan0ba63b82012-02-06 13:42:34 -080016
Michael Bohane25e15f2012-04-12 17:28:26 -070017#define QPNP_GPIO_INVERT_DISABLE 0
18#define QPNP_GPIO_INVERT_ENABLE 1
19
Michael Bohan0ba63b82012-02-06 13:42:34 -080020#define QPNP_GPIO_OUT_BUF_CMOS 0
Michael Bohane25e15f2012-04-12 17:28:26 -070021#define QPNP_GPIO_OUT_BUF_OPEN_DRAIN_NMOS 1
22#define QPNP_GPIO_OUT_BUF_OPEN_DRAIN_PMOS 2
Michael Bohan0ba63b82012-02-06 13:42:34 -080023
24#define QPNP_GPIO_VIN0 0
25#define QPNP_GPIO_VIN1 1
26#define QPNP_GPIO_VIN2 2
27#define QPNP_GPIO_VIN3 3
28#define QPNP_GPIO_VIN4 4
29#define QPNP_GPIO_VIN5 5
30#define QPNP_GPIO_VIN6 6
31#define QPNP_GPIO_VIN7 7
32
33#define QPNP_GPIO_PULL_UP_30 0
34#define QPNP_GPIO_PULL_UP_1P5 1
35#define QPNP_GPIO_PULL_UP_31P5 2
36#define QPNP_GPIO_PULL_UP_1P5_30 3
37#define QPNP_GPIO_PULL_DN 4
38#define QPNP_GPIO_PULL_NO 5
39
40#define QPNP_GPIO_OUT_STRENGTH_LOW 1
41#define QPNP_GPIO_OUT_STRENGTH_MED 2
42#define QPNP_GPIO_OUT_STRENGTH_HIGH 3
43
Michael Bohane25e15f2012-04-12 17:28:26 -070044#define QPNP_GPIO_SRC_FUNC_NORMAL 0
45#define QPNP_GPIO_SRC_FUNC_PAIRED 1
46#define QPNP_GPIO_SRC_FUNC_1 2
47#define QPNP_GPIO_SRC_FUNC_2 3
48#define QPNP_GPIO_SRC_DTEST1 4
49#define QPNP_GPIO_SRC_DTEST2 5
50#define QPNP_GPIO_SRC_DTEST3 6
51#define QPNP_GPIO_SRC_DTEST4 7
52
53#define QPNP_GPIO_MASTER_DISABLE 0
54#define QPNP_GPIO_MASTER_ENABLE 1
Michael Bohan0ba63b82012-02-06 13:42:34 -080055
56/**
57 * struct qpnp_gpio_cfg - structure to specify gpio configurtion values
58 * @direction: indicates whether the gpio should be input, output, or
59 * both. Should be of the type QPNP_GPIO_DIR_*
60 * @output_type: indicates gpio should be configured as CMOS or open
61 * drain. Should be of the type QPNP_GPIO_OUT_BUF_*
Michael Bohane25e15f2012-04-12 17:28:26 -070062 * @invert: Invert the signal of the gpio line -
63 * QPNP_GPIO_INVERT_DISABLE or QPNP_GPIO_INVERT_ENABLE
Michael Bohan0ba63b82012-02-06 13:42:34 -080064 * @pull: Indicates whether a pull up or pull down should be
65 * applied. If a pullup is required the current strength
66 * needs to be specified. Current values of 30uA, 1.5uA,
67 * 31.5uA, 1.5uA with 30uA boost are supported. This value
68 * should be one of the QPNP_GPIO_PULL_*
69 * @vin_sel: specifies the voltage level when the output is set to 1.
70 * For an input gpio specifies the voltage level at which
71 * the input is interpreted as a logical 1.
72 * @out_strength: the amount of current supplied for an output gpio,
73 * should be of the type QPNP_GPIO_STRENGTH_*
74 * @source_sel: choose alternate function for the gpio. Certain gpios
75 * can be paired (shorted) with each other. Some gpio pin
76 * can act as alternate functions. This parameter should
Michael Bohane25e15f2012-04-12 17:28:26 -070077 * be of type QPNP_GPIO_SRC_*.
78 * @master_en: QPNP_GPIO_MASTER_ENABLE = Enable features within the
79 * GPIO block based on configurations.
80 * QPNP_GPIO_MASTER_DISABLE = Completely disable the GPIO
81 * block and let the pin float with high impedance
82 * regardless of other settings.
Michael Bohan0ba63b82012-02-06 13:42:34 -080083 */
84struct qpnp_gpio_cfg {
Michael Bohane25e15f2012-04-12 17:28:26 -070085 unsigned int direction;
86 unsigned int output_type;
87 unsigned int invert;
88 unsigned int pull;
89 unsigned int vin_sel;
90 unsigned int out_strength;
91 unsigned int src_select;
92 unsigned int master_en;
Michael Bohan0ba63b82012-02-06 13:42:34 -080093};
94
95/**
96 * qpnp_gpio_config - Apply gpio configuration for Linux gpio
97 * @gpio: Linux gpio number to configure.
98 * @param: parameters to configure.
99 *
100 * This routine takes a Linux gpio number that corresponds with a
101 * PMIC gpio and applies the configuration specified in 'param'.
102 * This gpio number can be ascertained by of_get_gpio_flags() or
103 * the qpnp_gpio_map_gpio() API.
104 */
105int qpnp_gpio_config(int gpio, struct qpnp_gpio_cfg *param);
106
107/**
108 * qpnp_gpio_map_gpio - Obtain Linux GPIO number from device spec
109 * @slave_id: slave_id of the spmi_device for the gpio in question.
110 * @pmic_gpio: PMIC gpio number to lookup.
111 *
112 * This routine is used in legacy configurations that do not support
113 * Device Tree. If you are using Device Tree, you should not use this.
114 * For such cases, use of_get_gpio() instead.
115 */
116int qpnp_gpio_map_gpio(uint16_t slave_id, uint32_t pmic_gpio);