2 * max9877.c -- amp driver for max9877
4 * Copyright (C) 2009 Samsung Electronics Co.Ltd
5 * Author: Joonyoung Shim <jy0922.shim@samsung.com>
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.
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/i2c.h>
17 #include <linux/regmap.h>
18 #include <sound/soc.h>
19 #include <sound/tlv.h>
23 static struct regmap
*regmap
;
25 static struct reg_default max9877_regs
[] = {
33 static const unsigned int max9877_pgain_tlv
[] = {
35 0, 1, TLV_DB_SCALE_ITEM(0, 900, 0),
36 2, 2, TLV_DB_SCALE_ITEM(2000, 0, 0),
39 static const unsigned int max9877_output_tlv
[] = {
41 0, 7, TLV_DB_SCALE_ITEM(-7900, 400, 1),
42 8, 15, TLV_DB_SCALE_ITEM(-4700, 300, 0),
43 16, 23, TLV_DB_SCALE_ITEM(-2300, 200, 0),
44 24, 31, TLV_DB_SCALE_ITEM(-700, 100, 0),
47 static const char *max9877_out_mode
[] = {
56 "INA + INB -> SPK and HP",
59 static const char *max9877_osc_mode
[] = {
65 static const struct soc_enum max9877_enum
[] = {
66 SOC_ENUM_SINGLE(MAX9877_OUTPUT_MODE
, 0, ARRAY_SIZE(max9877_out_mode
),
68 SOC_ENUM_SINGLE(MAX9877_OUTPUT_MODE
, MAX9877_OSC_OFFSET
,
69 ARRAY_SIZE(max9877_osc_mode
), max9877_osc_mode
),
72 static const struct snd_kcontrol_new max9877_controls
[] = {
73 SOC_SINGLE_TLV("MAX9877 PGAINA Playback Volume",
74 MAX9877_INPUT_MODE
, 0, 2, 0, max9877_pgain_tlv
),
75 SOC_SINGLE_TLV("MAX9877 PGAINB Playback Volume",
76 MAX9877_INPUT_MODE
, 2, 2, 0, max9877_pgain_tlv
),
77 SOC_SINGLE_TLV("MAX9877 Amp Speaker Playback Volume",
78 MAX9877_SPK_VOLUME
, 0, 31, 0, max9877_output_tlv
),
79 SOC_DOUBLE_R_TLV("MAX9877 Amp HP Playback Volume",
80 MAX9877_HPL_VOLUME
, MAX9877_HPR_VOLUME
, 0, 31, 0,
82 SOC_SINGLE("MAX9877 INB Stereo Switch",
83 MAX9877_INPUT_MODE
, 4, 1, 1),
84 SOC_SINGLE("MAX9877 INA Stereo Switch",
85 MAX9877_INPUT_MODE
, 5, 1, 1),
86 SOC_SINGLE("MAX9877 Zero-crossing detection Switch",
87 MAX9877_INPUT_MODE
, 6, 1, 0),
88 SOC_SINGLE("MAX9877 Bypass Mode Switch",
89 MAX9877_OUTPUT_MODE
, 6, 1, 0),
90 SOC_ENUM("MAX9877 Output Mode", max9877_enum
[0]),
91 SOC_ENUM("MAX9877 Oscillator Mode", max9877_enum
[1]),
94 static const struct snd_soc_dapm_widget max9877_dapm_widgets
[] = {
95 SND_SOC_DAPM_INPUT("INA1"),
96 SND_SOC_DAPM_INPUT("INA2"),
97 SND_SOC_DAPM_INPUT("INB1"),
98 SND_SOC_DAPM_INPUT("INB2"),
99 SND_SOC_DAPM_INPUT("RXIN+"),
100 SND_SOC_DAPM_INPUT("RXIN-"),
102 SND_SOC_DAPM_PGA("SHDN", MAX9877_OUTPUT_MODE
, 7, 1, NULL
, 0),
104 SND_SOC_DAPM_OUTPUT("OUT+"),
105 SND_SOC_DAPM_OUTPUT("OUT-"),
106 SND_SOC_DAPM_OUTPUT("HPL"),
107 SND_SOC_DAPM_OUTPUT("HPR"),
110 static const struct snd_soc_dapm_route max9877_dapm_routes
[] = {
111 { "SHDN", NULL
, "INA1" },
112 { "SHDN", NULL
, "INA2" },
113 { "SHDN", NULL
, "INB1" },
114 { "SHDN", NULL
, "INB2" },
116 { "OUT+", NULL
, "RXIN+" },
117 { "OUT+", NULL
, "SHDN" },
119 { "OUT-", NULL
, "SHDN" },
120 { "OUT-", NULL
, "RXIN-" },
122 { "HPL", NULL
, "SHDN" },
123 { "HPR", NULL
, "SHDN" },
126 static const struct snd_soc_codec_driver max9877_codec
= {
127 .controls
= max9877_controls
,
128 .num_controls
= ARRAY_SIZE(max9877_controls
),
130 .dapm_widgets
= max9877_dapm_widgets
,
131 .num_dapm_widgets
= ARRAY_SIZE(max9877_dapm_widgets
),
132 .dapm_routes
= max9877_dapm_routes
,
133 .num_dapm_routes
= ARRAY_SIZE(max9877_dapm_routes
),
136 static const struct regmap_config max9877_regmap
= {
140 .reg_defaults
= max9877_regs
,
141 .num_reg_defaults
= ARRAY_SIZE(max9877_regs
),
142 .cache_type
= REGCACHE_RBTREE
,
145 static int max9877_i2c_probe(struct i2c_client
*client
,
146 const struct i2c_device_id
*id
)
150 regmap
= devm_regmap_init_i2c(client
, &max9877_regmap
);
152 return PTR_ERR(regmap
);
154 /* Ensure the device is in reset state */
155 for (i
= 0; i
< ARRAY_SIZE(max9877_regs
); i
++)
156 regmap_write(regmap
, max9877_regs
[i
].reg
, max9877_regs
[i
].def
);
158 return snd_soc_register_codec(&client
->dev
, &max9877_codec
, NULL
, 0);
161 static int max9877_i2c_remove(struct i2c_client
*client
)
163 snd_soc_unregister_codec(&client
->dev
);
168 static const struct i2c_device_id max9877_i2c_id
[] = {
172 MODULE_DEVICE_TABLE(i2c
, max9877_i2c_id
);
174 static struct i2c_driver max9877_i2c_driver
= {
177 .owner
= THIS_MODULE
,
179 .probe
= max9877_i2c_probe
,
180 .remove
= max9877_i2c_remove
,
181 .id_table
= max9877_i2c_id
,
184 module_i2c_driver(max9877_i2c_driver
);
186 MODULE_DESCRIPTION("ASoC MAX9877 amp driver");
187 MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
188 MODULE_LICENSE("GPL");