blob: 357f3c52f668ee9972db15a7231776b84a88a804 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/*
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_pianosa"
25#define LOG_NDEBUG 0
26
27#include <cutils/log.h>
28#include "acm_pianosa.h"
29
30extern int codec_reg_num;
31
32static void PMIC_Enable(void);
33static void PMIC_Disable(void);
34static void PMIC_Reset(void);
35static void PMIC_GetTypeAndID(int *type, unsigned char *id);
36static ACH_ReturnCode PMIC_Handle(void *setting);
37
38ACH_ComponentHandler PMIC_handler = {
39 COMPONENT_INACTIVE,
40 0,
41 PMIC_Enable,
42 PMIC_Disable,
43 PMIC_Reset,
44 PMIC_GetTypeAndID,
45 PMIC_Handle,
46};
47
48extern void I2CWrite(unsigned char numid, unsigned short value);
49extern void I2CRead(unsigned char numid, unsigned char *value);
50
51static void PMIC_RegSet(unsigned char numid, unsigned char value) {
52#ifndef DEBUG_FAKE_ACH
53 I2CWrite(numid, value);
54#endif
55}
56
57void PMIC_RegGet(unsigned char numid, unsigned char *value) {
58#ifndef DEBUG_FAKE_ACH
59 I2CRead(numid, value);
60#endif
61}
62
63static void PMIC_ResetRegCache() {
64 int size = sizeof(reg_cache) / sizeof(reg_cache[0]);
65 int i = 0;
66
67 for (i = 0; i < size; i++) {
68 reg_cache[i].reg_value = reg_cache[i].reg_default;
69 }
70}
71
72unsigned char PMIC_GetRegNumId(unsigned char reg_index) {
73 unsigned char i = 0;
74
75 for (i = 0; i < NUM_OF_REGS; i++) {
76 if (reg_cache[i].reg_index == reg_index) {
77 return codec_reg_num + i;
78 }
79 }
80
81 return 0;
82}
83
84//--------------------------------------------------------------
85//-------- External ACH APIs
86//--------------------------------------------------------------
87static void PMIC_Enable(void) {
88 LOGI(PMIC_Enable, "%s: enable pianosa component", __FUNCTION__);
89}
90
91static void PMIC_Disable(void) {
92 LOGI(PMIC_Disable, "%s: disable pianosa component", __FUNCTION__);
93}
94
95static void PMIC_Reset(void) {
96 LOGI(PMIC_Reset, "%s: Reset pianosa registers!", __FUNCTION__);
97 int size = sizeof(reg_cache) / sizeof(reg_cache[0]);
98 int size_col = sizeof(reg_cache[0]) / sizeof(unsigned char);
99 int i, k = 0;
100 int m;
101 unsigned char j, numid, value, cache_idx;
102 Pianosa_RegisterCache reg_cache_inorder[size];
103
104 for (j = 0x0; j <= 0xff; j++){
105 if (k == size){
106 LOGI(PMIC_Reset1, "%s: copy completed !", __FUNCTION__);
107 break;
108 }
109
110 for (i = 0; i < size; i++) {
111 if (reg_cache[i].reg_prior == j) {
112 memcpy(&reg_cache_inorder[k], &reg_cache[i], size_col);
113 k++;
114 }
115 }
116 }
117
118 for (k = 0; k < size; k++) {
119 if (reg_cache_inorder[k].reg_prior == 0x0) {
120 continue;
121 } else {
122 break;
123 }
124 }
125
126 for (; k < size; k++) {
127 numid = PMIC_GetRegNumId(reg_cache_inorder[k].reg_index);
128 if (numid == 0) {
129 LOGW(PMIC_Reset2, "%s: Invalid numid = %02d!", __FUNCTION__, numid);
130 continue;
131 }
132
133 value = reg_cache_inorder[k].reg_default;
134 cache_idx = numid - codec_reg_num;
135 if (cache_idx < size)
136 reg_cache[cache_idx].reg_value = value;
137 PMIC_RegSet(numid, value);
138#ifdef DEBUG_PMIC
139 LOGI(PMIC_Reset3, "%s: resets pianosa register 0x%02x to value --> 0x%02x",
140 __FUNCTION__,
141 reg_cache_inorder[k].reg_index,
142 value);
143#endif
144 }
145}
146
147static void PMIC_GetTypeAndID(int *type, unsigned char *id){
148 LOGI(PMIC_GetTypeAndID, "%s: Get type and ID for pianosa component", __FUNCTION__);
149 *type = COMPONENT_TYPE_POWER;
150 PMIC_RegGet(PIANOSA_ID_REG, id);
151}
152
153static ACH_ReturnCode PMIC_Handle(void *setting) {
154 ACH_ComponentParameter *param = (ACH_ComponentParameter *)setting;
155 unsigned short i = 0;
156 unsigned char numid, value, cache_idx;
157
158 if (param && param->i2c.reg_value) {
159 numid = PMIC_GetRegNumId(param->i2c.reg_index);
160 if (numid > 0) {
161 //compare with register cache
162 cache_idx = numid - codec_reg_num;
163 value = (reg_cache[cache_idx].reg_value & ~param->i2c.reg_mask) | (*param->i2c.reg_value);
164 if ((reg_cache[cache_idx].reg_value & param->i2c.reg_mask) != (*param->i2c.reg_value)) {
165#ifdef DEBUG_PMIC
166 LOGI(PMIC_Handle, "%s: set register 0x%02x [0x%02x --> 0x%02x]",
167 __FUNCTION__,
168 param->i2c.reg_index,
169 reg_cache[cache_idx].reg_value,
170 value);
171#endif
172 reg_cache[cache_idx].reg_value = value;
173 PMIC_RegSet(numid, reg_cache[cache_idx].reg_value);
174 } else {
175#ifdef DEBUG_PMIC
176 LOGI(PMIC_Handle1, "%s: set register 0x%02x [0x%02x --> 0x%02x] (unchanged)",
177 __FUNCTION__,
178 param->i2c.reg_index,
179 reg_cache[cache_idx].reg_value,
180 reg_cache[cache_idx].reg_value);
181#endif
182 }
183 }
184 }
185
186 return ACH_RC_OK;
187}