Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 2 | /* |
| 3 | * max9877.c -- amp driver for max9877 |
| 4 | * |
| 5 | * Copyright (C) 2009 Samsung Electronics Co.Ltd |
| 6 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/i2c.h> |
Mark Brown | 997288e | 2013-08-13 13:10:19 +0100 | [diff] [blame] | 12 | #include <linux/regmap.h> |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 13 | #include <sound/soc.h> |
| 14 | #include <sound/tlv.h> |
| 15 | |
| 16 | #include "max9877.h" |
| 17 | |
Axel Lin | c418a84 | 2015-07-05 17:48:29 +0800 | [diff] [blame] | 18 | static const struct reg_default max9877_regs[] = { |
Mark Brown | 997288e | 2013-08-13 13:10:19 +0100 | [diff] [blame] | 19 | { 0, 0x40 }, |
| 20 | { 1, 0x00 }, |
| 21 | { 2, 0x00 }, |
| 22 | { 3, 0x00 }, |
| 23 | { 4, 0x49 }, |
| 24 | }; |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 25 | |
Lars-Peter Clausen | d6e3bb7 | 2015-08-02 17:19:46 +0200 | [diff] [blame] | 26 | static const DECLARE_TLV_DB_RANGE(max9877_pgain_tlv, |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 27 | 0, 1, TLV_DB_SCALE_ITEM(0, 900, 0), |
Lars-Peter Clausen | d6e3bb7 | 2015-08-02 17:19:46 +0200 | [diff] [blame] | 28 | 2, 2, TLV_DB_SCALE_ITEM(2000, 0, 0) |
| 29 | ); |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 30 | |
Lars-Peter Clausen | d6e3bb7 | 2015-08-02 17:19:46 +0200 | [diff] [blame] | 31 | static const DECLARE_TLV_DB_RANGE(max9877_output_tlv, |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 32 | 0, 7, TLV_DB_SCALE_ITEM(-7900, 400, 1), |
| 33 | 8, 15, TLV_DB_SCALE_ITEM(-4700, 300, 0), |
| 34 | 16, 23, TLV_DB_SCALE_ITEM(-2300, 200, 0), |
Lars-Peter Clausen | d6e3bb7 | 2015-08-02 17:19:46 +0200 | [diff] [blame] | 35 | 24, 31, TLV_DB_SCALE_ITEM(-700, 100, 0) |
| 36 | ); |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 37 | |
| 38 | static const char *max9877_out_mode[] = { |
| 39 | "INA -> SPK", |
| 40 | "INA -> HP", |
| 41 | "INA -> SPK and HP", |
| 42 | "INB -> SPK", |
| 43 | "INB -> HP", |
| 44 | "INB -> SPK and HP", |
| 45 | "INA + INB -> SPK", |
| 46 | "INA + INB -> HP", |
| 47 | "INA + INB -> SPK and HP", |
| 48 | }; |
| 49 | |
| 50 | static const char *max9877_osc_mode[] = { |
| 51 | "1176KHz", |
| 52 | "1100KHz", |
| 53 | "700KHz", |
| 54 | }; |
| 55 | |
| 56 | static const struct soc_enum max9877_enum[] = { |
Mark Brown | d76a961 | 2013-08-13 13:20:15 +0100 | [diff] [blame] | 57 | SOC_ENUM_SINGLE(MAX9877_OUTPUT_MODE, 0, ARRAY_SIZE(max9877_out_mode), |
| 58 | max9877_out_mode), |
| 59 | SOC_ENUM_SINGLE(MAX9877_OUTPUT_MODE, MAX9877_OSC_OFFSET, |
| 60 | ARRAY_SIZE(max9877_osc_mode), max9877_osc_mode), |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | static const struct snd_kcontrol_new max9877_controls[] = { |
Mark Brown | d76a961 | 2013-08-13 13:20:15 +0100 | [diff] [blame] | 64 | SOC_SINGLE_TLV("MAX9877 PGAINA Playback Volume", |
| 65 | MAX9877_INPUT_MODE, 0, 2, 0, max9877_pgain_tlv), |
| 66 | SOC_SINGLE_TLV("MAX9877 PGAINB Playback Volume", |
| 67 | MAX9877_INPUT_MODE, 2, 2, 0, max9877_pgain_tlv), |
| 68 | SOC_SINGLE_TLV("MAX9877 Amp Speaker Playback Volume", |
| 69 | MAX9877_SPK_VOLUME, 0, 31, 0, max9877_output_tlv), |
| 70 | SOC_DOUBLE_R_TLV("MAX9877 Amp HP Playback Volume", |
| 71 | MAX9877_HPL_VOLUME, MAX9877_HPR_VOLUME, 0, 31, 0, |
| 72 | max9877_output_tlv), |
| 73 | SOC_SINGLE("MAX9877 INB Stereo Switch", |
| 74 | MAX9877_INPUT_MODE, 4, 1, 1), |
| 75 | SOC_SINGLE("MAX9877 INA Stereo Switch", |
| 76 | MAX9877_INPUT_MODE, 5, 1, 1), |
| 77 | SOC_SINGLE("MAX9877 Zero-crossing detection Switch", |
| 78 | MAX9877_INPUT_MODE, 6, 1, 0), |
| 79 | SOC_SINGLE("MAX9877 Bypass Mode Switch", |
| 80 | MAX9877_OUTPUT_MODE, 6, 1, 0), |
Mark Brown | d76a961 | 2013-08-13 13:20:15 +0100 | [diff] [blame] | 81 | SOC_ENUM("MAX9877 Output Mode", max9877_enum[0]), |
| 82 | SOC_ENUM("MAX9877 Oscillator Mode", max9877_enum[1]), |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 83 | }; |
| 84 | |
Mark Brown | 5cf9da8 | 2013-08-13 13:32:03 +0100 | [diff] [blame] | 85 | static const struct snd_soc_dapm_widget max9877_dapm_widgets[] = { |
| 86 | SND_SOC_DAPM_INPUT("INA1"), |
| 87 | SND_SOC_DAPM_INPUT("INA2"), |
| 88 | SND_SOC_DAPM_INPUT("INB1"), |
| 89 | SND_SOC_DAPM_INPUT("INB2"), |
| 90 | SND_SOC_DAPM_INPUT("RXIN+"), |
| 91 | SND_SOC_DAPM_INPUT("RXIN-"), |
| 92 | |
| 93 | SND_SOC_DAPM_PGA("SHDN", MAX9877_OUTPUT_MODE, 7, 1, NULL, 0), |
| 94 | |
| 95 | SND_SOC_DAPM_OUTPUT("OUT+"), |
| 96 | SND_SOC_DAPM_OUTPUT("OUT-"), |
| 97 | SND_SOC_DAPM_OUTPUT("HPL"), |
| 98 | SND_SOC_DAPM_OUTPUT("HPR"), |
| 99 | }; |
| 100 | |
| 101 | static const struct snd_soc_dapm_route max9877_dapm_routes[] = { |
| 102 | { "SHDN", NULL, "INA1" }, |
| 103 | { "SHDN", NULL, "INA2" }, |
| 104 | { "SHDN", NULL, "INB1" }, |
| 105 | { "SHDN", NULL, "INB2" }, |
| 106 | |
| 107 | { "OUT+", NULL, "RXIN+" }, |
| 108 | { "OUT+", NULL, "SHDN" }, |
| 109 | |
| 110 | { "OUT-", NULL, "SHDN" }, |
| 111 | { "OUT-", NULL, "RXIN-" }, |
| 112 | |
| 113 | { "HPL", NULL, "SHDN" }, |
| 114 | { "HPR", NULL, "SHDN" }, |
| 115 | }; |
| 116 | |
Lars-Peter Clausen | 623436a | 2015-07-16 21:22:50 +0200 | [diff] [blame] | 117 | static const struct snd_soc_component_driver max9877_component_driver = { |
Mark Brown | d76a961 | 2013-08-13 13:20:15 +0100 | [diff] [blame] | 118 | .controls = max9877_controls, |
| 119 | .num_controls = ARRAY_SIZE(max9877_controls), |
Mark Brown | 5cf9da8 | 2013-08-13 13:32:03 +0100 | [diff] [blame] | 120 | |
| 121 | .dapm_widgets = max9877_dapm_widgets, |
| 122 | .num_dapm_widgets = ARRAY_SIZE(max9877_dapm_widgets), |
| 123 | .dapm_routes = max9877_dapm_routes, |
| 124 | .num_dapm_routes = ARRAY_SIZE(max9877_dapm_routes), |
Mark Brown | d76a961 | 2013-08-13 13:20:15 +0100 | [diff] [blame] | 125 | }; |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 126 | |
Mark Brown | 997288e | 2013-08-13 13:10:19 +0100 | [diff] [blame] | 127 | static const struct regmap_config max9877_regmap = { |
| 128 | .reg_bits = 8, |
| 129 | .val_bits = 8, |
| 130 | |
| 131 | .reg_defaults = max9877_regs, |
| 132 | .num_reg_defaults = ARRAY_SIZE(max9877_regs), |
| 133 | .cache_type = REGCACHE_RBTREE, |
| 134 | }; |
| 135 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 136 | static int max9877_i2c_probe(struct i2c_client *client, |
| 137 | const struct i2c_device_id *id) |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 138 | { |
Lars-Peter Clausen | df2e268 | 2015-07-16 21:22:49 +0200 | [diff] [blame] | 139 | struct regmap *regmap; |
Mark Brown | 997288e | 2013-08-13 13:10:19 +0100 | [diff] [blame] | 140 | int i; |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 141 | |
Mark Brown | 997288e | 2013-08-13 13:10:19 +0100 | [diff] [blame] | 142 | regmap = devm_regmap_init_i2c(client, &max9877_regmap); |
| 143 | if (IS_ERR(regmap)) |
| 144 | return PTR_ERR(regmap); |
| 145 | |
| 146 | /* Ensure the device is in reset state */ |
| 147 | for (i = 0; i < ARRAY_SIZE(max9877_regs); i++) |
| 148 | regmap_write(regmap, max9877_regs[i].reg, max9877_regs[i].def); |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 149 | |
Lars-Peter Clausen | 623436a | 2015-07-16 21:22:50 +0200 | [diff] [blame] | 150 | return devm_snd_soc_register_component(&client->dev, |
| 151 | &max9877_component_driver, NULL, 0); |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | static const struct i2c_device_id max9877_i2c_id[] = { |
| 155 | { "max9877", 0 }, |
| 156 | { } |
| 157 | }; |
| 158 | MODULE_DEVICE_TABLE(i2c, max9877_i2c_id); |
| 159 | |
| 160 | static struct i2c_driver max9877_i2c_driver = { |
| 161 | .driver = { |
| 162 | .name = "max9877", |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 163 | }, |
| 164 | .probe = max9877_i2c_probe, |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 165 | .id_table = max9877_i2c_id, |
| 166 | }; |
| 167 | |
Sachin Kamat | a3627e9 | 2012-08-06 17:25:35 +0530 | [diff] [blame] | 168 | module_i2c_driver(max9877_i2c_driver); |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 169 | |
| 170 | MODULE_DESCRIPTION("ASoC MAX9877 amp driver"); |
| 171 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
| 172 | MODULE_LICENSE("GPL"); |