1 /******************************************************************************
2 *
3 * Copyright (C) 1999-2012 Broadcom Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 #define LOG_TAG "NfcNciHal"
20 #include <errno.h>
21 #include <hardware/hardware.h>
22 #include <hardware/nfc.h>
23 #include <malloc.h>
24 #include <string.h>
25 #include "HalAdaptation.h"
26 #include "_OverrideLog.h"
27
28 /*********************************
29 * NCI HAL method implementations.
30 *********************************/
31
hal_open(const struct nfc_nci_device * p_dev,nfc_stack_callback_t * p_hal_cback,nfc_stack_data_callback_t * p_hal_data_callback)32 static int hal_open(const struct nfc_nci_device* p_dev,
33 nfc_stack_callback_t* p_hal_cback,
34 nfc_stack_data_callback_t* p_hal_data_callback) {
35 int retval = 0;
36 bcm2079x_dev_t* dev = (bcm2079x_dev_t*)p_dev;
37
38 retval = HaiOpen(dev, p_hal_cback, p_hal_data_callback);
39 return retval;
40 }
41
hal_write(const struct nfc_nci_device * p_dev,uint16_t data_len,const uint8_t * p_data)42 static int hal_write(const struct nfc_nci_device* p_dev, uint16_t data_len,
43 const uint8_t* p_data) {
44 int retval = 0;
45 bcm2079x_dev_t* dev = (bcm2079x_dev_t*)p_dev;
46
47 retval = HaiWrite(dev, data_len, p_data);
48 return retval;
49 }
50
hal_core_initialized(const struct nfc_nci_device * p_dev,uint8_t * p_core_init_rsp_params)51 static int hal_core_initialized(const struct nfc_nci_device* p_dev,
52 uint8_t* p_core_init_rsp_params) {
53 int retval = 0;
54 bcm2079x_dev_t* dev = (bcm2079x_dev_t*)p_dev;
55
56 retval = HaiCoreInitialized(dev, p_core_init_rsp_params);
57 return retval;
58 }
59
hal_pre_discover(const struct nfc_nci_device * p_dev)60 static int hal_pre_discover(const struct nfc_nci_device* p_dev) {
61 int retval = 0;
62 bcm2079x_dev_t* dev = (bcm2079x_dev_t*)p_dev;
63
64 retval = HaiPreDiscover(dev);
65 return retval;
66 }
67
hal_close(const struct nfc_nci_device * p_dev)68 static int hal_close(const struct nfc_nci_device* p_dev) {
69 int retval = 0;
70 bcm2079x_dev_t* dev = (bcm2079x_dev_t*)p_dev;
71
72 retval = HaiClose(dev);
73 return retval;
74 }
75
hal_control_granted(const struct nfc_nci_device * p_dev)76 static int hal_control_granted(const struct nfc_nci_device* p_dev) {
77 int retval = 0;
78 bcm2079x_dev_t* dev = (bcm2079x_dev_t*)p_dev;
79
80 retval = HaiControlGranted(dev);
81 return retval;
82 }
83
hal_power_cycle(const struct nfc_nci_device * p_dev)84 static int hal_power_cycle(const struct nfc_nci_device* p_dev) {
85 int retval = 0;
86 bcm2079x_dev_t* dev = (bcm2079x_dev_t*)p_dev;
87
88 retval = HaiPowerCycle(dev);
89 return retval;
90 }
91
hal_get_max_nfcee(const struct nfc_nci_device * p_dev,uint8_t * maxNfcee)92 static int hal_get_max_nfcee(const struct nfc_nci_device* p_dev,
93 uint8_t* maxNfcee) {
94 int retval = 0;
95 bcm2079x_dev_t* dev = (bcm2079x_dev_t*)p_dev;
96
97 retval = HaiGetMaxNfcee(dev, maxNfcee);
98 return retval;
99 }
100
101 /*************************************
102 * Generic device handling.
103 *************************************/
104
105 /* Close an opened nfc device instance */
nfc_close(hw_device_t * dev)106 static int nfc_close(hw_device_t* dev) {
107 int retval = 0;
108 free(dev);
109 retval = HaiTerminateLibrary();
110 return retval;
111 }
112
nfc_open(const hw_module_t * module,const char * name,hw_device_t ** device)113 static int nfc_open(const hw_module_t* module, const char* name,
114 hw_device_t** device) {
115 ALOGD("%s: enter; name=%s", __func__, name);
116 int retval = 0; // 0 is ok; -1 is error
117
118 if (strcmp(name, NFC_NCI_CONTROLLER) == 0) {
119 bcm2079x_dev_t* dev = calloc(1, sizeof(bcm2079x_dev_t));
120
121 // Common hw_device_t fields
122 dev->nci_device.common.tag = HARDWARE_DEVICE_TAG;
123 dev->nci_device.common.version = 0x00010000; // [31:16] major, [15:0] minor
124 dev->nci_device.common.module = (struct hw_module_t*)module;
125 dev->nci_device.common.close = nfc_close;
126
127 // NCI HAL method pointers
128 dev->nci_device.open = hal_open;
129 dev->nci_device.write = hal_write;
130 dev->nci_device.core_initialized = hal_core_initialized;
131 dev->nci_device.pre_discover = hal_pre_discover;
132 dev->nci_device.close = hal_close;
133 dev->nci_device.control_granted = hal_control_granted;
134 dev->nci_device.power_cycle = hal_power_cycle;
135 // dev->nci_device.get_max_ee = hal_get_max_nfcee;
136
137 // Copy in
138 *device = (hw_device_t*)dev;
139
140 retval = HaiInitializeLibrary(dev);
141 } else {
142 retval = -EINVAL;
143 }
144 ALOGD("%s: exit %d", __func__, retval);
145 return retval;
146 }
147
148 static struct hw_module_methods_t nfc_module_methods = {
149 .open = nfc_open,
150 };
151
152 struct nfc_nci_module_t HAL_MODULE_INFO_SYM = {
153 .common =
154 {
155 .tag = HARDWARE_MODULE_TAG,
156 .module_api_version = 0x0100, // [15:8] major, [7:0] minor (1.0)
157 .hal_api_version = 0x00, // 0 is only valid value
158 .id = NFC_NCI_BCM2079X_HARDWARE_MODULE_ID,
159 .name = "BCM2079x NFC NCI HW HAL",
160 .author = "Broadcom Corporation",
161 .methods = &nfc_module_methods,
162 },
163 };
164