blob: a31b7f37664ab7d9d165140b7e2b6e43af72620e [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
15#define QPNP_GPIO_DIR_OUT 1
16#define QPNP_GPIO_DIR_IN 2
17#define QPNP_GPIO_DIR_BOTH (QPNP_GPIO_DIR_OUT | QPNP_GPIO_DIR_IN)
18
19#define QPNP_GPIO_OUT_BUF_OPEN_DRAIN 1
20#define QPNP_GPIO_OUT_BUF_CMOS 0
21
22#define QPNP_GPIO_VIN0 0
23#define QPNP_GPIO_VIN1 1
24#define QPNP_GPIO_VIN2 2
25#define QPNP_GPIO_VIN3 3
26#define QPNP_GPIO_VIN4 4
27#define QPNP_GPIO_VIN5 5
28#define QPNP_GPIO_VIN6 6
29#define QPNP_GPIO_VIN7 7
30
31#define QPNP_GPIO_PULL_UP_30 0
32#define QPNP_GPIO_PULL_UP_1P5 1
33#define QPNP_GPIO_PULL_UP_31P5 2
34#define QPNP_GPIO_PULL_UP_1P5_30 3
35#define QPNP_GPIO_PULL_DN 4
36#define QPNP_GPIO_PULL_NO 5
37
38#define QPNP_GPIO_OUT_STRENGTH_LOW 1
39#define QPNP_GPIO_OUT_STRENGTH_MED 2
40#define QPNP_GPIO_OUT_STRENGTH_HIGH 3
41
42#define QPNP_GPIO_FUNC_NORMAL 0
43#define QPNP_GPIO_FUNC_PAIRED 1
44#define QPNP_GPIO_FUNC_1 2
45#define QPNP_GPIO_FUNC_2 3
46#define QPNP_GPIO_DTEST1 4
47#define QPNP_GPIO_DTEST2 5
48#define QPNP_GPIO_DTEST3 6
49#define QPNP_GPIO_DTEST4 7
50
51/**
52 * struct qpnp_gpio_cfg - structure to specify gpio configurtion values
53 * @direction: indicates whether the gpio should be input, output, or
54 * both. Should be of the type QPNP_GPIO_DIR_*
55 * @output_type: indicates gpio should be configured as CMOS or open
56 * drain. Should be of the type QPNP_GPIO_OUT_BUF_*
57 * @output_value: The gpio output value of the gpio line - 0 or 1
58 * @pull: Indicates whether a pull up or pull down should be
59 * applied. If a pullup is required the current strength
60 * needs to be specified. Current values of 30uA, 1.5uA,
61 * 31.5uA, 1.5uA with 30uA boost are supported. This value
62 * should be one of the QPNP_GPIO_PULL_*
63 * @vin_sel: specifies the voltage level when the output is set to 1.
64 * For an input gpio specifies the voltage level at which
65 * the input is interpreted as a logical 1.
66 * @out_strength: the amount of current supplied for an output gpio,
67 * should be of the type QPNP_GPIO_STRENGTH_*
68 * @source_sel: choose alternate function for the gpio. Certain gpios
69 * can be paired (shorted) with each other. Some gpio pin
70 * can act as alternate functions. This parameter should
71 * be of type QPNP_GPIO_FUNC_*
Michael Bohan0ba63b82012-02-06 13:42:34 -080072 * @master_en: 1 = Enable features within the GPIO block based on
73 * configurations.
74 * 0 = Completely disable the GPIO block and let the pin
75 * float with high impedance regardless of other settings.
76 */
77struct qpnp_gpio_cfg {
78 int direction;
79 int output_type;
80 int output_value;
81 int pull;
82 int vin_sel;
83 int out_strength;
84 int src_select;
Michael Bohan0ba63b82012-02-06 13:42:34 -080085 int master_en;
86};
87
88/**
89 * qpnp_gpio_config - Apply gpio configuration for Linux gpio
90 * @gpio: Linux gpio number to configure.
91 * @param: parameters to configure.
92 *
93 * This routine takes a Linux gpio number that corresponds with a
94 * PMIC gpio and applies the configuration specified in 'param'.
95 * This gpio number can be ascertained by of_get_gpio_flags() or
96 * the qpnp_gpio_map_gpio() API.
97 */
98int qpnp_gpio_config(int gpio, struct qpnp_gpio_cfg *param);
99
100/**
101 * qpnp_gpio_map_gpio - Obtain Linux GPIO number from device spec
102 * @slave_id: slave_id of the spmi_device for the gpio in question.
103 * @pmic_gpio: PMIC gpio number to lookup.
104 *
105 * This routine is used in legacy configurations that do not support
106 * Device Tree. If you are using Device Tree, you should not use this.
107 * For such cases, use of_get_gpio() instead.
108 */
109int qpnp_gpio_map_gpio(uint16_t slave_id, uint32_t pmic_gpio);