1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * max9877.c -- amp driver for max9877
5 * Copyright (C) 2009 Samsung Electronics Co.Ltd
6 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/i2c.h>
12 #include <linux/regmap.h>
13 #include <sound/soc.h>
14 #include <sound/tlv.h>
18 static const struct reg_default max9877_regs
[] = {
26 static const DECLARE_TLV_DB_RANGE(max9877_pgain_tlv
,
27 0, 1, TLV_DB_SCALE_ITEM(0, 900, 0),
28 2, 2, TLV_DB_SCALE_ITEM(2000, 0, 0)
31 static const DECLARE_TLV_DB_RANGE(max9877_output_tlv
,
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),
35 24, 31, TLV_DB_SCALE_ITEM(-700, 100, 0)
38 static const char *max9877_out_mode
[] = {
47 "INA + INB -> SPK and HP",
50 static const char *max9877_osc_mode
[] = {
56 static const struct soc_enum max9877_enum
[] = {
57 SOC_ENUM_SINGLE(MAX9877_OUTPUT_MODE
, 0, ARRAY_SIZE(max9877_out_mode
),
59 SOC_ENUM_SINGLE(MAX9877_OUTPUT_MODE
, MAX9877_OSC_OFFSET
,
60 ARRAY_SIZE(max9877_osc_mode
), max9877_osc_mode
),
63 static const struct snd_kcontrol_new max9877_controls
[] = {
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,
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),
81 SOC_ENUM("MAX9877 Output Mode", max9877_enum
[0]),
82 SOC_ENUM("MAX9877 Oscillator Mode", max9877_enum
[1]),
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-"),
93 SND_SOC_DAPM_PGA("SHDN", MAX9877_OUTPUT_MODE
, 7, 1, NULL
, 0),
95 SND_SOC_DAPM_OUTPUT("OUT+"),
96 SND_SOC_DAPM_OUTPUT("OUT-"),
97 SND_SOC_DAPM_OUTPUT("HPL"),
98 SND_SOC_DAPM_OUTPUT("HPR"),
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" },
107 { "OUT+", NULL
, "RXIN+" },
108 { "OUT+", NULL
, "SHDN" },
110 { "OUT-", NULL
, "SHDN" },
111 { "OUT-", NULL
, "RXIN-" },
113 { "HPL", NULL
, "SHDN" },
114 { "HPR", NULL
, "SHDN" },
117 static const struct snd_soc_component_driver max9877_component_driver
= {
118 .controls
= max9877_controls
,
119 .num_controls
= ARRAY_SIZE(max9877_controls
),
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
),
127 static const struct regmap_config max9877_regmap
= {
131 .reg_defaults
= max9877_regs
,
132 .num_reg_defaults
= ARRAY_SIZE(max9877_regs
),
133 .cache_type
= REGCACHE_RBTREE
,
136 static int max9877_i2c_probe(struct i2c_client
*client
,
137 const struct i2c_device_id
*id
)
139 struct regmap
*regmap
;
142 regmap
= devm_regmap_init_i2c(client
, &max9877_regmap
);
144 return PTR_ERR(regmap
);
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
);
150 return devm_snd_soc_register_component(&client
->dev
,
151 &max9877_component_driver
, NULL
, 0);
154 static const struct i2c_device_id max9877_i2c_id
[] = {
158 MODULE_DEVICE_TABLE(i2c
, max9877_i2c_id
);
160 static struct i2c_driver max9877_i2c_driver
= {
164 .probe
= max9877_i2c_probe
,
165 .id_table
= max9877_i2c_id
,
168 module_i2c_driver(max9877_i2c_driver
);
170 MODULE_DESCRIPTION("ASoC MAX9877 amp driver");
171 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
172 MODULE_LICENSE("GPL");