10e45cab6SChristian Glindkamp /* 20e45cab6SChristian Glindkamp * max9850.c -- codec driver for max9850 30e45cab6SChristian Glindkamp * 40e45cab6SChristian Glindkamp * Copyright (C) 2011 taskit GmbH 50e45cab6SChristian Glindkamp * 60e45cab6SChristian Glindkamp * Author: Christian Glindkamp <christian.glindkamp@taskit.de> 70e45cab6SChristian Glindkamp * 80e45cab6SChristian Glindkamp * Initial development of this code was funded by 90e45cab6SChristian Glindkamp * MICRONIC Computer Systeme GmbH, http://www.mcsberlin.de/ 100e45cab6SChristian Glindkamp * 110e45cab6SChristian Glindkamp * This program is free software; you can redistribute it and/or modify it 120e45cab6SChristian Glindkamp * under the terms of the GNU General Public License as published by the 130e45cab6SChristian Glindkamp * Free Software Foundation; either version 2 of the License, or (at your 140e45cab6SChristian Glindkamp * option) any later version. 150e45cab6SChristian Glindkamp * 160e45cab6SChristian Glindkamp */ 170e45cab6SChristian Glindkamp 180e45cab6SChristian Glindkamp #include <linux/module.h> 190e45cab6SChristian Glindkamp #include <linux/init.h> 200e45cab6SChristian Glindkamp #include <linux/i2c.h> 21*06841662SMark Brown #include <linux/regmap.h> 220e45cab6SChristian Glindkamp #include <linux/slab.h> 230e45cab6SChristian Glindkamp #include <sound/pcm.h> 240e45cab6SChristian Glindkamp #include <sound/pcm_params.h> 250e45cab6SChristian Glindkamp #include <sound/soc.h> 260e45cab6SChristian Glindkamp #include <sound/tlv.h> 270e45cab6SChristian Glindkamp 280e45cab6SChristian Glindkamp #include "max9850.h" 290e45cab6SChristian Glindkamp 300e45cab6SChristian Glindkamp struct max9850_priv { 31*06841662SMark Brown struct regmap *regmap; 320e45cab6SChristian Glindkamp unsigned int sysclk; 330e45cab6SChristian Glindkamp }; 340e45cab6SChristian Glindkamp 350e45cab6SChristian Glindkamp /* max9850 register cache */ 36*06841662SMark Brown static const struct reg_default max9850_reg[] = { 37*06841662SMark Brown { 2, 0x0c }, 38*06841662SMark Brown { 3, 0x00 }, 39*06841662SMark Brown { 4, 0x00 }, 40*06841662SMark Brown { 5, 0x00 }, 41*06841662SMark Brown { 6, 0x00 }, 42*06841662SMark Brown { 7, 0x00 }, 43*06841662SMark Brown { 8, 0x00 }, 44*06841662SMark Brown { 9, 0x00 }, 45*06841662SMark Brown { 10, 0x00 }, 460e45cab6SChristian Glindkamp }; 470e45cab6SChristian Glindkamp 480e45cab6SChristian Glindkamp /* these registers are not used at the moment but provided for the sake of 490e45cab6SChristian Glindkamp * completeness */ 50*06841662SMark Brown static bool max9850_volatile_register(struct device *dev, unsigned int reg) 510e45cab6SChristian Glindkamp { 520e45cab6SChristian Glindkamp switch (reg) { 530e45cab6SChristian Glindkamp case MAX9850_STATUSA: 540e45cab6SChristian Glindkamp case MAX9850_STATUSB: 550e45cab6SChristian Glindkamp return 1; 560e45cab6SChristian Glindkamp default: 570e45cab6SChristian Glindkamp return 0; 580e45cab6SChristian Glindkamp } 590e45cab6SChristian Glindkamp } 600e45cab6SChristian Glindkamp 61*06841662SMark Brown static const struct regmap_config max9850_regmap = { 62*06841662SMark Brown .reg_bits = 8, 63*06841662SMark Brown .val_bits = 8, 64*06841662SMark Brown 65*06841662SMark Brown .max_register = MAX9850_DIGITAL_AUDIO, 66*06841662SMark Brown .volatile_reg = max9850_volatile_register, 67*06841662SMark Brown .cache_type = REGCACHE_RBTREE, 68*06841662SMark Brown }; 69*06841662SMark Brown 700e45cab6SChristian Glindkamp static const unsigned int max9850_tlv[] = { 710e45cab6SChristian Glindkamp TLV_DB_RANGE_HEAD(4), 720e45cab6SChristian Glindkamp 0x18, 0x1f, TLV_DB_SCALE_ITEM(-7450, 400, 0), 730e45cab6SChristian Glindkamp 0x20, 0x33, TLV_DB_SCALE_ITEM(-4150, 200, 0), 740e45cab6SChristian Glindkamp 0x34, 0x37, TLV_DB_SCALE_ITEM(-150, 100, 0), 750e45cab6SChristian Glindkamp 0x38, 0x3f, TLV_DB_SCALE_ITEM(250, 50, 0), 760e45cab6SChristian Glindkamp }; 770e45cab6SChristian Glindkamp 780e45cab6SChristian Glindkamp static const struct snd_kcontrol_new max9850_controls[] = { 790e45cab6SChristian Glindkamp SOC_SINGLE_TLV("Headphone Volume", MAX9850_VOLUME, 0, 0x3f, 1, max9850_tlv), 800e45cab6SChristian Glindkamp SOC_SINGLE("Headphone Switch", MAX9850_VOLUME, 7, 1, 1), 810e45cab6SChristian Glindkamp SOC_SINGLE("Mono Switch", MAX9850_GENERAL_PURPOSE, 2, 1, 0), 820e45cab6SChristian Glindkamp }; 830e45cab6SChristian Glindkamp 840e45cab6SChristian Glindkamp static const struct snd_kcontrol_new max9850_mixer_controls[] = { 850e45cab6SChristian Glindkamp SOC_DAPM_SINGLE("Line In Switch", MAX9850_ENABLE, 1, 1, 0), 860e45cab6SChristian Glindkamp }; 870e45cab6SChristian Glindkamp 880e45cab6SChristian Glindkamp static const struct snd_soc_dapm_widget max9850_dapm_widgets[] = { 890e45cab6SChristian Glindkamp SND_SOC_DAPM_SUPPLY("Charge Pump 1", MAX9850_ENABLE, 4, 0, NULL, 0), 900e45cab6SChristian Glindkamp SND_SOC_DAPM_SUPPLY("Charge Pump 2", MAX9850_ENABLE, 5, 0, NULL, 0), 910e45cab6SChristian Glindkamp SND_SOC_DAPM_SUPPLY("MCLK", MAX9850_ENABLE, 6, 0, NULL, 0), 920e45cab6SChristian Glindkamp SND_SOC_DAPM_SUPPLY("SHDN", MAX9850_ENABLE, 7, 0, NULL, 0), 930e45cab6SChristian Glindkamp SND_SOC_DAPM_MIXER_NAMED_CTL("Output Mixer", MAX9850_ENABLE, 2, 0, 940e45cab6SChristian Glindkamp &max9850_mixer_controls[0], 950e45cab6SChristian Glindkamp ARRAY_SIZE(max9850_mixer_controls)), 960e45cab6SChristian Glindkamp SND_SOC_DAPM_PGA("Headphone Output", MAX9850_ENABLE, 3, 0, NULL, 0), 970e45cab6SChristian Glindkamp SND_SOC_DAPM_DAC("DAC", "HiFi Playback", MAX9850_ENABLE, 0, 0), 980e45cab6SChristian Glindkamp SND_SOC_DAPM_OUTPUT("OUTL"), 990e45cab6SChristian Glindkamp SND_SOC_DAPM_OUTPUT("HPL"), 1000e45cab6SChristian Glindkamp SND_SOC_DAPM_OUTPUT("OUTR"), 1010e45cab6SChristian Glindkamp SND_SOC_DAPM_OUTPUT("HPR"), 1020e45cab6SChristian Glindkamp SND_SOC_DAPM_MIXER("Line Input", SND_SOC_NOPM, 0, 0, NULL, 0), 1030e45cab6SChristian Glindkamp SND_SOC_DAPM_INPUT("INL"), 1040e45cab6SChristian Glindkamp SND_SOC_DAPM_INPUT("INR"), 1050e45cab6SChristian Glindkamp }; 1060e45cab6SChristian Glindkamp 1075ee65ec6SAxel Lin static const struct snd_soc_dapm_route max9850_dapm_routes[] = { 1080e45cab6SChristian Glindkamp /* output mixer */ 1090e45cab6SChristian Glindkamp {"Output Mixer", NULL, "DAC"}, 1100e45cab6SChristian Glindkamp {"Output Mixer", "Line In Switch", "Line Input"}, 1110e45cab6SChristian Glindkamp 1120e45cab6SChristian Glindkamp /* outputs */ 1130e45cab6SChristian Glindkamp {"Headphone Output", NULL, "Output Mixer"}, 1140e45cab6SChristian Glindkamp {"HPL", NULL, "Headphone Output"}, 1150e45cab6SChristian Glindkamp {"HPR", NULL, "Headphone Output"}, 1160e45cab6SChristian Glindkamp {"OUTL", NULL, "Output Mixer"}, 1170e45cab6SChristian Glindkamp {"OUTR", NULL, "Output Mixer"}, 1180e45cab6SChristian Glindkamp 1190e45cab6SChristian Glindkamp /* inputs */ 1200e45cab6SChristian Glindkamp {"Line Input", NULL, "INL"}, 1210e45cab6SChristian Glindkamp {"Line Input", NULL, "INR"}, 1220e45cab6SChristian Glindkamp 1230e45cab6SChristian Glindkamp /* supplies */ 1240e45cab6SChristian Glindkamp {"Output Mixer", NULL, "Charge Pump 1"}, 1250e45cab6SChristian Glindkamp {"Output Mixer", NULL, "Charge Pump 2"}, 1260e45cab6SChristian Glindkamp {"Output Mixer", NULL, "SHDN"}, 1270e45cab6SChristian Glindkamp {"DAC", NULL, "MCLK"}, 1280e45cab6SChristian Glindkamp }; 1290e45cab6SChristian Glindkamp 1300e45cab6SChristian Glindkamp static int max9850_hw_params(struct snd_pcm_substream *substream, 1310e45cab6SChristian Glindkamp struct snd_pcm_hw_params *params, 1320e45cab6SChristian Glindkamp struct snd_soc_dai *dai) 1330e45cab6SChristian Glindkamp { 1340e45cab6SChristian Glindkamp struct snd_soc_codec *codec = dai->codec; 1350e45cab6SChristian Glindkamp struct max9850_priv *max9850 = snd_soc_codec_get_drvdata(codec); 1360e45cab6SChristian Glindkamp u64 lrclk_div; 1370e45cab6SChristian Glindkamp u8 sf, da; 1380e45cab6SChristian Glindkamp 1390e45cab6SChristian Glindkamp if (!max9850->sysclk) 1400e45cab6SChristian Glindkamp return -EINVAL; 1410e45cab6SChristian Glindkamp 1420e45cab6SChristian Glindkamp /* lrclk_div = 2^22 * rate / iclk with iclk = mclk / sf */ 1430e45cab6SChristian Glindkamp sf = (snd_soc_read(codec, MAX9850_CLOCK) >> 2) + 1; 1440e45cab6SChristian Glindkamp lrclk_div = (1 << 22); 1450e45cab6SChristian Glindkamp lrclk_div *= params_rate(params); 1460e45cab6SChristian Glindkamp lrclk_div *= sf; 1470e45cab6SChristian Glindkamp do_div(lrclk_div, max9850->sysclk); 1480e45cab6SChristian Glindkamp 1490e45cab6SChristian Glindkamp snd_soc_write(codec, MAX9850_LRCLK_MSB, (lrclk_div >> 8) & 0x7f); 1500e45cab6SChristian Glindkamp snd_soc_write(codec, MAX9850_LRCLK_LSB, lrclk_div & 0xff); 1510e45cab6SChristian Glindkamp 1520e45cab6SChristian Glindkamp switch (params_format(params)) { 1530e45cab6SChristian Glindkamp case SNDRV_PCM_FORMAT_S16_LE: 1540e45cab6SChristian Glindkamp da = 0; 1550e45cab6SChristian Glindkamp break; 1560e45cab6SChristian Glindkamp case SNDRV_PCM_FORMAT_S20_3LE: 1570e45cab6SChristian Glindkamp da = 0x2; 1580e45cab6SChristian Glindkamp break; 1590e45cab6SChristian Glindkamp case SNDRV_PCM_FORMAT_S24_LE: 1600e45cab6SChristian Glindkamp da = 0x3; 1610e45cab6SChristian Glindkamp break; 1620e45cab6SChristian Glindkamp default: 1630e45cab6SChristian Glindkamp return -EINVAL; 1640e45cab6SChristian Glindkamp } 1650e45cab6SChristian Glindkamp snd_soc_update_bits(codec, MAX9850_DIGITAL_AUDIO, 0x3, da); 1660e45cab6SChristian Glindkamp 1670e45cab6SChristian Glindkamp return 0; 1680e45cab6SChristian Glindkamp } 1690e45cab6SChristian Glindkamp 1700e45cab6SChristian Glindkamp static int max9850_set_dai_sysclk(struct snd_soc_dai *codec_dai, 1710e45cab6SChristian Glindkamp int clk_id, unsigned int freq, int dir) 1720e45cab6SChristian Glindkamp { 1730e45cab6SChristian Glindkamp struct snd_soc_codec *codec = codec_dai->codec; 1740e45cab6SChristian Glindkamp struct max9850_priv *max9850 = snd_soc_codec_get_drvdata(codec); 1750e45cab6SChristian Glindkamp 1760e45cab6SChristian Glindkamp /* calculate mclk -> iclk divider */ 1770e45cab6SChristian Glindkamp if (freq <= 13000000) 1780e45cab6SChristian Glindkamp snd_soc_write(codec, MAX9850_CLOCK, 0x0); 1790e45cab6SChristian Glindkamp else if (freq <= 26000000) 1800e45cab6SChristian Glindkamp snd_soc_write(codec, MAX9850_CLOCK, 0x4); 1810e45cab6SChristian Glindkamp else if (freq <= 40000000) 1820e45cab6SChristian Glindkamp snd_soc_write(codec, MAX9850_CLOCK, 0x8); 1830e45cab6SChristian Glindkamp else 1840e45cab6SChristian Glindkamp return -EINVAL; 1850e45cab6SChristian Glindkamp 1860e45cab6SChristian Glindkamp max9850->sysclk = freq; 1870e45cab6SChristian Glindkamp return 0; 1880e45cab6SChristian Glindkamp } 1890e45cab6SChristian Glindkamp 1900e45cab6SChristian Glindkamp static int max9850_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) 1910e45cab6SChristian Glindkamp { 1920e45cab6SChristian Glindkamp struct snd_soc_codec *codec = codec_dai->codec; 1930e45cab6SChristian Glindkamp u8 da = 0; 1940e45cab6SChristian Glindkamp 1950e45cab6SChristian Glindkamp /* set master/slave audio interface */ 1960e45cab6SChristian Glindkamp switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 1970e45cab6SChristian Glindkamp case SND_SOC_DAIFMT_CBM_CFM: 1980e45cab6SChristian Glindkamp da |= MAX9850_MASTER; 1990e45cab6SChristian Glindkamp break; 2000e45cab6SChristian Glindkamp case SND_SOC_DAIFMT_CBS_CFS: 2010e45cab6SChristian Glindkamp break; 2020e45cab6SChristian Glindkamp default: 2030e45cab6SChristian Glindkamp return -EINVAL; 2040e45cab6SChristian Glindkamp } 2050e45cab6SChristian Glindkamp 2060e45cab6SChristian Glindkamp /* interface format */ 2070e45cab6SChristian Glindkamp switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 2080e45cab6SChristian Glindkamp case SND_SOC_DAIFMT_I2S: 2090e45cab6SChristian Glindkamp da |= MAX9850_DLY; 2100e45cab6SChristian Glindkamp break; 2110e45cab6SChristian Glindkamp case SND_SOC_DAIFMT_RIGHT_J: 2120e45cab6SChristian Glindkamp da |= MAX9850_RTJ; 2130e45cab6SChristian Glindkamp break; 2140e45cab6SChristian Glindkamp case SND_SOC_DAIFMT_LEFT_J: 2150e45cab6SChristian Glindkamp break; 2160e45cab6SChristian Glindkamp default: 2170e45cab6SChristian Glindkamp return -EINVAL; 2180e45cab6SChristian Glindkamp } 2190e45cab6SChristian Glindkamp 2200e45cab6SChristian Glindkamp /* clock inversion */ 2210e45cab6SChristian Glindkamp switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 2220e45cab6SChristian Glindkamp case SND_SOC_DAIFMT_NB_NF: 2230e45cab6SChristian Glindkamp break; 2240e45cab6SChristian Glindkamp case SND_SOC_DAIFMT_IB_IF: 2250e45cab6SChristian Glindkamp da |= MAX9850_BCINV | MAX9850_INV; 2260e45cab6SChristian Glindkamp break; 2270e45cab6SChristian Glindkamp case SND_SOC_DAIFMT_IB_NF: 2280e45cab6SChristian Glindkamp da |= MAX9850_BCINV; 2290e45cab6SChristian Glindkamp break; 2300e45cab6SChristian Glindkamp case SND_SOC_DAIFMT_NB_IF: 2310e45cab6SChristian Glindkamp da |= MAX9850_INV; 2320e45cab6SChristian Glindkamp break; 2330e45cab6SChristian Glindkamp default: 2340e45cab6SChristian Glindkamp return -EINVAL; 2350e45cab6SChristian Glindkamp } 2360e45cab6SChristian Glindkamp 2370e45cab6SChristian Glindkamp /* set da */ 2380e45cab6SChristian Glindkamp snd_soc_write(codec, MAX9850_DIGITAL_AUDIO, da); 2390e45cab6SChristian Glindkamp 2400e45cab6SChristian Glindkamp return 0; 2410e45cab6SChristian Glindkamp } 2420e45cab6SChristian Glindkamp 2430e45cab6SChristian Glindkamp static int max9850_set_bias_level(struct snd_soc_codec *codec, 2440e45cab6SChristian Glindkamp enum snd_soc_bias_level level) 2450e45cab6SChristian Glindkamp { 246*06841662SMark Brown struct max9850_priv *max9850 = snd_soc_codec_get_drvdata(codec); 2470e45cab6SChristian Glindkamp int ret; 2480e45cab6SChristian Glindkamp 2490e45cab6SChristian Glindkamp switch (level) { 2500e45cab6SChristian Glindkamp case SND_SOC_BIAS_ON: 2510e45cab6SChristian Glindkamp break; 2520e45cab6SChristian Glindkamp case SND_SOC_BIAS_PREPARE: 2530e45cab6SChristian Glindkamp break; 2540e45cab6SChristian Glindkamp case SND_SOC_BIAS_STANDBY: 2550e45cab6SChristian Glindkamp if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { 256*06841662SMark Brown ret = regcache_sync(max9850->regmap); 2570e45cab6SChristian Glindkamp if (ret) { 2580e45cab6SChristian Glindkamp dev_err(codec->dev, 2590e45cab6SChristian Glindkamp "Failed to sync cache: %d\n", ret); 2600e45cab6SChristian Glindkamp return ret; 2610e45cab6SChristian Glindkamp } 2620e45cab6SChristian Glindkamp } 2630e45cab6SChristian Glindkamp break; 2640e45cab6SChristian Glindkamp case SND_SOC_BIAS_OFF: 2650e45cab6SChristian Glindkamp break; 2660e45cab6SChristian Glindkamp } 2670e45cab6SChristian Glindkamp codec->dapm.bias_level = level; 2680e45cab6SChristian Glindkamp return 0; 2690e45cab6SChristian Glindkamp } 2700e45cab6SChristian Glindkamp 2710e45cab6SChristian Glindkamp #define MAX9850_RATES SNDRV_PCM_RATE_8000_48000 2720e45cab6SChristian Glindkamp 2730e45cab6SChristian Glindkamp #define MAX9850_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 2740e45cab6SChristian Glindkamp SNDRV_PCM_FMTBIT_S24_LE) 2750e45cab6SChristian Glindkamp 27685e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops max9850_dai_ops = { 2770e45cab6SChristian Glindkamp .hw_params = max9850_hw_params, 2780e45cab6SChristian Glindkamp .set_sysclk = max9850_set_dai_sysclk, 2790e45cab6SChristian Glindkamp .set_fmt = max9850_set_dai_fmt, 2800e45cab6SChristian Glindkamp }; 2810e45cab6SChristian Glindkamp 2820e45cab6SChristian Glindkamp static struct snd_soc_dai_driver max9850_dai = { 2830e45cab6SChristian Glindkamp .name = "max9850-hifi", 2840e45cab6SChristian Glindkamp .playback = { 2850e45cab6SChristian Glindkamp .stream_name = "Playback", 2860e45cab6SChristian Glindkamp .channels_min = 1, 2870e45cab6SChristian Glindkamp .channels_max = 2, 2880e45cab6SChristian Glindkamp .rates = MAX9850_RATES, 2890e45cab6SChristian Glindkamp .formats = MAX9850_FORMATS 2900e45cab6SChristian Glindkamp }, 2910e45cab6SChristian Glindkamp .ops = &max9850_dai_ops, 2920e45cab6SChristian Glindkamp }; 2930e45cab6SChristian Glindkamp 2940e45cab6SChristian Glindkamp #ifdef CONFIG_PM 29584b315eeSLars-Peter Clausen static int max9850_suspend(struct snd_soc_codec *codec) 2960e45cab6SChristian Glindkamp { 2970e45cab6SChristian Glindkamp max9850_set_bias_level(codec, SND_SOC_BIAS_OFF); 2980e45cab6SChristian Glindkamp 2990e45cab6SChristian Glindkamp return 0; 3000e45cab6SChristian Glindkamp } 3010e45cab6SChristian Glindkamp 3020e45cab6SChristian Glindkamp static int max9850_resume(struct snd_soc_codec *codec) 3030e45cab6SChristian Glindkamp { 3040e45cab6SChristian Glindkamp max9850_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 3050e45cab6SChristian Glindkamp 3060e45cab6SChristian Glindkamp return 0; 3070e45cab6SChristian Glindkamp } 3080e45cab6SChristian Glindkamp #else 3090e45cab6SChristian Glindkamp #define max9850_suspend NULL 3100e45cab6SChristian Glindkamp #define max9850_resume NULL 3110e45cab6SChristian Glindkamp #endif 3120e45cab6SChristian Glindkamp 3130e45cab6SChristian Glindkamp static int max9850_probe(struct snd_soc_codec *codec) 3140e45cab6SChristian Glindkamp { 3150e45cab6SChristian Glindkamp int ret; 3160e45cab6SChristian Glindkamp 317*06841662SMark Brown ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP); 3180e45cab6SChristian Glindkamp if (ret < 0) { 3190e45cab6SChristian Glindkamp dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 3200e45cab6SChristian Glindkamp return ret; 3210e45cab6SChristian Glindkamp } 3220e45cab6SChristian Glindkamp 3230e45cab6SChristian Glindkamp /* enable zero-detect */ 3240e45cab6SChristian Glindkamp snd_soc_update_bits(codec, MAX9850_GENERAL_PURPOSE, 1, 1); 3250e45cab6SChristian Glindkamp /* enable slew-rate control */ 3260e45cab6SChristian Glindkamp snd_soc_update_bits(codec, MAX9850_VOLUME, 0x40, 0x40); 3270e45cab6SChristian Glindkamp /* set slew-rate 125ms */ 3280e45cab6SChristian Glindkamp snd_soc_update_bits(codec, MAX9850_CHARGE_PUMP, 0xff, 0xc0); 3290e45cab6SChristian Glindkamp 3300e45cab6SChristian Glindkamp return 0; 3310e45cab6SChristian Glindkamp } 3320e45cab6SChristian Glindkamp 3330e45cab6SChristian Glindkamp static struct snd_soc_codec_driver soc_codec_dev_max9850 = { 3340e45cab6SChristian Glindkamp .probe = max9850_probe, 3350e45cab6SChristian Glindkamp .suspend = max9850_suspend, 3360e45cab6SChristian Glindkamp .resume = max9850_resume, 3370e45cab6SChristian Glindkamp .set_bias_level = max9850_set_bias_level, 3385ee65ec6SAxel Lin 3395ee65ec6SAxel Lin .controls = max9850_controls, 3405ee65ec6SAxel Lin .num_controls = ARRAY_SIZE(max9850_controls), 3415ee65ec6SAxel Lin .dapm_widgets = max9850_dapm_widgets, 3425ee65ec6SAxel Lin .num_dapm_widgets = ARRAY_SIZE(max9850_dapm_widgets), 3435ee65ec6SAxel Lin .dapm_routes = max9850_dapm_routes, 3445ee65ec6SAxel Lin .num_dapm_routes = ARRAY_SIZE(max9850_dapm_routes), 3450e45cab6SChristian Glindkamp }; 3460e45cab6SChristian Glindkamp 3477a79e94eSBill Pemberton static int max9850_i2c_probe(struct i2c_client *i2c, 3480e45cab6SChristian Glindkamp const struct i2c_device_id *id) 3490e45cab6SChristian Glindkamp { 3500e45cab6SChristian Glindkamp struct max9850_priv *max9850; 3510e45cab6SChristian Glindkamp int ret; 3520e45cab6SChristian Glindkamp 353bf791bdbSAxel Lin max9850 = devm_kzalloc(&i2c->dev, sizeof(struct max9850_priv), 354bf791bdbSAxel Lin GFP_KERNEL); 3550e45cab6SChristian Glindkamp if (max9850 == NULL) 3560e45cab6SChristian Glindkamp return -ENOMEM; 3570e45cab6SChristian Glindkamp 358*06841662SMark Brown max9850->regmap = devm_regmap_init_i2c(i2c, &max9850_regmap); 359*06841662SMark Brown if (IS_ERR(max9850->regmap)) 360*06841662SMark Brown return PTR_ERR(max9850->regmap); 361*06841662SMark Brown 3620e45cab6SChristian Glindkamp i2c_set_clientdata(i2c, max9850); 3630e45cab6SChristian Glindkamp 3640e45cab6SChristian Glindkamp ret = snd_soc_register_codec(&i2c->dev, 3650e45cab6SChristian Glindkamp &soc_codec_dev_max9850, &max9850_dai, 1); 3660e45cab6SChristian Glindkamp return ret; 3670e45cab6SChristian Glindkamp } 3680e45cab6SChristian Glindkamp 3697a79e94eSBill Pemberton static int max9850_i2c_remove(struct i2c_client *client) 3700e45cab6SChristian Glindkamp { 3710e45cab6SChristian Glindkamp snd_soc_unregister_codec(&client->dev); 3720e45cab6SChristian Glindkamp return 0; 3730e45cab6SChristian Glindkamp } 3740e45cab6SChristian Glindkamp 3750e45cab6SChristian Glindkamp static const struct i2c_device_id max9850_i2c_id[] = { 3760e45cab6SChristian Glindkamp { "max9850", 0 }, 3770e45cab6SChristian Glindkamp { } 3780e45cab6SChristian Glindkamp }; 3790e45cab6SChristian Glindkamp MODULE_DEVICE_TABLE(i2c, max9850_i2c_id); 3800e45cab6SChristian Glindkamp 3810e45cab6SChristian Glindkamp static struct i2c_driver max9850_i2c_driver = { 3820e45cab6SChristian Glindkamp .driver = { 3830e45cab6SChristian Glindkamp .name = "max9850", 3840e45cab6SChristian Glindkamp .owner = THIS_MODULE, 3850e45cab6SChristian Glindkamp }, 3860e45cab6SChristian Glindkamp .probe = max9850_i2c_probe, 3877a79e94eSBill Pemberton .remove = max9850_i2c_remove, 3880e45cab6SChristian Glindkamp .id_table = max9850_i2c_id, 3890e45cab6SChristian Glindkamp }; 3900e45cab6SChristian Glindkamp 3914abdc8c8SSachin Kamat module_i2c_driver(max9850_i2c_driver); 3920e45cab6SChristian Glindkamp 3930e45cab6SChristian Glindkamp MODULE_AUTHOR("Christian Glindkamp <christian.glindkamp@taskit.de>"); 3940e45cab6SChristian Glindkamp MODULE_DESCRIPTION("ASoC MAX9850 codec driver"); 3950e45cab6SChristian Glindkamp MODULE_LICENSE("GPL"); 396