b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * All Rights Reserved |
| 3 | * |
| 4 | * MARVELL CONFIDENTIAL |
| 5 | * Copyright 2012 Marvell International Ltd All Rights Reserved. |
| 6 | * The source code contained or described herein and all documents related to |
| 7 | * the source code ("Material") are owned by Marvell International Ltd or its |
| 8 | * suppliers or licensors. Title to the Material remains with Marvell International Ltd |
| 9 | * or its suppliers and licensors. The Material contains trade secrets and |
| 10 | * proprietary and confidential information of Marvell or its suppliers and |
| 11 | * licensors. The Material is protected by worldwide copyright and trade secret |
| 12 | * laws and treaty provisions. No part of the Material may be used, copied, |
| 13 | * reproduced, modified, published, uploaded, posted, transmitted, distributed, |
| 14 | * or disclosed in any way without Marvell's prior express written permission. |
| 15 | * |
| 16 | * No license under any patent, copyright, trade secret or other intellectual |
| 17 | * property right is granted to or conferred upon you by disclosure or delivery |
| 18 | * of the Materials, either expressly, by implication, inducement, estoppel or |
| 19 | * otherwise. Any license under such intellectual property rights must be |
| 20 | * express and approved by Marvell in writing. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #define LOG_TAG "acm_ach_gpio" |
| 25 | #define LOG_NDEBUG 0 |
| 26 | |
| 27 | #include <cutils/log.h> |
| 28 | #include <sys/types.h> |
| 29 | #include <sys/stat.h> |
| 30 | #include <fcntl.h> |
| 31 | #include <errno.h> |
| 32 | #include <string.h> |
| 33 | #include "acm_ach.h" |
| 34 | |
| 35 | #ifndef GPIO_SPKR_SWITCH_PATH |
| 36 | #define GPIO_SPKR_SWITCH_PATH "/sys/bus/platform/devices/88pm80x-codec/gpio_speaker_switch_select" |
| 37 | #endif |
| 38 | |
| 39 | static void GPIO_Enable(void); |
| 40 | static void GPIO_Disable(void); |
| 41 | static void GPIO_Reset(void); |
| 42 | static void GPIO_GetTypeAndID(int *type, unsigned char *id); |
| 43 | static ACH_ReturnCode GPIO_Handle(void *setting); |
| 44 | |
| 45 | ACH_ComponentHandler gpio_handler = { |
| 46 | COMPONENT_INACTIVE, |
| 47 | 0, |
| 48 | GPIO_Enable, |
| 49 | GPIO_Disable, |
| 50 | GPIO_Reset, |
| 51 | GPIO_GetTypeAndID, |
| 52 | GPIO_Handle, |
| 53 | }; |
| 54 | |
| 55 | static void GPIO_Set(unsigned char port, unsigned char value) { |
| 56 | //FIXME only can manipulate the specific port(GPIO19) |
| 57 | char buf[2]; |
| 58 | int gpio_fd = open(GPIO_SPKR_SWITCH_PATH, O_RDWR | O_SYNC); |
| 59 | |
| 60 | if (gpio_fd == -1) { |
| 61 | ALOGW(GPIO_Set, "%s: Failed to open GPIO %d, %s", __FUNCTION__, port, |
| 62 | strerror(errno)); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | buf[1] = '\n'; |
| 67 | if (value == 1) { |
| 68 | buf[0] = '1'; |
| 69 | } else { |
| 70 | buf[0] = '0'; |
| 71 | } |
| 72 | write(gpio_fd, buf, sizeof(buf)); |
| 73 | |
| 74 | close(gpio_fd); |
| 75 | } |
| 76 | |
| 77 | static void GPIO_Get(unsigned char port, unsigned char *value) { |
| 78 | //FIXME only can manipulate the specific port(GPIO19) |
| 79 | int gpio_fd = open(GPIO_SPKR_SWITCH_PATH, O_RDONLY); |
| 80 | if (gpio_fd == -1) { |
| 81 | ALOGW(GPIO_Get, "%s: Failed to open GPIO %d, %s", __FUNCTION__, port, |
| 82 | strerror(errno)); |
| 83 | return; |
| 84 | } |
| 85 | read(gpio_fd, value, sizeof(unsigned char)); |
| 86 | close(gpio_fd); |
| 87 | } |
| 88 | |
| 89 | //-------------------------------------------------------------- |
| 90 | //-------- External ACH APIs |
| 91 | //-------------------------------------------------------------- |
| 92 | static void GPIO_Enable(void) { |
| 93 | ALOGI(GPIO_Enable, "%s: enable gpio component", __FUNCTION__); |
| 94 | // implemented if GPIO component needs |
| 95 | // GPIOEnable(); |
| 96 | usleep(2000); |
| 97 | } |
| 98 | |
| 99 | static void GPIO_Disable(void) { |
| 100 | ALOGI(GPIO_Disable, "%s: disable gpio component", __FUNCTION__); |
| 101 | // implemented if GPIO component needs |
| 102 | // GPIODisable(); |
| 103 | usleep(2000); |
| 104 | } |
| 105 | |
| 106 | static void GPIO_Reset(void) { |
| 107 | ALOGI(GPIO_Reset, "%s: reset gpio component", __FUNCTION__); |
| 108 | } |
| 109 | |
| 110 | static void GPIO_GetTypeAndID(int *type, unsigned char *id) { |
| 111 | ALOGI(GPIO_GetTypeAndID, "%s: Get type and ID for GPIO component", __FUNCTION__); |
| 112 | *type = COMPONENT_TYPE_GPIO; |
| 113 | // implemented if GPIO component needs id |
| 114 | //GPIO_Get(GPIO_ID, id); |
| 115 | } |
| 116 | |
| 117 | static ACH_ReturnCode GPIO_Handle(void *setting) { |
| 118 | ACH_ComponentParameter *param = (ACH_ComponentParameter *)setting; |
| 119 | |
| 120 | if (param) { |
| 121 | ALOGI(GPIO_Handle, "%s: set GPIO port %d [%d]", __FUNCTION__, |
| 122 | param->gpio.gpio_port, param->gpio.gpio_value); |
| 123 | GPIO_Set(param->gpio.gpio_port, param->gpio.gpio_value); |
| 124 | } |
| 125 | |
| 126 | return ACH_RC_OK; |
| 127 | } |