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 /* Close an opened pn544 device instance */ 23 static int pn544_close(hw_device_t *dev) { 24 free(dev); 25 return 0; 26 } 27 28 /* 29 * Generic device handling 30 */ 31 static int nfc_open(const hw_module_t* module, const char* name, 32 hw_device_t** device) { 33 if (strcmp(name, NFC_PN544_CONTROLLER) == 0) { 34 nfc_pn544_device_t *dev = calloc(1, sizeof(nfc_pn544_device_t)); 35 36 dev->common.tag = HARDWARE_DEVICE_TAG; 37 dev->common.version = 0; 38 dev->common.module = (struct hw_module_t*) module; 39 dev->common.close = pn544_close; 40 41 /* Example settings */ 42 dev->num_eeprom_settings = 0; 43 dev->eeprom_settings = NULL; 44 dev->linktype = PN544_LINK_TYPE_INVALID; 45 dev->device_node = NULL; 46 dev->enable_i2c_workaround = 0; 47 dev->i2c_device_address = 0; 48 49 *device = (hw_device_t*) dev; 50 return 0; 51 } else { 52 return -EINVAL; 53 } 54 } 55 56 57 static struct hw_module_methods_t nfc_module_methods = { 58 .open = nfc_open, 59 }; 60 61 struct nfc_module_t HAL_MODULE_INFO_SYM = { 62 .common = { 63 .tag = HARDWARE_MODULE_TAG, 64 .version_major = 1, 65 .version_minor = 0, 66 .id = NFC_HARDWARE_MODULE_ID, 67 .name = "Default NFC HW HAL", 68 .author = "The Android Open Source Project", 69 .methods = &nfc_module_methods, 70 }, 71 }; 72