4 * Copyright 2007 Wolfson Microelectronics PLC.
5 * Author: Graeme Gregory
6 * graeme.gregory@wolfsonmicro.com
7 * Copyright 2011 Lars-Peter Clausen <lars@metafoo.de>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
16 #include <linux/init.h>
17 #include <linux/module.h>
18 #include <linux/i2c.h>
19 #include <linux/regmap.h>
20 #include <linux/slab.h>
22 #include <sound/core.h>
23 #include <sound/soc.h>
24 #include <sound/tlv.h>
26 static const struct reg_default lm4857_default_regs[] = {
33 /* The register offsets in the cache array */
39 /* the shifts required to set these bits */
41 #define LM4857_WAKEUP 5
42 #define LM4857_EPGAIN 4
44 static const unsigned int lm4857_mode_values[] = {
52 static const char * const lm4857_mode_texts[] = {
56 "Loudspeaker + Headphone",
60 static SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(lm4857_mode_enum,
61 LM4857_CTRL, 0, 0xf, lm4857_mode_texts, lm4857_mode_values);
63 static const struct snd_kcontrol_new lm4857_mode_ctrl =
64 SOC_DAPM_ENUM("Mode", lm4857_mode_enum);
66 static const struct snd_soc_dapm_widget lm4857_dapm_widgets[] = {
67 SND_SOC_DAPM_INPUT("IN"),
69 SND_SOC_DAPM_DEMUX("Mode", SND_SOC_NOPM, 0, 0, &lm4857_mode_ctrl),
71 SND_SOC_DAPM_OUTPUT("LS"),
72 SND_SOC_DAPM_OUTPUT("HP"),
73 SND_SOC_DAPM_OUTPUT("EP"),
76 static const DECLARE_TLV_DB_SCALE(stereo_tlv, -4050, 150, 0);
77 static const DECLARE_TLV_DB_SCALE(mono_tlv, -3450, 150, 0);
79 static const struct snd_kcontrol_new lm4857_controls[] = {
80 SOC_SINGLE_TLV("Left Playback Volume", LM4857_LVOL, 0, 31, 0,
82 SOC_SINGLE_TLV("Right Playback Volume", LM4857_RVOL, 0, 31, 0,
84 SOC_SINGLE_TLV("Mono Playback Volume", LM4857_MVOL, 0, 31, 0,
86 SOC_SINGLE("Spk 3D Playback Switch", LM4857_LVOL, LM4857_3D, 1, 0),
87 SOC_SINGLE("HP 3D Playback Switch", LM4857_RVOL, LM4857_3D, 1, 0),
88 SOC_SINGLE("Fast Wakeup Playback Switch", LM4857_CTRL,
90 SOC_SINGLE("Earpiece 6dB Playback Switch", LM4857_CTRL,
94 static const struct snd_soc_dapm_route lm4857_routes[] = {
95 { "Mode", NULL, "IN" },
96 { "LS", "Loudspeaker", "Mode" },
97 { "LS", "Loudspeaker + Headphone", "Mode" },
98 { "HP", "Headphone", "Mode" },
99 { "HP", "Loudspeaker + Headphone", "Mode" },
100 { "EP", "Earpiece", "Mode" },
103 static struct snd_soc_component_driver lm4857_component_driver = {
104 .controls = lm4857_controls,
105 .num_controls = ARRAY_SIZE(lm4857_controls),
106 .dapm_widgets = lm4857_dapm_widgets,
107 .num_dapm_widgets = ARRAY_SIZE(lm4857_dapm_widgets),
108 .dapm_routes = lm4857_routes,
109 .num_dapm_routes = ARRAY_SIZE(lm4857_routes),
112 static const struct regmap_config lm4857_regmap_config = {
116 .max_register = LM4857_CTRL,
118 .cache_type = REGCACHE_FLAT,
119 .reg_defaults = lm4857_default_regs,
120 .num_reg_defaults = ARRAY_SIZE(lm4857_default_regs),
123 static int lm4857_i2c_probe(struct i2c_client *i2c,
124 const struct i2c_device_id *id)
126 struct regmap *regmap;
128 regmap = devm_regmap_init_i2c(i2c, &lm4857_regmap_config);
130 return PTR_ERR(regmap);
132 return devm_snd_soc_register_component(&i2c->dev,
133 &lm4857_component_driver, NULL, 0);
136 static const struct i2c_device_id lm4857_i2c_id[] = {
140 MODULE_DEVICE_TABLE(i2c, lm4857_i2c_id);
142 static struct i2c_driver lm4857_i2c_driver = {
145 .owner = THIS_MODULE,
147 .probe = lm4857_i2c_probe,
148 .id_table = lm4857_i2c_id,
151 module_i2c_driver(lm4857_i2c_driver);
153 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
154 MODULE_DESCRIPTION("LM4857 amplifier driver");
155 MODULE_LICENSE("GPL");