BD37033.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254
  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 0
  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);
  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. {//printk("==============[%s]:[ %d]\n", __FUNCTION__, __LINE__);
  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. {//printk("==============[%s]:[ %d]\n", __FUNCTION__, __LINE__);
  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. Sys_base = ioremap(0xe4900000, 0x1ff);
  1688. //cancel pop noise
  1689. /*val = readl(Sys_base + 0x6c);
  1690. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  1691. val &= ~(1 << 2);
  1692. } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
  1693. val &= ~(1 << 0);
  1694. }
  1695. writel(val,Sys_base+0x6c);*/
  1696. unsigned int rate = params_rate(params);
  1697. //printk("==============[%s]:[ %d] rate = %d\n", __FUNCTION__, __LINE__,rate);
  1698. switch (params_rate(params)) {
  1699. case 192000:
  1700. val = (768 << 16) | 1875;
  1701. break;
  1702. case 96000:
  1703. val = (384 << 16) | 1875;
  1704. break;
  1705. case 48000:
  1706. val = (192 << 16) | 1875;
  1707. break;
  1708. case 44100:
  1709. val = (1764 << 16) | 18750;
  1710. break;
  1711. case 32000:
  1712. val = (128 << 16) | 1875;
  1713. break;
  1714. case 24000:
  1715. val = (96 << 16) | 1875;
  1716. break;
  1717. case 22050:
  1718. val = (882 << 16) | 18750;
  1719. break;
  1720. case 16000:
  1721. val = (64 << 16) | 1875;
  1722. break;
  1723. case 12000:
  1724. val = (48 << 16) | 1875;
  1725. break;
  1726. case 11025:
  1727. val = (441 << 16) | 18750;
  1728. break;
  1729. case 8000:
  1730. val = (32 << 16) | 1875;
  1731. break;
  1732. case 4000:
  1733. val = (16 << 16) | 1875;
  1734. break;
  1735. default:
  1736. val = (1764 << 16) | 18750;
  1737. }
  1738. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  1739. writel(val, Sys_base + 0x19c);
  1740. } else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
  1741. writel(val, Sys_base + 0x174);
  1742. }
  1743. iounmap(Sys_base);
  1744. return 0;
  1745. }
  1746. #if 1
  1747. #define bd37033_RATES SNDRV_PCM_RATE_8000_96000
  1748. #define bd37033_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  1749. SNDRV_PCM_FMTBIT_S24_LE)
  1750. //static int bd37033_probe(struct snd_soc_codec *codec)
  1751. static int bd37033_probe(struct snd_soc_component *component)
  1752. {
  1753. return 0;
  1754. }
  1755. //static int bd37033_remove(struct snd_soc_codec *codec)
  1756. static void bd37033_remove(struct snd_soc_component *component)
  1757. {//printk("==============[%s]:[ %d]\n", __FUNCTION__, __LINE__);
  1758. return 0;
  1759. }
  1760. //static int bd37033_suspend(struct snd_soc_codec *codec)
  1761. static int bd37033_suspend(struct snd_soc_component *component)
  1762. {//printk("==============[%s]:[ %d]\n", __FUNCTION__, __LINE__);
  1763. return 0;
  1764. }
  1765. //static int bd37033_resume(struct snd_soc_codec *codec)
  1766. static int bd37033_resume(struct snd_soc_component *component)
  1767. {//printk("==============[%s]:[ %d]\n", __FUNCTION__, __LINE__);
  1768. return 0;
  1769. }
  1770. //static int bd37033_set_bias_level(struct snd_soc_codec *codec,
  1771. // enum snd_soc_bias_level level)
  1772. static int bd37033_set_bias_level(struct snd_soc_component *component,
  1773. enum snd_soc_bias_level level)
  1774. {//printk("==============[%s]:[ %d]\n", __FUNCTION__, __LINE__);
  1775. return 0;
  1776. }
  1777. static struct snd_soc_dai_ops bd37033_dai_ops = {
  1778. .startup = bd37033_startup,
  1779. .hw_params = bd37033_hw_params,
  1780. };
  1781. static struct snd_soc_dai_driver bd37033_dai[]={
  1782. #if 1
  1783. {
  1784. .name = "bd37033-lineout",
  1785. .playback = {
  1786. .stream_name = "Lineout Playback",
  1787. .channels_min = 1,
  1788. .channels_max = 2,
  1789. .rates = bd37033_RATES,
  1790. .formats = bd37033_FORMATS,
  1791. },
  1792. .ops = &bd37033_dai_ops,
  1793. },
  1794. #else
  1795. {
  1796. .name = "bd37033-rlineout",
  1797. .playback = {
  1798. .stream_name = "RLineout Playback",//RL_OUT RR_OUT
  1799. .channels_min = 1,
  1800. .channels_max = 2,
  1801. .rates = bd37033_RATES,
  1802. .formats = bd37033_FORMATS,
  1803. },
  1804. .ops = &bd37033_dai_ops,
  1805. },
  1806. {
  1807. .name = "bd37033-flineout",
  1808. .playback = {
  1809. .stream_name = "FLineout Playback",//FL_OUT FR_OUT
  1810. .channels_min = 1,
  1811. .channels_max = 2,
  1812. .rates = bd37033_RATES,
  1813. .formats = bd37033_FORMATS,
  1814. },
  1815. .ops = &bd37033_dai_ops,
  1816. },
  1817. #endif
  1818. };
  1819. //static struct snd_soc_codec_driver soc_codec_dev_bd37033= {
  1820. static struct snd_soc_component_driver soc_component_dev_bd37033= {
  1821. .probe = bd37033_probe,
  1822. .remove = bd37033_remove,
  1823. .suspend = bd37033_suspend,
  1824. .resume = bd37033_resume,
  1825. .set_bias_level = bd37033_set_bias_level,
  1826. //.component_driver = {
  1827. .controls = bd37033_controls,
  1828. .num_controls = ARRAY_SIZE(bd37033_controls),
  1829. //},
  1830. };
  1831. #endif
  1832. //static void clock_init(void)
  1833. //{
  1834. // void __iomem *Sys_base;
  1835. // unsigned int val;
  1836. // //select 240M clk source
  1837. // Sys_base = ioremap(0xe4900000, 0x1ff);
  1838. // val = readl(Sys_base + 0x6c);
  1839. // val &= ~((1 << 2) | (1 << 0));
  1840. // writel(val,Sys_base+0x6c);
  1841. // iounmap(Sys_base);
  1842. //}
  1843. static int bd37033_drv_probe(struct i2c_client *client, const struct i2c_device_id *id)
  1844. { //printk("==============[%s]:[ %d]\n", __FUNCTION__, __LINE__);
  1845. struct bd37033_data *bd;
  1846. int ret = -1;
  1847. //printk(KERN_INFO "==============>%s\n", __FUNCTION__);
  1848. bd = devm_kzalloc(&client->dev, sizeof(struct bd37033_data), GFP_KERNEL);
  1849. if (!bd)
  1850. return -ENOMEM;
  1851. bd->pd.reg_base = I2S_BASE,
  1852. bd->pd.reg_size = 0xFF,
  1853. bd->client = client;
  1854. bd->id = id;
  1855. my_bd = bd;
  1856. i2c_set_clientdata(client, bd);
  1857. bd37033_init(bd); //have to behind i2c_set_clientdata(client, bd);
  1858. // ret = snd_soc_register_codec(&client->dev,
  1859. // &soc_codec_dev_bd37033, bd37033_dai,
  1860. // ARRAY_SIZE(bd37033_dai));
  1861. ret = devm_snd_soc_register_component(&client->dev,
  1862. &soc_component_dev_bd37033, bd37033_dai,
  1863. ARRAY_SIZE(bd37033_dai));
  1864. if (ret < 0) {
  1865. dev_err(&client->dev, "Failed to register codec: %d\n", ret);
  1866. }
  1867. return ret;
  1868. //printk(KERN_INFO "==============>%s end\n", __FUNCTION__);
  1869. }
  1870. static int bd37033_drv_remove(struct i2c_client *client)
  1871. {
  1872. struct bd37033_data *bd = i2c_get_clientdata(client);
  1873. if (!bd)
  1874. {
  1875. printk(KERN_ERR "err %s, no device to remove\n",__FUNCTION__);
  1876. return -ENODEV;
  1877. }
  1878. if(bd)
  1879. kfree(bd);
  1880. i2c_set_clientdata(client, NULL);
  1881. return 0;
  1882. }
  1883. static void bd37033_drv_shutdown(struct i2c_client *client)
  1884. {
  1885. struct bd37033_data *bd = i2c_get_clientdata(client);
  1886. if(bd)
  1887. {
  1888. if(bd37033_set_mute(bd,MUTE_ON) == 0)
  1889. mute_status = MUTE_ON;
  1890. }
  1891. }
  1892. static const struct i2c_device_id BD37033_drv_id[] = {
  1893. {"drv_bd37033", 0},
  1894. {}
  1895. };
  1896. MODULE_DEVICE_TABLE(i2c, BD37033_drv_id);
  1897. static const struct of_device_id BD37033_drv_of_match[] = {
  1898. { .compatible = "arkmicro,drv_bd37033" },
  1899. { }
  1900. };
  1901. MODULE_DEVICE_TABLE(of, BD37033_drv_of_match);
  1902. static struct i2c_driver drv_bd37033_driver = {
  1903. .driver = {
  1904. .name = "drv_bd37033",
  1905. .of_match_table = BD37033_drv_of_match,
  1906. .owner = THIS_MODULE,
  1907. },
  1908. .id_table = BD37033_drv_id,
  1909. .probe = bd37033_drv_probe,
  1910. .remove = bd37033_drv_remove,
  1911. .shutdown = bd37033_drv_shutdown,
  1912. };
  1913. static int __init drv_bd37033_init(void)
  1914. {
  1915. return i2c_add_driver(&drv_bd37033_driver);
  1916. }
  1917. static void __exit drv_bd37033_exit(void)
  1918. {
  1919. i2c_del_driver(&drv_bd37033_driver);
  1920. }
  1921. module_init(drv_bd37033_init);
  1922. module_exit(drv_bd37033_exit);
  1923. MODULE_AUTHOR("n@n.com");
  1924. MODULE_DESCRIPTION("ark_drv");
  1925. MODULE_LICENSE("GPL");