1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411 |
- #include <linux/module.h>
- #include <linux/slab.h>
- #include <sound/soc.h>
- #include <linux/kernel.h>
- #include <linux/delay.h>
- #include <asoc/core.h>
- #include <asoc/wcd9xxx-common-v2.h>
- #include <asoc/wcd9xxx_registers.h>
- #define WCD_USLEEP_RANGE 50
- #define MAX_IMPED_PARAMS 6
- enum {
- DAC_GAIN_0DB = 0,
- DAC_GAIN_0P2DB,
- DAC_GAIN_0P4DB,
- DAC_GAIN_0P6DB,
- DAC_GAIN_0P8DB,
- DAC_GAIN_M0P2DB,
- DAC_GAIN_M0P4DB,
- DAC_GAIN_M0P6DB,
- };
- enum {
- VREF_FILT_R_0OHM = 0,
- VREF_FILT_R_25KOHM,
- VREF_FILT_R_50KOHM,
- VREF_FILT_R_100KOHM,
- };
- enum {
- DELTA_I_0MA,
- DELTA_I_10MA,
- DELTA_I_20MA,
- DELTA_I_30MA,
- DELTA_I_40MA,
- DELTA_I_50MA,
- };
- struct wcd_imped_val {
- u32 imped_val;
- u8 index;
- };
- static const struct wcd_reg_mask_val imped_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ff, 0xfe},
- {WCD9XXX_CDC_RX2_RX_PATH_SEC1, 0x01, 0x01},
- },
- {
- {WCD9XXX_CDC_RX1_RX_VOL_CTL, 0xff, 0xff},
- {WCD9XXX_CDC_RX1_RX_VOL_MIX_CTL, 0xff, 0xff},
- {WCD9XXX_CDC_RX1_RX_PATH_SEC1, 0x01, 0x00},
- {WCD9XXX_CDC_RX2_RX_VOL_CTL, 0xff, 0xff},
- {WCD9XXX_CDC_RX2_RX_VOL_MIX_CTL, 0xff, 0xff},
- {WCD9XXX_CDC_RX2_RX_PATH_SEC1, 0x01, 0x00},
- },
- };
- static const struct wcd_reg_mask_val imped_table_tavil[][MAX_IMPED_PARAMS] = {
- {
- {WCD9XXX_CDC_RX1_RX_VOL_CTL, 0xff, 0xf2},
- {WCD9XXX_CDC_RX1_RX_VOL_MIX_CTL, 0xff, 0xf2},
- {WCD9XXX_CDC_RX1_RX_PATH_SEC1, 0x01, 0x00},
- {WCD9XXX_CDC_RX2_RX_VOL_CTL, 0xff, 0xf2},
- {WCD9XXX_CDC_RX2_RX_VOL_MIX_CTL, 0xff, 0xf2},
- {WCD9XXX_CDC_RX2_RX_PATH_SEC1, 0x01, 0x00},
- },
- {
- {WCD9XXX_CDC_RX1_RX_VOL_CTL, 0xff, 0xf4},
- {WCD9XXX_CDC_RX1_RX_VOL_MIX_CTL, 0xff, 0xf4},
- {WCD9XXX_CDC_RX1_RX_PATH_SEC1, 0x01, 0x00},
- {WCD9XXX_CDC_RX2_RX_VOL_CTL, 0xff, 0xf4},
- {WCD9XXX_CDC_RX2_RX_VOL_MIX_CTL, 0xff, 0xf4},
- {WCD9XXX_CDC_RX2_RX_PATH_SEC1, 0x01, 0x00},
- },
- {
- {WCD9XXX_CDC_RX1_RX_VOL_CTL, 0xff, 0xf7},
- {WCD9XXX_CDC_RX1_RX_VOL_MIX_CTL, 0xff, 0xf7},
- {WCD9XXX_CDC_RX1_RX_PATH_SEC1, 0x01, 0x01},
- {WCD9XXX_CDC_RX2_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WCD9XXX_CDC_RX2_RX_VOL_CTL, 0xff, 0xfc},
- {WCD9XXX_CDC_RX2_RX_VOL_MIX_CTL, 0xff, 0xfc},
- {WCD9XXX_CDC_RX2_RX_PATH_SEC1, 0x01, 0x00},
- },
- {
- {WCD9XXX_CDC_RX1_RX_VOL_CTL, 0xff, 0xfd},
- {WCD9XXX_CDC_RX1_RX_VOL_MIX_CTL, 0xff, 0xfd},
- {WCD9XXX_CDC_RX1_RX_PATH_SEC1, 0x01, 0x00},
- {WCD9XXX_CDC_RX2_RX_VOL_CTL, 0xff, 0xfd},
- {WCD9XXX_CDC_RX2_RX_VOL_MIX_CTL, 0xff, 0xfd},
- {WCD9XXX_CDC_RX2_RX_PATH_SEC1, 0x01, 0x00},
- },
- {
- {WCD9XXX_CDC_RX1_RX_VOL_CTL, 0xff, 0xfd},
- {WCD9XXX_CDC_RX1_RX_VOL_MIX_CTL, 0xff, 0xfd},
- {WCD9XXX_CDC_RX1_RX_PATH_SEC1, 0x01, 0x01},
- {WCD9XXX_CDC_RX2_RX_VOL_CTL, 0xff, 0xfd},
- {WCD9XXX_CDC_RX2_RX_VOL_MIX_CTL, 0xff, 0xfd},
- {WCD9XXX_CDC_RX2_RX_PATH_SEC1, 0x01, 0x01},
- },
- };
- static const struct wcd_imped_val imped_index[] = {
- {4, 0},
- {5, 1},
- {6, 2},
- {7, 3},
- {8, 4},
- {9, 5},
- {10, 6},
- {11, 7},
- {12, 8},
- {13, 9},
- };
- static void (*clsh_state_fp[NUM_CLSH_STATES_V2])(struct snd_soc_component *,
- struct wcd_clsh_cdc_data *,
- u8 req_state, bool en, int mode);
- static int get_impedance_index(int imped)
- {
- int i = 0;
- if (imped < imped_index[i].imped_val) {
- pr_debug("%s, detected impedance is less than 4 Ohm\n",
- __func__);
- i = 0;
- goto ret;
- }
- if (imped >= imped_index[ARRAY_SIZE(imped_index) - 1].imped_val) {
- pr_debug("%s, detected impedance is greater than 12 Ohm\n",
- __func__);
- i = ARRAY_SIZE(imped_index) - 1;
- goto ret;
- }
- for (i = 0; i < ARRAY_SIZE(imped_index) - 1; i++) {
- if (imped >= imped_index[i].imped_val &&
- imped < imped_index[i + 1].imped_val)
- break;
- }
- ret:
- pr_debug("%s: selected impedance index = %d\n",
- __func__, imped_index[i].index);
- return imped_index[i].index;
- }
- void wcd_clsh_imped_config(struct snd_soc_component *component, int imped,
- bool reset)
- {
- int i;
- int index = 0;
- int table_size;
- static const struct wcd_reg_mask_val
- (*imped_table_ptr)[MAX_IMPED_PARAMS];
- struct wcd9xxx *wcd9xxx = dev_get_drvdata(component->dev->parent);
- if (IS_CODEC_TYPE(wcd9xxx, WCD934X)) {
- table_size = ARRAY_SIZE(imped_table_tavil);
- imped_table_ptr = imped_table_tavil;
- } else {
- table_size = ARRAY_SIZE(imped_table);
- imped_table_ptr = imped_table;
- }
-
- if (reset) {
- for (i = 0; i < MAX_IMPED_PARAMS; i++)
- snd_soc_component_update_bits(component,
- imped_table_ptr[index][i].reg,
- imped_table_ptr[index][i].mask, 0);
- return;
- }
- index = get_impedance_index(imped);
- if (index >= (ARRAY_SIZE(imped_index) - 1)) {
- pr_debug("%s, impedance not in range = %d\n", __func__, imped);
- return;
- }
- if (index >= table_size) {
- pr_debug("%s, impedance index not in range = %d\n", __func__,
- index);
- return;
- }
- for (i = 0; i < MAX_IMPED_PARAMS; i++)
- snd_soc_component_update_bits(component,
- imped_table_ptr[index][i].reg,
- imped_table_ptr[index][i].mask,
- imped_table_ptr[index][i].val);
- }
- EXPORT_SYMBOL(wcd_clsh_imped_config);
- static bool is_native_44_1_active(struct snd_soc_component *component)
- {
- bool native_active = false;
- u8 native_clk, rx1_rate, rx2_rate;
- native_clk = snd_soc_component_read32(component,
- WCD9XXX_CDC_CLK_RST_CTRL_MCLK_CONTROL);
- rx1_rate = snd_soc_component_read32(component,
- WCD9XXX_CDC_RX1_RX_PATH_CTL);
- rx2_rate = snd_soc_component_read32(component,
- WCD9XXX_CDC_RX2_RX_PATH_CTL);
- dev_dbg(component->dev, "%s: native_clk %x rx1_rate= %x rx2_rate= %x",
- __func__, native_clk, rx1_rate, rx2_rate);
- if ((native_clk & 0x2) &&
- ((rx1_rate & 0x0F) == 0x9 || (rx2_rate & 0x0F) == 0x9))
- native_active = true;
- return native_active;
- }
- static const char *mode_to_str(int mode)
- {
- switch (mode) {
- case CLS_H_NORMAL:
- return "CLS_H_NORMAL";
- case CLS_H_HIFI:
- return "CLS_H_HIFI";
- case CLS_H_LOHIFI:
- return "CLS_H_LOHIFI";
- case CLS_H_LP:
- return "CLS_H_LP";
- case CLS_H_ULP:
- return "CLS_H_ULP";
- case CLS_AB:
- return "CLS_AB";
- case CLS_AB_HIFI:
- return "CLS_AB_HIFI";
- default:
- return "CLS_H_INVALID";
- };
- }
- static const char *state_to_str(u8 state, char *buf, size_t buflen)
- {
- int i;
- int cnt = 0;
-
- static const char *const states[] = {
- "STATE_EAR",
- "STATE_HPH_L",
- "STATE_HPH_R",
- "STATE_LO",
- };
- if (state == WCD_CLSH_STATE_IDLE) {
- snprintf(buf, buflen, "[STATE_IDLE]");
- goto done;
- }
- buf[0] = '\0';
- for (i = 0; i < ARRAY_SIZE(states); i++) {
- if (!(state & (1 << i)))
- continue;
- cnt = snprintf(buf, buflen - cnt - 1, "%s%s%s", buf,
- buf[0] == '\0' ? "[" : "|",
- states[i]);
- }
- if (cnt > 0)
- strlcat(buf + cnt, "]", buflen);
- done:
- if (buf[0] == '\0')
- snprintf(buf, buflen, "[STATE_UNKNOWN]");
- return buf;
- }
- static inline void
- wcd_enable_clsh_block(struct snd_soc_component *component,
- struct wcd_clsh_cdc_data *clsh_d, bool enable)
- {
- if ((enable && ++clsh_d->clsh_users == 1) ||
- (!enable && --clsh_d->clsh_users == 0))
- snd_soc_component_update_bits(component, WCD9XXX_A_CDC_CLSH_CRC,
- 0x01, (u8) enable);
- if (clsh_d->clsh_users < 0)
- clsh_d->clsh_users = 0;
- dev_dbg(component->dev, "%s: clsh_users %d, enable %d", __func__,
- clsh_d->clsh_users, enable);
- }
- static inline bool wcd_clsh_enable_status(struct snd_soc_component *component)
- {
- return snd_soc_component_read32(component, WCD9XXX_A_CDC_CLSH_CRC) &
- 0x01;
- }
- static inline int wcd_clsh_get_int_mode(struct wcd_clsh_cdc_data *clsh_d,
- int clsh_state)
- {
- int mode;
- if ((clsh_state != WCD_CLSH_STATE_EAR) &&
- (clsh_state != WCD_CLSH_STATE_HPHL) &&
- (clsh_state != WCD_CLSH_STATE_HPHR) &&
- (clsh_state != WCD_CLSH_STATE_LO))
- mode = CLS_NONE;
- else
- mode = clsh_d->interpolator_modes[ffs(clsh_state)];
- return mode;
- }
- static inline void wcd_clsh_set_int_mode(struct wcd_clsh_cdc_data *clsh_d,
- int clsh_state, int mode)
- {
- if ((clsh_state != WCD_CLSH_STATE_EAR) &&
- (clsh_state != WCD_CLSH_STATE_HPHL) &&
- (clsh_state != WCD_CLSH_STATE_HPHR) &&
- (clsh_state != WCD_CLSH_STATE_LO))
- return;
- clsh_d->interpolator_modes[ffs(clsh_state)] = mode;
- }
- static inline void wcd_clsh_set_buck_mode(struct snd_soc_component *component,
- int mode)
- {
- if (mode == CLS_H_HIFI || mode == CLS_H_LOHIFI ||
- mode == CLS_AB_HIFI || mode == CLS_AB)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_ANA_RX_SUPPLIES,
- 0x08, 0x08);
- else
- snd_soc_component_update_bits(component,
- WCD9XXX_A_ANA_RX_SUPPLIES,
- 0x08, 0x00);
- }
- static inline void wcd_clsh_set_flyback_mode(
- struct snd_soc_component *component,
- int mode)
- {
- if (mode == CLS_H_HIFI || mode == CLS_H_LOHIFI ||
- mode == CLS_AB_HIFI || mode == CLS_AB)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_ANA_RX_SUPPLIES,
- 0x04, 0x04);
- else
- snd_soc_component_update_bits(component,
- WCD9XXX_A_ANA_RX_SUPPLIES,
- 0x04, 0x00);
- }
- static inline void wcd_clsh_gm3_boost_disable(
- struct snd_soc_component *component,
- int mode)
- {
- struct wcd9xxx *wcd9xxx = dev_get_drvdata(component->dev->parent);
- if (!IS_CODEC_TYPE(wcd9xxx, WCD934X))
- return;
- if (mode == CLS_H_HIFI || mode == CLS_H_LOHIFI ||
- mode == CLS_AB_HIFI || mode == CLS_AB) {
- if (TAVIL_IS_1_0(wcd9xxx))
- snd_soc_component_update_bits(component,
- WCD9XXX_HPH_CNP_WG_CTL,
- 0x80, 0x0);
- snd_soc_component_update_bits(component,
- WCD9XXX_FLYBACK_VNEG_CTRL_4,
- 0xF0, 0x80);
- } else {
- snd_soc_component_update_bits(component,
- WCD9XXX_HPH_CNP_WG_CTL,
- 0x80, 0x80);
- snd_soc_component_update_bits(component,
- WCD9XXX_FLYBACK_VNEG_CTRL_4,
- 0xF0, 0x70);
- }
- }
- static inline void wcd_clsh_force_iq_ctl(struct snd_soc_component *component,
- int mode)
- {
- struct wcd9xxx *wcd9xxx = dev_get_drvdata(component->dev->parent);
- if (!IS_CODEC_TYPE(wcd9xxx, WCD934X))
- return;
- if (mode == CLS_H_LOHIFI || mode == CLS_AB) {
- snd_soc_component_update_bits(component,
- WCD9XXX_HPH_NEW_INT_PA_MISC2,
- 0x20, 0x20);
- snd_soc_component_update_bits(component,
- WCD9XXX_RX_BIAS_HPH_LOWPOWER,
- 0xF0, 0xC0);
- snd_soc_component_update_bits(component,
- WCD9XXX_HPH_PA_CTL1,
- 0x0E, 0x02);
- } else {
- snd_soc_component_update_bits(component,
- WCD9XXX_HPH_NEW_INT_PA_MISC2,
- 0x20, 0x0);
- snd_soc_component_update_bits(component,
- WCD9XXX_RX_BIAS_HPH_LOWPOWER,
- 0xF0, 0x80);
- snd_soc_component_update_bits(component,
- WCD9XXX_HPH_PA_CTL1,
- 0x0E, 0x06);
- }
- }
- static void wcd_clsh_buck_ctrl(struct snd_soc_component *component,
- struct wcd_clsh_cdc_data *clsh_d,
- int mode,
- bool enable)
- {
-
- if ((enable && (++clsh_d->buck_users == 1)) ||
- (!enable && (--clsh_d->buck_users == 0)))
- snd_soc_component_update_bits(component,
- WCD9XXX_A_ANA_RX_SUPPLIES,
- (1 << 7), (enable << 7));
- dev_dbg(component->dev, "%s: buck_users %d, enable %d, mode: %s",
- __func__, clsh_d->buck_users, enable, mode_to_str(mode));
-
- usleep_range(500, 500 + WCD_USLEEP_RANGE);
- }
- static void wcd_clsh_flyback_ctrl(struct snd_soc_component *component,
- struct wcd_clsh_cdc_data *clsh_d,
- int mode,
- bool enable)
- {
- struct wcd9xxx *wcd9xxx = dev_get_drvdata(component->dev->parent);
- struct wcd9xxx_reg_val bulk_reg[2];
- u8 vneg[] = {0x00, 0x40};
-
- if ((enable && (++clsh_d->flyback_users == 1)) ||
- (!enable && (--clsh_d->flyback_users == 0))) {
- snd_soc_component_update_bits(component,
- WCD9XXX_A_ANA_RX_SUPPLIES,
- (1 << 6), (enable << 6));
-
- usleep_range(100, 110);
- if (enable && (TASHA_IS_1_1(wcd9xxx))) {
- wcd_clsh_set_flyback_mode(component, CLS_H_HIFI);
- snd_soc_component_update_bits(component,
- WCD9XXX_FLYBACK_EN,
- 0x60, 0x40);
- snd_soc_component_update_bits(component,
- WCD9XXX_FLYBACK_EN,
- 0x10, 0x10);
- vneg[0] = snd_soc_component_read32(component,
- WCD9XXX_A_ANA_RX_SUPPLIES);
- vneg[0] &= ~(0x40);
- vneg[1] = vneg[0] | 0x40;
- bulk_reg[0].reg = WCD9XXX_A_ANA_RX_SUPPLIES;
- bulk_reg[0].buf = &vneg[0];
- bulk_reg[0].bytes = 1;
- bulk_reg[1].reg = WCD9XXX_A_ANA_RX_SUPPLIES;
- bulk_reg[1].buf = &vneg[1];
- bulk_reg[1].bytes = 1;
-
- usleep_range(500, 510);
- wcd9xxx_slim_bulk_write(wcd9xxx, bulk_reg, 2,
- false);
- snd_soc_component_update_bits(component,
- WCD9XXX_FLYBACK_EN,
- 0x10, 0x00);
- wcd_clsh_set_flyback_mode(component, mode);
- }
- }
- dev_dbg(component->dev, "%s: flyback_users %d, enable %d, mode: %s",
- __func__, clsh_d->flyback_users, enable, mode_to_str(mode));
-
- usleep_range(500, 500 + WCD_USLEEP_RANGE);
- }
- static void wcd_clsh_set_gain_path(struct snd_soc_component *component,
- int mode)
- {
- u8 val = 0;
- struct wcd9xxx *wcd9xxx = dev_get_drvdata(component->dev->parent);
- if (!TASHA_IS_2_0(wcd9xxx))
- return;
- switch (mode) {
- case CLS_H_NORMAL:
- case CLS_AB:
- val = 0x00;
- break;
- case CLS_H_HIFI:
- val = 0x02;
- break;
- case CLS_H_LP:
- val = 0x01;
- break;
- default:
- return;
- };
- snd_soc_component_update_bits(component, WCD9XXX_HPH_L_EN,
- 0xC0, (val << 6));
- snd_soc_component_update_bits(component, WCD9XXX_HPH_R_EN,
- 0xC0, (val << 6));
- }
- static void wcd_clsh_set_hph_mode(struct snd_soc_component *component,
- int mode)
- {
- u8 val = 0;
- u8 gain = 0;
- u8 res_val = VREF_FILT_R_0OHM;
- u8 ipeak = DELTA_I_50MA;
- struct wcd9xxx *wcd9xxx = dev_get_drvdata(component->dev->parent);
- switch (mode) {
- case CLS_H_NORMAL:
- res_val = VREF_FILT_R_50KOHM;
- val = 0x00;
- gain = DAC_GAIN_0DB;
- ipeak = DELTA_I_50MA;
- break;
- case CLS_AB:
- val = 0x00;
- gain = DAC_GAIN_0DB;
- ipeak = DELTA_I_50MA;
- break;
- case CLS_AB_HIFI:
- val = 0x08;
- break;
- case CLS_H_HIFI:
- val = 0x08;
- gain = DAC_GAIN_M0P2DB;
- ipeak = DELTA_I_50MA;
- break;
- case CLS_H_LOHIFI:
- val = 0x00;
- if ((IS_CODEC_TYPE(wcd9xxx, WCD9335)) ||
- (IS_CODEC_TYPE(wcd9xxx, WCD9326))) {
- val = 0x08;
- gain = DAC_GAIN_M0P2DB;
- ipeak = DELTA_I_50MA;
- }
- break;
- case CLS_H_ULP:
- val = 0x0C;
- break;
- case CLS_H_LP:
- val = 0x04;
- ipeak = DELTA_I_30MA;
- break;
- default:
- return;
- };
-
- if ((IS_CODEC_TYPE(wcd9xxx, WCD934X)) &&
- (mode == CLS_H_LOHIFI || mode == CLS_AB))
- val = 0x04;
- snd_soc_component_update_bits(component, WCD9XXX_A_ANA_HPH, 0x0C, val);
- if (TASHA_IS_2_0(wcd9xxx)) {
- snd_soc_component_update_bits(component,
- WCD9XXX_CLASSH_CTRL_VCL_2,
- 0x30, (res_val << 4));
- if (mode != CLS_H_LP)
- snd_soc_component_update_bits(component,
- WCD9XXX_HPH_REFBUFF_UHQA_CTL,
- 0x07, gain);
- snd_soc_component_update_bits(component,
- WCD9XXX_CLASSH_CTRL_CCL_1,
- 0xF0, (ipeak << 4));
- }
- }
- static void wcd_clsh_set_flyback_vneg_ctl(struct snd_soc_component *component,
- bool enable)
- {
- struct wcd9xxx *wcd9xxx = dev_get_drvdata(component->dev->parent);
- if (!TASHA_IS_2_0(wcd9xxx))
- return;
- if (enable) {
- snd_soc_component_update_bits(component,
- WCD9XXX_FLYBACK_VNEG_CTRL_1, 0xE0, 0x00);
- snd_soc_component_update_bits(component,
- WCD9XXX_FLYBACK_VNEGDAC_CTRL_2,
- 0xE0, (0x07 << 5));
- } else {
- snd_soc_component_update_bits(component,
- WCD9XXX_FLYBACK_VNEG_CTRL_1,
- 0xE0, (0x07 << 5));
- snd_soc_component_update_bits(component,
- WCD9XXX_FLYBACK_VNEGDAC_CTRL_2,
- 0xE0, (0x02 << 5));
- }
- }
- static void wcd_clsh_set_flyback_current(struct snd_soc_component *component,
- int mode)
- {
- struct wcd9xxx *wcd9xxx = dev_get_drvdata(component->dev->parent);
- if (!TASHA_IS_2_0(wcd9xxx))
- return;
- snd_soc_component_update_bits(component, WCD9XXX_RX_BIAS_FLYB_BUFF,
- 0x0F, 0x0A);
- snd_soc_component_update_bits(component, WCD9XXX_RX_BIAS_FLYB_BUFF,
- 0xF0, 0xA0);
-
- usleep_range(100, 110);
- }
- static void wcd_clsh_set_buck_regulator_mode(
- struct snd_soc_component *component,
- int mode)
- {
- snd_soc_component_update_bits(component, WCD9XXX_A_ANA_RX_SUPPLIES,
- 0x02, 0x00);
- }
- static void wcd_clsh_state_lo(struct snd_soc_component *component,
- struct wcd_clsh_cdc_data *clsh_d,
- u8 req_state, bool is_enable, int mode)
- {
- dev_dbg(component->dev, "%s: mode: %s, %s\n", __func__,
- mode_to_str(mode),
- is_enable ? "enable" : "disable");
- if (mode != CLS_AB && mode != CLS_AB_HIFI) {
- dev_err_ratelimited(component->dev, "%s: LO cannot be in this mode: %d\n",
- __func__, mode);
- return;
- }
- if (is_enable) {
- wcd_clsh_set_buck_regulator_mode(component, mode);
- wcd_clsh_set_flyback_vneg_ctl(component, true);
- wcd_clsh_set_buck_mode(component, mode);
- wcd_clsh_set_flyback_mode(component, mode);
- wcd_clsh_flyback_ctrl(component, clsh_d, mode, true);
- wcd_clsh_set_flyback_current(component, mode);
- wcd_clsh_buck_ctrl(component, clsh_d, mode, true);
- } else {
- wcd_clsh_buck_ctrl(component, clsh_d, mode, false);
- wcd_clsh_flyback_ctrl(component, clsh_d, mode, false);
- wcd_clsh_set_flyback_mode(component, CLS_H_NORMAL);
- wcd_clsh_set_buck_mode(component, CLS_H_NORMAL);
- wcd_clsh_set_flyback_vneg_ctl(component, false);
- wcd_clsh_set_buck_regulator_mode(component, CLS_H_NORMAL);
- }
- }
- static void wcd_clsh_state_hph_ear(struct snd_soc_component *component,
- struct wcd_clsh_cdc_data *clsh_d,
- u8 req_state, bool is_enable, int mode)
- {
- int hph_mode = 0;
- dev_dbg(component->dev, "%s: mode: %s, %s\n", __func__,
- mode_to_str(mode),
- is_enable ? "enable" : "disable");
- if (is_enable) {
- if (req_state == WCD_CLSH_STATE_EAR) {
-
- if (clsh_d->state & WCD_CLSH_STATE_HPHL)
- hph_mode = wcd_clsh_get_int_mode(clsh_d,
- WCD_CLSH_STATE_HPHL);
- else if (clsh_d->state & WCD_CLSH_STATE_HPHR)
- hph_mode = wcd_clsh_get_int_mode(clsh_d,
- WCD_CLSH_STATE_HPHR);
- else
- return;
- if (hph_mode != CLS_AB && hph_mode != CLS_AB_HIFI
- && !is_native_44_1_active(component))
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX0_RX_PATH_CFG0,
- 0x40, 0x40);
- }
- if (is_native_44_1_active(component)) {
- snd_soc_component_write(component,
- WCD9XXX_CDC_CLSH_HPH_V_PA, 0x39);
- snd_soc_component_update_bits(component,
- WCD9XXX_CDC_RX0_RX_PATH_SEC0,
- 0x03, 0x00);
- if ((req_state == WCD_CLSH_STATE_HPHL) ||
- (req_state == WCD_CLSH_STATE_HPHR))
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX0_RX_PATH_CFG0,
- 0x40, 0x00);
- }
- if (req_state == WCD_CLSH_STATE_HPHL)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX1_RX_PATH_CFG0,
- 0x40, 0x40);
- if (req_state == WCD_CLSH_STATE_HPHR)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX2_RX_PATH_CFG0,
- 0x40, 0x40);
- if ((req_state == WCD_CLSH_STATE_HPHL) ||
- (req_state == WCD_CLSH_STATE_HPHR)) {
- wcd_clsh_set_gain_path(component, mode);
- wcd_clsh_set_flyback_mode(component, mode);
- wcd_clsh_set_buck_mode(component, mode);
- }
- } else {
- if (req_state == WCD_CLSH_STATE_EAR) {
-
- if (wcd_clsh_enable_status(component))
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX0_RX_PATH_CFG0,
- 0x40, 0x00);
- }
- if (is_native_44_1_active(component)) {
- snd_soc_component_write(component,
- WCD9XXX_CDC_CLSH_HPH_V_PA, 0x1C);
- snd_soc_component_update_bits(component,
- WCD9XXX_CDC_RX0_RX_PATH_SEC0,
- 0x03, 0x01);
- if (((clsh_d->state & WCD_CLSH_STATE_HPH_ST)
- != WCD_CLSH_STATE_HPH_ST) &&
- ((req_state == WCD_CLSH_STATE_HPHL) ||
- (req_state == WCD_CLSH_STATE_HPHR)))
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX0_RX_PATH_CFG0,
- 0x40, 0x40);
- }
- if (req_state == WCD_CLSH_STATE_HPHL)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX1_RX_PATH_CFG0,
- 0x40, 0x00);
- if (req_state == WCD_CLSH_STATE_HPHR)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX2_RX_PATH_CFG0,
- 0x40, 0x00);
- if ((req_state & WCD_CLSH_STATE_HPH_ST) &&
- !wcd_clsh_enable_status(component)) {
-
- wcd_enable_clsh_block(component, clsh_d, true);
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX0_RX_PATH_CFG0,
- 0x40, 0x40);
- wcd_clsh_set_flyback_mode(component, CLS_H_NORMAL);
- wcd_clsh_set_buck_mode(component, CLS_H_NORMAL);
- }
- }
- }
- static void wcd_clsh_state_ear_lo(struct snd_soc_component *component,
- struct wcd_clsh_cdc_data *clsh_d,
- u8 req_state, bool is_enable, int mode)
- {
- dev_dbg(component->dev, "%s: mode: %s, %s\n", __func__,
- mode_to_str(mode),
- is_enable ? "enable" : "disable");
- if (is_enable) {
-
- if (req_state == WCD_CLSH_STATE_EAR) {
-
- if (!wcd_clsh_enable_status(component)) {
- wcd_enable_clsh_block(component, clsh_d, true);
- wcd_clsh_set_buck_mode(component, mode);
- wcd_clsh_set_flyback_mode(component, mode);
- }
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX0_RX_PATH_CFG0,
- 0x40, 0x40);
- }
- } else {
- if (req_state == WCD_CLSH_STATE_EAR) {
-
- wcd_enable_clsh_block(component, clsh_d, false);
- wcd_clsh_set_buck_mode(component, CLS_H_NORMAL);
- wcd_clsh_set_flyback_mode(component, CLS_H_NORMAL);
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX0_RX_PATH_CFG0,
- 0x40, 0x00);
- }
-
- }
- }
- static void wcd_clsh_state_hph_lo(struct snd_soc_component *component,
- struct wcd_clsh_cdc_data *clsh_d,
- u8 req_state, bool is_enable, int mode)
- {
- int hph_mode = 0;
- dev_dbg(component->dev, "%s: mode: %s, %s\n", __func__,
- mode_to_str(mode),
- is_enable ? "enable" : "disable");
- if (is_enable) {
-
- if (req_state == WCD_CLSH_STATE_LO)
- wcd_clsh_set_buck_regulator_mode(component, CLS_AB);
- else {
- if (!wcd_clsh_enable_status(component)) {
- wcd_enable_clsh_block(component, clsh_d, true);
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_CLSH_K1_MSB,
- 0x0F, 0x00);
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_CLSH_K1_LSB,
- 0xFF, 0xC0);
- wcd_clsh_set_flyback_mode(component, mode);
- wcd_clsh_set_flyback_vneg_ctl(component, false);
- wcd_clsh_set_buck_mode(component, mode);
- wcd_clsh_set_hph_mode(component, mode);
- wcd_clsh_set_gain_path(component, mode);
- } else {
- dev_dbg(component->dev, "%s:clsh is already enabled\n",
- __func__);
- }
- if (req_state == WCD_CLSH_STATE_HPHL)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX1_RX_PATH_CFG0,
- 0x40, 0x40);
- if (req_state == WCD_CLSH_STATE_HPHR)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX2_RX_PATH_CFG0,
- 0x40, 0x40);
- }
- } else {
- if ((req_state == WCD_CLSH_STATE_HPHL) ||
- (req_state == WCD_CLSH_STATE_HPHR)) {
- if (req_state == WCD_CLSH_STATE_HPHL)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX1_RX_PATH_CFG0,
- 0x40, 0x00);
- if (req_state == WCD_CLSH_STATE_HPHR)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX2_RX_PATH_CFG0,
- 0x40, 0x00);
-
- if ((clsh_d->state & WCD_CLSH_STATE_HPH_ST)
- != WCD_CLSH_STATE_HPH_ST) {
- wcd_enable_clsh_block(component, clsh_d, false);
- wcd_clsh_set_flyback_vneg_ctl(component, true);
- wcd_clsh_set_flyback_mode(
- component, CLS_H_NORMAL);
- wcd_clsh_set_buck_mode(component, CLS_H_NORMAL);
- }
- } else {
-
- if (clsh_d->state & WCD_CLSH_STATE_HPHL)
- hph_mode = wcd_clsh_get_int_mode(clsh_d,
- WCD_CLSH_STATE_HPHL);
- else if (clsh_d->state & WCD_CLSH_STATE_HPHR)
- hph_mode = wcd_clsh_get_int_mode(clsh_d,
- WCD_CLSH_STATE_HPHR);
- else
- return;
- dev_dbg(component->dev, "%s: hph_mode = %d\n", __func__,
- hph_mode);
- if ((hph_mode == CLS_AB) ||
- (hph_mode == CLS_AB_HIFI) ||
- (hph_mode == CLS_NONE))
- goto end;
-
- if (wcd_clsh_enable_status(component)) {
- wcd_clsh_set_buck_regulator_mode(component,
- hph_mode);
- goto end;
- } else {
- dev_dbg(component->dev, "%s: clsh is not enabled\n",
- __func__);
- }
- wcd_enable_clsh_block(component, clsh_d, true);
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_CLSH_K1_MSB,
- 0x0F, 0x00);
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_CLSH_K1_LSB,
- 0xFF, 0xC0);
- wcd_clsh_set_buck_regulator_mode(component,
- hph_mode);
- if (clsh_d->state & WCD_CLSH_STATE_HPHL)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX1_RX_PATH_CFG0,
- 0x40, 0x40);
- if (clsh_d->state & WCD_CLSH_STATE_HPHR)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX2_RX_PATH_CFG0,
- 0x40, 0x40);
- wcd_clsh_set_hph_mode(component, hph_mode);
- }
- }
- end:
- return;
- }
- static void wcd_clsh_state_hph_st(struct snd_soc_component *component,
- struct wcd_clsh_cdc_data *clsh_d,
- u8 req_state, bool is_enable, int mode)
- {
- dev_dbg(component->dev, "%s: mode: %s, %s\n", __func__,
- mode_to_str(mode),
- is_enable ? "enable" : "disable");
- if (mode == CLS_AB || mode == CLS_AB_HIFI)
- return;
- if (is_enable) {
- if (req_state == WCD_CLSH_STATE_HPHL)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX1_RX_PATH_CFG0,
- 0x40, 0x40);
- if (req_state == WCD_CLSH_STATE_HPHR)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX2_RX_PATH_CFG0,
- 0x40, 0x40);
- } else {
- if (req_state == WCD_CLSH_STATE_HPHL)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX1_RX_PATH_CFG0,
- 0x40, 0x00);
- if (req_state == WCD_CLSH_STATE_HPHR)
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX2_RX_PATH_CFG0,
- 0x40, 0x00);
- }
- }
- static void wcd_clsh_state_hph_r(struct snd_soc_component *component,
- struct wcd_clsh_cdc_data *clsh_d,
- u8 req_state, bool is_enable, int mode)
- {
- dev_dbg(component->dev, "%s: mode: %s, %s\n", __func__,
- mode_to_str(mode),
- is_enable ? "enable" : "disable");
- if (mode == CLS_H_NORMAL) {
- dev_err_ratelimited(component->dev, "%s: Normal mode not applicable for hph_r\n",
- __func__);
- return;
- }
- if (is_enable) {
- if (mode != CLS_AB && mode != CLS_AB_HIFI) {
- wcd_enable_clsh_block(component, clsh_d, true);
-
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_CLSH_K1_MSB,
- 0x0F, 0x00);
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_CLSH_K1_LSB,
- 0xFF, 0xC0);
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX2_RX_PATH_CFG0,
- 0x40, 0x40);
- }
- wcd_clsh_set_buck_regulator_mode(component, mode);
- wcd_clsh_set_flyback_mode(component, mode);
- wcd_clsh_gm3_boost_disable(component, mode);
- wcd_clsh_force_iq_ctl(component, mode);
- wcd_clsh_flyback_ctrl(component, clsh_d, mode, true);
- wcd_clsh_set_flyback_current(component, mode);
- wcd_clsh_set_buck_mode(component, mode);
- wcd_clsh_buck_ctrl(component, clsh_d, mode, true);
- wcd_clsh_set_hph_mode(component, mode);
- wcd_clsh_set_gain_path(component, mode);
- } else {
- wcd_clsh_set_hph_mode(component, CLS_H_NORMAL);
- if (mode != CLS_AB && mode != CLS_AB_HIFI) {
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX2_RX_PATH_CFG0,
- 0x40, 0x00);
- wcd_enable_clsh_block(component, clsh_d, false);
- }
-
- wcd_clsh_buck_ctrl(component, clsh_d, CLS_H_NORMAL, false);
- wcd_clsh_flyback_ctrl(component, clsh_d, CLS_H_NORMAL, false);
- wcd_clsh_force_iq_ctl(component, CLS_H_NORMAL);
- wcd_clsh_gm3_boost_disable(component, CLS_H_NORMAL);
- wcd_clsh_set_flyback_mode(component, CLS_H_NORMAL);
- wcd_clsh_set_buck_mode(component, CLS_H_NORMAL);
- wcd_clsh_set_buck_regulator_mode(component, CLS_H_NORMAL);
- }
- }
- static void wcd_clsh_state_hph_l(struct snd_soc_component *component,
- struct wcd_clsh_cdc_data *clsh_d,
- u8 req_state, bool is_enable, int mode)
- {
- dev_dbg(component->dev, "%s: mode: %s, %s\n", __func__,
- mode_to_str(mode),
- is_enable ? "enable" : "disable");
- if (mode == CLS_H_NORMAL) {
- dev_err_ratelimited(component->dev, "%s: Normal mode not applicable for hph_l\n",
- __func__);
- return;
- }
- if (is_enable) {
- if (mode != CLS_AB && mode != CLS_AB_HIFI) {
- wcd_enable_clsh_block(component, clsh_d, true);
-
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_CLSH_K1_MSB,
- 0x0F, 0x00);
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_CLSH_K1_LSB,
- 0xFF, 0xC0);
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX1_RX_PATH_CFG0,
- 0x40, 0x40);
- }
- wcd_clsh_set_buck_regulator_mode(component, mode);
- wcd_clsh_set_flyback_mode(component, mode);
- wcd_clsh_gm3_boost_disable(component, mode);
- wcd_clsh_force_iq_ctl(component, mode);
- wcd_clsh_flyback_ctrl(component, clsh_d, mode, true);
- wcd_clsh_set_flyback_current(component, mode);
- wcd_clsh_set_buck_mode(component, mode);
- wcd_clsh_buck_ctrl(component, clsh_d, mode, true);
- wcd_clsh_set_hph_mode(component, mode);
- wcd_clsh_set_gain_path(component, mode);
- } else {
- wcd_clsh_set_hph_mode(component, CLS_H_NORMAL);
- if (mode != CLS_AB && mode != CLS_AB_HIFI) {
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX1_RX_PATH_CFG0,
- 0x40, 0x00);
- wcd_enable_clsh_block(component, clsh_d, false);
- }
-
- wcd_clsh_buck_ctrl(component, clsh_d, CLS_H_NORMAL, false);
- wcd_clsh_flyback_ctrl(component, clsh_d, CLS_H_NORMAL, false);
- wcd_clsh_force_iq_ctl(component, CLS_H_NORMAL);
- wcd_clsh_gm3_boost_disable(component, CLS_H_NORMAL);
- wcd_clsh_set_flyback_mode(component, CLS_H_NORMAL);
- wcd_clsh_set_buck_mode(component, CLS_H_NORMAL);
- wcd_clsh_set_buck_regulator_mode(component, CLS_H_NORMAL);
- }
- }
- static void wcd_clsh_state_ear(struct snd_soc_component *component,
- struct wcd_clsh_cdc_data *clsh_d,
- u8 req_state, bool is_enable, int mode)
- {
- dev_dbg(component->dev, "%s: mode: %s, %s\n", __func__,
- mode_to_str(mode),
- is_enable ? "enable" : "disable");
- if (mode != CLS_H_NORMAL) {
- dev_err_ratelimited(component->dev, "%s: mode: %s cannot be used for EAR\n",
- __func__, mode_to_str(mode));
- return;
- }
- if (is_enable) {
- wcd_enable_clsh_block(component, clsh_d, true);
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX0_RX_PATH_CFG0,
- 0x40, 0x40);
- wcd_clsh_set_buck_mode(component, mode);
- wcd_clsh_set_flyback_mode(component, mode);
- wcd_clsh_flyback_ctrl(component, clsh_d, mode, true);
- wcd_clsh_set_flyback_current(component, mode);
- wcd_clsh_buck_ctrl(component, clsh_d, mode, true);
- } else {
- snd_soc_component_update_bits(component,
- WCD9XXX_A_CDC_RX0_RX_PATH_CFG0,
- 0x40, 0x00);
- wcd_enable_clsh_block(component, clsh_d, false);
- wcd_clsh_buck_ctrl(component, clsh_d, mode, false);
- wcd_clsh_flyback_ctrl(component, clsh_d, mode, false);
- wcd_clsh_set_flyback_mode(component, CLS_H_NORMAL);
- wcd_clsh_set_buck_mode(component, CLS_H_NORMAL);
- }
- }
- static void wcd_clsh_state_err(struct snd_soc_component *component,
- struct wcd_clsh_cdc_data *clsh_d,
- u8 req_state, bool is_enable, int mode)
- {
- char msg[128];
- dev_err_ratelimited(component->dev,
- "%s Wrong request for class H state machine requested to %s %s",
- __func__, is_enable ? "enable" : "disable",
- state_to_str(req_state, msg, sizeof(msg)));
- WARN_ON(1);
- }
- static bool wcd_clsh_is_state_valid(u8 state)
- {
- switch (state) {
- case WCD_CLSH_STATE_IDLE:
- case WCD_CLSH_STATE_EAR:
- case WCD_CLSH_STATE_HPHL:
- case WCD_CLSH_STATE_HPHR:
- case WCD_CLSH_STATE_HPH_ST:
- case WCD_CLSH_STATE_LO:
- case WCD_CLSH_STATE_HPHL_EAR:
- case WCD_CLSH_STATE_HPHR_EAR:
- case WCD_CLSH_STATE_HPH_ST_EAR:
- case WCD_CLSH_STATE_HPHL_LO:
- case WCD_CLSH_STATE_HPHR_LO:
- case WCD_CLSH_STATE_HPH_ST_LO:
- case WCD_CLSH_STATE_EAR_LO:
- return true;
- default:
- return false;
- };
- }
- void wcd_clsh_fsm(struct snd_soc_component *component,
- struct wcd_clsh_cdc_data *cdc_clsh_d,
- u8 clsh_event, u8 req_state,
- int int_mode)
- {
- u8 old_state, new_state;
- char msg0[128], msg1[128];
- switch (clsh_event) {
- case WCD_CLSH_EVENT_PRE_DAC:
- old_state = cdc_clsh_d->state;
- new_state = old_state | req_state;
- if (!wcd_clsh_is_state_valid(new_state)) {
- dev_err_ratelimited(component->dev,
- "%s: Class-H not a valid new state: %s\n",
- __func__,
- state_to_str(new_state, msg0, sizeof(msg0)));
- return;
- }
- if (new_state == old_state) {
- dev_err_ratelimited(component->dev,
- "%s: Class-H already in requested state: %s\n",
- __func__,
- state_to_str(new_state, msg0, sizeof(msg0)));
- return;
- }
- cdc_clsh_d->state = new_state;
- wcd_clsh_set_int_mode(cdc_clsh_d, req_state, int_mode);
- (*clsh_state_fp[new_state]) (component, cdc_clsh_d, req_state,
- CLSH_REQ_ENABLE, int_mode);
- dev_dbg(component->dev,
- "%s: ClassH state transition from %s to %s\n",
- __func__, state_to_str(old_state, msg0, sizeof(msg0)),
- state_to_str(cdc_clsh_d->state, msg1, sizeof(msg1)));
- break;
- case WCD_CLSH_EVENT_POST_PA:
- old_state = cdc_clsh_d->state;
- new_state = old_state & (~req_state);
- if (new_state < NUM_CLSH_STATES_V2) {
- if (!wcd_clsh_is_state_valid(old_state)) {
- dev_err_ratelimited(component->dev,
- "%s:Invalid old state:%s\n",
- __func__,
- state_to_str(old_state, msg0,
- sizeof(msg0)));
- return;
- }
- if (new_state == old_state) {
- dev_err_ratelimited(component->dev,
- "%s: Class-H already in requested state: %s\n",
- __func__,
- state_to_str(new_state, msg0,
- sizeof(msg0)));
- return;
- }
- (*clsh_state_fp[old_state]) (component, cdc_clsh_d,
- req_state, CLSH_REQ_DISABLE,
- int_mode);
- cdc_clsh_d->state = new_state;
- wcd_clsh_set_int_mode(cdc_clsh_d, req_state, CLS_NONE);
- dev_dbg(component->dev, "%s: ClassH state transition from %s to %s\n",
- __func__, state_to_str(old_state, msg0,
- sizeof(msg0)),
- state_to_str(cdc_clsh_d->state, msg1,
- sizeof(msg1)));
- }
- break;
- };
- }
- EXPORT_SYMBOL(wcd_clsh_fsm);
- int wcd_clsh_get_clsh_state(struct wcd_clsh_cdc_data *clsh)
- {
- return clsh->state;
- }
- EXPORT_SYMBOL(wcd_clsh_get_clsh_state);
- void wcd_clsh_init(struct wcd_clsh_cdc_data *clsh)
- {
- int i;
- clsh->state = WCD_CLSH_STATE_IDLE;
- for (i = 0; i < NUM_CLSH_STATES_V2; i++)
- clsh_state_fp[i] = wcd_clsh_state_err;
- clsh_state_fp[WCD_CLSH_STATE_EAR] = wcd_clsh_state_ear;
- clsh_state_fp[WCD_CLSH_STATE_HPHL] =
- wcd_clsh_state_hph_l;
- clsh_state_fp[WCD_CLSH_STATE_HPHR] =
- wcd_clsh_state_hph_r;
- clsh_state_fp[WCD_CLSH_STATE_HPH_ST] =
- wcd_clsh_state_hph_st;
- clsh_state_fp[WCD_CLSH_STATE_LO] = wcd_clsh_state_lo;
- clsh_state_fp[WCD_CLSH_STATE_HPHL_EAR] =
- wcd_clsh_state_hph_ear;
- clsh_state_fp[WCD_CLSH_STATE_HPHR_EAR] =
- wcd_clsh_state_hph_ear;
- clsh_state_fp[WCD_CLSH_STATE_HPH_ST_EAR] =
- wcd_clsh_state_hph_ear;
- clsh_state_fp[WCD_CLSH_STATE_HPHL_LO] = wcd_clsh_state_hph_lo;
- clsh_state_fp[WCD_CLSH_STATE_HPHR_LO] = wcd_clsh_state_hph_lo;
- clsh_state_fp[WCD_CLSH_STATE_HPH_ST_LO] =
- wcd_clsh_state_hph_lo;
- clsh_state_fp[WCD_CLSH_STATE_EAR_LO] = wcd_clsh_state_ear_lo;
-
- wcd_clsh_set_int_mode(clsh, WCD_CLSH_STATE_EAR, CLS_NONE);
- wcd_clsh_set_int_mode(clsh, WCD_CLSH_STATE_HPHL, CLS_NONE);
- wcd_clsh_set_int_mode(clsh, WCD_CLSH_STATE_HPHR, CLS_NONE);
- wcd_clsh_set_int_mode(clsh, WCD_CLSH_STATE_LO, CLS_NONE);
- clsh->flyback_users = 0;
- clsh->buck_users = 0;
- clsh->clsh_users = 0;
- }
- EXPORT_SYMBOL(wcd_clsh_init);
- MODULE_DESCRIPTION("WCD9XXX Common Driver");
- MODULE_LICENSE("GPL v2");
|