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
20 #define LOG_TAG "NfcNciHal"
21 #include "OverrideLog.h"
22 #include <errno.h>
23 #include <malloc.h>
24 #include <string.h>
25 #include <hardware/hardware.h>
26 #include <hardware/nfc.h>
27 #include "HalAdaptation.h"
28
29
30 /*********************************
31 * NCI HAL method implementations.
32 *********************************/
33
34
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)35 static int 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)
36 {
37 int retval = 0;
38 bcm2079x_dev_t *dev = (bcm2079x_dev_t*) p_dev;
39
40 retval = HaiOpen (dev, p_hal_cback, p_hal_data_callback);
41 return retval;
42 }
43
44
hal_write(const struct nfc_nci_device * p_dev,uint16_t data_len,const uint8_t * p_data)45 static int hal_write (const struct nfc_nci_device *p_dev,
46 uint16_t data_len, const uint8_t *p_data)
47 {
48 int retval = 0;
49 bcm2079x_dev_t* dev = (bcm2079x_dev_t*) p_dev;
50
51 retval = HaiWrite (dev, data_len, p_data);
52 return retval;
53 }
54
55
hal_core_initialized(const struct nfc_nci_device * p_dev,uint8_t * p_core_init_rsp_params)56 static int hal_core_initialized (const struct nfc_nci_device *p_dev,
57 uint8_t* p_core_init_rsp_params)
58 {
59 int retval = 0;
60 bcm2079x_dev_t* dev = (bcm2079x_dev_t*) p_dev;
61
62 retval = HaiCoreInitialized (dev, p_core_init_rsp_params);
63 return retval;
64 }
65
66
hal_pre_discover(const struct nfc_nci_device * p_dev)67 static int hal_pre_discover (const struct nfc_nci_device *p_dev)
68 {
69 int retval = 0;
70 bcm2079x_dev_t* dev = (bcm2079x_dev_t*) p_dev;
71
72 retval = HaiPreDiscover (dev);
73 return retval;
74 }
75
76
hal_close(const struct nfc_nci_device * p_dev)77 static int hal_close (const struct nfc_nci_device *p_dev)
78 {
79 int retval = 0;
80 bcm2079x_dev_t* dev = (bcm2079x_dev_t*) p_dev;
81
82 retval = HaiClose (dev);
83 return retval;
84 }
85
86
hal_control_granted(const struct nfc_nci_device * p_dev)87 static int hal_control_granted (const struct nfc_nci_device *p_dev)
88 {
89 int retval = 0;
90 bcm2079x_dev_t* dev = (bcm2079x_dev_t*) p_dev;
91
92 retval = HaiControlGranted (dev);
93 return retval;
94 }
95
96
hal_power_cycle(const struct nfc_nci_device * p_dev)97 static int hal_power_cycle (const struct nfc_nci_device *p_dev)
98 {
99 int retval = 0;
100 bcm2079x_dev_t* dev = (bcm2079x_dev_t*) p_dev;
101
102 retval = HaiPowerCycle (dev);
103 return retval;
104 }
105
106
hal_get_max_nfcee(const struct nfc_nci_device * p_dev,uint8_t * maxNfcee)107 static int hal_get_max_nfcee (const struct nfc_nci_device *p_dev, uint8_t* maxNfcee)
108 {
109 int retval = 0;
110 bcm2079x_dev_t* dev = (bcm2079x_dev_t*) p_dev;
111
112 retval = HaiGetMaxNfcee (dev, maxNfcee);
113 return retval;
114 }
115
116
117 /*************************************
118 * Generic device handling.
119 *************************************/
120
121
122 /* Close an opened nfc device instance */
nfc_close(hw_device_t * dev)123 static int nfc_close (hw_device_t *dev)
124 {
125 int retval = 0;
126 free (dev);
127 retval = HaiTerminateLibrary ();
128 return retval;
129 }
130
131
nfc_open(const hw_module_t * module,const char * name,hw_device_t ** device)132 static int nfc_open (const hw_module_t* module, const char* name, hw_device_t** device)
133 {
134 ALOGD ("%s: enter; name=%s", __FUNCTION__, name);
135 int retval = 0; //0 is ok; -1 is error
136
137 if (strcmp (name, NFC_NCI_CONTROLLER) == 0)
138 {
139 bcm2079x_dev_t *dev = calloc (1, sizeof(bcm2079x_dev_t));
140
141 // Common hw_device_t fields
142 dev->nci_device.common.tag = HARDWARE_DEVICE_TAG;
143 dev->nci_device.common.version = 0x00010000; // [31:16] major, [15:0] minor
144 dev->nci_device.common.module = (struct hw_module_t*) module;
145 dev->nci_device.common.close = nfc_close;
146
147 // NCI HAL method pointers
148 dev->nci_device.open = hal_open;
149 dev->nci_device.write = hal_write;
150 dev->nci_device.core_initialized = hal_core_initialized;
151 dev->nci_device.pre_discover = hal_pre_discover;
152 dev->nci_device.close = hal_close;
153 dev->nci_device.control_granted = hal_control_granted;
154 dev->nci_device.power_cycle = hal_power_cycle;
155 //dev->nci_device.get_max_ee = hal_get_max_nfcee;
156
157
158 // Copy in
159 *device = (hw_device_t*) dev;
160
161 retval = HaiInitializeLibrary (dev);
162 }
163 else
164 {
165 retval = -EINVAL;
166 }
167 ALOGD ("%s: exit %d", __FUNCTION__, retval);
168 return retval;
169 }
170
171
172 static struct hw_module_methods_t nfc_module_methods =
173 {
174 .open = nfc_open,
175 };
176
177
178 struct nfc_nci_module_t HAL_MODULE_INFO_SYM =
179 {
180 .common =
181 {
182 .tag = HARDWARE_MODULE_TAG, .module_api_version = 0x0100, // [15:8] major, [7:0] minor (1.0)
183 .hal_api_version = 0x00, // 0 is only valid value
184 .id = NFC_NCI_BCM2079X_HARDWARE_MODULE_ID,
185 .name = "BCM2079x NFC NCI HW HAL",
186 .author = "Broadcom Corporation",
187 .methods = &nfc_module_methods,
188 },
189 };
190