blob: 300b325e2fdd66a50a846291ae63a82c165e4af9 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +01002/*
3 * LM4857 AMP driver
4 *
5 * Copyright 2007 Wolfson Microelectronics PLC.
6 * Author: Graeme Gregory
Mark Brown9a185b92011-10-06 11:10:01 +01007 * graeme.gregory@wolfsonmicro.com
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +01008 * Copyright 2011 Lars-Peter Clausen <lars@metafoo.de>
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +01009 */
10
11#include <linux/init.h>
12#include <linux/module.h>
13#include <linux/i2c.h>
Lars-Peter Clausen9b270962013-07-28 18:45:29 +020014#include <linux/regmap.h>
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +010015#include <linux/slab.h>
16
17#include <sound/core.h>
18#include <sound/soc.h>
19#include <sound/tlv.h>
20
Lars-Peter Clausen9b270962013-07-28 18:45:29 +020021static const struct reg_default lm4857_default_regs[] = {
22 { 0x0, 0x00 },
23 { 0x1, 0x00 },
24 { 0x2, 0x00 },
25 { 0x3, 0x00 },
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +010026};
27
28/* The register offsets in the cache array */
29#define LM4857_MVOL 0
30#define LM4857_LVOL 1
31#define LM4857_RVOL 2
32#define LM4857_CTRL 3
33
34/* the shifts required to set these bits */
35#define LM4857_3D 5
36#define LM4857_WAKEUP 5
37#define LM4857_EPGAIN 4
38
Lars-Peter Clausen0eb93ef2015-05-01 18:02:44 +020039static const unsigned int lm4857_mode_values[] = {
40 0,
41 6,
42 7,
43 8,
44 9,
45};
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +010046
Lars-Peter Clausen0eb93ef2015-05-01 18:02:44 +020047static const char * const lm4857_mode_texts[] = {
48 "Off",
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +010049 "Earpiece",
50 "Loudspeaker",
51 "Loudspeaker + Headphone",
52 "Headphone",
53};
54
Lars-Peter Clausen0eb93ef2015-05-01 18:02:44 +020055static SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(lm4857_mode_enum,
56 LM4857_CTRL, 0, 0xf, lm4857_mode_texts, lm4857_mode_values);
57
58static const struct snd_kcontrol_new lm4857_mode_ctrl =
59 SOC_DAPM_ENUM("Mode", lm4857_mode_enum);
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +010060
61static const struct snd_soc_dapm_widget lm4857_dapm_widgets[] = {
62 SND_SOC_DAPM_INPUT("IN"),
63
Lars-Peter Clausen0eb93ef2015-05-01 18:02:44 +020064 SND_SOC_DAPM_DEMUX("Mode", SND_SOC_NOPM, 0, 0, &lm4857_mode_ctrl),
65
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +010066 SND_SOC_DAPM_OUTPUT("LS"),
67 SND_SOC_DAPM_OUTPUT("HP"),
68 SND_SOC_DAPM_OUTPUT("EP"),
69};
70
71static const DECLARE_TLV_DB_SCALE(stereo_tlv, -4050, 150, 0);
72static const DECLARE_TLV_DB_SCALE(mono_tlv, -3450, 150, 0);
73
74static const struct snd_kcontrol_new lm4857_controls[] = {
75 SOC_SINGLE_TLV("Left Playback Volume", LM4857_LVOL, 0, 31, 0,
76 stereo_tlv),
77 SOC_SINGLE_TLV("Right Playback Volume", LM4857_RVOL, 0, 31, 0,
78 stereo_tlv),
79 SOC_SINGLE_TLV("Mono Playback Volume", LM4857_MVOL, 0, 31, 0,
80 mono_tlv),
81 SOC_SINGLE("Spk 3D Playback Switch", LM4857_LVOL, LM4857_3D, 1, 0),
82 SOC_SINGLE("HP 3D Playback Switch", LM4857_RVOL, LM4857_3D, 1, 0),
83 SOC_SINGLE("Fast Wakeup Playback Switch", LM4857_CTRL,
84 LM4857_WAKEUP, 1, 0),
85 SOC_SINGLE("Earpiece 6dB Playback Switch", LM4857_CTRL,
86 LM4857_EPGAIN, 1, 0),
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +010087};
88
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +010089static const struct snd_soc_dapm_route lm4857_routes[] = {
Lars-Peter Clausen0eb93ef2015-05-01 18:02:44 +020090 { "Mode", NULL, "IN" },
91 { "LS", "Loudspeaker", "Mode" },
92 { "LS", "Loudspeaker + Headphone", "Mode" },
93 { "HP", "Headphone", "Mode" },
94 { "HP", "Loudspeaker + Headphone", "Mode" },
95 { "EP", "Earpiece", "Mode" },
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +010096};
97
Bhumika Goyal6e37f932017-08-16 22:45:09 +053098static const struct snd_soc_component_driver lm4857_component_driver = {
Lars-Peter Clausen07ccc0f2013-07-28 18:45:28 +020099 .controls = lm4857_controls,
100 .num_controls = ARRAY_SIZE(lm4857_controls),
101 .dapm_widgets = lm4857_dapm_widgets,
102 .num_dapm_widgets = ARRAY_SIZE(lm4857_dapm_widgets),
103 .dapm_routes = lm4857_routes,
104 .num_dapm_routes = ARRAY_SIZE(lm4857_routes),
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +0100105};
106
Lars-Peter Clausen9b270962013-07-28 18:45:29 +0200107static const struct regmap_config lm4857_regmap_config = {
108 .val_bits = 6,
109 .reg_bits = 2,
110
111 .max_register = LM4857_CTRL,
112
113 .cache_type = REGCACHE_FLAT,
114 .reg_defaults = lm4857_default_regs,
115 .num_reg_defaults = ARRAY_SIZE(lm4857_default_regs),
116};
117
Bill Pemberton7a79e942012-12-07 09:26:37 -0500118static int lm4857_i2c_probe(struct i2c_client *i2c,
119 const struct i2c_device_id *id)
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +0100120{
Lars-Peter Clausen0eb93ef2015-05-01 18:02:44 +0200121 struct regmap *regmap;
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +0100122
Lars-Peter Clausen0eb93ef2015-05-01 18:02:44 +0200123 regmap = devm_regmap_init_i2c(i2c, &lm4857_regmap_config);
124 if (IS_ERR(regmap))
125 return PTR_ERR(regmap);
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +0100126
Lars-Peter Clausen08a1e642015-05-01 18:02:45 +0200127 return devm_snd_soc_register_component(&i2c->dev,
128 &lm4857_component_driver, NULL, 0);
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +0100129}
130
131static const struct i2c_device_id lm4857_i2c_id[] = {
132 { "lm4857", 0 },
133 { }
134};
135MODULE_DEVICE_TABLE(i2c, lm4857_i2c_id);
136
137static struct i2c_driver lm4857_i2c_driver = {
138 .driver = {
139 .name = "lm4857",
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +0100140 },
141 .probe = lm4857_i2c_probe,
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +0100142 .id_table = lm4857_i2c_id,
143};
144
Sachin Kamatf6ec1392012-08-06 17:25:49 +0530145module_i2c_driver(lm4857_i2c_driver);
Lars-Peter Clausen9b0a25f2011-03-07 08:04:55 +0100146
147MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
148MODULE_DESCRIPTION("LM4857 amplifier driver");
149MODULE_LICENSE("GPL");