| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
// |
| 3 |
// Audio driver for AK5558 ADC |
| 4 |
// |
| 5 |
// Copyright (C) 2015 Asahi Kasei Microdevices Corporation |
| 6 |
// Copyright 2018 NXP |
| 7 |
|
| 8 |
#include <linux/delay.h> |
| 9 |
#include <linux/gpio/consumer.h> |
| 10 |
#include <linux/i2c.h> |
| 11 |
#include <linux/module.h> |
| 12 |
#include <linux/of.h> |
| 13 |
#include <linux/pm_runtime.h> |
| 14 |
#include <linux/regmap.h> |
| 15 |
#include <linux/regulator/consumer.h> |
| 16 |
#include <linux/slab.h> |
| 17 |
|
| 18 |
#include <sound/initval.h> |
| 19 |
#include <sound/pcm.h> |
| 20 |
#include <sound/pcm_params.h> |
| 21 |
#include <sound/soc.h> |
| 22 |
#include <sound/soc-dapm.h> |
| 23 |
#include <sound/tlv.h> |
| 24 |
|
| 25 |
#include "ak5558.h" |
| 26 |
|
| 27 |
enum ak555x_type { |
| 28 |
AK5558, |
| 29 |
AK5552, |
| 30 |
}; |
| 31 |
|
| 32 |
#define AK5558_NUM_SUPPLIES 2 |
| 33 |
static const char *ak5558_supply_names[AK5558_NUM_SUPPLIES] = { |
| 34 |
"DVDD", |
| 35 |
"AVDD", |
| 36 |
}; |
| 37 |
|
| 38 |
/* AK5558 Codec Private Data */ |
| 39 |
struct ak5558_priv { |
| 40 |
struct regulator_bulk_data supplies[AK5558_NUM_SUPPLIES]; |
| 41 |
struct snd_soc_component component; |
| 42 |
struct regmap *regmap; |
| 43 |
struct i2c_client *i2c; |
| 44 |
struct gpio_desc *reset_gpiod; /* Reset & Power down GPIO */ |
| 45 |
int slots; |
| 46 |
int slot_width; |
| 47 |
}; |
| 48 |
|
| 49 |
/* ak5558 register cache & default register settings */ |
| 50 |
static const struct reg_default ak5558_reg[] = { |
| 51 |
{ 0x0, 0xFF }, /* 0x00 AK5558_00_POWER_MANAGEMENT1 */ |
| 52 |
{ 0x1, 0x01 }, /* 0x01 AK5558_01_POWER_MANAGEMENT2 */ |
| 53 |
{ 0x2, 0x01 }, /* 0x02 AK5558_02_CONTROL1 */ |
| 54 |
{ 0x3, 0x00 }, /* 0x03 AK5558_03_CONTROL2 */ |
| 55 |
{ 0x4, 0x00 }, /* 0x04 AK5558_04_CONTROL3 */ |
| 56 |
{ 0x5, 0x00 } /* 0x05 AK5558_05_DSD */ |
| 57 |
}; |
| 58 |
|
| 59 |
static const char * const mono_texts[] = { |
| 60 |
"8 Slot", "2 Slot", "4 Slot", "1 Slot", |
| 61 |
}; |
| 62 |
|
| 63 |
static const struct soc_enum ak5558_mono_enum[] = { |
| 64 |
SOC_ENUM_SINGLE(AK5558_01_POWER_MANAGEMENT2, 1, |
| 65 |
ARRAY_SIZE(mono_texts), mono_texts), |
| 66 |
}; |
| 67 |
|
| 68 |
static const char * const mono_5552_texts[] = { |
| 69 |
"2 Slot", "1 Slot (Fixed)", "2 Slot", "1 Slot (Optimal)", |
| 70 |
}; |
| 71 |
|
| 72 |
static const struct soc_enum ak5552_mono_enum[] = { |
| 73 |
SOC_ENUM_SINGLE(AK5558_01_POWER_MANAGEMENT2, 1, |
| 74 |
ARRAY_SIZE(mono_5552_texts), mono_5552_texts), |
| 75 |
}; |
| 76 |
|
| 77 |
static const char * const digfil_texts[] = { |
| 78 |
"Sharp Roll-Off", "Slow Roll-Off", |
| 79 |
"Short Delay Sharp Roll-Off", "Short Delay Slow Roll-Off", |
| 80 |
}; |
| 81 |
|
| 82 |
static const struct soc_enum ak5558_adcset_enum[] = { |
| 83 |
SOC_ENUM_SINGLE(AK5558_04_CONTROL3, 0, |
| 84 |
ARRAY_SIZE(digfil_texts), digfil_texts), |
| 85 |
}; |
| 86 |
|
| 87 |
static const struct snd_kcontrol_new ak5558_snd_controls[] = { |
| 88 |
SOC_ENUM("Monaural Mode", ak5558_mono_enum[0]), |
| 89 |
SOC_ENUM("Digital Filter", ak5558_adcset_enum[0]), |
| 90 |
}; |
| 91 |
|
| 92 |
static const struct snd_kcontrol_new ak5552_snd_controls[] = { |
| 93 |
SOC_ENUM("Monaural Mode", ak5552_mono_enum[0]), |
| 94 |
SOC_ENUM("Digital Filter", ak5558_adcset_enum[0]), |
| 95 |
}; |
| 96 |
|
| 97 |
static const struct snd_soc_dapm_widget ak5558_dapm_widgets[] = { |
| 98 |
/* Analog Input */ |
| 99 |
SND_SOC_DAPM_INPUT("AIN1"), |
| 100 |
SND_SOC_DAPM_INPUT("AIN2"), |
| 101 |
SND_SOC_DAPM_INPUT("AIN3"), |
| 102 |
SND_SOC_DAPM_INPUT("AIN4"), |
| 103 |
SND_SOC_DAPM_INPUT("AIN5"), |
| 104 |
SND_SOC_DAPM_INPUT("AIN6"), |
| 105 |
SND_SOC_DAPM_INPUT("AIN7"), |
| 106 |
SND_SOC_DAPM_INPUT("AIN8"), |
| 107 |
|
| 108 |
SND_SOC_DAPM_ADC("ADC Ch1", NULL, AK5558_00_POWER_MANAGEMENT1, 0, 0), |
| 109 |
SND_SOC_DAPM_ADC("ADC Ch2", NULL, AK5558_00_POWER_MANAGEMENT1, 1, 0), |
| 110 |
SND_SOC_DAPM_ADC("ADC Ch3", NULL, AK5558_00_POWER_MANAGEMENT1, 2, 0), |
| 111 |
SND_SOC_DAPM_ADC("ADC Ch4", NULL, AK5558_00_POWER_MANAGEMENT1, 3, 0), |
| 112 |
SND_SOC_DAPM_ADC("ADC Ch5", NULL, AK5558_00_POWER_MANAGEMENT1, 4, 0), |
| 113 |
SND_SOC_DAPM_ADC("ADC Ch6", NULL, AK5558_00_POWER_MANAGEMENT1, 5, 0), |
| 114 |
SND_SOC_DAPM_ADC("ADC Ch7", NULL, AK5558_00_POWER_MANAGEMENT1, 6, 0), |
| 115 |
SND_SOC_DAPM_ADC("ADC Ch8", NULL, AK5558_00_POWER_MANAGEMENT1, 7, 0), |
| 116 |
|
| 117 |
SND_SOC_DAPM_AIF_OUT("SDTO", "Capture", 0, SND_SOC_NOPM, 0, 0), |
| 118 |
}; |
| 119 |
|
| 120 |
static const struct snd_soc_dapm_widget ak5552_dapm_widgets[] = { |
| 121 |
/* Analog Input */ |
| 122 |
SND_SOC_DAPM_INPUT("AIN1"), |
| 123 |
SND_SOC_DAPM_INPUT("AIN2"), |
| 124 |
|
| 125 |
SND_SOC_DAPM_ADC("ADC Ch1", NULL, AK5558_00_POWER_MANAGEMENT1, 0, 0), |
| 126 |
SND_SOC_DAPM_ADC("ADC Ch2", NULL, AK5558_00_POWER_MANAGEMENT1, 1, 0), |
| 127 |
|
| 128 |
SND_SOC_DAPM_AIF_OUT("SDTO", "Capture", 0, SND_SOC_NOPM, 0, 0), |
| 129 |
}; |
| 130 |
|
| 131 |
static const struct snd_soc_dapm_route ak5558_intercon[] = { |
| 132 |
{"ADC Ch1", NULL, "AIN1"}, |
| 133 |
{"SDTO", NULL, "ADC Ch1"}, |
| 134 |
|
| 135 |
{"ADC Ch2", NULL, "AIN2"}, |
| 136 |
{"SDTO", NULL, "ADC Ch2"}, |
| 137 |
|
| 138 |
{"ADC Ch3", NULL, "AIN3"}, |
| 139 |
{"SDTO", NULL, "ADC Ch3"}, |
| 140 |
|
| 141 |
{"ADC Ch4", NULL, "AIN4"}, |
| 142 |
{"SDTO", NULL, "ADC Ch4"}, |
| 143 |
|
| 144 |
{"ADC Ch5", NULL, "AIN5"}, |
| 145 |
{"SDTO", NULL, "ADC Ch5"}, |
| 146 |
|
| 147 |
{"ADC Ch6", NULL, "AIN6"}, |
| 148 |
{"SDTO", NULL, "ADC Ch6"}, |
| 149 |
|
| 150 |
{"ADC Ch7", NULL, "AIN7"}, |
| 151 |
{"SDTO", NULL, "ADC Ch7"}, |
| 152 |
|
| 153 |
{"ADC Ch8", NULL, "AIN8"}, |
| 154 |
{"SDTO", NULL, "ADC Ch8"}, |
| 155 |
}; |
| 156 |
|
| 157 |
static const struct snd_soc_dapm_route ak5552_intercon[] = { |
| 158 |
{"ADC Ch1", NULL, "AIN1"}, |
| 159 |
{"SDTO", NULL, "ADC Ch1"}, |
| 160 |
|
| 161 |
{"ADC Ch2", NULL, "AIN2"}, |
| 162 |
{"SDTO", NULL, "ADC Ch2"}, |
| 163 |
}; |
| 164 |
|
| 165 |
static int ak5558_set_mcki(struct snd_soc_component *component) |
| 166 |
{ |
| 167 |
return snd_soc_component_update_bits(component, AK5558_02_CONTROL1, AK5558_CKS, |
| 168 |
AK5558_CKS_AUTO); |
| 169 |
} |
| 170 |
|
| 171 |
static int ak5558_hw_params(struct snd_pcm_substream *substream, |
| 172 |
struct snd_pcm_hw_params *params, |
| 173 |
struct snd_soc_dai *dai) |
| 174 |
{ |
| 175 |
struct snd_soc_component *component = dai->component; |
| 176 |
struct ak5558_priv *ak5558 = snd_soc_component_get_drvdata(component); |
| 177 |
u8 bits; |
| 178 |
int pcm_width = max(params_physical_width(params), ak5558->slot_width); |
| 179 |
|
| 180 |
switch (pcm_width) { |
| 181 |
case 16: |
| 182 |
bits = AK5558_DIF_24BIT_MODE; |
| 183 |
break; |
| 184 |
case 32: |
| 185 |
bits = AK5558_DIF_32BIT_MODE; |
| 186 |
break; |
| 187 |
default: |
| 188 |
return -EINVAL; |
| 189 |
} |
| 190 |
|
| 191 |
snd_soc_component_update_bits(component, AK5558_02_CONTROL1, AK5558_BITS, bits); |
| 192 |
|
| 193 |
return 0; |
| 194 |
} |
| 195 |
|
| 196 |
static int ak5558_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt) |
| 197 |
{ |
| 198 |
struct snd_soc_component *component = dai->component; |
| 199 |
u8 format; |
| 200 |
|
| 201 |
switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) { |
| 202 |
case SND_SOC_DAIFMT_CBC_CFC: |
| 203 |
break; |
| 204 |
case SND_SOC_DAIFMT_CBP_CFP: |
| 205 |
break; |
| 206 |
case SND_SOC_DAIFMT_CBC_CFP: |
| 207 |
case SND_SOC_DAIFMT_CBP_CFC: |
| 208 |
default: |
| 209 |
dev_err(dai->dev, "Clock mode unsupported"); |
| 210 |
return -EINVAL; |
| 211 |
} |
| 212 |
|
| 213 |
/* set master/slave audio interface */ |
| 214 |
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 215 |
case SND_SOC_DAIFMT_I2S: |
| 216 |
format = AK5558_DIF_I2S_MODE; |
| 217 |
break; |
| 218 |
case SND_SOC_DAIFMT_LEFT_J: |
| 219 |
format = AK5558_DIF_MSB_MODE; |
| 220 |
break; |
| 221 |
case SND_SOC_DAIFMT_DSP_B: |
| 222 |
format = AK5558_DIF_MSB_MODE; |
| 223 |
break; |
| 224 |
default: |
| 225 |
return -EINVAL; |
| 226 |
} |
| 227 |
|
| 228 |
snd_soc_component_update_bits(component, AK5558_02_CONTROL1, AK5558_DIF, format); |
| 229 |
|
| 230 |
return 0; |
| 231 |
} |
| 232 |
|
| 233 |
static int ak5558_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, |
| 234 |
unsigned int rx_mask, int slots, |
| 235 |
int slot_width) |
| 236 |
{ |
| 237 |
struct snd_soc_component *component = dai->component; |
| 238 |
struct ak5558_priv *ak5558 = snd_soc_component_get_drvdata(component); |
| 239 |
int tdm_mode; |
| 240 |
|
| 241 |
ak5558->slots = slots; |
| 242 |
ak5558->slot_width = slot_width; |
| 243 |
|
| 244 |
switch (slots * slot_width) { |
| 245 |
case 128: |
| 246 |
tdm_mode = AK5558_MODE_TDM128; |
| 247 |
break; |
| 248 |
case 256: |
| 249 |
tdm_mode = AK5558_MODE_TDM256; |
| 250 |
break; |
| 251 |
case 512: |
| 252 |
tdm_mode = AK5558_MODE_TDM512; |
| 253 |
break; |
| 254 |
default: |
| 255 |
tdm_mode = AK5558_MODE_NORMAL; |
| 256 |
break; |
| 257 |
} |
| 258 |
|
| 259 |
snd_soc_component_update_bits(component, AK5558_03_CONTROL2, AK5558_MODE_BITS, |
| 260 |
tdm_mode); |
| 261 |
return 0; |
| 262 |
} |
| 263 |
|
| 264 |
#define AK5558_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\ |
| 265 |
SNDRV_PCM_FMTBIT_S24_LE |\ |
| 266 |
SNDRV_PCM_FMTBIT_S32_LE) |
| 267 |
|
| 268 |
static const unsigned int ak5558_rates[] = { |
| 269 |
8000, 11025, 16000, 22050, |
| 270 |
32000, 44100, 48000, 88200, |
| 271 |
96000, 176400, 192000, 352800, |
| 272 |
384000, 705600, 768000, 1411200, |
| 273 |
2822400, |
| 274 |
}; |
| 275 |
|
| 276 |
static const struct snd_pcm_hw_constraint_list ak5558_rate_constraints = { |
| 277 |
.count = ARRAY_SIZE(ak5558_rates), |
| 278 |
.list = ak5558_rates, |
| 279 |
}; |
| 280 |
|
| 281 |
static int ak5558_startup(struct snd_pcm_substream *substream, |
| 282 |
struct snd_soc_dai *dai) |
| 283 |
{ |
| 284 |
return snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 285 |
SNDRV_PCM_HW_PARAM_RATE, |
| 286 |
&ak5558_rate_constraints); |
| 287 |
} |
| 288 |
|
| 289 |
static const struct snd_soc_dai_ops ak5558_dai_ops = { |
| 290 |
.startup = ak5558_startup, |
| 291 |
.hw_params = ak5558_hw_params, |
| 292 |
|
| 293 |
.set_fmt = ak5558_set_dai_fmt, |
| 294 |
.set_tdm_slot = ak5558_set_tdm_slot, |
| 295 |
}; |
| 296 |
|
| 297 |
static struct snd_soc_dai_driver ak5558_dai = { |
| 298 |
.name = "ak5558-aif", |
| 299 |
.capture = { |
| 300 |
.stream_name = "Capture", |
| 301 |
.channels_min = 1, |
| 302 |
.channels_max = 8, |
| 303 |
.rates = SNDRV_PCM_RATE_KNOT, |
| 304 |
.formats = AK5558_FORMATS, |
| 305 |
}, |
| 306 |
.ops = &ak5558_dai_ops, |
| 307 |
}; |
| 308 |
|
| 309 |
static struct snd_soc_dai_driver ak5552_dai = { |
| 310 |
.name = "ak5552-aif", |
| 311 |
.capture = { |
| 312 |
.stream_name = "Capture", |
| 313 |
.channels_min = 1, |
| 314 |
.channels_max = 2, |
| 315 |
.rates = SNDRV_PCM_RATE_KNOT, |
| 316 |
.formats = AK5558_FORMATS, |
| 317 |
}, |
| 318 |
.ops = &ak5558_dai_ops, |
| 319 |
}; |
| 320 |
|
| 321 |
static void ak5558_reset(struct ak5558_priv *ak5558, bool active) |
| 322 |
{ |
| 323 |
if (!ak5558->reset_gpiod) |
| 324 |
return; |
| 325 |
|
| 326 |
gpiod_set_value_cansleep(ak5558->reset_gpiod, active); |
| 327 |
usleep_range(1000, 2000); |
| 328 |
} |
| 329 |
|
| 330 |
static int ak5558_probe(struct snd_soc_component *component) |
| 331 |
{ |
| 332 |
struct ak5558_priv *ak5558 = snd_soc_component_get_drvdata(component); |
| 333 |
|
| 334 |
ak5558_reset(ak5558, false); |
| 335 |
return ak5558_set_mcki(component); |
| 336 |
} |
| 337 |
|
| 338 |
static void ak5558_remove(struct snd_soc_component *component) |
| 339 |
{ |
| 340 |
struct ak5558_priv *ak5558 = snd_soc_component_get_drvdata(component); |
| 341 |
|
| 342 |
ak5558_reset(ak5558, true); |
| 343 |
} |
| 344 |
|
| 345 |
static int ak5558_runtime_suspend(struct device *dev) |
| 346 |
{ |
| 347 |
struct ak5558_priv *ak5558 = dev_get_drvdata(dev); |
| 348 |
|
| 349 |
regcache_cache_only(ak5558->regmap, true); |
| 350 |
ak5558_reset(ak5558, true); |
| 351 |
|
| 352 |
regulator_bulk_disable(ARRAY_SIZE(ak5558->supplies), |
| 353 |
ak5558->supplies); |
| 354 |
return 0; |
| 355 |
} |
| 356 |
|
| 357 |
static int ak5558_runtime_resume(struct device *dev) |
| 358 |
{ |
| 359 |
struct ak5558_priv *ak5558 = dev_get_drvdata(dev); |
| 360 |
int ret; |
| 361 |
|
| 362 |
ret = regulator_bulk_enable(ARRAY_SIZE(ak5558->supplies), |
| 363 |
ak5558->supplies); |
| 364 |
if (ret != 0) { |
| 365 |
dev_err(dev, "Failed to enable supplies: %d\n", ret); |
| 366 |
return ret; |
| 367 |
} |
| 368 |
|
| 369 |
ak5558_reset(ak5558, true); |
| 370 |
ak5558_reset(ak5558, false); |
| 371 |
|
| 372 |
regcache_cache_only(ak5558->regmap, false); |
| 373 |
regcache_mark_dirty(ak5558->regmap); |
| 374 |
|
| 375 |
ret = regcache_sync(ak5558->regmap); |
| 376 |
if (ret) |
| 377 |
goto err; |
| 378 |
|
| 379 |
return 0; |
| 380 |
err: |
| 381 |
regcache_cache_only(ak5558->regmap, true); |
| 382 |
regulator_bulk_disable(ARRAY_SIZE(ak5558->supplies), ak5558->supplies); |
| 383 |
return ret; |
| 384 |
} |
| 385 |
|
| 386 |
static const struct dev_pm_ops ak5558_pm = { |
| 387 |
RUNTIME_PM_OPS(ak5558_runtime_suspend, ak5558_runtime_resume, NULL) |
| 388 |
SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) |
| 389 |
}; |
| 390 |
|
| 391 |
static const struct snd_soc_component_driver soc_codec_dev_ak5558 = { |
| 392 |
.probe = ak5558_probe, |
| 393 |
.remove = ak5558_remove, |
| 394 |
.controls = ak5558_snd_controls, |
| 395 |
.num_controls = ARRAY_SIZE(ak5558_snd_controls), |
| 396 |
.dapm_widgets = ak5558_dapm_widgets, |
| 397 |
.num_dapm_widgets = ARRAY_SIZE(ak5558_dapm_widgets), |
| 398 |
.dapm_routes = ak5558_intercon, |
| 399 |
.num_dapm_routes = ARRAY_SIZE(ak5558_intercon), |
| 400 |
.idle_bias_on = 1, |
| 401 |
.use_pmdown_time = 1, |
| 402 |
.endianness = 1, |
| 403 |
}; |
| 404 |
|
| 405 |
static const struct snd_soc_component_driver soc_codec_dev_ak5552 = { |
| 406 |
.probe = ak5558_probe, |
| 407 |
.remove = ak5558_remove, |
| 408 |
.controls = ak5552_snd_controls, |
| 409 |
.num_controls = ARRAY_SIZE(ak5552_snd_controls), |
| 410 |
.dapm_widgets = ak5552_dapm_widgets, |
| 411 |
.num_dapm_widgets = ARRAY_SIZE(ak5552_dapm_widgets), |
| 412 |
.dapm_routes = ak5552_intercon, |
| 413 |
.num_dapm_routes = ARRAY_SIZE(ak5552_intercon), |
| 414 |
.idle_bias_on = 1, |
| 415 |
.use_pmdown_time = 1, |
| 416 |
.endianness = 1, |
| 417 |
}; |
| 418 |
|
| 419 |
static const struct regmap_config ak5558_regmap = { |
| 420 |
.reg_bits = 8, |
| 421 |
.val_bits = 8, |
| 422 |
|
| 423 |
.max_register = AK5558_05_DSD, |
| 424 |
.reg_defaults = ak5558_reg, |
| 425 |
.num_reg_defaults = ARRAY_SIZE(ak5558_reg), |
| 426 |
.cache_type = REGCACHE_RBTREE, |
| 427 |
}; |
| 428 |
|
| 429 |
static int ak5558_i2c_probe(struct i2c_client *i2c) |
| 430 |
{ |
| 431 |
struct ak5558_priv *ak5558; |
| 432 |
int ret = 0; |
| 433 |
int dev_id; |
| 434 |
int i; |
| 435 |
|
| 436 |
ak5558 = devm_kzalloc(&i2c->dev, sizeof(*ak5558), GFP_KERNEL); |
| 437 |
if (!ak5558) |
| 438 |
return -ENOMEM; |
| 439 |
|
| 440 |
ak5558->regmap = devm_regmap_init_i2c(i2c, &ak5558_regmap); |
| 441 |
if (IS_ERR(ak5558->regmap)) |
| 442 |
return PTR_ERR(ak5558->regmap); |
| 443 |
|
| 444 |
i2c_set_clientdata(i2c, ak5558); |
| 445 |
ak5558->i2c = i2c; |
| 446 |
|
| 447 |
ak5558->reset_gpiod = devm_gpiod_get_optional(&i2c->dev, "reset", |
| 448 |
GPIOD_OUT_LOW); |
| 449 |
if (IS_ERR(ak5558->reset_gpiod)) |
| 450 |
return PTR_ERR(ak5558->reset_gpiod); |
| 451 |
|
| 452 |
for (i = 0; i < ARRAY_SIZE(ak5558->supplies); i++) |
| 453 |
ak5558->supplies[i].supply = ak5558_supply_names[i]; |
| 454 |
|
| 455 |
ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(ak5558->supplies), |
| 456 |
ak5558->supplies); |
| 457 |
if (ret != 0) { |
| 458 |
dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); |
| 459 |
return ret; |
| 460 |
} |
| 461 |
|
| 462 |
dev_id = (uintptr_t)of_device_get_match_data(&i2c->dev); |
| 463 |
switch (dev_id) { |
| 464 |
case AK5552: |
| 465 |
ret = devm_snd_soc_register_component(&i2c->dev, |
| 466 |
&soc_codec_dev_ak5552, |
| 467 |
&ak5552_dai, 1); |
| 468 |
break; |
| 469 |
case AK5558: |
| 470 |
ret = devm_snd_soc_register_component(&i2c->dev, |
| 471 |
&soc_codec_dev_ak5558, |
| 472 |
&ak5558_dai, 1); |
| 473 |
break; |
| 474 |
default: |
| 475 |
dev_err(&i2c->dev, "unexpected device type\n"); |
| 476 |
return -EINVAL; |
| 477 |
} |
| 478 |
if (ret < 0) { |
| 479 |
dev_err(&i2c->dev, "failed to register component: %d\n", ret); |
| 480 |
return ret; |
| 481 |
} |
| 482 |
|
| 483 |
pm_runtime_enable(&i2c->dev); |
| 484 |
regcache_cache_only(ak5558->regmap, true); |
| 485 |
|
| 486 |
return 0; |
| 487 |
} |
| 488 |
|
| 489 |
static void ak5558_i2c_remove(struct i2c_client *i2c) |
| 490 |
{ |
| 491 |
pm_runtime_disable(&i2c->dev); |
| 492 |
} |
| 493 |
|
| 494 |
static const struct of_device_id ak5558_i2c_dt_ids[] __maybe_unused = { |
| 495 |
{ .compatible = "asahi-kasei,ak5558", .data = (void *) AK5558 }, |
| 496 |
{ .compatible = "asahi-kasei,ak5552", .data = (void *) AK5552 }, |
| 497 |
{ } |
| 498 |
}; |
| 499 |
MODULE_DEVICE_TABLE(of, ak5558_i2c_dt_ids); |
| 500 |
|
| 501 |
static struct i2c_driver ak5558_i2c_driver = { |
| 502 |
.driver = { |
| 503 |
.name = "ak5558", |
| 504 |
.of_match_table = of_match_ptr(ak5558_i2c_dt_ids), |
| 505 |
.pm = pm_ptr(&ak5558_pm), |
| 506 |
}, |
| 507 |
.probe = ak5558_i2c_probe, |
| 508 |
.remove = ak5558_i2c_remove, |
| 509 |
}; |
| 510 |
|
| 511 |
module_i2c_driver(ak5558_i2c_driver); |
| 512 |
|
| 513 |
MODULE_AUTHOR("Junichi Wakasugi <[email protected]>"); |
| 514 |
MODULE_AUTHOR("Mihai Serban <[email protected]>"); |
| 515 |
MODULE_DESCRIPTION("ASoC AK5558 ADC driver"); |
| 516 |
MODULE_LICENSE("GPL v2"); |