Simon Wilson | 907b20a | 2014-02-06 18:42:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | #ifndef ANDROID_INCLUDE_HARDWARE_MCU_H |
| 18 | #define ANDROID_INCLUDE_HARDWARE_MCU_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/cdefs.h> |
| 22 | #include <sys/types.h> |
| 23 | |
| 24 | #include <hardware/hardware.h> |
| 25 | |
| 26 | __BEGIN_DECLS |
| 27 | |
| 28 | #define MCU_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1) |
| 29 | |
| 30 | /* |
| 31 | * The id of this module |
| 32 | */ |
| 33 | #define MCU_HARDWARE_MODULE_ID "mcu" |
| 34 | |
| 35 | /* |
| 36 | * MCU message keys passed to (*sendMessage) |
| 37 | */ |
| 38 | #define MCU_PARAMETER_MSG_ENABLE_MCU "enable_mcu" |
| 39 | |
| 40 | /* |
| 41 | * MCU message values passed to (*sendMessage) |
| 42 | */ |
| 43 | #define MCU_PARAMETER_ARG_ON "on" |
| 44 | #define MCU_PARAMETER_ARG_OFF "off" |
| 45 | |
| 46 | /* |
| 47 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
| 48 | * and the fields of this data structure must begin with hw_module_t |
| 49 | * followed by module specific information. |
| 50 | */ |
| 51 | typedef struct mcu_module { |
| 52 | struct hw_module_t common; |
| 53 | |
| 54 | /* |
| 55 | * (*init)() performs MCU module setup actions at runtime startup, such |
| 56 | * as to initialize an external MCU. This is called only by the MCU HAL |
| 57 | * instance loaded by PowerManagerService. |
| 58 | * |
| 59 | * Returns 0 on success or -errno on error. |
| 60 | */ |
| 61 | int (*init)(struct mcu_module *module); |
| 62 | |
| 63 | /* |
| 64 | * (*sendMessage)() passes a message/argument pair to the MCU to execute |
| 65 | * a function. msg is NULL-terminated. If arg is text, then arg_len must |
| 66 | * reflect the string length. result is a heap-allocated buffer that the |
| 67 | * caller must free. If there is no result, then *result will be NULL and |
| 68 | * *result_len will be 0. |
| 69 | * |
| 70 | * Returns 0 on success or -errno in case of error (for example, if the |
| 71 | * MCU does not support the specified message.) |
| 72 | * |
| 73 | */ |
| 74 | int (*sendMessage)(struct mcu_module *module, const char *msg, |
| 75 | const void *arg, size_t arg_len, void **result, |
| 76 | size_t *result_len); |
| 77 | |
| 78 | } mcu_module_t; |
| 79 | |
| 80 | __END_DECLS |
| 81 | |
| 82 | #endif // ANDROID_INCLUDE_HARDWARE_MCU_H |