snd-aoa-codec-tas.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. * Apple Onboard Audio driver for tas codec
  3. *
  4. * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
  5. *
  6. * GPL v2, can be found in COPYING.
  7. *
  8. * Open questions:
  9. * - How to distinguish between 3004 and versions?
  10. *
  11. * FIXMEs:
  12. * - This codec driver doesn't honour the 'connected'
  13. * property of the aoa_codec struct, hence if
  14. * it is used in machines where not everything is
  15. * connected it will display wrong mixer elements.
  16. * - Driver assumes that the microphone is always
  17. * monaureal and connected to the right channel of
  18. * the input. This should also be a codec-dependent
  19. * flag, maybe the codec should have 3 different
  20. * bits for the three different possibilities how
  21. * it can be hooked up...
  22. * But as long as I don't see any hardware hooked
  23. * up that way...
  24. * - As Apple notes in their code, the tas3004 seems
  25. * to delay the right channel by one sample. You can
  26. * see this when for example recording stereo in
  27. * audacity, or recording the tas output via cable
  28. * on another machine (use a sinus generator or so).
  29. * I tried programming the BiQuads but couldn't
  30. * make the delay work, maybe someone can read the
  31. * datasheet and fix it. The relevant Apple comment
  32. * is in AppleTAS3004Audio.cpp lines 1637 ff. Note
  33. * that their comment describing how they program
  34. * the filters sucks...
  35. *
  36. * Other things:
  37. * - this should actually register *two* aoa_codec
  38. * structs since it has two inputs. Then it must
  39. * use the prepare callback to forbid running the
  40. * secondary output on a different clock.
  41. * Also, whatever bus knows how to do this must
  42. * provide two soundbus_dev devices and the fabric
  43. * must be able to link them correctly.
  44. *
  45. * I don't even know if Apple ever uses the second
  46. * port on the tas3004 though, I don't think their
  47. * i2s controllers can even do it. OTOH, they all
  48. * derive the clocks from common clocks, so it
  49. * might just be possible. The framework allows the
  50. * codec to refine the transfer_info items in the
  51. * usable callback, so we can simply remove the
  52. * rates the second instance is not using when it
  53. * actually is in use.
  54. * Maybe we'll need to make the sound busses have
  55. * a 'clock group id' value so the codec can
  56. * determine if the two outputs can be driven at
  57. * the same time. But that is likely overkill, up
  58. * to the fabric to not link them up incorrectly,
  59. * and up to the hardware designer to not wire
  60. * them up in some weird unusable way.
  61. */
  62. #include <stddef.h>
  63. #include <linux/i2c.h>
  64. #include <linux/i2c-dev.h>
  65. #include <asm/pmac_low_i2c.h>
  66. #include <asm/prom.h>
  67. #include <linux/delay.h>
  68. #include <linux/module.h>
  69. MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
  70. MODULE_LICENSE("GPL");
  71. MODULE_DESCRIPTION("tas codec driver for snd-aoa");
  72. #include "snd-aoa-codec-tas.h"
  73. #include "snd-aoa-codec-tas-gain-table.h"
  74. #include "../aoa.h"
  75. #include "../soundbus/soundbus.h"
  76. #define PFX "snd-aoa-codec-tas: "
  77. struct tas {
  78. struct aoa_codec codec;
  79. struct i2c_client i2c;
  80. u32 muted_l:1, muted_r:1,
  81. controls_created:1;
  82. u8 cached_volume_l, cached_volume_r;
  83. u8 mixer_l[3], mixer_r[3];
  84. u8 acr;
  85. };
  86. static struct tas *codec_to_tas(struct aoa_codec *codec)
  87. {
  88. return container_of(codec, struct tas, codec);
  89. }
  90. static inline int tas_write_reg(struct tas *tas, u8 reg, u8 len, u8 *data)
  91. {
  92. if (len == 1)
  93. return i2c_smbus_write_byte_data(&tas->i2c, reg, *data);
  94. else
  95. return i2c_smbus_write_i2c_block_data(&tas->i2c, reg, len, data);
  96. }
  97. static void tas_set_volume(struct tas *tas)
  98. {
  99. u8 block[6];
  100. int tmp;
  101. u8 left, right;
  102. left = tas->cached_volume_l;
  103. right = tas->cached_volume_r;
  104. if (left > 177) left = 177;
  105. if (right > 177) right = 177;
  106. if (tas->muted_l) left = 0;
  107. if (tas->muted_r) right = 0;
  108. /* analysing the volume and mixer tables shows
  109. * that they are similar enough when we shift
  110. * the mixer table down by 4 bits. The error
  111. * is miniscule, in just one item the error
  112. * is 1, at a value of 0x07f17b (mixer table
  113. * value is 0x07f17a) */
  114. tmp = tas_gaintable[left];
  115. block[0] = tmp>>20;
  116. block[1] = tmp>>12;
  117. block[2] = tmp>>4;
  118. tmp = tas_gaintable[right];
  119. block[3] = tmp>>20;
  120. block[4] = tmp>>12;
  121. block[5] = tmp>>4;
  122. tas_write_reg(tas, TAS_REG_VOL, 6, block);
  123. }
  124. static void tas_set_mixer(struct tas *tas)
  125. {
  126. u8 block[9];
  127. int tmp, i;
  128. u8 val;
  129. for (i=0;i<3;i++) {
  130. val = tas->mixer_l[i];
  131. if (val > 177) val = 177;
  132. tmp = tas_gaintable[val];
  133. block[3*i+0] = tmp>>16;
  134. block[3*i+1] = tmp>>8;
  135. block[3*i+2] = tmp;
  136. }
  137. tas_write_reg(tas, TAS_REG_LMIX, 9, block);
  138. for (i=0;i<3;i++) {
  139. val = tas->mixer_r[i];
  140. if (val > 177) val = 177;
  141. tmp = tas_gaintable[val];
  142. block[3*i+0] = tmp>>16;
  143. block[3*i+1] = tmp>>8;
  144. block[3*i+2] = tmp;
  145. }
  146. tas_write_reg(tas, TAS_REG_RMIX, 9, block);
  147. }
  148. /* alsa stuff */
  149. static int tas_dev_register(struct snd_device *dev)
  150. {
  151. return 0;
  152. }
  153. static struct snd_device_ops ops = {
  154. .dev_register = tas_dev_register,
  155. };
  156. static int tas_snd_vol_info(struct snd_kcontrol *kcontrol,
  157. struct snd_ctl_elem_info *uinfo)
  158. {
  159. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  160. uinfo->count = 2;
  161. uinfo->value.integer.min = 0;
  162. uinfo->value.integer.max = 177;
  163. return 0;
  164. }
  165. static int tas_snd_vol_get(struct snd_kcontrol *kcontrol,
  166. struct snd_ctl_elem_value *ucontrol)
  167. {
  168. struct tas *tas = snd_kcontrol_chip(kcontrol);
  169. ucontrol->value.integer.value[0] = tas->cached_volume_l;
  170. ucontrol->value.integer.value[1] = tas->cached_volume_r;
  171. return 0;
  172. }
  173. static int tas_snd_vol_put(struct snd_kcontrol *kcontrol,
  174. struct snd_ctl_elem_value *ucontrol)
  175. {
  176. struct tas *tas = snd_kcontrol_chip(kcontrol);
  177. if (tas->cached_volume_l == ucontrol->value.integer.value[0]
  178. && tas->cached_volume_r == ucontrol->value.integer.value[1])
  179. return 0;
  180. tas->cached_volume_l = ucontrol->value.integer.value[0];
  181. tas->cached_volume_r = ucontrol->value.integer.value[1];
  182. tas_set_volume(tas);
  183. return 1;
  184. }
  185. static struct snd_kcontrol_new volume_control = {
  186. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  187. .name = "Master Playback Volume",
  188. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  189. .info = tas_snd_vol_info,
  190. .get = tas_snd_vol_get,
  191. .put = tas_snd_vol_put,
  192. };
  193. static int tas_snd_mute_info(struct snd_kcontrol *kcontrol,
  194. struct snd_ctl_elem_info *uinfo)
  195. {
  196. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  197. uinfo->count = 2;
  198. uinfo->value.integer.min = 0;
  199. uinfo->value.integer.max = 1;
  200. return 0;
  201. }
  202. static int tas_snd_mute_get(struct snd_kcontrol *kcontrol,
  203. struct snd_ctl_elem_value *ucontrol)
  204. {
  205. struct tas *tas = snd_kcontrol_chip(kcontrol);
  206. ucontrol->value.integer.value[0] = !tas->muted_l;
  207. ucontrol->value.integer.value[1] = !tas->muted_r;
  208. return 0;
  209. }
  210. static int tas_snd_mute_put(struct snd_kcontrol *kcontrol,
  211. struct snd_ctl_elem_value *ucontrol)
  212. {
  213. struct tas *tas = snd_kcontrol_chip(kcontrol);
  214. if (tas->muted_l == !ucontrol->value.integer.value[0]
  215. && tas->muted_r == !ucontrol->value.integer.value[1])
  216. return 0;
  217. tas->muted_l = !ucontrol->value.integer.value[0];
  218. tas->muted_r = !ucontrol->value.integer.value[1];
  219. tas_set_volume(tas);
  220. return 1;
  221. }
  222. static struct snd_kcontrol_new mute_control = {
  223. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  224. .name = "Master Playback Switch",
  225. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  226. .info = tas_snd_mute_info,
  227. .get = tas_snd_mute_get,
  228. .put = tas_snd_mute_put,
  229. };
  230. static int tas_snd_mixer_info(struct snd_kcontrol *kcontrol,
  231. struct snd_ctl_elem_info *uinfo)
  232. {
  233. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  234. uinfo->count = 2;
  235. uinfo->value.integer.min = 0;
  236. uinfo->value.integer.max = 177;
  237. return 0;
  238. }
  239. static int tas_snd_mixer_get(struct snd_kcontrol *kcontrol,
  240. struct snd_ctl_elem_value *ucontrol)
  241. {
  242. struct tas *tas = snd_kcontrol_chip(kcontrol);
  243. int idx = kcontrol->private_value;
  244. ucontrol->value.integer.value[0] = tas->mixer_l[idx];
  245. ucontrol->value.integer.value[1] = tas->mixer_r[idx];
  246. return 0;
  247. }
  248. static int tas_snd_mixer_put(struct snd_kcontrol *kcontrol,
  249. struct snd_ctl_elem_value *ucontrol)
  250. {
  251. struct tas *tas = snd_kcontrol_chip(kcontrol);
  252. int idx = kcontrol->private_value;
  253. if (tas->mixer_l[idx] == ucontrol->value.integer.value[0]
  254. && tas->mixer_r[idx] == ucontrol->value.integer.value[1])
  255. return 0;
  256. tas->mixer_l[idx] = ucontrol->value.integer.value[0];
  257. tas->mixer_r[idx] = ucontrol->value.integer.value[1];
  258. tas_set_mixer(tas);
  259. return 1;
  260. }
  261. #define MIXER_CONTROL(n,descr,idx) \
  262. static struct snd_kcontrol_new n##_control = { \
  263. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  264. .name = descr " Playback Volume", \
  265. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  266. .info = tas_snd_mixer_info, \
  267. .get = tas_snd_mixer_get, \
  268. .put = tas_snd_mixer_put, \
  269. .private_value = idx, \
  270. }
  271. MIXER_CONTROL(pcm1, "PCM1", 0);
  272. MIXER_CONTROL(monitor, "Monitor", 2);
  273. static int tas_snd_capture_source_info(struct snd_kcontrol *kcontrol,
  274. struct snd_ctl_elem_info *uinfo)
  275. {
  276. static char *texts[] = { "Line-In", "Microphone" };
  277. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  278. uinfo->count = 1;
  279. uinfo->value.enumerated.items = 2;
  280. if (uinfo->value.enumerated.item > 1)
  281. uinfo->value.enumerated.item = 1;
  282. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  283. return 0;
  284. }
  285. static int tas_snd_capture_source_get(struct snd_kcontrol *kcontrol,
  286. struct snd_ctl_elem_value *ucontrol)
  287. {
  288. struct tas *tas = snd_kcontrol_chip(kcontrol);
  289. ucontrol->value.enumerated.item[0] = !!(tas->acr & TAS_ACR_INPUT_B);
  290. return 0;
  291. }
  292. static int tas_snd_capture_source_put(struct snd_kcontrol *kcontrol,
  293. struct snd_ctl_elem_value *ucontrol)
  294. {
  295. struct tas *tas = snd_kcontrol_chip(kcontrol);
  296. int oldacr = tas->acr;
  297. tas->acr &= ~TAS_ACR_INPUT_B;
  298. if (ucontrol->value.enumerated.item[0])
  299. tas->acr |= TAS_ACR_INPUT_B;
  300. if (oldacr == tas->acr)
  301. return 0;
  302. tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr);
  303. return 1;
  304. }
  305. static struct snd_kcontrol_new capture_source_control = {
  306. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  307. /* If we name this 'Input Source', it properly shows up in
  308. * alsamixer as a selection, * but it's shown under the
  309. * 'Playback' category.
  310. * If I name it 'Capture Source', it shows up in strange
  311. * ways (two bools of which one can be selected at a
  312. * time) but at least it's shown in the 'Capture'
  313. * category.
  314. * I was told that this was due to backward compatibility,
  315. * but I don't understand then why the mangling is *not*
  316. * done when I name it "Input Source".....
  317. */
  318. .name = "Capture Source",
  319. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  320. .info = tas_snd_capture_source_info,
  321. .get = tas_snd_capture_source_get,
  322. .put = tas_snd_capture_source_put,
  323. };
  324. static struct transfer_info tas_transfers[] = {
  325. {
  326. /* input */
  327. .formats = SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S16_BE |
  328. SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S24_BE,
  329. .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
  330. .transfer_in = 1,
  331. },
  332. {
  333. /* output */
  334. .formats = SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S16_BE |
  335. SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S24_BE,
  336. .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
  337. .transfer_in = 0,
  338. },
  339. {}
  340. };
  341. static int tas_usable(struct codec_info_item *cii,
  342. struct transfer_info *ti,
  343. struct transfer_info *out)
  344. {
  345. return 1;
  346. }
  347. static int tas_reset_init(struct tas *tas)
  348. {
  349. u8 tmp;
  350. tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 0);
  351. msleep(1);
  352. tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 1);
  353. msleep(1);
  354. tas->codec.gpio->methods->set_hw_reset(tas->codec.gpio, 0);
  355. msleep(1);
  356. tas->acr &= ~TAS_ACR_ANALOG_PDOWN;
  357. tas->acr |= TAS_ACR_B_MONAUREAL | TAS_ACR_B_MON_SEL_RIGHT;
  358. if (tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr))
  359. return -ENODEV;
  360. tmp = TAS_MCS_SCLK64 | TAS_MCS_SPORT_MODE_I2S | TAS_MCS_SPORT_WL_24BIT;
  361. if (tas_write_reg(tas, TAS_REG_MCS, 1, &tmp))
  362. return -ENODEV;
  363. tmp = 0;
  364. if (tas_write_reg(tas, TAS_REG_MCS2, 1, &tmp))
  365. return -ENODEV;
  366. return 0;
  367. }
  368. /* we are controlled via i2c and assume that is always up
  369. * If that wasn't the case, we'd have to suspend once
  370. * our i2c device is suspended, and then take note of that! */
  371. static int tas_suspend(struct tas *tas)
  372. {
  373. tas->acr |= TAS_ACR_ANALOG_PDOWN;
  374. tas_write_reg(tas, TAS_REG_ACR, 1, &tas->acr);
  375. return 0;
  376. }
  377. static int tas_resume(struct tas *tas)
  378. {
  379. /* reset codec */
  380. tas_reset_init(tas);
  381. tas_set_volume(tas);
  382. tas_set_mixer(tas);
  383. return 0;
  384. }
  385. #ifdef CONFIG_PM
  386. static int _tas_suspend(struct codec_info_item *cii, pm_message_t state)
  387. {
  388. return tas_suspend(cii->codec_data);
  389. }
  390. static int _tas_resume(struct codec_info_item *cii)
  391. {
  392. return tas_resume(cii->codec_data);
  393. }
  394. #endif
  395. static struct codec_info tas_codec_info = {
  396. .transfers = tas_transfers,
  397. /* in theory, we can drive it at 512 too...
  398. * but so far the framework doesn't allow
  399. * for that and I don't see much point in it. */
  400. .sysclock_factor = 256,
  401. /* same here, could be 32 for just one 16 bit format */
  402. .bus_factor = 64,
  403. .owner = THIS_MODULE,
  404. .usable = tas_usable,
  405. #ifdef CONFIG_PM
  406. .suspend = _tas_suspend,
  407. .resume = _tas_resume,
  408. #endif
  409. };
  410. static int tas_init_codec(struct aoa_codec *codec)
  411. {
  412. struct tas *tas = codec_to_tas(codec);
  413. int err;
  414. if (!tas->codec.gpio || !tas->codec.gpio->methods) {
  415. printk(KERN_ERR PFX "gpios not assigned!!\n");
  416. return -EINVAL;
  417. }
  418. if (tas_reset_init(tas)) {
  419. printk(KERN_ERR PFX "tas failed to initialise\n");
  420. return -ENXIO;
  421. }
  422. if (tas->codec.soundbus_dev->attach_codec(tas->codec.soundbus_dev,
  423. aoa_get_card(),
  424. &tas_codec_info, tas)) {
  425. printk(KERN_ERR PFX "error attaching tas to soundbus\n");
  426. return -ENODEV;
  427. }
  428. if (aoa_snd_device_new(SNDRV_DEV_LOWLEVEL, tas, &ops)) {
  429. printk(KERN_ERR PFX "failed to create tas snd device!\n");
  430. return -ENODEV;
  431. }
  432. err = aoa_snd_ctl_add(snd_ctl_new1(&volume_control, tas));
  433. if (err)
  434. goto error;
  435. err = aoa_snd_ctl_add(snd_ctl_new1(&mute_control, tas));
  436. if (err)
  437. goto error;
  438. err = aoa_snd_ctl_add(snd_ctl_new1(&pcm1_control, tas));
  439. if (err)
  440. goto error;
  441. err = aoa_snd_ctl_add(snd_ctl_new1(&monitor_control, tas));
  442. if (err)
  443. goto error;
  444. err = aoa_snd_ctl_add(snd_ctl_new1(&capture_source_control, tas));
  445. if (err)
  446. goto error;
  447. return 0;
  448. error:
  449. tas->codec.soundbus_dev->detach_codec(tas->codec.soundbus_dev, tas);
  450. snd_device_free(aoa_get_card(), tas);
  451. return err;
  452. }
  453. static void tas_exit_codec(struct aoa_codec *codec)
  454. {
  455. struct tas *tas = codec_to_tas(codec);
  456. if (!tas->codec.soundbus_dev)
  457. return;
  458. tas->codec.soundbus_dev->detach_codec(tas->codec.soundbus_dev, tas);
  459. }
  460. static struct i2c_driver tas_driver;
  461. static int tas_create(struct i2c_adapter *adapter,
  462. struct device_node *node,
  463. int addr)
  464. {
  465. struct tas *tas;
  466. tas = kzalloc(sizeof(struct tas), GFP_KERNEL);
  467. if (!tas)
  468. return -ENOMEM;
  469. tas->i2c.driver = &tas_driver;
  470. tas->i2c.adapter = adapter;
  471. tas->i2c.addr = addr;
  472. strlcpy(tas->i2c.name, "tas audio codec", I2C_NAME_SIZE-1);
  473. if (i2c_attach_client(&tas->i2c)) {
  474. printk(KERN_ERR PFX "failed to attach to i2c\n");
  475. goto fail;
  476. }
  477. strlcpy(tas->codec.name, "tas", MAX_CODEC_NAME_LEN-1);
  478. tas->codec.owner = THIS_MODULE;
  479. tas->codec.init = tas_init_codec;
  480. tas->codec.exit = tas_exit_codec;
  481. tas->codec.node = of_node_get(node);
  482. if (aoa_codec_register(&tas->codec)) {
  483. goto detach;
  484. }
  485. printk(KERN_DEBUG "snd-aoa-codec-tas: created and attached tas instance\n");
  486. return 0;
  487. detach:
  488. i2c_detach_client(&tas->i2c);
  489. fail:
  490. kfree(tas);
  491. return -EINVAL;
  492. }
  493. static int tas_i2c_attach(struct i2c_adapter *adapter)
  494. {
  495. struct device_node *busnode, *dev = NULL;
  496. struct pmac_i2c_bus *bus;
  497. bus = pmac_i2c_adapter_to_bus(adapter);
  498. if (bus == NULL)
  499. return -ENODEV;
  500. busnode = pmac_i2c_get_bus_node(bus);
  501. while ((dev = of_get_next_child(busnode, dev)) != NULL) {
  502. if (device_is_compatible(dev, "tas3004")) {
  503. u32 *addr;
  504. printk(KERN_DEBUG PFX "found tas3004\n");
  505. addr = (u32 *) get_property(dev, "reg", NULL);
  506. if (!addr)
  507. continue;
  508. return tas_create(adapter, dev, ((*addr) >> 1) & 0x7f);
  509. }
  510. /* older machines have no 'codec' node with a 'compatible'
  511. * property that says 'tas3004', they just have a 'deq'
  512. * node without any such property... */
  513. if (strcmp(dev->name, "deq") == 0) {
  514. u32 *_addr, addr;
  515. printk(KERN_DEBUG PFX "found 'deq' node\n");
  516. _addr = (u32 *) get_property(dev, "i2c-address", NULL);
  517. if (!_addr)
  518. continue;
  519. addr = ((*_addr) >> 1) & 0x7f;
  520. /* now, if the address doesn't match any of the two
  521. * that a tas3004 can have, we cannot handle this.
  522. * I doubt it ever happens but hey. */
  523. if (addr != 0x34 && addr != 0x35)
  524. continue;
  525. return tas_create(adapter, dev, addr);
  526. }
  527. }
  528. return -ENODEV;
  529. }
  530. static int tas_i2c_detach(struct i2c_client *client)
  531. {
  532. struct tas *tas = container_of(client, struct tas, i2c);
  533. int err;
  534. u8 tmp = TAS_ACR_ANALOG_PDOWN;
  535. if ((err = i2c_detach_client(client)))
  536. return err;
  537. aoa_codec_unregister(&tas->codec);
  538. of_node_put(tas->codec.node);
  539. /* power down codec chip */
  540. tas_write_reg(tas, TAS_REG_ACR, 1, &tmp);
  541. kfree(tas);
  542. return 0;
  543. }
  544. static struct i2c_driver tas_driver = {
  545. .driver = {
  546. .name = "aoa_codec_tas",
  547. .owner = THIS_MODULE,
  548. },
  549. .attach_adapter = tas_i2c_attach,
  550. .detach_client = tas_i2c_detach,
  551. };
  552. static int __init tas_init(void)
  553. {
  554. return i2c_add_driver(&tas_driver);
  555. }
  556. static void __exit tas_exit(void)
  557. {
  558. i2c_del_driver(&tas_driver);
  559. }
  560. module_init(tas_init);
  561. module_exit(tas_exit);