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