• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15 */
16 
17 #include <errno.h>
18 #include <string.h>
19 
20 #include <hardware/hardware.h>
21 #include <hardware/nfc.h>
22 
23 static uint8_t pn544_eedata_settings[][4] = {
24     // DIFFERENTIAL_ANTENNA
25 
26     // RF Settings
27     {0x00,0x9B,0xD1,0x0D} // Tx consumption higher than 0x0D (average 50mA)
28     ,{0x00,0x9B,0xD2,0x24} // GSP setting for this threshold
29     ,{0x00,0x9B,0xD3,0x0A} // Tx consumption higher than 0x0A (average 40mA)
30     ,{0x00,0x9B,0xD4,0x22} // GSP setting for this threshold
31     ,{0x00,0x9B,0xD5,0x08} // Tx consumption higher than 0x08 (average 30mA)
32     ,{0x00,0x9B,0xD6,0x1E} // GSP setting for this threshold
33     ,{0x00,0x9B,0xDD,0x1C} // GSP setting for this threshold
34     ,{0x00,0x9B,0x84,0x13} // ANACM2 setting
35     ,{0x00,0x99,0x81,0x7F} // ANAVMID setting PCD
36     ,{0x00,0x99,0x7A,0x04} // ANATXMODGSPON
37     ,{0x00,0x99,0x77,0x40} // ANATXCWGSPON
38     ,{0x00,0x99,0x31,0x70} // ANAVMID setting PICC
39     ,{0x00,0x99,0x2A,0xF5} // ANATXMODGSN-TYPEB
40     ,{0x00,0x99,0x29,0xF5} // ANATXMODGSN-TYPEA
41     // For tegra we don't override load modulation settings.
42 
43     // Enable PBTF
44     ,{0x00,0x98,0x00,0x3F} // SECURE_ELEMENT_CONFIGURATION - No Secure Element
45     ,{0x00,0x9F,0x09,0x00} // SWP_PBTF_RFU
46     ,{0x00,0x9F,0x0A,0x05} // SWP_PBTF_RFLD  --> RFLEVEL Detector for PBTF
47     ,{0x00,0x9E,0xD1,0xA1} //
48 
49     // Change RF Level Detector ANARFLDWU
50     ,{0x00,0x99,0x23,0x00} // Default Value is 0x01
51 
52     // Low-power polling
53     ,{0x00,0x9E,0x74,0xB0} // Default Value is 0x00, bits 0->2: sensitivity (0==max,  6==min),
54                            // bit 3: RFU,
55                            // bits 4,5 hybrid low-power: # of low-power polls per regular poll
56                            // bit 6: RFU
57                            // bit 7: (0 -> disabled, 1 -> enabled)
58     ,{0x00,0x9E,0x7D,0xB0} // bits 0->3: RFU,
59                            // bits 4,5: # retries after low power detection
60                            // 0=1 retry, 1=2 retry, 2=3 retry, 3=4 retry
61                            // bit 6: RFU,
62                            // bit 7: Enable or disable retry mechanism (0: disable, 1: enable)
63     ,{0x00,0x9F,0x28,0x01} // bits 0->7: # of measurements per low-power poll
64 
65     // Polling Loop - Card Emulation Timeout
66     ,{0x00,0x9F,0x35,0x14} // Time for which PN544 stays in Card Emulation mode after leaving RF field
67     ,{0x00,0x9F,0x36,0x60} // Default value 0x0411 = 50 ms ---> New Value : 0x1460 = 250 ms
68 
69     //LLC Timer
70     ,{0x00,0x9C,0x31,0x00} // Guard host time-out in ms (MSB)
71     ,{0x00,0x9C,0x32,0xC8} // Guard host time-out in ms (LSB)
72     ,{0x00,0x9C,0x19,0x40} // Max RX retry (PN544=>host?)
73     ,{0x00,0x9C,0x1A,0x40} // Max TX retry (PN544=>host?)
74 
75     ,{0x00,0x9C,0x0C,0x00} //
76     ,{0x00,0x9C,0x0D,0x00} //
77     ,{0x00,0x9C,0x12,0x00} //
78     ,{0x00,0x9C,0x13,0x00} //
79 
80     //WTX for LLCP communication
81     ,{0x00,0x98,0xA2,0x0E} // Max value: 14 (default value: 09)
82 
83     //SE GPIO
84     ,{0x00, 0x98, 0x93, 0x40}
85 
86     // Set NFCT ATQA
87     ,{0x00, 0x98, 0x7D, 0x02}
88     ,{0x00, 0x98, 0x7E, 0x00}
89 
90     // Enable CEA detection mechanism
91     ,{0x00, 0x9F, 0xC8, 0x01}
92     // Set NFC-F poll RC=0x00
93     ,{0x00, 0x9F, 0x9A, 0x00}
94     // Setting for EMD support for ISO 14443-4 Reader
95     ,{0x00,0x9F,0x09,0x00} // 0x00 - Disable EMD support, 0x01 - Enable EMD support
96 };
97 
pn544_close(hw_device_t * dev)98 static int pn544_close(hw_device_t *dev) {
99     free(dev);
100 
101     return 0;
102 }
103 
104 /*
105  * Generic device handling
106  */
107 
nfc_open(const hw_module_t * module,const char * name,hw_device_t ** device)108 static int nfc_open(const hw_module_t* module, const char* name,
109         hw_device_t** device) {
110     if (strcmp(name, NFC_PN544_CONTROLLER) == 0) {
111         nfc_pn544_device_t *dev = calloc(1, sizeof(nfc_pn544_device_t));
112 
113         dev->common.tag = HARDWARE_DEVICE_TAG;
114         dev->common.version = 0;
115         dev->common.module = (struct hw_module_t*) module;
116         dev->common.close = pn544_close;
117 
118         dev->num_eeprom_settings = sizeof(pn544_eedata_settings) / 4;
119         dev->eeprom_settings = (uint8_t*)pn544_eedata_settings;
120         dev->linktype = PN544_LINK_TYPE_I2C;
121         dev->device_node = "/dev/pn544";
122         dev->enable_i2c_workaround = 1;
123         dev->i2c_device_address = 0x51;
124         *device = (hw_device_t*) dev;
125         return 0;
126     } else {
127         return -EINVAL;
128     }
129 }
130 
131 static struct hw_module_methods_t nfc_module_methods = {
132     .open = nfc_open,
133 };
134 
135 struct nfc_module_t HAL_MODULE_INFO_SYM = {
136     .common = {
137         .tag = HARDWARE_MODULE_TAG,
138         .version_major = 1,
139         .version_minor = 0,
140         .id = NFC_HARDWARE_MODULE_ID,
141         .name = "Tegra NFC HW HAL",
142         .author = "The Android Open Source Project",
143         .methods = &nfc_module_methods,
144     },
145 };
146