blob: fb448dde018da75a1d5681b6a8fa678eb50f953d [file] [log] [blame]
Joonyoung Shim9db9ed92009-07-15 20:34:00 +09001/*
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 Brown997288e2013-08-13 13:10:19 +010017#include <linux/regmap.h>
Joonyoung Shim9db9ed92009-07-15 20:34:00 +090018#include <sound/soc.h>
19#include <sound/tlv.h>
20
21#include "max9877.h"
22
Axel Linc418a842015-07-05 17:48:29 +080023static const struct reg_default max9877_regs[] = {
Mark Brown997288e2013-08-13 13:10:19 +010024 { 0, 0x40 },
25 { 1, 0x00 },
26 { 2, 0x00 },
27 { 3, 0x00 },
28 { 4, 0x49 },
29};
Joonyoung Shim9db9ed92009-07-15 20:34:00 +090030
Joonyoung Shim9db9ed92009-07-15 20:34:00 +090031static 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
37static 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
45static 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
57static const char *max9877_osc_mode[] = {
58 "1176KHz",
59 "1100KHz",
60 "700KHz",
61};
62
63static const struct soc_enum max9877_enum[] = {
Mark Brownd76a9612013-08-13 13:20:15 +010064 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 Shim9db9ed92009-07-15 20:34:00 +090068};
69
70static const struct snd_kcontrol_new max9877_controls[] = {
Mark Brownd76a9612013-08-13 13:20:15 +010071 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 Brownd76a9612013-08-13 13:20:15 +010088 SOC_ENUM("MAX9877 Output Mode", max9877_enum[0]),
89 SOC_ENUM("MAX9877 Oscillator Mode", max9877_enum[1]),
Joonyoung Shim9db9ed92009-07-15 20:34:00 +090090};
91
Mark Brown5cf9da82013-08-13 13:32:03 +010092static const struct snd_soc_dapm_widget max9877_dapm_widgets[] = {
93SND_SOC_DAPM_INPUT("INA1"),
94SND_SOC_DAPM_INPUT("INA2"),
95SND_SOC_DAPM_INPUT("INB1"),
96SND_SOC_DAPM_INPUT("INB2"),
97SND_SOC_DAPM_INPUT("RXIN+"),
98SND_SOC_DAPM_INPUT("RXIN-"),
99
100SND_SOC_DAPM_PGA("SHDN", MAX9877_OUTPUT_MODE, 7, 1, NULL, 0),
101
102SND_SOC_DAPM_OUTPUT("OUT+"),
103SND_SOC_DAPM_OUTPUT("OUT-"),
104SND_SOC_DAPM_OUTPUT("HPL"),
105SND_SOC_DAPM_OUTPUT("HPR"),
106};
107
108static 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 Clausen623436a2015-07-16 21:22:50 +0200124static const struct snd_soc_component_driver max9877_component_driver = {
Mark Brownd76a9612013-08-13 13:20:15 +0100125 .controls = max9877_controls,
126 .num_controls = ARRAY_SIZE(max9877_controls),
Mark Brown5cf9da82013-08-13 13:32:03 +0100127
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 Brownd76a9612013-08-13 13:20:15 +0100132};
Joonyoung Shim9db9ed92009-07-15 20:34:00 +0900133
Mark Brown997288e2013-08-13 13:10:19 +0100134static 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 Pemberton7a79e942012-12-07 09:26:37 -0500143static int max9877_i2c_probe(struct i2c_client *client,
144 const struct i2c_device_id *id)
Joonyoung Shim9db9ed92009-07-15 20:34:00 +0900145{
Lars-Peter Clausendf2e2682015-07-16 21:22:49 +0200146 struct regmap *regmap;
Mark Brown997288e2013-08-13 13:10:19 +0100147 int i;
Joonyoung Shim9db9ed92009-07-15 20:34:00 +0900148
Mark Brown997288e2013-08-13 13:10:19 +0100149 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 Shim9db9ed92009-07-15 20:34:00 +0900156
Lars-Peter Clausen623436a2015-07-16 21:22:50 +0200157 return devm_snd_soc_register_component(&client->dev,
158 &max9877_component_driver, NULL, 0);
Joonyoung Shim9db9ed92009-07-15 20:34:00 +0900159}
160
161static const struct i2c_device_id max9877_i2c_id[] = {
162 { "max9877", 0 },
163 { }
164};
165MODULE_DEVICE_TABLE(i2c, max9877_i2c_id);
166
167static struct i2c_driver max9877_i2c_driver = {
168 .driver = {
169 .name = "max9877",
Joonyoung Shim9db9ed92009-07-15 20:34:00 +0900170 },
171 .probe = max9877_i2c_probe,
Joonyoung Shim9db9ed92009-07-15 20:34:00 +0900172 .id_table = max9877_i2c_id,
173};
174
Sachin Kamata3627e92012-08-06 17:25:35 +0530175module_i2c_driver(max9877_i2c_driver);
Joonyoung Shim9db9ed92009-07-15 20:34:00 +0900176
177MODULE_DESCRIPTION("ASoC MAX9877 amp driver");
178MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
179MODULE_LICENSE("GPL");