ak4535.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /*
  2. * ak4535.c -- AK4535 ALSA Soc Audio driver
  3. *
  4. * Copyright 2005 Openedhand Ltd.
  5. *
  6. * Author: Richard Purdie <richard@openedhand.com>
  7. *
  8. * Based on wm8753.c by Liam Girdwood
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/module.h>
  15. #include <linux/moduleparam.h>
  16. #include <linux/init.h>
  17. #include <linux/delay.h>
  18. #include <linux/pm.h>
  19. #include <linux/i2c.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/slab.h>
  22. #include <sound/core.h>
  23. #include <sound/pcm.h>
  24. #include <sound/pcm_params.h>
  25. #include <sound/soc.h>
  26. #include <sound/initval.h>
  27. #include "ak4535.h"
  28. #define AK4535_VERSION "0.3"
  29. /* codec private data */
  30. struct ak4535_priv {
  31. unsigned int sysclk;
  32. enum snd_soc_control_type control_type;
  33. void *control_data;
  34. };
  35. /*
  36. * ak4535 register cache
  37. */
  38. static const u16 ak4535_reg[AK4535_CACHEREGNUM] = {
  39. 0x0000, 0x0080, 0x0000, 0x0003,
  40. 0x0002, 0x0000, 0x0011, 0x0001,
  41. 0x0000, 0x0040, 0x0036, 0x0010,
  42. 0x0000, 0x0000, 0x0057, 0x0000,
  43. };
  44. /*
  45. * read ak4535 register cache
  46. */
  47. static inline unsigned int ak4535_read_reg_cache(struct snd_soc_codec *codec,
  48. unsigned int reg)
  49. {
  50. u16 *cache = codec->reg_cache;
  51. if (reg >= AK4535_CACHEREGNUM)
  52. return -1;
  53. return cache[reg];
  54. }
  55. /*
  56. * write ak4535 register cache
  57. */
  58. static inline void ak4535_write_reg_cache(struct snd_soc_codec *codec,
  59. u16 reg, unsigned int value)
  60. {
  61. u16 *cache = codec->reg_cache;
  62. if (reg >= AK4535_CACHEREGNUM)
  63. return;
  64. cache[reg] = value;
  65. }
  66. /*
  67. * write to the AK4535 register space
  68. */
  69. static int ak4535_write(struct snd_soc_codec *codec, unsigned int reg,
  70. unsigned int value)
  71. {
  72. u8 data[2];
  73. /* data is
  74. * D15..D8 AK4535 register offset
  75. * D7...D0 register data
  76. */
  77. data[0] = reg & 0xff;
  78. data[1] = value & 0xff;
  79. ak4535_write_reg_cache(codec, reg, value);
  80. if (codec->hw_write(codec->control_data, data, 2) == 2)
  81. return 0;
  82. else
  83. return -EIO;
  84. }
  85. static int ak4535_sync(struct snd_soc_codec *codec)
  86. {
  87. u16 *cache = codec->reg_cache;
  88. int i, r = 0;
  89. for (i = 0; i < AK4535_CACHEREGNUM; i++)
  90. r |= ak4535_write(codec, i, cache[i]);
  91. return r;
  92. };
  93. static const char *ak4535_mono_gain[] = {"+6dB", "-17dB"};
  94. static const char *ak4535_mono_out[] = {"(L + R)/2", "Hi-Z"};
  95. static const char *ak4535_hp_out[] = {"Stereo", "Mono"};
  96. static const char *ak4535_deemp[] = {"44.1kHz", "Off", "48kHz", "32kHz"};
  97. static const char *ak4535_mic_select[] = {"Internal", "External"};
  98. static const struct soc_enum ak4535_enum[] = {
  99. SOC_ENUM_SINGLE(AK4535_SIG1, 7, 2, ak4535_mono_gain),
  100. SOC_ENUM_SINGLE(AK4535_SIG1, 6, 2, ak4535_mono_out),
  101. SOC_ENUM_SINGLE(AK4535_MODE2, 2, 2, ak4535_hp_out),
  102. SOC_ENUM_SINGLE(AK4535_DAC, 0, 4, ak4535_deemp),
  103. SOC_ENUM_SINGLE(AK4535_MIC, 1, 2, ak4535_mic_select),
  104. };
  105. static const struct snd_kcontrol_new ak4535_snd_controls[] = {
  106. SOC_SINGLE("ALC2 Switch", AK4535_SIG1, 1, 1, 0),
  107. SOC_ENUM("Mono 1 Output", ak4535_enum[1]),
  108. SOC_ENUM("Mono 1 Gain", ak4535_enum[0]),
  109. SOC_ENUM("Headphone Output", ak4535_enum[2]),
  110. SOC_ENUM("Playback Deemphasis", ak4535_enum[3]),
  111. SOC_SINGLE("Bass Volume", AK4535_DAC, 2, 3, 0),
  112. SOC_SINGLE("Mic Boost (+20dB) Switch", AK4535_MIC, 0, 1, 0),
  113. SOC_ENUM("Mic Select", ak4535_enum[4]),
  114. SOC_SINGLE("ALC Operation Time", AK4535_TIMER, 0, 3, 0),
  115. SOC_SINGLE("ALC Recovery Time", AK4535_TIMER, 2, 3, 0),
  116. SOC_SINGLE("ALC ZC Time", AK4535_TIMER, 4, 3, 0),
  117. SOC_SINGLE("ALC 1 Switch", AK4535_ALC1, 5, 1, 0),
  118. SOC_SINGLE("ALC 2 Switch", AK4535_ALC1, 6, 1, 0),
  119. SOC_SINGLE("ALC Volume", AK4535_ALC2, 0, 127, 0),
  120. SOC_SINGLE("Capture Volume", AK4535_PGA, 0, 127, 0),
  121. SOC_SINGLE("Left Playback Volume", AK4535_LATT, 0, 127, 1),
  122. SOC_SINGLE("Right Playback Volume", AK4535_RATT, 0, 127, 1),
  123. SOC_SINGLE("AUX Bypass Volume", AK4535_VOL, 0, 15, 0),
  124. SOC_SINGLE("Mic Sidetone Volume", AK4535_VOL, 4, 7, 0),
  125. };
  126. /* Mono 1 Mixer */
  127. static const struct snd_kcontrol_new ak4535_mono1_mixer_controls[] = {
  128. SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG1, 4, 1, 0),
  129. SOC_DAPM_SINGLE("Mono Playback Switch", AK4535_SIG1, 5, 1, 0),
  130. };
  131. /* Stereo Mixer */
  132. static const struct snd_kcontrol_new ak4535_stereo_mixer_controls[] = {
  133. SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG2, 4, 1, 0),
  134. SOC_DAPM_SINGLE("Playback Switch", AK4535_SIG2, 7, 1, 0),
  135. SOC_DAPM_SINGLE("Aux Bypass Switch", AK4535_SIG2, 5, 1, 0),
  136. };
  137. /* Input Mixer */
  138. static const struct snd_kcontrol_new ak4535_input_mixer_controls[] = {
  139. SOC_DAPM_SINGLE("Mic Capture Switch", AK4535_MIC, 2, 1, 0),
  140. SOC_DAPM_SINGLE("Aux Capture Switch", AK4535_MIC, 5, 1, 0),
  141. };
  142. /* Input mux */
  143. static const struct snd_kcontrol_new ak4535_input_mux_control =
  144. SOC_DAPM_ENUM("Input Select", ak4535_enum[4]);
  145. /* HP L switch */
  146. static const struct snd_kcontrol_new ak4535_hpl_control =
  147. SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 1, 1, 1);
  148. /* HP R switch */
  149. static const struct snd_kcontrol_new ak4535_hpr_control =
  150. SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 0, 1, 1);
  151. /* mono 2 switch */
  152. static const struct snd_kcontrol_new ak4535_mono2_control =
  153. SOC_DAPM_SINGLE("Switch", AK4535_SIG1, 0, 1, 0);
  154. /* Line out switch */
  155. static const struct snd_kcontrol_new ak4535_line_control =
  156. SOC_DAPM_SINGLE("Switch", AK4535_SIG2, 6, 1, 0);
  157. /* ak4535 dapm widgets */
  158. static const struct snd_soc_dapm_widget ak4535_dapm_widgets[] = {
  159. SND_SOC_DAPM_MIXER("Stereo Mixer", SND_SOC_NOPM, 0, 0,
  160. &ak4535_stereo_mixer_controls[0],
  161. ARRAY_SIZE(ak4535_stereo_mixer_controls)),
  162. SND_SOC_DAPM_MIXER("Mono1 Mixer", SND_SOC_NOPM, 0, 0,
  163. &ak4535_mono1_mixer_controls[0],
  164. ARRAY_SIZE(ak4535_mono1_mixer_controls)),
  165. SND_SOC_DAPM_MIXER("Input Mixer", SND_SOC_NOPM, 0, 0,
  166. &ak4535_input_mixer_controls[0],
  167. ARRAY_SIZE(ak4535_input_mixer_controls)),
  168. SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0,
  169. &ak4535_input_mux_control),
  170. SND_SOC_DAPM_DAC("DAC", "Playback", AK4535_PM2, 0, 0),
  171. SND_SOC_DAPM_SWITCH("Mono 2 Enable", SND_SOC_NOPM, 0, 0,
  172. &ak4535_mono2_control),
  173. /* speaker powersave bit */
  174. SND_SOC_DAPM_PGA("Speaker Enable", AK4535_MODE2, 0, 0, NULL, 0),
  175. SND_SOC_DAPM_SWITCH("Line Out Enable", SND_SOC_NOPM, 0, 0,
  176. &ak4535_line_control),
  177. SND_SOC_DAPM_SWITCH("Left HP Enable", SND_SOC_NOPM, 0, 0,
  178. &ak4535_hpl_control),
  179. SND_SOC_DAPM_SWITCH("Right HP Enable", SND_SOC_NOPM, 0, 0,
  180. &ak4535_hpr_control),
  181. SND_SOC_DAPM_OUTPUT("LOUT"),
  182. SND_SOC_DAPM_OUTPUT("HPL"),
  183. SND_SOC_DAPM_OUTPUT("ROUT"),
  184. SND_SOC_DAPM_OUTPUT("HPR"),
  185. SND_SOC_DAPM_OUTPUT("SPP"),
  186. SND_SOC_DAPM_OUTPUT("SPN"),
  187. SND_SOC_DAPM_OUTPUT("MOUT1"),
  188. SND_SOC_DAPM_OUTPUT("MOUT2"),
  189. SND_SOC_DAPM_OUTPUT("MICOUT"),
  190. SND_SOC_DAPM_ADC("ADC", "Capture", AK4535_PM1, 0, 0),
  191. SND_SOC_DAPM_PGA("Spk Amp", AK4535_PM2, 3, 0, NULL, 0),
  192. SND_SOC_DAPM_PGA("HP R Amp", AK4535_PM2, 1, 0, NULL, 0),
  193. SND_SOC_DAPM_PGA("HP L Amp", AK4535_PM2, 2, 0, NULL, 0),
  194. SND_SOC_DAPM_PGA("Mic", AK4535_PM1, 1, 0, NULL, 0),
  195. SND_SOC_DAPM_PGA("Line Out", AK4535_PM1, 4, 0, NULL, 0),
  196. SND_SOC_DAPM_PGA("Mono Out", AK4535_PM1, 3, 0, NULL, 0),
  197. SND_SOC_DAPM_PGA("AUX In", AK4535_PM1, 2, 0, NULL, 0),
  198. SND_SOC_DAPM_MICBIAS("Mic Int Bias", AK4535_MIC, 3, 0),
  199. SND_SOC_DAPM_MICBIAS("Mic Ext Bias", AK4535_MIC, 4, 0),
  200. SND_SOC_DAPM_INPUT("MICIN"),
  201. SND_SOC_DAPM_INPUT("MICEXT"),
  202. SND_SOC_DAPM_INPUT("AUX"),
  203. SND_SOC_DAPM_INPUT("MIN"),
  204. SND_SOC_DAPM_INPUT("AIN"),
  205. };
  206. static const struct snd_soc_dapm_route ak4535_audio_map[] = {
  207. /*stereo mixer */
  208. {"Stereo Mixer", "Playback Switch", "DAC"},
  209. {"Stereo Mixer", "Mic Sidetone Switch", "Mic"},
  210. {"Stereo Mixer", "Aux Bypass Switch", "AUX In"},
  211. /* mono1 mixer */
  212. {"Mono1 Mixer", "Mic Sidetone Switch", "Mic"},
  213. {"Mono1 Mixer", "Mono Playback Switch", "DAC"},
  214. /* Mic */
  215. {"Mic", NULL, "AIN"},
  216. {"Input Mux", "Internal", "Mic Int Bias"},
  217. {"Input Mux", "External", "Mic Ext Bias"},
  218. {"Mic Int Bias", NULL, "MICIN"},
  219. {"Mic Ext Bias", NULL, "MICEXT"},
  220. {"MICOUT", NULL, "Input Mux"},
  221. /* line out */
  222. {"LOUT", NULL, "Line Out Enable"},
  223. {"ROUT", NULL, "Line Out Enable"},
  224. {"Line Out Enable", "Switch", "Line Out"},
  225. {"Line Out", NULL, "Stereo Mixer"},
  226. /* mono1 out */
  227. {"MOUT1", NULL, "Mono Out"},
  228. {"Mono Out", NULL, "Mono1 Mixer"},
  229. /* left HP */
  230. {"HPL", NULL, "Left HP Enable"},
  231. {"Left HP Enable", "Switch", "HP L Amp"},
  232. {"HP L Amp", NULL, "Stereo Mixer"},
  233. /* right HP */
  234. {"HPR", NULL, "Right HP Enable"},
  235. {"Right HP Enable", "Switch", "HP R Amp"},
  236. {"HP R Amp", NULL, "Stereo Mixer"},
  237. /* speaker */
  238. {"SPP", NULL, "Speaker Enable"},
  239. {"SPN", NULL, "Speaker Enable"},
  240. {"Speaker Enable", "Switch", "Spk Amp"},
  241. {"Spk Amp", NULL, "MIN"},
  242. /* mono 2 */
  243. {"MOUT2", NULL, "Mono 2 Enable"},
  244. {"Mono 2 Enable", "Switch", "Stereo Mixer"},
  245. /* Aux In */
  246. {"Aux In", NULL, "AUX"},
  247. /* ADC */
  248. {"ADC", NULL, "Input Mixer"},
  249. {"Input Mixer", "Mic Capture Switch", "Mic"},
  250. {"Input Mixer", "Aux Capture Switch", "Aux In"},
  251. };
  252. static int ak4535_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  253. int clk_id, unsigned int freq, int dir)
  254. {
  255. struct snd_soc_codec *codec = codec_dai->codec;
  256. struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
  257. ak4535->sysclk = freq;
  258. return 0;
  259. }
  260. static int ak4535_hw_params(struct snd_pcm_substream *substream,
  261. struct snd_pcm_hw_params *params,
  262. struct snd_soc_dai *dai)
  263. {
  264. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  265. struct snd_soc_codec *codec = rtd->codec;
  266. struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
  267. u8 mode2 = ak4535_read_reg_cache(codec, AK4535_MODE2) & ~(0x3 << 5);
  268. int rate = params_rate(params), fs = 256;
  269. if (rate)
  270. fs = ak4535->sysclk / rate;
  271. /* set fs */
  272. switch (fs) {
  273. case 1024:
  274. mode2 |= (0x2 << 5);
  275. break;
  276. case 512:
  277. mode2 |= (0x1 << 5);
  278. break;
  279. case 256:
  280. break;
  281. }
  282. /* set rate */
  283. ak4535_write(codec, AK4535_MODE2, mode2);
  284. return 0;
  285. }
  286. static int ak4535_set_dai_fmt(struct snd_soc_dai *codec_dai,
  287. unsigned int fmt)
  288. {
  289. struct snd_soc_codec *codec = codec_dai->codec;
  290. u8 mode1 = 0;
  291. /* interface format */
  292. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  293. case SND_SOC_DAIFMT_I2S:
  294. mode1 = 0x0002;
  295. break;
  296. case SND_SOC_DAIFMT_LEFT_J:
  297. mode1 = 0x0001;
  298. break;
  299. default:
  300. return -EINVAL;
  301. }
  302. /* use 32 fs for BCLK to save power */
  303. mode1 |= 0x4;
  304. ak4535_write(codec, AK4535_MODE1, mode1);
  305. return 0;
  306. }
  307. static int ak4535_mute(struct snd_soc_dai *dai, int mute)
  308. {
  309. struct snd_soc_codec *codec = dai->codec;
  310. u16 mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC);
  311. if (!mute)
  312. ak4535_write(codec, AK4535_DAC, mute_reg & ~0x20);
  313. else
  314. ak4535_write(codec, AK4535_DAC, mute_reg | 0x20);
  315. return 0;
  316. }
  317. static int ak4535_set_bias_level(struct snd_soc_codec *codec,
  318. enum snd_soc_bias_level level)
  319. {
  320. u16 i, mute_reg;
  321. switch (level) {
  322. case SND_SOC_BIAS_ON:
  323. mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC);
  324. ak4535_write(codec, AK4535_DAC, mute_reg & ~0x20);
  325. break;
  326. case SND_SOC_BIAS_PREPARE:
  327. mute_reg = ak4535_read_reg_cache(codec, AK4535_DAC);
  328. ak4535_write(codec, AK4535_DAC, mute_reg | 0x20);
  329. break;
  330. case SND_SOC_BIAS_STANDBY:
  331. i = ak4535_read_reg_cache(codec, AK4535_PM1);
  332. ak4535_write(codec, AK4535_PM1, i | 0x80);
  333. i = ak4535_read_reg_cache(codec, AK4535_PM2);
  334. ak4535_write(codec, AK4535_PM2, i & (~0x80));
  335. break;
  336. case SND_SOC_BIAS_OFF:
  337. i = ak4535_read_reg_cache(codec, AK4535_PM1);
  338. ak4535_write(codec, AK4535_PM1, i & (~0x80));
  339. break;
  340. }
  341. codec->dapm.bias_level = level;
  342. return 0;
  343. }
  344. #define AK4535_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
  345. SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
  346. SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
  347. static struct snd_soc_dai_ops ak4535_dai_ops = {
  348. .hw_params = ak4535_hw_params,
  349. .set_fmt = ak4535_set_dai_fmt,
  350. .digital_mute = ak4535_mute,
  351. .set_sysclk = ak4535_set_dai_sysclk,
  352. };
  353. static struct snd_soc_dai_driver ak4535_dai = {
  354. .name = "ak4535-hifi",
  355. .playback = {
  356. .stream_name = "Playback",
  357. .channels_min = 1,
  358. .channels_max = 2,
  359. .rates = AK4535_RATES,
  360. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  361. .capture = {
  362. .stream_name = "Capture",
  363. .channels_min = 1,
  364. .channels_max = 2,
  365. .rates = AK4535_RATES,
  366. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  367. .ops = &ak4535_dai_ops,
  368. };
  369. static int ak4535_suspend(struct snd_soc_codec *codec, pm_message_t state)
  370. {
  371. ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF);
  372. return 0;
  373. }
  374. static int ak4535_resume(struct snd_soc_codec *codec)
  375. {
  376. ak4535_sync(codec);
  377. ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  378. return 0;
  379. }
  380. static int ak4535_probe(struct snd_soc_codec *codec)
  381. {
  382. struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
  383. printk(KERN_INFO "AK4535 Audio Codec %s", AK4535_VERSION);
  384. codec->control_data = ak4535->control_data;
  385. /* power on device */
  386. ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  387. snd_soc_add_controls(codec, ak4535_snd_controls,
  388. ARRAY_SIZE(ak4535_snd_controls));
  389. return 0;
  390. }
  391. /* power down chip */
  392. static int ak4535_remove(struct snd_soc_codec *codec)
  393. {
  394. ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF);
  395. return 0;
  396. }
  397. static struct snd_soc_codec_driver soc_codec_dev_ak4535 = {
  398. .probe = ak4535_probe,
  399. .remove = ak4535_remove,
  400. .suspend = ak4535_suspend,
  401. .resume = ak4535_resume,
  402. .read = ak4535_read_reg_cache,
  403. .write = ak4535_write,
  404. .set_bias_level = ak4535_set_bias_level,
  405. .reg_cache_size = ARRAY_SIZE(ak4535_reg),
  406. .reg_word_size = sizeof(u8),
  407. .reg_cache_default = ak4535_reg,
  408. .dapm_widgets = ak4535_dapm_widgets,
  409. .num_dapm_widgets = ARRAY_SIZE(ak4535_dapm_widgets),
  410. .dapm_routes = ak4535_audio_map,
  411. .num_dapm_routes = ARRAY_SIZE(ak4535_audio_map),
  412. };
  413. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  414. static __devinit int ak4535_i2c_probe(struct i2c_client *i2c,
  415. const struct i2c_device_id *id)
  416. {
  417. struct ak4535_priv *ak4535;
  418. int ret;
  419. ak4535 = kzalloc(sizeof(struct ak4535_priv), GFP_KERNEL);
  420. if (ak4535 == NULL)
  421. return -ENOMEM;
  422. i2c_set_clientdata(i2c, ak4535);
  423. ak4535->control_data = i2c;
  424. ak4535->control_type = SND_SOC_I2C;
  425. ret = snd_soc_register_codec(&i2c->dev,
  426. &soc_codec_dev_ak4535, &ak4535_dai, 1);
  427. if (ret < 0)
  428. kfree(ak4535);
  429. return ret;
  430. }
  431. static __devexit int ak4535_i2c_remove(struct i2c_client *client)
  432. {
  433. snd_soc_unregister_codec(&client->dev);
  434. kfree(i2c_get_clientdata(client));
  435. return 0;
  436. }
  437. static const struct i2c_device_id ak4535_i2c_id[] = {
  438. { "ak4535", 0 },
  439. { }
  440. };
  441. MODULE_DEVICE_TABLE(i2c, ak4535_i2c_id);
  442. static struct i2c_driver ak4535_i2c_driver = {
  443. .driver = {
  444. .name = "ak4535-codec",
  445. .owner = THIS_MODULE,
  446. },
  447. .probe = ak4535_i2c_probe,
  448. .remove = __devexit_p(ak4535_i2c_remove),
  449. .id_table = ak4535_i2c_id,
  450. };
  451. #endif
  452. static int __init ak4535_modinit(void)
  453. {
  454. int ret = 0;
  455. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  456. ret = i2c_add_driver(&ak4535_i2c_driver);
  457. if (ret != 0) {
  458. printk(KERN_ERR "Failed to register AK4535 I2C driver: %d\n",
  459. ret);
  460. }
  461. #endif
  462. return ret;
  463. }
  464. module_init(ak4535_modinit);
  465. static void __exit ak4535_exit(void)
  466. {
  467. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  468. i2c_del_driver(&ak4535_i2c_driver);
  469. #endif
  470. }
  471. module_exit(ak4535_exit);
  472. MODULE_DESCRIPTION("Soc AK4535 driver");
  473. MODULE_AUTHOR("Richard Purdie");
  474. MODULE_LICENSE("GPL");