Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 2 | /* |
| 3 | * LM4857 AMP driver |
| 4 | * |
| 5 | * Copyright 2007 Wolfson Microelectronics PLC. |
| 6 | * Author: Graeme Gregory |
Mark Brown | 9a185b9 | 2011-10-06 11:10:01 +0100 | [diff] [blame] | 7 | * graeme.gregory@wolfsonmicro.com |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 8 | * Copyright 2011 Lars-Peter Clausen <lars@metafoo.de> |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/i2c.h> |
Lars-Peter Clausen | 9b27096 | 2013-07-28 18:45:29 +0200 | [diff] [blame] | 14 | #include <linux/regmap.h> |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 15 | #include <linux/slab.h> |
| 16 | |
| 17 | #include <sound/core.h> |
| 18 | #include <sound/soc.h> |
| 19 | #include <sound/tlv.h> |
| 20 | |
Lars-Peter Clausen | 9b27096 | 2013-07-28 18:45:29 +0200 | [diff] [blame] | 21 | static const struct reg_default lm4857_default_regs[] = { |
| 22 | { 0x0, 0x00 }, |
| 23 | { 0x1, 0x00 }, |
| 24 | { 0x2, 0x00 }, |
| 25 | { 0x3, 0x00 }, |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 26 | }; |
| 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 Clausen | 0eb93ef | 2015-05-01 18:02:44 +0200 | [diff] [blame] | 39 | static const unsigned int lm4857_mode_values[] = { |
| 40 | 0, |
| 41 | 6, |
| 42 | 7, |
| 43 | 8, |
| 44 | 9, |
| 45 | }; |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 46 | |
Lars-Peter Clausen | 0eb93ef | 2015-05-01 18:02:44 +0200 | [diff] [blame] | 47 | static const char * const lm4857_mode_texts[] = { |
| 48 | "Off", |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 49 | "Earpiece", |
| 50 | "Loudspeaker", |
| 51 | "Loudspeaker + Headphone", |
| 52 | "Headphone", |
| 53 | }; |
| 54 | |
Lars-Peter Clausen | 0eb93ef | 2015-05-01 18:02:44 +0200 | [diff] [blame] | 55 | static SOC_VALUE_ENUM_SINGLE_AUTODISABLE_DECL(lm4857_mode_enum, |
| 56 | LM4857_CTRL, 0, 0xf, lm4857_mode_texts, lm4857_mode_values); |
| 57 | |
| 58 | static const struct snd_kcontrol_new lm4857_mode_ctrl = |
| 59 | SOC_DAPM_ENUM("Mode", lm4857_mode_enum); |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 60 | |
| 61 | static const struct snd_soc_dapm_widget lm4857_dapm_widgets[] = { |
| 62 | SND_SOC_DAPM_INPUT("IN"), |
| 63 | |
Lars-Peter Clausen | 0eb93ef | 2015-05-01 18:02:44 +0200 | [diff] [blame] | 64 | SND_SOC_DAPM_DEMUX("Mode", SND_SOC_NOPM, 0, 0, &lm4857_mode_ctrl), |
| 65 | |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 66 | SND_SOC_DAPM_OUTPUT("LS"), |
| 67 | SND_SOC_DAPM_OUTPUT("HP"), |
| 68 | SND_SOC_DAPM_OUTPUT("EP"), |
| 69 | }; |
| 70 | |
| 71 | static const DECLARE_TLV_DB_SCALE(stereo_tlv, -4050, 150, 0); |
| 72 | static const DECLARE_TLV_DB_SCALE(mono_tlv, -3450, 150, 0); |
| 73 | |
| 74 | static 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 Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 87 | }; |
| 88 | |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 89 | static const struct snd_soc_dapm_route lm4857_routes[] = { |
Lars-Peter Clausen | 0eb93ef | 2015-05-01 18:02:44 +0200 | [diff] [blame] | 90 | { "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 Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 96 | }; |
| 97 | |
Bhumika Goyal | 6e37f93 | 2017-08-16 22:45:09 +0530 | [diff] [blame] | 98 | static const struct snd_soc_component_driver lm4857_component_driver = { |
Lars-Peter Clausen | 07ccc0f | 2013-07-28 18:45:28 +0200 | [diff] [blame] | 99 | .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 Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 105 | }; |
| 106 | |
Lars-Peter Clausen | 9b27096 | 2013-07-28 18:45:29 +0200 | [diff] [blame] | 107 | static 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 Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 118 | static int lm4857_i2c_probe(struct i2c_client *i2c, |
| 119 | const struct i2c_device_id *id) |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 120 | { |
Lars-Peter Clausen | 0eb93ef | 2015-05-01 18:02:44 +0200 | [diff] [blame] | 121 | struct regmap *regmap; |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 122 | |
Lars-Peter Clausen | 0eb93ef | 2015-05-01 18:02:44 +0200 | [diff] [blame] | 123 | regmap = devm_regmap_init_i2c(i2c, &lm4857_regmap_config); |
| 124 | if (IS_ERR(regmap)) |
| 125 | return PTR_ERR(regmap); |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 126 | |
Lars-Peter Clausen | 08a1e64 | 2015-05-01 18:02:45 +0200 | [diff] [blame] | 127 | return devm_snd_soc_register_component(&i2c->dev, |
| 128 | &lm4857_component_driver, NULL, 0); |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static const struct i2c_device_id lm4857_i2c_id[] = { |
| 132 | { "lm4857", 0 }, |
| 133 | { } |
| 134 | }; |
| 135 | MODULE_DEVICE_TABLE(i2c, lm4857_i2c_id); |
| 136 | |
| 137 | static struct i2c_driver lm4857_i2c_driver = { |
| 138 | .driver = { |
| 139 | .name = "lm4857", |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 140 | }, |
| 141 | .probe = lm4857_i2c_probe, |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 142 | .id_table = lm4857_i2c_id, |
| 143 | }; |
| 144 | |
Sachin Kamat | f6ec139 | 2012-08-06 17:25:49 +0530 | [diff] [blame] | 145 | module_i2c_driver(lm4857_i2c_driver); |
Lars-Peter Clausen | 9b0a25f | 2011-03-07 08:04:55 +0100 | [diff] [blame] | 146 | |
| 147 | MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); |
| 148 | MODULE_DESCRIPTION("LM4857 amplifier driver"); |
| 149 | MODULE_LICENSE("GPL"); |