xref: /aosp_15_r20/hardware/libhardware/modules/nfc/nfc_pn544_example.c (revision e01b6f769022e40d0923dee176e8dc7cd1d52984)
1*e01b6f76SAndroid Build Coastguard Worker /*
2*e01b6f76SAndroid Build Coastguard Worker  * Copyright (C) 2011 The Android Open Source Project
3*e01b6f76SAndroid Build Coastguard Worker  *
4*e01b6f76SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*e01b6f76SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*e01b6f76SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*e01b6f76SAndroid Build Coastguard Worker  *
8*e01b6f76SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*e01b6f76SAndroid Build Coastguard Worker  *
10*e01b6f76SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*e01b6f76SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*e01b6f76SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*e01b6f76SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*e01b6f76SAndroid Build Coastguard Worker  * limitations under the License.
15*e01b6f76SAndroid Build Coastguard Worker  */
16*e01b6f76SAndroid Build Coastguard Worker #include <errno.h>
17*e01b6f76SAndroid Build Coastguard Worker #include <malloc.h>
18*e01b6f76SAndroid Build Coastguard Worker #include <string.h>
19*e01b6f76SAndroid Build Coastguard Worker 
20*e01b6f76SAndroid Build Coastguard Worker #include <hardware/hardware.h>
21*e01b6f76SAndroid Build Coastguard Worker #include <hardware/nfc.h>
22*e01b6f76SAndroid Build Coastguard Worker 
23*e01b6f76SAndroid Build Coastguard Worker /* Close an opened pn544 device instance */
pn544_close(hw_device_t * dev)24*e01b6f76SAndroid Build Coastguard Worker static int pn544_close(hw_device_t *dev) {
25*e01b6f76SAndroid Build Coastguard Worker     free(dev);
26*e01b6f76SAndroid Build Coastguard Worker     return 0;
27*e01b6f76SAndroid Build Coastguard Worker }
28*e01b6f76SAndroid Build Coastguard Worker 
29*e01b6f76SAndroid Build Coastguard Worker /*
30*e01b6f76SAndroid Build Coastguard Worker  * Generic device handling
31*e01b6f76SAndroid Build Coastguard Worker  */
nfc_open(const hw_module_t * module,const char * name,hw_device_t ** device)32*e01b6f76SAndroid Build Coastguard Worker static int nfc_open(const hw_module_t* module, const char* name,
33*e01b6f76SAndroid Build Coastguard Worker         hw_device_t** device) {
34*e01b6f76SAndroid Build Coastguard Worker     if (strcmp(name, NFC_PN544_CONTROLLER) == 0) {
35*e01b6f76SAndroid Build Coastguard Worker         nfc_pn544_device_t *dev = calloc(1, sizeof(nfc_pn544_device_t));
36*e01b6f76SAndroid Build Coastguard Worker 
37*e01b6f76SAndroid Build Coastguard Worker         dev->common.tag = HARDWARE_DEVICE_TAG;
38*e01b6f76SAndroid Build Coastguard Worker         dev->common.version = 0;
39*e01b6f76SAndroid Build Coastguard Worker         dev->common.module = (struct hw_module_t*) module;
40*e01b6f76SAndroid Build Coastguard Worker         dev->common.close = pn544_close;
41*e01b6f76SAndroid Build Coastguard Worker 
42*e01b6f76SAndroid Build Coastguard Worker         /* Example settings */
43*e01b6f76SAndroid Build Coastguard Worker         dev->num_eeprom_settings = 0;
44*e01b6f76SAndroid Build Coastguard Worker         dev->eeprom_settings = NULL;
45*e01b6f76SAndroid Build Coastguard Worker         dev->linktype = PN544_LINK_TYPE_INVALID;
46*e01b6f76SAndroid Build Coastguard Worker         dev->device_node = NULL;
47*e01b6f76SAndroid Build Coastguard Worker         dev->enable_i2c_workaround = 0;
48*e01b6f76SAndroid Build Coastguard Worker         dev->i2c_device_address = 0;
49*e01b6f76SAndroid Build Coastguard Worker 
50*e01b6f76SAndroid Build Coastguard Worker         *device = (hw_device_t*) dev;
51*e01b6f76SAndroid Build Coastguard Worker         return 0;
52*e01b6f76SAndroid Build Coastguard Worker     } else {
53*e01b6f76SAndroid Build Coastguard Worker         return -EINVAL;
54*e01b6f76SAndroid Build Coastguard Worker     }
55*e01b6f76SAndroid Build Coastguard Worker }
56*e01b6f76SAndroid Build Coastguard Worker 
57*e01b6f76SAndroid Build Coastguard Worker 
58*e01b6f76SAndroid Build Coastguard Worker static struct hw_module_methods_t nfc_module_methods = {
59*e01b6f76SAndroid Build Coastguard Worker     .open = nfc_open,
60*e01b6f76SAndroid Build Coastguard Worker };
61*e01b6f76SAndroid Build Coastguard Worker 
62*e01b6f76SAndroid Build Coastguard Worker struct nfc_module_t HAL_MODULE_INFO_SYM = {
63*e01b6f76SAndroid Build Coastguard Worker     .common = {
64*e01b6f76SAndroid Build Coastguard Worker         .tag = HARDWARE_MODULE_TAG,
65*e01b6f76SAndroid Build Coastguard Worker         .version_major = 1,
66*e01b6f76SAndroid Build Coastguard Worker         .version_minor = 0,
67*e01b6f76SAndroid Build Coastguard Worker         .id = NFC_HARDWARE_MODULE_ID,
68*e01b6f76SAndroid Build Coastguard Worker         .name = "Default NFC HW HAL",
69*e01b6f76SAndroid Build Coastguard Worker         .author = "The Android Open Source Project",
70*e01b6f76SAndroid Build Coastguard Worker         .methods = &nfc_module_methods,
71*e01b6f76SAndroid Build Coastguard Worker     },
72*e01b6f76SAndroid Build Coastguard Worker };
73