Home | History | Annotate | Download | only in nfc
      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,0x3E} // ANATXMODGSPON
     37     ,{0x00,0x99,0x77,0xFF} // ANATXCWGSPON
     38     ,{0x00,0x99,0x31,0x70} // ANAVMID setting PICC
     39     ,{0x00,0x99,0x2A,0xF5} // ANATXMODGSN-TYPEB
     40 #ifdef grouper
     41     ,{0x00,0x99,0x29,0xF5} // ANATXMODGSN-TYPEA
     42 #else
     43     ,{0x00,0x99,0x29,0xFF} // ANATXMODGSN-TYPEA
     44 #endif
     45     // For tegra we don't override load modulation settings.
     46 
     47     // Enable PBTF
     48     ,{0x00,0x98,0x00,0x3F} // SECURE_ELEMENT_CONFIGURATION - No Secure Element
     49     ,{0x00,0x9F,0x09,0x00} // SWP_PBTF_RFU
     50     ,{0x00,0x9F,0x0A,0x05} // SWP_PBTF_RFLD  --> RFLEVEL Detector for PBTF
     51     ,{0x00,0x9E,0xD1,0xA1} //
     52 
     53     // Change RF Level Detector ANARFLDWU
     54     ,{0x00,0x99,0x23,0x00} // Default Value is 0x01
     55 
     56     // Low-power polling
     57     ,{0x00,0x9E,0x74,0xB0} // Default Value is 0x00, bits 0->2: sensitivity (0==max,  6==min),
     58                            // bit 3: RFU,
     59                            // bits 4,5 hybrid low-power: # of low-power polls per regular poll
     60                            // bit 6: RFU
     61                            // bit 7: (0 -> disabled, 1 -> enabled)
     62     ,{0x00,0x9E,0x7D,0xB0} // bits 0->3: RFU,
     63                            // bits 4,5: # retries after low power detection
     64                            // 0=1 retry, 1=2 retry, 2=3 retry, 3=4 retry
     65                            // bit 6: RFU,
     66                            // bit 7: Enable or disable retry mechanism (0: disable, 1: enable)
     67     ,{0x00,0x9F,0x28,0x01} // bits 0->7: # of measurements per low-power poll
     68 
     69     // Polling Loop - Card Emulation Timeout
     70     ,{0x00,0x9F,0x35,0x14} // Time for which PN544 stays in Card Emulation mode after leaving RF field
     71     ,{0x00,0x9F,0x36,0x60} // Default value 0x0411 = 50 ms ---> New Value : 0x1460 = 250 ms
     72 
     73     //LLC Timer
     74     ,{0x00,0x9C,0x31,0x00} // Guard host time-out in ms (MSB)
     75     ,{0x00,0x9C,0x32,0xC8} // Guard host time-out in ms (LSB)
     76     ,{0x00,0x9C,0x19,0x40} // Max RX retry (PN544=>host?)
     77     ,{0x00,0x9C,0x1A,0x40} // Max TX retry (PN544=>host?)
     78 
     79     ,{0x00,0x9C,0x0C,0x00} //
     80     ,{0x00,0x9C,0x0D,0x00} //
     81     ,{0x00,0x9C,0x12,0x00} //
     82     ,{0x00,0x9C,0x13,0x00} //
     83 
     84     //WTX for LLCP communication
     85     ,{0x00,0x98,0xA2,0x0E} // Max value: 14 (default value: 09)
     86 
     87     //SE GPIO
     88     ,{0x00, 0x98, 0x93, 0x40}
     89 
     90     // Set NFCT ATQA
     91     ,{0x00, 0x98, 0x7D, 0x02}
     92     ,{0x00, 0x98, 0x7E, 0x00}
     93 
     94     // Enable CEA detection mechanism
     95     ,{0x00, 0x9F, 0xC8, 0x01}
     96     // Set NFC-F poll RC=0x00
     97     ,{0x00, 0x9F, 0x9A, 0x00}
     98     // Setting for EMD support for ISO 14443-4 Reader
     99     ,{0x00,0x9F,0x09,0x00} // 0x00 - Disable EMD support, 0x01 - Enable EMD support
    100 };
    101 
    102 static int pn544_close(hw_device_t *dev) {
    103     free(dev);
    104 
    105     return 0;
    106 }
    107 
    108 /*
    109  * Generic device handling
    110  */
    111 
    112 static int nfc_open(const hw_module_t* module, const char* name,
    113         hw_device_t** device) {
    114     if (strcmp(name, NFC_PN544_CONTROLLER) == 0) {
    115         nfc_pn544_device_t *dev = calloc(1, sizeof(nfc_pn544_device_t));
    116 
    117         dev->common.tag = HARDWARE_DEVICE_TAG;
    118         dev->common.version = 0;
    119         dev->common.module = (struct hw_module_t*) module;
    120         dev->common.close = pn544_close;
    121 
    122         dev->num_eeprom_settings = sizeof(pn544_eedata_settings) / 4;
    123         dev->eeprom_settings = (uint8_t*)pn544_eedata_settings;
    124         dev->linktype = PN544_LINK_TYPE_I2C;
    125         dev->device_node = "/dev/pn544";
    126         dev->enable_i2c_workaround = 1;
    127         dev->i2c_device_address = 0x51;
    128         *device = (hw_device_t*) dev;
    129         return 0;
    130     } else {
    131         return -EINVAL;
    132     }
    133 }
    134 
    135 static struct hw_module_methods_t nfc_module_methods = {
    136     .open = nfc_open,
    137 };
    138 
    139 struct nfc_module_t HAL_MODULE_INFO_SYM = {
    140     .common = {
    141         .tag = HARDWARE_MODULE_TAG,
    142         .version_major = 1,
    143         .version_minor = 0,
    144         .id = NFC_HARDWARE_MODULE_ID,
    145         .name = "Tegra NFC HW HAL",
    146         .author = "The Android Open Source Project",
    147         .methods = &nfc_module_methods,
    148     },
    149 };
    150