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