tlv320dac33.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684
  1. /*
  2. * ALSA SoC Texas Instruments TLV320DAC33 codec driver
  3. *
  4. * Author: Peter Ujfalusi <peter.ujfalusi@nokia.com>
  5. *
  6. * Copyright: (C) 2009 Nokia Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <linux/module.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/init.h>
  26. #include <linux/delay.h>
  27. #include <linux/pm.h>
  28. #include <linux/i2c.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/gpio.h>
  32. #include <linux/regulator/consumer.h>
  33. #include <linux/slab.h>
  34. #include <sound/core.h>
  35. #include <sound/pcm.h>
  36. #include <sound/pcm_params.h>
  37. #include <sound/soc.h>
  38. #include <sound/initval.h>
  39. #include <sound/tlv.h>
  40. #include <sound/tlv320dac33-plat.h>
  41. #include "tlv320dac33.h"
  42. #define DAC33_BUFFER_SIZE_BYTES 24576 /* bytes, 12288 16 bit words,
  43. * 6144 stereo */
  44. #define DAC33_BUFFER_SIZE_SAMPLES 6144
  45. #define NSAMPLE_MAX 5700
  46. #define MODE7_LTHR 10
  47. #define MODE7_UTHR (DAC33_BUFFER_SIZE_SAMPLES - 10)
  48. #define BURST_BASEFREQ_HZ 49152000
  49. #define SAMPLES_TO_US(rate, samples) \
  50. (1000000000 / ((rate * 1000) / samples))
  51. #define US_TO_SAMPLES(rate, us) \
  52. (rate / (1000000 / (us < 1000000 ? us : 1000000)))
  53. #define UTHR_FROM_PERIOD_SIZE(samples, playrate, burstrate) \
  54. ((samples * 5000) / ((burstrate * 5000) / (burstrate - playrate)))
  55. static void dac33_calculate_times(struct snd_pcm_substream *substream);
  56. static int dac33_prepare_chip(struct snd_pcm_substream *substream);
  57. enum dac33_state {
  58. DAC33_IDLE = 0,
  59. DAC33_PREFILL,
  60. DAC33_PLAYBACK,
  61. DAC33_FLUSH,
  62. };
  63. enum dac33_fifo_modes {
  64. DAC33_FIFO_BYPASS = 0,
  65. DAC33_FIFO_MODE1,
  66. DAC33_FIFO_MODE7,
  67. DAC33_FIFO_LAST_MODE,
  68. };
  69. #define DAC33_NUM_SUPPLIES 3
  70. static const char *dac33_supply_names[DAC33_NUM_SUPPLIES] = {
  71. "AVDD",
  72. "DVDD",
  73. "IOVDD",
  74. };
  75. struct tlv320dac33_priv {
  76. struct mutex mutex;
  77. struct workqueue_struct *dac33_wq;
  78. struct work_struct work;
  79. struct snd_soc_codec *codec;
  80. struct regulator_bulk_data supplies[DAC33_NUM_SUPPLIES];
  81. struct snd_pcm_substream *substream;
  82. int power_gpio;
  83. int chip_power;
  84. int irq;
  85. unsigned int refclk;
  86. unsigned int alarm_threshold; /* set to be half of LATENCY_TIME_MS */
  87. unsigned int nsample_min; /* nsample should not be lower than
  88. * this */
  89. unsigned int nsample_max; /* nsample should not be higher than
  90. * this */
  91. enum dac33_fifo_modes fifo_mode;/* FIFO mode selection */
  92. unsigned int nsample; /* burst read amount from host */
  93. int mode1_latency; /* latency caused by the i2c writes in
  94. * us */
  95. int auto_fifo_config; /* Configure the FIFO based on the
  96. * period size */
  97. u8 burst_bclkdiv; /* BCLK divider value in burst mode */
  98. unsigned int burst_rate; /* Interface speed in Burst modes */
  99. int keep_bclk; /* Keep the BCLK continuously running
  100. * in FIFO modes */
  101. spinlock_t lock;
  102. unsigned long long t_stamp1; /* Time stamp for FIFO modes to */
  103. unsigned long long t_stamp2; /* calculate the FIFO caused delay */
  104. unsigned int mode1_us_burst; /* Time to burst read n number of
  105. * samples */
  106. unsigned int mode7_us_to_lthr; /* Time to reach lthr from uthr */
  107. unsigned int uthr;
  108. enum dac33_state state;
  109. enum snd_soc_control_type control_type;
  110. void *control_data;
  111. };
  112. static const u8 dac33_reg[DAC33_CACHEREGNUM] = {
  113. 0x00, 0x00, 0x00, 0x00, /* 0x00 - 0x03 */
  114. 0x00, 0x00, 0x00, 0x00, /* 0x04 - 0x07 */
  115. 0x00, 0x00, 0x00, 0x00, /* 0x08 - 0x0b */
  116. 0x00, 0x00, 0x00, 0x00, /* 0x0c - 0x0f */
  117. 0x00, 0x00, 0x00, 0x00, /* 0x10 - 0x13 */
  118. 0x00, 0x00, 0x00, 0x00, /* 0x14 - 0x17 */
  119. 0x00, 0x00, 0x00, 0x00, /* 0x18 - 0x1b */
  120. 0x00, 0x00, 0x00, 0x00, /* 0x1c - 0x1f */
  121. 0x00, 0x00, 0x00, 0x00, /* 0x20 - 0x23 */
  122. 0x00, 0x00, 0x00, 0x00, /* 0x24 - 0x27 */
  123. 0x00, 0x00, 0x00, 0x00, /* 0x28 - 0x2b */
  124. 0x00, 0x00, 0x00, 0x80, /* 0x2c - 0x2f */
  125. 0x80, 0x00, 0x00, 0x00, /* 0x30 - 0x33 */
  126. 0x00, 0x00, 0x00, 0x00, /* 0x34 - 0x37 */
  127. 0x00, 0x00, /* 0x38 - 0x39 */
  128. /* Registers 0x3a - 0x3f are reserved */
  129. 0x00, 0x00, /* 0x3a - 0x3b */
  130. 0x00, 0x00, 0x00, 0x00, /* 0x3c - 0x3f */
  131. 0x00, 0x00, 0x00, 0x00, /* 0x40 - 0x43 */
  132. 0x00, 0x80, /* 0x44 - 0x45 */
  133. /* Registers 0x46 - 0x47 are reserved */
  134. 0x80, 0x80, /* 0x46 - 0x47 */
  135. 0x80, 0x00, 0x00, /* 0x48 - 0x4a */
  136. /* Registers 0x4b - 0x7c are reserved */
  137. 0x00, /* 0x4b */
  138. 0x00, 0x00, 0x00, 0x00, /* 0x4c - 0x4f */
  139. 0x00, 0x00, 0x00, 0x00, /* 0x50 - 0x53 */
  140. 0x00, 0x00, 0x00, 0x00, /* 0x54 - 0x57 */
  141. 0x00, 0x00, 0x00, 0x00, /* 0x58 - 0x5b */
  142. 0x00, 0x00, 0x00, 0x00, /* 0x5c - 0x5f */
  143. 0x00, 0x00, 0x00, 0x00, /* 0x60 - 0x63 */
  144. 0x00, 0x00, 0x00, 0x00, /* 0x64 - 0x67 */
  145. 0x00, 0x00, 0x00, 0x00, /* 0x68 - 0x6b */
  146. 0x00, 0x00, 0x00, 0x00, /* 0x6c - 0x6f */
  147. 0x00, 0x00, 0x00, 0x00, /* 0x70 - 0x73 */
  148. 0x00, 0x00, 0x00, 0x00, /* 0x74 - 0x77 */
  149. 0x00, 0x00, 0x00, 0x00, /* 0x78 - 0x7b */
  150. 0x00, /* 0x7c */
  151. 0xda, 0x33, 0x03, /* 0x7d - 0x7f */
  152. };
  153. /* Register read and write */
  154. static inline unsigned int dac33_read_reg_cache(struct snd_soc_codec *codec,
  155. unsigned reg)
  156. {
  157. u8 *cache = codec->reg_cache;
  158. if (reg >= DAC33_CACHEREGNUM)
  159. return 0;
  160. return cache[reg];
  161. }
  162. static inline void dac33_write_reg_cache(struct snd_soc_codec *codec,
  163. u8 reg, u8 value)
  164. {
  165. u8 *cache = codec->reg_cache;
  166. if (reg >= DAC33_CACHEREGNUM)
  167. return;
  168. cache[reg] = value;
  169. }
  170. static int dac33_read(struct snd_soc_codec *codec, unsigned int reg,
  171. u8 *value)
  172. {
  173. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  174. int val, ret = 0;
  175. *value = reg & 0xff;
  176. /* If powered off, return the cached value */
  177. if (dac33->chip_power) {
  178. val = i2c_smbus_read_byte_data(codec->control_data, value[0]);
  179. if (val < 0) {
  180. dev_err(codec->dev, "Read failed (%d)\n", val);
  181. value[0] = dac33_read_reg_cache(codec, reg);
  182. ret = val;
  183. } else {
  184. value[0] = val;
  185. dac33_write_reg_cache(codec, reg, val);
  186. }
  187. } else {
  188. value[0] = dac33_read_reg_cache(codec, reg);
  189. }
  190. return ret;
  191. }
  192. static int dac33_write(struct snd_soc_codec *codec, unsigned int reg,
  193. unsigned int value)
  194. {
  195. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  196. u8 data[2];
  197. int ret = 0;
  198. /*
  199. * data is
  200. * D15..D8 dac33 register offset
  201. * D7...D0 register data
  202. */
  203. data[0] = reg & 0xff;
  204. data[1] = value & 0xff;
  205. dac33_write_reg_cache(codec, data[0], data[1]);
  206. if (dac33->chip_power) {
  207. ret = codec->hw_write(codec->control_data, data, 2);
  208. if (ret != 2)
  209. dev_err(codec->dev, "Write failed (%d)\n", ret);
  210. else
  211. ret = 0;
  212. }
  213. return ret;
  214. }
  215. static int dac33_write_locked(struct snd_soc_codec *codec, unsigned int reg,
  216. unsigned int value)
  217. {
  218. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  219. int ret;
  220. mutex_lock(&dac33->mutex);
  221. ret = dac33_write(codec, reg, value);
  222. mutex_unlock(&dac33->mutex);
  223. return ret;
  224. }
  225. #define DAC33_I2C_ADDR_AUTOINC 0x80
  226. static int dac33_write16(struct snd_soc_codec *codec, unsigned int reg,
  227. unsigned int value)
  228. {
  229. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  230. u8 data[3];
  231. int ret = 0;
  232. /*
  233. * data is
  234. * D23..D16 dac33 register offset
  235. * D15..D8 register data MSB
  236. * D7...D0 register data LSB
  237. */
  238. data[0] = reg & 0xff;
  239. data[1] = (value >> 8) & 0xff;
  240. data[2] = value & 0xff;
  241. dac33_write_reg_cache(codec, data[0], data[1]);
  242. dac33_write_reg_cache(codec, data[0] + 1, data[2]);
  243. if (dac33->chip_power) {
  244. /* We need to set autoincrement mode for 16 bit writes */
  245. data[0] |= DAC33_I2C_ADDR_AUTOINC;
  246. ret = codec->hw_write(codec->control_data, data, 3);
  247. if (ret != 3)
  248. dev_err(codec->dev, "Write failed (%d)\n", ret);
  249. else
  250. ret = 0;
  251. }
  252. return ret;
  253. }
  254. static void dac33_init_chip(struct snd_soc_codec *codec)
  255. {
  256. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  257. if (unlikely(!dac33->chip_power))
  258. return;
  259. /* 44-46: DAC Control Registers */
  260. /* A : DAC sample rate Fsref/1.5 */
  261. dac33_write(codec, DAC33_DAC_CTRL_A, DAC33_DACRATE(0));
  262. /* B : DAC src=normal, not muted */
  263. dac33_write(codec, DAC33_DAC_CTRL_B, DAC33_DACSRCR_RIGHT |
  264. DAC33_DACSRCL_LEFT);
  265. /* C : (defaults) */
  266. dac33_write(codec, DAC33_DAC_CTRL_C, 0x00);
  267. /* 73 : volume soft stepping control,
  268. clock source = internal osc (?) */
  269. dac33_write(codec, DAC33_ANA_VOL_SOFT_STEP_CTRL, DAC33_VOLCLKEN);
  270. /* Restore only selected registers (gains mostly) */
  271. dac33_write(codec, DAC33_LDAC_DIG_VOL_CTRL,
  272. dac33_read_reg_cache(codec, DAC33_LDAC_DIG_VOL_CTRL));
  273. dac33_write(codec, DAC33_RDAC_DIG_VOL_CTRL,
  274. dac33_read_reg_cache(codec, DAC33_RDAC_DIG_VOL_CTRL));
  275. dac33_write(codec, DAC33_LINEL_TO_LLO_VOL,
  276. dac33_read_reg_cache(codec, DAC33_LINEL_TO_LLO_VOL));
  277. dac33_write(codec, DAC33_LINER_TO_RLO_VOL,
  278. dac33_read_reg_cache(codec, DAC33_LINER_TO_RLO_VOL));
  279. }
  280. static inline int dac33_read_id(struct snd_soc_codec *codec)
  281. {
  282. int i, ret = 0;
  283. u8 reg;
  284. for (i = 0; i < 3; i++) {
  285. ret = dac33_read(codec, DAC33_DEVICE_ID_MSB + i, &reg);
  286. if (ret < 0)
  287. break;
  288. }
  289. return ret;
  290. }
  291. static inline void dac33_soft_power(struct snd_soc_codec *codec, int power)
  292. {
  293. u8 reg;
  294. reg = dac33_read_reg_cache(codec, DAC33_PWR_CTRL);
  295. if (power)
  296. reg |= DAC33_PDNALLB;
  297. else
  298. reg &= ~(DAC33_PDNALLB | DAC33_OSCPDNB |
  299. DAC33_DACRPDNB | DAC33_DACLPDNB);
  300. dac33_write(codec, DAC33_PWR_CTRL, reg);
  301. }
  302. static int dac33_hard_power(struct snd_soc_codec *codec, int power)
  303. {
  304. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  305. int ret = 0;
  306. mutex_lock(&dac33->mutex);
  307. /* Safety check */
  308. if (unlikely(power == dac33->chip_power)) {
  309. dev_dbg(codec->dev, "Trying to set the same power state: %s\n",
  310. power ? "ON" : "OFF");
  311. goto exit;
  312. }
  313. if (power) {
  314. ret = regulator_bulk_enable(ARRAY_SIZE(dac33->supplies),
  315. dac33->supplies);
  316. if (ret != 0) {
  317. dev_err(codec->dev,
  318. "Failed to enable supplies: %d\n", ret);
  319. goto exit;
  320. }
  321. if (dac33->power_gpio >= 0)
  322. gpio_set_value(dac33->power_gpio, 1);
  323. dac33->chip_power = 1;
  324. } else {
  325. dac33_soft_power(codec, 0);
  326. if (dac33->power_gpio >= 0)
  327. gpio_set_value(dac33->power_gpio, 0);
  328. ret = regulator_bulk_disable(ARRAY_SIZE(dac33->supplies),
  329. dac33->supplies);
  330. if (ret != 0) {
  331. dev_err(codec->dev,
  332. "Failed to disable supplies: %d\n", ret);
  333. goto exit;
  334. }
  335. dac33->chip_power = 0;
  336. }
  337. exit:
  338. mutex_unlock(&dac33->mutex);
  339. return ret;
  340. }
  341. static int playback_event(struct snd_soc_dapm_widget *w,
  342. struct snd_kcontrol *kcontrol, int event)
  343. {
  344. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(w->codec);
  345. switch (event) {
  346. case SND_SOC_DAPM_PRE_PMU:
  347. if (likely(dac33->substream)) {
  348. dac33_calculate_times(dac33->substream);
  349. dac33_prepare_chip(dac33->substream);
  350. }
  351. break;
  352. }
  353. return 0;
  354. }
  355. static int dac33_get_nsample(struct snd_kcontrol *kcontrol,
  356. struct snd_ctl_elem_value *ucontrol)
  357. {
  358. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  359. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  360. ucontrol->value.integer.value[0] = dac33->nsample;
  361. return 0;
  362. }
  363. static int dac33_set_nsample(struct snd_kcontrol *kcontrol,
  364. struct snd_ctl_elem_value *ucontrol)
  365. {
  366. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  367. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  368. int ret = 0;
  369. if (dac33->nsample == ucontrol->value.integer.value[0])
  370. return 0;
  371. if (ucontrol->value.integer.value[0] < dac33->nsample_min ||
  372. ucontrol->value.integer.value[0] > dac33->nsample_max) {
  373. ret = -EINVAL;
  374. } else {
  375. dac33->nsample = ucontrol->value.integer.value[0];
  376. /* Re calculate the burst time */
  377. dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate,
  378. dac33->nsample);
  379. }
  380. return ret;
  381. }
  382. static int dac33_get_uthr(struct snd_kcontrol *kcontrol,
  383. struct snd_ctl_elem_value *ucontrol)
  384. {
  385. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  386. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  387. ucontrol->value.integer.value[0] = dac33->uthr;
  388. return 0;
  389. }
  390. static int dac33_set_uthr(struct snd_kcontrol *kcontrol,
  391. struct snd_ctl_elem_value *ucontrol)
  392. {
  393. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  394. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  395. int ret = 0;
  396. if (dac33->substream)
  397. return -EBUSY;
  398. if (dac33->uthr == ucontrol->value.integer.value[0])
  399. return 0;
  400. if (ucontrol->value.integer.value[0] < (MODE7_LTHR + 10) ||
  401. ucontrol->value.integer.value[0] > MODE7_UTHR)
  402. ret = -EINVAL;
  403. else
  404. dac33->uthr = ucontrol->value.integer.value[0];
  405. return ret;
  406. }
  407. static int dac33_get_fifo_mode(struct snd_kcontrol *kcontrol,
  408. struct snd_ctl_elem_value *ucontrol)
  409. {
  410. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  411. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  412. ucontrol->value.integer.value[0] = dac33->fifo_mode;
  413. return 0;
  414. }
  415. static int dac33_set_fifo_mode(struct snd_kcontrol *kcontrol,
  416. struct snd_ctl_elem_value *ucontrol)
  417. {
  418. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  419. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  420. int ret = 0;
  421. if (dac33->fifo_mode == ucontrol->value.integer.value[0])
  422. return 0;
  423. /* Do not allow changes while stream is running*/
  424. if (codec->active)
  425. return -EPERM;
  426. if (ucontrol->value.integer.value[0] < 0 ||
  427. ucontrol->value.integer.value[0] >= DAC33_FIFO_LAST_MODE)
  428. ret = -EINVAL;
  429. else
  430. dac33->fifo_mode = ucontrol->value.integer.value[0];
  431. return ret;
  432. }
  433. /* Codec operation modes */
  434. static const char *dac33_fifo_mode_texts[] = {
  435. "Bypass", "Mode 1", "Mode 7"
  436. };
  437. static const struct soc_enum dac33_fifo_mode_enum =
  438. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(dac33_fifo_mode_texts),
  439. dac33_fifo_mode_texts);
  440. /* L/R Line Output Gain */
  441. static const char *lr_lineout_gain_texts[] = {
  442. "Line -12dB DAC 0dB", "Line -6dB DAC 6dB",
  443. "Line 0dB DAC 12dB", "Line 6dB DAC 18dB",
  444. };
  445. static const struct soc_enum l_lineout_gain_enum =
  446. SOC_ENUM_SINGLE(DAC33_LDAC_PWR_CTRL, 0,
  447. ARRAY_SIZE(lr_lineout_gain_texts),
  448. lr_lineout_gain_texts);
  449. static const struct soc_enum r_lineout_gain_enum =
  450. SOC_ENUM_SINGLE(DAC33_RDAC_PWR_CTRL, 0,
  451. ARRAY_SIZE(lr_lineout_gain_texts),
  452. lr_lineout_gain_texts);
  453. /*
  454. * DACL/R digital volume control:
  455. * from 0 dB to -63.5 in 0.5 dB steps
  456. * Need to be inverted later on:
  457. * 0x00 == 0 dB
  458. * 0x7f == -63.5 dB
  459. */
  460. static DECLARE_TLV_DB_SCALE(dac_digivol_tlv, -6350, 50, 0);
  461. static const struct snd_kcontrol_new dac33_snd_controls[] = {
  462. SOC_DOUBLE_R_TLV("DAC Digital Playback Volume",
  463. DAC33_LDAC_DIG_VOL_CTRL, DAC33_RDAC_DIG_VOL_CTRL,
  464. 0, 0x7f, 1, dac_digivol_tlv),
  465. SOC_DOUBLE_R("DAC Digital Playback Switch",
  466. DAC33_LDAC_DIG_VOL_CTRL, DAC33_RDAC_DIG_VOL_CTRL, 7, 1, 1),
  467. SOC_DOUBLE_R("Line to Line Out Volume",
  468. DAC33_LINEL_TO_LLO_VOL, DAC33_LINER_TO_RLO_VOL, 0, 127, 1),
  469. SOC_ENUM("Left Line Output Gain", l_lineout_gain_enum),
  470. SOC_ENUM("Right Line Output Gain", r_lineout_gain_enum),
  471. };
  472. static const struct snd_kcontrol_new dac33_mode_snd_controls[] = {
  473. SOC_ENUM_EXT("FIFO Mode", dac33_fifo_mode_enum,
  474. dac33_get_fifo_mode, dac33_set_fifo_mode),
  475. };
  476. static const struct snd_kcontrol_new dac33_fifo_snd_controls[] = {
  477. SOC_SINGLE_EXT("nSample", 0, 0, 5900, 0,
  478. dac33_get_nsample, dac33_set_nsample),
  479. SOC_SINGLE_EXT("UTHR", 0, 0, MODE7_UTHR, 0,
  480. dac33_get_uthr, dac33_set_uthr),
  481. };
  482. /* Analog bypass */
  483. static const struct snd_kcontrol_new dac33_dapm_abypassl_control =
  484. SOC_DAPM_SINGLE("Switch", DAC33_LINEL_TO_LLO_VOL, 7, 1, 1);
  485. static const struct snd_kcontrol_new dac33_dapm_abypassr_control =
  486. SOC_DAPM_SINGLE("Switch", DAC33_LINER_TO_RLO_VOL, 7, 1, 1);
  487. static const struct snd_soc_dapm_widget dac33_dapm_widgets[] = {
  488. SND_SOC_DAPM_OUTPUT("LEFT_LO"),
  489. SND_SOC_DAPM_OUTPUT("RIGHT_LO"),
  490. SND_SOC_DAPM_INPUT("LINEL"),
  491. SND_SOC_DAPM_INPUT("LINER"),
  492. SND_SOC_DAPM_DAC("DACL", "Left Playback", SND_SOC_NOPM, 0, 0),
  493. SND_SOC_DAPM_DAC("DACR", "Right Playback", SND_SOC_NOPM, 0, 0),
  494. /* Analog bypass */
  495. SND_SOC_DAPM_SWITCH("Analog Left Bypass", SND_SOC_NOPM, 0, 0,
  496. &dac33_dapm_abypassl_control),
  497. SND_SOC_DAPM_SWITCH("Analog Right Bypass", SND_SOC_NOPM, 0, 0,
  498. &dac33_dapm_abypassr_control),
  499. SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Left Amplifier",
  500. DAC33_OUT_AMP_PWR_CTRL, 6, 3, 3, 0),
  501. SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Right Amplifier",
  502. DAC33_OUT_AMP_PWR_CTRL, 4, 3, 3, 0),
  503. SND_SOC_DAPM_SUPPLY("Left DAC Power",
  504. DAC33_LDAC_PWR_CTRL, 2, 0, NULL, 0),
  505. SND_SOC_DAPM_SUPPLY("Right DAC Power",
  506. DAC33_RDAC_PWR_CTRL, 2, 0, NULL, 0),
  507. SND_SOC_DAPM_PRE("Prepare Playback", playback_event),
  508. };
  509. static const struct snd_soc_dapm_route audio_map[] = {
  510. /* Analog bypass */
  511. {"Analog Left Bypass", "Switch", "LINEL"},
  512. {"Analog Right Bypass", "Switch", "LINER"},
  513. {"Output Left Amplifier", NULL, "DACL"},
  514. {"Output Right Amplifier", NULL, "DACR"},
  515. {"Output Left Amplifier", NULL, "Analog Left Bypass"},
  516. {"Output Right Amplifier", NULL, "Analog Right Bypass"},
  517. {"Output Left Amplifier", NULL, "Left DAC Power"},
  518. {"Output Right Amplifier", NULL, "Right DAC Power"},
  519. /* output */
  520. {"LEFT_LO", NULL, "Output Left Amplifier"},
  521. {"RIGHT_LO", NULL, "Output Right Amplifier"},
  522. };
  523. static int dac33_add_widgets(struct snd_soc_codec *codec)
  524. {
  525. struct snd_soc_dapm_context *dapm = &codec->dapm;
  526. snd_soc_dapm_new_controls(dapm, dac33_dapm_widgets,
  527. ARRAY_SIZE(dac33_dapm_widgets));
  528. /* set up audio path interconnects */
  529. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  530. return 0;
  531. }
  532. static int dac33_set_bias_level(struct snd_soc_codec *codec,
  533. enum snd_soc_bias_level level)
  534. {
  535. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  536. int ret;
  537. switch (level) {
  538. case SND_SOC_BIAS_ON:
  539. if (!dac33->substream)
  540. dac33_soft_power(codec, 1);
  541. break;
  542. case SND_SOC_BIAS_PREPARE:
  543. break;
  544. case SND_SOC_BIAS_STANDBY:
  545. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
  546. /* Coming from OFF, switch on the codec */
  547. ret = dac33_hard_power(codec, 1);
  548. if (ret != 0)
  549. return ret;
  550. dac33_init_chip(codec);
  551. }
  552. break;
  553. case SND_SOC_BIAS_OFF:
  554. /* Do not power off, when the codec is already off */
  555. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
  556. return 0;
  557. ret = dac33_hard_power(codec, 0);
  558. if (ret != 0)
  559. return ret;
  560. break;
  561. }
  562. codec->dapm.bias_level = level;
  563. return 0;
  564. }
  565. static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33)
  566. {
  567. struct snd_soc_codec *codec = dac33->codec;
  568. unsigned int delay;
  569. switch (dac33->fifo_mode) {
  570. case DAC33_FIFO_MODE1:
  571. dac33_write16(codec, DAC33_NSAMPLE_MSB,
  572. DAC33_THRREG(dac33->nsample));
  573. /* Take the timestamps */
  574. spin_lock_irq(&dac33->lock);
  575. dac33->t_stamp2 = ktime_to_us(ktime_get());
  576. dac33->t_stamp1 = dac33->t_stamp2;
  577. spin_unlock_irq(&dac33->lock);
  578. dac33_write16(codec, DAC33_PREFILL_MSB,
  579. DAC33_THRREG(dac33->alarm_threshold));
  580. /* Enable Alarm Threshold IRQ with a delay */
  581. delay = SAMPLES_TO_US(dac33->burst_rate,
  582. dac33->alarm_threshold) + 1000;
  583. usleep_range(delay, delay + 500);
  584. dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MAT);
  585. break;
  586. case DAC33_FIFO_MODE7:
  587. /* Take the timestamp */
  588. spin_lock_irq(&dac33->lock);
  589. dac33->t_stamp1 = ktime_to_us(ktime_get());
  590. /* Move back the timestamp with drain time */
  591. dac33->t_stamp1 -= dac33->mode7_us_to_lthr;
  592. spin_unlock_irq(&dac33->lock);
  593. dac33_write16(codec, DAC33_PREFILL_MSB,
  594. DAC33_THRREG(MODE7_LTHR));
  595. /* Enable Upper Threshold IRQ */
  596. dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MUT);
  597. break;
  598. default:
  599. dev_warn(codec->dev, "Unhandled FIFO mode: %d\n",
  600. dac33->fifo_mode);
  601. break;
  602. }
  603. }
  604. static inline void dac33_playback_handler(struct tlv320dac33_priv *dac33)
  605. {
  606. struct snd_soc_codec *codec = dac33->codec;
  607. switch (dac33->fifo_mode) {
  608. case DAC33_FIFO_MODE1:
  609. /* Take the timestamp */
  610. spin_lock_irq(&dac33->lock);
  611. dac33->t_stamp2 = ktime_to_us(ktime_get());
  612. spin_unlock_irq(&dac33->lock);
  613. dac33_write16(codec, DAC33_NSAMPLE_MSB,
  614. DAC33_THRREG(dac33->nsample));
  615. break;
  616. case DAC33_FIFO_MODE7:
  617. /* At the moment we are not using interrupts in mode7 */
  618. break;
  619. default:
  620. dev_warn(codec->dev, "Unhandled FIFO mode: %d\n",
  621. dac33->fifo_mode);
  622. break;
  623. }
  624. }
  625. static void dac33_work(struct work_struct *work)
  626. {
  627. struct snd_soc_codec *codec;
  628. struct tlv320dac33_priv *dac33;
  629. u8 reg;
  630. dac33 = container_of(work, struct tlv320dac33_priv, work);
  631. codec = dac33->codec;
  632. mutex_lock(&dac33->mutex);
  633. switch (dac33->state) {
  634. case DAC33_PREFILL:
  635. dac33->state = DAC33_PLAYBACK;
  636. dac33_prefill_handler(dac33);
  637. break;
  638. case DAC33_PLAYBACK:
  639. dac33_playback_handler(dac33);
  640. break;
  641. case DAC33_IDLE:
  642. break;
  643. case DAC33_FLUSH:
  644. dac33->state = DAC33_IDLE;
  645. /* Mask all interrupts from dac33 */
  646. dac33_write(codec, DAC33_FIFO_IRQ_MASK, 0);
  647. /* flush fifo */
  648. reg = dac33_read_reg_cache(codec, DAC33_FIFO_CTRL_A);
  649. reg |= DAC33_FIFOFLUSH;
  650. dac33_write(codec, DAC33_FIFO_CTRL_A, reg);
  651. break;
  652. }
  653. mutex_unlock(&dac33->mutex);
  654. }
  655. static irqreturn_t dac33_interrupt_handler(int irq, void *dev)
  656. {
  657. struct snd_soc_codec *codec = dev;
  658. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  659. spin_lock(&dac33->lock);
  660. dac33->t_stamp1 = ktime_to_us(ktime_get());
  661. spin_unlock(&dac33->lock);
  662. /* Do not schedule the workqueue in Mode7 */
  663. if (dac33->fifo_mode != DAC33_FIFO_MODE7)
  664. queue_work(dac33->dac33_wq, &dac33->work);
  665. return IRQ_HANDLED;
  666. }
  667. static void dac33_oscwait(struct snd_soc_codec *codec)
  668. {
  669. int timeout = 60;
  670. u8 reg;
  671. do {
  672. usleep_range(1000, 2000);
  673. dac33_read(codec, DAC33_INT_OSC_STATUS, &reg);
  674. } while (((reg & 0x03) != DAC33_OSCSTATUS_NORMAL) && timeout--);
  675. if ((reg & 0x03) != DAC33_OSCSTATUS_NORMAL)
  676. dev_err(codec->dev,
  677. "internal oscillator calibration failed\n");
  678. }
  679. static int dac33_startup(struct snd_pcm_substream *substream,
  680. struct snd_soc_dai *dai)
  681. {
  682. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  683. struct snd_soc_codec *codec = rtd->codec;
  684. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  685. /* Stream started, save the substream pointer */
  686. dac33->substream = substream;
  687. return 0;
  688. }
  689. static void dac33_shutdown(struct snd_pcm_substream *substream,
  690. struct snd_soc_dai *dai)
  691. {
  692. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  693. struct snd_soc_codec *codec = rtd->codec;
  694. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  695. dac33->substream = NULL;
  696. /* Reset the nSample restrictions */
  697. dac33->nsample_min = 0;
  698. dac33->nsample_max = NSAMPLE_MAX;
  699. }
  700. static int dac33_hw_params(struct snd_pcm_substream *substream,
  701. struct snd_pcm_hw_params *params,
  702. struct snd_soc_dai *dai)
  703. {
  704. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  705. struct snd_soc_codec *codec = rtd->codec;
  706. /* Check parameters for validity */
  707. switch (params_rate(params)) {
  708. case 44100:
  709. case 48000:
  710. break;
  711. default:
  712. dev_err(codec->dev, "unsupported rate %d\n",
  713. params_rate(params));
  714. return -EINVAL;
  715. }
  716. switch (params_format(params)) {
  717. case SNDRV_PCM_FORMAT_S16_LE:
  718. break;
  719. default:
  720. dev_err(codec->dev, "unsupported format %d\n",
  721. params_format(params));
  722. return -EINVAL;
  723. }
  724. return 0;
  725. }
  726. #define CALC_OSCSET(rate, refclk) ( \
  727. ((((rate * 10000) / refclk) * 4096) + 7000) / 10000)
  728. #define CALC_RATIOSET(rate, refclk) ( \
  729. ((((refclk * 100000) / rate) * 16384) + 50000) / 100000)
  730. /*
  731. * tlv320dac33 is strict on the sequence of the register writes, if the register
  732. * writes happens in different order, than dac33 might end up in unknown state.
  733. * Use the known, working sequence of register writes to initialize the dac33.
  734. */
  735. static int dac33_prepare_chip(struct snd_pcm_substream *substream)
  736. {
  737. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  738. struct snd_soc_codec *codec = rtd->codec;
  739. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  740. unsigned int oscset, ratioset, pwr_ctrl, reg_tmp;
  741. u8 aictrl_a, aictrl_b, fifoctrl_a;
  742. switch (substream->runtime->rate) {
  743. case 44100:
  744. case 48000:
  745. oscset = CALC_OSCSET(substream->runtime->rate, dac33->refclk);
  746. ratioset = CALC_RATIOSET(substream->runtime->rate,
  747. dac33->refclk);
  748. break;
  749. default:
  750. dev_err(codec->dev, "unsupported rate %d\n",
  751. substream->runtime->rate);
  752. return -EINVAL;
  753. }
  754. aictrl_a = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_A);
  755. aictrl_a &= ~(DAC33_NCYCL_MASK | DAC33_WLEN_MASK);
  756. /* Read FIFO control A, and clear FIFO flush bit */
  757. fifoctrl_a = dac33_read_reg_cache(codec, DAC33_FIFO_CTRL_A);
  758. fifoctrl_a &= ~DAC33_FIFOFLUSH;
  759. fifoctrl_a &= ~DAC33_WIDTH;
  760. switch (substream->runtime->format) {
  761. case SNDRV_PCM_FORMAT_S16_LE:
  762. aictrl_a |= (DAC33_NCYCL_16 | DAC33_WLEN_16);
  763. fifoctrl_a |= DAC33_WIDTH;
  764. break;
  765. default:
  766. dev_err(codec->dev, "unsupported format %d\n",
  767. substream->runtime->format);
  768. return -EINVAL;
  769. }
  770. mutex_lock(&dac33->mutex);
  771. if (!dac33->chip_power) {
  772. /*
  773. * Chip is not powered yet.
  774. * Do the init in the dac33_set_bias_level later.
  775. */
  776. mutex_unlock(&dac33->mutex);
  777. return 0;
  778. }
  779. dac33_soft_power(codec, 0);
  780. dac33_soft_power(codec, 1);
  781. reg_tmp = dac33_read_reg_cache(codec, DAC33_INT_OSC_CTRL);
  782. dac33_write(codec, DAC33_INT_OSC_CTRL, reg_tmp);
  783. /* Write registers 0x08 and 0x09 (MSB, LSB) */
  784. dac33_write16(codec, DAC33_INT_OSC_FREQ_RAT_A, oscset);
  785. /* calib time: 128 is a nice number ;) */
  786. dac33_write(codec, DAC33_CALIB_TIME, 128);
  787. /* adjustment treshold & step */
  788. dac33_write(codec, DAC33_INT_OSC_CTRL_B, DAC33_ADJTHRSHLD(2) |
  789. DAC33_ADJSTEP(1));
  790. /* div=4 / gain=1 / div */
  791. dac33_write(codec, DAC33_INT_OSC_CTRL_C, DAC33_REFDIV(4));
  792. pwr_ctrl = dac33_read_reg_cache(codec, DAC33_PWR_CTRL);
  793. pwr_ctrl |= DAC33_OSCPDNB | DAC33_DACRPDNB | DAC33_DACLPDNB;
  794. dac33_write(codec, DAC33_PWR_CTRL, pwr_ctrl);
  795. dac33_oscwait(codec);
  796. if (dac33->fifo_mode) {
  797. /* Generic for all FIFO modes */
  798. /* 50-51 : ASRC Control registers */
  799. dac33_write(codec, DAC33_ASRC_CTRL_A, DAC33_SRCLKDIV(1));
  800. dac33_write(codec, DAC33_ASRC_CTRL_B, 1); /* ??? */
  801. /* Write registers 0x34 and 0x35 (MSB, LSB) */
  802. dac33_write16(codec, DAC33_SRC_REF_CLK_RATIO_A, ratioset);
  803. /* Set interrupts to high active */
  804. dac33_write(codec, DAC33_INTP_CTRL_A, DAC33_INTPM_AHIGH);
  805. } else {
  806. /* FIFO bypass mode */
  807. /* 50-51 : ASRC Control registers */
  808. dac33_write(codec, DAC33_ASRC_CTRL_A, DAC33_SRCBYP);
  809. dac33_write(codec, DAC33_ASRC_CTRL_B, 0); /* ??? */
  810. }
  811. /* Interrupt behaviour configuration */
  812. switch (dac33->fifo_mode) {
  813. case DAC33_FIFO_MODE1:
  814. dac33_write(codec, DAC33_FIFO_IRQ_MODE_B,
  815. DAC33_ATM(DAC33_FIFO_IRQ_MODE_LEVEL));
  816. break;
  817. case DAC33_FIFO_MODE7:
  818. dac33_write(codec, DAC33_FIFO_IRQ_MODE_A,
  819. DAC33_UTM(DAC33_FIFO_IRQ_MODE_LEVEL));
  820. break;
  821. default:
  822. /* in FIFO bypass mode, the interrupts are not used */
  823. break;
  824. }
  825. aictrl_b = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B);
  826. switch (dac33->fifo_mode) {
  827. case DAC33_FIFO_MODE1:
  828. /*
  829. * For mode1:
  830. * Disable the FIFO bypass (Enable the use of FIFO)
  831. * Select nSample mode
  832. * BCLK is only running when data is needed by DAC33
  833. */
  834. fifoctrl_a &= ~DAC33_FBYPAS;
  835. fifoctrl_a &= ~DAC33_FAUTO;
  836. if (dac33->keep_bclk)
  837. aictrl_b |= DAC33_BCLKON;
  838. else
  839. aictrl_b &= ~DAC33_BCLKON;
  840. break;
  841. case DAC33_FIFO_MODE7:
  842. /*
  843. * For mode1:
  844. * Disable the FIFO bypass (Enable the use of FIFO)
  845. * Select Threshold mode
  846. * BCLK is only running when data is needed by DAC33
  847. */
  848. fifoctrl_a &= ~DAC33_FBYPAS;
  849. fifoctrl_a |= DAC33_FAUTO;
  850. if (dac33->keep_bclk)
  851. aictrl_b |= DAC33_BCLKON;
  852. else
  853. aictrl_b &= ~DAC33_BCLKON;
  854. break;
  855. default:
  856. /*
  857. * For FIFO bypass mode:
  858. * Enable the FIFO bypass (Disable the FIFO use)
  859. * Set the BCLK as continous
  860. */
  861. fifoctrl_a |= DAC33_FBYPAS;
  862. aictrl_b |= DAC33_BCLKON;
  863. break;
  864. }
  865. dac33_write(codec, DAC33_FIFO_CTRL_A, fifoctrl_a);
  866. dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_A, aictrl_a);
  867. dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_B, aictrl_b);
  868. /*
  869. * BCLK divide ratio
  870. * 0: 1.5
  871. * 1: 1
  872. * 2: 2
  873. * ...
  874. * 254: 254
  875. * 255: 255
  876. */
  877. if (dac33->fifo_mode)
  878. dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C,
  879. dac33->burst_bclkdiv);
  880. else
  881. dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C, 32);
  882. switch (dac33->fifo_mode) {
  883. case DAC33_FIFO_MODE1:
  884. dac33_write16(codec, DAC33_ATHR_MSB,
  885. DAC33_THRREG(dac33->alarm_threshold));
  886. break;
  887. case DAC33_FIFO_MODE7:
  888. /*
  889. * Configure the threshold levels, and leave 10 sample space
  890. * at the bottom, and also at the top of the FIFO
  891. */
  892. dac33_write16(codec, DAC33_UTHR_MSB, DAC33_THRREG(dac33->uthr));
  893. dac33_write16(codec, DAC33_LTHR_MSB, DAC33_THRREG(MODE7_LTHR));
  894. break;
  895. default:
  896. break;
  897. }
  898. mutex_unlock(&dac33->mutex);
  899. return 0;
  900. }
  901. static void dac33_calculate_times(struct snd_pcm_substream *substream)
  902. {
  903. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  904. struct snd_soc_codec *codec = rtd->codec;
  905. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  906. unsigned int period_size = substream->runtime->period_size;
  907. unsigned int rate = substream->runtime->rate;
  908. unsigned int nsample_limit;
  909. /* In bypass mode we don't need to calculate */
  910. if (!dac33->fifo_mode)
  911. return;
  912. switch (dac33->fifo_mode) {
  913. case DAC33_FIFO_MODE1:
  914. /* Number of samples under i2c latency */
  915. dac33->alarm_threshold = US_TO_SAMPLES(rate,
  916. dac33->mode1_latency);
  917. nsample_limit = DAC33_BUFFER_SIZE_SAMPLES -
  918. dac33->alarm_threshold;
  919. if (dac33->auto_fifo_config) {
  920. if (period_size <= dac33->alarm_threshold)
  921. /*
  922. * Configure nSamaple to number of periods,
  923. * which covers the latency requironment.
  924. */
  925. dac33->nsample = period_size *
  926. ((dac33->alarm_threshold / period_size) +
  927. (dac33->alarm_threshold % period_size ?
  928. 1 : 0));
  929. else if (period_size > nsample_limit)
  930. dac33->nsample = nsample_limit;
  931. else
  932. dac33->nsample = period_size;
  933. } else {
  934. /* nSample time shall not be shorter than i2c latency */
  935. dac33->nsample_min = dac33->alarm_threshold;
  936. /*
  937. * nSample should not be bigger than alsa buffer minus
  938. * size of one period to avoid overruns
  939. */
  940. dac33->nsample_max = substream->runtime->buffer_size -
  941. period_size;
  942. if (dac33->nsample_max > nsample_limit)
  943. dac33->nsample_max = nsample_limit;
  944. /* Correct the nSample if it is outside of the ranges */
  945. if (dac33->nsample < dac33->nsample_min)
  946. dac33->nsample = dac33->nsample_min;
  947. if (dac33->nsample > dac33->nsample_max)
  948. dac33->nsample = dac33->nsample_max;
  949. }
  950. dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate,
  951. dac33->nsample);
  952. dac33->t_stamp1 = 0;
  953. dac33->t_stamp2 = 0;
  954. break;
  955. case DAC33_FIFO_MODE7:
  956. if (dac33->auto_fifo_config) {
  957. dac33->uthr = UTHR_FROM_PERIOD_SIZE(
  958. period_size,
  959. rate,
  960. dac33->burst_rate) + 9;
  961. if (dac33->uthr > MODE7_UTHR)
  962. dac33->uthr = MODE7_UTHR;
  963. if (dac33->uthr < (MODE7_LTHR + 10))
  964. dac33->uthr = (MODE7_LTHR + 10);
  965. }
  966. dac33->mode7_us_to_lthr =
  967. SAMPLES_TO_US(substream->runtime->rate,
  968. dac33->uthr - MODE7_LTHR + 1);
  969. dac33->t_stamp1 = 0;
  970. break;
  971. default:
  972. break;
  973. }
  974. }
  975. static int dac33_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
  976. struct snd_soc_dai *dai)
  977. {
  978. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  979. struct snd_soc_codec *codec = rtd->codec;
  980. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  981. int ret = 0;
  982. switch (cmd) {
  983. case SNDRV_PCM_TRIGGER_START:
  984. case SNDRV_PCM_TRIGGER_RESUME:
  985. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  986. if (dac33->fifo_mode) {
  987. dac33->state = DAC33_PREFILL;
  988. queue_work(dac33->dac33_wq, &dac33->work);
  989. }
  990. break;
  991. case SNDRV_PCM_TRIGGER_STOP:
  992. case SNDRV_PCM_TRIGGER_SUSPEND:
  993. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  994. if (dac33->fifo_mode) {
  995. dac33->state = DAC33_FLUSH;
  996. queue_work(dac33->dac33_wq, &dac33->work);
  997. }
  998. break;
  999. default:
  1000. ret = -EINVAL;
  1001. }
  1002. return ret;
  1003. }
  1004. static snd_pcm_sframes_t dac33_dai_delay(
  1005. struct snd_pcm_substream *substream,
  1006. struct snd_soc_dai *dai)
  1007. {
  1008. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  1009. struct snd_soc_codec *codec = rtd->codec;
  1010. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  1011. unsigned long long t0, t1, t_now;
  1012. unsigned int time_delta, uthr;
  1013. int samples_out, samples_in, samples;
  1014. snd_pcm_sframes_t delay = 0;
  1015. switch (dac33->fifo_mode) {
  1016. case DAC33_FIFO_BYPASS:
  1017. break;
  1018. case DAC33_FIFO_MODE1:
  1019. spin_lock(&dac33->lock);
  1020. t0 = dac33->t_stamp1;
  1021. t1 = dac33->t_stamp2;
  1022. spin_unlock(&dac33->lock);
  1023. t_now = ktime_to_us(ktime_get());
  1024. /* We have not started to fill the FIFO yet, delay is 0 */
  1025. if (!t1)
  1026. goto out;
  1027. if (t0 > t1) {
  1028. /*
  1029. * Phase 1:
  1030. * After Alarm threshold, and before nSample write
  1031. */
  1032. time_delta = t_now - t0;
  1033. samples_out = time_delta ? US_TO_SAMPLES(
  1034. substream->runtime->rate,
  1035. time_delta) : 0;
  1036. if (likely(dac33->alarm_threshold > samples_out))
  1037. delay = dac33->alarm_threshold - samples_out;
  1038. else
  1039. delay = 0;
  1040. } else if ((t_now - t1) <= dac33->mode1_us_burst) {
  1041. /*
  1042. * Phase 2:
  1043. * After nSample write (during burst operation)
  1044. */
  1045. time_delta = t_now - t0;
  1046. samples_out = time_delta ? US_TO_SAMPLES(
  1047. substream->runtime->rate,
  1048. time_delta) : 0;
  1049. time_delta = t_now - t1;
  1050. samples_in = time_delta ? US_TO_SAMPLES(
  1051. dac33->burst_rate,
  1052. time_delta) : 0;
  1053. samples = dac33->alarm_threshold;
  1054. samples += (samples_in - samples_out);
  1055. if (likely(samples > 0))
  1056. delay = samples;
  1057. else
  1058. delay = 0;
  1059. } else {
  1060. /*
  1061. * Phase 3:
  1062. * After burst operation, before next alarm threshold
  1063. */
  1064. time_delta = t_now - t0;
  1065. samples_out = time_delta ? US_TO_SAMPLES(
  1066. substream->runtime->rate,
  1067. time_delta) : 0;
  1068. samples_in = dac33->nsample;
  1069. samples = dac33->alarm_threshold;
  1070. samples += (samples_in - samples_out);
  1071. if (likely(samples > 0))
  1072. delay = samples > DAC33_BUFFER_SIZE_SAMPLES ?
  1073. DAC33_BUFFER_SIZE_SAMPLES : samples;
  1074. else
  1075. delay = 0;
  1076. }
  1077. break;
  1078. case DAC33_FIFO_MODE7:
  1079. spin_lock(&dac33->lock);
  1080. t0 = dac33->t_stamp1;
  1081. uthr = dac33->uthr;
  1082. spin_unlock(&dac33->lock);
  1083. t_now = ktime_to_us(ktime_get());
  1084. /* We have not started to fill the FIFO yet, delay is 0 */
  1085. if (!t0)
  1086. goto out;
  1087. if (t_now <= t0) {
  1088. /*
  1089. * Either the timestamps are messed or equal. Report
  1090. * maximum delay
  1091. */
  1092. delay = uthr;
  1093. goto out;
  1094. }
  1095. time_delta = t_now - t0;
  1096. if (time_delta <= dac33->mode7_us_to_lthr) {
  1097. /*
  1098. * Phase 1:
  1099. * After burst (draining phase)
  1100. */
  1101. samples_out = US_TO_SAMPLES(
  1102. substream->runtime->rate,
  1103. time_delta);
  1104. if (likely(uthr > samples_out))
  1105. delay = uthr - samples_out;
  1106. else
  1107. delay = 0;
  1108. } else {
  1109. /*
  1110. * Phase 2:
  1111. * During burst operation
  1112. */
  1113. time_delta = time_delta - dac33->mode7_us_to_lthr;
  1114. samples_out = US_TO_SAMPLES(
  1115. substream->runtime->rate,
  1116. time_delta);
  1117. samples_in = US_TO_SAMPLES(
  1118. dac33->burst_rate,
  1119. time_delta);
  1120. delay = MODE7_LTHR + samples_in - samples_out;
  1121. if (unlikely(delay > uthr))
  1122. delay = uthr;
  1123. }
  1124. break;
  1125. default:
  1126. dev_warn(codec->dev, "Unhandled FIFO mode: %d\n",
  1127. dac33->fifo_mode);
  1128. break;
  1129. }
  1130. out:
  1131. return delay;
  1132. }
  1133. static int dac33_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  1134. int clk_id, unsigned int freq, int dir)
  1135. {
  1136. struct snd_soc_codec *codec = codec_dai->codec;
  1137. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  1138. u8 ioc_reg, asrcb_reg;
  1139. ioc_reg = dac33_read_reg_cache(codec, DAC33_INT_OSC_CTRL);
  1140. asrcb_reg = dac33_read_reg_cache(codec, DAC33_ASRC_CTRL_B);
  1141. switch (clk_id) {
  1142. case TLV320DAC33_MCLK:
  1143. ioc_reg |= DAC33_REFSEL;
  1144. asrcb_reg |= DAC33_SRCREFSEL;
  1145. break;
  1146. case TLV320DAC33_SLEEPCLK:
  1147. ioc_reg &= ~DAC33_REFSEL;
  1148. asrcb_reg &= ~DAC33_SRCREFSEL;
  1149. break;
  1150. default:
  1151. dev_err(codec->dev, "Invalid clock ID (%d)\n", clk_id);
  1152. break;
  1153. }
  1154. dac33->refclk = freq;
  1155. dac33_write_reg_cache(codec, DAC33_INT_OSC_CTRL, ioc_reg);
  1156. dac33_write_reg_cache(codec, DAC33_ASRC_CTRL_B, asrcb_reg);
  1157. return 0;
  1158. }
  1159. static int dac33_set_dai_fmt(struct snd_soc_dai *codec_dai,
  1160. unsigned int fmt)
  1161. {
  1162. struct snd_soc_codec *codec = codec_dai->codec;
  1163. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  1164. u8 aictrl_a, aictrl_b;
  1165. aictrl_a = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_A);
  1166. aictrl_b = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B);
  1167. /* set master/slave audio interface */
  1168. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1169. case SND_SOC_DAIFMT_CBM_CFM:
  1170. /* Codec Master */
  1171. aictrl_a |= (DAC33_MSBCLK | DAC33_MSWCLK);
  1172. break;
  1173. case SND_SOC_DAIFMT_CBS_CFS:
  1174. /* Codec Slave */
  1175. if (dac33->fifo_mode) {
  1176. dev_err(codec->dev, "FIFO mode requires master mode\n");
  1177. return -EINVAL;
  1178. } else
  1179. aictrl_a &= ~(DAC33_MSBCLK | DAC33_MSWCLK);
  1180. break;
  1181. default:
  1182. return -EINVAL;
  1183. }
  1184. aictrl_a &= ~DAC33_AFMT_MASK;
  1185. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1186. case SND_SOC_DAIFMT_I2S:
  1187. aictrl_a |= DAC33_AFMT_I2S;
  1188. break;
  1189. case SND_SOC_DAIFMT_DSP_A:
  1190. aictrl_a |= DAC33_AFMT_DSP;
  1191. aictrl_b &= ~DAC33_DATA_DELAY_MASK;
  1192. aictrl_b |= DAC33_DATA_DELAY(0);
  1193. break;
  1194. case SND_SOC_DAIFMT_RIGHT_J:
  1195. aictrl_a |= DAC33_AFMT_RIGHT_J;
  1196. break;
  1197. case SND_SOC_DAIFMT_LEFT_J:
  1198. aictrl_a |= DAC33_AFMT_LEFT_J;
  1199. break;
  1200. default:
  1201. dev_err(codec->dev, "Unsupported format (%u)\n",
  1202. fmt & SND_SOC_DAIFMT_FORMAT_MASK);
  1203. return -EINVAL;
  1204. }
  1205. dac33_write_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_A, aictrl_a);
  1206. dac33_write_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B, aictrl_b);
  1207. return 0;
  1208. }
  1209. static int dac33_soc_probe(struct snd_soc_codec *codec)
  1210. {
  1211. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  1212. int ret = 0;
  1213. codec->control_data = dac33->control_data;
  1214. codec->hw_write = (hw_write_t) i2c_master_send;
  1215. codec->dapm.idle_bias_off = 1;
  1216. dac33->codec = codec;
  1217. /* Read the tlv320dac33 ID registers */
  1218. ret = dac33_hard_power(codec, 1);
  1219. if (ret != 0) {
  1220. dev_err(codec->dev, "Failed to power up codec: %d\n", ret);
  1221. goto err_power;
  1222. }
  1223. ret = dac33_read_id(codec);
  1224. dac33_hard_power(codec, 0);
  1225. if (ret < 0) {
  1226. dev_err(codec->dev, "Failed to read chip ID: %d\n", ret);
  1227. ret = -ENODEV;
  1228. goto err_power;
  1229. }
  1230. /* Check if the IRQ number is valid and request it */
  1231. if (dac33->irq >= 0) {
  1232. ret = request_irq(dac33->irq, dac33_interrupt_handler,
  1233. IRQF_TRIGGER_RISING | IRQF_DISABLED,
  1234. codec->name, codec);
  1235. if (ret < 0) {
  1236. dev_err(codec->dev, "Could not request IRQ%d (%d)\n",
  1237. dac33->irq, ret);
  1238. dac33->irq = -1;
  1239. }
  1240. if (dac33->irq != -1) {
  1241. /* Setup work queue */
  1242. dac33->dac33_wq =
  1243. create_singlethread_workqueue("tlv320dac33");
  1244. if (dac33->dac33_wq == NULL) {
  1245. free_irq(dac33->irq, codec);
  1246. return -ENOMEM;
  1247. }
  1248. INIT_WORK(&dac33->work, dac33_work);
  1249. }
  1250. }
  1251. snd_soc_add_controls(codec, dac33_snd_controls,
  1252. ARRAY_SIZE(dac33_snd_controls));
  1253. /* Only add the FIFO controls, if we have valid IRQ number */
  1254. if (dac33->irq >= 0) {
  1255. snd_soc_add_controls(codec, dac33_mode_snd_controls,
  1256. ARRAY_SIZE(dac33_mode_snd_controls));
  1257. /* FIFO usage controls only, if autoio config is not selected */
  1258. if (!dac33->auto_fifo_config)
  1259. snd_soc_add_controls(codec, dac33_fifo_snd_controls,
  1260. ARRAY_SIZE(dac33_fifo_snd_controls));
  1261. }
  1262. dac33_add_widgets(codec);
  1263. err_power:
  1264. return ret;
  1265. }
  1266. static int dac33_soc_remove(struct snd_soc_codec *codec)
  1267. {
  1268. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  1269. dac33_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1270. if (dac33->irq >= 0) {
  1271. free_irq(dac33->irq, dac33->codec);
  1272. destroy_workqueue(dac33->dac33_wq);
  1273. }
  1274. return 0;
  1275. }
  1276. static int dac33_soc_suspend(struct snd_soc_codec *codec, pm_message_t state)
  1277. {
  1278. dac33_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1279. return 0;
  1280. }
  1281. static int dac33_soc_resume(struct snd_soc_codec *codec)
  1282. {
  1283. dac33_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1284. return 0;
  1285. }
  1286. static struct snd_soc_codec_driver soc_codec_dev_tlv320dac33 = {
  1287. .read = dac33_read_reg_cache,
  1288. .write = dac33_write_locked,
  1289. .set_bias_level = dac33_set_bias_level,
  1290. .reg_cache_size = ARRAY_SIZE(dac33_reg),
  1291. .reg_word_size = sizeof(u8),
  1292. .reg_cache_default = dac33_reg,
  1293. .probe = dac33_soc_probe,
  1294. .remove = dac33_soc_remove,
  1295. .suspend = dac33_soc_suspend,
  1296. .resume = dac33_soc_resume,
  1297. };
  1298. #define DAC33_RATES (SNDRV_PCM_RATE_44100 | \
  1299. SNDRV_PCM_RATE_48000)
  1300. #define DAC33_FORMATS SNDRV_PCM_FMTBIT_S16_LE
  1301. static struct snd_soc_dai_ops dac33_dai_ops = {
  1302. .startup = dac33_startup,
  1303. .shutdown = dac33_shutdown,
  1304. .hw_params = dac33_hw_params,
  1305. .trigger = dac33_pcm_trigger,
  1306. .delay = dac33_dai_delay,
  1307. .set_sysclk = dac33_set_dai_sysclk,
  1308. .set_fmt = dac33_set_dai_fmt,
  1309. };
  1310. static struct snd_soc_dai_driver dac33_dai = {
  1311. .name = "tlv320dac33-hifi",
  1312. .playback = {
  1313. .stream_name = "Playback",
  1314. .channels_min = 2,
  1315. .channels_max = 2,
  1316. .rates = DAC33_RATES,
  1317. .formats = DAC33_FORMATS,},
  1318. .ops = &dac33_dai_ops,
  1319. };
  1320. static int __devinit dac33_i2c_probe(struct i2c_client *client,
  1321. const struct i2c_device_id *id)
  1322. {
  1323. struct tlv320dac33_platform_data *pdata;
  1324. struct tlv320dac33_priv *dac33;
  1325. int ret, i;
  1326. if (client->dev.platform_data == NULL) {
  1327. dev_err(&client->dev, "Platform data not set\n");
  1328. return -ENODEV;
  1329. }
  1330. pdata = client->dev.platform_data;
  1331. dac33 = kzalloc(sizeof(struct tlv320dac33_priv), GFP_KERNEL);
  1332. if (dac33 == NULL)
  1333. return -ENOMEM;
  1334. dac33->control_data = client;
  1335. mutex_init(&dac33->mutex);
  1336. spin_lock_init(&dac33->lock);
  1337. i2c_set_clientdata(client, dac33);
  1338. dac33->power_gpio = pdata->power_gpio;
  1339. dac33->burst_bclkdiv = pdata->burst_bclkdiv;
  1340. /* Pre calculate the burst rate */
  1341. dac33->burst_rate = BURST_BASEFREQ_HZ / dac33->burst_bclkdiv / 32;
  1342. dac33->keep_bclk = pdata->keep_bclk;
  1343. dac33->auto_fifo_config = pdata->auto_fifo_config;
  1344. dac33->mode1_latency = pdata->mode1_latency;
  1345. if (!dac33->mode1_latency)
  1346. dac33->mode1_latency = 10000; /* 10ms */
  1347. dac33->irq = client->irq;
  1348. dac33->nsample = NSAMPLE_MAX;
  1349. dac33->nsample_max = NSAMPLE_MAX;
  1350. dac33->uthr = MODE7_UTHR;
  1351. /* Disable FIFO use by default */
  1352. dac33->fifo_mode = DAC33_FIFO_BYPASS;
  1353. /* Check if the reset GPIO number is valid and request it */
  1354. if (dac33->power_gpio >= 0) {
  1355. ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset");
  1356. if (ret < 0) {
  1357. dev_err(&client->dev,
  1358. "Failed to request reset GPIO (%d)\n",
  1359. dac33->power_gpio);
  1360. goto err_gpio;
  1361. }
  1362. gpio_direction_output(dac33->power_gpio, 0);
  1363. }
  1364. for (i = 0; i < ARRAY_SIZE(dac33->supplies); i++)
  1365. dac33->supplies[i].supply = dac33_supply_names[i];
  1366. ret = regulator_bulk_get(&client->dev, ARRAY_SIZE(dac33->supplies),
  1367. dac33->supplies);
  1368. if (ret != 0) {
  1369. dev_err(&client->dev, "Failed to request supplies: %d\n", ret);
  1370. goto err_get;
  1371. }
  1372. ret = snd_soc_register_codec(&client->dev,
  1373. &soc_codec_dev_tlv320dac33, &dac33_dai, 1);
  1374. if (ret < 0)
  1375. goto err_register;
  1376. return ret;
  1377. err_register:
  1378. regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies);
  1379. err_get:
  1380. if (dac33->power_gpio >= 0)
  1381. gpio_free(dac33->power_gpio);
  1382. err_gpio:
  1383. kfree(dac33);
  1384. return ret;
  1385. }
  1386. static int __devexit dac33_i2c_remove(struct i2c_client *client)
  1387. {
  1388. struct tlv320dac33_priv *dac33 = i2c_get_clientdata(client);
  1389. if (unlikely(dac33->chip_power))
  1390. dac33_hard_power(dac33->codec, 0);
  1391. if (dac33->power_gpio >= 0)
  1392. gpio_free(dac33->power_gpio);
  1393. regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies);
  1394. snd_soc_unregister_codec(&client->dev);
  1395. kfree(dac33);
  1396. return 0;
  1397. }
  1398. static const struct i2c_device_id tlv320dac33_i2c_id[] = {
  1399. {
  1400. .name = "tlv320dac33",
  1401. .driver_data = 0,
  1402. },
  1403. { },
  1404. };
  1405. static struct i2c_driver tlv320dac33_i2c_driver = {
  1406. .driver = {
  1407. .name = "tlv320dac33-codec",
  1408. .owner = THIS_MODULE,
  1409. },
  1410. .probe = dac33_i2c_probe,
  1411. .remove = __devexit_p(dac33_i2c_remove),
  1412. .id_table = tlv320dac33_i2c_id,
  1413. };
  1414. static int __init dac33_module_init(void)
  1415. {
  1416. int r;
  1417. r = i2c_add_driver(&tlv320dac33_i2c_driver);
  1418. if (r < 0) {
  1419. printk(KERN_ERR "DAC33: driver registration failed\n");
  1420. return r;
  1421. }
  1422. return 0;
  1423. }
  1424. module_init(dac33_module_init);
  1425. static void __exit dac33_module_exit(void)
  1426. {
  1427. i2c_del_driver(&tlv320dac33_i2c_driver);
  1428. }
  1429. module_exit(dac33_module_exit);
  1430. MODULE_DESCRIPTION("ASoC TLV320DAC33 codec driver");
  1431. MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@nokia.com>");
  1432. MODULE_LICENSE("GPL");