blob: 71fede9224c4fbf18f122f7f1a2e51353833359e [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Joonyoung Shim9db9ed92009-07-15 20:34:00 +09002/*
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 Shim9db9ed92009-07-15 20:34:00 +09007 */
8
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/i2c.h>
Mark Brown997288e2013-08-13 13:10:19 +010012#include <linux/regmap.h>
Joonyoung Shim9db9ed92009-07-15 20:34:00 +090013#include <sound/soc.h>
14#include <sound/tlv.h>
15
16#include "max9877.h"
17
Axel Linc418a842015-07-05 17:48:29 +080018static const struct reg_default max9877_regs[] = {
Mark Brown997288e2013-08-13 13:10:19 +010019 { 0, 0x40 },
20 { 1, 0x00 },
21 { 2, 0x00 },
22 { 3, 0x00 },
23 { 4, 0x49 },
24};
Joonyoung Shim9db9ed92009-07-15 20:34:00 +090025
Lars-Peter Clausend6e3bb72015-08-02 17:19:46 +020026static const DECLARE_TLV_DB_RANGE(max9877_pgain_tlv,
Joonyoung Shim9db9ed92009-07-15 20:34:00 +090027 0, 1, TLV_DB_SCALE_ITEM(0, 900, 0),
Lars-Peter Clausend6e3bb72015-08-02 17:19:46 +020028 2, 2, TLV_DB_SCALE_ITEM(2000, 0, 0)
29);
Joonyoung Shim9db9ed92009-07-15 20:34:00 +090030
Lars-Peter Clausend6e3bb72015-08-02 17:19:46 +020031static const DECLARE_TLV_DB_RANGE(max9877_output_tlv,
Joonyoung Shim9db9ed92009-07-15 20:34:00 +090032 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 Clausend6e3bb72015-08-02 17:19:46 +020035 24, 31, TLV_DB_SCALE_ITEM(-700, 100, 0)
36);
Joonyoung Shim9db9ed92009-07-15 20:34:00 +090037
38static 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
50static const char *max9877_osc_mode[] = {
51 "1176KHz",
52 "1100KHz",
53 "700KHz",
54};
55
56static const struct soc_enum max9877_enum[] = {
Mark Brownd76a9612013-08-13 13:20:15 +010057 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 Shim9db9ed92009-07-15 20:34:00 +090061};
62
63static const struct snd_kcontrol_new max9877_controls[] = {
Mark Brownd76a9612013-08-13 13:20:15 +010064 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 Brownd76a9612013-08-13 13:20:15 +010081 SOC_ENUM("MAX9877 Output Mode", max9877_enum[0]),
82 SOC_ENUM("MAX9877 Oscillator Mode", max9877_enum[1]),
Joonyoung Shim9db9ed92009-07-15 20:34:00 +090083};
84
Mark Brown5cf9da82013-08-13 13:32:03 +010085static const struct snd_soc_dapm_widget max9877_dapm_widgets[] = {
86SND_SOC_DAPM_INPUT("INA1"),
87SND_SOC_DAPM_INPUT("INA2"),
88SND_SOC_DAPM_INPUT("INB1"),
89SND_SOC_DAPM_INPUT("INB2"),
90SND_SOC_DAPM_INPUT("RXIN+"),
91SND_SOC_DAPM_INPUT("RXIN-"),
92
93SND_SOC_DAPM_PGA("SHDN", MAX9877_OUTPUT_MODE, 7, 1, NULL, 0),
94
95SND_SOC_DAPM_OUTPUT("OUT+"),
96SND_SOC_DAPM_OUTPUT("OUT-"),
97SND_SOC_DAPM_OUTPUT("HPL"),
98SND_SOC_DAPM_OUTPUT("HPR"),
99};
100
101static 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 Clausen623436a2015-07-16 21:22:50 +0200117static const struct snd_soc_component_driver max9877_component_driver = {
Mark Brownd76a9612013-08-13 13:20:15 +0100118 .controls = max9877_controls,
119 .num_controls = ARRAY_SIZE(max9877_controls),
Mark Brown5cf9da82013-08-13 13:32:03 +0100120
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 Brownd76a9612013-08-13 13:20:15 +0100125};
Joonyoung Shim9db9ed92009-07-15 20:34:00 +0900126
Mark Brown997288e2013-08-13 13:10:19 +0100127static 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 Pemberton7a79e942012-12-07 09:26:37 -0500136static int max9877_i2c_probe(struct i2c_client *client,
137 const struct i2c_device_id *id)
Joonyoung Shim9db9ed92009-07-15 20:34:00 +0900138{
Lars-Peter Clausendf2e2682015-07-16 21:22:49 +0200139 struct regmap *regmap;
Mark Brown997288e2013-08-13 13:10:19 +0100140 int i;
Joonyoung Shim9db9ed92009-07-15 20:34:00 +0900141
Mark Brown997288e2013-08-13 13:10:19 +0100142 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 Shim9db9ed92009-07-15 20:34:00 +0900149
Lars-Peter Clausen623436a2015-07-16 21:22:50 +0200150 return devm_snd_soc_register_component(&client->dev,
151 &max9877_component_driver, NULL, 0);
Joonyoung Shim9db9ed92009-07-15 20:34:00 +0900152}
153
154static const struct i2c_device_id max9877_i2c_id[] = {
155 { "max9877", 0 },
156 { }
157};
158MODULE_DEVICE_TABLE(i2c, max9877_i2c_id);
159
160static struct i2c_driver max9877_i2c_driver = {
161 .driver = {
162 .name = "max9877",
Joonyoung Shim9db9ed92009-07-15 20:34:00 +0900163 },
164 .probe = max9877_i2c_probe,
Joonyoung Shim9db9ed92009-07-15 20:34:00 +0900165 .id_table = max9877_i2c_id,
166};
167
Sachin Kamata3627e92012-08-06 17:25:35 +0530168module_i2c_driver(max9877_i2c_driver);
Joonyoung Shim9db9ed92009-07-15 20:34:00 +0900169
170MODULE_DESCRIPTION("ASoC MAX9877 amp driver");
171MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
172MODULE_LICENSE("GPL");