blob: 4398df775d7cf90a41646d37b33328290e43abe9 [file] [log] [blame]
Madan Mohan Koyyalamudif2e7dcc2013-06-18 13:03:26 -07001/* Copyright (c) 2013, The Linux Foundation. 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#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 {
33 UNSOLICITED_READ_MODE = 0,
34 SOLICITED_READ_MODE
35};
36
37enum ekernel_logging_mode {
38 LEVEL_0 = 0, /* For Basic Comms, such asNCI TX/TX to NFCC */
39 LEVEL_1, /* Other Debug e.g. Notifications, ISR hit, etc ..*/
40 LEVEL_2,
41 LEVEL_3,
42 LEVEL_4,
43 LEVEL_5
44};
45
46struct DeviceMode {
47 enum ehandler_mode handle_flavour;
48} tDeviceMode;
49
50#define NFC_DRIVER_NAME "nfc-nci"
51#define NFC_I2C_DRIVER_NAME "NCI NFC I2C Interface",
52
53#define NCI_I2C_SLAVE (0x2C)
54#define NFC_I2C_BUS 3 /* 6, 10, 4, 5 */
55#define NFC_SET_PWR _IOW(0xE9, 0x01, unsigned int)
56#define NFCC_MODE _IOW(0xE9, 0x02, unsigned int)
57#define NFC_KERNEL_LOGGING_MODE _IOW(0xE9, 0x03, unsigned int)
58#define SET_RX_BLOCK _IOW(0xE9, 0x04, unsigned int)
59#define SET_EMULATOR_TEST_POINT _IOW(0xE9, 0x05, unsigned int)
60
61#define NFC_MAX_I2C_TRANSFER (0x0400)
62#define NFC_MSG_MAX_SIZE (0x21)
63
64#define NFC_RX_BUFFER_CNT_START (0x0)
65
66#define NFC_RX_BUFFER_BLOCK_SIZE (0x120) /* Bytes per Block */
67#define NFC_RX_BUFFER_PAGE_SIZE (0x1000) /* Page size Bytes */
68#define NFC_RX_BUFFER_PAGES (0x8)
69#define NFC_RX_ORDER_FREE_PAGES (0x3) /* Free 8 Pages */
70
71/* The total no. of Blocks */
72#define NFC_RX_BUFFER_CNT_LIMIT (unsigned short)( \
73 ( \
74 ((NFC_RX_BUFFER_PAGE_SIZE) *\
75 (NFC_RX_BUFFER_PAGES))/\
76 (NFC_RX_BUFFER_BLOCK_SIZE)\
77 ) \
78 ) \
79
80#define PAYLOAD_HEADER_LENGTH (0x3)
81#define PAYLOAD_LENGTH_MAX (256)
82#define BYTE (0x8)
83#define NCI_IDENTIFIER (0x10)
84
85/** Power Management Related **/
86
87#define NFCC_WAKE (0x01)
88#define NFCC_SLEEP (0x00)
89
90#define XTAL_CLOCK (0X00)
91#define REFERENCE_CLOCK (0X01)
92
93/* LDO Trim Settings */
94#define IPTAT_TRIM (0x1F)
95#define V1P1_TRIM (0x0F)
96#define V1P8_TRIM (0x0F)
97#define VBATT_OK_THRESHOLD (0x07)
98
99#define PWR_EN (0x08) /* Enable 1.1V LDO Regulator */
100#define LS_EN (0x04) /* Enable 1.1V->1.8V Level Shifters */
101
102/* Write '1' to cause wake event to NFCC. If set NFCC will not go to SLEEP */
103#define NCI_WAKE (0x02)
104
105#define NCI_ENA (0x01) /* Write '1' to enable PLL */
106#define FREQ_SEL (0x00) /* XO Frequency Select */
107#define FREQ_SEL_13 (0x00) /* XO Frequency Select = 13.56MHz */
108#define FREQ_SEL_19 (0x01) /* XO Frequency Select = 19.20 MHz */
109#define FREQ_SEL_26 (0x02) /* XO Frequency Select = 26.00 MHz */
110#define FREQ_SEL_27 (0x03) /* XO Frequency Select = 27.12 MHz */
111#define FREQ_SEL_37 (0x04) /* XO Frequency Select = 37.40 MHz */
112#define FREQ_SEL_38 (0x05) /* XO Frequency Select = 38.40 MHz */
113#define FREQ_SEL_40 (0x06) /* XO Frequency Select = 40.00 MHz */
114#define FREQ_SEL_48 (0x07) /* XO Frequency Select = 48.00 MHz */
115#define FREQ_SEL_27 (0x03) /* XO Frequency Select */
116
117
118#define QUALIFY_REFCLK (0x80)
119#define QUALIFY_OSC (0x40)
120#define LOCALBIASXTAL (0x20)
121#define BIAS2X_FORCE (0x10)
122#define BIAS2X (0x08)
123#define LBIAS2X (0x04)
124#define SMALLRF (0x02)
125#define SMALLRBIAS (0x01)
126
127/* Select as appropriate */
128#define CRYSTAL_OSC ((QUALIFY_REFCLK) | (QUALIFY_OSC) | \
129 (LOCALBIASXTAL) | (BIAS2X_FORCE) | \
130 (BIAS2X) | (LBIAS2X) | (SMALLRF) | (SMALLRBIAS))
131
132#define CDACIN (0x3F) /* Tuning range for load capacitor at X1*/
133#define CDACOUT (0x3F) /* Tuning range for load capacitor at X2*/
134
135#define RAW(reg, value) (raw_##reg[1] = value)
136
137/* Logging macro with threshold control */
138#define PRINTK(LEVEL, THRESHOLD, pString, ...) ( \
139 if (LEVEL > THRESHOLD) { \
140 pr_info(pString, ##__VA_ARGS__); \
141 } \
142 )
143
144/* board config */
145struct nfc_platform_data {
146 int (*request_resources) (struct i2c_client *client);
147 void (*free_resources) (void);
148 void (*enable) (int fw);
149 int (*test) (void);
150 void (*disable) (void);
151};
152/*
153 * Internal NFCC Hardware states. At present these may not be possible to
154 * detect in software as possibly no power when
155 * in monitor state! Also, need to detect DISABLE control GPIO from PMIC.
156 */
157enum nfcc_hardware_state {
158 NFCC_STATE_MONITOR, /* VBAT < h/w Critcal Voltage */
159 /* VBAT > H/W Critical Voltage;
160 Lowest Power Mode - DISABLE = 1; only
161 possible when phone is ON */
162 NFCC_STATE_HPD,
163 /* VBAT > H/W Critical Voltage; DISABLE = 0;
164 Only possible when phone is ON */
165 NFCC_STSTE_ULPM,
166 /* VBAT > H/W Critical Voltage; DISABLE = 0;
167 Powered by PMIC & VBAT; 1.8V I/O supply on; VDDPX available, boot is
168 initiated by host over I2C */
169 NFCC_STATE_NORMAL_REGION1,
170 /* VBAT > H/W Critical Voltage; DISABLE = 0;
171 Powered by VBAT; 1.8V I/O supply on; VDDPX available, boot is initiated
172 by host over I2C */
173 NFCC_STATE_NORMAL_REGION2,
174};
175
176/* We assume here that VBATT > h/w Critical Voltage */
177enum nfcc_state {
178 /* Assume In ULPM state, ready for initialisation, cannot detect for
179 Monitor or HPD states */
180 NFCC_STATE_COLD,
181 /* (VDDPX==1) && (Following I2C initialisation). In Region 1 or Region2
182 state WAKE */
183 NFCC_STATE_NORMAL_WAKE,
184 /* (VDDPX==1) && (Following I2C initialisation). In Region 1 or Region2
185 state SLEEP */
186 NFCC_STATE_NORMAL_SLEEP,
187};
188
189
190enum nfcc_irq {
191 NFCC_NO_INT,
192 NFCC_INT,
193};
194
195
196struct nfc_info {
197 struct miscdevice miscdev;
198 struct i2c_client *i2c_dev;
199 struct regulator_bulk_data regs[3];
200 enum nfcc_state state;
201 wait_queue_head_t read_wait;
202 loff_t read_offset;
203 struct mutex read_mutex;
204 struct mutex mutex;
205 u8 *buf;
206 size_t buflen;
207 spinlock_t irq_enabled_lock;
208 unsigned int count_irq;
209 enum nfcc_irq read_irq;
210};
211
212
213struct nfc_i2c_platform_data {
214 unsigned int nfc_irq_gpio;
215 unsigned int nfc_clk_en_gpio;
216 unsigned int dis_gpio;
217 unsigned int irq_gpio;
218 unsigned int ven_gpio;
219 unsigned int firm_gpio;
220 unsigned int reg;
221};
222#endif