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 17 18 #ifndef ANDROID_LOCAL_TIME_HAL_INTERFACE_H 19 #define ANDROID_LOCAL_TIME_HAL_INTERFACE_H 20 21 #include <stdint.h> 22 23 #include <hardware/hardware.h> 24 25 __BEGIN_DECLS 26 27 /** 28 * The id of this module 29 */ 30 #define LOCAL_TIME_HARDWARE_MODULE_ID "local_time" 31 32 /** 33 * Name of the local time devices to open 34 */ 35 #define LOCAL_TIME_HARDWARE_INTERFACE "local_time_hw_if" 36 37 /**********************************************************************/ 38 39 /** 40 * A structure used to collect low level sync data in a lab environment. Most 41 * HAL implementations will never need this structure. 42 */ 43 struct local_time_debug_event { 44 int64_t local_timesync_event_id; 45 int64_t local_time; 46 }; 47 48 /** 49 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 50 * and the fields of this data structure must begin with hw_module_t 51 * followed by module specific information. 52 */ 53 struct local_time_module { 54 struct hw_module_t common; 55 }; 56 57 struct local_time_hw_device { 58 struct hw_device_t common; 59 60 /** 61 * 62 * Returns the current value of the system wide local time counter 63 */ 64 int64_t (*get_local_time)(struct local_time_hw_device* dev); 65 66 /** 67 * 68 * Returns the nominal frequency (in hertz) of the system wide local time 69 * counter 70 */ 71 uint64_t (*get_local_freq)(struct local_time_hw_device* dev); 72 73 /** 74 * 75 * Sets the HW slew rate of oscillator which drives the system wide local 76 * time counter. On success, platforms should return 0. Platforms which 77 * do not support HW slew should leave this method set to NULL. 78 * 79 * Valid values for rate range from MIN_INT16 to MAX_INT16. Platform 80 * implementations should attempt map this range linearly to the min/max 81 * slew rate of their hardware. 82 */ 83 int (*set_local_slew)(struct local_time_hw_device* dev, int16_t rate); 84 85 /** 86 * 87 * A method used to collect low level sync data in a lab environments. 88 * Most HAL implementations will simply set this member to NULL, or return 89 * -EINVAL to indicate that this functionality is not supported. 90 * Production HALs should never support this method. 91 */ 92 int (*get_debug_log)(struct local_time_hw_device* dev, 93 struct local_time_debug_event* records, 94 int max_records); 95 }; 96 97 typedef struct local_time_hw_device local_time_hw_device_t; 98 99 /** convenience API for opening and closing a supported device */ 100 101 static inline int local_time_hw_device_open( 102 const struct hw_module_t* module, 103 struct local_time_hw_device** device) 104 { 105 return module->methods->open(module, LOCAL_TIME_HARDWARE_INTERFACE, 106 (struct hw_device_t**)device); 107 } 108 109 static inline int local_time_hw_device_close(struct local_time_hw_device* device) 110 { 111 return device->common.close(&device->common); 112 } 113 114 115 __END_DECLS 116 117 #endif // ANDROID_LOCAL_TIME_INTERFACE_H 118