blob: 398fa3f6a4b01cbeabd614698a64ce06e4353ff0 [file] [log] [blame]
Houston Hoffman4fda2ff2014-01-31 18:17:37 -08001/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -07002 *
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#ifndef __NFC_NCI_H
14#define __NFC_NCI_H
15
16#include <linux/i2c.h>
17#include <linux/types.h>
18#include <linux/version.h>
19
20#include <linux/semaphore.h>
21#include <linux/completion.h>
22
23#include <linux/ioctl.h>
24#include <linux/cdev.h>
25#include <linux/miscdevice.h>
26
27struct nfc_device {
28 struct cdev cdev;
29 struct class *char_class;
30};
31
32enum ehandler_mode {
Bansidhar Gopalachari25fc8742013-07-16 00:46:19 -070033 UNSOLICITED_MODE = 0,
34 SOLICITED_MODE,
35 UNSOLICITED_FTM_RAW_MODE,
36 SOLICITED_FTM_RAW_MODE
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -070037};
38
39enum ekernel_logging_mode {
40 LEVEL_0 = 0, /* For Basic Comms, such asNCI TX/TX to NFCC */
41 LEVEL_1, /* Other Debug e.g. Notifications, ISR hit, etc ..*/
42 LEVEL_2,
43 LEVEL_3,
44 LEVEL_4,
45 LEVEL_5
46};
47
Bansidhar Gopalachari25fc8742013-07-16 00:46:19 -070048struct devicemode {
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -070049 enum ehandler_mode handle_flavour;
Bansidhar Gopalachari25fc8742013-07-16 00:46:19 -070050} tdevicemode;
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -070051
Bansidhar Gopalacharibe0e4d92013-09-19 19:30:36 +010052#define NFC_DRIVER_NAME "nfc-nci"
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -070053#define NFC_I2C_DRIVER_NAME "NCI NFC I2C Interface",
54
Bansidhar Gopalacharibe0e4d92013-09-19 19:30:36 +010055#define NCI_I2C_SLAVE (0x2C)
56#define NFC_I2C_BUS 3 /* 6, 10, 4, 5 */
57#define NFC_SET_PWR _IOW(0xE9, 0x01, unsigned int)
58#define NFCC_MODE _IOW(0xE9, 0x02, unsigned int)
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -070059#define NFC_KERNEL_LOGGING_MODE _IOW(0xE9, 0x03, unsigned int)
Bansidhar Gopalacharibe0e4d92013-09-19 19:30:36 +010060#define SET_RX_BLOCK _IOW(0xE9, 0x04, unsigned int)
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -070061#define SET_EMULATOR_TEST_POINT _IOW(0xE9, 0x05, unsigned int)
Bansidhar Gopalacharibe0e4d92013-09-19 19:30:36 +010062#define NFCC_VERSION _IOW(0xE9, 0x08, unsigned int)
Nakul Kadannavareed3d152014-12-03 17:48:10 +000063#define NFC_GET_EFUSE _IOW(0xE9, 0x09, unsigned int)
Nakul Kadannavar380f0d72014-10-10 11:00:34 +010064#define NFCC_INITIAL_CORE_RESET_NTF _IOW(0xE9, 0x10, unsigned int)
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -070065
Bansidhar Gopalacharibe0e4d92013-09-19 19:30:36 +010066#define NFC_MAX_I2C_TRANSFER (0x0400)
67#define NFC_MSG_MAX_SIZE (0x21)
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -070068
69#define NFC_RX_BUFFER_CNT_START (0x0)
70
Bansidhar Gopalacharibe0e4d92013-09-19 19:30:36 +010071#define NFC_RX_BUFFER_BLOCK_SIZE (0x120) /* Bytes per Block */
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -070072#define NFC_RX_BUFFER_PAGE_SIZE (0x1000) /* Page size Bytes */
73#define NFC_RX_BUFFER_PAGES (0x8)
Bansidhar Gopalacharibe0e4d92013-09-19 19:30:36 +010074#define NFC_RX_ORDER_FREE_PAGES (0x3) /* Free 8 Pages */
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -070075
76/* The total no. of Blocks */
77#define NFC_RX_BUFFER_CNT_LIMIT (unsigned short)( \
78 ( \
79 ((NFC_RX_BUFFER_PAGE_SIZE) *\
80 (NFC_RX_BUFFER_PAGES))/\
81 (NFC_RX_BUFFER_BLOCK_SIZE)\
82 ) \
83 ) \
84
85#define PAYLOAD_HEADER_LENGTH (0x3)
86#define PAYLOAD_LENGTH_MAX (256)
87#define BYTE (0x8)
88#define NCI_IDENTIFIER (0x10)
89
90/** Power Management Related **/
91
Bansidhar Gopalacharibe0e4d92013-09-19 19:30:36 +010092#define NFCC_WAKE (0x01)
93#define NFCC_SLEEP (0x00)
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -070094
Bansidhar Gopalacharibe0e4d92013-09-19 19:30:36 +010095#define XTAL_CLOCK (0X00)
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -070096#define REFERENCE_CLOCK (0X01)
97
98/* LDO Trim Settings */
99#define IPTAT_TRIM (0x1F)
100#define V1P1_TRIM (0x0F)
101#define V1P8_TRIM (0x0F)
102#define VBATT_OK_THRESHOLD (0x07)
103
104#define PWR_EN (0x08) /* Enable 1.1V LDO Regulator */
105#define LS_EN (0x04) /* Enable 1.1V->1.8V Level Shifters */
106
107/* Write '1' to cause wake event to NFCC. If set NFCC will not go to SLEEP */
108#define NCI_WAKE (0x02)
109
110#define NCI_ENA (0x01) /* Write '1' to enable PLL */
111#define FREQ_SEL (0x00) /* XO Frequency Select */
112#define FREQ_SEL_13 (0x00) /* XO Frequency Select = 13.56MHz */
113#define FREQ_SEL_19 (0x01) /* XO Frequency Select = 19.20 MHz */
114#define FREQ_SEL_26 (0x02) /* XO Frequency Select = 26.00 MHz */
115#define FREQ_SEL_27 (0x03) /* XO Frequency Select = 27.12 MHz */
116#define FREQ_SEL_37 (0x04) /* XO Frequency Select = 37.40 MHz */
117#define FREQ_SEL_38 (0x05) /* XO Frequency Select = 38.40 MHz */
118#define FREQ_SEL_40 (0x06) /* XO Frequency Select = 40.00 MHz */
119#define FREQ_SEL_48 (0x07) /* XO Frequency Select = 48.00 MHz */
120#define FREQ_SEL_27 (0x03) /* XO Frequency Select */
121
122
123#define QUALIFY_REFCLK (0x80)
124#define QUALIFY_OSC (0x40)
125#define LOCALBIASXTAL (0x20)
126#define BIAS2X_FORCE (0x10)
127#define BIAS2X (0x08)
Bansidhar Gopalacharibe0e4d92013-09-19 19:30:36 +0100128#define LBIAS2X (0x04)
129#define SMALLRF (0x02)
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -0700130#define SMALLRBIAS (0x01)
131
132/* Select as appropriate */
133#define CRYSTAL_OSC ((QUALIFY_REFCLK) | (QUALIFY_OSC) | \
134 (LOCALBIASXTAL) | (BIAS2X_FORCE) | \
135 (BIAS2X) | (LBIAS2X) | (SMALLRF) | (SMALLRBIAS))
136
137#define CDACIN (0x3F) /* Tuning range for load capacitor at X1*/
138#define CDACOUT (0x3F) /* Tuning range for load capacitor at X2*/
139
140#define RAW(reg, value) (raw_##reg[1] = value)
141
142/* Logging macro with threshold control */
143#define PRINTK(LEVEL, THRESHOLD, pString, ...) ( \
144 if (LEVEL > THRESHOLD) { \
145 pr_info(pString, ##__VA_ARGS__); \
146 } \
147 )
148
149/* board config */
150struct nfc_platform_data {
151 int (*request_resources) (struct i2c_client *client);
152 void (*free_resources) (void);
153 void (*enable) (int fw);
154 int (*test) (void);
155 void (*disable) (void);
156};
157/*
158 * Internal NFCC Hardware states. At present these may not be possible to
159 * detect in software as possibly no power when
160 * in monitor state! Also, need to detect DISABLE control GPIO from PMIC.
161 */
162enum nfcc_hardware_state {
163 NFCC_STATE_MONITOR, /* VBAT < h/w Critcal Voltage */
164 /* VBAT > H/W Critical Voltage;
165 Lowest Power Mode - DISABLE = 1; only
166 possible when phone is ON */
167 NFCC_STATE_HPD,
168 /* VBAT > H/W Critical Voltage; DISABLE = 0;
169 Only possible when phone is ON */
170 NFCC_STSTE_ULPM,
171 /* VBAT > H/W Critical Voltage; DISABLE = 0;
172 Powered by PMIC & VBAT; 1.8V I/O supply on; VDDPX available, boot is
173 initiated by host over I2C */
174 NFCC_STATE_NORMAL_REGION1,
175 /* VBAT > H/W Critical Voltage; DISABLE = 0;
176 Powered by VBAT; 1.8V I/O supply on; VDDPX available, boot is initiated
177 by host over I2C */
178 NFCC_STATE_NORMAL_REGION2,
179};
180
181/* We assume here that VBATT > h/w Critical Voltage */
182enum nfcc_state {
183 /* Assume In ULPM state, ready for initialisation, cannot detect for
184 Monitor or HPD states */
185 NFCC_STATE_COLD,
186 /* (VDDPX==1) && (Following I2C initialisation). In Region 1 or Region2
187 state WAKE */
188 NFCC_STATE_NORMAL_WAKE,
189 /* (VDDPX==1) && (Following I2C initialisation). In Region 1 or Region2
190 state SLEEP */
191 NFCC_STATE_NORMAL_SLEEP,
192};
193
194
195enum nfcc_irq {
196 NFCC_NO_INT,
197 NFCC_INT,
198};
199
Nakul Kadannavar380f0d72014-10-10 11:00:34 +0100200enum nfcc_initial_core_reset_ntf {
201 TIMEDOUT_INITIAL_CORE_RESET_NTF = 0, /* 0*/
202 ARRIVED_INITIAL_CORE_RESET_NTF, /* 1 */
203 DEFAULT_INITIAL_CORE_RESET_NTF, /*2*/
204};
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -0700205
206struct nfc_info {
207 struct miscdevice miscdev;
208 struct i2c_client *i2c_dev;
209 struct regulator_bulk_data regs[3];
210 enum nfcc_state state;
211 wait_queue_head_t read_wait;
212 loff_t read_offset;
213 struct mutex read_mutex;
214 struct mutex mutex;
215 u8 *buf;
216 size_t buflen;
217 spinlock_t irq_enabled_lock;
218 unsigned int count_irq;
219 enum nfcc_irq read_irq;
220};
221
222
223struct nfc_i2c_platform_data {
224 unsigned int nfc_irq_gpio;
225 unsigned int nfc_clk_en_gpio;
226 unsigned int dis_gpio;
227 unsigned int irq_gpio;
228 unsigned int ven_gpio;
229 unsigned int firm_gpio;
230 unsigned int reg;
231};
232#endif