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