tlv320dac33.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703
  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 inline void dac33_disable_digital(struct snd_soc_codec *codec)
  303. {
  304. u8 reg;
  305. /* Stop the DAI clock */
  306. reg = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B);
  307. reg &= ~DAC33_BCLKON;
  308. dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_B, reg);
  309. /* Power down the Oscillator, and DACs */
  310. reg = dac33_read_reg_cache(codec, DAC33_PWR_CTRL);
  311. reg &= ~(DAC33_OSCPDNB | DAC33_DACRPDNB | DAC33_DACLPDNB);
  312. dac33_write(codec, DAC33_PWR_CTRL, reg);
  313. }
  314. static int dac33_hard_power(struct snd_soc_codec *codec, int power)
  315. {
  316. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  317. int ret = 0;
  318. mutex_lock(&dac33->mutex);
  319. /* Safety check */
  320. if (unlikely(power == dac33->chip_power)) {
  321. dev_dbg(codec->dev, "Trying to set the same power state: %s\n",
  322. power ? "ON" : "OFF");
  323. goto exit;
  324. }
  325. if (power) {
  326. ret = regulator_bulk_enable(ARRAY_SIZE(dac33->supplies),
  327. dac33->supplies);
  328. if (ret != 0) {
  329. dev_err(codec->dev,
  330. "Failed to enable supplies: %d\n", ret);
  331. goto exit;
  332. }
  333. if (dac33->power_gpio >= 0)
  334. gpio_set_value(dac33->power_gpio, 1);
  335. dac33->chip_power = 1;
  336. } else {
  337. dac33_soft_power(codec, 0);
  338. if (dac33->power_gpio >= 0)
  339. gpio_set_value(dac33->power_gpio, 0);
  340. ret = regulator_bulk_disable(ARRAY_SIZE(dac33->supplies),
  341. dac33->supplies);
  342. if (ret != 0) {
  343. dev_err(codec->dev,
  344. "Failed to disable supplies: %d\n", ret);
  345. goto exit;
  346. }
  347. dac33->chip_power = 0;
  348. }
  349. exit:
  350. mutex_unlock(&dac33->mutex);
  351. return ret;
  352. }
  353. static int dac33_playback_event(struct snd_soc_dapm_widget *w,
  354. struct snd_kcontrol *kcontrol, int event)
  355. {
  356. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(w->codec);
  357. switch (event) {
  358. case SND_SOC_DAPM_PRE_PMU:
  359. if (likely(dac33->substream)) {
  360. dac33_calculate_times(dac33->substream);
  361. dac33_prepare_chip(dac33->substream);
  362. }
  363. break;
  364. case SND_SOC_DAPM_POST_PMD:
  365. dac33_disable_digital(w->codec);
  366. break;
  367. }
  368. return 0;
  369. }
  370. static int dac33_get_nsample(struct snd_kcontrol *kcontrol,
  371. struct snd_ctl_elem_value *ucontrol)
  372. {
  373. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  374. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  375. ucontrol->value.integer.value[0] = dac33->nsample;
  376. return 0;
  377. }
  378. static int dac33_set_nsample(struct snd_kcontrol *kcontrol,
  379. struct snd_ctl_elem_value *ucontrol)
  380. {
  381. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  382. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  383. int ret = 0;
  384. if (dac33->nsample == ucontrol->value.integer.value[0])
  385. return 0;
  386. if (ucontrol->value.integer.value[0] < dac33->nsample_min ||
  387. ucontrol->value.integer.value[0] > dac33->nsample_max) {
  388. ret = -EINVAL;
  389. } else {
  390. dac33->nsample = ucontrol->value.integer.value[0];
  391. /* Re calculate the burst time */
  392. dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate,
  393. dac33->nsample);
  394. }
  395. return ret;
  396. }
  397. static int dac33_get_uthr(struct snd_kcontrol *kcontrol,
  398. struct snd_ctl_elem_value *ucontrol)
  399. {
  400. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  401. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  402. ucontrol->value.integer.value[0] = dac33->uthr;
  403. return 0;
  404. }
  405. static int dac33_set_uthr(struct snd_kcontrol *kcontrol,
  406. struct snd_ctl_elem_value *ucontrol)
  407. {
  408. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  409. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  410. int ret = 0;
  411. if (dac33->substream)
  412. return -EBUSY;
  413. if (dac33->uthr == ucontrol->value.integer.value[0])
  414. return 0;
  415. if (ucontrol->value.integer.value[0] < (MODE7_LTHR + 10) ||
  416. ucontrol->value.integer.value[0] > MODE7_UTHR)
  417. ret = -EINVAL;
  418. else
  419. dac33->uthr = ucontrol->value.integer.value[0];
  420. return ret;
  421. }
  422. static int dac33_get_fifo_mode(struct snd_kcontrol *kcontrol,
  423. struct snd_ctl_elem_value *ucontrol)
  424. {
  425. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  426. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  427. ucontrol->value.integer.value[0] = dac33->fifo_mode;
  428. return 0;
  429. }
  430. static int dac33_set_fifo_mode(struct snd_kcontrol *kcontrol,
  431. struct snd_ctl_elem_value *ucontrol)
  432. {
  433. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  434. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  435. int ret = 0;
  436. if (dac33->fifo_mode == ucontrol->value.integer.value[0])
  437. return 0;
  438. /* Do not allow changes while stream is running*/
  439. if (codec->active)
  440. return -EPERM;
  441. if (ucontrol->value.integer.value[0] < 0 ||
  442. ucontrol->value.integer.value[0] >= DAC33_FIFO_LAST_MODE)
  443. ret = -EINVAL;
  444. else
  445. dac33->fifo_mode = ucontrol->value.integer.value[0];
  446. return ret;
  447. }
  448. /* Codec operation modes */
  449. static const char *dac33_fifo_mode_texts[] = {
  450. "Bypass", "Mode 1", "Mode 7"
  451. };
  452. static const struct soc_enum dac33_fifo_mode_enum =
  453. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(dac33_fifo_mode_texts),
  454. dac33_fifo_mode_texts);
  455. /* L/R Line Output Gain */
  456. static const char *lr_lineout_gain_texts[] = {
  457. "Line -12dB DAC 0dB", "Line -6dB DAC 6dB",
  458. "Line 0dB DAC 12dB", "Line 6dB DAC 18dB",
  459. };
  460. static const struct soc_enum l_lineout_gain_enum =
  461. SOC_ENUM_SINGLE(DAC33_LDAC_PWR_CTRL, 0,
  462. ARRAY_SIZE(lr_lineout_gain_texts),
  463. lr_lineout_gain_texts);
  464. static const struct soc_enum r_lineout_gain_enum =
  465. SOC_ENUM_SINGLE(DAC33_RDAC_PWR_CTRL, 0,
  466. ARRAY_SIZE(lr_lineout_gain_texts),
  467. lr_lineout_gain_texts);
  468. /*
  469. * DACL/R digital volume control:
  470. * from 0 dB to -63.5 in 0.5 dB steps
  471. * Need to be inverted later on:
  472. * 0x00 == 0 dB
  473. * 0x7f == -63.5 dB
  474. */
  475. static DECLARE_TLV_DB_SCALE(dac_digivol_tlv, -6350, 50, 0);
  476. static const struct snd_kcontrol_new dac33_snd_controls[] = {
  477. SOC_DOUBLE_R_TLV("DAC Digital Playback Volume",
  478. DAC33_LDAC_DIG_VOL_CTRL, DAC33_RDAC_DIG_VOL_CTRL,
  479. 0, 0x7f, 1, dac_digivol_tlv),
  480. SOC_DOUBLE_R("DAC Digital Playback Switch",
  481. DAC33_LDAC_DIG_VOL_CTRL, DAC33_RDAC_DIG_VOL_CTRL, 7, 1, 1),
  482. SOC_DOUBLE_R("Line to Line Out Volume",
  483. DAC33_LINEL_TO_LLO_VOL, DAC33_LINER_TO_RLO_VOL, 0, 127, 1),
  484. SOC_ENUM("Left Line Output Gain", l_lineout_gain_enum),
  485. SOC_ENUM("Right Line Output Gain", r_lineout_gain_enum),
  486. };
  487. static const struct snd_kcontrol_new dac33_mode_snd_controls[] = {
  488. SOC_ENUM_EXT("FIFO Mode", dac33_fifo_mode_enum,
  489. dac33_get_fifo_mode, dac33_set_fifo_mode),
  490. };
  491. static const struct snd_kcontrol_new dac33_fifo_snd_controls[] = {
  492. SOC_SINGLE_EXT("nSample", 0, 0, 5900, 0,
  493. dac33_get_nsample, dac33_set_nsample),
  494. SOC_SINGLE_EXT("UTHR", 0, 0, MODE7_UTHR, 0,
  495. dac33_get_uthr, dac33_set_uthr),
  496. };
  497. /* Analog bypass */
  498. static const struct snd_kcontrol_new dac33_dapm_abypassl_control =
  499. SOC_DAPM_SINGLE("Switch", DAC33_LINEL_TO_LLO_VOL, 7, 1, 1);
  500. static const struct snd_kcontrol_new dac33_dapm_abypassr_control =
  501. SOC_DAPM_SINGLE("Switch", DAC33_LINER_TO_RLO_VOL, 7, 1, 1);
  502. static const struct snd_soc_dapm_widget dac33_dapm_widgets[] = {
  503. SND_SOC_DAPM_OUTPUT("LEFT_LO"),
  504. SND_SOC_DAPM_OUTPUT("RIGHT_LO"),
  505. SND_SOC_DAPM_INPUT("LINEL"),
  506. SND_SOC_DAPM_INPUT("LINER"),
  507. SND_SOC_DAPM_DAC("DACL", "Left Playback", SND_SOC_NOPM, 0, 0),
  508. SND_SOC_DAPM_DAC("DACR", "Right Playback", SND_SOC_NOPM, 0, 0),
  509. /* Analog bypass */
  510. SND_SOC_DAPM_SWITCH("Analog Left Bypass", SND_SOC_NOPM, 0, 0,
  511. &dac33_dapm_abypassl_control),
  512. SND_SOC_DAPM_SWITCH("Analog Right Bypass", SND_SOC_NOPM, 0, 0,
  513. &dac33_dapm_abypassr_control),
  514. SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Left Amplifier",
  515. DAC33_OUT_AMP_PWR_CTRL, 6, 3, 3, 0),
  516. SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Right Amplifier",
  517. DAC33_OUT_AMP_PWR_CTRL, 4, 3, 3, 0),
  518. SND_SOC_DAPM_SUPPLY("Left DAC Power",
  519. DAC33_LDAC_PWR_CTRL, 2, 0, NULL, 0),
  520. SND_SOC_DAPM_SUPPLY("Right DAC Power",
  521. DAC33_RDAC_PWR_CTRL, 2, 0, NULL, 0),
  522. SND_SOC_DAPM_PRE("Pre Playback", dac33_playback_event),
  523. SND_SOC_DAPM_POST("Post Playback", dac33_playback_event),
  524. };
  525. static const struct snd_soc_dapm_route audio_map[] = {
  526. /* Analog bypass */
  527. {"Analog Left Bypass", "Switch", "LINEL"},
  528. {"Analog Right Bypass", "Switch", "LINER"},
  529. {"Output Left Amplifier", NULL, "DACL"},
  530. {"Output Right Amplifier", NULL, "DACR"},
  531. {"Output Left Amplifier", NULL, "Analog Left Bypass"},
  532. {"Output Right Amplifier", NULL, "Analog Right Bypass"},
  533. {"Output Left Amplifier", NULL, "Left DAC Power"},
  534. {"Output Right Amplifier", NULL, "Right DAC Power"},
  535. /* output */
  536. {"LEFT_LO", NULL, "Output Left Amplifier"},
  537. {"RIGHT_LO", NULL, "Output Right Amplifier"},
  538. };
  539. static int dac33_add_widgets(struct snd_soc_codec *codec)
  540. {
  541. struct snd_soc_dapm_context *dapm = &codec->dapm;
  542. snd_soc_dapm_new_controls(dapm, dac33_dapm_widgets,
  543. ARRAY_SIZE(dac33_dapm_widgets));
  544. /* set up audio path interconnects */
  545. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  546. return 0;
  547. }
  548. static int dac33_set_bias_level(struct snd_soc_codec *codec,
  549. enum snd_soc_bias_level level)
  550. {
  551. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  552. int ret;
  553. switch (level) {
  554. case SND_SOC_BIAS_ON:
  555. if (!dac33->substream)
  556. dac33_soft_power(codec, 1);
  557. break;
  558. case SND_SOC_BIAS_PREPARE:
  559. break;
  560. case SND_SOC_BIAS_STANDBY:
  561. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
  562. /* Coming from OFF, switch on the codec */
  563. ret = dac33_hard_power(codec, 1);
  564. if (ret != 0)
  565. return ret;
  566. dac33_init_chip(codec);
  567. }
  568. break;
  569. case SND_SOC_BIAS_OFF:
  570. /* Do not power off, when the codec is already off */
  571. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF)
  572. return 0;
  573. ret = dac33_hard_power(codec, 0);
  574. if (ret != 0)
  575. return ret;
  576. break;
  577. }
  578. codec->dapm.bias_level = level;
  579. return 0;
  580. }
  581. static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33)
  582. {
  583. struct snd_soc_codec *codec = dac33->codec;
  584. unsigned int delay;
  585. switch (dac33->fifo_mode) {
  586. case DAC33_FIFO_MODE1:
  587. dac33_write16(codec, DAC33_NSAMPLE_MSB,
  588. DAC33_THRREG(dac33->nsample));
  589. /* Take the timestamps */
  590. spin_lock_irq(&dac33->lock);
  591. dac33->t_stamp2 = ktime_to_us(ktime_get());
  592. dac33->t_stamp1 = dac33->t_stamp2;
  593. spin_unlock_irq(&dac33->lock);
  594. dac33_write16(codec, DAC33_PREFILL_MSB,
  595. DAC33_THRREG(dac33->alarm_threshold));
  596. /* Enable Alarm Threshold IRQ with a delay */
  597. delay = SAMPLES_TO_US(dac33->burst_rate,
  598. dac33->alarm_threshold) + 1000;
  599. usleep_range(delay, delay + 500);
  600. dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MAT);
  601. break;
  602. case DAC33_FIFO_MODE7:
  603. /* Take the timestamp */
  604. spin_lock_irq(&dac33->lock);
  605. dac33->t_stamp1 = ktime_to_us(ktime_get());
  606. /* Move back the timestamp with drain time */
  607. dac33->t_stamp1 -= dac33->mode7_us_to_lthr;
  608. spin_unlock_irq(&dac33->lock);
  609. dac33_write16(codec, DAC33_PREFILL_MSB,
  610. DAC33_THRREG(MODE7_LTHR));
  611. /* Enable Upper Threshold IRQ */
  612. dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MUT);
  613. break;
  614. default:
  615. dev_warn(codec->dev, "Unhandled FIFO mode: %d\n",
  616. dac33->fifo_mode);
  617. break;
  618. }
  619. }
  620. static inline void dac33_playback_handler(struct tlv320dac33_priv *dac33)
  621. {
  622. struct snd_soc_codec *codec = dac33->codec;
  623. switch (dac33->fifo_mode) {
  624. case DAC33_FIFO_MODE1:
  625. /* Take the timestamp */
  626. spin_lock_irq(&dac33->lock);
  627. dac33->t_stamp2 = ktime_to_us(ktime_get());
  628. spin_unlock_irq(&dac33->lock);
  629. dac33_write16(codec, DAC33_NSAMPLE_MSB,
  630. DAC33_THRREG(dac33->nsample));
  631. break;
  632. case DAC33_FIFO_MODE7:
  633. /* At the moment we are not using interrupts in mode7 */
  634. break;
  635. default:
  636. dev_warn(codec->dev, "Unhandled FIFO mode: %d\n",
  637. dac33->fifo_mode);
  638. break;
  639. }
  640. }
  641. static void dac33_work(struct work_struct *work)
  642. {
  643. struct snd_soc_codec *codec;
  644. struct tlv320dac33_priv *dac33;
  645. u8 reg;
  646. dac33 = container_of(work, struct tlv320dac33_priv, work);
  647. codec = dac33->codec;
  648. mutex_lock(&dac33->mutex);
  649. switch (dac33->state) {
  650. case DAC33_PREFILL:
  651. dac33->state = DAC33_PLAYBACK;
  652. dac33_prefill_handler(dac33);
  653. break;
  654. case DAC33_PLAYBACK:
  655. dac33_playback_handler(dac33);
  656. break;
  657. case DAC33_IDLE:
  658. break;
  659. case DAC33_FLUSH:
  660. dac33->state = DAC33_IDLE;
  661. /* Mask all interrupts from dac33 */
  662. dac33_write(codec, DAC33_FIFO_IRQ_MASK, 0);
  663. /* flush fifo */
  664. reg = dac33_read_reg_cache(codec, DAC33_FIFO_CTRL_A);
  665. reg |= DAC33_FIFOFLUSH;
  666. dac33_write(codec, DAC33_FIFO_CTRL_A, reg);
  667. break;
  668. }
  669. mutex_unlock(&dac33->mutex);
  670. }
  671. static irqreturn_t dac33_interrupt_handler(int irq, void *dev)
  672. {
  673. struct snd_soc_codec *codec = dev;
  674. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  675. spin_lock(&dac33->lock);
  676. dac33->t_stamp1 = ktime_to_us(ktime_get());
  677. spin_unlock(&dac33->lock);
  678. /* Do not schedule the workqueue in Mode7 */
  679. if (dac33->fifo_mode != DAC33_FIFO_MODE7)
  680. queue_work(dac33->dac33_wq, &dac33->work);
  681. return IRQ_HANDLED;
  682. }
  683. static void dac33_oscwait(struct snd_soc_codec *codec)
  684. {
  685. int timeout = 60;
  686. u8 reg;
  687. do {
  688. usleep_range(1000, 2000);
  689. dac33_read(codec, DAC33_INT_OSC_STATUS, &reg);
  690. } while (((reg & 0x03) != DAC33_OSCSTATUS_NORMAL) && timeout--);
  691. if ((reg & 0x03) != DAC33_OSCSTATUS_NORMAL)
  692. dev_err(codec->dev,
  693. "internal oscillator calibration failed\n");
  694. }
  695. static int dac33_startup(struct snd_pcm_substream *substream,
  696. struct snd_soc_dai *dai)
  697. {
  698. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  699. struct snd_soc_codec *codec = rtd->codec;
  700. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  701. /* Stream started, save the substream pointer */
  702. dac33->substream = substream;
  703. return 0;
  704. }
  705. static void dac33_shutdown(struct snd_pcm_substream *substream,
  706. struct snd_soc_dai *dai)
  707. {
  708. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  709. struct snd_soc_codec *codec = rtd->codec;
  710. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  711. dac33->substream = NULL;
  712. /* Reset the nSample restrictions */
  713. dac33->nsample_min = 0;
  714. dac33->nsample_max = NSAMPLE_MAX;
  715. }
  716. static int dac33_hw_params(struct snd_pcm_substream *substream,
  717. struct snd_pcm_hw_params *params,
  718. struct snd_soc_dai *dai)
  719. {
  720. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  721. struct snd_soc_codec *codec = rtd->codec;
  722. /* Check parameters for validity */
  723. switch (params_rate(params)) {
  724. case 44100:
  725. case 48000:
  726. break;
  727. default:
  728. dev_err(codec->dev, "unsupported rate %d\n",
  729. params_rate(params));
  730. return -EINVAL;
  731. }
  732. switch (params_format(params)) {
  733. case SNDRV_PCM_FORMAT_S16_LE:
  734. break;
  735. default:
  736. dev_err(codec->dev, "unsupported format %d\n",
  737. params_format(params));
  738. return -EINVAL;
  739. }
  740. return 0;
  741. }
  742. #define CALC_OSCSET(rate, refclk) ( \
  743. ((((rate * 10000) / refclk) * 4096) + 7000) / 10000)
  744. #define CALC_RATIOSET(rate, refclk) ( \
  745. ((((refclk * 100000) / rate) * 16384) + 50000) / 100000)
  746. /*
  747. * tlv320dac33 is strict on the sequence of the register writes, if the register
  748. * writes happens in different order, than dac33 might end up in unknown state.
  749. * Use the known, working sequence of register writes to initialize the dac33.
  750. */
  751. static int dac33_prepare_chip(struct snd_pcm_substream *substream)
  752. {
  753. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  754. struct snd_soc_codec *codec = rtd->codec;
  755. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  756. unsigned int oscset, ratioset, pwr_ctrl, reg_tmp;
  757. u8 aictrl_a, aictrl_b, fifoctrl_a;
  758. switch (substream->runtime->rate) {
  759. case 44100:
  760. case 48000:
  761. oscset = CALC_OSCSET(substream->runtime->rate, dac33->refclk);
  762. ratioset = CALC_RATIOSET(substream->runtime->rate,
  763. dac33->refclk);
  764. break;
  765. default:
  766. dev_err(codec->dev, "unsupported rate %d\n",
  767. substream->runtime->rate);
  768. return -EINVAL;
  769. }
  770. aictrl_a = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_A);
  771. aictrl_a &= ~(DAC33_NCYCL_MASK | DAC33_WLEN_MASK);
  772. /* Read FIFO control A, and clear FIFO flush bit */
  773. fifoctrl_a = dac33_read_reg_cache(codec, DAC33_FIFO_CTRL_A);
  774. fifoctrl_a &= ~DAC33_FIFOFLUSH;
  775. fifoctrl_a &= ~DAC33_WIDTH;
  776. switch (substream->runtime->format) {
  777. case SNDRV_PCM_FORMAT_S16_LE:
  778. aictrl_a |= (DAC33_NCYCL_16 | DAC33_WLEN_16);
  779. fifoctrl_a |= DAC33_WIDTH;
  780. break;
  781. default:
  782. dev_err(codec->dev, "unsupported format %d\n",
  783. substream->runtime->format);
  784. return -EINVAL;
  785. }
  786. mutex_lock(&dac33->mutex);
  787. if (!dac33->chip_power) {
  788. /*
  789. * Chip is not powered yet.
  790. * Do the init in the dac33_set_bias_level later.
  791. */
  792. mutex_unlock(&dac33->mutex);
  793. return 0;
  794. }
  795. dac33_soft_power(codec, 0);
  796. dac33_soft_power(codec, 1);
  797. reg_tmp = dac33_read_reg_cache(codec, DAC33_INT_OSC_CTRL);
  798. dac33_write(codec, DAC33_INT_OSC_CTRL, reg_tmp);
  799. /* Write registers 0x08 and 0x09 (MSB, LSB) */
  800. dac33_write16(codec, DAC33_INT_OSC_FREQ_RAT_A, oscset);
  801. /* calib time: 128 is a nice number ;) */
  802. dac33_write(codec, DAC33_CALIB_TIME, 128);
  803. /* adjustment treshold & step */
  804. dac33_write(codec, DAC33_INT_OSC_CTRL_B, DAC33_ADJTHRSHLD(2) |
  805. DAC33_ADJSTEP(1));
  806. /* div=4 / gain=1 / div */
  807. dac33_write(codec, DAC33_INT_OSC_CTRL_C, DAC33_REFDIV(4));
  808. pwr_ctrl = dac33_read_reg_cache(codec, DAC33_PWR_CTRL);
  809. pwr_ctrl |= DAC33_OSCPDNB | DAC33_DACRPDNB | DAC33_DACLPDNB;
  810. dac33_write(codec, DAC33_PWR_CTRL, pwr_ctrl);
  811. dac33_oscwait(codec);
  812. if (dac33->fifo_mode) {
  813. /* Generic for all FIFO modes */
  814. /* 50-51 : ASRC Control registers */
  815. dac33_write(codec, DAC33_ASRC_CTRL_A, DAC33_SRCLKDIV(1));
  816. dac33_write(codec, DAC33_ASRC_CTRL_B, 1); /* ??? */
  817. /* Write registers 0x34 and 0x35 (MSB, LSB) */
  818. dac33_write16(codec, DAC33_SRC_REF_CLK_RATIO_A, ratioset);
  819. /* Set interrupts to high active */
  820. dac33_write(codec, DAC33_INTP_CTRL_A, DAC33_INTPM_AHIGH);
  821. } else {
  822. /* FIFO bypass mode */
  823. /* 50-51 : ASRC Control registers */
  824. dac33_write(codec, DAC33_ASRC_CTRL_A, DAC33_SRCBYP);
  825. dac33_write(codec, DAC33_ASRC_CTRL_B, 0); /* ??? */
  826. }
  827. /* Interrupt behaviour configuration */
  828. switch (dac33->fifo_mode) {
  829. case DAC33_FIFO_MODE1:
  830. dac33_write(codec, DAC33_FIFO_IRQ_MODE_B,
  831. DAC33_ATM(DAC33_FIFO_IRQ_MODE_LEVEL));
  832. break;
  833. case DAC33_FIFO_MODE7:
  834. dac33_write(codec, DAC33_FIFO_IRQ_MODE_A,
  835. DAC33_UTM(DAC33_FIFO_IRQ_MODE_LEVEL));
  836. break;
  837. default:
  838. /* in FIFO bypass mode, the interrupts are not used */
  839. break;
  840. }
  841. aictrl_b = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B);
  842. switch (dac33->fifo_mode) {
  843. case DAC33_FIFO_MODE1:
  844. /*
  845. * For mode1:
  846. * Disable the FIFO bypass (Enable the use of FIFO)
  847. * Select nSample mode
  848. * BCLK is only running when data is needed by DAC33
  849. */
  850. fifoctrl_a &= ~DAC33_FBYPAS;
  851. fifoctrl_a &= ~DAC33_FAUTO;
  852. if (dac33->keep_bclk)
  853. aictrl_b |= DAC33_BCLKON;
  854. else
  855. aictrl_b &= ~DAC33_BCLKON;
  856. break;
  857. case DAC33_FIFO_MODE7:
  858. /*
  859. * For mode1:
  860. * Disable the FIFO bypass (Enable the use of FIFO)
  861. * Select Threshold mode
  862. * BCLK is only running when data is needed by DAC33
  863. */
  864. fifoctrl_a &= ~DAC33_FBYPAS;
  865. fifoctrl_a |= DAC33_FAUTO;
  866. if (dac33->keep_bclk)
  867. aictrl_b |= DAC33_BCLKON;
  868. else
  869. aictrl_b &= ~DAC33_BCLKON;
  870. break;
  871. default:
  872. /*
  873. * For FIFO bypass mode:
  874. * Enable the FIFO bypass (Disable the FIFO use)
  875. * Set the BCLK as continous
  876. */
  877. fifoctrl_a |= DAC33_FBYPAS;
  878. aictrl_b |= DAC33_BCLKON;
  879. break;
  880. }
  881. dac33_write(codec, DAC33_FIFO_CTRL_A, fifoctrl_a);
  882. dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_A, aictrl_a);
  883. dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_B, aictrl_b);
  884. /*
  885. * BCLK divide ratio
  886. * 0: 1.5
  887. * 1: 1
  888. * 2: 2
  889. * ...
  890. * 254: 254
  891. * 255: 255
  892. */
  893. if (dac33->fifo_mode)
  894. dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C,
  895. dac33->burst_bclkdiv);
  896. else
  897. dac33_write(codec, DAC33_SER_AUDIOIF_CTRL_C, 32);
  898. switch (dac33->fifo_mode) {
  899. case DAC33_FIFO_MODE1:
  900. dac33_write16(codec, DAC33_ATHR_MSB,
  901. DAC33_THRREG(dac33->alarm_threshold));
  902. break;
  903. case DAC33_FIFO_MODE7:
  904. /*
  905. * Configure the threshold levels, and leave 10 sample space
  906. * at the bottom, and also at the top of the FIFO
  907. */
  908. dac33_write16(codec, DAC33_UTHR_MSB, DAC33_THRREG(dac33->uthr));
  909. dac33_write16(codec, DAC33_LTHR_MSB, DAC33_THRREG(MODE7_LTHR));
  910. break;
  911. default:
  912. break;
  913. }
  914. mutex_unlock(&dac33->mutex);
  915. return 0;
  916. }
  917. static void dac33_calculate_times(struct snd_pcm_substream *substream)
  918. {
  919. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  920. struct snd_soc_codec *codec = rtd->codec;
  921. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  922. unsigned int period_size = substream->runtime->period_size;
  923. unsigned int rate = substream->runtime->rate;
  924. unsigned int nsample_limit;
  925. /* In bypass mode we don't need to calculate */
  926. if (!dac33->fifo_mode)
  927. return;
  928. switch (dac33->fifo_mode) {
  929. case DAC33_FIFO_MODE1:
  930. /* Number of samples under i2c latency */
  931. dac33->alarm_threshold = US_TO_SAMPLES(rate,
  932. dac33->mode1_latency);
  933. nsample_limit = DAC33_BUFFER_SIZE_SAMPLES -
  934. dac33->alarm_threshold;
  935. if (dac33->auto_fifo_config) {
  936. if (period_size <= dac33->alarm_threshold)
  937. /*
  938. * Configure nSamaple to number of periods,
  939. * which covers the latency requironment.
  940. */
  941. dac33->nsample = period_size *
  942. ((dac33->alarm_threshold / period_size) +
  943. (dac33->alarm_threshold % period_size ?
  944. 1 : 0));
  945. else if (period_size > nsample_limit)
  946. dac33->nsample = nsample_limit;
  947. else
  948. dac33->nsample = period_size;
  949. } else {
  950. /* nSample time shall not be shorter than i2c latency */
  951. dac33->nsample_min = dac33->alarm_threshold;
  952. /*
  953. * nSample should not be bigger than alsa buffer minus
  954. * size of one period to avoid overruns
  955. */
  956. dac33->nsample_max = substream->runtime->buffer_size -
  957. period_size;
  958. if (dac33->nsample_max > nsample_limit)
  959. dac33->nsample_max = nsample_limit;
  960. /* Correct the nSample if it is outside of the ranges */
  961. if (dac33->nsample < dac33->nsample_min)
  962. dac33->nsample = dac33->nsample_min;
  963. if (dac33->nsample > dac33->nsample_max)
  964. dac33->nsample = dac33->nsample_max;
  965. }
  966. dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate,
  967. dac33->nsample);
  968. dac33->t_stamp1 = 0;
  969. dac33->t_stamp2 = 0;
  970. break;
  971. case DAC33_FIFO_MODE7:
  972. if (dac33->auto_fifo_config) {
  973. dac33->uthr = UTHR_FROM_PERIOD_SIZE(
  974. period_size,
  975. rate,
  976. dac33->burst_rate) + 9;
  977. if (dac33->uthr > MODE7_UTHR)
  978. dac33->uthr = MODE7_UTHR;
  979. if (dac33->uthr < (MODE7_LTHR + 10))
  980. dac33->uthr = (MODE7_LTHR + 10);
  981. }
  982. dac33->mode7_us_to_lthr =
  983. SAMPLES_TO_US(substream->runtime->rate,
  984. dac33->uthr - MODE7_LTHR + 1);
  985. dac33->t_stamp1 = 0;
  986. break;
  987. default:
  988. break;
  989. }
  990. }
  991. static int dac33_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
  992. struct snd_soc_dai *dai)
  993. {
  994. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  995. struct snd_soc_codec *codec = rtd->codec;
  996. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  997. int ret = 0;
  998. switch (cmd) {
  999. case SNDRV_PCM_TRIGGER_START:
  1000. case SNDRV_PCM_TRIGGER_RESUME:
  1001. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  1002. if (dac33->fifo_mode) {
  1003. dac33->state = DAC33_PREFILL;
  1004. queue_work(dac33->dac33_wq, &dac33->work);
  1005. }
  1006. break;
  1007. case SNDRV_PCM_TRIGGER_STOP:
  1008. case SNDRV_PCM_TRIGGER_SUSPEND:
  1009. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  1010. if (dac33->fifo_mode) {
  1011. dac33->state = DAC33_FLUSH;
  1012. queue_work(dac33->dac33_wq, &dac33->work);
  1013. }
  1014. break;
  1015. default:
  1016. ret = -EINVAL;
  1017. }
  1018. return ret;
  1019. }
  1020. static snd_pcm_sframes_t dac33_dai_delay(
  1021. struct snd_pcm_substream *substream,
  1022. struct snd_soc_dai *dai)
  1023. {
  1024. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  1025. struct snd_soc_codec *codec = rtd->codec;
  1026. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  1027. unsigned long long t0, t1, t_now;
  1028. unsigned int time_delta, uthr;
  1029. int samples_out, samples_in, samples;
  1030. snd_pcm_sframes_t delay = 0;
  1031. switch (dac33->fifo_mode) {
  1032. case DAC33_FIFO_BYPASS:
  1033. break;
  1034. case DAC33_FIFO_MODE1:
  1035. spin_lock(&dac33->lock);
  1036. t0 = dac33->t_stamp1;
  1037. t1 = dac33->t_stamp2;
  1038. spin_unlock(&dac33->lock);
  1039. t_now = ktime_to_us(ktime_get());
  1040. /* We have not started to fill the FIFO yet, delay is 0 */
  1041. if (!t1)
  1042. goto out;
  1043. if (t0 > t1) {
  1044. /*
  1045. * Phase 1:
  1046. * After Alarm threshold, and before nSample write
  1047. */
  1048. time_delta = t_now - t0;
  1049. samples_out = time_delta ? US_TO_SAMPLES(
  1050. substream->runtime->rate,
  1051. time_delta) : 0;
  1052. if (likely(dac33->alarm_threshold > samples_out))
  1053. delay = dac33->alarm_threshold - samples_out;
  1054. else
  1055. delay = 0;
  1056. } else if ((t_now - t1) <= dac33->mode1_us_burst) {
  1057. /*
  1058. * Phase 2:
  1059. * After nSample write (during burst operation)
  1060. */
  1061. time_delta = t_now - t0;
  1062. samples_out = time_delta ? US_TO_SAMPLES(
  1063. substream->runtime->rate,
  1064. time_delta) : 0;
  1065. time_delta = t_now - t1;
  1066. samples_in = time_delta ? US_TO_SAMPLES(
  1067. dac33->burst_rate,
  1068. time_delta) : 0;
  1069. samples = dac33->alarm_threshold;
  1070. samples += (samples_in - samples_out);
  1071. if (likely(samples > 0))
  1072. delay = samples;
  1073. else
  1074. delay = 0;
  1075. } else {
  1076. /*
  1077. * Phase 3:
  1078. * After burst operation, before next alarm threshold
  1079. */
  1080. time_delta = t_now - t0;
  1081. samples_out = time_delta ? US_TO_SAMPLES(
  1082. substream->runtime->rate,
  1083. time_delta) : 0;
  1084. samples_in = dac33->nsample;
  1085. samples = dac33->alarm_threshold;
  1086. samples += (samples_in - samples_out);
  1087. if (likely(samples > 0))
  1088. delay = samples > DAC33_BUFFER_SIZE_SAMPLES ?
  1089. DAC33_BUFFER_SIZE_SAMPLES : samples;
  1090. else
  1091. delay = 0;
  1092. }
  1093. break;
  1094. case DAC33_FIFO_MODE7:
  1095. spin_lock(&dac33->lock);
  1096. t0 = dac33->t_stamp1;
  1097. uthr = dac33->uthr;
  1098. spin_unlock(&dac33->lock);
  1099. t_now = ktime_to_us(ktime_get());
  1100. /* We have not started to fill the FIFO yet, delay is 0 */
  1101. if (!t0)
  1102. goto out;
  1103. if (t_now <= t0) {
  1104. /*
  1105. * Either the timestamps are messed or equal. Report
  1106. * maximum delay
  1107. */
  1108. delay = uthr;
  1109. goto out;
  1110. }
  1111. time_delta = t_now - t0;
  1112. if (time_delta <= dac33->mode7_us_to_lthr) {
  1113. /*
  1114. * Phase 1:
  1115. * After burst (draining phase)
  1116. */
  1117. samples_out = US_TO_SAMPLES(
  1118. substream->runtime->rate,
  1119. time_delta);
  1120. if (likely(uthr > samples_out))
  1121. delay = uthr - samples_out;
  1122. else
  1123. delay = 0;
  1124. } else {
  1125. /*
  1126. * Phase 2:
  1127. * During burst operation
  1128. */
  1129. time_delta = time_delta - dac33->mode7_us_to_lthr;
  1130. samples_out = US_TO_SAMPLES(
  1131. substream->runtime->rate,
  1132. time_delta);
  1133. samples_in = US_TO_SAMPLES(
  1134. dac33->burst_rate,
  1135. time_delta);
  1136. delay = MODE7_LTHR + samples_in - samples_out;
  1137. if (unlikely(delay > uthr))
  1138. delay = uthr;
  1139. }
  1140. break;
  1141. default:
  1142. dev_warn(codec->dev, "Unhandled FIFO mode: %d\n",
  1143. dac33->fifo_mode);
  1144. break;
  1145. }
  1146. out:
  1147. return delay;
  1148. }
  1149. static int dac33_set_dai_sysclk(struct snd_soc_dai *codec_dai,
  1150. int clk_id, unsigned int freq, int dir)
  1151. {
  1152. struct snd_soc_codec *codec = codec_dai->codec;
  1153. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  1154. u8 ioc_reg, asrcb_reg;
  1155. ioc_reg = dac33_read_reg_cache(codec, DAC33_INT_OSC_CTRL);
  1156. asrcb_reg = dac33_read_reg_cache(codec, DAC33_ASRC_CTRL_B);
  1157. switch (clk_id) {
  1158. case TLV320DAC33_MCLK:
  1159. ioc_reg |= DAC33_REFSEL;
  1160. asrcb_reg |= DAC33_SRCREFSEL;
  1161. break;
  1162. case TLV320DAC33_SLEEPCLK:
  1163. ioc_reg &= ~DAC33_REFSEL;
  1164. asrcb_reg &= ~DAC33_SRCREFSEL;
  1165. break;
  1166. default:
  1167. dev_err(codec->dev, "Invalid clock ID (%d)\n", clk_id);
  1168. break;
  1169. }
  1170. dac33->refclk = freq;
  1171. dac33_write_reg_cache(codec, DAC33_INT_OSC_CTRL, ioc_reg);
  1172. dac33_write_reg_cache(codec, DAC33_ASRC_CTRL_B, asrcb_reg);
  1173. return 0;
  1174. }
  1175. static int dac33_set_dai_fmt(struct snd_soc_dai *codec_dai,
  1176. unsigned int fmt)
  1177. {
  1178. struct snd_soc_codec *codec = codec_dai->codec;
  1179. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  1180. u8 aictrl_a, aictrl_b;
  1181. aictrl_a = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_A);
  1182. aictrl_b = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B);
  1183. /* set master/slave audio interface */
  1184. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  1185. case SND_SOC_DAIFMT_CBM_CFM:
  1186. /* Codec Master */
  1187. aictrl_a |= (DAC33_MSBCLK | DAC33_MSWCLK);
  1188. break;
  1189. case SND_SOC_DAIFMT_CBS_CFS:
  1190. /* Codec Slave */
  1191. if (dac33->fifo_mode) {
  1192. dev_err(codec->dev, "FIFO mode requires master mode\n");
  1193. return -EINVAL;
  1194. } else
  1195. aictrl_a &= ~(DAC33_MSBCLK | DAC33_MSWCLK);
  1196. break;
  1197. default:
  1198. return -EINVAL;
  1199. }
  1200. aictrl_a &= ~DAC33_AFMT_MASK;
  1201. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  1202. case SND_SOC_DAIFMT_I2S:
  1203. aictrl_a |= DAC33_AFMT_I2S;
  1204. break;
  1205. case SND_SOC_DAIFMT_DSP_A:
  1206. aictrl_a |= DAC33_AFMT_DSP;
  1207. aictrl_b &= ~DAC33_DATA_DELAY_MASK;
  1208. aictrl_b |= DAC33_DATA_DELAY(0);
  1209. break;
  1210. case SND_SOC_DAIFMT_RIGHT_J:
  1211. aictrl_a |= DAC33_AFMT_RIGHT_J;
  1212. break;
  1213. case SND_SOC_DAIFMT_LEFT_J:
  1214. aictrl_a |= DAC33_AFMT_LEFT_J;
  1215. break;
  1216. default:
  1217. dev_err(codec->dev, "Unsupported format (%u)\n",
  1218. fmt & SND_SOC_DAIFMT_FORMAT_MASK);
  1219. return -EINVAL;
  1220. }
  1221. dac33_write_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_A, aictrl_a);
  1222. dac33_write_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_B, aictrl_b);
  1223. return 0;
  1224. }
  1225. static int dac33_soc_probe(struct snd_soc_codec *codec)
  1226. {
  1227. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  1228. int ret = 0;
  1229. codec->control_data = dac33->control_data;
  1230. codec->hw_write = (hw_write_t) i2c_master_send;
  1231. codec->dapm.idle_bias_off = 1;
  1232. dac33->codec = codec;
  1233. /* Read the tlv320dac33 ID registers */
  1234. ret = dac33_hard_power(codec, 1);
  1235. if (ret != 0) {
  1236. dev_err(codec->dev, "Failed to power up codec: %d\n", ret);
  1237. goto err_power;
  1238. }
  1239. ret = dac33_read_id(codec);
  1240. dac33_hard_power(codec, 0);
  1241. if (ret < 0) {
  1242. dev_err(codec->dev, "Failed to read chip ID: %d\n", ret);
  1243. ret = -ENODEV;
  1244. goto err_power;
  1245. }
  1246. /* Check if the IRQ number is valid and request it */
  1247. if (dac33->irq >= 0) {
  1248. ret = request_irq(dac33->irq, dac33_interrupt_handler,
  1249. IRQF_TRIGGER_RISING | IRQF_DISABLED,
  1250. codec->name, codec);
  1251. if (ret < 0) {
  1252. dev_err(codec->dev, "Could not request IRQ%d (%d)\n",
  1253. dac33->irq, ret);
  1254. dac33->irq = -1;
  1255. }
  1256. if (dac33->irq != -1) {
  1257. /* Setup work queue */
  1258. dac33->dac33_wq =
  1259. create_singlethread_workqueue("tlv320dac33");
  1260. if (dac33->dac33_wq == NULL) {
  1261. free_irq(dac33->irq, codec);
  1262. return -ENOMEM;
  1263. }
  1264. INIT_WORK(&dac33->work, dac33_work);
  1265. }
  1266. }
  1267. snd_soc_add_controls(codec, dac33_snd_controls,
  1268. ARRAY_SIZE(dac33_snd_controls));
  1269. /* Only add the FIFO controls, if we have valid IRQ number */
  1270. if (dac33->irq >= 0) {
  1271. snd_soc_add_controls(codec, dac33_mode_snd_controls,
  1272. ARRAY_SIZE(dac33_mode_snd_controls));
  1273. /* FIFO usage controls only, if autoio config is not selected */
  1274. if (!dac33->auto_fifo_config)
  1275. snd_soc_add_controls(codec, dac33_fifo_snd_controls,
  1276. ARRAY_SIZE(dac33_fifo_snd_controls));
  1277. }
  1278. dac33_add_widgets(codec);
  1279. err_power:
  1280. return ret;
  1281. }
  1282. static int dac33_soc_remove(struct snd_soc_codec *codec)
  1283. {
  1284. struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
  1285. dac33_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1286. if (dac33->irq >= 0) {
  1287. free_irq(dac33->irq, dac33->codec);
  1288. destroy_workqueue(dac33->dac33_wq);
  1289. }
  1290. return 0;
  1291. }
  1292. static int dac33_soc_suspend(struct snd_soc_codec *codec, pm_message_t state)
  1293. {
  1294. dac33_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1295. return 0;
  1296. }
  1297. static int dac33_soc_resume(struct snd_soc_codec *codec)
  1298. {
  1299. dac33_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1300. return 0;
  1301. }
  1302. static struct snd_soc_codec_driver soc_codec_dev_tlv320dac33 = {
  1303. .read = dac33_read_reg_cache,
  1304. .write = dac33_write_locked,
  1305. .set_bias_level = dac33_set_bias_level,
  1306. .reg_cache_size = ARRAY_SIZE(dac33_reg),
  1307. .reg_word_size = sizeof(u8),
  1308. .reg_cache_default = dac33_reg,
  1309. .probe = dac33_soc_probe,
  1310. .remove = dac33_soc_remove,
  1311. .suspend = dac33_soc_suspend,
  1312. .resume = dac33_soc_resume,
  1313. };
  1314. #define DAC33_RATES (SNDRV_PCM_RATE_44100 | \
  1315. SNDRV_PCM_RATE_48000)
  1316. #define DAC33_FORMATS SNDRV_PCM_FMTBIT_S16_LE
  1317. static struct snd_soc_dai_ops dac33_dai_ops = {
  1318. .startup = dac33_startup,
  1319. .shutdown = dac33_shutdown,
  1320. .hw_params = dac33_hw_params,
  1321. .trigger = dac33_pcm_trigger,
  1322. .delay = dac33_dai_delay,
  1323. .set_sysclk = dac33_set_dai_sysclk,
  1324. .set_fmt = dac33_set_dai_fmt,
  1325. };
  1326. static struct snd_soc_dai_driver dac33_dai = {
  1327. .name = "tlv320dac33-hifi",
  1328. .playback = {
  1329. .stream_name = "Playback",
  1330. .channels_min = 2,
  1331. .channels_max = 2,
  1332. .rates = DAC33_RATES,
  1333. .formats = DAC33_FORMATS,},
  1334. .ops = &dac33_dai_ops,
  1335. };
  1336. static int __devinit dac33_i2c_probe(struct i2c_client *client,
  1337. const struct i2c_device_id *id)
  1338. {
  1339. struct tlv320dac33_platform_data *pdata;
  1340. struct tlv320dac33_priv *dac33;
  1341. int ret, i;
  1342. if (client->dev.platform_data == NULL) {
  1343. dev_err(&client->dev, "Platform data not set\n");
  1344. return -ENODEV;
  1345. }
  1346. pdata = client->dev.platform_data;
  1347. dac33 = kzalloc(sizeof(struct tlv320dac33_priv), GFP_KERNEL);
  1348. if (dac33 == NULL)
  1349. return -ENOMEM;
  1350. dac33->control_data = client;
  1351. mutex_init(&dac33->mutex);
  1352. spin_lock_init(&dac33->lock);
  1353. i2c_set_clientdata(client, dac33);
  1354. dac33->power_gpio = pdata->power_gpio;
  1355. dac33->burst_bclkdiv = pdata->burst_bclkdiv;
  1356. /* Pre calculate the burst rate */
  1357. dac33->burst_rate = BURST_BASEFREQ_HZ / dac33->burst_bclkdiv / 32;
  1358. dac33->keep_bclk = pdata->keep_bclk;
  1359. dac33->auto_fifo_config = pdata->auto_fifo_config;
  1360. dac33->mode1_latency = pdata->mode1_latency;
  1361. if (!dac33->mode1_latency)
  1362. dac33->mode1_latency = 10000; /* 10ms */
  1363. dac33->irq = client->irq;
  1364. dac33->nsample = NSAMPLE_MAX;
  1365. dac33->nsample_max = NSAMPLE_MAX;
  1366. dac33->uthr = MODE7_UTHR;
  1367. /* Disable FIFO use by default */
  1368. dac33->fifo_mode = DAC33_FIFO_BYPASS;
  1369. /* Check if the reset GPIO number is valid and request it */
  1370. if (dac33->power_gpio >= 0) {
  1371. ret = gpio_request(dac33->power_gpio, "tlv320dac33 reset");
  1372. if (ret < 0) {
  1373. dev_err(&client->dev,
  1374. "Failed to request reset GPIO (%d)\n",
  1375. dac33->power_gpio);
  1376. goto err_gpio;
  1377. }
  1378. gpio_direction_output(dac33->power_gpio, 0);
  1379. }
  1380. for (i = 0; i < ARRAY_SIZE(dac33->supplies); i++)
  1381. dac33->supplies[i].supply = dac33_supply_names[i];
  1382. ret = regulator_bulk_get(&client->dev, ARRAY_SIZE(dac33->supplies),
  1383. dac33->supplies);
  1384. if (ret != 0) {
  1385. dev_err(&client->dev, "Failed to request supplies: %d\n", ret);
  1386. goto err_get;
  1387. }
  1388. ret = snd_soc_register_codec(&client->dev,
  1389. &soc_codec_dev_tlv320dac33, &dac33_dai, 1);
  1390. if (ret < 0)
  1391. goto err_register;
  1392. return ret;
  1393. err_register:
  1394. regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies);
  1395. err_get:
  1396. if (dac33->power_gpio >= 0)
  1397. gpio_free(dac33->power_gpio);
  1398. err_gpio:
  1399. kfree(dac33);
  1400. return ret;
  1401. }
  1402. static int __devexit dac33_i2c_remove(struct i2c_client *client)
  1403. {
  1404. struct tlv320dac33_priv *dac33 = i2c_get_clientdata(client);
  1405. if (unlikely(dac33->chip_power))
  1406. dac33_hard_power(dac33->codec, 0);
  1407. if (dac33->power_gpio >= 0)
  1408. gpio_free(dac33->power_gpio);
  1409. regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies);
  1410. snd_soc_unregister_codec(&client->dev);
  1411. kfree(dac33);
  1412. return 0;
  1413. }
  1414. static const struct i2c_device_id tlv320dac33_i2c_id[] = {
  1415. {
  1416. .name = "tlv320dac33",
  1417. .driver_data = 0,
  1418. },
  1419. { },
  1420. };
  1421. static struct i2c_driver tlv320dac33_i2c_driver = {
  1422. .driver = {
  1423. .name = "tlv320dac33-codec",
  1424. .owner = THIS_MODULE,
  1425. },
  1426. .probe = dac33_i2c_probe,
  1427. .remove = __devexit_p(dac33_i2c_remove),
  1428. .id_table = tlv320dac33_i2c_id,
  1429. };
  1430. static int __init dac33_module_init(void)
  1431. {
  1432. int r;
  1433. r = i2c_add_driver(&tlv320dac33_i2c_driver);
  1434. if (r < 0) {
  1435. printk(KERN_ERR "DAC33: driver registration failed\n");
  1436. return r;
  1437. }
  1438. return 0;
  1439. }
  1440. module_init(dac33_module_init);
  1441. static void __exit dac33_module_exit(void)
  1442. {
  1443. i2c_del_driver(&tlv320dac33_i2c_driver);
  1444. }
  1445. module_exit(dac33_module_exit);
  1446. MODULE_DESCRIPTION("ASoC TLV320DAC33 codec driver");
  1447. MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@nokia.com>");
  1448. MODULE_LICENSE("GPL");