BD37033.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318
  1. #include <linux/kernel.h>
  2. #include <linux/module.h>
  3. #include <linux/mm.h>
  4. #include <linux/slab.h>
  5. #include <linux/fs.h>
  6. #include <linux/i2c.h>
  7. #include <linux/errno.h>
  8. #include <asm/uaccess.h>
  9. #include <linux/list.h>
  10. #include <linux/sched.h>
  11. #include <linux/interrupt.h>
  12. //#include <mach/va_map.h>
  13. //#include <mach/irqs.h>
  14. #include <linux/delay.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/cdev.h>
  17. #include <linux/gpio.h>
  18. #include <asm/setup.h>
  19. #include <asm/io.h>
  20. #include <sound/core.h>
  21. #include <sound/pcm.h>
  22. #include <sound/soc.h>
  23. #include <sound/soc-dapm.h>
  24. #include <linux/pwm.h>
  25. #include <linux/err.h>
  26. //#include <mach/hardware.h>
  27. //#include <linux/ark/sddac.h>
  28. #include <linux/init.h>
  29. #include <linux/moduleparam.h>
  30. #include <linux/string.h>
  31. #include "BD37033.h"
  32. static struct bd37033_data *my_bd;
  33. static SELECT_DARA select_data;
  34. static int mute_status = MUTE_OFF;
  35. static struct bd37033_module_param mp = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
  36. static int bd37033_set_stream(unsigned char input_ch);
  37. static int bd37033_set_volume(unsigned char volume);
  38. static int bd37033_set_fader(unsigned char reg_addr, unsigned char value);
  39. static int set_tone_gain(unsigned char reg_addr, unsigned char value);
  40. static int bd37033_set_mute(struct bd37033_data *bd, int state);
  41. static void bd37033_init(struct bd37033_data *bd);
  42. module_param_named(mute_state, mp.mute, int, 0644);
  43. module_param_named(input_channel, mp.input_channel, int, 0644);
  44. module_param_named(volume_gain, mp.volume, int, 0644);
  45. module_param_named(input_gain, mp.input_gain, int, 0644);
  46. module_param_named(fl_gain, mp.fl_gain, int, 0644);
  47. module_param_named(fr_gain, mp.fr_gain, int, 0644);
  48. module_param_named(rl_gain, mp.rl_gain, int, 0644);
  49. module_param_named(rr_gain, mp.rr_gain, int, 0644);
  50. module_param_named(bass_gain, mp.bass_gain, int, 0644);
  51. module_param_named(middle_gain, mp.middle_gain, int, 0644);
  52. module_param_named(treble_gain, mp.treble_gain, int, 0644);
  53. static int bd37033_write_bytes(struct i2c_client *client,
  54. unsigned char subaddr,
  55. unsigned char regaddr,
  56. unsigned char* regval,
  57. int len)
  58. {
  59. struct i2c_msg msg;
  60. s32 ret = -1;
  61. s32 retries = 0;
  62. u8 buf[255] = {0};
  63. #ifdef CONFIG_SND_SOC_BD37033_NOP
  64. return 0;
  65. #endif
  66. buf[0] = regaddr;
  67. memcpy(&buf[1],regval,len);
  68. //printk(KERN_DEBUG "regaddr:0x%x regval: 0x%x.\n",regaddr,regval);
  69. msg.flags = 0;
  70. msg.addr = subaddr;
  71. msg.len = len+1;
  72. msg.buf = buf;
  73. while(retries < 5)
  74. {
  75. ret = i2c_transfer(client->adapter, &msg, 1);
  76. //printk(KERN_ERR "%s ret = %d\n",__FUNCTION__,ret);
  77. if(ret == 1)
  78. break;
  79. retries++;
  80. }
  81. if((retries >= 5))
  82. {
  83. printk(KERN_ERR "err %s.\n",__FUNCTION__);
  84. }
  85. return ret;
  86. }
  87. static int bd37033_write_byte(struct i2c_client *client,
  88. unsigned char subaddr,
  89. unsigned char regaddr,
  90. unsigned char regval)
  91. {
  92. struct i2c_msg msg;
  93. s32 ret = -1;
  94. s32 retries = 0;
  95. u8 buf[2] = {0};
  96. #ifdef CONFIG_SND_SOC_BD37033_NOP
  97. return 0;
  98. #endif
  99. buf[0] = regaddr;
  100. buf[1] = regval;
  101. //printk(KERN_DEBUG "regaddr:0x%x regval: 0x%x.\n",regaddr,regval);
  102. msg.flags = 0;
  103. msg.addr = subaddr;
  104. msg.len = 2;
  105. msg.buf = buf;
  106. while(retries < 5)
  107. {
  108. ret = i2c_transfer(client->adapter, &msg, 1);
  109. //printk(KERN_ERR "%s ret = %d\n",__FUNCTION__,ret);
  110. if(ret == 1)
  111. break;
  112. retries++;
  113. }
  114. if((retries >= 5))
  115. {
  116. printk(KERN_ERR "err %s timeout.\n",__FUNCTION__);
  117. }
  118. return (ret>0 ? 0 : -1);
  119. }
  120. static unsigned char *get_data_addr(unsigned char regaddr)
  121. {
  122. unsigned char *addr = NULL;
  123. switch(regaddr)
  124. {
  125. case SELECT_ADDR_INITIAL_SETUP:
  126. addr = &select_data.select_data_initial_setup;
  127. break;
  128. case SELECT_ADDR_LPF_SETUP:
  129. addr = &select_data.select_data_lpf_setup;
  130. break;
  131. case SELECT_ADDR_MIXING_SETUP:
  132. addr = &select_data.select_data_mixing_setup;
  133. break;
  134. case SELECT_ADDR_INPUT_SELECTOR:
  135. addr = &select_data.select_data_input_selector;
  136. break;
  137. case SELECT_ADDR_INPUT_GAIN:
  138. addr = &select_data.select_data_input_gain;
  139. break;
  140. case SELECT_ADDR_VOLUME_GAIN:
  141. addr = &select_data.select_data_volume_gain;
  142. break;
  143. case SELECT_ADDR_FADER_1CH_FRONT:
  144. addr = &select_data.select_data_fader_1ch_front_gain;
  145. break;
  146. case SELECT_ADDR_FADER_2CH_FRONT:
  147. addr = &select_data.select_data_fader_2ch_front_gain;
  148. break;
  149. case SELECT_ADDR_FADER_1CH_REAR:
  150. addr = &select_data.select_data_fader_1ch_rear_gain;
  151. break;
  152. case SELECT_ADDR_FADER_2CH_REAR:
  153. addr = &select_data.select_data_fader_2ch_rear_gain;
  154. break;
  155. case SELECT_ADDR_FADER_1CH_SUB:
  156. addr = &select_data.select_data_fader_1ch_sub_gain;
  157. break;
  158. case SELECT_ADDR_MIXINT_2CH_SUB:
  159. addr = &select_data.select_data_mixing_2ch_sub_gain;
  160. break;
  161. case SELECT_ADDR_BASS_SETUP:
  162. addr = &select_data.select_data_bass_setup;
  163. break;
  164. case SELECT_ADDR_MIDDLE_SETUP:
  165. addr = &select_data.select_data_middle_setup;
  166. break;
  167. case SELECT_ADDR_TREBLE_SETUP:
  168. addr = &select_data.select_data_treble_setup;
  169. break;
  170. case SELECT_ADDR_BASS_GAIN:
  171. addr = &select_data.select_data_bass_gain;
  172. break;
  173. case SELECT_ADDR_MIDDLE_GAIN:
  174. addr = &select_data.select_data_middle_gain;
  175. break;
  176. case SELECT_ADDR_TREBLE_GAIN:
  177. addr = &select_data.select_data_treble_gain;
  178. break;
  179. case SELECT_ADDR_LOUDNESS_GAIN:
  180. addr = &select_data.select_data_loudness_gain;
  181. break;
  182. case SELECT_ADDR_SYSTEM_RESET:
  183. addr = &select_data.select_data_system_reset;
  184. break;
  185. default:
  186. break;
  187. }
  188. return addr;
  189. }
  190. #if 1
  191. static int register_write(unsigned char regaddr, unsigned char regval)
  192. {
  193. unsigned char *data_addr;
  194. struct i2c_client *client = NULL;
  195. int ret = -1;
  196. if(!my_bd)
  197. return ret;
  198. client = my_bd->client;
  199. ret = bd37033_write_byte(client,client->addr,regaddr,regval);
  200. if(!ret)
  201. {
  202. data_addr = get_data_addr(regaddr);
  203. if(data_addr)
  204. {
  205. *data_addr = regval;
  206. }
  207. }
  208. return ret;
  209. }
  210. static int register_read(unsigned char regaddr)
  211. {
  212. unsigned char *data_addr;
  213. int regval = -1;
  214. data_addr = get_data_addr(regaddr);
  215. if(data_addr)
  216. {
  217. regval = *data_addr;
  218. printk(KERN_LEVEL "regval:%x\n",regval);
  219. }
  220. return regval;
  221. }
  222. #endif
  223. /*************************************************************************************************
  224. **************************
  225. ************************** Register Operation Functions
  226. **************************
  227. *************************************************************************************************/
  228. static int bd37033_mixing_setup(struct bd37033_data *bd, int type, unsigned char value)
  229. {
  230. struct i2c_client *client = bd->client;
  231. unsigned char mixing = select_data.select_data_mixing_setup;
  232. int ret = -1;
  233. switch(type)
  234. {
  235. case BD37033_MIXING_1CH_SWITCH_TYPE:
  236. mixing &= ~(0x01<<1);
  237. mixing |= value<<1;
  238. break;
  239. case BD37033_MIXING_2CH_SWITCH_TYPE:
  240. mixing &= ~(0x01<<2);
  241. mixing |= value<<2;
  242. break;
  243. case BD37033_MIXING_LOUDNESS_F0_TYPE:
  244. mixing &= ~(0x03<<3);
  245. mixing |= value<<3;
  246. break;
  247. case BD37033_MIXING_INPUT_SELECT_TYPE:
  248. mixing &= ~(0x03<<6);
  249. mixing |= value<<6;
  250. break;
  251. default:
  252. break;
  253. }
  254. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_MIXING_SETUP, mixing);
  255. if(ret == 0)
  256. select_data.select_data_mixing_setup = mixing;
  257. return ret;
  258. }
  259. static int bd37033_select_input_channel(struct bd37033_data *bd, unsigned char value)
  260. {
  261. struct i2c_client *client = bd->client;
  262. unsigned char input_select = select_data.select_data_input_selector;
  263. unsigned char mute_state = select_data.select_data_input_gain >> 7;
  264. int ret = -1;
  265. switch(value)
  266. {
  267. case BD37033_INPUT_SELECTOR_A_SINGLE:
  268. case BD37033_INPUT_SELECTOR_B_SINGLE:
  269. case BD37033_INPUT_SELECTOR_C_SINGLE:
  270. case BD37033_INPUT_SELECTOR_D_SINGLE:
  271. case BD37033_INPUT_SELECTOR_E1_SINGLE:
  272. case BD37033_INPUT_SELECTOR_E2_SINGLE:
  273. case BD37033_INPUT_SELECTOR_D_DIFF:
  274. case BD37033_INPUT_SELECTOR_E_FULL_DIFF:
  275. case BD37033_INPUT_SELECTOR_INPUT_SHORT:
  276. bd37033_set_mute(bd,MUTE_ON); //mute while switch input channel
  277. input_select &= ~(0x1f);
  278. input_select |= value;
  279. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_INPUT_SELECTOR, input_select);
  280. if(ret == 0)
  281. select_data.select_data_input_selector = input_select;
  282. bd37033_set_mute(bd,mute_state);//mute_state
  283. break;
  284. case BD37033_INPUT_SELECTOR_FULL_DIFF_TYPE_NEGATIVE_INPUT:
  285. input_select &= ~(0x1<<7);
  286. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_INPUT_SELECTOR, input_select);
  287. if(ret == 0)
  288. select_data.select_data_input_selector = input_select;
  289. break;
  290. case BD37033_INPUT_SELECTOR_FULL_DIFF_TYPE_BIAS:
  291. input_select |= (0x1<<7);
  292. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_INPUT_SELECTOR, input_select);
  293. if(ret == 0)
  294. select_data.select_data_input_selector = input_select;
  295. break;
  296. default:
  297. break;
  298. }
  299. return ret;
  300. }
  301. static int bd37033_set_input_gain(struct bd37033_data *bd, unsigned char value)
  302. {
  303. struct i2c_client *client = bd->client;
  304. unsigned char input_gain = select_data.select_data_input_gain;
  305. int ret = -1;
  306. /* maximum input gain 16dB */
  307. if(value > 0x10)
  308. value = 0x10;
  309. /* minimum input gain 0dB */
  310. if(value >= 0)
  311. {
  312. input_gain &= ~(0x1f);
  313. input_gain |= value;
  314. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_INPUT_GAIN, input_gain);
  315. if(ret == 0)
  316. select_data.select_data_input_gain = input_gain;
  317. }
  318. return ret;
  319. }
  320. static int bd37033_set_mute(struct bd37033_data *bd, int state)
  321. {
  322. struct i2c_client *client = bd->client;
  323. unsigned char mute_state = select_data.select_data_input_gain;
  324. int ret = -1;
  325. if(state == MUTE_ON)
  326. {
  327. mute_state |= (1<<7);
  328. }
  329. else if(state == MUTE_OFF)
  330. {
  331. mute_state &= ~(1<<7);
  332. }
  333. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_INPUT_GAIN, mute_state);
  334. if(ret == 0)
  335. select_data.select_data_input_gain = mute_state;
  336. return ret;
  337. }
  338. static int bd37033_set_volume_gain(struct bd37033_data *bd, unsigned char value)
  339. {
  340. struct i2c_client *client = bd->client;
  341. unsigned char volume = select_data.select_data_volume_gain;
  342. int ret = -1;
  343. if(value == 0xff)
  344. {
  345. volume = 0xff;
  346. }
  347. else if(value >= 0x80)
  348. {
  349. if(value > 0xcf)
  350. value = 0xcf;
  351. volume = value;
  352. }
  353. else
  354. {
  355. if(value < 0x71)
  356. value = 0x71;
  357. volume = value;
  358. }
  359. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_VOLUME_GAIN, volume);
  360. if(ret == 0)
  361. select_data.select_data_volume_gain = volume;
  362. return ret;
  363. }
  364. static int bd37033_set_fader_mixing_gain(struct bd37033_data *bd, unsigned char select_addr, unsigned char value)
  365. {
  366. struct i2c_client *client = bd->client;
  367. unsigned char *data_addr = get_data_addr(select_addr);
  368. unsigned char gain = *data_addr;
  369. int ret = -1;
  370. if(value == 0xff)
  371. {
  372. gain = value;
  373. }
  374. else if(value > 0x80)
  375. {
  376. if(value > 0xcf)
  377. value = 0xcf;
  378. gain = value;
  379. }
  380. else
  381. {
  382. if(value < 0x71)
  383. value = 0x71;
  384. gain = value;
  385. }
  386. ret = bd37033_write_byte(client, client->addr, select_addr, gain);
  387. if(ret == 0)
  388. *data_addr = gain;
  389. return ret;
  390. }
  391. static int bd37033_bass_middle_treble_setup(struct bd37033_data *bd, unsigned char mode, unsigned char value)
  392. {
  393. struct i2c_client *client = bd->client;
  394. unsigned char select = 0;
  395. int ret = -1;
  396. switch(mode)
  397. {
  398. case BASS_Q:
  399. {
  400. select = select_data.select_data_bass_setup;
  401. select &= ~(0x3<<0);
  402. select |= value;
  403. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_BASS_SETUP, select);
  404. if(ret == 0)
  405. select_data.select_data_bass_setup = select;
  406. break;
  407. }
  408. case BASS_F0:
  409. {
  410. select = select_data.select_data_bass_setup;
  411. select &= ~(0x3<<4);
  412. select |= (value<<4);
  413. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_BASS_SETUP, select);
  414. if(ret == 0)
  415. select_data.select_data_bass_setup = select;
  416. break;
  417. }
  418. case MIDDLE_Q:
  419. {
  420. select = select_data.select_data_middle_setup;
  421. select &= ~(0x3<<0);
  422. select |= value;
  423. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_MIDDLE_SETUP, select);
  424. if(ret == 0)
  425. select_data.select_data_middle_setup = select;
  426. break;
  427. }
  428. case MIDDLE_F0:
  429. {
  430. select = select_data.select_data_middle_setup;
  431. select &= ~(0x3<<4);
  432. select |= (value<<4);
  433. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_MIDDLE_SETUP, select);
  434. if(ret == 0)
  435. select_data.select_data_middle_setup = select;
  436. break;
  437. }
  438. case TREBLE_Q:
  439. {
  440. select = select_data.select_data_treble_setup;
  441. select &= ~(0x1<<0);
  442. select |= value;
  443. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_TREBLE_SETUP, select);
  444. if(ret == 0)
  445. select_data.select_data_treble_setup = select;
  446. break;
  447. }
  448. case TREBLE_F0:
  449. {
  450. select = select_data.select_data_treble_setup;
  451. select &= ~(0x3<<4);
  452. select |= (value<<4);
  453. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_TREBLE_SETUP, select);
  454. if(ret == 0)
  455. select_data.select_data_treble_setup = select;
  456. break;
  457. }
  458. default:
  459. break;
  460. }
  461. return ret;
  462. }
  463. static int bd37033_set_bass_middle_treble_gain(struct bd37033_data *bd, unsigned char select_addr, unsigned char value)
  464. {
  465. struct i2c_client *client = bd->client;
  466. unsigned char *data_addr = get_data_addr(select_addr);
  467. int ret = -1;
  468. ret = bd37033_write_byte(client, client->addr, select_addr, value);
  469. if(ret == 0)
  470. *data_addr = value;
  471. return ret;
  472. }
  473. static int bd37033_set_loudness_gain(struct bd37033_data *bd, signed char value)
  474. {
  475. struct i2c_client *client = bd->client;
  476. unsigned char loudness = select_data.select_data_loudness_gain;
  477. int ret = -1;
  478. if(value > 0x0f)
  479. value = 0x0f;
  480. if(value < 0)
  481. return ret;
  482. loudness &= ~(0x1f);
  483. loudness |= value;
  484. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_LOUDNESS_GAIN, loudness);
  485. if(ret == 0)
  486. select_data.select_data_loudness_gain = loudness;
  487. return ret;
  488. }
  489. static int bd37033_set_loudness_hicut(struct bd37033_data *bd, signed char value)
  490. {
  491. struct i2c_client *client = bd->client;
  492. unsigned char hicut = select_data.select_data_loudness_gain;
  493. int ret = -1;
  494. hicut &= ~(3<<5);
  495. hicut |= value<<5;
  496. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_LOUDNESS_GAIN, hicut);
  497. if(ret == 0)
  498. select_data.select_data_loudness_gain = hicut;
  499. return ret;
  500. }
  501. static int bd37033_lpf_setup(struct bd37033_data *bd, int type, signed char value)
  502. {
  503. struct i2c_client *client = bd->client;
  504. unsigned char lpf = select_data.select_data_lpf_setup;
  505. int ret = -1;
  506. switch(type)
  507. {
  508. case BD37033_LPF_SETUP_SUB_LPF_FC_TYPE:
  509. lpf &= ~(0x07<<0);
  510. lpf |= value<<0;
  511. if(value == 0x05) //fc = pass ==> parse = 0
  512. {
  513. lpf &= ~(0x01<<7);
  514. }
  515. break;
  516. case BD37033_LPF_SETUP_SUB_INPUT_SELECT_TYPE:
  517. lpf &= ~(0x01<<3);
  518. lpf |= value<<3;
  519. break;
  520. case BD37033_LPF_SETUP_SUB_OUTPUT_SELECT_TYPE:
  521. lpf &= ~(0x03<<4);
  522. lpf |= value<<4;
  523. break;
  524. case BD37033_LPF_SETUP_LEVEL_METER_RESET_TYPE:
  525. lpf &= ~(0x01<<6);
  526. lpf |= value<<6;
  527. break;
  528. case BD37033_LPF_SETUP_LPF_PHASE_TYPE:
  529. lpf &= ~(0x01<<7);
  530. lpf |= value<<7;
  531. break;
  532. default:
  533. break;
  534. }
  535. ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_LPF_SETUP, lpf);
  536. if(ret == 0)
  537. select_data.select_data_lpf_setup = lpf;
  538. return ret;
  539. }
  540. int bd37033_sys_reset(struct bd37033_data *bd)
  541. {
  542. //struct i2c_client *client = bd->client;
  543. //int ret = -1;
  544. //ret = bd37033_write_byte(client, client->addr, SELECT_ADDR_SYSTEM_RESET, 0x81);
  545. if(bd37033_set_mute(bd,MUTE_ON) == 0)
  546. mute_status = MUTE_ON;
  547. bd37033_init(bd);
  548. return 0;
  549. }
  550. int bd37033_set_default(struct bd37033_data *bd)
  551. {
  552. //input channel select
  553. if(mp.input_channel >= 0)
  554. bd37033_set_stream(mp.input_channel);
  555. else
  556. bd37033_select_input_channel(bd,BD37033_INPUT_SELECTOR_D_SINGLE); //default: navi
  557. //set loudness f0
  558. bd37033_mixing_setup(my_bd,BD37033_MIXING_LOUDNESS_F0_TYPE,1); //1: 800HZ
  559. //set volume
  560. if(mp.volume >= 0)
  561. bd37033_set_volume(mp.volume);
  562. else //default : 0x94
  563. bd37033_set_volume_gain(bd,0x94);
  564. //set input gain
  565. if(mp.input_gain >= 0)
  566. bd37033_set_input_gain(bd,mp.input_gain);
  567. else //default: 0
  568. bd37033_set_input_gain(bd,0);
  569. //select out channel
  570. if (!of_property_read_u32(bd->client->dev.of_node, "flout-gain", &bd->dac.vol_flout))
  571. mp.fl_gain = bd->dac.vol_flout;
  572. if (!of_property_read_u32(bd->client->dev.of_node, "frout-gain", &bd->dac.vol_flout))
  573. mp.fr_gain = bd->dac.vol_flout;
  574. if (!of_property_read_u32(bd->client->dev.of_node, "rlout-gain", &bd->dac.vol_flout))
  575. mp.rl_gain = bd->dac.vol_flout;
  576. if (!of_property_read_u32(bd->client->dev.of_node, "rrout-gain", &bd->dac.vol_flout))
  577. mp.rr_gain = bd->dac.vol_flout;
  578. //printk("dac.vol_flout = %d dac.vol_flout = %d dac.vol_flout = %d dac.vol_flout = %d\n",bd->dac.vol_flout,bd->dac.vol_flout,bd->dac.vol_flout,bd->dac.vol_flout);
  579. //printk("mp.fl_gain = %d mp.fr_gain = %d mp.rl_gain = %d mp.rr_gain = %d\n",mp.fl_gain,mp.fr_gain,mp.rl_gain,mp.rr_gain);
  580. if(mp.fl_gain >= 0)
  581. bd37033_set_fader(SELECT_ADDR_FADER_1CH_FRONT,mp.fl_gain);
  582. if(mp.fr_gain >= 0)
  583. bd37033_set_fader(SELECT_ADDR_FADER_2CH_FRONT,mp.fr_gain);
  584. if(mp.rl_gain >= 0)
  585. bd37033_set_fader(SELECT_ADDR_FADER_1CH_REAR,mp.rl_gain);
  586. if(mp.rr_gain >= 0)
  587. bd37033_set_fader(SELECT_ADDR_FADER_2CH_REAR,mp.rr_gain);
  588. if((mp.fl_gain < 0) && (mp.fr_gain < 0) && (mp.rl_gain < 0) && (mp.rr_gain < 0)) //default: fl
  589. bd37033_set_fader_mixing_gain(bd,SELECT_ADDR_FADER_1CH_FRONT,0); //FL
  590. //mp.mute -1: default unmute; 0->unmute; others:mute
  591. if(mp.mute <= 0)
  592. {
  593. if(bd37033_set_mute(bd,MUTE_OFF) == 0)
  594. mute_status = MUTE_OFF;
  595. }
  596. else
  597. {
  598. if(bd37033_set_mute(bd,MUTE_ON) == 0)
  599. mute_status = MUTE_ON;
  600. }
  601. if(mp.bass_gain >= 0)
  602. set_tone_gain(SELECT_ADDR_BASS_GAIN, mp.bass_gain);
  603. if(mp.middle_gain >= 0)
  604. set_tone_gain(SELECT_ADDR_MIDDLE_GAIN, mp.middle_gain);
  605. if(mp.treble_gain >= 0)
  606. set_tone_gain(SELECT_ADDR_TREBLE_GAIN, mp.treble_gain);
  607. memset(&mp, -1, sizeof(struct bd37033_module_param));
  608. return 0;
  609. }
  610. static void bd37033_init(struct bd37033_data *bd)
  611. {
  612. struct i2c_client *client = NULL;
  613. if (bd == NULL)
  614. {
  615. printk(KERN_ERR "err %s, bd37033_data null\n",__FUNCTION__);
  616. return ;
  617. }
  618. client = bd->client;
  619. if (client == NULL)
  620. {
  621. printk(KERN_ERR "err %s, i2c_client null\n",__FUNCTION__);
  622. return ;
  623. }
  624. //set default value
  625. select_data.select_data_initial_setup = 0xA4;
  626. select_data.select_data_lpf_setup = 0x00;
  627. select_data.select_data_mixing_setup = 0x00;
  628. select_data.select_data_input_selector = 0x0;
  629. select_data.select_data_input_gain = 0x80;
  630. mute_status = MUTE_ON;
  631. select_data.select_data_volume_gain = 0xff;
  632. select_data.select_data_fader_1ch_front_gain = 0xff;
  633. select_data.select_data_fader_2ch_front_gain = 0xff;
  634. select_data.select_data_fader_1ch_rear_gain = 0xff;
  635. select_data.select_data_fader_2ch_rear_gain = 0xff;
  636. select_data.select_data_fader_1ch_sub_gain = 0xff;
  637. select_data.select_data_mixing_2ch_sub_gain = 0xff;
  638. select_data.select_data_bass_setup = 0x0;
  639. select_data.select_data_middle_setup = 0x0;
  640. select_data.select_data_treble_setup = 0x0;
  641. select_data.select_data_bass_gain = 0x80;
  642. select_data.select_data_middle_gain = 0x80;
  643. select_data.select_data_treble_gain = 0x80;
  644. select_data.select_data_loudness_gain = 0x0;
  645. select_data.select_data_system_reset = 0x81;
  646. bd37033_write_bytes(client, client->addr, SELECT_ADDR_INITIAL_SETUP, (unsigned char *)(&select_data),sizeof(select_data));
  647. bd37033_set_default(bd);
  648. }
  649. /*************************************************************************************************
  650. **************************
  651. ************************** ALSA Controls Interface Functions
  652. **************************
  653. *************************************************************************************************/
  654. static int get_stream (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  655. {
  656. unsigned char input_ch = select_data.select_data_input_selector & 0x1f;
  657. switch(input_ch)
  658. {
  659. case BD37033_INPUT_SELECTOR_A_SINGLE:
  660. ucontrol->value.integer.value[0] = BD37033_STREAM_A_SINGLE;
  661. break;
  662. case BD37033_INPUT_SELECTOR_B_SINGLE:
  663. ucontrol->value.integer.value[0] = BD37033_STREAM_B_SINGLE;
  664. break;
  665. case BD37033_INPUT_SELECTOR_C_SINGLE:
  666. ucontrol->value.integer.value[0] = BD37033_STREAM_C_SINGLE;
  667. break;
  668. case BD37033_INPUT_SELECTOR_D_SINGLE:
  669. ucontrol->value.integer.value[0] = BD37033_STREAM_D_SINGLE;
  670. break;
  671. case BD37033_INPUT_SELECTOR_E1_SINGLE:
  672. ucontrol->value.integer.value[0] = BD37033_STREAM_E1_SINGLE;
  673. break;
  674. case BD37033_INPUT_SELECTOR_E2_SINGLE:
  675. ucontrol->value.integer.value[0] = BD37033_STREAM_E2_SINGL;
  676. break;
  677. case BD37033_INPUT_SELECTOR_D_DIFF:
  678. ucontrol->value.integer.value[0] = BD37033_STREAM_D_DIF;
  679. break;
  680. case BD37033_INPUT_SELECTOR_E_FULL_DIFF:
  681. ucontrol->value.integer.value[0] = BD37033_STREAM_E_FULL_DIFF;
  682. break;
  683. case BD37033_INPUT_SELECTOR_INPUT_SHORT:
  684. ucontrol->value.integer.value[0] = BD37033_STREAM_INPUT_SHORT;
  685. break;
  686. default:
  687. break;
  688. }
  689. return 0;
  690. }
  691. static int bd37033_set_stream(unsigned char input_ch)
  692. {
  693. int ret = -1;
  694. switch (input_ch) {
  695. case BD37033_STREAM_A_SINGLE:
  696. ret = bd37033_select_input_channel(my_bd,BD37033_INPUT_SELECTOR_A_SINGLE);
  697. break;
  698. case BD37033_STREAM_B_SINGLE:
  699. ret = bd37033_select_input_channel(my_bd,BD37033_INPUT_SELECTOR_B_SINGLE);
  700. break;
  701. case BD37033_STREAM_C_SINGLE:
  702. ret = bd37033_select_input_channel(my_bd,BD37033_INPUT_SELECTOR_C_SINGLE);
  703. break;
  704. case BD37033_STREAM_D_SINGLE:
  705. ret = bd37033_select_input_channel(my_bd,BD37033_INPUT_SELECTOR_D_SINGLE);
  706. break;
  707. case BD37033_STREAM_E1_SINGLE:
  708. ret = bd37033_select_input_channel(my_bd,BD37033_INPUT_SELECTOR_E1_SINGLE);
  709. break;
  710. case BD37033_STREAM_E2_SINGL:
  711. ret = bd37033_select_input_channel(my_bd,BD37033_INPUT_SELECTOR_E2_SINGLE);
  712. break;
  713. case BD37033_STREAM_D_DIF:
  714. ret = bd37033_select_input_channel(my_bd,BD37033_INPUT_SELECTOR_D_DIFF);
  715. break;
  716. case BD37033_STREAM_E_FULL_DIFF:
  717. ret = bd37033_select_input_channel(my_bd,BD37033_INPUT_SELECTOR_E_FULL_DIFF);
  718. break;
  719. case BD37033_STREAM_INPUT_SHORT:
  720. ret = bd37033_select_input_channel(my_bd,BD37033_INPUT_SELECTOR_INPUT_SHORT);
  721. break;
  722. default:
  723. break;
  724. }
  725. return ret;
  726. }
  727. static int set_stream (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  728. {
  729. //struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
  730. int ret = -1;
  731. unsigned char input_ch = select_data.select_data_input_selector & 0x1f;
  732. if (input_ch == ucontrol->value.integer.value[0])
  733. return 0;
  734. input_ch = ucontrol->value.integer.value[0];
  735. ret = bd37033_set_stream(input_ch);
  736. return ret;
  737. }
  738. static int get_stream_full_diff_type (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  739. {
  740. ucontrol->value.integer.value[0] = (select_data.select_data_input_selector >> 7) & 0x1;
  741. return 0;
  742. }
  743. static int set_stream_full_diff_type (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  744. {
  745. unsigned char type = (select_data.select_data_input_selector >> 7) & 0x1;
  746. int ret = -1;
  747. if(type == ucontrol->value.integer.value[0])
  748. return 0;
  749. type = ucontrol->value.integer.value[0];
  750. switch(type)
  751. {
  752. case 0:
  753. ret = bd37033_select_input_channel(my_bd,BD37033_INPUT_SELECTOR_FULL_DIFF_TYPE_NEGATIVE_INPUT);
  754. break;
  755. case 1:
  756. ret = bd37033_select_input_channel(my_bd,BD37033_INPUT_SELECTOR_FULL_DIFF_TYPE_BIAS);
  757. break;
  758. default:
  759. break;
  760. }
  761. return ret;
  762. }
  763. /***************************************************************************************************
  764. *
  765. * Input Gain Setting
  766. *
  767. ***************************************************************************************************/
  768. static int get_stream_gain (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  769. {
  770. ucontrol->value.integer.value[0] = (select_data.select_data_input_gain & 0x1f);
  771. return 0;
  772. }
  773. static int set_stream_gain (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  774. {
  775. //struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
  776. int ret = -1;
  777. unsigned char gain = (select_data.select_data_input_gain & 0x1f);
  778. if (gain == ucontrol->value.integer.value[0])
  779. return 0;
  780. gain = ucontrol->value.integer.value[0];
  781. ret = bd37033_set_input_gain(my_bd,gain);
  782. return ret;
  783. }
  784. /***************************************************************************************************
  785. *
  786. * Fader Gain Setting
  787. *
  788. ***************************************************************************************************/
  789. static int bd37033_get_fader(unsigned char reg_addr)
  790. {
  791. unsigned char *fader_addr = get_data_addr(reg_addr);
  792. unsigned char fader = *fader_addr;
  793. if(fader >= 0x80)
  794. {
  795. if(fader == 0xff)
  796. {
  797. fader = 0;
  798. }
  799. else if(fader >= 0xcf)
  800. {
  801. fader = 1;
  802. }
  803. else
  804. {
  805. fader &= ~(0x1<<7);
  806. fader = 80 - fader;
  807. }
  808. }
  809. else
  810. {
  811. if(fader < 0x71) //make sure fader gain <= 15db
  812. fader = 95;
  813. else
  814. fader = 80 + (0x80 - fader);
  815. }
  816. return fader;
  817. }
  818. static int bd37033_set_fader(unsigned char reg_addr, unsigned char value)
  819. {
  820. unsigned char fader = bd37033_get_fader(reg_addr);
  821. int ret = -1;
  822. if (fader == value)
  823. return 0;
  824. fader = value;
  825. if(fader <= 80)
  826. {
  827. if(fader == 0) // mute
  828. {
  829. fader = 0xff;
  830. }
  831. else // -79db < fader gain <= 0db
  832. {
  833. fader = 80 - fader;
  834. fader |= (1<<7);
  835. }
  836. }
  837. else
  838. {
  839. if(fader > 95) // fader gain > +15db
  840. {
  841. fader = 0x71; //+15db
  842. }
  843. else //0db < fader gain < +15db
  844. {
  845. fader -= 80;
  846. fader = 0x80 - fader;
  847. }
  848. }
  849. ret = bd37033_set_fader_mixing_gain(my_bd,reg_addr,fader);
  850. return ret;
  851. }
  852. static int get_fl_fader (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  853. {
  854. ucontrol->value.integer.value[0] = bd37033_get_fader(SELECT_ADDR_FADER_1CH_FRONT);
  855. return 0;
  856. }
  857. static int set_fl_fader (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  858. {
  859. return bd37033_set_fader(SELECT_ADDR_FADER_1CH_FRONT,ucontrol->value.integer.value[0]);
  860. }
  861. static int get_fr_fader (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  862. {
  863. ucontrol->value.integer.value[0] = bd37033_get_fader(SELECT_ADDR_FADER_2CH_FRONT);
  864. return 0;
  865. }
  866. static int set_fr_fader (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  867. {
  868. return bd37033_set_fader(SELECT_ADDR_FADER_2CH_FRONT,ucontrol->value.integer.value[0]);
  869. }
  870. static int get_rl_fader (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  871. {
  872. ucontrol->value.integer.value[0] = bd37033_get_fader(SELECT_ADDR_FADER_2CH_REAR);
  873. return 0;
  874. }
  875. static int set_rl_fader (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  876. {
  877. return bd37033_set_fader(SELECT_ADDR_FADER_2CH_REAR,ucontrol->value.integer.value[0]);
  878. }
  879. static int get_rr_fader (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  880. {
  881. ucontrol->value.integer.value[0] = bd37033_get_fader(SELECT_ADDR_FADER_1CH_REAR);
  882. return 0;
  883. }
  884. static int set_rr_fader (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  885. {
  886. return bd37033_set_fader(SELECT_ADDR_FADER_1CH_REAR,ucontrol->value.integer.value[0]);
  887. }
  888. static int get_sub1_fader (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  889. {
  890. ucontrol->value.integer.value[0] = bd37033_get_fader(SELECT_ADDR_FADER_1CH_SUB);
  891. return 0;
  892. }
  893. static int set_sub1_fader (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  894. {
  895. return bd37033_set_fader(SELECT_ADDR_FADER_1CH_SUB,ucontrol->value.integer.value[0]);
  896. }
  897. static int get_sub2_fader (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  898. {
  899. ucontrol->value.integer.value[0] = bd37033_get_fader(SELECT_ADDR_MIXINT_2CH_SUB);
  900. return 0;
  901. }
  902. static int set_sub2_fader (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  903. {
  904. return bd37033_set_fader(SELECT_ADDR_MIXINT_2CH_SUB,ucontrol->value.integer.value[0]);
  905. }
  906. /***************************************************************************************************
  907. *
  908. * Volume Gain Setting
  909. *
  910. ***************************************************************************************************/
  911. static int bd37033_get_volume(void)
  912. {
  913. unsigned char volume = select_data.select_data_volume_gain;
  914. if(volume >= 0x80)
  915. {
  916. if(volume == 0xff)
  917. {
  918. volume = 0;
  919. }
  920. else if(volume >= 0xcf)
  921. {
  922. volume = 1;
  923. }
  924. else
  925. {
  926. volume &= ~(0x1<<7);
  927. volume = 80 - volume;
  928. }
  929. }
  930. else
  931. {
  932. if(volume < 0x71) //volume gain < 15db
  933. volume = 95;
  934. else
  935. volume = 80 + (0x80 - volume);
  936. }
  937. return volume;
  938. }
  939. static int bd37033_set_volume(unsigned char volume)
  940. {
  941. int ret;
  942. #if 1 //if volume=0, then set mute
  943. if(volume == 0)
  944. {
  945. if((select_data.select_data_input_gain & 0x80) == 0x0)
  946. bd37033_set_mute(my_bd,MUTE_ON);
  947. }
  948. else
  949. {
  950. if((select_data.select_data_input_gain & 0x80) == 0x80)
  951. {
  952. if(mute_status == MUTE_OFF)//when register is set mute, if mute_status==false, the register is set by volume=0, not mute setting,so when volume > 0, do not set mute off
  953. bd37033_set_mute(my_bd,MUTE_OFF);
  954. }
  955. }
  956. #endif
  957. if(volume <= 80)
  958. {
  959. if(volume == 0) // volume gain < -79db
  960. {
  961. volume = 0xff;
  962. }
  963. else // -79db < volume gain <= 0db
  964. {
  965. volume = 80 - volume;
  966. volume |= (1<<7);
  967. }
  968. }
  969. else
  970. {
  971. if(volume > 95) // volume gain > +15db
  972. {
  973. volume = 0x71; //+15db
  974. }
  975. else //0db < volume gain < +15db
  976. {
  977. volume -= 80;
  978. volume = 0x80 - volume;
  979. }
  980. }
  981. ret = bd37033_set_volume_gain(my_bd,volume);
  982. return ret;
  983. }
  984. static int get_volume (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  985. {
  986. ucontrol->value.integer.value[0] = bd37033_get_volume();
  987. return 0;
  988. }
  989. static int set_volume (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  990. {
  991. int ret = -1;
  992. unsigned char volume = bd37033_get_volume();
  993. if (volume == ucontrol->value.integer.value[0])
  994. return 0;
  995. volume = ucontrol->value.integer.value[0];
  996. ret = bd37033_set_volume(volume);
  997. return ret;
  998. }
  999. /***************************************************************************************************
  1000. *
  1001. * Mixing Setting
  1002. *
  1003. ***************************************************************************************************/
  1004. static int get_mixing_channel1_switch(struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1005. {
  1006. ucontrol->value.integer.value[0] = (select_data.select_data_mixing_setup >> 1) & 0x01;
  1007. return 0;
  1008. }
  1009. static int set_mixing_channel1_switch (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1010. {
  1011. //struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
  1012. unsigned char ch1 = (select_data.select_data_mixing_setup >> 1) & 0x01;
  1013. int ret = -1;
  1014. if (ch1 == ucontrol->value.integer.value[0])
  1015. return 0;
  1016. ch1 = ucontrol->value.integer.value[0];
  1017. switch (ch1)
  1018. {
  1019. case 0:
  1020. case 1:
  1021. ret = bd37033_mixing_setup(my_bd,BD37033_MIXING_1CH_SWITCH_TYPE,ch1);
  1022. break;
  1023. default:
  1024. break;
  1025. }
  1026. return ret;
  1027. }
  1028. static int get_mixing_channel2_switch(struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1029. {
  1030. ucontrol->value.integer.value[0] = (select_data.select_data_mixing_setup >> 2) & 0x01;
  1031. return 0;
  1032. }
  1033. static int set_mixing_channel2_switch (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1034. {
  1035. //struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
  1036. unsigned char ch2 = (select_data.select_data_mixing_setup >> 2) & 0x01;
  1037. int ret = -1;
  1038. if (ch2 == ucontrol->value.integer.value[0])
  1039. return 0;
  1040. ch2 = ucontrol->value.integer.value[0];
  1041. switch (ch2)
  1042. {
  1043. case 0:
  1044. case 1:
  1045. ret = bd37033_mixing_setup(my_bd,BD37033_MIXING_2CH_SWITCH_TYPE,ch2);
  1046. break;
  1047. default:
  1048. break;
  1049. }
  1050. return ret;
  1051. }
  1052. static int get_loudness_f0(struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1053. {
  1054. ucontrol->value.integer.value[0] = (select_data.select_data_mixing_setup>>3) & 0x03;
  1055. return 0;
  1056. }
  1057. static int set_loudness_f0 (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1058. {
  1059. //struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
  1060. unsigned char f0 = (select_data.select_data_mixing_setup>>3) & 0x03;
  1061. int ret = -1;
  1062. if (f0 == ucontrol->value.integer.value[0])
  1063. return 0;
  1064. f0 = ucontrol->value.integer.value[0];
  1065. switch (f0)
  1066. {
  1067. case 0:
  1068. case 1:
  1069. case 2:
  1070. ret = bd37033_mixing_setup(my_bd,BD37033_MIXING_LOUDNESS_F0_TYPE,f0);
  1071. break;
  1072. default:
  1073. break;
  1074. }
  1075. return ret;
  1076. }
  1077. static int get_mixing_input_select(struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1078. {
  1079. ucontrol->value.integer.value[0] = (select_data.select_data_mixing_setup >> 6) & 0x03;
  1080. return 0;
  1081. }
  1082. static int set_mixing_input_select (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1083. {
  1084. //struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
  1085. unsigned char input = (select_data.select_data_mixing_setup >> 6) & 0x03;
  1086. int ret = -1;
  1087. if (input == ucontrol->value.integer.value[0])
  1088. return 0;
  1089. input = ucontrol->value.integer.value[0];
  1090. switch (input)
  1091. {
  1092. case 0:
  1093. case 1:
  1094. case 2:
  1095. ret = bd37033_mixing_setup(my_bd,BD37033_MIXING_INPUT_SELECT_TYPE,input);
  1096. break;
  1097. default:
  1098. break;
  1099. }
  1100. return ret;
  1101. }
  1102. /***************************************************************************************************
  1103. *
  1104. * Mute setting
  1105. *
  1106. ***************************************************************************************************/
  1107. static int get_mute_status(struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1108. {
  1109. #if 0
  1110. if((select_data.select_data_input_gain & 0x80) == 0x80)
  1111. ucontrol->value.integer.value[0] = MUTE_ON;
  1112. else
  1113. ucontrol->value.integer.value[0] = MUTE_OFF;
  1114. #else
  1115. ucontrol->value.integer.value[0] = mute_status;
  1116. #endif
  1117. return 0;
  1118. }
  1119. static int set_mute_status (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1120. {
  1121. //struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
  1122. unsigned char mute = (select_data.select_data_input_gain & 0x80)>>7;
  1123. int ret = -1;
  1124. if (mute == ucontrol->value.integer.value[0])
  1125. return 0;
  1126. mute = ucontrol->value.integer.value[0];
  1127. switch (mute)
  1128. {
  1129. case MUTE_OFF:
  1130. ret = bd37033_set_mute(my_bd,MUTE_OFF);
  1131. if(ret == 0)
  1132. mute_status = MUTE_OFF;
  1133. break;
  1134. case MUTE_ON:
  1135. ret = bd37033_set_mute(my_bd,MUTE_ON);
  1136. if(ret == 0)
  1137. mute_status = MUTE_ON;
  1138. break;
  1139. default:
  1140. break;
  1141. }
  1142. return ret;
  1143. }
  1144. /***************************************************************************************************
  1145. *
  1146. * Tone F0 and Q Setting
  1147. *
  1148. ***************************************************************************************************/
  1149. static int set_tone_q(unsigned char reg_addr, unsigned char type, unsigned char value)
  1150. {
  1151. int ret = -1;
  1152. unsigned char q = *(get_data_addr(reg_addr));
  1153. q = (q>>0)&(0x3);
  1154. if (q == value)
  1155. return 0;
  1156. switch (value) {
  1157. case 0:
  1158. case 1:
  1159. case 2:
  1160. case 3:
  1161. if(type == TREBLE_Q)
  1162. {
  1163. if(value < 2)
  1164. ret = bd37033_bass_middle_treble_setup(my_bd,type,value);
  1165. }
  1166. else
  1167. {
  1168. ret = bd37033_bass_middle_treble_setup(my_bd,type,value);
  1169. }
  1170. break;
  1171. default:
  1172. break;
  1173. }
  1174. return ret;
  1175. }
  1176. static int set_tone_f0(unsigned char reg_addr, unsigned char type, unsigned char value)
  1177. {
  1178. int ret = -1;
  1179. unsigned char f0 = *(get_data_addr(reg_addr));
  1180. f0 = (f0>>4)&(0x3);
  1181. if (f0 == value)
  1182. return 0;
  1183. switch (value) {
  1184. case 0:
  1185. case 1:
  1186. case 2:
  1187. case 3:
  1188. ret = bd37033_bass_middle_treble_setup(my_bd,type,value);
  1189. break;
  1190. default:
  1191. break;
  1192. }
  1193. return ret;
  1194. }
  1195. static int get_bass_q(struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1196. {
  1197. ucontrol->value.integer.value[0] = (select_data.select_data_bass_setup & 0x3);
  1198. return 0;
  1199. }
  1200. static int set_bass_q (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1201. {
  1202. return set_tone_q(SELECT_ADDR_BASS_SETUP,BASS_Q,ucontrol->value.integer.value[0]);
  1203. }
  1204. static int get_middle_q(struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1205. {
  1206. ucontrol->value.integer.value[0] = (select_data.select_data_middle_setup & 0x3);
  1207. return 0;
  1208. }
  1209. static int set_middle_q (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1210. {
  1211. return set_tone_q(SELECT_ADDR_MIDDLE_SETUP,MIDDLE_Q,ucontrol->value.integer.value[0]);
  1212. }
  1213. static int get_treble_q(struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1214. {
  1215. ucontrol->value.integer.value[0] = (select_data.select_data_treble_setup & 0x1);
  1216. return 0;
  1217. }
  1218. static int set_treble_q (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1219. {
  1220. return set_tone_q(SELECT_ADDR_TREBLE_SETUP,TREBLE_Q,ucontrol->value.integer.value[0]);
  1221. }
  1222. static int get_bass_f0(struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1223. {
  1224. ucontrol->value.integer.value[0] = (select_data.select_data_bass_setup>>4) & 0x3;
  1225. return 0;
  1226. }
  1227. static int set_bass_f0 (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1228. {
  1229. return set_tone_f0(SELECT_ADDR_BASS_SETUP,BASS_F0,ucontrol->value.integer.value[0]);
  1230. }
  1231. static int get_middle_f0(struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1232. {
  1233. ucontrol->value.integer.value[0] = (select_data.select_data_middle_setup>>4) & 0x3;
  1234. return 0;
  1235. }
  1236. static int set_middle_f0 (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1237. {
  1238. return set_tone_f0(SELECT_ADDR_MIDDLE_SETUP,MIDDLE_F0,ucontrol->value.integer.value[0]);
  1239. }
  1240. static int get_treble_f0(struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1241. {
  1242. ucontrol->value.integer.value[0] = (select_data.select_data_treble_setup>>4) & 0x3;
  1243. return 0;
  1244. }
  1245. static int set_treble_f0 (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1246. {
  1247. return set_tone_f0(SELECT_ADDR_TREBLE_SETUP,TREBLE_F0,ucontrol->value.integer.value[0]);
  1248. }
  1249. /***************************************************************************************************
  1250. *
  1251. * Tone Gain Setting
  1252. *
  1253. ***************************************************************************************************/
  1254. static int get_tone_gain(unsigned char reg_addr)
  1255. {
  1256. unsigned char gain = *(get_data_addr(reg_addr));
  1257. if(gain & (0x1<<7)) //boost
  1258. gain = 15 - (gain & 0x1f);
  1259. else
  1260. gain = 15 + (gain & 0x1f);
  1261. return gain;
  1262. }
  1263. static int set_tone_gain(unsigned char reg_addr, unsigned char value)
  1264. {
  1265. int ret = -1;
  1266. unsigned char gain = get_tone_gain(reg_addr);
  1267. if (gain == value)
  1268. return 0;
  1269. if(value <= 15) //cut : 0-14, 15(boost or cut) ,boost : 16-30
  1270. {
  1271. gain = 15 - value;
  1272. gain |= (0x1<<7);
  1273. }
  1274. else
  1275. {
  1276. gain = value - 15;
  1277. }
  1278. ret = bd37033_set_bass_middle_treble_gain(my_bd, reg_addr, gain);
  1279. return ret;
  1280. }
  1281. static int get_bass_gain (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1282. {
  1283. ucontrol->value.integer.value[0] = get_tone_gain(SELECT_ADDR_BASS_GAIN);
  1284. return 0;
  1285. }
  1286. static int set_bass_gain (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1287. {
  1288. return set_tone_gain(SELECT_ADDR_BASS_GAIN, ucontrol->value.integer.value[0]);
  1289. }
  1290. static int get_middle_gain (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1291. {
  1292. ucontrol->value.integer.value[0] = get_tone_gain(SELECT_ADDR_MIDDLE_GAIN);
  1293. return 0;
  1294. }
  1295. static int set_middle_gain (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1296. {
  1297. return set_tone_gain(SELECT_ADDR_MIDDLE_GAIN, ucontrol->value.integer.value[0]);
  1298. }
  1299. static int get_treble_gain (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1300. {
  1301. ucontrol->value.integer.value[0] = get_tone_gain(SELECT_ADDR_TREBLE_GAIN);
  1302. return 0;
  1303. }
  1304. static int set_treble_gain (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1305. {
  1306. return set_tone_gain(SELECT_ADDR_TREBLE_GAIN, ucontrol->value.integer.value[0]);
  1307. }
  1308. /***************************************************************************************************
  1309. *
  1310. * bd37033 reset
  1311. *
  1312. ***************************************************************************************************/
  1313. static int get_reset (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1314. {
  1315. //ucontrol->value.integer.value[0] = select_data.select_data_system_reset;
  1316. return 0;
  1317. }
  1318. static int set_reset (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1319. {
  1320. //struct snd_soc_card *card = snd_kcontrol_chip(kcontrol);
  1321. int ret = -1;
  1322. ret = bd37033_sys_reset(my_bd);
  1323. return ret;
  1324. }
  1325. /***************************************************************************************************
  1326. *
  1327. * loudness setting
  1328. *
  1329. ***************************************************************************************************/
  1330. static int get_loudness (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1331. {
  1332. ucontrol->value.integer.value[0] = select_data.select_data_loudness_gain & 0x1f;
  1333. return 0;
  1334. }
  1335. static int set_loudness (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1336. {
  1337. int ret = -1;
  1338. unsigned char gain = select_data.select_data_loudness_gain & 0x1f;
  1339. if (gain == ucontrol->value.integer.value[0])
  1340. return 0;
  1341. gain = ucontrol->value.integer.value[0];
  1342. ret = bd37033_set_loudness_gain(my_bd, gain);
  1343. return ret;
  1344. }
  1345. static int get_loudness_hicut (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1346. {
  1347. ucontrol->value.integer.value[0] = (select_data.select_data_loudness_gain>>5) & 0x03;
  1348. return 0;
  1349. }
  1350. static int set_loudness_hicut (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1351. {
  1352. int ret = -1;
  1353. unsigned char hicut = (select_data.select_data_loudness_gain>>5) & 0x03;
  1354. if (hicut == ucontrol->value.integer.value[0])
  1355. return 0;
  1356. hicut = ucontrol->value.integer.value[0];
  1357. switch(hicut)
  1358. {
  1359. case 0:
  1360. case 1:
  1361. case 2:
  1362. case 3:
  1363. ret = bd37033_set_loudness_hicut(my_bd, hicut);
  1364. break;
  1365. default:
  1366. break;
  1367. }
  1368. return ret;
  1369. }
  1370. /***************************************************************************************************
  1371. *
  1372. * subwoofer setting
  1373. *
  1374. ***************************************************************************************************/
  1375. static int get_lpf_fc (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1376. {
  1377. ucontrol->value.integer.value[0] = select_data.select_data_lpf_setup & 0x07;
  1378. return 0;
  1379. }
  1380. static int set_lpf_fc (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1381. {
  1382. int ret = -1;
  1383. unsigned char fc = select_data.select_data_lpf_setup & 0x07;
  1384. if (fc == ucontrol->value.integer.value[0])
  1385. return 0;
  1386. fc = ucontrol->value.integer.value[0];
  1387. switch(fc)
  1388. {
  1389. case 0:
  1390. case 1:
  1391. case 2:
  1392. case 3:
  1393. case 4:
  1394. case 5:
  1395. ret = bd37033_lpf_setup(my_bd, BD37033_LPF_SETUP_SUB_LPF_FC_TYPE,fc);
  1396. break;
  1397. default:
  1398. break;
  1399. }
  1400. return ret;
  1401. }
  1402. static int get_sub_input_select (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1403. {
  1404. ucontrol->value.integer.value[0] = (select_data.select_data_lpf_setup >> 3) & 0x01;
  1405. return 0;
  1406. }
  1407. static int set_sub_input_select (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1408. {
  1409. int ret = -1;
  1410. unsigned char input = (select_data.select_data_lpf_setup >> 3) & 0x01;
  1411. if (input == ucontrol->value.integer.value[0])
  1412. return 0;
  1413. input = ucontrol->value.integer.value[0];
  1414. switch(input)
  1415. {
  1416. case 0:
  1417. case 1:
  1418. ret = bd37033_lpf_setup(my_bd, BD37033_LPF_SETUP_SUB_INPUT_SELECT_TYPE,input);
  1419. break;
  1420. default:
  1421. break;
  1422. }
  1423. return ret;
  1424. }
  1425. static int get_sub_output_select (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1426. {
  1427. ucontrol->value.integer.value[0] = (select_data.select_data_lpf_setup >> 4) & 0x03;
  1428. return 0;
  1429. }
  1430. static int set_sub_output_select (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1431. {
  1432. int ret = -1;
  1433. unsigned char output = (select_data.select_data_lpf_setup >> 4) & 0x03;
  1434. if (output == ucontrol->value.integer.value[0])
  1435. return 0;
  1436. output = ucontrol->value.integer.value[0];
  1437. switch(output)
  1438. {
  1439. case 0:
  1440. case 1:
  1441. case 2:
  1442. case 3:
  1443. ret = bd37033_lpf_setup(my_bd, BD37033_LPF_SETUP_SUB_OUTPUT_SELECT_TYPE,output);
  1444. break;
  1445. default:
  1446. break;
  1447. }
  1448. return ret;
  1449. }
  1450. static int get_sub_lpf_parse (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1451. {
  1452. ucontrol->value.integer.value[0] = (select_data.select_data_lpf_setup >> 7) & 0x01;
  1453. return 0;
  1454. }
  1455. static int set_sub_lpf_parse (struct snd_kcontrol * kcontrol, struct snd_ctl_elem_value * ucontrol)
  1456. {
  1457. int ret = -1;
  1458. unsigned char parse = (select_data.select_data_lpf_setup >> 7) & 0x01;
  1459. if (parse == ucontrol->value.integer.value[0])
  1460. return 0;
  1461. parse = ucontrol->value.integer.value[0];
  1462. switch(parse)
  1463. {
  1464. case 0:
  1465. case 1:
  1466. ret = bd37033_lpf_setup(my_bd, BD37033_LPF_SETUP_LPF_PHASE_TYPE,parse);
  1467. break;
  1468. default:
  1469. break;
  1470. }
  1471. return ret;
  1472. }
  1473. static const char *stream_select[] = {
  1474. "A_SINGLE",
  1475. "B_SINGLE",
  1476. "C_SINGLE:BT",
  1477. "D_SINGLE:NAVI",
  1478. "E1_SINGLE:RADIO",
  1479. "E2_SINGLE:AUX",
  1480. "D_DIFF:D",
  1481. "E_FULL_DIFF:E1+E2",
  1482. "INPUT_SHORT:ALL",
  1483. };
  1484. static const char *stream_full_diff_type_select[] = {
  1485. "FULL_DIFF_TYPE:NEGATIVE INPUT",
  1486. "FULL_DIFF_TYPE:BIAS",
  1487. };
  1488. static const char *bass_q_switch[] = {
  1489. "BASS_Q:0.5",
  1490. "BASS_Q:1.0",
  1491. "BASS_Q:1.5",
  1492. "BASS_Q:2.0",
  1493. };
  1494. static const char *middle_q_switch[] = {
  1495. "MIDDLE_Q:0.75",
  1496. "MIDDLE_Q:1.00",
  1497. "MIDDLE_Q:1.25",
  1498. "MIDDLE_Q:1.50",
  1499. };
  1500. static const char *treble_q_switch[] = {
  1501. "TREBLE_Q:0.75",
  1502. "TREBLE_Q:1.25",
  1503. };
  1504. static const char *bass_f0_switch[] = {
  1505. "BASS_F0:60HZ",
  1506. "BASS_F0:80HZ",
  1507. "BASS_F0:100HZ",
  1508. "BASS_F0:120HZ",
  1509. };
  1510. static const char *middle_f0_switch[] = {
  1511. "MIDDLE_F0:0.5KHZ",
  1512. "MIDDLE_F0:1KHZ",
  1513. "MIDDLE_F0:1.5KHZ",
  1514. "MIDDLE_F0:2.5KHZ",
  1515. };
  1516. static const char *treble_f0_switch[] = {
  1517. "TREBLE_F0:7.5KHZ",
  1518. "TREBLE_F0:10KHZ",
  1519. "TREBLE_F0:12.5KHZ",
  1520. "TREBLE_F0:15KHZ",
  1521. };
  1522. static const char *loudness_f0_switch[] = {
  1523. "LOUDNESS_F0:400HZ",
  1524. "LOUDNESS_F0:800HZ",
  1525. "LOUDNESS_F0:2400HZ",
  1526. };
  1527. static const char *loudness_hicut_switch[] = {
  1528. "HI_CUT:0",
  1529. "HI_CUT:1",
  1530. "HI_CUT:2",
  1531. "HI_CUT:3",
  1532. };
  1533. static const char *mixing_input_select[] = {
  1534. "MIN",
  1535. "A_SINGLE",
  1536. "B_SINGLE",
  1537. };
  1538. static const char *mixing_channel_select[] = {
  1539. "ON",
  1540. "OFF",
  1541. };
  1542. static const char *mute_switch[] = {
  1543. "OFF",
  1544. "ON",
  1545. };
  1546. static const char *reset_switch[] = {
  1547. "RESET",
  1548. };
  1549. static const char *lpf_fc[] = {
  1550. "OFF",
  1551. "55HZ",
  1552. "85HZ",
  1553. "120HZ",
  1554. "160HZ",
  1555. "PASS",
  1556. };
  1557. static const char *sub_input_select[] = {
  1558. "LOUDNESS",
  1559. "INPUT SELECTOR",
  1560. };
  1561. static const char *sub_output_select[] = {
  1562. "LPF",
  1563. "FRONT",
  1564. "REAR",
  1565. "SUBWOOFER",
  1566. };
  1567. static const char *sub_lpf_parse[] = {
  1568. "0",
  1569. "180",
  1570. };
  1571. static const struct soc_enum stream_sel_enum =
  1572. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(stream_select), stream_select);
  1573. static const struct soc_enum stream_full_diff_type_sel_enum =
  1574. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(stream_full_diff_type_select), stream_full_diff_type_select);
  1575. static const struct soc_enum mixing_channel1_enum =
  1576. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(mixing_channel_select), mixing_channel_select);
  1577. static const struct soc_enum mixing_channel2_enum =
  1578. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(mixing_channel_select), mixing_channel_select);
  1579. static const struct soc_enum loudness_f0_select_enum =
  1580. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(loudness_f0_switch), loudness_f0_switch);
  1581. static const struct soc_enum mixing_input_select_enum =
  1582. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(mixing_input_select), mixing_input_select);
  1583. static const struct soc_enum loudness_hicut_select_enum =
  1584. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(loudness_hicut_switch), loudness_hicut_switch);
  1585. static const struct soc_enum bass_q_switch_enum =
  1586. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(bass_q_switch), bass_q_switch);
  1587. static const struct soc_enum middle_q_switch_enum =
  1588. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(middle_q_switch), middle_q_switch);
  1589. static const struct soc_enum treble_q_switch_enum =
  1590. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(treble_q_switch), treble_q_switch);
  1591. static const struct soc_enum bass_f0_switch_enum =
  1592. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(bass_f0_switch), bass_f0_switch);
  1593. static const struct soc_enum middle_f0_switch_enum =
  1594. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(middle_f0_switch), middle_f0_switch);
  1595. static const struct soc_enum treble_f0_switch_enum =
  1596. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(treble_f0_switch), treble_f0_switch);
  1597. static const struct soc_enum mute_switch_enum =
  1598. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(mute_switch), mute_switch);
  1599. static const struct soc_enum reset_enum =
  1600. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(reset_switch), reset_switch);
  1601. static const struct soc_enum sub_lpf_fc_enum =
  1602. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(lpf_fc), lpf_fc);
  1603. static const struct soc_enum sub_input_select_enum =
  1604. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sub_input_select), sub_input_select);
  1605. static const struct soc_enum sub_output_select_enum =
  1606. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sub_output_select), sub_output_select);
  1607. static const struct soc_enum sub_lpf_parse_enum =
  1608. SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(sub_lpf_parse), sub_lpf_parse);
  1609. static const struct snd_kcontrol_new bd37033_controls[] = {
  1610. SOC_SINGLE_EXT("EQ Bass", 0, 0, 30, 0,
  1611. get_bass_gain, set_bass_gain),
  1612. SOC_ENUM_EXT("EQ BassF0", bass_f0_switch_enum,
  1613. get_bass_f0, set_bass_f0),
  1614. SOC_ENUM_EXT("EQ BassQ", bass_q_switch_enum,
  1615. get_bass_q, set_bass_q),
  1616. SOC_SINGLE_EXT("EQ Middle", 0, 0, 30, 0,
  1617. get_middle_gain, set_middle_gain),
  1618. SOC_ENUM_EXT("EQ MiddleF0", middle_f0_switch_enum,
  1619. get_middle_f0, set_middle_f0),
  1620. SOC_ENUM_EXT("EQ MiddleQ", middle_q_switch_enum,
  1621. get_middle_q, set_middle_q),
  1622. SOC_SINGLE_EXT("EQ Treble", 0, 0, 30, 0,
  1623. get_treble_gain, set_treble_gain),
  1624. SOC_ENUM_EXT("EQ TrebleF0", treble_f0_switch_enum,
  1625. get_treble_f0, set_treble_f0),
  1626. SOC_ENUM_EXT("EQ TrebleQ", treble_q_switch_enum,
  1627. get_treble_q, set_treble_q),
  1628. SOC_SINGLE_EXT("PA Input-Gain", 0, 0, 16, 0,
  1629. get_stream_gain, set_stream_gain),
  1630. SOC_ENUM_EXT("PA Input Select", stream_sel_enum,
  1631. get_stream, set_stream),
  1632. SOC_ENUM_EXT("PA Input-Full-Diff-Type Select", stream_full_diff_type_sel_enum,
  1633. get_stream_full_diff_type, set_stream_full_diff_type),
  1634. SOC_SINGLE_EXT("PA Fader-FL", 0, 0, 95, 0,
  1635. get_fl_fader, set_fl_fader),
  1636. SOC_SINGLE_EXT("PA Fader-FR", 0, 0, 95, 0,
  1637. get_fr_fader, set_fr_fader),
  1638. SOC_SINGLE_EXT("PA Fader-RL", 0, 0, 95, 0,
  1639. get_rl_fader, set_rl_fader),
  1640. SOC_SINGLE_EXT("PA Fader-RR", 0, 0, 95, 0,
  1641. get_rr_fader, set_rr_fader),
  1642. SOC_SINGLE_EXT("PA Fader-Sub1", 0, 0, 95, 0,
  1643. get_sub1_fader, set_sub1_fader),
  1644. SOC_SINGLE_EXT("PA Fader-Sub2", 0, 0, 95, 0,
  1645. get_sub2_fader, set_sub2_fader),
  1646. SOC_ENUM_EXT("PA Mute", mute_switch_enum,
  1647. get_mute_status, set_mute_status),
  1648. SOC_ENUM_EXT("PA Reset", reset_enum,
  1649. get_reset, set_reset),
  1650. SOC_SINGLE_EXT("PA Volume", 0, 0, 95, 0,
  1651. get_volume, set_volume),
  1652. SOC_SINGLE_EXT("PA Loudness", 0, 0, 15, 0,
  1653. get_loudness, set_loudness),
  1654. SOC_ENUM_EXT("PA Loudness-HiCut Select", loudness_hicut_select_enum,
  1655. get_loudness_hicut, set_loudness_hicut),
  1656. SOC_ENUM_EXT("PA Loudness-F0 Select", loudness_f0_select_enum,
  1657. get_loudness_f0, set_loudness_f0),
  1658. SOC_ENUM_EXT("PA Mixing-CH1 Switch", mixing_channel1_enum,
  1659. get_mixing_channel1_switch, set_mixing_channel1_switch),
  1660. SOC_ENUM_EXT("PA Mixing-CH2 Switch", mixing_channel2_enum,
  1661. get_mixing_channel2_switch, set_mixing_channel2_switch),
  1662. SOC_ENUM_EXT("PA Mixing-Input Select", mixing_input_select_enum,
  1663. get_mixing_input_select, set_mixing_input_select),
  1664. SOC_ENUM_EXT("PA Sub-Input Select", sub_input_select_enum,
  1665. get_sub_input_select, set_sub_input_select),
  1666. SOC_ENUM_EXT("PA Sub-LPF-FC Select", sub_lpf_fc_enum,
  1667. get_lpf_fc, set_lpf_fc),
  1668. SOC_ENUM_EXT("PA Sub-LPF-Parse Select", sub_lpf_parse_enum,
  1669. get_sub_lpf_parse, set_sub_lpf_parse),
  1670. SOC_ENUM_EXT("PA Sub-Output Select", sub_output_select_enum,
  1671. get_sub_output_select, set_sub_output_select),
  1672. };
  1673. static int bd37033_startup(struct snd_pcm_substream *substream,struct snd_soc_dai *dai)
  1674. {
  1675. int ret = 0;
  1676. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  1677. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  1678. /* variable MCLK */
  1679. // ret = snd_soc_dai_set_sysclk(codec_dai, 0, 0, SND_SOC_CLOCK_IN);
  1680. return ret;
  1681. }
  1682. static int bd37033_hw_params(
  1683. struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params,struct snd_soc_dai *dai)
  1684. {
  1685. void __iomem *Sys_base;
  1686. unsigned int val;
  1687. #if 0
  1688. Sys_base = ioremap(0xe4900000, 0x1ff);
  1689. //cancel pop noise
  1690. /*val = readl(Sys_base + 0x6c);
  1691. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  1692. val &= ~(1 << 2);
  1693. } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
  1694. val &= ~(1 << 0);
  1695. }
  1696. writel(val,Sys_base+0x6c);*/
  1697. unsigned int rate = params_rate(params);
  1698. //printk("==============[%s]:[ %d] rate = %d\n", __FUNCTION__, __LINE__,rate);
  1699. switch (params_rate(params)) {
  1700. case 192000:
  1701. val = (768 << 16) | 1875;
  1702. break;
  1703. case 96000:
  1704. val = (384 << 16) | 1875;
  1705. break;
  1706. case 48000:
  1707. val = (192 << 16) | 1875;
  1708. break;
  1709. case 44100:
  1710. val = (1764 << 16) | 18750;
  1711. break;
  1712. case 32000:
  1713. val = (128 << 16) | 1875;
  1714. break;
  1715. case 24000:
  1716. val = (96 << 16) | 1875;
  1717. break;
  1718. case 22050:
  1719. val = (882 << 16) | 18750;
  1720. break;
  1721. case 16000:
  1722. val = (64 << 16) | 1875;
  1723. break;
  1724. case 12000:
  1725. val = (48 << 16) | 1875;
  1726. break;
  1727. case 11025:
  1728. val = (441 << 16) | 18750;
  1729. break;
  1730. case 8000:
  1731. val = (32 << 16) | 1875;
  1732. break;
  1733. case 4000:
  1734. val = (16 << 16) | 1875;
  1735. break;
  1736. default:
  1737. val = (1764 << 16) | 18750;
  1738. }
  1739. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  1740. writel(val, Sys_base + 0x19c);
  1741. } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
  1742. writel(val, Sys_base + 0x174);
  1743. }
  1744. iounmap(Sys_base);
  1745. #endif
  1746. return 0;
  1747. }
  1748. #if 1
  1749. #define bd37033_RATES SNDRV_PCM_RATE_8000_96000
  1750. #define bd37033_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  1751. SNDRV_PCM_FMTBIT_S24_LE)
  1752. //static int bd37033_probe(struct snd_soc_codec *codec)
  1753. static int bd37033_probe(struct snd_soc_component *component)
  1754. {
  1755. return 0;
  1756. }
  1757. //static int bd37033_remove(struct snd_soc_codec *codec)
  1758. static void bd37033_remove(struct snd_soc_component *component)
  1759. {//printk("==============[%s]:[ %d]\n", __FUNCTION__, __LINE__);
  1760. return 0;
  1761. }
  1762. //static int bd37033_suspend(struct snd_soc_codec *codec)
  1763. static int bd37033_suspend(struct snd_soc_component *component)
  1764. {//printk("==============[%s]:[ %d]\n", __FUNCTION__, __LINE__);
  1765. return 0;
  1766. }
  1767. //static int bd37033_resume(struct snd_soc_codec *codec)
  1768. static int bd37033_resume(struct snd_soc_component *component)
  1769. {//printk("==============[%s]:[ %d]\n", __FUNCTION__, __LINE__);
  1770. return 0;
  1771. }
  1772. //static int bd37033_set_bias_level(struct snd_soc_codec *codec,
  1773. // enum snd_soc_bias_level level)
  1774. static int bd37033_set_bias_level(struct snd_soc_component *component,
  1775. enum snd_soc_bias_level level)
  1776. {//printk("==============[%s]:[ %d]\n", __FUNCTION__, __LINE__);
  1777. return 0;
  1778. }
  1779. static struct snd_soc_dai_ops bd37033_dai_ops = {
  1780. .startup = bd37033_startup,
  1781. .hw_params = bd37033_hw_params,
  1782. };
  1783. static struct snd_soc_dai_driver bd37033_dai[]={
  1784. #if 1
  1785. {
  1786. .name = "bd37033-lineout",
  1787. .playback = {
  1788. .stream_name = "Lineout Playback",
  1789. .channels_min = 1,
  1790. .channels_max = 2,
  1791. .rates = bd37033_RATES,
  1792. .formats = bd37033_FORMATS,
  1793. },
  1794. .ops = &bd37033_dai_ops,
  1795. },
  1796. #else
  1797. {
  1798. .name = "bd37033-rlineout",
  1799. .playback = {
  1800. .stream_name = "RLineout Playback",//RL_OUT RR_OUT
  1801. .channels_min = 1,
  1802. .channels_max = 2,
  1803. .rates = bd37033_RATES,
  1804. .formats = bd37033_FORMATS,
  1805. },
  1806. .ops = &bd37033_dai_ops,
  1807. },
  1808. {
  1809. .name = "bd37033-flineout",
  1810. .playback = {
  1811. .stream_name = "FLineout Playback",//FL_OUT FR_OUT
  1812. .channels_min = 1,
  1813. .channels_max = 2,
  1814. .rates = bd37033_RATES,
  1815. .formats = bd37033_FORMATS,
  1816. },
  1817. .ops = &bd37033_dai_ops,
  1818. },
  1819. #endif
  1820. };
  1821. //static struct snd_soc_codec_driver soc_codec_dev_bd37033= {
  1822. static struct snd_soc_component_driver soc_component_dev_bd37033= {
  1823. .probe = bd37033_probe,
  1824. .remove = bd37033_remove,
  1825. .suspend = bd37033_suspend,
  1826. .resume = bd37033_resume,
  1827. .set_bias_level = bd37033_set_bias_level,
  1828. //.component_driver = {
  1829. .controls = bd37033_controls,
  1830. .num_controls = ARRAY_SIZE(bd37033_controls),
  1831. //},
  1832. };
  1833. #endif
  1834. //static void clock_init(void)
  1835. //{
  1836. // void __iomem *Sys_base;
  1837. // unsigned int val;
  1838. // //select 240M clk source
  1839. // Sys_base = ioremap(0xe4900000, 0x1ff);
  1840. // val = readl(Sys_base + 0x6c);
  1841. // val &= ~((1 << 2) | (1 << 0));
  1842. // writel(val,Sys_base+0x6c);
  1843. // iounmap(Sys_base);
  1844. //}
  1845. static ssize_t bd37033_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  1846. {
  1847. int val=0, flag=0;
  1848. u8 i=0, reg, num, value_w, value_r;
  1849. struct bd37033_data *bd = dev_get_drvdata(dev);
  1850. val = simple_strtol(buf, NULL, 16);
  1851. flag = (val >> 16) & 0xFF;
  1852. if (flag) {
  1853. reg = (val >> 8) & 0xFF;
  1854. value_w = val & 0xFF;
  1855. printk("\nWrite: start REG:0x%02x,val:0x%02x,count:0x%02x\n", reg, value_w, flag);
  1856. while(flag--) {
  1857. register_write(reg, value_w);
  1858. printk("Write 0x%02x to REG:0x%02x\n", value_w, reg);
  1859. reg++;
  1860. }
  1861. } else {
  1862. reg = (val >> 8) & 0xFF;
  1863. num = val & 0xff;
  1864. printk("\nRead: start REG:0x%02x,count:0x%02x\n", reg, num);
  1865. do {
  1866. value_r = 0;
  1867. //es7210_read(reg, &value_r, bd->client);
  1868. value_r = register_read(reg);
  1869. printk("REG[0x%02x]: 0x%02x; ", reg, value_r);
  1870. reg++;
  1871. i++;
  1872. if ((i==num) || (i%4==0)) printk("\n");
  1873. } while (i<num);
  1874. }
  1875. return count;
  1876. }
  1877. static ssize_t bd37033_show(struct device *dev, struct device_attribute *attr, char *buf)
  1878. {
  1879. printk("echo flag|reg|val > bd37033\n");
  1880. printk("eg read star addres=0x06,count 0x10:echo 0610 >bd37033\n");
  1881. printk("eg write star addres=0x90,value=0x3c,count=4:echo 4903c >bd37033\n");
  1882. //printk("eg write value:0xfe to address:0x06 :echo 106fe > bd37033\n");
  1883. return 0;
  1884. }
  1885. static DEVICE_ATTR(bd37033, 0644, bd37033_show, bd37033_store);
  1886. static struct attribute *bd37033_debug_attrs[] = {
  1887. &dev_attr_bd37033.attr,
  1888. NULL,
  1889. };
  1890. static struct attribute_group bd37033_debug_attr_group = {
  1891. .name = "bd37033_debug",
  1892. .attrs = bd37033_debug_attrs,
  1893. };
  1894. static int bd37033_drv_probe(struct i2c_client *client, const struct i2c_device_id *id)
  1895. { //printk("==============[%s]:[ %d]\n", __FUNCTION__, __LINE__);
  1896. struct bd37033_data *bd;
  1897. int ret = -1;
  1898. //printk(KERN_INFO "==============>%s\n", __FUNCTION__);
  1899. bd = devm_kzalloc(&client->dev, sizeof(struct bd37033_data), GFP_KERNEL);
  1900. if (!bd)
  1901. return -ENOMEM;
  1902. bd->pd.reg_base = I2S_BASE,
  1903. bd->pd.reg_size = 0xFF,
  1904. bd->client = client;
  1905. bd->id = id;
  1906. my_bd = bd;
  1907. i2c_set_clientdata(client, bd);
  1908. bd37033_init(bd); //have to behind i2c_set_clientdata(client, bd);
  1909. // ret = snd_soc_register_codec(&client->dev,
  1910. // &soc_codec_dev_bd37033, bd37033_dai,
  1911. // ARRAY_SIZE(bd37033_dai));
  1912. // ret = devm_snd_soc_register_component(&client->dev,
  1913. // &soc_component_dev_bd37033, bd37033_dai,
  1914. // ARRAY_SIZE(bd37033_dai));
  1915. ret = devm_snd_soc_register_component(&client->dev,
  1916. &soc_component_dev_bd37033, NULL,
  1917. 0);
  1918. if (ret < 0) {
  1919. dev_err(&client->dev, "Failed to register codec: %d\n", ret);
  1920. }
  1921. ret = sysfs_create_group(&client->dev.kobj, &bd37033_debug_attr_group);
  1922. if (ret) {
  1923. pr_err("failed to create attr group\n");
  1924. }
  1925. //printk(KERN_INFO "==============>%s end\n", __FUNCTION__);
  1926. return ret;
  1927. }
  1928. static int bd37033_drv_remove(struct i2c_client *client)
  1929. {
  1930. struct bd37033_data *bd = i2c_get_clientdata(client);
  1931. if (!bd)
  1932. {
  1933. printk(KERN_ERR "err %s, no device to remove\n",__FUNCTION__);
  1934. return -ENODEV;
  1935. }
  1936. if(bd)
  1937. kfree(bd);
  1938. i2c_set_clientdata(client, NULL);
  1939. return 0;
  1940. }
  1941. static void bd37033_drv_shutdown(struct i2c_client *client)
  1942. {
  1943. struct bd37033_data *bd = i2c_get_clientdata(client);
  1944. if(bd)
  1945. {
  1946. if(bd37033_set_mute(bd,MUTE_ON) == 0)
  1947. mute_status = MUTE_ON;
  1948. }
  1949. }
  1950. static const struct i2c_device_id BD37033_drv_id[] = {
  1951. {"drv_bd37033", 0},
  1952. {}
  1953. };
  1954. MODULE_DEVICE_TABLE(i2c, BD37033_drv_id);
  1955. static const struct of_device_id BD37033_drv_of_match[] = {
  1956. { .compatible = "arkmicro,drv_bd37033" },
  1957. { }
  1958. };
  1959. MODULE_DEVICE_TABLE(of, BD37033_drv_of_match);
  1960. static struct i2c_driver drv_bd37033_driver = {
  1961. .driver = {
  1962. .name = "drv_bd37033",
  1963. .of_match_table = BD37033_drv_of_match,
  1964. .owner = THIS_MODULE,
  1965. },
  1966. .id_table = BD37033_drv_id,
  1967. .probe = bd37033_drv_probe,
  1968. .remove = bd37033_drv_remove,
  1969. .shutdown = bd37033_drv_shutdown,
  1970. };
  1971. static int __init drv_bd37033_init(void)
  1972. {
  1973. return i2c_add_driver(&drv_bd37033_driver);
  1974. }
  1975. static void __exit drv_bd37033_exit(void)
  1976. {
  1977. i2c_del_driver(&drv_bd37033_driver);
  1978. }
  1979. module_init(drv_bd37033_init);
  1980. module_exit(drv_bd37033_exit);
  1981. MODULE_AUTHOR("n@n.com");
  1982. MODULE_DESCRIPTION("ark_drv");
  1983. MODULE_LICENSE("GPL");