blob: e7fb53e93af9501d1ece4c8ec01e0f645a0b838a [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
13#include <mach/qpnp.h>
14
Michael Bohane25e15f2012-04-12 17:28:26 -070015#define QPNP_GPIO_DIR_IN 0
Michael Bohan0ba63b82012-02-06 13:42:34 -080016#define QPNP_GPIO_DIR_OUT 1
Michael Bohane25e15f2012-04-12 17:28:26 -070017#define QPNP_GPIO_DIR_BOTH 2
Michael Bohan0ba63b82012-02-06 13:42:34 -080018
Michael Bohane25e15f2012-04-12 17:28:26 -070019#define QPNP_GPIO_INVERT_DISABLE 0
20#define QPNP_GPIO_INVERT_ENABLE 1
21
Michael Bohan0ba63b82012-02-06 13:42:34 -080022#define QPNP_GPIO_OUT_BUF_CMOS 0
Michael Bohane25e15f2012-04-12 17:28:26 -070023#define QPNP_GPIO_OUT_BUF_OPEN_DRAIN_NMOS 1
24#define QPNP_GPIO_OUT_BUF_OPEN_DRAIN_PMOS 2
Michael Bohan0ba63b82012-02-06 13:42:34 -080025
26#define QPNP_GPIO_VIN0 0
27#define QPNP_GPIO_VIN1 1
28#define QPNP_GPIO_VIN2 2
29#define QPNP_GPIO_VIN3 3
30#define QPNP_GPIO_VIN4 4
31#define QPNP_GPIO_VIN5 5
32#define QPNP_GPIO_VIN6 6
33#define QPNP_GPIO_VIN7 7
34
35#define QPNP_GPIO_PULL_UP_30 0
36#define QPNP_GPIO_PULL_UP_1P5 1
37#define QPNP_GPIO_PULL_UP_31P5 2
38#define QPNP_GPIO_PULL_UP_1P5_30 3
39#define QPNP_GPIO_PULL_DN 4
40#define QPNP_GPIO_PULL_NO 5
41
42#define QPNP_GPIO_OUT_STRENGTH_LOW 1
43#define QPNP_GPIO_OUT_STRENGTH_MED 2
44#define QPNP_GPIO_OUT_STRENGTH_HIGH 3
45
Michael Bohane25e15f2012-04-12 17:28:26 -070046#define QPNP_GPIO_SRC_FUNC_NORMAL 0
47#define QPNP_GPIO_SRC_FUNC_PAIRED 1
48#define QPNP_GPIO_SRC_FUNC_1 2
49#define QPNP_GPIO_SRC_FUNC_2 3
50#define QPNP_GPIO_SRC_DTEST1 4
51#define QPNP_GPIO_SRC_DTEST2 5
52#define QPNP_GPIO_SRC_DTEST3 6
53#define QPNP_GPIO_SRC_DTEST4 7
54
55#define QPNP_GPIO_MASTER_DISABLE 0
56#define QPNP_GPIO_MASTER_ENABLE 1
Michael Bohan0ba63b82012-02-06 13:42:34 -080057
58/**
59 * struct qpnp_gpio_cfg - structure to specify gpio configurtion values
60 * @direction: indicates whether the gpio should be input, output, or
61 * both. Should be of the type QPNP_GPIO_DIR_*
62 * @output_type: indicates gpio should be configured as CMOS or open
63 * drain. Should be of the type QPNP_GPIO_OUT_BUF_*
Michael Bohane25e15f2012-04-12 17:28:26 -070064 * @invert: Invert the signal of the gpio line -
65 * QPNP_GPIO_INVERT_DISABLE or QPNP_GPIO_INVERT_ENABLE
Michael Bohan0ba63b82012-02-06 13:42:34 -080066 * @pull: Indicates whether a pull up or pull down should be
67 * applied. If a pullup is required the current strength
68 * needs to be specified. Current values of 30uA, 1.5uA,
69 * 31.5uA, 1.5uA with 30uA boost are supported. This value
70 * should be one of the QPNP_GPIO_PULL_*
71 * @vin_sel: specifies the voltage level when the output is set to 1.
72 * For an input gpio specifies the voltage level at which
73 * the input is interpreted as a logical 1.
74 * @out_strength: the amount of current supplied for an output gpio,
75 * should be of the type QPNP_GPIO_STRENGTH_*
76 * @source_sel: choose alternate function for the gpio. Certain gpios
77 * can be paired (shorted) with each other. Some gpio pin
78 * can act as alternate functions. This parameter should
Michael Bohane25e15f2012-04-12 17:28:26 -070079 * be of type QPNP_GPIO_SRC_*.
80 * @master_en: QPNP_GPIO_MASTER_ENABLE = Enable features within the
81 * GPIO block based on configurations.
82 * QPNP_GPIO_MASTER_DISABLE = Completely disable the GPIO
83 * block and let the pin float with high impedance
84 * regardless of other settings.
Michael Bohan0ba63b82012-02-06 13:42:34 -080085 */
86struct qpnp_gpio_cfg {
Michael Bohane25e15f2012-04-12 17:28:26 -070087 unsigned int direction;
88 unsigned int output_type;
89 unsigned int invert;
90 unsigned int pull;
91 unsigned int vin_sel;
92 unsigned int out_strength;
93 unsigned int src_select;
94 unsigned int master_en;
Michael Bohan0ba63b82012-02-06 13:42:34 -080095};
96
97/**
98 * qpnp_gpio_config - Apply gpio configuration for Linux gpio
99 * @gpio: Linux gpio number to configure.
100 * @param: parameters to configure.
101 *
102 * This routine takes a Linux gpio number that corresponds with a
103 * PMIC gpio and applies the configuration specified in 'param'.
104 * This gpio number can be ascertained by of_get_gpio_flags() or
105 * the qpnp_gpio_map_gpio() API.
106 */
107int qpnp_gpio_config(int gpio, struct qpnp_gpio_cfg *param);
108
109/**
110 * qpnp_gpio_map_gpio - Obtain Linux GPIO number from device spec
111 * @slave_id: slave_id of the spmi_device for the gpio in question.
112 * @pmic_gpio: PMIC gpio number to lookup.
113 *
114 * This routine is used in legacy configurations that do not support
115 * Device Tree. If you are using Device Tree, you should not use this.
116 * For such cases, use of_get_gpio() instead.
117 */
118int qpnp_gpio_map_gpio(uint16_t slave_id, uint32_t pmic_gpio);