Mike J. Chen | ad255ee | 2011-08-15 11:59:47 -0700 | [diff] [blame] | 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 { |
Stewart Miles | 84d3549 | 2014-05-01 09:03:27 -0700 | [diff] [blame] | 58 | /** |
| 59 | * Common methods of the local time hardware device. This *must* be the first member of |
| 60 | * local_time_hw_device as users of this structure will cast a hw_device_t to |
| 61 | * local_time_hw_device pointer in contexts where it's known the hw_device_t references a |
| 62 | * local_time_hw_device. |
| 63 | */ |
Mike J. Chen | ad255ee | 2011-08-15 11:59:47 -0700 | [diff] [blame] | 64 | struct hw_device_t common; |
| 65 | |
| 66 | /** |
| 67 | * |
| 68 | * Returns the current value of the system wide local time counter |
| 69 | */ |
| 70 | int64_t (*get_local_time)(struct local_time_hw_device* dev); |
| 71 | |
| 72 | /** |
| 73 | * |
| 74 | * Returns the nominal frequency (in hertz) of the system wide local time |
| 75 | * counter |
| 76 | */ |
| 77 | uint64_t (*get_local_freq)(struct local_time_hw_device* dev); |
| 78 | |
| 79 | /** |
| 80 | * |
| 81 | * Sets the HW slew rate of oscillator which drives the system wide local |
| 82 | * time counter. On success, platforms should return 0. Platforms which |
| 83 | * do not support HW slew should leave this method set to NULL. |
| 84 | * |
| 85 | * Valid values for rate range from MIN_INT16 to MAX_INT16. Platform |
| 86 | * implementations should attempt map this range linearly to the min/max |
| 87 | * slew rate of their hardware. |
| 88 | */ |
| 89 | int (*set_local_slew)(struct local_time_hw_device* dev, int16_t rate); |
| 90 | |
| 91 | /** |
| 92 | * |
| 93 | * A method used to collect low level sync data in a lab environments. |
| 94 | * Most HAL implementations will simply set this member to NULL, or return |
| 95 | * -EINVAL to indicate that this functionality is not supported. |
| 96 | * Production HALs should never support this method. |
| 97 | */ |
| 98 | int (*get_debug_log)(struct local_time_hw_device* dev, |
| 99 | struct local_time_debug_event* records, |
| 100 | int max_records); |
| 101 | }; |
| 102 | |
| 103 | typedef struct local_time_hw_device local_time_hw_device_t; |
| 104 | |
| 105 | /** convenience API for opening and closing a supported device */ |
| 106 | |
| 107 | static inline int local_time_hw_device_open( |
| 108 | const struct hw_module_t* module, |
| 109 | struct local_time_hw_device** device) |
| 110 | { |
| 111 | return module->methods->open(module, LOCAL_TIME_HARDWARE_INTERFACE, |
Colin Cross | cc8d9f9 | 2016-10-06 16:44:23 -0700 | [diff] [blame] | 112 | TO_HW_DEVICE_T_OPEN(device)); |
Mike J. Chen | ad255ee | 2011-08-15 11:59:47 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static inline int local_time_hw_device_close(struct local_time_hw_device* device) |
| 116 | { |
| 117 | return device->common.close(&device->common); |
| 118 | } |
| 119 | |
| 120 | |
| 121 | __END_DECLS |
| 122 | |
| 123 | #endif // ANDROID_LOCAL_TIME_INTERFACE_H |