| /* |
| * All Rights Reserved |
| * |
| * MARVELL CONFIDENTIAL |
| * Copyright 2012 Marvell International Ltd All Rights Reserved. |
| * The source code contained or described herein and all documents related to |
| * the source code ("Material") are owned by Marvell International Ltd or its |
| * suppliers or licensors. Title to the Material remains with Marvell International Ltd |
| * or its suppliers and licensors. The Material contains trade secrets and |
| * proprietary and confidential information of Marvell or its suppliers and |
| * licensors. The Material is protected by worldwide copyright and trade secret |
| * laws and treaty provisions. No part of the Material may be used, copied, |
| * reproduced, modified, published, uploaded, posted, transmitted, distributed, |
| * or disclosed in any way without Marvell's prior express written permission. |
| * |
| * No license under any patent, copyright, trade secret or other intellectual |
| * property right is granted to or conferred upon you by disclosure or delivery |
| * of the Materials, either expressly, by implication, inducement, estoppel or |
| * otherwise. Any license under such intellectual property rights must be |
| * express and approved by Marvell in writing. |
| * |
| */ |
| |
| #define LOG_TAG "acm_ach_gpio" |
| #define LOG_NDEBUG 0 |
| |
| #include <cutils/log.h> |
| #include <sys/types.h> |
| #include <sys/stat.h> |
| #include <fcntl.h> |
| #include <errno.h> |
| #include <string.h> |
| #include "acm_ach.h" |
| |
| #ifndef GPIO_SPKR_SWITCH_PATH |
| #define GPIO_SPKR_SWITCH_PATH "/sys/bus/platform/devices/88pm80x-codec/gpio_speaker_switch_select" |
| #endif |
| |
| static void GPIO_Enable(void); |
| static void GPIO_Disable(void); |
| static void GPIO_Reset(void); |
| static void GPIO_GetTypeAndID(int *type, unsigned char *id); |
| static ACH_ReturnCode GPIO_Handle(void *setting); |
| |
| ACH_ComponentHandler gpio_handler = { |
| COMPONENT_INACTIVE, |
| 0, |
| GPIO_Enable, |
| GPIO_Disable, |
| GPIO_Reset, |
| GPIO_GetTypeAndID, |
| GPIO_Handle, |
| }; |
| |
| static void GPIO_Set(unsigned char port, unsigned char value) { |
| //FIXME only can manipulate the specific port(GPIO19) |
| char buf[2]; |
| int gpio_fd = open(GPIO_SPKR_SWITCH_PATH, O_RDWR | O_SYNC); |
| |
| if (gpio_fd == -1) { |
| ALOGW(GPIO_Set, "%s: Failed to open GPIO %d, %s", __FUNCTION__, port, |
| strerror(errno)); |
| return; |
| } |
| |
| buf[1] = '\n'; |
| if (value == 1) { |
| buf[0] = '1'; |
| } else { |
| buf[0] = '0'; |
| } |
| write(gpio_fd, buf, sizeof(buf)); |
| |
| close(gpio_fd); |
| } |
| |
| static void GPIO_Get(unsigned char port, unsigned char *value) { |
| //FIXME only can manipulate the specific port(GPIO19) |
| int gpio_fd = open(GPIO_SPKR_SWITCH_PATH, O_RDONLY); |
| if (gpio_fd == -1) { |
| ALOGW(GPIO_Get, "%s: Failed to open GPIO %d, %s", __FUNCTION__, port, |
| strerror(errno)); |
| return; |
| } |
| read(gpio_fd, value, sizeof(unsigned char)); |
| close(gpio_fd); |
| } |
| |
| //-------------------------------------------------------------- |
| //-------- External ACH APIs |
| //-------------------------------------------------------------- |
| static void GPIO_Enable(void) { |
| ALOGI(GPIO_Enable, "%s: enable gpio component", __FUNCTION__); |
| // implemented if GPIO component needs |
| // GPIOEnable(); |
| usleep(2000); |
| } |
| |
| static void GPIO_Disable(void) { |
| ALOGI(GPIO_Disable, "%s: disable gpio component", __FUNCTION__); |
| // implemented if GPIO component needs |
| // GPIODisable(); |
| usleep(2000); |
| } |
| |
| static void GPIO_Reset(void) { |
| ALOGI(GPIO_Reset, "%s: reset gpio component", __FUNCTION__); |
| } |
| |
| static void GPIO_GetTypeAndID(int *type, unsigned char *id) { |
| ALOGI(GPIO_GetTypeAndID, "%s: Get type and ID for GPIO component", __FUNCTION__); |
| *type = COMPONENT_TYPE_GPIO; |
| // implemented if GPIO component needs id |
| //GPIO_Get(GPIO_ID, id); |
| } |
| |
| static ACH_ReturnCode GPIO_Handle(void *setting) { |
| ACH_ComponentParameter *param = (ACH_ComponentParameter *)setting; |
| |
| if (param) { |
| ALOGI(GPIO_Handle, "%s: set GPIO port %d [%d]", __FUNCTION__, |
| param->gpio.gpio_port, param->gpio.gpio_value); |
| GPIO_Set(param->gpio.gpio_port, param->gpio.gpio_value); |
| } |
| |
| return ACH_RC_OK; |
| } |