• 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 #include <errno.h>
17 #include <string.h>
18 
19 #include <hardware/hardware.h>
20 #include <hardware/nfc.h>
21 
22 static uint8_t pn544_eedata_settings[][4] = {
23     // DIFFERENTIAL_ANTENNA
24 
25     // RF Settings
26     {0x00,0x9B,0xD1,0x0D} // Tx consumption higher than 0x0D (average 50mA)
27     ,{0x00,0x9B,0xD2,0x24} // GSP setting for this threshold
28     ,{0x00,0x9B,0xD3,0x0A} // Tx consumption higher than 0x0A (average 40mA)
29     ,{0x00,0x9B,0xD4,0x22} // GSP setting for this threshold
30     ,{0x00,0x9B,0xD5,0x08} // Tx consumption higher than 0x08 (average 30mA)
31     ,{0x00,0x9B,0xD6,0x1E} // GSP setting for this threshold
32     ,{0x00,0x9B,0xDD,0x1C} // GSP setting for this threshold
33     ,{0x00,0x9B,0x84,0x13} // ANACM2 setting
34 
35     // Enable PBTF
36     ,{0x00,0x98,0x00,0x3F} // SECURE_ELEMENT_CONFIGURATION - No Secure Element
37     ,{0x00,0x9F,0x09,0x00} // SWP_PBTF_RFU
38     ,{0x00,0x9F,0x0A,0x05} // SWP_PBTF_RFLD  --> RFLEVEL Detector for PBTF
39     ,{0x00,0x9E,0xD1,0xA1} //
40 
41     // Change RF Level Detector ANARFLDWU
42     ,{0x00,0x99,0x23,0x00} // Default Value is 0x01
43 
44     // Low-power polling
45     ,{0x00,0x9E,0x74,0xB0} // Default Value is 0x00, bits 0->2: sensitivity (0==max, 6==min),
46                            // bit 3: RFU,
47                            // bits 4,5 hybrid low-power: # of low-power polls per regular poll
48                            // bit 6: RFU
49                            // bit 7: (0 -> disabled, 1 -> enabled)
50     ,{0x00,0x9E,0x7D,0xB0} // bits 0->3: RFU,
51                            // bits 4,5: # retries after low power detection
52                            // 0=1 retry, 1=2 retry, 2=3 retry, 3=4 retry
53                            // bit 6: RFU,
54                            // bit 7: Enable or disable retry mechanism (0: disable, 1: enable)
55     ,{0x00,0x9F,0x28,0x01} // bits 0->7: # of measurements per low-power poll
56 
57     //LLC Timer
58     ,{0x00,0x9C,0x31,0x00} // Guard host time-out in ms (MSB)
59     ,{0x00,0x9C,0x32,0xC8} // Guard host time-out in ms (LSB)
60     ,{0x00,0x9C,0x19,0x40} // Max RX retry (PN544=>host?)
61     ,{0x00,0x9C,0x1A,0x40} // Max TX retry (PN544=>host?)
62 
63     ,{0x00,0x9C,0x0C,0x00} //
64     ,{0x00,0x9C,0x0D,0x00} //
65     ,{0x00,0x9C,0x12,0x00} //
66     ,{0x00,0x9C,0x13,0x00} //
67 
68     // NFC-DEP Target Waiting Time (WT)
69     ,{0x00,0x98,0xA2,0x08} // Set to 0x08 as required by [digital] (default value: 09)
70 
71     //SE GPIO
72     ,{0x00, 0x98, 0x93, 0x40}
73 
74     // Set NFCT ATQA
75     ,{0x00, 0x98, 0x7D, 0x02}
76     ,{0x00, 0x98, 0x7E, 0x00}
77 
78     // Enable CEA detection mechanism
79     ,{0x00, 0x9F, 0xC8, 0x01}
80     // Set NFC-F poll RC=0x00
81     ,{0x00, 0x9F, 0x9A, 0x00}
82     // Setting for EMD support for ISO 14443-4 Reader
83     ,{0x00,0x9F,0x09,0x00} // 0x00 - Disable EMD support, 0x01 - Enable EMD support
84 };
85 
pn544_close(hw_device_t * dev)86 static int pn544_close(hw_device_t *dev) {
87     free(dev);
88 
89     return 0;
90 }
91 
92 /*
93  * Generic device handling
94  */
95 
nfc_open(const hw_module_t * module,const char * name,hw_device_t ** device)96 static int nfc_open(const hw_module_t* module, const char* name,
97         hw_device_t** device) {
98     if (strcmp(name, NFC_PN544_CONTROLLER) == 0) {
99         nfc_pn544_device_t *dev = calloc(1, sizeof(nfc_pn544_device_t));
100 
101         dev->common.tag = HARDWARE_DEVICE_TAG;
102         dev->common.version = 0;
103         dev->common.module = (struct hw_module_t*) module;
104         dev->common.close = pn544_close;
105 
106         dev->num_eeprom_settings = sizeof(pn544_eedata_settings) / 4;
107         dev->eeprom_settings = (uint8_t*)pn544_eedata_settings;
108         dev->linktype = PN544_LINK_TYPE_I2C;
109         dev->device_node = "/dev/pn544";
110         dev->enable_i2c_workaround = 1;
111         *device = (hw_device_t*) dev;
112         return 0;
113     } else {
114         return -EINVAL;
115     }
116 }
117 
118 static struct hw_module_methods_t nfc_module_methods = {
119     .open = nfc_open,
120 };
121 
122 struct nfc_module_t HAL_MODULE_INFO_SYM = {
123     .common = {
124         .tag = HARDWARE_MODULE_TAG,
125         .version_major = 1,
126         .version_minor = 0,
127         .id = NFC_HARDWARE_MODULE_ID,
128         .name = "Herring NFC HW HAL",
129         .author = "The Android Open Source Project",
130         .methods = &nfc_module_methods,
131     },
132 };
133