| /* |
| * 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_pianosa" |
| #define LOG_NDEBUG 0 |
| |
| #include <cutils/log.h> |
| #include "acm_pianosa.h" |
| |
| extern int codec_reg_num; |
| |
| static void PMIC_Enable(void); |
| static void PMIC_Disable(void); |
| static void PMIC_Reset(void); |
| static void PMIC_GetTypeAndID(int *type, unsigned char *id); |
| static ACH_ReturnCode PMIC_Handle(void *setting); |
| |
| ACH_ComponentHandler PMIC_handler = { |
| COMPONENT_INACTIVE, |
| 0, |
| PMIC_Enable, |
| PMIC_Disable, |
| PMIC_Reset, |
| PMIC_GetTypeAndID, |
| PMIC_Handle, |
| }; |
| |
| extern void I2CWrite(unsigned char numid, unsigned short value); |
| extern void I2CRead(unsigned char numid, unsigned char *value); |
| |
| static void PMIC_RegSet(unsigned char numid, unsigned char value) { |
| #ifndef DEBUG_FAKE_ACH |
| I2CWrite(numid, value); |
| #endif |
| } |
| |
| void PMIC_RegGet(unsigned char numid, unsigned char *value) { |
| #ifndef DEBUG_FAKE_ACH |
| I2CRead(numid, value); |
| #endif |
| } |
| |
| static void PMIC_ResetRegCache() { |
| int size = sizeof(reg_cache) / sizeof(reg_cache[0]); |
| int i = 0; |
| |
| for (i = 0; i < size; i++) { |
| reg_cache[i].reg_value = reg_cache[i].reg_default; |
| } |
| } |
| |
| unsigned char PMIC_GetRegNumId(unsigned char reg_index) { |
| unsigned char i = 0; |
| |
| for (i = 0; i < NUM_OF_REGS; i++) { |
| if (reg_cache[i].reg_index == reg_index) { |
| return codec_reg_num + i; |
| } |
| } |
| |
| return 0; |
| } |
| |
| //-------------------------------------------------------------- |
| //-------- External ACH APIs |
| //-------------------------------------------------------------- |
| static void PMIC_Enable(void) { |
| LOGI(PMIC_Enable, "%s: enable pianosa component", __FUNCTION__); |
| } |
| |
| static void PMIC_Disable(void) { |
| LOGI(PMIC_Disable, "%s: disable pianosa component", __FUNCTION__); |
| } |
| |
| static void PMIC_Reset(void) { |
| LOGI(PMIC_Reset, "%s: Reset pianosa registers!", __FUNCTION__); |
| int size = sizeof(reg_cache) / sizeof(reg_cache[0]); |
| int size_col = sizeof(reg_cache[0]) / sizeof(unsigned char); |
| int i, k = 0; |
| int m; |
| unsigned char j, numid, value, cache_idx; |
| Pianosa_RegisterCache reg_cache_inorder[size]; |
| |
| for (j = 0x0; j <= 0xff; j++){ |
| if (k == size){ |
| LOGI(PMIC_Reset1, "%s: copy completed !", __FUNCTION__); |
| break; |
| } |
| |
| for (i = 0; i < size; i++) { |
| if (reg_cache[i].reg_prior == j) { |
| memcpy(®_cache_inorder[k], ®_cache[i], size_col); |
| k++; |
| } |
| } |
| } |
| |
| for (k = 0; k < size; k++) { |
| if (reg_cache_inorder[k].reg_prior == 0x0) { |
| continue; |
| } else { |
| break; |
| } |
| } |
| |
| for (; k < size; k++) { |
| numid = PMIC_GetRegNumId(reg_cache_inorder[k].reg_index); |
| if (numid == 0) { |
| LOGW(PMIC_Reset2, "%s: Invalid numid = %02d!", __FUNCTION__, numid); |
| continue; |
| } |
| |
| value = reg_cache_inorder[k].reg_default; |
| cache_idx = numid - codec_reg_num; |
| if (cache_idx < size) |
| reg_cache[cache_idx].reg_value = value; |
| PMIC_RegSet(numid, value); |
| #ifdef DEBUG_PMIC |
| LOGI(PMIC_Reset3, "%s: resets pianosa register 0x%02x to value --> 0x%02x", |
| __FUNCTION__, |
| reg_cache_inorder[k].reg_index, |
| value); |
| #endif |
| } |
| } |
| |
| static void PMIC_GetTypeAndID(int *type, unsigned char *id){ |
| LOGI(PMIC_GetTypeAndID, "%s: Get type and ID for pianosa component", __FUNCTION__); |
| *type = COMPONENT_TYPE_POWER; |
| PMIC_RegGet(PIANOSA_ID_REG, id); |
| } |
| |
| static ACH_ReturnCode PMIC_Handle(void *setting) { |
| ACH_ComponentParameter *param = (ACH_ComponentParameter *)setting; |
| unsigned short i = 0; |
| unsigned char numid, value, cache_idx; |
| |
| if (param && param->i2c.reg_value) { |
| numid = PMIC_GetRegNumId(param->i2c.reg_index); |
| if (numid > 0) { |
| //compare with register cache |
| cache_idx = numid - codec_reg_num; |
| value = (reg_cache[cache_idx].reg_value & ~param->i2c.reg_mask) | (*param->i2c.reg_value); |
| if ((reg_cache[cache_idx].reg_value & param->i2c.reg_mask) != (*param->i2c.reg_value)) { |
| #ifdef DEBUG_PMIC |
| LOGI(PMIC_Handle, "%s: set register 0x%02x [0x%02x --> 0x%02x]", |
| __FUNCTION__, |
| param->i2c.reg_index, |
| reg_cache[cache_idx].reg_value, |
| value); |
| #endif |
| reg_cache[cache_idx].reg_value = value; |
| PMIC_RegSet(numid, reg_cache[cache_idx].reg_value); |
| } else { |
| #ifdef DEBUG_PMIC |
| LOGI(PMIC_Handle1, "%s: set register 0x%02x [0x%02x --> 0x%02x] (unchanged)", |
| __FUNCTION__, |
| param->i2c.reg_index, |
| reg_cache[cache_idx].reg_value, |
| reg_cache[cache_idx].reg_value); |
| #endif |
| } |
| } |
| } |
| |
| return ACH_RC_OK; |
| } |