blob: 5ddf58d1237f56d98703b64b51288e931946fbc4 [file] [log] [blame]
Dima Zavin0f88be22009-01-20 19:25:50 -08001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
4 *
Duy Truongf3ac7b32013-02-13 01:07:28 -08005 * Copyright (c) 2009-2012, The Linux Foundation. All rights reserved.
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -08006 *
Dima Zavin0f88be22009-01-20 19:25:50 -08007 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google, Inc. nor the names of its contributors
17 * may be used to endorse or promote products derived from this
18 * software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef __DEV_GPIO_KEYPAD_H
35#define __DEV_GPIO_KEYPAD_H
36
37#include <sys/types.h>
38
39/* unset: drive active output low, set: drive active output high */
40#define GPIOKPF_ACTIVE_HIGH (1U << 0)
41#define GPIOKPF_DRIVE_INACTIVE (1U << 1)
42
43struct gpio_keypad_info {
44 /* size must be ninputs * noutputs */
45 const uint16_t *keymap;
46 unsigned *input_gpios;
47 unsigned *output_gpios;
48 int ninputs;
49 int noutputs;
50 /* time to wait before reading inputs after driving each output */
51 time_t settle_time;
52 time_t poll_time;
53 unsigned flags;
54};
55
56void gpio_keypad_init(struct gpio_keypad_info *kpinfo);
57
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -080058// GPIO configurations
59
60#define SSBI_REG_ADDR_GPIO_BASE 0x150
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -080061
62#define QT_PMIC_GPIO_KYPD_SNS 0x008
63#define QT_PMIC_GPIO_KYPD_DRV 0x003
64
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -080065#define SSBI_OFFSET_ADDR_GPIO_KYPD_SNS 0x000
66#define SSBI_OFFSET_ADDR_GPIO_KYPD_DRV 0x008
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -080067
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -080068#define SSBI_REG_ADDR_GPIO(n) (SSBI_REG_ADDR_GPIO_BASE + n)
69
70#define PM_GPIO_DIR_OUT 0x01
71#define PM_GPIO_DIR_IN 0x02
72#define PM_GPIO_DIR_BOTH (PM_GPIO_DIR_OUT | PM_GPIO_DIR_IN)
73
74#define PM_GPIO_PULL_UP1 2
75#define PM_GPIO_PULL_UP2 3
76#define PM_GPIO_PULL_DN 4
77#define PM_GPIO_PULL_NO 5
78
79#define PM_GPIO_STRENGTH_NO 0
80#define PM_GPIO_STRENGTH_HIGH 1
81#define PM_GPIO_STRENGTH_MED 2
82#define PM_GPIO_STRENGTH_LOW 3
83
84#define PM_GPIO_FUNC_NORMAL 0
85#define PM_GPIO_FUNC_PAIRED 1
86#define PM_GPIO_FUNC_1 2
87#define PM_GPIO_FUNC_2 3
88
89#define PM8058_GPIO_BANK_MASK 0x70
90#define PM8058_GPIO_BANK_SHIFT 4
91#define PM8058_GPIO_WRITE 0x80
92
93/* Bank 0 */
94#define PM8058_GPIO_VIN_MASK 0x0E
95#define PM8058_GPIO_VIN_SHIFT 1
96#define PM8058_GPIO_MODE_ENABLE 0x01
97
98/* Bank 1 */
99#define PM8058_GPIO_MODE_MASK 0x0C
100#define PM8058_GPIO_MODE_SHIFT 2
101#define PM8058_GPIO_OUT_BUFFER 0x02
102#define PM8058_GPIO_OUT_INVERT 0x01
103
104#define PM8058_GPIO_MODE_OFF 3
105#define PM8058_GPIO_MODE_OUTPUT 2
106#define PM8058_GPIO_MODE_INPUT 0
107#define PM8058_GPIO_MODE_BOTH 1
108
109/* Bank 2 */
110#define PM8058_GPIO_PULL_MASK 0x0E
111#define PM8058_GPIO_PULL_SHIFT 1
112
113/* Bank 3 */
114#define PM8058_GPIO_OUT_STRENGTH_MASK 0x0C
115#define PM8058_GPIO_OUT_STRENGTH_SHIFT 2
116
117/* Bank 4 */
118#define PM8058_GPIO_FUNC_MASK 0x0E
119#define PM8058_GPIO_FUNC_SHIFT 1
120
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800121struct pm8058_gpio {
122 int direction;
123 int pull;
124 int vin_sel; /* 0..7 */
125 int out_strength;
126 int function;
127 int inv_int_pol; /* invert interrupt polarity */
128};
129
Greg Griscod6250552011-06-29 14:40:23 -0700130bool pm8058_gpio_get(unsigned int gpio);
131
Chandan Uddarajubedca152010-06-02 23:05:15 -0700132typedef int (*read_func)(unsigned char *, unsigned short, unsigned short);
133typedef int (*write_func)(unsigned char *, unsigned short, unsigned short);
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800134typedef int (*gpio_get_func)(uint8_t, uint8_t *);
Chandan Uddarajubedca152010-06-02 23:05:15 -0700135
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800136struct qwerty_keypad_info {
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800137 unsigned int *keymap;
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800138 unsigned int *gpiomap;
139 unsigned int mapsize;
140 unsigned char *old_keys;
141 unsigned char *rec_keys;
142 unsigned int rows;
143 unsigned int columns;
144 unsigned int num_of_reads;
145 read_func rd_func;
146 write_func wr_func;
147 gpio_get_func key_gpio_get;
148
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800149 /* time to wait before reading inputs after driving each output */
150 time_t settle_time;
151 time_t poll_time;
152 unsigned flags;
153};
154
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800155void ssbi_keypad_init (struct qwerty_keypad_info *);
156
Dima Zavin0f88be22009-01-20 19:25:50 -0800157#endif /* __DEV_GPIO_KEYPAD_H */