67
73
unsigned int step_delay;
75
struct delayed_work work;
70
76
struct completion ramp_done;
73
79
struct twl6040_jack_data {
74
80
struct snd_soc_jack *jack;
81
struct delayed_work work;
78
85
/* codec private data */
79
86
struct twl6040_data {
92
int hs_power_mode_locked;
85
94
unsigned int sysclk;
86
struct snd_pcm_hw_constraint_list *sysclk_constraints;
87
struct completion ready;
88
99
struct twl6040_jack_data hs_jack;
89
100
struct snd_soc_codec *codec;
90
101
struct workqueue_struct *workqueue;
91
struct delayed_work delayed_work;
92
102
struct mutex mutex;
93
103
struct twl6040_output headset;
94
104
struct twl6040_output handsfree;
95
struct workqueue_struct *hf_workqueue;
96
struct workqueue_struct *hs_workqueue;
97
struct delayed_work hs_delayed_work;
98
struct delayed_work hf_delayed_work;
102
108
* twl6040 register cache & default register settings
104
110
static const u8 twl6040_reg[TWL6040_CACHEREGNUM] = {
105
0x00, /* not used 0x00 */
106
0x4B, /* TWL6040_ASICID (ro) 0x01 */
107
0x00, /* TWL6040_ASICREV (ro) 0x02 */
108
0x00, /* TWL6040_INTID 0x03 */
109
0x00, /* TWL6040_INTMR 0x04 */
110
0x00, /* TWL6040_NCPCTRL 0x05 */
111
0x00, /* TWL6040_LDOCTL 0x06 */
112
0x60, /* TWL6040_HPPLLCTL 0x07 */
113
0x00, /* TWL6040_LPPLLCTL 0x08 */
114
0x4A, /* TWL6040_LPPLLDIV 0x09 */
115
0x00, /* TWL6040_AMICBCTL 0x0A */
116
0x00, /* TWL6040_DMICBCTL 0x0B */
117
0x18, /* TWL6040_MICLCTL 0x0C - No input selected on Left Mic */
118
0x18, /* TWL6040_MICRCTL 0x0D - No input selected on Right Mic */
119
0x00, /* TWL6040_MICGAIN 0x0E */
120
0x1B, /* TWL6040_LINEGAIN 0x0F */
121
0x00, /* TWL6040_HSLCTL 0x10 */
122
0x00, /* TWL6040_HSRCTL 0x11 */
123
0x00, /* TWL6040_HSGAIN 0x12 */
124
0x00, /* TWL6040_EARCTL 0x13 */
125
0x00, /* TWL6040_HFLCTL 0x14 */
126
0x00, /* TWL6040_HFLGAIN 0x15 */
127
0x00, /* TWL6040_HFRCTL 0x16 */
128
0x00, /* TWL6040_HFRGAIN 0x17 */
129
0x00, /* TWL6040_VIBCTLL 0x18 */
130
0x00, /* TWL6040_VIBDATL 0x19 */
131
0x00, /* TWL6040_VIBCTLR 0x1A */
132
0x00, /* TWL6040_VIBDATR 0x1B */
133
0x00, /* TWL6040_HKCTL1 0x1C */
134
0x00, /* TWL6040_HKCTL2 0x1D */
135
0x00, /* TWL6040_GPOCTL 0x1E */
136
0x00, /* TWL6040_ALB 0x1F */
137
0x00, /* TWL6040_DLB 0x20 */
138
0x00, /* not used 0x21 */
139
0x00, /* not used 0x22 */
140
0x00, /* not used 0x23 */
141
0x00, /* not used 0x24 */
142
0x00, /* not used 0x25 */
143
0x00, /* not used 0x26 */
144
0x00, /* not used 0x27 */
145
0x00, /* TWL6040_TRIM1 0x28 */
146
0x00, /* TWL6040_TRIM2 0x29 */
147
0x00, /* TWL6040_TRIM3 0x2A */
148
0x00, /* TWL6040_HSOTRIM 0x2B */
149
0x00, /* TWL6040_HFOTRIM 0x2C */
150
0x09, /* TWL6040_ACCCTL 0x2D */
151
0x00, /* TWL6040_STATUS (ro) 0x2E */
155
* twl6040 vio/gnd registers:
156
* registers under vio/gnd supply can be accessed
157
* before the power-up sequence, after NRESPWRON goes high
159
static const int twl6040_vio_reg[TWL6040_VIOREGNUM] = {
166
TWL6040_REG_AMICBCTL,
167
TWL6040_REG_DMICBCTL,
181
* twl6040 vdd/vss registers:
182
* registers under vdd/vss supplies can only be accessed
183
* after the power-up sequence
185
static const int twl6040_vdd_reg[TWL6040_VDDREGNUM] = {
186
TWL6040_REG_HPPLLCTL,
187
TWL6040_REG_LPPLLCTL,
188
TWL6040_REG_LPPLLDIV,
111
0x00, /* not used 0x00 */
112
0x4B, /* REG_ASICID 0x01 (ro) */
113
0x00, /* REG_ASICREV 0x02 (ro) */
114
0x00, /* REG_INTID 0x03 */
115
0x00, /* REG_INTMR 0x04 */
116
0x00, /* REG_NCPCTRL 0x05 */
117
0x00, /* REG_LDOCTL 0x06 */
118
0x60, /* REG_HPPLLCTL 0x07 */
119
0x00, /* REG_LPPLLCTL 0x08 */
120
0x4A, /* REG_LPPLLDIV 0x09 */
121
0x00, /* REG_AMICBCTL 0x0A */
122
0x00, /* REG_DMICBCTL 0x0B */
123
0x00, /* REG_MICLCTL 0x0C */
124
0x00, /* REG_MICRCTL 0x0D */
125
0x00, /* REG_MICGAIN 0x0E */
126
0x1B, /* REG_LINEGAIN 0x0F */
127
0x00, /* REG_HSLCTL 0x10 */
128
0x00, /* REG_HSRCTL 0x11 */
129
0x00, /* REG_HSGAIN 0x12 */
130
0x00, /* REG_EARCTL 0x13 */
131
0x00, /* REG_HFLCTL 0x14 */
132
0x00, /* REG_HFLGAIN 0x15 */
133
0x00, /* REG_HFRCTL 0x16 */
134
0x00, /* REG_HFRGAIN 0x17 */
135
0x00, /* REG_VIBCTLL 0x18 */
136
0x00, /* REG_VIBDATL 0x19 */
137
0x00, /* REG_VIBCTLR 0x1A */
138
0x00, /* REG_VIBDATR 0x1B */
139
0x00, /* REG_HKCTL1 0x1C */
140
0x00, /* REG_HKCTL2 0x1D */
141
0x00, /* REG_GPOCTL 0x1E */
142
0x00, /* REG_ALB 0x1F */
143
0x00, /* REG_DLB 0x20 */
144
0x00, /* not used 0x21 */
145
0x00, /* not used 0x22 */
146
0x00, /* not used 0x23 */
147
0x00, /* not used 0x24 */
148
0x00, /* not used 0x25 */
149
0x00, /* not used 0x26 */
150
0x00, /* not used 0x27 */
151
0x00, /* REG_TRIM1 0x28 */
152
0x00, /* REG_TRIM2 0x29 */
153
0x00, /* REG_TRIM3 0x2A */
154
0x00, /* REG_HSOTRIM 0x2B */
155
0x00, /* REG_HFOTRIM 0x2C */
156
0x09, /* REG_ACCCTL 0x2D */
157
0x00, /* REG_STATUS 0x2E (ro) */
159
0x00, /* REG_SW_SHADOW 0x2F - Shadow, non HW register */
162
/* List of registers to be restored after power up */
163
static const int twl6040_restore_list[] = {
189
164
TWL6040_REG_MICLCTL,
190
165
TWL6040_REG_MICRCTL,
191
166
TWL6040_REG_MICGAIN,
256
256
static int twl6040_write(struct snd_soc_codec *codec,
257
257
unsigned int reg, unsigned int value)
259
struct twl6040 *twl6040 = codec->control_data;
259
261
if (reg >= TWL6040_CACHEREGNUM)
262
264
twl6040_write_reg_cache(codec, reg, value);
263
return twl_i2c_write_u8(TWL_MODULE_AUDIO_VOICE, value, reg);
266
static void twl6040_init_vio_regs(struct snd_soc_codec *codec)
268
u8 *cache = codec->reg_cache;
271
/* allow registers to be accessed by i2c */
272
twl6040_write(codec, TWL6040_REG_ACCCTL, cache[TWL6040_REG_ACCCTL]);
274
for (i = 0; i < TWL6040_VIOREGNUM; i++) {
275
reg = twl6040_vio_reg[i];
276
/* skip read-only registers (ASICID, ASICREV, STATUS) */
278
case TWL6040_REG_ASICID:
279
case TWL6040_REG_ASICREV:
280
case TWL6040_REG_STATUS:
285
twl6040_write(codec, reg, cache[reg]);
289
static void twl6040_init_vdd_regs(struct snd_soc_codec *codec)
291
u8 *cache = codec->reg_cache;
294
for (i = 0; i < TWL6040_VDDREGNUM; i++) {
295
reg = twl6040_vdd_reg[i];
265
if (likely(reg < TWL6040_REG_SW_SHADOW))
266
return twl6040_reg_write(twl6040, reg, value);
271
static void twl6040_init_chip(struct snd_soc_codec *codec)
273
struct twl6040 *twl6040 = codec->control_data;
276
/* Update reg_cache: ASICREV, and TRIM values */
277
val = twl6040_get_revid(twl6040);
278
twl6040_write_reg_cache(codec, TWL6040_REG_ASICREV, val);
280
twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM1);
281
twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM2);
282
twl6040_read_reg_volatile(codec, TWL6040_REG_TRIM3);
283
twl6040_read_reg_volatile(codec, TWL6040_REG_HSOTRIM);
284
twl6040_read_reg_volatile(codec, TWL6040_REG_HFOTRIM);
286
/* Change chip defaults */
287
/* No imput selected for microphone amplifiers */
288
twl6040_write_reg_cache(codec, TWL6040_REG_MICLCTL, 0x18);
289
twl6040_write_reg_cache(codec, TWL6040_REG_MICRCTL, 0x18);
292
* We need to lower the default gain values, so the ramp code
293
* can work correctly for the first playback.
294
* This reduces the pop noise heard at the first playback.
296
twl6040_write_reg_cache(codec, TWL6040_REG_HSGAIN, 0xff);
297
twl6040_write_reg_cache(codec, TWL6040_REG_EARCTL, 0x1e);
298
twl6040_write_reg_cache(codec, TWL6040_REG_HFLGAIN, 0x1d);
299
twl6040_write_reg_cache(codec, TWL6040_REG_HFRGAIN, 0x1d);
300
twl6040_write_reg_cache(codec, TWL6040_REG_LINEGAIN, 0);
303
static void twl6040_restore_regs(struct snd_soc_codec *codec)
305
u8 *cache = codec->reg_cache;
308
for (i = 0; i < ARRAY_SIZE(twl6040_restore_list); i++) {
309
reg = twl6040_restore_list[i];
296
310
twl6040_write(codec, reg, cache[reg]);
565
600
/* don't use volume ramp for power-up */
601
out->ramp = TWL6040_RAMP_UP;
566
602
out->left_step = out->left_vol;
567
603
out->right_step = out->right_vol;
569
if (!delayed_work_pending(work)) {
570
out->ramp = TWL6040_RAMP_UP;
571
queue_delayed_work(queue, work,
572
msecs_to_jiffies(1));
605
queue_delayed_work(priv->workqueue, work, msecs_to_jiffies(1));
576
608
case SND_SOC_DAPM_PRE_PMD:
577
609
if (!out->active)
580
if (!delayed_work_pending(work)) {
581
/* use volume ramp for power-down */
584
out->ramp = TWL6040_RAMP_DOWN;
585
INIT_COMPLETION(out->ramp_done);
587
queue_delayed_work(queue, work,
588
msecs_to_jiffies(1));
590
wait_for_completion_timeout(&out->ramp_done,
591
msecs_to_jiffies(2000));
612
/* use volume ramp for power-down */
613
out->ramp = TWL6040_RAMP_DOWN;
614
INIT_COMPLETION(out->ramp_done);
616
queue_delayed_work(priv->workqueue, work, msecs_to_jiffies(1));
618
wait_for_completion_timeout(&out->ramp_done,
619
msecs_to_jiffies(2000));
599
/* twl6040 codec manual power-up sequence */
600
static void twl6040_power_up(struct snd_soc_codec *codec)
602
u8 ncpctl, ldoctl, lppllctl, accctl;
604
ncpctl = twl6040_read_reg_cache(codec, TWL6040_REG_NCPCTL);
605
ldoctl = twl6040_read_reg_cache(codec, TWL6040_REG_LDOCTL);
606
lppllctl = twl6040_read_reg_cache(codec, TWL6040_REG_LPPLLCTL);
607
accctl = twl6040_read_reg_cache(codec, TWL6040_REG_ACCCTL);
609
/* enable reference system */
610
ldoctl |= TWL6040_REFENA;
611
twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
613
/* enable internal oscillator */
614
ldoctl |= TWL6040_OSCENA;
615
twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
617
/* enable high-side ldo */
618
ldoctl |= TWL6040_HSLDOENA;
619
twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
621
/* enable negative charge pump */
622
ncpctl |= TWL6040_NCPENA | TWL6040_NCPOPEN;
623
twl6040_write(codec, TWL6040_REG_NCPCTL, ncpctl);
625
/* enable low-side ldo */
626
ldoctl |= TWL6040_LSLDOENA;
627
twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
629
/* enable low-power pll */
630
lppllctl |= TWL6040_LPLLENA;
631
twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl);
632
/* reset state machine */
633
accctl |= TWL6040_RESETSPLIT;
634
twl6040_write(codec, TWL6040_REG_ACCCTL, accctl);
636
accctl &= ~TWL6040_RESETSPLIT;
637
twl6040_write(codec, TWL6040_REG_ACCCTL, accctl);
638
/* disable internal oscillator */
639
ldoctl &= ~TWL6040_OSCENA;
640
twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
643
/* twl6040 codec manual power-down sequence */
644
static void twl6040_power_down(struct snd_soc_codec *codec)
646
u8 ncpctl, ldoctl, lppllctl, accctl;
648
ncpctl = twl6040_read_reg_cache(codec, TWL6040_REG_NCPCTL);
649
ldoctl = twl6040_read_reg_cache(codec, TWL6040_REG_LDOCTL);
650
lppllctl = twl6040_read_reg_cache(codec, TWL6040_REG_LPPLLCTL);
651
accctl = twl6040_read_reg_cache(codec, TWL6040_REG_ACCCTL);
653
/* enable internal oscillator */
654
ldoctl |= TWL6040_OSCENA;
655
twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
657
/* disable low-power pll */
658
lppllctl &= ~TWL6040_LPLLENA;
659
twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl);
660
/* disable low-side ldo */
661
ldoctl &= ~TWL6040_LSLDOENA;
662
twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
664
/* disable negative charge pump */
665
ncpctl &= ~(TWL6040_NCPENA | TWL6040_NCPOPEN);
666
twl6040_write(codec, TWL6040_REG_NCPCTL, ncpctl);
668
/* disable high-side ldo */
669
ldoctl &= ~TWL6040_HSLDOENA;
670
twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
672
/* disable internal oscillator */
673
ldoctl &= ~TWL6040_OSCENA;
674
twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
675
/* disable reference system */
676
ldoctl &= ~TWL6040_REFENA;
677
twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
681
626
/* set headset dac and driver power mode */
682
627
static int headset_power_mode(struct snd_soc_codec *codec, int high_perf)
684
629
int hslctl, hsrctl;
685
int mask = TWL6040_HSDRVMODEL | TWL6040_HSDACMODEL;
630
int mask = TWL6040_HSDRVMODE | TWL6040_HSDACMODE;
687
632
hslctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSLCTL);
688
633
hsrctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSRCTL);
704
649
static int twl6040_hs_dac_event(struct snd_soc_dapm_widget *w,
705
650
struct snd_kcontrol *kcontrol, int event)
652
struct snd_soc_codec *codec = w->codec;
656
* Workaround for Headset DC offset caused pop noise:
657
* Both HS DAC need to be turned on (before the HS driver) and off at
660
hslctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSLCTL);
661
hsrctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSRCTL);
662
if (SND_SOC_DAPM_EVENT_ON(event)) {
663
hslctl |= TWL6040_HSDACENA;
664
hsrctl |= TWL6040_HSDACENA;
666
hslctl &= ~TWL6040_HSDACENA;
667
hsrctl &= ~TWL6040_HSDACENA;
669
twl6040_write(codec, TWL6040_REG_HSLCTL, hslctl);
670
twl6040_write(codec, TWL6040_REG_HSRCTL, hsrctl);
711
static int twl6040_power_mode_event(struct snd_soc_dapm_widget *w,
676
static int twl6040_ep_drv_event(struct snd_soc_dapm_widget *w,
712
677
struct snd_kcontrol *kcontrol, int event)
714
679
struct snd_soc_codec *codec = w->codec;
715
680
struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
717
if (SND_SOC_DAPM_EVENT_ON(event))
683
if (SND_SOC_DAPM_EVENT_ON(event)) {
684
/* Earphone doesn't support low power mode */
685
priv->hs_power_mode_locked = 1;
686
ret = headset_power_mode(codec, 1);
688
priv->hs_power_mode_locked = 0;
689
ret = headset_power_mode(codec, priv->hs_power_mode);
727
697
static void twl6040_hs_jack_report(struct snd_soc_codec *codec,
840
793
struct twl6040_output *out = &twl6040_priv->headset;
841
794
struct soc_mixer_control *mc =
842
795
(struct soc_mixer_control *)kcontrol->private_value;
843
unsigned int reg = mc->reg;
846
798
case TWL6040_REG_HSGAIN:
847
799
out = &twl6040_priv->headset;
848
ucontrol->value.integer.value[0] = out->left_vol;
849
ucontrol->value.integer.value[1] = out->right_vol;
856
return snd_soc_get_volsw(kcontrol, ucontrol);
859
static int twl6040_put_volsw_2r_vu(struct snd_kcontrol *kcontrol,
860
struct snd_ctl_elem_value *ucontrol)
862
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
863
struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec);
864
struct twl6040_output *out = NULL;
865
struct soc_mixer_control *mc =
866
(struct soc_mixer_control *)kcontrol->private_value;
868
unsigned int reg = mc->reg;
870
/* For HS and HF we shadow the values and only actually write
871
* them out when active in order to ensure the amplifier comes on
872
* as quietly as possible. */
874
case TWL6040_REG_HFLGAIN:
875
case TWL6040_REG_HFRGAIN:
876
out = &twl6040_priv->handsfree;
883
out->left_vol = ucontrol->value.integer.value[0];
884
out->right_vol = ucontrol->value.integer.value[1];
889
ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
896
static int twl6040_get_volsw_2r(struct snd_kcontrol *kcontrol,
897
struct snd_ctl_elem_value *ucontrol)
899
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
900
struct twl6040_data *twl6040_priv = snd_soc_codec_get_drvdata(codec);
901
struct twl6040_output *out = &twl6040_priv->handsfree;
902
struct soc_mixer_control *mc =
903
(struct soc_mixer_control *)kcontrol->private_value;
904
unsigned int reg = mc->reg;
906
/* If these are cached registers use the cache */
908
case TWL6040_REG_HFLGAIN:
909
case TWL6040_REG_HFRGAIN:
910
out = &twl6040_priv->handsfree;
911
ucontrol->value.integer.value[0] = out->left_vol;
912
ucontrol->value.integer.value[1] = out->right_vol;
919
return snd_soc_get_volsw_2r(kcontrol, ucontrol);
922
/* double control with volume update */
923
#define SOC_TWL6040_DOUBLE_TLV(xname, xreg, shift_left, shift_right, xmax,\
925
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
926
.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
927
SNDRV_CTL_ELEM_ACCESS_READWRITE,\
928
.tlv.p = (tlv_array), \
929
.info = snd_soc_info_volsw, .get = twl6040_get_volsw, \
930
.put = twl6040_put_volsw, \
931
.private_value = (unsigned long)&(struct soc_mixer_control) \
932
{.reg = xreg, .shift = shift_left, .rshift = shift_right,\
933
.max = xmax, .platform_max = xmax, .invert = xinvert} }
935
/* double control with volume update */
936
#define SOC_TWL6040_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax,\
938
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
939
.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
940
SNDRV_CTL_ELEM_ACCESS_READWRITE | \
941
SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
942
.tlv.p = (tlv_array), \
943
.info = snd_soc_info_volsw_2r, \
944
.get = twl6040_get_volsw_2r, .put = twl6040_put_volsw_2r_vu, \
945
.private_value = (unsigned long)&(struct soc_mixer_control) \
946
{.reg = reg_left, .rreg = reg_right, .shift = xshift, \
947
.rshift = xshift, .max = xmax, .invert = xinvert}, }
801
case TWL6040_REG_HFLGAIN:
802
out = &twl6040_priv->handsfree;
805
dev_warn(codec->dev, "%s: Unexpected register: 0x%02x\n",
810
ucontrol->value.integer.value[0] = out->left_vol;
811
ucontrol->value.integer.value[1] = out->right_vol;
815
static int twl6040_soc_dapm_put_vibra_enum(struct snd_kcontrol *kcontrol,
816
struct snd_ctl_elem_value *ucontrol)
818
struct snd_soc_dapm_widget_list *wlist = snd_kcontrol_chip(kcontrol);
819
struct snd_soc_dapm_widget *widget = wlist->widgets[0];
820
struct snd_soc_codec *codec = widget->codec;
821
struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
824
/* Do not allow changes while Input/FF efect is running */
825
val = twl6040_read_reg_volatile(codec, e->reg);
826
if (val & TWL6040_VIBENA && !(val & TWL6040_VIBSEL))
829
return snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
950
833
* MICATT volume control:
1037
933
static const struct snd_kcontrol_new hfr_mux_controls =
1038
934
SOC_DAPM_ENUM("Route", twl6040_hf_enum[1]);
1040
static const struct snd_kcontrol_new ep_driver_switch_controls =
1041
SOC_DAPM_SINGLE("Switch", TWL6040_REG_EARCTL, 0, 1, 0);
936
static const struct snd_kcontrol_new ep_path_enable_control =
937
SOC_DAPM_SINGLE("Switch", TWL6040_REG_SW_SHADOW, 0, 1, 0);
939
static const struct snd_kcontrol_new auxl_switch_control =
940
SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFLCTL, 6, 1, 0);
942
static const struct snd_kcontrol_new auxr_switch_control =
943
SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFRCTL, 6, 1, 0);
945
/* Vibra playback switches */
946
static const struct snd_kcontrol_new vibral_mux_controls =
947
SOC_DAPM_ENUM_EXT("Route", twl6040_vibra_enum[0],
948
snd_soc_dapm_get_enum_double,
949
twl6040_soc_dapm_put_vibra_enum);
951
static const struct snd_kcontrol_new vibrar_mux_controls =
952
SOC_DAPM_ENUM_EXT("Route", twl6040_vibra_enum[1],
953
snd_soc_dapm_get_enum_double,
954
twl6040_soc_dapm_put_vibra_enum);
956
/* Headset power mode */
957
static const char *twl6040_power_mode_texts[] = {
958
"Low-Power", "High-Perfomance",
961
static const struct soc_enum twl6040_power_mode_enum =
962
SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(twl6040_power_mode_texts),
963
twl6040_power_mode_texts);
965
static int twl6040_headset_power_get_enum(struct snd_kcontrol *kcontrol,
966
struct snd_ctl_elem_value *ucontrol)
968
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
969
struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
971
ucontrol->value.enumerated.item[0] = priv->hs_power_mode;
976
static int twl6040_headset_power_put_enum(struct snd_kcontrol *kcontrol,
977
struct snd_ctl_elem_value *ucontrol)
979
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
980
struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
981
int high_perf = ucontrol->value.enumerated.item[0];
984
if (!priv->hs_power_mode_locked)
985
ret = headset_power_mode(codec, high_perf);
988
priv->hs_power_mode = high_perf;
993
static int twl6040_pll_get_enum(struct snd_kcontrol *kcontrol,
994
struct snd_ctl_elem_value *ucontrol)
996
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
997
struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
999
ucontrol->value.enumerated.item[0] = priv->pll_power_mode;
1004
static int twl6040_pll_put_enum(struct snd_kcontrol *kcontrol,
1005
struct snd_ctl_elem_value *ucontrol)
1007
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1008
struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
1010
priv->pll_power_mode = ucontrol->value.enumerated.item[0];
1015
int twl6040_get_clk_id(struct snd_soc_codec *codec)
1017
struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
1019
return priv->pll_power_mode;
1021
EXPORT_SYMBOL_GPL(twl6040_get_clk_id);
1023
int twl6040_get_trim_value(struct snd_soc_codec *codec, enum twl6040_trim trim)
1025
if (unlikely(trim >= TWL6040_TRIM_INVAL))
1028
return twl6040_read_reg_cache(codec, TWL6040_REG_TRIM1 + trim);
1030
EXPORT_SYMBOL_GPL(twl6040_get_trim_value);
1043
1032
static const struct snd_kcontrol_new twl6040_snd_controls[] = {
1044
1033
/* Capture gains */
1052
1041
TWL6040_REG_LINEGAIN, 0, 3, 7, 0, afm_amp_tlv),
1054
1043
/* Playback gains */
1055
SOC_TWL6040_DOUBLE_TLV("Headset Playback Volume",
1056
TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, hs_tlv),
1057
SOC_TWL6040_DOUBLE_R_TLV("Handsfree Playback Volume",
1058
TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, hf_tlv),
1044
SOC_DOUBLE_EXT_TLV("Headset Playback Volume",
1045
TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, twl6040_get_volsw,
1046
twl6040_put_volsw, hs_tlv),
1047
SOC_DOUBLE_R_EXT_TLV("Handsfree Playback Volume",
1048
TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1,
1049
twl6040_get_volsw, twl6040_put_volsw, hf_tlv),
1059
1050
SOC_SINGLE_TLV("Earphone Playback Volume",
1060
1051
TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv),
1053
SOC_ENUM_EXT("Headset Power Mode", twl6040_power_mode_enum,
1054
twl6040_headset_power_get_enum,
1055
twl6040_headset_power_put_enum),
1057
SOC_ENUM_EXT("PLL Selection", twl6040_power_mode_enum,
1058
twl6040_pll_get_enum, twl6040_pll_put_enum),
1063
1061
static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = {
1110
1112
TWL6040_REG_DMICBCTL, 4, 0),
1113
SND_SOC_DAPM_DAC_E("HSDAC Left", "Headset Playback",
1114
TWL6040_REG_HSLCTL, 0, 0,
1115
twl6040_hs_dac_event,
1116
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1117
SND_SOC_DAPM_DAC_E("HSDAC Right", "Headset Playback",
1118
TWL6040_REG_HSRCTL, 0, 0,
1119
twl6040_hs_dac_event,
1120
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1121
SND_SOC_DAPM_DAC_E("HFDAC Left", "Handsfree Playback",
1122
TWL6040_REG_HFLCTL, 0, 0,
1123
twl6040_power_mode_event,
1124
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1125
SND_SOC_DAPM_DAC_E("HFDAC Right", "Handsfree Playback",
1126
TWL6040_REG_HFRCTL, 0, 0,
1127
twl6040_power_mode_event,
1128
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1115
SND_SOC_DAPM_DAC("HSDAC Left", "Headset Playback", SND_SOC_NOPM, 0, 0),
1116
SND_SOC_DAPM_DAC("HSDAC Right", "Headset Playback", SND_SOC_NOPM, 0, 0),
1117
SND_SOC_DAPM_DAC("HFDAC Left", "Handsfree Playback",
1118
TWL6040_REG_HFLCTL, 0, 0),
1119
SND_SOC_DAPM_DAC("HFDAC Right", "Handsfree Playback",
1120
TWL6040_REG_HFRCTL, 0, 0),
1121
/* Virtual DAC for vibra path (DL4 channel) */
1122
SND_SOC_DAPM_DAC("VIBRA DAC", "Vibra Playback",
1123
SND_SOC_NOPM, 0, 0),
1130
SND_SOC_DAPM_MUX("HF Left Playback",
1125
SND_SOC_DAPM_MUX("Handsfree Left Playback",
1131
1126
SND_SOC_NOPM, 0, 0, &hfl_mux_controls),
1132
SND_SOC_DAPM_MUX("HF Right Playback",
1127
SND_SOC_DAPM_MUX("Handsfree Right Playback",
1133
1128
SND_SOC_NOPM, 0, 0, &hfr_mux_controls),
1134
1129
/* Analog playback Muxes */
1135
SND_SOC_DAPM_MUX("HS Left Playback",
1130
SND_SOC_DAPM_MUX("Headset Left Playback",
1136
1131
SND_SOC_NOPM, 0, 0, &hsl_mux_controls),
1137
SND_SOC_DAPM_MUX("HS Right Playback",
1132
SND_SOC_DAPM_MUX("Headset Right Playback",
1138
1133
SND_SOC_NOPM, 0, 0, &hsr_mux_controls),
1135
SND_SOC_DAPM_MUX("Vibra Left Playback", SND_SOC_NOPM, 0, 0,
1136
&vibral_mux_controls),
1137
SND_SOC_DAPM_MUX("Vibra Right Playback", SND_SOC_NOPM, 0, 0,
1138
&vibrar_mux_controls),
1140
SND_SOC_DAPM_SWITCH("Earphone Playback", SND_SOC_NOPM, 0, 0,
1141
&ep_path_enable_control),
1142
SND_SOC_DAPM_SWITCH("AUXL Playback", SND_SOC_NOPM, 0, 0,
1143
&auxl_switch_control),
1144
SND_SOC_DAPM_SWITCH("AUXR Playback", SND_SOC_NOPM, 0, 0,
1145
&auxr_switch_control),
1140
1147
/* Analog playback drivers */
1141
SND_SOC_DAPM_OUT_DRV_E("Handsfree Left Driver",
1148
SND_SOC_DAPM_OUT_DRV_E("HF Left Driver",
1142
1149
TWL6040_REG_HFLCTL, 4, 0, NULL, 0,
1144
1151
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1145
SND_SOC_DAPM_OUT_DRV_E("Handsfree Right Driver",
1152
SND_SOC_DAPM_OUT_DRV_E("HF Right Driver",
1146
1153
TWL6040_REG_HFRCTL, 4, 0, NULL, 0,
1148
1155
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1149
SND_SOC_DAPM_OUT_DRV_E("Headset Left Driver",
1156
SND_SOC_DAPM_OUT_DRV_E("HS Left Driver",
1150
1157
TWL6040_REG_HSLCTL, 2, 0, NULL, 0,
1152
1159
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1153
SND_SOC_DAPM_OUT_DRV_E("Headset Right Driver",
1160
SND_SOC_DAPM_OUT_DRV_E("HS Right Driver",
1154
1161
TWL6040_REG_HSRCTL, 2, 0, NULL, 0,
1156
1163
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
1157
SND_SOC_DAPM_SWITCH_E("Earphone Driver",
1158
SND_SOC_NOPM, 0, 0, &ep_driver_switch_controls,
1159
twl6040_power_mode_event,
1160
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1164
SND_SOC_DAPM_OUT_DRV_E("Earphone Driver",
1165
TWL6040_REG_EARCTL, 0, 0, NULL, 0,
1166
twl6040_ep_drv_event,
1167
SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
1168
SND_SOC_DAPM_OUT_DRV("Vibra Left Driver",
1169
TWL6040_REG_VIBCTLL, 0, 0, NULL, 0),
1170
SND_SOC_DAPM_OUT_DRV("Vibra Right Driver",
1171
TWL6040_REG_VIBCTLR, 0, 0, NULL, 0),
1173
SND_SOC_DAPM_SUPPLY("Vibra Left Control", TWL6040_REG_VIBCTLL, 2, 0,
1175
SND_SOC_DAPM_SUPPLY("Vibra Right Control", TWL6040_REG_VIBCTLR, 2, 0,
1177
SND_SOC_DAPM_SUPPLY_S("HSDAC Power", 1, SND_SOC_NOPM, 0, 0,
1178
twl6040_hs_dac_event,
1179
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
1162
1181
/* Analog playback PGAs */
1163
SND_SOC_DAPM_PGA("HFDAC Left PGA",
1182
SND_SOC_DAPM_PGA("HF Left PGA",
1164
1183
TWL6040_REG_HFLCTL, 1, 0, NULL, 0),
1165
SND_SOC_DAPM_PGA("HFDAC Right PGA",
1184
SND_SOC_DAPM_PGA("HF Right PGA",
1166
1185
TWL6040_REG_HFRCTL, 1, 0, NULL, 0),
1184
1203
{"ADC Right", NULL, "MicAmpR"},
1187
{"AFMAmpL", "NULL", "AFML"},
1188
{"AFMAmpR", "NULL", "AFMR"},
1190
{"HS Left Playback", "HS DAC", "HSDAC Left"},
1191
{"HS Left Playback", "Line-In amp", "AFMAmpL"},
1193
{"HS Right Playback", "HS DAC", "HSDAC Right"},
1194
{"HS Right Playback", "Line-In amp", "AFMAmpR"},
1196
{"Headset Left Driver", "NULL", "HS Left Playback"},
1197
{"Headset Right Driver", "NULL", "HS Right Playback"},
1199
{"HSOL", NULL, "Headset Left Driver"},
1200
{"HSOR", NULL, "Headset Right Driver"},
1206
{"AFMAmpL", NULL, "AFML"},
1207
{"AFMAmpR", NULL, "AFMR"},
1209
{"HSDAC Left", NULL, "HSDAC Power"},
1210
{"HSDAC Right", NULL, "HSDAC Power"},
1212
{"Headset Left Playback", "HS DAC", "HSDAC Left"},
1213
{"Headset Left Playback", "Line-In amp", "AFMAmpL"},
1215
{"Headset Right Playback", "HS DAC", "HSDAC Right"},
1216
{"Headset Right Playback", "Line-In amp", "AFMAmpR"},
1218
{"HS Left Driver", NULL, "Headset Left Playback"},
1219
{"HS Right Driver", NULL, "Headset Right Playback"},
1221
{"HSOL", NULL, "HS Left Driver"},
1222
{"HSOR", NULL, "HS Right Driver"},
1202
1224
/* Earphone playback path */
1203
{"Earphone Driver", "Switch", "HSDAC Left"},
1225
{"Earphone Playback", "Switch", "HSDAC Left"},
1226
{"Earphone Driver", NULL, "Earphone Playback"},
1204
1227
{"EP", NULL, "Earphone Driver"},
1206
{"HF Left Playback", "HF DAC", "HFDAC Left"},
1207
{"HF Left Playback", "Line-In amp", "AFMAmpL"},
1209
{"HF Right Playback", "HF DAC", "HFDAC Right"},
1210
{"HF Right Playback", "Line-In amp", "AFMAmpR"},
1212
{"HFDAC Left PGA", NULL, "HF Left Playback"},
1213
{"HFDAC Right PGA", NULL, "HF Right Playback"},
1215
{"Handsfree Left Driver", "Switch", "HFDAC Left PGA"},
1216
{"Handsfree Right Driver", "Switch", "HFDAC Right PGA"},
1218
{"HFL", NULL, "Handsfree Left Driver"},
1219
{"HFR", NULL, "Handsfree Right Driver"},
1229
{"Handsfree Left Playback", "HF DAC", "HFDAC Left"},
1230
{"Handsfree Left Playback", "Line-In amp", "AFMAmpL"},
1232
{"Handsfree Right Playback", "HF DAC", "HFDAC Right"},
1233
{"Handsfree Right Playback", "Line-In amp", "AFMAmpR"},
1235
{"HF Left PGA", NULL, "Handsfree Left Playback"},
1236
{"HF Right PGA", NULL, "Handsfree Right Playback"},
1238
{"HF Left Driver", NULL, "HF Left PGA"},
1239
{"HF Right Driver", NULL, "HF Right PGA"},
1241
{"HFL", NULL, "HF Left Driver"},
1242
{"HFR", NULL, "HF Right Driver"},
1244
{"AUXL Playback", "Switch", "HF Left PGA"},
1245
{"AUXR Playback", "Switch", "HF Right PGA"},
1247
{"AUXL", NULL, "AUXL Playback"},
1248
{"AUXR", NULL, "AUXR Playback"},
1250
/* Vibrator paths */
1251
{"Vibra Left Playback", "Audio PDM", "VIBRA DAC"},
1252
{"Vibra Right Playback", "Audio PDM", "VIBRA DAC"},
1254
{"Vibra Left Driver", NULL, "Vibra Left Playback"},
1255
{"Vibra Right Driver", NULL, "Vibra Right Playback"},
1256
{"Vibra Left Driver", NULL, "Vibra Left Control"},
1257
{"Vibra Right Driver", NULL, "Vibra Right Control"},
1259
{"VIBRAL", NULL, "Vibra Left Driver"},
1260
{"VIBRAR", NULL, "Vibra Right Driver"},
1222
static int twl6040_add_widgets(struct snd_soc_codec *codec)
1224
struct snd_soc_dapm_context *dapm = &codec->dapm;
1226
snd_soc_dapm_new_controls(dapm, twl6040_dapm_widgets,
1227
ARRAY_SIZE(twl6040_dapm_widgets));
1228
snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon));
1229
snd_soc_dapm_new_widgets(dapm);
1234
static int twl6040_power_up_completion(struct snd_soc_codec *codec,
1237
struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
1241
time_left = wait_for_completion_timeout(&priv->ready,
1242
msecs_to_jiffies(144));
1245
twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &intid,
1247
if (!(intid & TWL6040_READYINT)) {
1248
dev_err(codec->dev, "timeout waiting for READYINT\n");
1253
priv->codec_powered = 1;
1258
1263
static int twl6040_set_bias_level(struct snd_soc_codec *codec,
1259
1264
enum snd_soc_bias_level level)
1266
struct twl6040 *twl6040 = codec->control_data;
1261
1267
struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
1262
int audpwron = priv->audpwron;
1263
int naudint = priv->naudint;
1266
1270
switch (level) {
1272
1276
if (priv->codec_powered)
1275
if (gpio_is_valid(audpwron)) {
1276
/* use AUDPWRON line */
1277
gpio_set_value(audpwron, 1);
1279
/* wait for power-up completion */
1280
ret = twl6040_power_up_completion(codec, naudint);
1284
/* sync registers updated during power-up sequence */
1285
twl6040_read_reg_volatile(codec, TWL6040_REG_NCPCTL);
1286
twl6040_read_reg_volatile(codec, TWL6040_REG_LDOCTL);
1287
twl6040_read_reg_volatile(codec, TWL6040_REG_LPPLLCTL);
1289
/* use manual power-up sequence */
1290
twl6040_power_up(codec);
1291
priv->codec_powered = 1;
1294
/* initialize vdd/vss registers with reg_cache */
1295
twl6040_init_vdd_regs(codec);
1279
ret = twl6040_power(twl6040, 1);
1283
priv->codec_powered = 1;
1285
twl6040_restore_regs(codec);
1297
1287
/* Set external boost GPO */
1298
1288
twl6040_write(codec, TWL6040_REG_GPOCTL, 0x02);
1300
/* Set initial minimal gain values */
1301
twl6040_write(codec, TWL6040_REG_HSGAIN, 0xFF);
1302
twl6040_write(codec, TWL6040_REG_EARCTL, 0x1E);
1303
twl6040_write(codec, TWL6040_REG_HFLGAIN, 0x1D);
1304
twl6040_write(codec, TWL6040_REG_HFRGAIN, 0x1D);
1306
1290
case SND_SOC_BIAS_OFF:
1307
1291
if (!priv->codec_powered)
1310
if (gpio_is_valid(audpwron)) {
1311
/* use AUDPWRON line */
1312
gpio_set_value(audpwron, 0);
1314
/* power-down sequence latency */
1317
/* sync registers updated during power-down sequence */
1318
twl6040_read_reg_volatile(codec, TWL6040_REG_NCPCTL);
1319
twl6040_read_reg_volatile(codec, TWL6040_REG_LDOCTL);
1320
twl6040_write_reg_cache(codec, TWL6040_REG_LPPLLCTL,
1323
/* use manual power-down sequence */
1324
twl6040_power_down(codec);
1294
twl6040_power(twl6040, 0);
1327
1295
priv->codec_powered = 0;
1451
1383
struct snd_soc_codec *codec = codec_dai->codec;
1452
1384
struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
1453
u8 hppllctl, lppllctl;
1455
hppllctl = twl6040_read_reg_cache(codec, TWL6040_REG_HPPLLCTL);
1456
lppllctl = twl6040_read_reg_cache(codec, TWL6040_REG_LPPLLCTL);
1458
1386
switch (clk_id) {
1459
1387
case TWL6040_SYSCLK_SEL_LPPLL:
1462
/* headset dac and driver must be in low-power mode */
1463
headset_power_mode(codec, 0);
1465
/* clk32k input requires low-power pll */
1466
lppllctl |= TWL6040_LPLLENA;
1467
twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl);
1469
lppllctl &= ~TWL6040_HPLLSEL;
1470
twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl);
1471
hppllctl &= ~TWL6040_HPLLENA;
1472
twl6040_write(codec, TWL6040_REG_HPPLLCTL, hppllctl);
1475
dev_err(codec->dev, "unknown mclk freq %d\n", freq);
1480
switch (priv->sysclk) {
1482
lppllctl |= TWL6040_LPLLFIN;
1485
lppllctl &= ~TWL6040_LPLLFIN;
1488
/* sysclk not yet configured */
1489
lppllctl &= ~TWL6040_LPLLFIN;
1490
priv->sysclk = 19200000;
1494
twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl);
1496
priv->pll = TWL6040_LPPLL_ID;
1497
priv->sysclk_constraints = &lp_constraints;
1499
1388
case TWL6040_SYSCLK_SEL_HPPLL:
1500
hppllctl &= ~TWL6040_MCLK_MSK;
1504
/* mclk input, pll enabled */
1505
hppllctl |= TWL6040_MCLK_12000KHZ |
1510
/* mclk input, pll disabled */
1511
hppllctl |= TWL6040_MCLK_19200KHZ |
1512
TWL6040_HPLLSQRENA |
1516
/* mclk input, pll enabled */
1517
hppllctl |= TWL6040_MCLK_26000KHZ |
1522
/* clk slicer, pll disabled */
1523
hppllctl |= TWL6040_MCLK_38400KHZ |
1524
TWL6040_HPLLSQRENA |
1528
dev_err(codec->dev, "unknown mclk freq %d\n", freq);
1532
/* headset dac and driver must be in high-performance mode */
1533
headset_power_mode(codec, 1);
1535
twl6040_write(codec, TWL6040_REG_HPPLLCTL, hppllctl);
1537
lppllctl |= TWL6040_HPLLSEL;
1538
twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl);
1539
lppllctl &= ~TWL6040_LPLLENA;
1540
twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl);
1542
/* high-performance pll can provide only 19.2 MHz */
1543
priv->pll = TWL6040_HPPLL_ID;
1544
priv->sysclk = 19200000;
1545
priv->sysclk_constraints = &hp_constraints;
1390
priv->clk_in = freq;
1548
1393
dev_err(codec->dev, "unknown clk_id %d\n", clk_id);
1612
1503
snd_soc_codec_set_drvdata(codec, priv);
1614
1505
priv->codec = codec;
1616
twl_i2c_read_u8(TWL_MODULE_AUDIO_VOICE, &icrev, TWL6040_REG_ASICREV);
1618
if (twl_codec && (icrev > 0))
1619
audpwron = twl_codec->audpwron_gpio;
1624
naudint = twl_codec->naudint_irq;
1628
priv->audpwron = audpwron;
1629
priv->naudint = naudint;
1630
priv->workqueue = create_singlethread_workqueue("twl6040-codec");
1506
codec->control_data = dev_get_drvdata(codec->dev->parent);
1507
codec->ignore_pmdown_time = 1;
1509
if (pdata && pdata->hs_left_step && pdata->hs_right_step) {
1510
priv->hs_left_step = pdata->hs_left_step;
1511
priv->hs_right_step = pdata->hs_right_step;
1513
priv->hs_left_step = 1;
1514
priv->hs_right_step = 1;
1517
if (pdata && pdata->hf_left_step && pdata->hf_right_step) {
1518
priv->hf_left_step = pdata->hf_left_step;
1519
priv->hf_right_step = pdata->hf_right_step;
1521
priv->hf_left_step = 1;
1522
priv->hf_right_step = 1;
1525
priv->plug_irq = platform_get_irq(pdev, 0);
1526
if (priv->plug_irq < 0) {
1527
dev_err(codec->dev, "invalid irq\n");
1532
priv->workqueue = alloc_workqueue("twl6040-codec", 0, 0);
1632
1533
if (!priv->workqueue) {
1637
INIT_DELAYED_WORK(&priv->delayed_work, twl6040_accessory_work);
1538
INIT_DELAYED_WORK(&priv->hs_jack.work, twl6040_accessory_work);
1539
INIT_DELAYED_WORK(&priv->headset.work, twl6040_pga_hs_work);
1540
INIT_DELAYED_WORK(&priv->handsfree.work, twl6040_pga_hf_work);
1639
1542
mutex_init(&priv->mutex);
1641
init_completion(&priv->ready);
1642
1544
init_completion(&priv->headset.ramp_done);
1643
1545
init_completion(&priv->handsfree.ramp_done);
1645
if (gpio_is_valid(audpwron)) {
1646
ret = gpio_request(audpwron, "audpwron");
1650
ret = gpio_direction_output(audpwron, 0);
1654
priv->codec_powered = 0;
1656
/* enable only codec ready interrupt */
1657
intmr &= ~(TWL6040_READYMSK | TWL6040_PLUGMSK);
1659
/* reset interrupt status to allow correct power up sequence */
1660
twl6040_read_reg_volatile(codec, TWL6040_REG_INTID);
1662
twl6040_write(codec, TWL6040_REG_INTMR, intmr);
1665
/* audio interrupt */
1666
ret = request_threaded_irq(naudint, NULL,
1667
twl6040_naudint_handler,
1668
IRQF_TRIGGER_LOW | IRQF_ONESHOT,
1669
"twl6040_codec", codec);
1674
/* init vio registers */
1675
twl6040_init_vio_regs(codec);
1677
priv->hf_workqueue = create_singlethread_workqueue("twl6040-hf");
1678
if (priv->hf_workqueue == NULL) {
1682
priv->hs_workqueue = create_singlethread_workqueue("twl6040-hs");
1683
if (priv->hs_workqueue == NULL) {
1688
INIT_DELAYED_WORK(&priv->hs_delayed_work, twl6040_pga_hs_work);
1689
INIT_DELAYED_WORK(&priv->hf_delayed_work, twl6040_pga_hf_work);
1547
ret = request_threaded_irq(priv->plug_irq, NULL, twl6040_audio_handler,
1548
0, "twl6040_irq_plug", codec);
1550
dev_err(codec->dev, "PLUG IRQ request failed: %d\n", ret);
1554
twl6040_init_chip(codec);
1691
1556
/* power on device */
1692
1557
ret = twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1696
snd_soc_add_controls(codec, twl6040_snd_controls,
1697
ARRAY_SIZE(twl6040_snd_controls));
1698
twl6040_add_widgets(codec);
1703
destroy_workqueue(priv->hs_workqueue);
1705
destroy_workqueue(priv->hf_workqueue);
1708
free_irq(naudint, codec);
1710
if (gpio_is_valid(audpwron))
1711
gpio_free(audpwron);
1562
free_irq(priv->plug_irq, codec);
1713
1564
destroy_workqueue(priv->workqueue);