24 #include <linux/module.h>
26 #include <linux/kernel.h>
31 #include <linux/i2c.h>
35 #include <linux/slab.h>
47 #define WM2000_NUM_SUPPLIES 3
81 static int wm2000_write(
struct i2c_client *i2c,
unsigned int reg,
84 struct wm2000_priv *wm2000 = i2c_get_clientdata(i2c);
88 static unsigned int wm2000_read(
struct i2c_client *
i2c,
unsigned int r)
90 struct wm2000_priv *wm2000 = i2c_get_clientdata(i2c);
101 static void wm2000_reset(
struct wm2000_priv *wm2000)
112 static int wm2000_poll_bit(
struct i2c_client *i2c,
118 val = wm2000_read(i2c, reg);
120 while (!(val & mask) && --timeout) {
122 val = wm2000_read(i2c, reg);
142 dev_err(&i2c->
dev,
"Failed to enable supplies: %d\n", ret);
147 dev_dbg(&i2c->
dev,
"Disabling MCLK divider\n");
151 dev_dbg(&i2c->
dev,
"Enabling MCLK divider\n");
162 dev_err(&i2c->
dev,
"ANC engine failed to reset\n");
169 dev_err(&i2c->
dev,
"ANC engine failed to initialise\n");
184 dev_err(&i2c->
dev,
"i2c_transfer() failed: %d\n", ret);
189 dev_err(&i2c->
dev,
"i2c_transfer() failed, %d != %d\n",
224 dev_err(&i2c->
dev,
"Timed out waiting for device\n");
237 static int wm2000_power_down(
struct i2c_client *i2c,
int analogue)
253 dev_err(&i2c->
dev,
"Timeout waiting for ANC power down\n");
259 dev_err(&i2c->
dev,
"Timeout waiting for ANC engine idle\n");
271 static int wm2000_enter_bypass(
struct i2c_client *i2c,
int analogue)
290 dev_err(&i2c->
dev,
"Timeout waiting for ANC disable\n");
296 dev_err(&i2c->
dev,
"Timeout waiting for ANC engine idle\n");
309 static int wm2000_exit_bypass(
struct i2c_client *i2c,
int analogue)
333 dev_err(&i2c->
dev,
"Timed out waiting for MOUSE\n");
343 static int wm2000_enter_standby(
struct i2c_client *i2c,
int analogue)
365 "Timed out waiting for ANC disable after 1ms\n");
371 "Timed out waiting for standby\n");
386 static int wm2000_exit_standby(
struct i2c_client *i2c,
int analogue)
412 dev_err(&i2c->
dev,
"Timed out waiting for MOUSE\n");
431 } anc_transitions[] = {
445 wm2000_enter_standby,
470 wm2000_enter_standby,
495 wm2000_enter_standby,
533 static int wm2000_anc_transition(
struct wm2000_priv *wm2000,
543 for (i = 0; i <
ARRAY_SIZE(anc_transitions); i++)
545 anc_transitions[i].dest == mode)
548 dev_err(&i2c->
dev,
"No transition for %d->%d\n",
554 if (!anc_transitions[i].
step[j])
556 ret = anc_transitions[
i].step[
j](i2c,
557 anc_transitions[
i].analogue);
565 static int wm2000_anc_set_mode(
struct wm2000_priv *wm2000)
578 dev_dbg(&i2c->
dev,
"Set mode %d (enabled %d, mute %d, active %d)\n",
582 return wm2000_anc_transition(wm2000, mode);
585 static int wm2000_anc_mode_get(
struct snd_kcontrol *kcontrol,
596 static int wm2000_anc_mode_put(
struct snd_kcontrol *kcontrol,
608 return wm2000_anc_set_mode(wm2000);
611 static int wm2000_speaker_get(
struct snd_kcontrol *kcontrol,
622 static int wm2000_speaker_put(
struct snd_kcontrol *kcontrol,
627 int val = ucontrol->
value.enumerated.item[0];
634 return wm2000_anc_set_mode(wm2000);
640 wm2000_anc_mode_put),
658 return wm2000_anc_set_mode(wm2000);
670 wm2000_anc_power_event,
676 {
"SPKN",
NULL,
"ANC Engine" },
677 {
"SPKP",
NULL,
"ANC Engine" },
678 {
"ANC Engine",
NULL,
"LINN" },
679 {
"ANC Engine",
NULL,
"LINP" },
687 return wm2000_anc_transition(wm2000,
ANC_OFF);
694 return wm2000_anc_set_mode(wm2000);
697 #define wm2000_suspend NULL
698 #define wm2000_resume NULL
701 static bool wm2000_readable_reg(
struct device *
dev,
unsigned int reg)
728 static const struct regmap_config wm2000_regmap = {
733 .readable_reg = wm2000_readable_reg,
741 wm2000_anc_set_mode(wm2000);
750 return wm2000_anc_transition(wm2000,
ANC_OFF);
754 .probe = wm2000_probe,
755 .remove = wm2000_remove,
759 .dapm_widgets = wm2000_dapm_widgets,
760 .num_dapm_widgets =
ARRAY_SIZE(wm2000_dapm_widgets),
761 .dapm_routes = wm2000_audio_map,
762 .num_dapm_routes =
ARRAY_SIZE(wm2000_audio_map),
763 .controls = wm2000_controls,
780 if (wm2000 ==
NULL) {
781 dev_err(&i2c->
dev,
"Unable to allocate private data\n");
788 if (IS_ERR(wm2000->
regmap)) {
789 ret = PTR_ERR(wm2000->
regmap);
790 dev_err(&i2c->
dev,
"Failed to allocate register map: %d\n",
796 wm2000->
supplies[i].supply = wm2000_supplies[i];
801 dev_err(&i2c->
dev,
"Failed to get supplies: %d\n", ret);
807 dev_err(&i2c->
dev,
"Failed to enable supplies: %d\n", ret);
818 dev_err(&i2c->
dev,
"Device is not a WM2000 - ID %x\n",
id);
826 filename =
"wm2000_anc.bin";
827 pdata = dev_get_platdata(&i2c->
dev);
838 dev_err(&i2c->
dev,
"Failed to acquire ANC data: %d\n", ret);
862 wm2000_reset(wm2000);
887 static struct i2c_driver wm2000_i2c_driver = {
892 .probe = wm2000_i2c_probe,
894 .id_table = wm2000_i2c_id,