2009-07-15 15:34:00 +04:00
|
|
|
/*
|
|
|
|
* max9877.c -- amp driver for max9877
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Samsung Electronics Co.Ltd
|
|
|
|
* Author: Joonyoung Shim <jy0922.shim@samsung.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/i2c.h>
|
2013-08-13 16:10:19 +04:00
|
|
|
#include <linux/regmap.h>
|
2009-07-15 15:34:00 +04:00
|
|
|
#include <sound/soc.h>
|
|
|
|
#include <sound/tlv.h>
|
|
|
|
|
|
|
|
#include "max9877.h"
|
|
|
|
|
2013-08-13 16:10:19 +04:00
|
|
|
static struct regmap *regmap;
|
2009-07-15 15:34:00 +04:00
|
|
|
|
2013-08-13 16:10:19 +04:00
|
|
|
static struct reg_default max9877_regs[] = {
|
|
|
|
{ 0, 0x40 },
|
|
|
|
{ 1, 0x00 },
|
|
|
|
{ 2, 0x00 },
|
|
|
|
{ 3, 0x00 },
|
|
|
|
{ 4, 0x49 },
|
|
|
|
};
|
2009-07-15 15:34:00 +04:00
|
|
|
|
|
|
|
static const unsigned int max9877_pgain_tlv[] = {
|
|
|
|
TLV_DB_RANGE_HEAD(2),
|
|
|
|
0, 1, TLV_DB_SCALE_ITEM(0, 900, 0),
|
|
|
|
2, 2, TLV_DB_SCALE_ITEM(2000, 0, 0),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const unsigned int max9877_output_tlv[] = {
|
|
|
|
TLV_DB_RANGE_HEAD(4),
|
|
|
|
0, 7, TLV_DB_SCALE_ITEM(-7900, 400, 1),
|
|
|
|
8, 15, TLV_DB_SCALE_ITEM(-4700, 300, 0),
|
|
|
|
16, 23, TLV_DB_SCALE_ITEM(-2300, 200, 0),
|
|
|
|
24, 31, TLV_DB_SCALE_ITEM(-700, 100, 0),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *max9877_out_mode[] = {
|
|
|
|
"INA -> SPK",
|
|
|
|
"INA -> HP",
|
|
|
|
"INA -> SPK and HP",
|
|
|
|
"INB -> SPK",
|
|
|
|
"INB -> HP",
|
|
|
|
"INB -> SPK and HP",
|
|
|
|
"INA + INB -> SPK",
|
|
|
|
"INA + INB -> HP",
|
|
|
|
"INA + INB -> SPK and HP",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *max9877_osc_mode[] = {
|
|
|
|
"1176KHz",
|
|
|
|
"1100KHz",
|
|
|
|
"700KHz",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct soc_enum max9877_enum[] = {
|
2013-08-13 16:20:15 +04:00
|
|
|
SOC_ENUM_SINGLE(MAX9877_OUTPUT_MODE, 0, ARRAY_SIZE(max9877_out_mode),
|
|
|
|
max9877_out_mode),
|
|
|
|
SOC_ENUM_SINGLE(MAX9877_OUTPUT_MODE, MAX9877_OSC_OFFSET,
|
|
|
|
ARRAY_SIZE(max9877_osc_mode), max9877_osc_mode),
|
2009-07-15 15:34:00 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct snd_kcontrol_new max9877_controls[] = {
|
2013-08-13 16:20:15 +04:00
|
|
|
SOC_SINGLE_TLV("MAX9877 PGAINA Playback Volume",
|
|
|
|
MAX9877_INPUT_MODE, 0, 2, 0, max9877_pgain_tlv),
|
|
|
|
SOC_SINGLE_TLV("MAX9877 PGAINB Playback Volume",
|
|
|
|
MAX9877_INPUT_MODE, 2, 2, 0, max9877_pgain_tlv),
|
|
|
|
SOC_SINGLE_TLV("MAX9877 Amp Speaker Playback Volume",
|
|
|
|
MAX9877_SPK_VOLUME, 0, 31, 0, max9877_output_tlv),
|
|
|
|
SOC_DOUBLE_R_TLV("MAX9877 Amp HP Playback Volume",
|
|
|
|
MAX9877_HPL_VOLUME, MAX9877_HPR_VOLUME, 0, 31, 0,
|
|
|
|
max9877_output_tlv),
|
|
|
|
SOC_SINGLE("MAX9877 INB Stereo Switch",
|
|
|
|
MAX9877_INPUT_MODE, 4, 1, 1),
|
|
|
|
SOC_SINGLE("MAX9877 INA Stereo Switch",
|
|
|
|
MAX9877_INPUT_MODE, 5, 1, 1),
|
|
|
|
SOC_SINGLE("MAX9877 Zero-crossing detection Switch",
|
|
|
|
MAX9877_INPUT_MODE, 6, 1, 0),
|
|
|
|
SOC_SINGLE("MAX9877 Bypass Mode Switch",
|
|
|
|
MAX9877_OUTPUT_MODE, 6, 1, 0),
|
|
|
|
SOC_SINGLE("MAX9877 Shutdown Mode Switch",
|
|
|
|
MAX9877_OUTPUT_MODE, 7, 1, 1),
|
|
|
|
SOC_ENUM("MAX9877 Output Mode", max9877_enum[0]),
|
|
|
|
SOC_ENUM("MAX9877 Oscillator Mode", max9877_enum[1]),
|
2009-07-15 15:34:00 +04:00
|
|
|
};
|
|
|
|
|
2013-08-13 16:20:15 +04:00
|
|
|
static const struct snd_soc_codec_driver max9877_codec = {
|
|
|
|
.controls = max9877_controls,
|
|
|
|
.num_controls = ARRAY_SIZE(max9877_controls),
|
|
|
|
};
|
2009-07-15 15:34:00 +04:00
|
|
|
|
2013-08-13 16:10:19 +04:00
|
|
|
static const struct regmap_config max9877_regmap = {
|
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 8,
|
|
|
|
|
|
|
|
.reg_defaults = max9877_regs,
|
|
|
|
.num_reg_defaults = ARRAY_SIZE(max9877_regs),
|
|
|
|
.cache_type = REGCACHE_RBTREE,
|
|
|
|
};
|
|
|
|
|
2012-12-07 18:26:37 +04:00
|
|
|
static int max9877_i2c_probe(struct i2c_client *client,
|
|
|
|
const struct i2c_device_id *id)
|
2009-07-15 15:34:00 +04:00
|
|
|
{
|
2013-08-13 16:10:19 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
regmap = devm_regmap_init_i2c(client, &max9877_regmap);
|
|
|
|
if (IS_ERR(regmap))
|
|
|
|
return PTR_ERR(regmap);
|
2009-07-15 15:34:00 +04:00
|
|
|
|
2013-08-13 16:10:19 +04:00
|
|
|
/* Ensure the device is in reset state */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(max9877_regs); i++)
|
|
|
|
regmap_write(regmap, max9877_regs[i].reg, max9877_regs[i].def);
|
2009-07-15 15:34:00 +04:00
|
|
|
|
2013-08-13 16:20:15 +04:00
|
|
|
return snd_soc_register_codec(&client->dev, &max9877_codec, NULL, 0);
|
2009-07-15 15:34:00 +04:00
|
|
|
}
|
|
|
|
|
2012-12-07 18:26:37 +04:00
|
|
|
static int max9877_i2c_remove(struct i2c_client *client)
|
2009-07-15 15:34:00 +04:00
|
|
|
{
|
2013-08-13 16:20:15 +04:00
|
|
|
snd_soc_unregister_codec(&client->dev);
|
2009-07-15 15:34:00 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id max9877_i2c_id[] = {
|
|
|
|
{ "max9877", 0 },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, max9877_i2c_id);
|
|
|
|
|
|
|
|
static struct i2c_driver max9877_i2c_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "max9877",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.probe = max9877_i2c_probe,
|
2012-12-07 18:26:37 +04:00
|
|
|
.remove = max9877_i2c_remove,
|
2009-07-15 15:34:00 +04:00
|
|
|
.id_table = max9877_i2c_id,
|
|
|
|
};
|
|
|
|
|
2012-08-06 15:55:35 +04:00
|
|
|
module_i2c_driver(max9877_i2c_driver);
|
2009-07-15 15:34:00 +04:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("ASoC MAX9877 amp driver");
|
|
|
|
MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|