Lines Matching +full:comp +full:- +full:int

1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
3 // Copyright (c) 2017-2018, Linaro Limited
10 #include "wcd-clsh-v2.h"
13 int state;
14 int mode;
15 int flyback_users;
16 int buck_users;
17 int clsh_users;
18 int codec_version;
19 struct snd_soc_component *comp; member
22 /* Class-H registers for codecs from and above WCD9335 */
122 struct snd_soc_component *comp = ctrl->comp; in wcd_enable_clsh_block() local
124 if ((enable && ++ctrl->clsh_users == 1) || in wcd_enable_clsh_block()
125 (!enable && --ctrl->clsh_users == 0)) in wcd_enable_clsh_block()
126 snd_soc_component_update_bits(comp, WCD9XXX_A_CDC_CLSH_CRC, in wcd_enable_clsh_block()
129 if (ctrl->clsh_users < 0) in wcd_enable_clsh_block()
130 ctrl->clsh_users = 0; in wcd_enable_clsh_block()
133 static inline void wcd_clsh_set_buck_mode(struct snd_soc_component *comp, in wcd_clsh_set_buck_mode() argument
134 int mode) in wcd_clsh_set_buck_mode()
138 snd_soc_component_update_bits(comp, WCD9XXX_A_ANA_RX_SUPPLIES, in wcd_clsh_set_buck_mode()
142 snd_soc_component_update_bits(comp, WCD9XXX_A_ANA_RX_SUPPLIES, in wcd_clsh_set_buck_mode()
148 int mode) in wcd_clsh_v3_set_buck_mode()
161 static inline void wcd_clsh_set_flyback_mode(struct snd_soc_component *comp, in wcd_clsh_set_flyback_mode() argument
162 int mode) in wcd_clsh_set_flyback_mode()
166 snd_soc_component_update_bits(comp, WCD9XXX_A_ANA_RX_SUPPLIES, in wcd_clsh_set_flyback_mode()
170 snd_soc_component_update_bits(comp, WCD9XXX_A_ANA_RX_SUPPLIES, in wcd_clsh_set_flyback_mode()
176 int mode, in wcd_clsh_buck_ctrl()
179 struct snd_soc_component *comp = ctrl->comp; in wcd_clsh_buck_ctrl() local
182 if ((enable && (++ctrl->buck_users == 1)) || in wcd_clsh_buck_ctrl()
183 (!enable && (--ctrl->buck_users == 0))) in wcd_clsh_buck_ctrl()
184 snd_soc_component_update_bits(comp, WCD9XXX_A_ANA_RX_SUPPLIES, in wcd_clsh_buck_ctrl()
196 int mode, in wcd_clsh_v3_buck_ctrl()
200 if ((enable && (++ctrl->buck_users == 1)) || in wcd_clsh_v3_buck_ctrl()
201 (!enable && (--ctrl->buck_users == 0))) { in wcd_clsh_v3_buck_ctrl()
225 int mode, in wcd_clsh_flyback_ctrl()
228 struct snd_soc_component *comp = ctrl->comp; in wcd_clsh_flyback_ctrl() local
231 if ((enable && (++ctrl->flyback_users == 1)) || in wcd_clsh_flyback_ctrl()
232 (!enable && (--ctrl->flyback_users == 0))) { in wcd_clsh_flyback_ctrl()
233 snd_soc_component_update_bits(comp, WCD9XXX_A_ANA_RX_SUPPLIES, in wcd_clsh_flyback_ctrl()
246 static void wcd_clsh_set_gain_path(struct wcd_clsh_ctrl *ctrl, int mode) in wcd_clsh_set_gain_path()
248 struct snd_soc_component *comp = ctrl->comp; in wcd_clsh_set_gain_path() local
249 int val = 0; in wcd_clsh_set_gain_path()
264 snd_soc_component_update_bits(comp, WCD9XXX_HPH_L_EN, in wcd_clsh_set_gain_path()
268 snd_soc_component_update_bits(comp, WCD9XXX_HPH_R_EN, in wcd_clsh_set_gain_path()
273 static void wcd_clsh_v2_set_hph_mode(struct snd_soc_component *comp, int mode) in wcd_clsh_v2_set_hph_mode() argument
275 int val = 0, gain = 0, res_val; in wcd_clsh_v2_set_hph_mode()
276 int ipeak = WCD9XXX_CLASSH_CTRL_CCL_1_DELTA_IPEAK_50MA; in wcd_clsh_v2_set_hph_mode()
302 snd_soc_component_update_bits(comp, WCD9XXX_A_ANA_HPH, in wcd_clsh_v2_set_hph_mode()
304 snd_soc_component_update_bits(comp, WCD9XXX_CLASSH_CTRL_VCL_2, in wcd_clsh_v2_set_hph_mode()
308 snd_soc_component_update_bits(comp, in wcd_clsh_v2_set_hph_mode()
312 snd_soc_component_update_bits(comp, WCD9XXX_CLASSH_CTRL_CCL_1, in wcd_clsh_v2_set_hph_mode()
318 int mode) in wcd_clsh_v3_set_hph_mode()
341 dev_err(component->dev, "%s:Invalid mode %d\n", __func__, mode); in wcd_clsh_v3_set_hph_mode()
348 void wcd_clsh_set_hph_mode(struct wcd_clsh_ctrl *ctrl, int mode) in wcd_clsh_set_hph_mode()
350 struct snd_soc_component *comp = ctrl->comp; in wcd_clsh_set_hph_mode() local
352 if (ctrl->codec_version >= WCD937X) in wcd_clsh_set_hph_mode()
353 wcd_clsh_v3_set_hph_mode(comp, mode); in wcd_clsh_set_hph_mode()
355 wcd_clsh_v2_set_hph_mode(comp, mode); in wcd_clsh_set_hph_mode()
360 static void wcd_clsh_set_flyback_current(struct snd_soc_component *comp, in wcd_clsh_set_flyback_current() argument
361 int mode) in wcd_clsh_set_flyback_current()
364 snd_soc_component_update_bits(comp, WCD9XXX_RX_BIAS_FLYB_BUFF, in wcd_clsh_set_flyback_current()
366 snd_soc_component_update_bits(comp, WCD9XXX_RX_BIAS_FLYB_BUFF, in wcd_clsh_set_flyback_current()
372 static void wcd_clsh_set_buck_regulator_mode(struct snd_soc_component *comp, in wcd_clsh_set_buck_regulator_mode() argument
373 int mode) in wcd_clsh_set_buck_regulator_mode()
376 snd_soc_component_update_bits(comp, WCD9XXX_A_ANA_RX_SUPPLIES, in wcd_clsh_set_buck_regulator_mode()
380 snd_soc_component_update_bits(comp, WCD9XXX_A_ANA_RX_SUPPLIES, in wcd_clsh_set_buck_regulator_mode()
386 int mode) in wcd_clsh_v3_set_buck_regulator_mode()
393 int mode) in wcd_clsh_v3_set_flyback_mode()
414 int mode, bool enable) in wcd_clsh_v3_force_iq_ctl()
454 int mode, in wcd_clsh_v3_flyback_ctrl()
458 if ((enable && (++ctrl->flyback_users == 1)) || in wcd_clsh_v3_flyback_ctrl()
459 (!enable && (--ctrl->flyback_users == 0))) { in wcd_clsh_v3_flyback_ctrl()
480 int mode) in wcd_clsh_v3_set_flyback_current()
490 static void wcd_clsh_v3_state_aux(struct wcd_clsh_ctrl *ctrl, int req_state, in wcd_clsh_v3_state_aux()
491 bool is_enable, int mode) in wcd_clsh_v3_state_aux()
493 struct snd_soc_component *component = ctrl->comp; in wcd_clsh_v3_state_aux()
509 static void wcd_clsh_state_lo(struct wcd_clsh_ctrl *ctrl, int req_state, in wcd_clsh_state_lo()
510 bool is_enable, int mode) in wcd_clsh_state_lo()
512 struct snd_soc_component *comp = ctrl->comp; in wcd_clsh_state_lo() local
515 dev_err(comp->dev, "%s: LO cannot be in this mode: %d\n", in wcd_clsh_state_lo()
521 wcd_clsh_set_buck_regulator_mode(comp, mode); in wcd_clsh_state_lo()
522 wcd_clsh_set_buck_mode(comp, mode); in wcd_clsh_state_lo()
523 wcd_clsh_set_flyback_mode(comp, mode); in wcd_clsh_state_lo()
525 wcd_clsh_set_flyback_current(comp, mode); in wcd_clsh_state_lo()
530 wcd_clsh_set_flyback_mode(comp, CLS_H_NORMAL); in wcd_clsh_state_lo()
531 wcd_clsh_set_buck_mode(comp, CLS_H_NORMAL); in wcd_clsh_state_lo()
532 wcd_clsh_set_buck_regulator_mode(comp, CLS_H_NORMAL); in wcd_clsh_state_lo()
536 static void wcd_clsh_v3_state_hph_r(struct wcd_clsh_ctrl *ctrl, int req_state, in wcd_clsh_v3_state_hph_r()
537 bool is_enable, int mode) in wcd_clsh_v3_state_hph_r()
539 struct snd_soc_component *component = ctrl->comp; in wcd_clsh_v3_state_hph_r()
542 dev_dbg(component->dev, "%s: Normal mode not applicable for hph_r\n", in wcd_clsh_v3_state_hph_r()
568 static void wcd_clsh_state_hph_r(struct wcd_clsh_ctrl *ctrl, int req_state, in wcd_clsh_state_hph_r()
569 bool is_enable, int mode) in wcd_clsh_state_hph_r()
571 struct snd_soc_component *comp = ctrl->comp; in wcd_clsh_state_hph_r() local
574 dev_err(comp->dev, "%s: Normal mode not applicable for hph_r\n", in wcd_clsh_state_hph_r()
586 snd_soc_component_update_bits(comp, in wcd_clsh_state_hph_r()
590 snd_soc_component_update_bits(comp, in wcd_clsh_state_hph_r()
594 snd_soc_component_update_bits(comp, in wcd_clsh_state_hph_r()
599 wcd_clsh_set_buck_regulator_mode(comp, mode); in wcd_clsh_state_hph_r()
600 wcd_clsh_set_flyback_mode(comp, mode); in wcd_clsh_state_hph_r()
602 wcd_clsh_set_flyback_current(comp, mode); in wcd_clsh_state_hph_r()
603 wcd_clsh_set_buck_mode(comp, mode); in wcd_clsh_state_hph_r()
605 wcd_clsh_v2_set_hph_mode(comp, mode); in wcd_clsh_state_hph_r()
608 wcd_clsh_v2_set_hph_mode(comp, CLS_H_NORMAL); in wcd_clsh_state_hph_r()
611 snd_soc_component_update_bits(comp, in wcd_clsh_state_hph_r()
620 wcd_clsh_set_flyback_mode(comp, CLS_H_NORMAL); in wcd_clsh_state_hph_r()
621 wcd_clsh_set_buck_mode(comp, CLS_H_NORMAL); in wcd_clsh_state_hph_r()
622 wcd_clsh_set_buck_regulator_mode(comp, CLS_H_NORMAL); in wcd_clsh_state_hph_r()
626 static void wcd_clsh_v3_state_hph_l(struct wcd_clsh_ctrl *ctrl, int req_state, in wcd_clsh_v3_state_hph_l()
627 bool is_enable, int mode) in wcd_clsh_v3_state_hph_l()
629 struct snd_soc_component *component = ctrl->comp; in wcd_clsh_v3_state_hph_l()
632 dev_dbg(component->dev, "%s: Normal mode not applicable for hph_l\n", in wcd_clsh_v3_state_hph_l()
658 static void wcd_clsh_state_hph_l(struct wcd_clsh_ctrl *ctrl, int req_state, in wcd_clsh_state_hph_l()
659 bool is_enable, int mode) in wcd_clsh_state_hph_l()
661 struct snd_soc_component *comp = ctrl->comp; in wcd_clsh_state_hph_l() local
664 dev_err(comp->dev, "%s: Normal mode not applicable for hph_l\n", in wcd_clsh_state_hph_l()
676 snd_soc_component_update_bits(comp, in wcd_clsh_state_hph_l()
680 snd_soc_component_update_bits(comp, in wcd_clsh_state_hph_l()
684 snd_soc_component_update_bits(comp, in wcd_clsh_state_hph_l()
689 wcd_clsh_set_buck_regulator_mode(comp, mode); in wcd_clsh_state_hph_l()
690 wcd_clsh_set_flyback_mode(comp, mode); in wcd_clsh_state_hph_l()
692 wcd_clsh_set_flyback_current(comp, mode); in wcd_clsh_state_hph_l()
693 wcd_clsh_set_buck_mode(comp, mode); in wcd_clsh_state_hph_l()
695 wcd_clsh_v2_set_hph_mode(comp, mode); in wcd_clsh_state_hph_l()
698 wcd_clsh_v2_set_hph_mode(comp, CLS_H_NORMAL); in wcd_clsh_state_hph_l()
701 snd_soc_component_update_bits(comp, in wcd_clsh_state_hph_l()
710 wcd_clsh_set_flyback_mode(comp, CLS_H_NORMAL); in wcd_clsh_state_hph_l()
711 wcd_clsh_set_buck_mode(comp, CLS_H_NORMAL); in wcd_clsh_state_hph_l()
712 wcd_clsh_set_buck_regulator_mode(comp, CLS_H_NORMAL); in wcd_clsh_state_hph_l()
716 static void wcd_clsh_v3_state_ear(struct wcd_clsh_ctrl *ctrl, int req_state, in wcd_clsh_v3_state_ear()
717 bool is_enable, int mode) in wcd_clsh_v3_state_ear()
719 struct snd_soc_component *component = ctrl->comp; in wcd_clsh_v3_state_ear()
742 static void wcd_clsh_state_ear(struct wcd_clsh_ctrl *ctrl, int req_state, in wcd_clsh_state_ear()
743 bool is_enable, int mode) in wcd_clsh_state_ear()
745 struct snd_soc_component *comp = ctrl->comp; in wcd_clsh_state_ear() local
748 dev_err(comp->dev, "%s: mode: %d cannot be used for EAR\n", in wcd_clsh_state_ear()
755 snd_soc_component_update_bits(comp, in wcd_clsh_state_ear()
759 wcd_clsh_set_buck_mode(comp, mode); in wcd_clsh_state_ear()
760 wcd_clsh_set_flyback_mode(comp, mode); in wcd_clsh_state_ear()
762 wcd_clsh_set_flyback_current(comp, mode); in wcd_clsh_state_ear()
765 snd_soc_component_update_bits(comp, in wcd_clsh_state_ear()
772 wcd_clsh_set_flyback_mode(comp, CLS_H_NORMAL); in wcd_clsh_state_ear()
773 wcd_clsh_set_buck_mode(comp, CLS_H_NORMAL); in wcd_clsh_state_ear()
777 static int _wcd_clsh_ctrl_set_state(struct wcd_clsh_ctrl *ctrl, int req_state, in _wcd_clsh_ctrl_set_state()
778 bool is_enable, int mode) in _wcd_clsh_ctrl_set_state()
782 if (ctrl->codec_version >= WCD937X) in _wcd_clsh_ctrl_set_state()
788 if (ctrl->codec_version >= WCD937X) in _wcd_clsh_ctrl_set_state()
794 if (ctrl->codec_version >= WCD937X) in _wcd_clsh_ctrl_set_state()
800 if (ctrl->codec_version < WCD937X) in _wcd_clsh_ctrl_set_state()
804 if (ctrl->codec_version >= WCD937X) in _wcd_clsh_ctrl_set_state()
820 static bool wcd_clsh_is_state_valid(int state) in wcd_clsh_is_state_valid()
844 int wcd_clsh_ctrl_set_state(struct wcd_clsh_ctrl *ctrl, in wcd_clsh_ctrl_set_state()
846 int nstate, in wcd_clsh_ctrl_set_state()
849 struct snd_soc_component *comp = ctrl->comp; in wcd_clsh_ctrl_set_state() local
851 if (nstate == ctrl->state) in wcd_clsh_ctrl_set_state()
855 dev_err(comp->dev, "Class-H not a valid new state:\n"); in wcd_clsh_ctrl_set_state()
856 return -EINVAL; in wcd_clsh_ctrl_set_state()
868 ctrl->state = nstate; in wcd_clsh_ctrl_set_state()
869 ctrl->mode = mode; in wcd_clsh_ctrl_set_state()
875 int wcd_clsh_ctrl_get_state(struct wcd_clsh_ctrl *ctrl) in wcd_clsh_ctrl_get_state()
877 return ctrl->state; in wcd_clsh_ctrl_get_state()
881 struct wcd_clsh_ctrl *wcd_clsh_ctrl_alloc(struct snd_soc_component *comp, in wcd_clsh_ctrl_alloc() argument
882 int version) in wcd_clsh_ctrl_alloc()
888 return ERR_PTR(-ENOMEM); in wcd_clsh_ctrl_alloc()
890 ctrl->state = WCD_CLSH_STATE_IDLE; in wcd_clsh_ctrl_alloc()
891 ctrl->comp = comp; in wcd_clsh_ctrl_alloc()
892 ctrl->codec_version = version; in wcd_clsh_ctrl_alloc()
904 MODULE_DESCRIPTION("WCD93XX Class-H driver");