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 | |
Mark Brown | 997288e | 2013-08-13 13:10:19 +0100 | [diff] [blame] | 23 | static struct regmap *regmap; |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 24 | |
Mark Brown | 997288e | 2013-08-13 13:10:19 +0100 | [diff] [blame] | 25 | static struct reg_default max9877_regs[] = { |
| 26 | { 0, 0x40 }, |
| 27 | { 1, 0x00 }, |
| 28 | { 2, 0x00 }, |
| 29 | { 3, 0x00 }, |
| 30 | { 4, 0x49 }, |
| 31 | }; |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 32 | |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 33 | static const unsigned int max9877_pgain_tlv[] = { |
| 34 | TLV_DB_RANGE_HEAD(2), |
| 35 | 0, 1, TLV_DB_SCALE_ITEM(0, 900, 0), |
| 36 | 2, 2, TLV_DB_SCALE_ITEM(2000, 0, 0), |
| 37 | }; |
| 38 | |
| 39 | static const unsigned int max9877_output_tlv[] = { |
| 40 | TLV_DB_RANGE_HEAD(4), |
| 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), |
| 45 | }; |
| 46 | |
| 47 | static const char *max9877_out_mode[] = { |
| 48 | "INA -> SPK", |
| 49 | "INA -> HP", |
| 50 | "INA -> SPK and HP", |
| 51 | "INB -> SPK", |
| 52 | "INB -> HP", |
| 53 | "INB -> SPK and HP", |
| 54 | "INA + INB -> SPK", |
| 55 | "INA + INB -> HP", |
| 56 | "INA + INB -> SPK and HP", |
| 57 | }; |
| 58 | |
| 59 | static const char *max9877_osc_mode[] = { |
| 60 | "1176KHz", |
| 61 | "1100KHz", |
| 62 | "700KHz", |
| 63 | }; |
| 64 | |
| 65 | static const struct soc_enum max9877_enum[] = { |
Mark Brown | d76a961 | 2013-08-13 13:20:15 +0100 | [diff] [blame^] | 66 | SOC_ENUM_SINGLE(MAX9877_OUTPUT_MODE, 0, ARRAY_SIZE(max9877_out_mode), |
| 67 | max9877_out_mode), |
| 68 | SOC_ENUM_SINGLE(MAX9877_OUTPUT_MODE, MAX9877_OSC_OFFSET, |
| 69 | ARRAY_SIZE(max9877_osc_mode), max9877_osc_mode), |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | static const struct snd_kcontrol_new max9877_controls[] = { |
Mark Brown | d76a961 | 2013-08-13 13:20:15 +0100 | [diff] [blame^] | 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, |
| 81 | max9877_output_tlv), |
| 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_SINGLE("MAX9877 Shutdown Mode Switch", |
| 91 | MAX9877_OUTPUT_MODE, 7, 1, 1), |
| 92 | SOC_ENUM("MAX9877 Output Mode", max9877_enum[0]), |
| 93 | SOC_ENUM("MAX9877 Oscillator Mode", max9877_enum[1]), |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 94 | }; |
| 95 | |
Mark Brown | d76a961 | 2013-08-13 13:20:15 +0100 | [diff] [blame^] | 96 | static const struct snd_soc_codec_driver max9877_codec = { |
| 97 | .controls = max9877_controls, |
| 98 | .num_controls = ARRAY_SIZE(max9877_controls), |
| 99 | }; |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 100 | |
Mark Brown | 997288e | 2013-08-13 13:10:19 +0100 | [diff] [blame] | 101 | static const struct regmap_config max9877_regmap = { |
| 102 | .reg_bits = 8, |
| 103 | .val_bits = 8, |
| 104 | |
| 105 | .reg_defaults = max9877_regs, |
| 106 | .num_reg_defaults = ARRAY_SIZE(max9877_regs), |
| 107 | .cache_type = REGCACHE_RBTREE, |
| 108 | }; |
| 109 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 110 | static int max9877_i2c_probe(struct i2c_client *client, |
| 111 | const struct i2c_device_id *id) |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 112 | { |
Mark Brown | 997288e | 2013-08-13 13:10:19 +0100 | [diff] [blame] | 113 | int i; |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 114 | |
Mark Brown | 997288e | 2013-08-13 13:10:19 +0100 | [diff] [blame] | 115 | regmap = devm_regmap_init_i2c(client, &max9877_regmap); |
| 116 | if (IS_ERR(regmap)) |
| 117 | return PTR_ERR(regmap); |
| 118 | |
| 119 | /* Ensure the device is in reset state */ |
| 120 | for (i = 0; i < ARRAY_SIZE(max9877_regs); i++) |
| 121 | regmap_write(regmap, max9877_regs[i].reg, max9877_regs[i].def); |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 122 | |
Mark Brown | d76a961 | 2013-08-13 13:20:15 +0100 | [diff] [blame^] | 123 | return snd_soc_register_codec(&client->dev, &max9877_codec, NULL, 0); |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 124 | } |
| 125 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 126 | static int max9877_i2c_remove(struct i2c_client *client) |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 127 | { |
Mark Brown | d76a961 | 2013-08-13 13:20:15 +0100 | [diff] [blame^] | 128 | snd_soc_unregister_codec(&client->dev); |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | static const struct i2c_device_id max9877_i2c_id[] = { |
| 134 | { "max9877", 0 }, |
| 135 | { } |
| 136 | }; |
| 137 | MODULE_DEVICE_TABLE(i2c, max9877_i2c_id); |
| 138 | |
| 139 | static struct i2c_driver max9877_i2c_driver = { |
| 140 | .driver = { |
| 141 | .name = "max9877", |
| 142 | .owner = THIS_MODULE, |
| 143 | }, |
| 144 | .probe = max9877_i2c_probe, |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 145 | .remove = max9877_i2c_remove, |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 146 | .id_table = max9877_i2c_id, |
| 147 | }; |
| 148 | |
Sachin Kamat | a3627e9 | 2012-08-06 17:25:35 +0530 | [diff] [blame] | 149 | module_i2c_driver(max9877_i2c_driver); |
Joonyoung Shim | 9db9ed9 | 2009-07-15 20:34:00 +0900 | [diff] [blame] | 150 | |
| 151 | MODULE_DESCRIPTION("ASoC MAX9877 amp driver"); |
| 152 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); |
| 153 | MODULE_LICENSE("GPL"); |