Joonwoo Park | 11133b8 | 2013-01-03 17:26:38 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/firmware.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/device.h> |
| 18 | #include <linux/printk.h> |
| 19 | #include <linux/ratelimit.h> |
| 20 | #include <linux/debugfs.h> |
| 21 | #include <linux/mfd/wcd9xxx/core.h> |
| 22 | #include <linux/mfd/wcd9xxx/wcd9xxx_registers.h> |
| 23 | #include <linux/mfd/wcd9xxx/wcd9320_registers.h> |
| 24 | #include <linux/mfd/wcd9xxx/pdata.h> |
| 25 | #include <sound/pcm.h> |
| 26 | #include <sound/pcm_params.h> |
| 27 | #include <sound/soc.h> |
| 28 | #include <sound/soc-dapm.h> |
| 29 | #include <sound/tlv.h> |
| 30 | #include <linux/bitops.h> |
| 31 | #include <linux/delay.h> |
| 32 | #include <linux/pm_runtime.h> |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/gpio.h> |
| 35 | #include "wcd9xxx-resmgr.h" |
| 36 | |
| 37 | static char wcd9xxx_event_string[][64] = { |
| 38 | "WCD9XXX_EVENT_INVALID", |
| 39 | |
| 40 | "WCD9XXX_EVENT_PRE_RCO_ON", |
| 41 | "WCD9XXX_EVENT_POST_RCO_ON", |
| 42 | "WCD9XXX_EVENT_PRE_RCO_OFF", |
| 43 | "WCD9XXX_EVENT_POST_RCO_OFF", |
| 44 | |
| 45 | "WCD9XXX_EVENT_PRE_MCLK_ON", |
| 46 | "WCD9XXX_EVENT_POST_MCLK_ON", |
| 47 | "WCD9XXX_EVENT_PRE_MCLK_OFF", |
| 48 | "WCD9XXX_EVENT_POST_MCLK_OFF", |
| 49 | |
| 50 | "WCD9XXX_EVENT_PRE_BG_OFF", |
| 51 | "WCD9XXX_EVENT_POST_BG_OFF", |
| 52 | "WCD9XXX_EVENT_PRE_BG_AUDIO_ON", |
| 53 | "WCD9XXX_EVENT_POST_BG_AUDIO_ON", |
| 54 | "WCD9XXX_EVENT_PRE_BG_MBHC_ON", |
| 55 | "WCD9XXX_EVENT_POST_BG_MBHC_ON", |
| 56 | |
| 57 | "WCD9XXX_EVENT_PRE_MICBIAS_1_OFF", |
| 58 | "WCD9XXX_EVENT_POST_MICBIAS_1_OFF", |
| 59 | "WCD9XXX_EVENT_PRE_MICBIAS_2_OFF", |
| 60 | "WCD9XXX_EVENT_POST_MICBIAS_2_OFF", |
| 61 | "WCD9XXX_EVENT_PRE_MICBIAS_3_OFF", |
| 62 | "WCD9XXX_EVENT_POST_MICBIAS_3_OFF", |
| 63 | "WCD9XXX_EVENT_PRE_MICBIAS_4_OFF", |
| 64 | "WCD9XXX_EVENT_POST_MICBIAS_4_OFF", |
| 65 | "WCD9XXX_EVENT_PRE_MICBIAS_1_ON", |
| 66 | "WCD9XXX_EVENT_POST_MICBIAS_1_ON", |
| 67 | "WCD9XXX_EVENT_PRE_MICBIAS_2_ON", |
| 68 | "WCD9XXX_EVENT_POST_MICBIAS_2_ON", |
| 69 | "WCD9XXX_EVENT_PRE_MICBIAS_3_ON", |
| 70 | "WCD9XXX_EVENT_POST_MICBIAS_3_ON", |
| 71 | "WCD9XXX_EVENT_PRE_MICBIAS_4_ON", |
| 72 | "WCD9XXX_EVENT_POST_MICBIAS_4_ON", |
| 73 | |
| 74 | "WCD9XXX_EVENT_PRE_CFILT_1_OFF", |
| 75 | "WCD9XXX_EVENT_POST_CFILT_1_OFF", |
| 76 | "WCD9XXX_EVENT_PRE_CFILT_2_OFF", |
| 77 | "WCD9XXX_EVENT_POST_CFILT_2_OFF", |
| 78 | "WCD9XXX_EVENT_PRE_CFILT_3_OFF", |
| 79 | "WCD9XXX_EVENT_POST_CFILT_3_OFF", |
| 80 | "WCD9XXX_EVENT_PRE_CFILT_1_ON", |
| 81 | "WCD9XXX_EVENT_POST_CFILT_1_ON", |
| 82 | "WCD9XXX_EVENT_PRE_CFILT_2_ON", |
| 83 | "WCD9XXX_EVENT_POST_CFILT_2_ON", |
| 84 | "WCD9XXX_EVENT_PRE_CFILT_3_ON", |
| 85 | "WCD9XXX_EVENT_POST_CFILT_3_ON", |
| 86 | |
| 87 | "WCD9XXX_EVENT_PRE_HPHL_PA_ON", |
| 88 | "WCD9XXX_EVENT_POST_HPHL_PA_OFF", |
| 89 | "WCD9XXX_EVENT_PRE_HPHR_PA_ON", |
| 90 | "WCD9XXX_EVENT_POST_HPHR_PA_OFF", |
| 91 | |
| 92 | "WCD9XXX_EVENT_POST_RESUME", |
| 93 | |
| 94 | "WCD9XXX_EVENT_LAST", |
| 95 | }; |
| 96 | |
Joonwoo Park | cc52d47 | 2013-01-28 10:10:12 -0800 | [diff] [blame] | 97 | struct wcd9xxx_resmgr_cond_entry { |
| 98 | unsigned short reg; |
| 99 | int shift; |
| 100 | bool invert; |
| 101 | enum wcd9xxx_resmgr_cond cond; |
| 102 | struct list_head list; |
| 103 | }; |
| 104 | |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 105 | static enum wcd9xxx_clock_type wcd9xxx_save_clock(struct wcd9xxx_resmgr |
| 106 | *resmgr); |
| 107 | static void wcd9xxx_restore_clock(struct wcd9xxx_resmgr *resmgr, |
| 108 | enum wcd9xxx_clock_type type); |
| 109 | |
| 110 | const char *wcd9xxx_get_event_string(enum wcd9xxx_notify_event type) |
| 111 | { |
| 112 | return wcd9xxx_event_string[type]; |
| 113 | } |
| 114 | |
| 115 | void wcd9xxx_resmgr_notifier_call(struct wcd9xxx_resmgr *resmgr, |
| 116 | const enum wcd9xxx_notify_event e) |
| 117 | { |
| 118 | pr_debug("%s: notifier call event %d\n", __func__, e); |
| 119 | blocking_notifier_call_chain(&resmgr->notifier, e, resmgr); |
| 120 | } |
| 121 | |
Joonwoo Park | d87ec4c | 2012-10-30 15:44:18 -0700 | [diff] [blame] | 122 | static void wcd9xxx_disable_bg(struct wcd9xxx_resmgr *resmgr) |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 123 | { |
| 124 | /* Notify bg mode change */ |
| 125 | wcd9xxx_resmgr_notifier_call(resmgr, WCD9XXX_EVENT_PRE_BG_OFF); |
| 126 | /* Disable bg */ |
Joonwoo Park | 11133b8 | 2013-01-03 17:26:38 -0800 | [diff] [blame] | 127 | snd_soc_update_bits(resmgr->codec, WCD9XXX_A_BIAS_CENTRAL_BG_CTL, |
| 128 | 0x03, 0x00); |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 129 | usleep_range(100, 100); |
| 130 | /* Notify bg mode change */ |
| 131 | wcd9xxx_resmgr_notifier_call(resmgr, WCD9XXX_EVENT_POST_BG_OFF); |
| 132 | } |
| 133 | |
Joonwoo Park | d87ec4c | 2012-10-30 15:44:18 -0700 | [diff] [blame] | 134 | /* |
| 135 | * BG enablement should always enable in slow mode. |
| 136 | * The fast mode doesn't need to be enabled as fast mode BG is to be driven |
| 137 | * by MBHC override. |
| 138 | */ |
| 139 | static void wcd9xxx_enable_bg(struct wcd9xxx_resmgr *resmgr) |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 140 | { |
| 141 | struct snd_soc_codec *codec = resmgr->codec; |
| 142 | |
Joonwoo Park | d87ec4c | 2012-10-30 15:44:18 -0700 | [diff] [blame] | 143 | /* Enable BG in slow mode and precharge */ |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 144 | snd_soc_update_bits(codec, WCD9XXX_A_BIAS_CENTRAL_BG_CTL, 0x80, 0x80); |
| 145 | snd_soc_update_bits(codec, WCD9XXX_A_BIAS_CENTRAL_BG_CTL, 0x04, 0x04); |
| 146 | snd_soc_update_bits(codec, WCD9XXX_A_BIAS_CENTRAL_BG_CTL, 0x01, 0x01); |
| 147 | usleep_range(1000, 1000); |
| 148 | snd_soc_update_bits(codec, WCD9XXX_A_BIAS_CENTRAL_BG_CTL, 0x80, 0x00); |
Joonwoo Park | d87ec4c | 2012-10-30 15:44:18 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static void wcd9xxx_enable_bg_audio(struct wcd9xxx_resmgr *resmgr) |
| 152 | { |
| 153 | /* Notify bandgap mode change */ |
| 154 | wcd9xxx_resmgr_notifier_call(resmgr, WCD9XXX_EVENT_PRE_BG_AUDIO_ON); |
| 155 | wcd9xxx_enable_bg(resmgr); |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 156 | /* Notify bandgap mode change */ |
| 157 | wcd9xxx_resmgr_notifier_call(resmgr, WCD9XXX_EVENT_POST_BG_AUDIO_ON); |
| 158 | } |
| 159 | |
| 160 | static void wcd9xxx_enable_bg_mbhc(struct wcd9xxx_resmgr *resmgr) |
| 161 | { |
| 162 | struct snd_soc_codec *codec = resmgr->codec; |
| 163 | |
| 164 | /* Notify bandgap mode change */ |
| 165 | wcd9xxx_resmgr_notifier_call(resmgr, WCD9XXX_EVENT_PRE_BG_MBHC_ON); |
| 166 | |
| 167 | /* |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 168 | * mclk should be off or clk buff source souldn't be VBG |
| 169 | * Let's turn off mclk always |
| 170 | */ |
| 171 | WARN_ON(snd_soc_read(codec, WCD9XXX_A_CLK_BUFF_EN2) & (1 << 2)); |
Joonwoo Park | d87ec4c | 2012-10-30 15:44:18 -0700 | [diff] [blame] | 172 | wcd9xxx_enable_bg(resmgr); |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 173 | /* Notify bandgap mode change */ |
| 174 | wcd9xxx_resmgr_notifier_call(resmgr, WCD9XXX_EVENT_POST_BG_MBHC_ON); |
| 175 | } |
| 176 | |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 177 | static void wcd9xxx_disable_clock_block(struct wcd9xxx_resmgr *resmgr) |
| 178 | { |
| 179 | struct snd_soc_codec *codec = resmgr->codec; |
| 180 | |
| 181 | pr_debug("%s: enter\n", __func__); |
| 182 | WCD9XXX_BCL_ASSERT_LOCKED(resmgr); |
| 183 | |
| 184 | /* Notify */ |
| 185 | if (resmgr->clk_type == WCD9XXX_CLK_RCO) |
| 186 | wcd9xxx_resmgr_notifier_call(resmgr, WCD9XXX_EVENT_PRE_RCO_OFF); |
| 187 | else |
| 188 | wcd9xxx_resmgr_notifier_call(resmgr, |
| 189 | WCD9XXX_EVENT_PRE_MCLK_OFF); |
| 190 | /* Disable clock */ |
| 191 | snd_soc_update_bits(codec, WCD9XXX_A_CLK_BUFF_EN2, 0x04, 0x00); |
| 192 | usleep_range(50, 50); |
| 193 | snd_soc_update_bits(codec, WCD9XXX_A_CLK_BUFF_EN2, 0x02, 0x02); |
| 194 | snd_soc_update_bits(codec, WCD9XXX_A_CLK_BUFF_EN1, 0x05, 0x00); |
| 195 | usleep_range(50, 50); |
| 196 | /* Notify */ |
| 197 | if (resmgr->clk_type == WCD9XXX_CLK_RCO) |
| 198 | wcd9xxx_resmgr_notifier_call(resmgr, |
| 199 | WCD9XXX_EVENT_POST_RCO_OFF); |
| 200 | else |
| 201 | wcd9xxx_resmgr_notifier_call(resmgr, |
| 202 | WCD9XXX_EVENT_POST_MCLK_OFF); |
| 203 | pr_debug("%s: leave\n", __func__); |
| 204 | } |
| 205 | |
Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 206 | void wcd9xxx_resmgr_post_ssr(struct wcd9xxx_resmgr *resmgr) |
| 207 | { |
| 208 | int old_bg_audio_users, old_bg_mbhc_users; |
Ravishankar Sarawadi | 2293efe | 2013-01-11 16:37:23 -0800 | [diff] [blame] | 209 | int old_clk_rco_users, old_clk_mclk_users; |
Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 210 | |
Ravishankar Sarawadi | 2293efe | 2013-01-11 16:37:23 -0800 | [diff] [blame] | 211 | pr_debug("%s: enter\n", __func__); |
Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 212 | WCD9XXX_BCL_ASSERT_LOCKED(resmgr); |
| 213 | |
| 214 | old_bg_audio_users = resmgr->bg_audio_users; |
Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 215 | old_bg_mbhc_users = resmgr->bg_mbhc_users; |
Ravishankar Sarawadi | 2293efe | 2013-01-11 16:37:23 -0800 | [diff] [blame] | 216 | old_clk_rco_users = resmgr->clk_rco_users; |
| 217 | old_clk_mclk_users = resmgr->clk_mclk_users; |
| 218 | resmgr->bg_audio_users = 0; |
Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 219 | resmgr->bg_mbhc_users = 0; |
Ravishankar Sarawadi | 2293efe | 2013-01-11 16:37:23 -0800 | [diff] [blame] | 220 | resmgr->bandgap_type = WCD9XXX_BANDGAP_OFF; |
| 221 | resmgr->clk_rco_users = 0; |
| 222 | resmgr->clk_mclk_users = 0; |
| 223 | resmgr->clk_type = WCD9XXX_CLK_OFF; |
Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 224 | |
Ravishankar Sarawadi | 2293efe | 2013-01-11 16:37:23 -0800 | [diff] [blame] | 225 | if (old_bg_audio_users) { |
| 226 | while (old_bg_audio_users--) |
| 227 | wcd9xxx_resmgr_get_bandgap(resmgr, |
| 228 | WCD9XXX_BANDGAP_AUDIO_MODE); |
| 229 | } |
Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 230 | |
Ravishankar Sarawadi | 2293efe | 2013-01-11 16:37:23 -0800 | [diff] [blame] | 231 | if (old_bg_mbhc_users) { |
| 232 | while (old_bg_mbhc_users--) |
| 233 | wcd9xxx_resmgr_get_bandgap(resmgr, |
| 234 | WCD9XXX_BANDGAP_MBHC_MODE); |
| 235 | } |
| 236 | |
| 237 | if (old_clk_mclk_users) { |
| 238 | while (old_clk_mclk_users--) |
| 239 | wcd9xxx_resmgr_get_clk_block(resmgr, WCD9XXX_CLK_MCLK); |
| 240 | } |
| 241 | |
| 242 | if (old_clk_rco_users) { |
| 243 | while (old_clk_rco_users--) |
| 244 | wcd9xxx_resmgr_get_clk_block(resmgr, WCD9XXX_CLK_RCO); |
| 245 | } |
| 246 | pr_debug("%s: leave\n", __func__); |
Ravishankar Sarawadi | 839fcf3 | 2012-11-14 12:13:00 -0800 | [diff] [blame] | 247 | } |
| 248 | |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 249 | /* |
| 250 | * wcd9xxx_resmgr_get_bandgap : Vote for bandgap ref |
| 251 | * choice : WCD9XXX_BANDGAP_AUDIO_MODE, WCD9XXX_BANDGAP_MBHC_MODE |
| 252 | */ |
| 253 | void wcd9xxx_resmgr_get_bandgap(struct wcd9xxx_resmgr *resmgr, |
| 254 | const enum wcd9xxx_bandgap_type choice) |
| 255 | { |
| 256 | enum wcd9xxx_clock_type clock_save; |
| 257 | |
| 258 | pr_debug("%s: enter, wants %d\n", __func__, choice); |
| 259 | |
| 260 | WCD9XXX_BCL_ASSERT_LOCKED(resmgr); |
| 261 | switch (choice) { |
| 262 | case WCD9XXX_BANDGAP_AUDIO_MODE: |
| 263 | resmgr->bg_audio_users++; |
| 264 | if (resmgr->bg_audio_users == 1 && resmgr->bg_mbhc_users) { |
| 265 | /* |
| 266 | * Current bg is MBHC mode, about to switch to |
| 267 | * audio mode. |
| 268 | */ |
| 269 | WARN_ON(resmgr->bandgap_type != |
| 270 | WCD9XXX_BANDGAP_MBHC_MODE); |
| 271 | |
| 272 | /* BG mode can be changed only with clock off */ |
| 273 | clock_save = wcd9xxx_save_clock(resmgr); |
| 274 | /* Swtich BG mode */ |
Joonwoo Park | d87ec4c | 2012-10-30 15:44:18 -0700 | [diff] [blame] | 275 | wcd9xxx_disable_bg(resmgr); |
| 276 | wcd9xxx_enable_bg_audio(resmgr); |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 277 | /* restore clock */ |
| 278 | wcd9xxx_restore_clock(resmgr, clock_save); |
| 279 | } else if (resmgr->bg_audio_users == 1) { |
| 280 | /* currently off, just enable it */ |
| 281 | WARN_ON(resmgr->bandgap_type != WCD9XXX_BANDGAP_OFF); |
Joonwoo Park | d87ec4c | 2012-10-30 15:44:18 -0700 | [diff] [blame] | 282 | wcd9xxx_enable_bg_audio(resmgr); |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 283 | } |
| 284 | resmgr->bandgap_type = WCD9XXX_BANDGAP_AUDIO_MODE; |
| 285 | break; |
| 286 | case WCD9XXX_BANDGAP_MBHC_MODE: |
| 287 | resmgr->bg_mbhc_users++; |
| 288 | if (resmgr->bandgap_type == WCD9XXX_BANDGAP_MBHC_MODE || |
| 289 | resmgr->bandgap_type == WCD9XXX_BANDGAP_AUDIO_MODE) |
| 290 | /* do nothing */ |
| 291 | break; |
| 292 | |
| 293 | /* bg mode can be changed only with clock off */ |
| 294 | clock_save = wcd9xxx_save_clock(resmgr); |
| 295 | /* enable bg with MBHC mode */ |
| 296 | wcd9xxx_enable_bg_mbhc(resmgr); |
| 297 | /* restore clock */ |
| 298 | wcd9xxx_restore_clock(resmgr, clock_save); |
| 299 | /* save current mode */ |
| 300 | resmgr->bandgap_type = WCD9XXX_BANDGAP_MBHC_MODE; |
| 301 | break; |
| 302 | default: |
| 303 | pr_err("%s: Error, Invalid bandgap settings\n", __func__); |
| 304 | break; |
| 305 | } |
| 306 | |
| 307 | pr_debug("%s: bg users audio %d, mbhc %d\n", __func__, |
| 308 | resmgr->bg_audio_users, resmgr->bg_mbhc_users); |
| 309 | } |
| 310 | |
| 311 | /* |
| 312 | * wcd9xxx_resmgr_put_bandgap : Unvote bandgap ref that has been voted |
| 313 | * choice : WCD9XXX_BANDGAP_AUDIO_MODE, WCD9XXX_BANDGAP_MBHC_MODE |
| 314 | */ |
| 315 | void wcd9xxx_resmgr_put_bandgap(struct wcd9xxx_resmgr *resmgr, |
| 316 | enum wcd9xxx_bandgap_type choice) |
| 317 | { |
| 318 | enum wcd9xxx_clock_type clock_save; |
| 319 | |
| 320 | pr_debug("%s: enter choice %d\n", __func__, choice); |
| 321 | |
| 322 | WCD9XXX_BCL_ASSERT_LOCKED(resmgr); |
| 323 | switch (choice) { |
| 324 | case WCD9XXX_BANDGAP_AUDIO_MODE: |
| 325 | if (--resmgr->bg_audio_users == 0) { |
| 326 | if (resmgr->bg_mbhc_users) { |
| 327 | /* bg mode can be changed only with clock off */ |
| 328 | clock_save = wcd9xxx_save_clock(resmgr); |
| 329 | /* switch to MBHC mode */ |
| 330 | wcd9xxx_enable_bg_mbhc(resmgr); |
| 331 | /* restore clock */ |
| 332 | wcd9xxx_restore_clock(resmgr, clock_save); |
| 333 | resmgr->bandgap_type = |
| 334 | WCD9XXX_BANDGAP_MBHC_MODE; |
| 335 | } else { |
| 336 | /* turn off */ |
| 337 | wcd9xxx_disable_bg(resmgr); |
| 338 | resmgr->bandgap_type = WCD9XXX_BANDGAP_OFF; |
| 339 | } |
| 340 | } |
| 341 | break; |
| 342 | case WCD9XXX_BANDGAP_MBHC_MODE: |
| 343 | WARN(resmgr->bandgap_type == WCD9XXX_BANDGAP_OFF, |
| 344 | "Unexpected bandgap type %d\n", resmgr->bandgap_type); |
| 345 | if (--resmgr->bg_mbhc_users == 0 && |
| 346 | resmgr->bandgap_type == WCD9XXX_BANDGAP_MBHC_MODE) { |
| 347 | wcd9xxx_disable_bg(resmgr); |
| 348 | resmgr->bandgap_type = WCD9XXX_BANDGAP_OFF; |
| 349 | } |
| 350 | break; |
| 351 | default: |
| 352 | pr_err("%s: Error, Invalid bandgap settings\n", __func__); |
| 353 | break; |
| 354 | } |
| 355 | |
| 356 | pr_debug("%s: bg users audio %d, mbhc %d\n", __func__, |
| 357 | resmgr->bg_audio_users, resmgr->bg_mbhc_users); |
| 358 | } |
| 359 | |
| 360 | void wcd9xxx_resmgr_enable_rx_bias(struct wcd9xxx_resmgr *resmgr, u32 enable) |
| 361 | { |
| 362 | struct snd_soc_codec *codec = resmgr->codec; |
| 363 | |
| 364 | if (enable) { |
| 365 | resmgr->rx_bias_count++; |
| 366 | if (resmgr->rx_bias_count == 1) |
| 367 | snd_soc_update_bits(codec, WCD9XXX_A_RX_COM_BIAS, |
| 368 | 0x80, 0x80); |
| 369 | } else { |
| 370 | resmgr->rx_bias_count--; |
| 371 | if (!resmgr->rx_bias_count) |
| 372 | snd_soc_update_bits(codec, WCD9XXX_A_RX_COM_BIAS, |
| 373 | 0x80, 0x00); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | int wcd9xxx_resmgr_enable_config_mode(struct snd_soc_codec *codec, int enable) |
| 378 | { |
| 379 | pr_debug("%s: enable = %d\n", __func__, enable); |
| 380 | if (enable) { |
| 381 | snd_soc_update_bits(codec, WCD9XXX_A_RC_OSC_FREQ, 0x10, 0); |
| 382 | /* bandgap mode to fast */ |
| 383 | snd_soc_write(codec, WCD9XXX_A_BIAS_OSC_BG_CTL, 0x17); |
| 384 | usleep_range(5, 5); |
| 385 | snd_soc_update_bits(codec, WCD9XXX_A_RC_OSC_FREQ, 0x80, 0x80); |
| 386 | snd_soc_update_bits(codec, WCD9XXX_A_RC_OSC_TEST, 0x80, 0x80); |
| 387 | usleep_range(10, 10); |
| 388 | snd_soc_update_bits(codec, WCD9XXX_A_RC_OSC_TEST, 0x80, 0); |
| 389 | usleep_range(10000, 10000); |
| 390 | snd_soc_update_bits(codec, WCD9XXX_A_CLK_BUFF_EN1, 0x08, 0x08); |
| 391 | } else { |
| 392 | snd_soc_update_bits(codec, WCD9XXX_A_BIAS_OSC_BG_CTL, 0x1, 0); |
| 393 | snd_soc_update_bits(codec, WCD9XXX_A_RC_OSC_FREQ, 0x80, 0); |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | static void wcd9xxx_enable_clock_block(struct wcd9xxx_resmgr *resmgr, |
| 400 | int config_mode) |
| 401 | { |
| 402 | struct snd_soc_codec *codec = resmgr->codec; |
| 403 | |
| 404 | pr_debug("%s: config_mode = %d\n", __func__, config_mode); |
| 405 | /* transit to RCO requires mclk off */ |
| 406 | WARN_ON(snd_soc_read(codec, WCD9XXX_A_CLK_BUFF_EN2) & (1 << 2)); |
| 407 | if (config_mode) { |
| 408 | /* Notify */ |
| 409 | wcd9xxx_resmgr_notifier_call(resmgr, WCD9XXX_EVENT_PRE_RCO_ON); |
| 410 | /* enable RCO and switch to it */ |
| 411 | wcd9xxx_resmgr_enable_config_mode(codec, 1); |
| 412 | snd_soc_write(codec, WCD9XXX_A_CLK_BUFF_EN2, 0x02); |
| 413 | usleep_range(1000, 1000); |
| 414 | } else { |
| 415 | /* Notify */ |
| 416 | wcd9xxx_resmgr_notifier_call(resmgr, WCD9XXX_EVENT_PRE_MCLK_ON); |
| 417 | /* switch to MCLK */ |
| 418 | snd_soc_update_bits(codec, WCD9XXX_A_CLK_BUFF_EN1, 0x08, 0x00); |
| 419 | /* if RCO is enabled, switch from it */ |
| 420 | if (snd_soc_read(codec, WCD9XXX_A_RC_OSC_FREQ) & 0x80) { |
| 421 | snd_soc_write(codec, WCD9XXX_A_CLK_BUFF_EN2, 0x02); |
| 422 | wcd9xxx_resmgr_enable_config_mode(codec, 0); |
| 423 | } |
Bhalchandra Gajare | 2725930 | 2013-03-28 16:56:59 -0700 | [diff] [blame] | 424 | /* clk source to ext clk and clk buff ref to VBG */ |
| 425 | snd_soc_update_bits(codec, WCD9XXX_A_CLK_BUFF_EN1, 0x0C, 0x04); |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | snd_soc_update_bits(codec, WCD9XXX_A_CLK_BUFF_EN1, 0x01, 0x01); |
Bhalchandra Gajare | 2725930 | 2013-03-28 16:56:59 -0700 | [diff] [blame] | 429 | /* sleep time required by codec hardware to enable clock buffer */ |
| 430 | usleep_range(1000, 1200); |
| 431 | |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 432 | snd_soc_update_bits(codec, WCD9XXX_A_CLK_BUFF_EN2, 0x02, 0x00); |
| 433 | |
| 434 | /* on MCLK */ |
| 435 | snd_soc_update_bits(codec, WCD9XXX_A_CLK_BUFF_EN2, 0x04, 0x04); |
| 436 | snd_soc_update_bits(codec, WCD9XXX_A_CDC_CLK_MCLK_CTL, 0x01, 0x01); |
| 437 | usleep_range(50, 50); |
| 438 | |
| 439 | /* Notify */ |
| 440 | if (config_mode) |
| 441 | wcd9xxx_resmgr_notifier_call(resmgr, |
| 442 | WCD9XXX_EVENT_POST_RCO_ON); |
| 443 | else |
| 444 | wcd9xxx_resmgr_notifier_call(resmgr, |
| 445 | WCD9XXX_EVENT_POST_MCLK_ON); |
| 446 | } |
| 447 | |
| 448 | /* |
| 449 | * disable clock and return previous clock state |
| 450 | */ |
| 451 | static enum wcd9xxx_clock_type wcd9xxx_save_clock(struct wcd9xxx_resmgr *resmgr) |
| 452 | { |
| 453 | WCD9XXX_BCL_ASSERT_LOCKED(resmgr); |
| 454 | if (resmgr->clk_type != WCD9XXX_CLK_OFF) |
| 455 | wcd9xxx_disable_clock_block(resmgr); |
| 456 | return resmgr->clk_type != WCD9XXX_CLK_OFF; |
| 457 | } |
| 458 | |
| 459 | static void wcd9xxx_restore_clock(struct wcd9xxx_resmgr *resmgr, |
| 460 | enum wcd9xxx_clock_type type) |
| 461 | { |
| 462 | if (type != WCD9XXX_CLK_OFF) |
| 463 | wcd9xxx_enable_clock_block(resmgr, type == WCD9XXX_CLK_RCO); |
| 464 | } |
| 465 | |
| 466 | void wcd9xxx_resmgr_get_clk_block(struct wcd9xxx_resmgr *resmgr, |
| 467 | enum wcd9xxx_clock_type type) |
| 468 | { |
| 469 | pr_debug("%s: current %d, requested %d, rco_users %d, mclk_users %d\n", |
| 470 | __func__, resmgr->clk_type, type, |
| 471 | resmgr->clk_rco_users, resmgr->clk_mclk_users); |
| 472 | WCD9XXX_BCL_ASSERT_LOCKED(resmgr); |
| 473 | switch (type) { |
| 474 | case WCD9XXX_CLK_RCO: |
| 475 | if (++resmgr->clk_rco_users == 1 && |
| 476 | resmgr->clk_type == WCD9XXX_CLK_OFF) { |
| 477 | /* enable RCO and switch to it */ |
| 478 | wcd9xxx_enable_clock_block(resmgr, 1); |
| 479 | resmgr->clk_type = WCD9XXX_CLK_RCO; |
| 480 | } |
| 481 | break; |
| 482 | case WCD9XXX_CLK_MCLK: |
| 483 | if (++resmgr->clk_mclk_users == 1 && |
| 484 | resmgr->clk_type == WCD9XXX_CLK_OFF) { |
| 485 | /* switch to MCLK */ |
| 486 | wcd9xxx_enable_clock_block(resmgr, 0); |
| 487 | resmgr->clk_type = WCD9XXX_CLK_MCLK; |
| 488 | } else if (resmgr->clk_mclk_users == 1 && |
| 489 | resmgr->clk_type == WCD9XXX_CLK_RCO) { |
| 490 | /* if RCO is enabled, switch from it */ |
| 491 | WARN_ON(!(snd_soc_read(resmgr->codec, |
| 492 | WCD9XXX_A_RC_OSC_FREQ) & 0x80)); |
| 493 | /* disable clock block */ |
| 494 | wcd9xxx_disable_clock_block(resmgr); |
| 495 | /* switch to RCO */ |
| 496 | wcd9xxx_enable_clock_block(resmgr, 0); |
| 497 | resmgr->clk_type = WCD9XXX_CLK_MCLK; |
| 498 | } |
| 499 | break; |
| 500 | default: |
| 501 | pr_err("%s: Error, Invalid clock get request %d\n", __func__, |
| 502 | type); |
| 503 | break; |
| 504 | } |
| 505 | pr_debug("%s: leave\n", __func__); |
| 506 | } |
| 507 | |
| 508 | void wcd9xxx_resmgr_put_clk_block(struct wcd9xxx_resmgr *resmgr, |
| 509 | enum wcd9xxx_clock_type type) |
| 510 | { |
| 511 | pr_debug("%s: current %d, put %d\n", __func__, resmgr->clk_type, type); |
| 512 | |
| 513 | WCD9XXX_BCL_ASSERT_LOCKED(resmgr); |
| 514 | switch (type) { |
| 515 | case WCD9XXX_CLK_RCO: |
| 516 | if (--resmgr->clk_rco_users == 0 && |
| 517 | resmgr->clk_type == WCD9XXX_CLK_RCO) { |
| 518 | wcd9xxx_disable_clock_block(resmgr); |
| 519 | resmgr->clk_type = WCD9XXX_CLK_OFF; |
| 520 | } |
| 521 | break; |
| 522 | case WCD9XXX_CLK_MCLK: |
| 523 | if (--resmgr->clk_mclk_users == 0 && |
| 524 | resmgr->clk_rco_users == 0) { |
| 525 | wcd9xxx_disable_clock_block(resmgr); |
| 526 | resmgr->clk_type = WCD9XXX_CLK_OFF; |
| 527 | } else if (resmgr->clk_mclk_users == 0 && |
| 528 | resmgr->clk_rco_users) { |
| 529 | /* disable clock */ |
| 530 | wcd9xxx_disable_clock_block(resmgr); |
| 531 | /* switch to RCO */ |
| 532 | wcd9xxx_enable_clock_block(resmgr, 1); |
| 533 | resmgr->clk_type = WCD9XXX_CLK_RCO; |
| 534 | } |
| 535 | break; |
| 536 | default: |
| 537 | pr_err("%s: Error, Invalid clock get request %d\n", __func__, |
| 538 | type); |
| 539 | break; |
| 540 | } |
| 541 | WARN_ON(resmgr->clk_rco_users < 0); |
| 542 | WARN_ON(resmgr->clk_mclk_users < 0); |
| 543 | |
| 544 | pr_debug("%s: new rco_users %d, mclk_users %d\n", __func__, |
| 545 | resmgr->clk_rco_users, resmgr->clk_mclk_users); |
| 546 | } |
| 547 | |
| 548 | static void wcd9xxx_resmgr_update_cfilt_usage(struct wcd9xxx_resmgr *resmgr, |
| 549 | enum wcd9xxx_cfilt_sel cfilt_sel, |
| 550 | bool inc) |
| 551 | { |
| 552 | u16 micb_cfilt_reg; |
| 553 | enum wcd9xxx_notify_event e_pre_on, e_post_off; |
| 554 | struct snd_soc_codec *codec = resmgr->codec; |
| 555 | |
| 556 | switch (cfilt_sel) { |
| 557 | case WCD9XXX_CFILT1_SEL: |
| 558 | micb_cfilt_reg = WCD9XXX_A_MICB_CFILT_1_CTL; |
| 559 | e_pre_on = WCD9XXX_EVENT_PRE_CFILT_1_ON; |
| 560 | e_post_off = WCD9XXX_EVENT_POST_CFILT_1_OFF; |
| 561 | break; |
| 562 | case WCD9XXX_CFILT2_SEL: |
| 563 | micb_cfilt_reg = WCD9XXX_A_MICB_CFILT_2_CTL; |
| 564 | e_pre_on = WCD9XXX_EVENT_PRE_CFILT_2_ON; |
| 565 | e_post_off = WCD9XXX_EVENT_POST_CFILT_2_OFF; |
| 566 | break; |
| 567 | case WCD9XXX_CFILT3_SEL: |
| 568 | micb_cfilt_reg = WCD9XXX_A_MICB_CFILT_3_CTL; |
| 569 | e_pre_on = WCD9XXX_EVENT_PRE_CFILT_3_ON; |
| 570 | e_post_off = WCD9XXX_EVENT_POST_CFILT_3_OFF; |
| 571 | break; |
| 572 | default: |
| 573 | WARN(1, "Invalid CFILT selection %d\n", cfilt_sel); |
| 574 | return; /* should not happen */ |
| 575 | } |
| 576 | |
| 577 | if (inc) { |
| 578 | if ((resmgr->cfilt_users[cfilt_sel]++) == 0) { |
| 579 | /* Notify */ |
| 580 | wcd9xxx_resmgr_notifier_call(resmgr, e_pre_on); |
| 581 | /* Enable CFILT */ |
| 582 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0x80); |
| 583 | } |
| 584 | } else { |
| 585 | /* |
| 586 | * Check if count not zero, decrease |
| 587 | * then check if zero, go ahead disable cfilter |
| 588 | */ |
| 589 | WARN(resmgr->cfilt_users[cfilt_sel] == 0, |
| 590 | "Invalid CFILT use count 0\n"); |
| 591 | if ((--resmgr->cfilt_users[cfilt_sel]) == 0) { |
| 592 | /* Disable CFILT */ |
| 593 | snd_soc_update_bits(codec, micb_cfilt_reg, 0x80, 0); |
| 594 | /* Notify MBHC so MBHC can switch CFILT to fast mode */ |
| 595 | wcd9xxx_resmgr_notifier_call(resmgr, e_post_off); |
| 596 | } |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | void wcd9xxx_resmgr_cfilt_get(struct wcd9xxx_resmgr *resmgr, |
| 601 | enum wcd9xxx_cfilt_sel cfilt_sel) |
| 602 | { |
| 603 | return wcd9xxx_resmgr_update_cfilt_usage(resmgr, cfilt_sel, true); |
| 604 | } |
| 605 | |
| 606 | void wcd9xxx_resmgr_cfilt_put(struct wcd9xxx_resmgr *resmgr, |
| 607 | enum wcd9xxx_cfilt_sel cfilt_sel) |
| 608 | { |
| 609 | return wcd9xxx_resmgr_update_cfilt_usage(resmgr, cfilt_sel, false); |
| 610 | } |
| 611 | |
| 612 | int wcd9xxx_resmgr_get_k_val(struct wcd9xxx_resmgr *resmgr, |
| 613 | unsigned int cfilt_mv) |
| 614 | { |
| 615 | int rc = -EINVAL; |
| 616 | unsigned int ldoh_v = resmgr->pdata->micbias.ldoh_v; |
| 617 | unsigned min_mv, max_mv; |
| 618 | |
| 619 | switch (ldoh_v) { |
| 620 | case WCD9XXX_LDOH_1P95_V: |
| 621 | min_mv = 160; |
| 622 | max_mv = 1800; |
| 623 | break; |
| 624 | case WCD9XXX_LDOH_2P35_V: |
| 625 | min_mv = 200; |
| 626 | max_mv = 2200; |
| 627 | break; |
| 628 | case WCD9XXX_LDOH_2P75_V: |
| 629 | min_mv = 240; |
| 630 | max_mv = 2600; |
| 631 | break; |
| 632 | case WCD9XXX_LDOH_3P0_V: |
| 633 | min_mv = 260; |
| 634 | max_mv = 2875; |
| 635 | break; |
| 636 | default: |
| 637 | goto done; |
| 638 | } |
| 639 | |
| 640 | if (cfilt_mv < min_mv || cfilt_mv > max_mv) |
| 641 | goto done; |
| 642 | |
| 643 | for (rc = 4; rc <= 44; rc++) { |
| 644 | min_mv = max_mv * (rc) / 44; |
| 645 | if (min_mv >= cfilt_mv) { |
| 646 | rc -= 4; |
| 647 | break; |
| 648 | } |
| 649 | } |
| 650 | done: |
| 651 | return rc; |
| 652 | } |
| 653 | |
Joonwoo Park | cc52d47 | 2013-01-28 10:10:12 -0800 | [diff] [blame] | 654 | void wcd9xxx_resmgr_cond_trigger_cond(struct wcd9xxx_resmgr *resmgr, |
| 655 | enum wcd9xxx_resmgr_cond cond) |
| 656 | { |
| 657 | struct list_head *l; |
| 658 | struct wcd9xxx_resmgr_cond_entry *e; |
| 659 | bool set; |
| 660 | |
| 661 | pr_debug("%s: enter\n", __func__); |
| 662 | WCD9XXX_BCL_ASSERT_LOCKED(resmgr); |
| 663 | set = !!test_bit(cond, &resmgr->cond_flags); |
| 664 | list_for_each(l, &resmgr->update_bit_cond_h) { |
| 665 | e = list_entry(l, struct wcd9xxx_resmgr_cond_entry, list); |
| 666 | if (e->cond == cond) |
| 667 | snd_soc_update_bits(resmgr->codec, e->reg, |
| 668 | 1 << e->shift, |
| 669 | (set ? !e->invert : e->invert) |
| 670 | << e->shift); |
| 671 | } |
| 672 | pr_debug("%s: leave\n", __func__); |
| 673 | } |
| 674 | |
| 675 | void wcd9xxx_resmgr_cond_update_cond(struct wcd9xxx_resmgr *resmgr, |
| 676 | enum wcd9xxx_resmgr_cond cond, bool set) |
| 677 | { |
| 678 | WCD9XXX_BCL_ASSERT_LOCKED(resmgr); |
| 679 | if ((set && !test_and_set_bit(cond, &resmgr->cond_flags)) || |
| 680 | (!set && test_and_clear_bit(cond, &resmgr->cond_flags))) { |
| 681 | pr_debug("%s: Resource %d condition changed to %s\n", __func__, |
| 682 | cond, set ? "set" : "clear"); |
| 683 | wcd9xxx_resmgr_cond_trigger_cond(resmgr, cond); |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | int wcd9xxx_resmgr_add_cond_update_bits(struct wcd9xxx_resmgr *resmgr, |
| 688 | enum wcd9xxx_resmgr_cond cond, |
| 689 | unsigned short reg, int shift, |
| 690 | bool invert) |
| 691 | { |
| 692 | struct wcd9xxx_resmgr_cond_entry *entry; |
| 693 | |
Joonwoo Park | cc52d47 | 2013-01-28 10:10:12 -0800 | [diff] [blame] | 694 | entry = kmalloc(sizeof(*entry), GFP_KERNEL); |
| 695 | if (!entry) |
| 696 | return -ENOMEM; |
| 697 | |
| 698 | entry->cond = cond; |
| 699 | entry->reg = reg; |
| 700 | entry->shift = shift; |
| 701 | entry->invert = invert; |
Joonwoo Park | 3edb989 | 2013-03-05 17:44:54 -0800 | [diff] [blame] | 702 | |
| 703 | WCD9XXX_BCL_LOCK(resmgr); |
Joonwoo Park | cc52d47 | 2013-01-28 10:10:12 -0800 | [diff] [blame] | 704 | list_add_tail(&entry->list, &resmgr->update_bit_cond_h); |
| 705 | |
| 706 | wcd9xxx_resmgr_cond_trigger_cond(resmgr, cond); |
Joonwoo Park | 3edb989 | 2013-03-05 17:44:54 -0800 | [diff] [blame] | 707 | WCD9XXX_BCL_UNLOCK(resmgr); |
Joonwoo Park | cc52d47 | 2013-01-28 10:10:12 -0800 | [diff] [blame] | 708 | |
| 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | /* |
| 713 | * wcd9xxx_resmgr_rm_cond_update_bits : |
| 714 | * Clear bit and remove from the conditional bit update list |
| 715 | */ |
| 716 | int wcd9xxx_resmgr_rm_cond_update_bits(struct wcd9xxx_resmgr *resmgr, |
| 717 | enum wcd9xxx_resmgr_cond cond, |
| 718 | unsigned short reg, int shift, |
| 719 | bool invert) |
| 720 | { |
| 721 | struct list_head *l, *next; |
| 722 | struct wcd9xxx_resmgr_cond_entry *e = NULL; |
| 723 | |
| 724 | pr_debug("%s: enter\n", __func__); |
Joonwoo Park | 3edb989 | 2013-03-05 17:44:54 -0800 | [diff] [blame] | 725 | WCD9XXX_BCL_LOCK(resmgr); |
Joonwoo Park | cc52d47 | 2013-01-28 10:10:12 -0800 | [diff] [blame] | 726 | list_for_each_safe(l, next, &resmgr->update_bit_cond_h) { |
| 727 | e = list_entry(l, struct wcd9xxx_resmgr_cond_entry, list); |
| 728 | if (e->reg == reg && e->shift == shift && e->invert == invert) { |
| 729 | snd_soc_update_bits(resmgr->codec, e->reg, |
| 730 | 1 << e->shift, |
| 731 | e->invert << e->shift); |
| 732 | list_del(&e->list); |
Joonwoo Park | 3edb989 | 2013-03-05 17:44:54 -0800 | [diff] [blame] | 733 | WCD9XXX_BCL_UNLOCK(resmgr); |
Joonwoo Park | cc52d47 | 2013-01-28 10:10:12 -0800 | [diff] [blame] | 734 | kfree(e); |
| 735 | return 0; |
| 736 | } |
| 737 | } |
Joonwoo Park | 3edb989 | 2013-03-05 17:44:54 -0800 | [diff] [blame] | 738 | WCD9XXX_BCL_UNLOCK(resmgr); |
Joonwoo Park | cc52d47 | 2013-01-28 10:10:12 -0800 | [diff] [blame] | 739 | pr_err("%s: Cannot find update bit entry reg 0x%x, shift %d\n", |
| 740 | __func__, e ? e->reg : 0, e ? e->shift : 0); |
| 741 | |
| 742 | return -EINVAL; |
| 743 | } |
| 744 | |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 745 | int wcd9xxx_resmgr_register_notifier(struct wcd9xxx_resmgr *resmgr, |
| 746 | struct notifier_block *nblock) |
| 747 | { |
| 748 | return blocking_notifier_chain_register(&resmgr->notifier, nblock); |
| 749 | } |
| 750 | |
| 751 | int wcd9xxx_resmgr_unregister_notifier(struct wcd9xxx_resmgr *resmgr, |
| 752 | struct notifier_block *nblock) |
| 753 | { |
| 754 | return blocking_notifier_chain_unregister(&resmgr->notifier, nblock); |
| 755 | } |
| 756 | |
| 757 | int wcd9xxx_resmgr_init(struct wcd9xxx_resmgr *resmgr, |
| 758 | struct snd_soc_codec *codec, |
| 759 | struct wcd9xxx *wcd9xxx, |
| 760 | struct wcd9xxx_pdata *pdata, |
| 761 | struct wcd9xxx_reg_address *reg_addr) |
| 762 | { |
| 763 | WARN(ARRAY_SIZE(wcd9xxx_event_string) != WCD9XXX_EVENT_LAST + 1, |
| 764 | "Event string table isn't up to date!, %d != %d\n", |
| 765 | ARRAY_SIZE(wcd9xxx_event_string), WCD9XXX_EVENT_LAST + 1); |
| 766 | |
| 767 | resmgr->bandgap_type = WCD9XXX_BANDGAP_OFF; |
| 768 | resmgr->codec = codec; |
| 769 | /* This gives access of core handle to lock/unlock suspend */ |
| 770 | resmgr->core = wcd9xxx; |
| 771 | resmgr->pdata = pdata; |
| 772 | resmgr->reg_addr = reg_addr; |
| 773 | |
Joonwoo Park | cc52d47 | 2013-01-28 10:10:12 -0800 | [diff] [blame] | 774 | INIT_LIST_HEAD(&resmgr->update_bit_cond_h); |
| 775 | |
Joonwoo Park | a889026 | 2012-10-15 12:04:27 -0700 | [diff] [blame] | 776 | BLOCKING_INIT_NOTIFIER_HEAD(&resmgr->notifier); |
| 777 | |
| 778 | mutex_init(&resmgr->codec_resource_lock); |
| 779 | |
| 780 | return 0; |
| 781 | } |
| 782 | |
| 783 | void wcd9xxx_resmgr_deinit(struct wcd9xxx_resmgr *resmgr) |
| 784 | { |
| 785 | mutex_destroy(&resmgr->codec_resource_lock); |
| 786 | } |
| 787 | |
| 788 | void wcd9xxx_resmgr_bcl_lock(struct wcd9xxx_resmgr *resmgr) |
| 789 | { |
| 790 | mutex_lock(&resmgr->codec_resource_lock); |
| 791 | } |
| 792 | |
| 793 | void wcd9xxx_resmgr_bcl_unlock(struct wcd9xxx_resmgr *resmgr) |
| 794 | { |
| 795 | mutex_unlock(&resmgr->codec_resource_lock); |
| 796 | } |
| 797 | |
| 798 | MODULE_DESCRIPTION("wcd9xxx resmgr module"); |
| 799 | MODULE_LICENSE("GPL v2"); |