ite8172.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259
  1. /*
  2. * ite8172.c -- ITE IT8172G Sound Driver.
  3. *
  4. * Copyright 2001 MontaVista Software Inc.
  5. * Author: MontaVista Software, Inc.
  6. * stevel@mvista.com or source@mvista.com
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  14. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  16. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  17. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  18. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  19. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. *
  24. * You should have received a copy of the GNU General Public License along
  25. * with this program; if not, write to the Free Software Foundation, Inc.,
  26. * 675 Mass Ave, Cambridge, MA 02139, USA.
  27. *
  28. *
  29. * Module command line parameters:
  30. *
  31. * Supported devices:
  32. * /dev/dsp standard OSS /dev/dsp device
  33. * /dev/mixer standard OSS /dev/mixer device
  34. *
  35. * Notes:
  36. *
  37. * 1. Much of the OSS buffer allocation, ioctl's, and mmap'ing are
  38. * taken, slightly modified or not at all, from the ES1371 driver,
  39. * so refer to the credits in es1371.c for those. The rest of the
  40. * code (probe, open, read, write, the ISR, etc.) is new.
  41. * 2. The following support is untested:
  42. * * Memory mapping the audio buffers, and the ioctl controls that go
  43. * with it.
  44. * * S/PDIF output.
  45. * * I2S support.
  46. * 3. The following is not supported:
  47. * * legacy audio mode.
  48. * 4. Support for volume button interrupts is implemented but doesn't
  49. * work yet.
  50. *
  51. * Revision history
  52. * 02.08.2001 Initial release
  53. * 06.22.2001 Added I2S support
  54. * 07.30.2003 Removed initialisation to zero for static variables
  55. * (spdif[NR_DEVICE], i2s_fmt[NR_DEVICE], and devindex)
  56. */
  57. #include <linux/module.h>
  58. #include <linux/string.h>
  59. #include <linux/ioport.h>
  60. #include <linux/sched.h>
  61. #include <linux/delay.h>
  62. #include <linux/sound.h>
  63. #include <linux/slab.h>
  64. #include <linux/soundcard.h>
  65. #include <linux/pci.h>
  66. #include <linux/init.h>
  67. #include <linux/poll.h>
  68. #include <linux/bitops.h>
  69. #include <linux/proc_fs.h>
  70. #include <linux/spinlock.h>
  71. #include <linux/smp_lock.h>
  72. #include <linux/ac97_codec.h>
  73. #include <linux/interrupt.h>
  74. #include <asm/io.h>
  75. #include <asm/dma.h>
  76. #include <asm/uaccess.h>
  77. #include <asm/it8172/it8172.h>
  78. /* --------------------------------------------------------------------- */
  79. #undef OSS_DOCUMENTED_MIXER_SEMANTICS
  80. #define IT8172_DEBUG
  81. #undef IT8172_VERBOSE_DEBUG
  82. #define DBG(x) {}
  83. #define IT8172_MODULE_NAME "IT8172 audio"
  84. #define PFX IT8172_MODULE_NAME
  85. #ifdef IT8172_DEBUG
  86. #define dbg(format, arg...) printk(KERN_DEBUG PFX ": " format "\n" , ## arg)
  87. #else
  88. #define dbg(format, arg...) do {} while (0)
  89. #endif
  90. #define err(format, arg...) printk(KERN_ERR PFX ": " format "\n" , ## arg)
  91. #define info(format, arg...) printk(KERN_INFO PFX ": " format "\n" , ## arg)
  92. #define warn(format, arg...) printk(KERN_WARNING PFX ": " format "\n" , ## arg)
  93. #define IT8172_MODULE_NAME "IT8172 audio"
  94. #define PFX IT8172_MODULE_NAME
  95. #ifdef IT8172_DEBUG
  96. #define dbg(format, arg...) printk(KERN_DEBUG PFX ": " format "\n" , ## arg)
  97. #else
  98. #define dbg(format, arg...) do {} while (0)
  99. #endif
  100. #define err(format, arg...) printk(KERN_ERR PFX ": " format "\n" , ## arg)
  101. #define info(format, arg...) printk(KERN_INFO PFX ": " format "\n" , ## arg)
  102. #define warn(format, arg...) printk(KERN_WARNING PFX ": " format "\n" , ## arg)
  103. static const unsigned sample_shift[] = { 0, 1, 1, 2 };
  104. /*
  105. * Audio Controller register bit definitions follow. See
  106. * include/asm/it8172/it8172.h for register offsets.
  107. */
  108. /* PCM Out Volume Reg */
  109. #define PCMOV_PCMOM (1<<15) /* PCM Out Mute default 1: mute */
  110. #define PCMOV_PCMRCG_BIT 8 /* PCM Right channel Gain */
  111. #define PCMOV_PCMRCG_MASK (0x1f<<PCMOV_PCMRCG_BIT)
  112. #define PCMOV_PCMLCG_BIT 0 /* PCM Left channel gain */
  113. #define PCMOV_PCMLCG_MASK 0x1f
  114. /* FM Out Volume Reg */
  115. #define FMOV_FMOM (1<<15) /* FM Out Mute default 1: mute */
  116. #define FMOV_FMRCG_BIT 8 /* FM Right channel Gain */
  117. #define FMOV_FMRCG_MASK (0x1f<<FMOV_FMRCG_BIT)
  118. #define FMOV_FMLCG_BIT 0 /* FM Left channel gain */
  119. #define FMOV_FMLCG_MASK 0x1f
  120. /* I2S Out Volume Reg */
  121. #define I2SV_I2SOM (1<<15) /* I2S Out Mute default 1: mute */
  122. #define I2SV_I2SRCG_BIT 8 /* I2S Right channel Gain */
  123. #define I2SV_I2SRCG_MASK (0x1f<<I2SV_I2SRCG_BIT)
  124. #define I2SV_I2SLCG_BIT 0 /* I2S Left channel gain */
  125. #define I2SV_I2SLCG_MASK 0x1f
  126. /* Digital Recording Source Select Reg */
  127. #define DRSS_BIT 0
  128. #define DRSS_MASK 0x07
  129. #define DRSS_AC97_PRIM 0
  130. #define DRSS_FM 1
  131. #define DRSS_I2S 2
  132. #define DRSS_PCM 3
  133. #define DRSS_AC97_SEC 4
  134. /* Playback/Capture Channel Control Registers */
  135. #define CC_SM (1<<15) /* Stereo, Mone 0: mono 1: stereo */
  136. #define CC_DF (1<<14) /* Data Format 0: 8 bit 1: 16 bit */
  137. #define CC_FMT_BIT 14
  138. #define CC_FMT_MASK (0x03<<CC_FMT_BIT)
  139. #define CC_CF_BIT 12 /* Channel format (Playback only) */
  140. #define CC_CF_MASK (0x03<<CC_CF_BIT)
  141. #define CC_CF_2 0
  142. #define CC_CF_4 (1<<CC_CF_BIT)
  143. #define CC_CF_6 (2<<CC_CF_BIT)
  144. #define CC_SR_BIT 8 /* sample Rate */
  145. #define CC_SR_MASK (0x0f<<CC_SR_BIT)
  146. #define CC_SR_5500 0
  147. #define CC_SR_8000 (1<<CC_SR_BIT)
  148. #define CC_SR_9600 (2<<CC_SR_BIT)
  149. #define CC_SR_11025 (3<<CC_SR_BIT)
  150. #define CC_SR_16000 (4<<CC_SR_BIT)
  151. #define CC_SR_19200 (5<<CC_SR_BIT)
  152. #define CC_SR_22050 (6<<CC_SR_BIT)
  153. #define CC_SR_32000 (7<<CC_SR_BIT)
  154. #define CC_SR_38400 (8<<CC_SR_BIT)
  155. #define CC_SR_44100 (9<<CC_SR_BIT)
  156. #define CC_SR_48000 (10<<CC_SR_BIT)
  157. #define CC_CSP (1<<7) /* Channel stop
  158. * 0: End of Current buffer
  159. * 1: Immediately stop when rec stop */
  160. #define CC_CP (1<<6) /* Channel pause 0: normal, 1: pause */
  161. #define CC_CA (1<<5) /* Channel Action 0: Stop , 1: start */
  162. #define CC_CB2L (1<<2) /* Cur. buf. 2 xfr is last 0: No, 1: Yes */
  163. #define CC_CB1L (1<<1) /* Cur. buf. 1 xfr is last 0: No, 1: Yes */
  164. #define CC_DE 1 /* DFC/DFIFO Data Empty 1: empty, 0: not empty
  165. * (Playback only)
  166. */
  167. /* Codec Control Reg */
  168. #define CODECC_GME (1<<9) /* AC97 GPIO Mode enable */
  169. #define CODECC_ATM (1<<8) /* AC97 ATE test mode 0: test 1: normal */
  170. #define CODECC_WR (1<<6) /* AC97 Warn reset 1: warm reset , 0: Normal */
  171. #define CODECC_CR (1<<5) /* AC97 Cold reset 1: Cold reset , 0: Normal */
  172. /* I2S Control Reg */
  173. #define I2SMC_SR_BIT 6 /* I2S Sampling rate
  174. * 00: 48KHz, 01: 44.1 KHz, 10: 32 32 KHz */
  175. #define I2SMC_SR_MASK (0x03<<I2SMC_SR_BIT)
  176. #define I2SMC_SR_48000 0
  177. #define I2SMC_SR_44100 (1<<I2SMC_SR_BIT)
  178. #define I2SMC_SR_32000 (2<<I2SMC_SR_BIT)
  179. #define I2SMC_SRSS (1<<5) /* Sample Rate Source Select 1:S/W, 0: H/W */
  180. #define I2SMC_I2SF_BIT 0 /* I2S Format */
  181. #define I2SMC_I2SF_MASK 0x03
  182. #define I2SMC_I2SF_DAC 0
  183. #define I2SMC_I2SF_ADC 2
  184. #define I2SMC_I2SF_I2S 3
  185. /* Volume up, Down, Mute */
  186. #define VS_VMP (1<<2) /* Volume mute 1: pushed, 0: not */
  187. #define VS_VDP (1<<1) /* Volume Down 1: pushed, 0: not */
  188. #define VS_VUP 1 /* Volime Up 1: pushed, 0: not */
  189. /* SRC, Mixer test control/DFC status reg */
  190. #define SRCS_DPUSC (1<<5) /* DFC Playback underrun Status/clear */
  191. #define SRCS_DCOSC (1<<4) /* DFC Capture Overrun Status/clear */
  192. #define SRCS_SIS (1<<3) /* SRC input select 1: Mixer, 0: Codec I/F */
  193. #define SRCS_CDIS_BIT 0 /* Codec Data Input Select */
  194. #define SRCS_CDIS_MASK 0x07
  195. #define SRCS_CDIS_MIXER 0
  196. #define SRCS_CDIS_PCM 1
  197. #define SRCS_CDIS_I2S 2
  198. #define SRCS_CDIS_FM 3
  199. #define SRCS_CDIS_DFC 4
  200. /* Codec Index Reg command Port */
  201. #define CIRCP_CID_BIT 10
  202. #define CIRCP_CID_MASK (0x03<<CIRCP_CID_BIT)
  203. #define CIRCP_CPS (1<<9) /* Command Port Status 0: ready, 1: busy */
  204. #define CIRCP_DPVF (1<<8) /* Data Port Valid Flag 0: invalis, 1: valid */
  205. #define CIRCP_RWC (1<<7) /* Read/write command */
  206. #define CIRCP_CIA_BIT 0
  207. #define CIRCP_CIA_MASK 0x007F /* Codec Index Address */
  208. /* Test Mode Control/Test group Select Control */
  209. /* General Control Reg */
  210. #define GC_VDC_BIT 6 /* Volume Division Control */
  211. #define GC_VDC_MASK (0x03<<GC_VDC_BIT)
  212. #define GC_VDC_NONE 0
  213. #define GC_VDC_DIV2 (1<<GC_VDC_BIT)
  214. #define GC_VDC_DIV4 (2<<GC_VDC_BIT)
  215. #define GC_SOE (1<<2) /* S/PDIF Output enable */
  216. #define GC_SWR 1 /* Software warn reset */
  217. /* Interrupt mask Control Reg */
  218. #define IMC_VCIM (1<<6) /* Volume CNTL interrupt mask */
  219. #define IMC_CCIM (1<<1) /* Capture Chan. iterrupt mask */
  220. #define IMC_PCIM 1 /* Playback Chan. interrupt mask */
  221. /* Interrupt status/clear reg */
  222. #define ISC_VCI (1<<6) /* Volume CNTL interrupt 1: clears */
  223. #define ISC_CCI (1<<1) /* Capture Chan. interrupt 1: clears */
  224. #define ISC_PCI 1 /* Playback Chan. interrupt 1: clears */
  225. /* misc stuff */
  226. #define POLL_COUNT 0x5000
  227. /* --------------------------------------------------------------------- */
  228. /*
  229. * Define DIGITAL1 as the I2S channel, since it is not listed in
  230. * soundcard.h.
  231. */
  232. #define SOUND_MIXER_I2S SOUND_MIXER_DIGITAL1
  233. #define SOUND_MASK_I2S SOUND_MASK_DIGITAL1
  234. #define SOUND_MIXER_READ_I2S MIXER_READ(SOUND_MIXER_I2S)
  235. #define SOUND_MIXER_WRITE_I2S MIXER_WRITE(SOUND_MIXER_I2S)
  236. /* --------------------------------------------------------------------- */
  237. struct it8172_state {
  238. /* list of it8172 devices */
  239. struct list_head devs;
  240. /* the corresponding pci_dev structure */
  241. struct pci_dev *dev;
  242. /* soundcore stuff */
  243. int dev_audio;
  244. /* hardware resources */
  245. unsigned long io;
  246. unsigned int irq;
  247. /* PCI ID's */
  248. u16 vendor;
  249. u16 device;
  250. u8 rev; /* the chip revision */
  251. /* options */
  252. int spdif_volume; /* S/PDIF output is enabled if != -1 */
  253. int i2s_volume; /* current I2S out volume, in OSS format */
  254. int i2s_recording;/* 1 = recording from I2S, 0 = not */
  255. #ifdef IT8172_DEBUG
  256. /* debug /proc entry */
  257. struct proc_dir_entry *ps;
  258. struct proc_dir_entry *ac97_ps;
  259. #endif /* IT8172_DEBUG */
  260. struct ac97_codec codec;
  261. unsigned short pcc, capcc;
  262. unsigned dacrate, adcrate;
  263. spinlock_t lock;
  264. struct semaphore open_sem;
  265. mode_t open_mode;
  266. wait_queue_head_t open_wait;
  267. struct dmabuf {
  268. void *rawbuf;
  269. dma_addr_t dmaaddr;
  270. unsigned buforder;
  271. unsigned numfrag;
  272. unsigned fragshift;
  273. void* nextIn;
  274. void* nextOut;
  275. int count;
  276. int curBufPtr;
  277. unsigned total_bytes;
  278. unsigned error; /* over/underrun */
  279. wait_queue_head_t wait;
  280. /* redundant, but makes calculations easier */
  281. unsigned fragsize;
  282. unsigned dmasize;
  283. unsigned fragsamples;
  284. /* OSS stuff */
  285. unsigned mapped:1;
  286. unsigned ready:1;
  287. unsigned stopped:1;
  288. unsigned ossfragshift;
  289. int ossmaxfrags;
  290. unsigned subdivision;
  291. } dma_dac, dma_adc;
  292. };
  293. /* --------------------------------------------------------------------- */
  294. static LIST_HEAD(devs);
  295. /* --------------------------------------------------------------------- */
  296. static inline unsigned ld2(unsigned int x)
  297. {
  298. unsigned r = 0;
  299. if (x >= 0x10000) {
  300. x >>= 16;
  301. r += 16;
  302. }
  303. if (x >= 0x100) {
  304. x >>= 8;
  305. r += 8;
  306. }
  307. if (x >= 0x10) {
  308. x >>= 4;
  309. r += 4;
  310. }
  311. if (x >= 4) {
  312. x >>= 2;
  313. r += 2;
  314. }
  315. if (x >= 2)
  316. r++;
  317. return r;
  318. }
  319. /* --------------------------------------------------------------------- */
  320. static void it8172_delay(int msec)
  321. {
  322. unsigned long tmo;
  323. signed long tmo2;
  324. if (in_interrupt())
  325. return;
  326. tmo = jiffies + (msec*HZ)/1000;
  327. for (;;) {
  328. tmo2 = tmo - jiffies;
  329. if (tmo2 <= 0)
  330. break;
  331. schedule_timeout(tmo2);
  332. }
  333. }
  334. static unsigned short
  335. get_compat_rate(unsigned* rate)
  336. {
  337. unsigned rate_out = *rate;
  338. unsigned short sr;
  339. if (rate_out >= 46050) {
  340. sr = CC_SR_48000; rate_out = 48000;
  341. } else if (rate_out >= 41250) {
  342. sr = CC_SR_44100; rate_out = 44100;
  343. } else if (rate_out >= 35200) {
  344. sr = CC_SR_38400; rate_out = 38400;
  345. } else if (rate_out >= 27025) {
  346. sr = CC_SR_32000; rate_out = 32000;
  347. } else if (rate_out >= 20625) {
  348. sr = CC_SR_22050; rate_out = 22050;
  349. } else if (rate_out >= 17600) {
  350. sr = CC_SR_19200; rate_out = 19200;
  351. } else if (rate_out >= 13513) {
  352. sr = CC_SR_16000; rate_out = 16000;
  353. } else if (rate_out >= 10313) {
  354. sr = CC_SR_11025; rate_out = 11025;
  355. } else if (rate_out >= 8800) {
  356. sr = CC_SR_9600; rate_out = 9600;
  357. } else if (rate_out >= 6750) {
  358. sr = CC_SR_8000; rate_out = 8000;
  359. } else {
  360. sr = CC_SR_5500; rate_out = 5500;
  361. }
  362. *rate = rate_out;
  363. return sr;
  364. }
  365. static void set_adc_rate(struct it8172_state *s, unsigned rate)
  366. {
  367. unsigned long flags;
  368. unsigned short sr;
  369. sr = get_compat_rate(&rate);
  370. spin_lock_irqsave(&s->lock, flags);
  371. s->capcc &= ~CC_SR_MASK;
  372. s->capcc |= sr;
  373. outw(s->capcc, s->io+IT_AC_CAPCC);
  374. spin_unlock_irqrestore(&s->lock, flags);
  375. s->adcrate = rate;
  376. }
  377. static void set_dac_rate(struct it8172_state *s, unsigned rate)
  378. {
  379. unsigned long flags;
  380. unsigned short sr;
  381. sr = get_compat_rate(&rate);
  382. spin_lock_irqsave(&s->lock, flags);
  383. s->pcc &= ~CC_SR_MASK;
  384. s->pcc |= sr;
  385. outw(s->pcc, s->io+IT_AC_PCC);
  386. spin_unlock_irqrestore(&s->lock, flags);
  387. s->dacrate = rate;
  388. }
  389. /* --------------------------------------------------------------------- */
  390. static u16 rdcodec(struct ac97_codec *codec, u8 addr)
  391. {
  392. struct it8172_state *s = (struct it8172_state *)codec->private_data;
  393. unsigned long flags;
  394. unsigned short circp, data;
  395. int i;
  396. spin_lock_irqsave(&s->lock, flags);
  397. for (i = 0; i < POLL_COUNT; i++)
  398. if (!(inw(s->io+IT_AC_CIRCP) & CIRCP_CPS))
  399. break;
  400. if (i == POLL_COUNT)
  401. err("rdcodec: codec ready poll expired!");
  402. circp = addr & CIRCP_CIA_MASK;
  403. circp |= (codec->id << CIRCP_CID_BIT);
  404. circp |= CIRCP_RWC; // read command
  405. outw(circp, s->io+IT_AC_CIRCP);
  406. /* now wait for the data */
  407. for (i = 0; i < POLL_COUNT; i++)
  408. if (inw(s->io+IT_AC_CIRCP) & CIRCP_DPVF)
  409. break;
  410. if (i == POLL_COUNT)
  411. err("rdcodec: read poll expired!");
  412. data = inw(s->io+IT_AC_CIRDP);
  413. spin_unlock_irqrestore(&s->lock, flags);
  414. return data;
  415. }
  416. static void wrcodec(struct ac97_codec *codec, u8 addr, u16 data)
  417. {
  418. struct it8172_state *s = (struct it8172_state *)codec->private_data;
  419. unsigned long flags;
  420. unsigned short circp;
  421. int i;
  422. spin_lock_irqsave(&s->lock, flags);
  423. for (i = 0; i < POLL_COUNT; i++)
  424. if (!(inw(s->io+IT_AC_CIRCP) & CIRCP_CPS))
  425. break;
  426. if (i == POLL_COUNT)
  427. err("wrcodec: codec ready poll expired!");
  428. circp = addr & CIRCP_CIA_MASK;
  429. circp |= (codec->id << CIRCP_CID_BIT);
  430. circp &= ~CIRCP_RWC; // write command
  431. outw(data, s->io+IT_AC_CIRDP); // send data first
  432. outw(circp, s->io+IT_AC_CIRCP);
  433. spin_unlock_irqrestore(&s->lock, flags);
  434. }
  435. static void waitcodec(struct ac97_codec *codec)
  436. {
  437. unsigned short temp;
  438. /* codec_wait is used to wait for a ready state after
  439. an AC97_RESET. */
  440. it8172_delay(10);
  441. temp = rdcodec(codec, 0x26);
  442. // If power down, power up
  443. if (temp & 0x3f00) {
  444. // Power on
  445. wrcodec(codec, 0x26, 0);
  446. it8172_delay(100);
  447. // Reread
  448. temp = rdcodec(codec, 0x26);
  449. }
  450. // Check if Codec REF,ANL,DAC,ADC ready***/
  451. if ((temp & 0x3f0f) != 0x000f) {
  452. err("codec reg 26 status (0x%x) not ready!!", temp);
  453. return;
  454. }
  455. }
  456. /* --------------------------------------------------------------------- */
  457. static inline void stop_adc(struct it8172_state *s)
  458. {
  459. struct dmabuf* db = &s->dma_adc;
  460. unsigned long flags;
  461. unsigned char imc;
  462. if (db->stopped)
  463. return;
  464. spin_lock_irqsave(&s->lock, flags);
  465. s->capcc &= ~(CC_CA | CC_CP | CC_CB2L | CC_CB1L);
  466. s->capcc |= CC_CSP;
  467. outw(s->capcc, s->io+IT_AC_CAPCC);
  468. // disable capture interrupt
  469. imc = inb(s->io+IT_AC_IMC);
  470. outb(imc | IMC_CCIM, s->io+IT_AC_IMC);
  471. db->stopped = 1;
  472. spin_unlock_irqrestore(&s->lock, flags);
  473. }
  474. static inline void stop_dac(struct it8172_state *s)
  475. {
  476. struct dmabuf* db = &s->dma_dac;
  477. unsigned long flags;
  478. unsigned char imc;
  479. if (db->stopped)
  480. return;
  481. spin_lock_irqsave(&s->lock, flags);
  482. s->pcc &= ~(CC_CA | CC_CP | CC_CB2L | CC_CB1L);
  483. s->pcc |= CC_CSP;
  484. outw(s->pcc, s->io+IT_AC_PCC);
  485. // disable playback interrupt
  486. imc = inb(s->io+IT_AC_IMC);
  487. outb(imc | IMC_PCIM, s->io+IT_AC_IMC);
  488. db->stopped = 1;
  489. spin_unlock_irqrestore(&s->lock, flags);
  490. }
  491. static void start_dac(struct it8172_state *s)
  492. {
  493. struct dmabuf* db = &s->dma_dac;
  494. unsigned long flags;
  495. unsigned char imc;
  496. unsigned long buf1, buf2;
  497. if (!db->stopped)
  498. return;
  499. spin_lock_irqsave(&s->lock, flags);
  500. // reset Buffer 1 and 2 pointers to nextOut and nextOut+fragsize
  501. buf1 = virt_to_bus(db->nextOut);
  502. buf2 = buf1 + db->fragsize;
  503. if (buf2 >= db->dmaaddr + db->dmasize)
  504. buf2 -= db->dmasize;
  505. outl(buf1, s->io+IT_AC_PCB1STA);
  506. outl(buf2, s->io+IT_AC_PCB2STA);
  507. db->curBufPtr = IT_AC_PCB1STA;
  508. // enable playback interrupt
  509. imc = inb(s->io+IT_AC_IMC);
  510. outb(imc & ~IMC_PCIM, s->io+IT_AC_IMC);
  511. s->pcc &= ~(CC_CSP | CC_CP | CC_CB2L | CC_CB1L);
  512. s->pcc |= CC_CA;
  513. outw(s->pcc, s->io+IT_AC_PCC);
  514. db->stopped = 0;
  515. spin_unlock_irqrestore(&s->lock, flags);
  516. }
  517. static void start_adc(struct it8172_state *s)
  518. {
  519. struct dmabuf* db = &s->dma_adc;
  520. unsigned long flags;
  521. unsigned char imc;
  522. unsigned long buf1, buf2;
  523. if (!db->stopped)
  524. return;
  525. spin_lock_irqsave(&s->lock, flags);
  526. // reset Buffer 1 and 2 pointers to nextIn and nextIn+fragsize
  527. buf1 = virt_to_bus(db->nextIn);
  528. buf2 = buf1 + db->fragsize;
  529. if (buf2 >= db->dmaaddr + db->dmasize)
  530. buf2 -= db->dmasize;
  531. outl(buf1, s->io+IT_AC_CAPB1STA);
  532. outl(buf2, s->io+IT_AC_CAPB2STA);
  533. db->curBufPtr = IT_AC_CAPB1STA;
  534. // enable capture interrupt
  535. imc = inb(s->io+IT_AC_IMC);
  536. outb(imc & ~IMC_CCIM, s->io+IT_AC_IMC);
  537. s->capcc &= ~(CC_CSP | CC_CP | CC_CB2L | CC_CB1L);
  538. s->capcc |= CC_CA;
  539. outw(s->capcc, s->io+IT_AC_CAPCC);
  540. db->stopped = 0;
  541. spin_unlock_irqrestore(&s->lock, flags);
  542. }
  543. /* --------------------------------------------------------------------- */
  544. #define DMABUF_DEFAULTORDER (17-PAGE_SHIFT)
  545. #define DMABUF_MINORDER 1
  546. static inline void dealloc_dmabuf(struct it8172_state *s, struct dmabuf *db)
  547. {
  548. struct page *page, *pend;
  549. if (db->rawbuf) {
  550. /* undo marking the pages as reserved */
  551. pend = virt_to_page(db->rawbuf +
  552. (PAGE_SIZE << db->buforder) - 1);
  553. for (page = virt_to_page(db->rawbuf); page <= pend; page++)
  554. ClearPageReserved(page);
  555. pci_free_consistent(s->dev, PAGE_SIZE << db->buforder,
  556. db->rawbuf, db->dmaaddr);
  557. }
  558. db->rawbuf = db->nextIn = db->nextOut = NULL;
  559. db->mapped = db->ready = 0;
  560. }
  561. static int prog_dmabuf(struct it8172_state *s, struct dmabuf *db,
  562. unsigned rate, unsigned fmt, unsigned reg)
  563. {
  564. int order;
  565. unsigned bytepersec;
  566. unsigned bufs;
  567. struct page *page, *pend;
  568. if (!db->rawbuf) {
  569. db->ready = db->mapped = 0;
  570. for (order = DMABUF_DEFAULTORDER;
  571. order >= DMABUF_MINORDER; order--)
  572. if ((db->rawbuf =
  573. pci_alloc_consistent(s->dev,
  574. PAGE_SIZE << order,
  575. &db->dmaaddr)))
  576. break;
  577. if (!db->rawbuf)
  578. return -ENOMEM;
  579. db->buforder = order;
  580. /* now mark the pages as reserved;
  581. otherwise remap_pfn_range doesn't do what we want */
  582. pend = virt_to_page(db->rawbuf +
  583. (PAGE_SIZE << db->buforder) - 1);
  584. for (page = virt_to_page(db->rawbuf); page <= pend; page++)
  585. SetPageReserved(page);
  586. }
  587. db->count = 0;
  588. db->nextIn = db->nextOut = db->rawbuf;
  589. bytepersec = rate << sample_shift[fmt];
  590. bufs = PAGE_SIZE << db->buforder;
  591. if (db->ossfragshift) {
  592. if ((1000 << db->ossfragshift) < bytepersec)
  593. db->fragshift = ld2(bytepersec/1000);
  594. else
  595. db->fragshift = db->ossfragshift;
  596. } else {
  597. db->fragshift = ld2(bytepersec/100/(db->subdivision ?
  598. db->subdivision : 1));
  599. if (db->fragshift < 3)
  600. db->fragshift = 3;
  601. }
  602. db->numfrag = bufs >> db->fragshift;
  603. while (db->numfrag < 4 && db->fragshift > 3) {
  604. db->fragshift--;
  605. db->numfrag = bufs >> db->fragshift;
  606. }
  607. db->fragsize = 1 << db->fragshift;
  608. if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
  609. db->numfrag = db->ossmaxfrags;
  610. db->fragsamples = db->fragsize >> sample_shift[fmt];
  611. db->dmasize = db->numfrag << db->fragshift;
  612. memset(db->rawbuf, (fmt & (CC_DF>>CC_FMT_BIT)) ? 0 : 0x80, bufs);
  613. #ifdef IT8172_VERBOSE_DEBUG
  614. dbg("rate=%d, fragsize=%d, numfrag=%d, dmasize=%d",
  615. rate, db->fragsize, db->numfrag, db->dmasize);
  616. #endif
  617. // set data length register
  618. outw(db->fragsize, s->io+reg+2);
  619. db->ready = 1;
  620. return 0;
  621. }
  622. static inline int prog_dmabuf_adc(struct it8172_state *s)
  623. {
  624. stop_adc(s);
  625. return prog_dmabuf(s, &s->dma_adc, s->adcrate,
  626. (s->capcc & CC_FMT_MASK) >> CC_FMT_BIT,
  627. IT_AC_CAPCC);
  628. }
  629. static inline int prog_dmabuf_dac(struct it8172_state *s)
  630. {
  631. stop_dac(s);
  632. return prog_dmabuf(s, &s->dma_dac, s->dacrate,
  633. (s->pcc & CC_FMT_MASK) >> CC_FMT_BIT,
  634. IT_AC_PCC);
  635. }
  636. /* hold spinlock for the following! */
  637. static irqreturn_t it8172_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  638. {
  639. struct it8172_state *s = (struct it8172_state *)dev_id;
  640. struct dmabuf* dac = &s->dma_dac;
  641. struct dmabuf* adc = &s->dma_adc;
  642. unsigned char isc, vs;
  643. unsigned short vol, mute;
  644. unsigned long newptr;
  645. spin_lock(&s->lock);
  646. isc = inb(s->io+IT_AC_ISC);
  647. /* fastpath out, to ease interrupt sharing */
  648. if (!(isc & (ISC_VCI | ISC_CCI | ISC_PCI))) {
  649. spin_unlock(&s->lock);
  650. return IRQ_NONE;
  651. }
  652. /* clear audio interrupts first */
  653. outb(isc | ISC_VCI | ISC_CCI | ISC_PCI, s->io+IT_AC_ISC);
  654. /* handle volume button events (ignore if S/PDIF enabled) */
  655. if ((isc & ISC_VCI) && s->spdif_volume == -1) {
  656. vs = inb(s->io+IT_AC_VS);
  657. outb(0, s->io+IT_AC_VS);
  658. vol = inw(s->io+IT_AC_PCMOV);
  659. mute = vol & PCMOV_PCMOM;
  660. vol &= PCMOV_PCMLCG_MASK;
  661. if ((vs & VS_VUP) && vol > 0)
  662. vol--;
  663. if ((vs & VS_VDP) && vol < 0x1f)
  664. vol++;
  665. vol |= (vol << PCMOV_PCMRCG_BIT);
  666. if (vs & VS_VMP)
  667. vol |= (mute ^ PCMOV_PCMOM);
  668. outw(vol, s->io+IT_AC_PCMOV);
  669. }
  670. /* update capture pointers */
  671. if (isc & ISC_CCI) {
  672. if (adc->count > adc->dmasize - adc->fragsize) {
  673. // Overrun. Stop ADC and log the error
  674. stop_adc(s);
  675. adc->error++;
  676. dbg("adc overrun");
  677. } else {
  678. newptr = virt_to_bus(adc->nextIn) + 2*adc->fragsize;
  679. if (newptr >= adc->dmaaddr + adc->dmasize)
  680. newptr -= adc->dmasize;
  681. outl(newptr, s->io+adc->curBufPtr);
  682. adc->curBufPtr = (adc->curBufPtr == IT_AC_CAPB1STA) ?
  683. IT_AC_CAPB2STA : IT_AC_CAPB1STA;
  684. adc->nextIn += adc->fragsize;
  685. if (adc->nextIn >= adc->rawbuf + adc->dmasize)
  686. adc->nextIn -= adc->dmasize;
  687. adc->count += adc->fragsize;
  688. adc->total_bytes += adc->fragsize;
  689. /* wake up anybody listening */
  690. if (waitqueue_active(&adc->wait))
  691. wake_up_interruptible(&adc->wait);
  692. }
  693. }
  694. /* update playback pointers */
  695. if (isc & ISC_PCI) {
  696. newptr = virt_to_bus(dac->nextOut) + 2*dac->fragsize;
  697. if (newptr >= dac->dmaaddr + dac->dmasize)
  698. newptr -= dac->dmasize;
  699. outl(newptr, s->io+dac->curBufPtr);
  700. dac->curBufPtr = (dac->curBufPtr == IT_AC_PCB1STA) ?
  701. IT_AC_PCB2STA : IT_AC_PCB1STA;
  702. dac->nextOut += dac->fragsize;
  703. if (dac->nextOut >= dac->rawbuf + dac->dmasize)
  704. dac->nextOut -= dac->dmasize;
  705. dac->count -= dac->fragsize;
  706. dac->total_bytes += dac->fragsize;
  707. /* wake up anybody listening */
  708. if (waitqueue_active(&dac->wait))
  709. wake_up_interruptible(&dac->wait);
  710. if (dac->count <= 0)
  711. stop_dac(s);
  712. }
  713. spin_unlock(&s->lock);
  714. return IRQ_HANDLED;
  715. }
  716. /* --------------------------------------------------------------------- */
  717. static int it8172_open_mixdev(struct inode *inode, struct file *file)
  718. {
  719. int minor = iminor(inode);
  720. struct list_head *list;
  721. struct it8172_state *s;
  722. for (list = devs.next; ; list = list->next) {
  723. if (list == &devs)
  724. return -ENODEV;
  725. s = list_entry(list, struct it8172_state, devs);
  726. if (s->codec.dev_mixer == minor)
  727. break;
  728. }
  729. file->private_data = s;
  730. return nonseekable_open(inode, file);
  731. }
  732. static int it8172_release_mixdev(struct inode *inode, struct file *file)
  733. {
  734. return 0;
  735. }
  736. static u16
  737. cvt_ossvol(unsigned int gain)
  738. {
  739. u16 ret;
  740. if (gain == 0)
  741. return 0;
  742. if (gain > 100)
  743. gain = 100;
  744. ret = (100 - gain + 32) / 4;
  745. ret = ret > 31 ? 31 : ret;
  746. return ret;
  747. }
  748. static int mixdev_ioctl(struct ac97_codec *codec, unsigned int cmd,
  749. unsigned long arg)
  750. {
  751. struct it8172_state *s = (struct it8172_state *)codec->private_data;
  752. unsigned int left, right;
  753. unsigned long flags;
  754. int val;
  755. u16 vol;
  756. /*
  757. * When we are in S/PDIF mode, we want to disable any analog output so
  758. * we filter the master/PCM channel volume ioctls.
  759. *
  760. * Also filter I2S channel, which AC'97 knows nothing about.
  761. */
  762. switch (cmd) {
  763. case SOUND_MIXER_WRITE_VOLUME:
  764. // if not in S/PDIF mode, pass to AC'97
  765. if (s->spdif_volume == -1)
  766. break;
  767. return 0;
  768. case SOUND_MIXER_WRITE_PCM:
  769. // if not in S/PDIF mode, pass to AC'97
  770. if (s->spdif_volume == -1)
  771. break;
  772. if (get_user(val, (int *)arg))
  773. return -EFAULT;
  774. right = ((val >> 8) & 0xff);
  775. left = (val & 0xff);
  776. if (right > 100)
  777. right = 100;
  778. if (left > 100)
  779. left = 100;
  780. s->spdif_volume = (right << 8) | left;
  781. vol = cvt_ossvol(left);
  782. vol |= (cvt_ossvol(right) << PCMOV_PCMRCG_BIT);
  783. if (vol == 0)
  784. vol = PCMOV_PCMOM; // mute
  785. spin_lock_irqsave(&s->lock, flags);
  786. outw(vol, s->io+IT_AC_PCMOV);
  787. spin_unlock_irqrestore(&s->lock, flags);
  788. return put_user(s->spdif_volume, (int *)arg);
  789. case SOUND_MIXER_READ_PCM:
  790. // if not in S/PDIF mode, pass to AC'97
  791. if (s->spdif_volume == -1)
  792. break;
  793. return put_user(s->spdif_volume, (int *)arg);
  794. case SOUND_MIXER_WRITE_I2S:
  795. if (get_user(val, (int *)arg))
  796. return -EFAULT;
  797. right = ((val >> 8) & 0xff);
  798. left = (val & 0xff);
  799. if (right > 100)
  800. right = 100;
  801. if (left > 100)
  802. left = 100;
  803. s->i2s_volume = (right << 8) | left;
  804. vol = cvt_ossvol(left);
  805. vol |= (cvt_ossvol(right) << I2SV_I2SRCG_BIT);
  806. if (vol == 0)
  807. vol = I2SV_I2SOM; // mute
  808. outw(vol, s->io+IT_AC_I2SV);
  809. return put_user(s->i2s_volume, (int *)arg);
  810. case SOUND_MIXER_READ_I2S:
  811. return put_user(s->i2s_volume, (int *)arg);
  812. case SOUND_MIXER_WRITE_RECSRC:
  813. if (get_user(val, (int *)arg))
  814. return -EFAULT;
  815. if (val & SOUND_MASK_I2S) {
  816. s->i2s_recording = 1;
  817. outb(DRSS_I2S, s->io+IT_AC_DRSS);
  818. return 0;
  819. } else {
  820. s->i2s_recording = 0;
  821. outb(DRSS_AC97_PRIM, s->io+IT_AC_DRSS);
  822. // now let AC'97 select record source
  823. break;
  824. }
  825. case SOUND_MIXER_READ_RECSRC:
  826. if (s->i2s_recording)
  827. return put_user(SOUND_MASK_I2S, (int *)arg);
  828. else
  829. // let AC'97 report recording source
  830. break;
  831. }
  832. return codec->mixer_ioctl(codec, cmd, arg);
  833. }
  834. static int it8172_ioctl_mixdev(struct inode *inode, struct file *file,
  835. unsigned int cmd, unsigned long arg)
  836. {
  837. struct it8172_state *s = (struct it8172_state *)file->private_data;
  838. struct ac97_codec *codec = &s->codec;
  839. return mixdev_ioctl(codec, cmd, arg);
  840. }
  841. static /*const*/ struct file_operations it8172_mixer_fops = {
  842. .owner = THIS_MODULE,
  843. .llseek = no_llseek,
  844. .ioctl = it8172_ioctl_mixdev,
  845. .open = it8172_open_mixdev,
  846. .release = it8172_release_mixdev,
  847. };
  848. /* --------------------------------------------------------------------- */
  849. static int drain_dac(struct it8172_state *s, int nonblock)
  850. {
  851. unsigned long flags;
  852. int count, tmo;
  853. if (s->dma_dac.mapped || !s->dma_dac.ready || s->dma_dac.stopped)
  854. return 0;
  855. for (;;) {
  856. spin_lock_irqsave(&s->lock, flags);
  857. count = s->dma_dac.count;
  858. spin_unlock_irqrestore(&s->lock, flags);
  859. if (count <= 0)
  860. break;
  861. if (signal_pending(current))
  862. break;
  863. //if (nonblock)
  864. //return -EBUSY;
  865. tmo = 1000 * count / s->dacrate;
  866. tmo >>= sample_shift[(s->pcc & CC_FMT_MASK) >> CC_FMT_BIT];
  867. it8172_delay(tmo);
  868. }
  869. if (signal_pending(current))
  870. return -ERESTARTSYS;
  871. return 0;
  872. }
  873. /* --------------------------------------------------------------------- */
  874. /*
  875. * Copy audio data to/from user buffer from/to dma buffer, taking care
  876. * that we wrap when reading/writing the dma buffer. Returns actual byte
  877. * count written to or read from the dma buffer.
  878. */
  879. static int copy_dmabuf_user(struct dmabuf *db, char* userbuf,
  880. int count, int to_user)
  881. {
  882. char* bufptr = to_user ? db->nextOut : db->nextIn;
  883. char* bufend = db->rawbuf + db->dmasize;
  884. if (bufptr + count > bufend) {
  885. int partial = (int)(bufend - bufptr);
  886. if (to_user) {
  887. if (copy_to_user(userbuf, bufptr, partial))
  888. return -EFAULT;
  889. if (copy_to_user(userbuf + partial, db->rawbuf,
  890. count - partial))
  891. return -EFAULT;
  892. } else {
  893. if (copy_from_user(bufptr, userbuf, partial))
  894. return -EFAULT;
  895. if (copy_from_user(db->rawbuf,
  896. userbuf + partial,
  897. count - partial))
  898. return -EFAULT;
  899. }
  900. } else {
  901. if (to_user) {
  902. if (copy_to_user(userbuf, bufptr, count))
  903. return -EFAULT;
  904. } else {
  905. if (copy_from_user(bufptr, userbuf, count))
  906. return -EFAULT;
  907. }
  908. }
  909. return count;
  910. }
  911. static ssize_t it8172_read(struct file *file, char *buffer,
  912. size_t count, loff_t *ppos)
  913. {
  914. struct it8172_state *s = (struct it8172_state *)file->private_data;
  915. struct dmabuf *db = &s->dma_adc;
  916. ssize_t ret;
  917. unsigned long flags;
  918. int cnt, remainder, avail;
  919. if (db->mapped)
  920. return -ENXIO;
  921. if (!access_ok(VERIFY_WRITE, buffer, count))
  922. return -EFAULT;
  923. ret = 0;
  924. while (count > 0) {
  925. // wait for samples in capture buffer
  926. do {
  927. spin_lock_irqsave(&s->lock, flags);
  928. if (db->stopped)
  929. start_adc(s);
  930. avail = db->count;
  931. spin_unlock_irqrestore(&s->lock, flags);
  932. if (avail <= 0) {
  933. if (file->f_flags & O_NONBLOCK) {
  934. if (!ret)
  935. ret = -EAGAIN;
  936. return ret;
  937. }
  938. interruptible_sleep_on(&db->wait);
  939. if (signal_pending(current)) {
  940. if (!ret)
  941. ret = -ERESTARTSYS;
  942. return ret;
  943. }
  944. }
  945. } while (avail <= 0);
  946. // copy from nextOut to user
  947. if ((cnt = copy_dmabuf_user(db, buffer, count > avail ?
  948. avail : count, 1)) < 0) {
  949. if (!ret)
  950. ret = -EFAULT;
  951. return ret;
  952. }
  953. spin_lock_irqsave(&s->lock, flags);
  954. db->count -= cnt;
  955. spin_unlock_irqrestore(&s->lock, flags);
  956. db->nextOut += cnt;
  957. if (db->nextOut >= db->rawbuf + db->dmasize)
  958. db->nextOut -= db->dmasize;
  959. count -= cnt;
  960. buffer += cnt;
  961. ret += cnt;
  962. } // while (count > 0)
  963. /*
  964. * See if the dma buffer count after this read call is
  965. * aligned on a fragsize boundary. If not, read from
  966. * buffer until we reach a boundary, and let's hope this
  967. * is just the last remainder of an audio record. If not
  968. * it means the user is not reading in fragsize chunks, in
  969. * which case it's his/her fault that there are audio gaps
  970. * in their record.
  971. */
  972. spin_lock_irqsave(&s->lock, flags);
  973. remainder = db->count % db->fragsize;
  974. if (remainder) {
  975. db->nextOut += remainder;
  976. if (db->nextOut >= db->rawbuf + db->dmasize)
  977. db->nextOut -= db->dmasize;
  978. db->count -= remainder;
  979. }
  980. spin_unlock_irqrestore(&s->lock, flags);
  981. return ret;
  982. }
  983. static ssize_t it8172_write(struct file *file, const char *buffer,
  984. size_t count, loff_t *ppos)
  985. {
  986. struct it8172_state *s = (struct it8172_state *)file->private_data;
  987. struct dmabuf *db = &s->dma_dac;
  988. ssize_t ret;
  989. unsigned long flags;
  990. int cnt, remainder, avail;
  991. if (db->mapped)
  992. return -ENXIO;
  993. if (!access_ok(VERIFY_READ, buffer, count))
  994. return -EFAULT;
  995. ret = 0;
  996. while (count > 0) {
  997. // wait for space in playback buffer
  998. do {
  999. spin_lock_irqsave(&s->lock, flags);
  1000. avail = db->dmasize - db->count;
  1001. spin_unlock_irqrestore(&s->lock, flags);
  1002. if (avail <= 0) {
  1003. if (file->f_flags & O_NONBLOCK) {
  1004. if (!ret)
  1005. ret = -EAGAIN;
  1006. return ret;
  1007. }
  1008. interruptible_sleep_on(&db->wait);
  1009. if (signal_pending(current)) {
  1010. if (!ret)
  1011. ret = -ERESTARTSYS;
  1012. return ret;
  1013. }
  1014. }
  1015. } while (avail <= 0);
  1016. // copy to nextIn
  1017. if ((cnt = copy_dmabuf_user(db, (char*)buffer,
  1018. count > avail ?
  1019. avail : count, 0)) < 0) {
  1020. if (!ret)
  1021. ret = -EFAULT;
  1022. return ret;
  1023. }
  1024. spin_lock_irqsave(&s->lock, flags);
  1025. db->count += cnt;
  1026. if (db->stopped)
  1027. start_dac(s);
  1028. spin_unlock_irqrestore(&s->lock, flags);
  1029. db->nextIn += cnt;
  1030. if (db->nextIn >= db->rawbuf + db->dmasize)
  1031. db->nextIn -= db->dmasize;
  1032. count -= cnt;
  1033. buffer += cnt;
  1034. ret += cnt;
  1035. } // while (count > 0)
  1036. /*
  1037. * See if the dma buffer count after this write call is
  1038. * aligned on a fragsize boundary. If not, fill buffer
  1039. * with silence to the next boundary, and let's hope this
  1040. * is just the last remainder of an audio playback. If not
  1041. * it means the user is not sending us fragsize chunks, in
  1042. * which case it's his/her fault that there are audio gaps
  1043. * in their playback.
  1044. */
  1045. spin_lock_irqsave(&s->lock, flags);
  1046. remainder = db->count % db->fragsize;
  1047. if (remainder) {
  1048. int fill_cnt = db->fragsize - remainder;
  1049. memset(db->nextIn, 0, fill_cnt);
  1050. db->nextIn += fill_cnt;
  1051. if (db->nextIn >= db->rawbuf + db->dmasize)
  1052. db->nextIn -= db->dmasize;
  1053. db->count += fill_cnt;
  1054. }
  1055. spin_unlock_irqrestore(&s->lock, flags);
  1056. return ret;
  1057. }
  1058. /* No kernel lock - we have our own spinlock */
  1059. static unsigned int it8172_poll(struct file *file,
  1060. struct poll_table_struct *wait)
  1061. {
  1062. struct it8172_state *s = (struct it8172_state *)file->private_data;
  1063. unsigned long flags;
  1064. unsigned int mask = 0;
  1065. if (file->f_mode & FMODE_WRITE) {
  1066. if (!s->dma_dac.ready)
  1067. return 0;
  1068. poll_wait(file, &s->dma_dac.wait, wait);
  1069. }
  1070. if (file->f_mode & FMODE_READ) {
  1071. if (!s->dma_adc.ready)
  1072. return 0;
  1073. poll_wait(file, &s->dma_adc.wait, wait);
  1074. }
  1075. spin_lock_irqsave(&s->lock, flags);
  1076. if (file->f_mode & FMODE_READ) {
  1077. if (s->dma_adc.count >= (signed)s->dma_adc.fragsize)
  1078. mask |= POLLIN | POLLRDNORM;
  1079. }
  1080. if (file->f_mode & FMODE_WRITE) {
  1081. if (s->dma_dac.mapped) {
  1082. if (s->dma_dac.count >= (signed)s->dma_dac.fragsize)
  1083. mask |= POLLOUT | POLLWRNORM;
  1084. } else {
  1085. if ((signed)s->dma_dac.dmasize >=
  1086. s->dma_dac.count + (signed)s->dma_dac.fragsize)
  1087. mask |= POLLOUT | POLLWRNORM;
  1088. }
  1089. }
  1090. spin_unlock_irqrestore(&s->lock, flags);
  1091. return mask;
  1092. }
  1093. static int it8172_mmap(struct file *file, struct vm_area_struct *vma)
  1094. {
  1095. struct it8172_state *s = (struct it8172_state *)file->private_data;
  1096. struct dmabuf *db;
  1097. unsigned long size;
  1098. lock_kernel();
  1099. if (vma->vm_flags & VM_WRITE)
  1100. db = &s->dma_dac;
  1101. else if (vma->vm_flags & VM_READ)
  1102. db = &s->dma_adc;
  1103. else {
  1104. unlock_kernel();
  1105. return -EINVAL;
  1106. }
  1107. if (vma->vm_pgoff != 0) {
  1108. unlock_kernel();
  1109. return -EINVAL;
  1110. }
  1111. size = vma->vm_end - vma->vm_start;
  1112. if (size > (PAGE_SIZE << db->buforder)) {
  1113. unlock_kernel();
  1114. return -EINVAL;
  1115. }
  1116. if (remap_pfn_range(vma, vma->vm_start,
  1117. virt_to_phys(db->rawbuf) >> PAGE_SHIFT,
  1118. size, vma->vm_page_prot)) {
  1119. unlock_kernel();
  1120. return -EAGAIN;
  1121. }
  1122. db->mapped = 1;
  1123. unlock_kernel();
  1124. return 0;
  1125. }
  1126. #ifdef IT8172_VERBOSE_DEBUG
  1127. static struct ioctl_str_t {
  1128. unsigned int cmd;
  1129. const char* str;
  1130. } ioctl_str[] = {
  1131. {SNDCTL_DSP_RESET, "SNDCTL_DSP_RESET"},
  1132. {SNDCTL_DSP_SYNC, "SNDCTL_DSP_SYNC"},
  1133. {SNDCTL_DSP_SPEED, "SNDCTL_DSP_SPEED"},
  1134. {SNDCTL_DSP_STEREO, "SNDCTL_DSP_STEREO"},
  1135. {SNDCTL_DSP_GETBLKSIZE, "SNDCTL_DSP_GETBLKSIZE"},
  1136. {SNDCTL_DSP_SAMPLESIZE, "SNDCTL_DSP_SAMPLESIZE"},
  1137. {SNDCTL_DSP_CHANNELS, "SNDCTL_DSP_CHANNELS"},
  1138. {SOUND_PCM_WRITE_CHANNELS, "SOUND_PCM_WRITE_CHANNELS"},
  1139. {SOUND_PCM_WRITE_FILTER, "SOUND_PCM_WRITE_FILTER"},
  1140. {SNDCTL_DSP_POST, "SNDCTL_DSP_POST"},
  1141. {SNDCTL_DSP_SUBDIVIDE, "SNDCTL_DSP_SUBDIVIDE"},
  1142. {SNDCTL_DSP_SETFRAGMENT, "SNDCTL_DSP_SETFRAGMENT"},
  1143. {SNDCTL_DSP_GETFMTS, "SNDCTL_DSP_GETFMTS"},
  1144. {SNDCTL_DSP_SETFMT, "SNDCTL_DSP_SETFMT"},
  1145. {SNDCTL_DSP_GETOSPACE, "SNDCTL_DSP_GETOSPACE"},
  1146. {SNDCTL_DSP_GETISPACE, "SNDCTL_DSP_GETISPACE"},
  1147. {SNDCTL_DSP_NONBLOCK, "SNDCTL_DSP_NONBLOCK"},
  1148. {SNDCTL_DSP_GETCAPS, "SNDCTL_DSP_GETCAPS"},
  1149. {SNDCTL_DSP_GETTRIGGER, "SNDCTL_DSP_GETTRIGGER"},
  1150. {SNDCTL_DSP_SETTRIGGER, "SNDCTL_DSP_SETTRIGGER"},
  1151. {SNDCTL_DSP_GETIPTR, "SNDCTL_DSP_GETIPTR"},
  1152. {SNDCTL_DSP_GETOPTR, "SNDCTL_DSP_GETOPTR"},
  1153. {SNDCTL_DSP_MAPINBUF, "SNDCTL_DSP_MAPINBUF"},
  1154. {SNDCTL_DSP_MAPOUTBUF, "SNDCTL_DSP_MAPOUTBUF"},
  1155. {SNDCTL_DSP_SETSYNCRO, "SNDCTL_DSP_SETSYNCRO"},
  1156. {SNDCTL_DSP_SETDUPLEX, "SNDCTL_DSP_SETDUPLEX"},
  1157. {SNDCTL_DSP_GETODELAY, "SNDCTL_DSP_GETODELAY"},
  1158. {SNDCTL_DSP_GETCHANNELMASK, "SNDCTL_DSP_GETCHANNELMASK"},
  1159. {SNDCTL_DSP_BIND_CHANNEL, "SNDCTL_DSP_BIND_CHANNEL"},
  1160. {OSS_GETVERSION, "OSS_GETVERSION"},
  1161. {SOUND_PCM_READ_RATE, "SOUND_PCM_READ_RATE"},
  1162. {SOUND_PCM_READ_CHANNELS, "SOUND_PCM_READ_CHANNELS"},
  1163. {SOUND_PCM_READ_BITS, "SOUND_PCM_READ_BITS"},
  1164. {SOUND_PCM_READ_FILTER, "SOUND_PCM_READ_FILTER"}
  1165. };
  1166. #endif
  1167. static int it8172_ioctl(struct inode *inode, struct file *file,
  1168. unsigned int cmd, unsigned long arg)
  1169. {
  1170. struct it8172_state *s = (struct it8172_state *)file->private_data;
  1171. unsigned long flags;
  1172. audio_buf_info abinfo;
  1173. count_info cinfo;
  1174. int count;
  1175. int val, mapped, ret, diff;
  1176. mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
  1177. ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
  1178. #ifdef IT8172_VERBOSE_DEBUG
  1179. for (count=0; count<sizeof(ioctl_str)/sizeof(ioctl_str[0]); count++) {
  1180. if (ioctl_str[count].cmd == cmd)
  1181. break;
  1182. }
  1183. if (count < sizeof(ioctl_str)/sizeof(ioctl_str[0]))
  1184. dbg("ioctl %s, arg=0x%08x",
  1185. ioctl_str[count].str, (unsigned int)arg);
  1186. else
  1187. dbg("ioctl unknown, 0x%x", cmd);
  1188. #endif
  1189. switch (cmd) {
  1190. case OSS_GETVERSION:
  1191. return put_user(SOUND_VERSION, (int *)arg);
  1192. case SNDCTL_DSP_SYNC:
  1193. if (file->f_mode & FMODE_WRITE)
  1194. return drain_dac(s, file->f_flags & O_NONBLOCK);
  1195. return 0;
  1196. case SNDCTL_DSP_SETDUPLEX:
  1197. return 0;
  1198. case SNDCTL_DSP_GETCAPS:
  1199. return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME |
  1200. DSP_CAP_TRIGGER | DSP_CAP_MMAP, (int *)arg);
  1201. case SNDCTL_DSP_RESET:
  1202. if (file->f_mode & FMODE_WRITE) {
  1203. stop_dac(s);
  1204. synchronize_irq(s->irq);
  1205. s->dma_dac.count = s->dma_dac.total_bytes = 0;
  1206. s->dma_dac.nextIn = s->dma_dac.nextOut =
  1207. s->dma_dac.rawbuf;
  1208. }
  1209. if (file->f_mode & FMODE_READ) {
  1210. stop_adc(s);
  1211. synchronize_irq(s->irq);
  1212. s->dma_adc.count = s->dma_adc.total_bytes = 0;
  1213. s->dma_adc.nextIn = s->dma_adc.nextOut =
  1214. s->dma_adc.rawbuf;
  1215. }
  1216. return 0;
  1217. case SNDCTL_DSP_SPEED:
  1218. if (get_user(val, (int *)arg))
  1219. return -EFAULT;
  1220. if (val >= 0) {
  1221. if (file->f_mode & FMODE_READ) {
  1222. stop_adc(s);
  1223. set_adc_rate(s, val);
  1224. if ((ret = prog_dmabuf_adc(s)))
  1225. return ret;
  1226. }
  1227. if (file->f_mode & FMODE_WRITE) {
  1228. stop_dac(s);
  1229. set_dac_rate(s, val);
  1230. if ((ret = prog_dmabuf_dac(s)))
  1231. return ret;
  1232. }
  1233. }
  1234. return put_user((file->f_mode & FMODE_READ) ?
  1235. s->adcrate : s->dacrate, (int *)arg);
  1236. case SNDCTL_DSP_STEREO:
  1237. if (get_user(val, (int *)arg))
  1238. return -EFAULT;
  1239. if (file->f_mode & FMODE_READ) {
  1240. stop_adc(s);
  1241. if (val)
  1242. s->capcc |= CC_SM;
  1243. else
  1244. s->capcc &= ~CC_SM;
  1245. outw(s->capcc, s->io+IT_AC_CAPCC);
  1246. if ((ret = prog_dmabuf_adc(s)))
  1247. return ret;
  1248. }
  1249. if (file->f_mode & FMODE_WRITE) {
  1250. stop_dac(s);
  1251. if (val)
  1252. s->pcc |= CC_SM;
  1253. else
  1254. s->pcc &= ~CC_SM;
  1255. outw(s->pcc, s->io+IT_AC_PCC);
  1256. if ((ret = prog_dmabuf_dac(s)))
  1257. return ret;
  1258. }
  1259. return 0;
  1260. case SNDCTL_DSP_CHANNELS:
  1261. if (get_user(val, (int *)arg))
  1262. return -EFAULT;
  1263. if (val != 0) {
  1264. if (file->f_mode & FMODE_READ) {
  1265. stop_adc(s);
  1266. if (val >= 2) {
  1267. val = 2;
  1268. s->capcc |= CC_SM;
  1269. }
  1270. else
  1271. s->capcc &= ~CC_SM;
  1272. outw(s->capcc, s->io+IT_AC_CAPCC);
  1273. if ((ret = prog_dmabuf_adc(s)))
  1274. return ret;
  1275. }
  1276. if (file->f_mode & FMODE_WRITE) {
  1277. stop_dac(s);
  1278. switch (val) {
  1279. case 1:
  1280. s->pcc &= ~CC_SM;
  1281. break;
  1282. case 2:
  1283. s->pcc |= CC_SM;
  1284. break;
  1285. default:
  1286. // FIX! support multichannel???
  1287. val = 2;
  1288. s->pcc |= CC_SM;
  1289. break;
  1290. }
  1291. outw(s->pcc, s->io+IT_AC_PCC);
  1292. if ((ret = prog_dmabuf_dac(s)))
  1293. return ret;
  1294. }
  1295. }
  1296. return put_user(val, (int *)arg);
  1297. case SNDCTL_DSP_GETFMTS: /* Returns a mask */
  1298. return put_user(AFMT_S16_LE|AFMT_U8, (int *)arg);
  1299. case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
  1300. if (get_user(val, (int *)arg))
  1301. return -EFAULT;
  1302. if (val != AFMT_QUERY) {
  1303. if (file->f_mode & FMODE_READ) {
  1304. stop_adc(s);
  1305. if (val == AFMT_S16_LE)
  1306. s->capcc |= CC_DF;
  1307. else {
  1308. val = AFMT_U8;
  1309. s->capcc &= ~CC_DF;
  1310. }
  1311. outw(s->capcc, s->io+IT_AC_CAPCC);
  1312. if ((ret = prog_dmabuf_adc(s)))
  1313. return ret;
  1314. }
  1315. if (file->f_mode & FMODE_WRITE) {
  1316. stop_dac(s);
  1317. if (val == AFMT_S16_LE)
  1318. s->pcc |= CC_DF;
  1319. else {
  1320. val = AFMT_U8;
  1321. s->pcc &= ~CC_DF;
  1322. }
  1323. outw(s->pcc, s->io+IT_AC_PCC);
  1324. if ((ret = prog_dmabuf_dac(s)))
  1325. return ret;
  1326. }
  1327. } else {
  1328. if (file->f_mode & FMODE_READ)
  1329. val = (s->capcc & CC_DF) ?
  1330. AFMT_S16_LE : AFMT_U8;
  1331. else
  1332. val = (s->pcc & CC_DF) ?
  1333. AFMT_S16_LE : AFMT_U8;
  1334. }
  1335. return put_user(val, (int *)arg);
  1336. case SNDCTL_DSP_POST:
  1337. return 0;
  1338. case SNDCTL_DSP_GETTRIGGER:
  1339. val = 0;
  1340. spin_lock_irqsave(&s->lock, flags);
  1341. if (file->f_mode & FMODE_READ && !s->dma_adc.stopped)
  1342. val |= PCM_ENABLE_INPUT;
  1343. if (file->f_mode & FMODE_WRITE && !s->dma_dac.stopped)
  1344. val |= PCM_ENABLE_OUTPUT;
  1345. spin_unlock_irqrestore(&s->lock, flags);
  1346. return put_user(val, (int *)arg);
  1347. case SNDCTL_DSP_SETTRIGGER:
  1348. if (get_user(val, (int *)arg))
  1349. return -EFAULT;
  1350. if (file->f_mode & FMODE_READ) {
  1351. if (val & PCM_ENABLE_INPUT)
  1352. start_adc(s);
  1353. else
  1354. stop_adc(s);
  1355. }
  1356. if (file->f_mode & FMODE_WRITE) {
  1357. if (val & PCM_ENABLE_OUTPUT)
  1358. start_dac(s);
  1359. else
  1360. stop_dac(s);
  1361. }
  1362. return 0;
  1363. case SNDCTL_DSP_GETOSPACE:
  1364. if (!(file->f_mode & FMODE_WRITE))
  1365. return -EINVAL;
  1366. abinfo.fragsize = s->dma_dac.fragsize;
  1367. spin_lock_irqsave(&s->lock, flags);
  1368. count = s->dma_dac.count;
  1369. if (!s->dma_dac.stopped)
  1370. count -= (s->dma_dac.fragsize -
  1371. inw(s->io+IT_AC_PCDL));
  1372. spin_unlock_irqrestore(&s->lock, flags);
  1373. if (count < 0)
  1374. count = 0;
  1375. abinfo.bytes = s->dma_dac.dmasize - count;
  1376. abinfo.fragstotal = s->dma_dac.numfrag;
  1377. abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
  1378. return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ?
  1379. -EFAULT : 0;
  1380. case SNDCTL_DSP_GETISPACE:
  1381. if (!(file->f_mode & FMODE_READ))
  1382. return -EINVAL;
  1383. abinfo.fragsize = s->dma_adc.fragsize;
  1384. spin_lock_irqsave(&s->lock, flags);
  1385. count = s->dma_adc.count;
  1386. if (!s->dma_adc.stopped)
  1387. count += (s->dma_adc.fragsize -
  1388. inw(s->io+IT_AC_CAPCDL));
  1389. spin_unlock_irqrestore(&s->lock, flags);
  1390. if (count < 0)
  1391. count = 0;
  1392. abinfo.bytes = count;
  1393. abinfo.fragstotal = s->dma_adc.numfrag;
  1394. abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;
  1395. return copy_to_user((void *)arg, &abinfo, sizeof(abinfo)) ?
  1396. -EFAULT : 0;
  1397. case SNDCTL_DSP_NONBLOCK:
  1398. file->f_flags |= O_NONBLOCK;
  1399. return 0;
  1400. case SNDCTL_DSP_GETODELAY:
  1401. if (!(file->f_mode & FMODE_WRITE))
  1402. return -EINVAL;
  1403. spin_lock_irqsave(&s->lock, flags);
  1404. count = s->dma_dac.count;
  1405. if (!s->dma_dac.stopped)
  1406. count -= (s->dma_dac.fragsize -
  1407. inw(s->io+IT_AC_PCDL));
  1408. spin_unlock_irqrestore(&s->lock, flags);
  1409. if (count < 0)
  1410. count = 0;
  1411. return put_user(count, (int *)arg);
  1412. case SNDCTL_DSP_GETIPTR:
  1413. if (!(file->f_mode & FMODE_READ))
  1414. return -EINVAL;
  1415. spin_lock_irqsave(&s->lock, flags);
  1416. cinfo.bytes = s->dma_adc.total_bytes;
  1417. count = s->dma_adc.count;
  1418. if (!s->dma_adc.stopped) {
  1419. diff = s->dma_adc.fragsize - inw(s->io+IT_AC_CAPCDL);
  1420. count += diff;
  1421. cinfo.bytes += diff;
  1422. cinfo.ptr = inl(s->io+s->dma_adc.curBufPtr) -
  1423. s->dma_adc.dmaaddr;
  1424. } else
  1425. cinfo.ptr = virt_to_bus(s->dma_adc.nextIn) -
  1426. s->dma_adc.dmaaddr;
  1427. if (s->dma_adc.mapped)
  1428. s->dma_adc.count &= s->dma_adc.fragsize-1;
  1429. spin_unlock_irqrestore(&s->lock, flags);
  1430. if (count < 0)
  1431. count = 0;
  1432. cinfo.blocks = count >> s->dma_adc.fragshift;
  1433. if (copy_to_user((void *)arg, &cinfo, sizeof(cinfo)))
  1434. return -EFAULT;
  1435. return 0;
  1436. case SNDCTL_DSP_GETOPTR:
  1437. if (!(file->f_mode & FMODE_READ))
  1438. return -EINVAL;
  1439. spin_lock_irqsave(&s->lock, flags);
  1440. cinfo.bytes = s->dma_dac.total_bytes;
  1441. count = s->dma_dac.count;
  1442. if (!s->dma_dac.stopped) {
  1443. diff = s->dma_dac.fragsize - inw(s->io+IT_AC_CAPCDL);
  1444. count -= diff;
  1445. cinfo.bytes += diff;
  1446. cinfo.ptr = inl(s->io+s->dma_dac.curBufPtr) -
  1447. s->dma_dac.dmaaddr;
  1448. } else
  1449. cinfo.ptr = virt_to_bus(s->dma_dac.nextOut) -
  1450. s->dma_dac.dmaaddr;
  1451. if (s->dma_dac.mapped)
  1452. s->dma_dac.count &= s->dma_dac.fragsize-1;
  1453. spin_unlock_irqrestore(&s->lock, flags);
  1454. if (count < 0)
  1455. count = 0;
  1456. cinfo.blocks = count >> s->dma_dac.fragshift;
  1457. if (copy_to_user((void *)arg, &cinfo, sizeof(cinfo)))
  1458. return -EFAULT;
  1459. return 0;
  1460. case SNDCTL_DSP_GETBLKSIZE:
  1461. if (file->f_mode & FMODE_WRITE)
  1462. return put_user(s->dma_dac.fragsize, (int *)arg);
  1463. else
  1464. return put_user(s->dma_adc.fragsize, (int *)arg);
  1465. case SNDCTL_DSP_SETFRAGMENT:
  1466. if (get_user(val, (int *)arg))
  1467. return -EFAULT;
  1468. if (file->f_mode & FMODE_READ) {
  1469. stop_adc(s);
  1470. s->dma_adc.ossfragshift = val & 0xffff;
  1471. s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff;
  1472. if (s->dma_adc.ossfragshift < 4)
  1473. s->dma_adc.ossfragshift = 4;
  1474. if (s->dma_adc.ossfragshift > 15)
  1475. s->dma_adc.ossfragshift = 15;
  1476. if (s->dma_adc.ossmaxfrags < 4)
  1477. s->dma_adc.ossmaxfrags = 4;
  1478. if ((ret = prog_dmabuf_adc(s)))
  1479. return ret;
  1480. }
  1481. if (file->f_mode & FMODE_WRITE) {
  1482. stop_dac(s);
  1483. s->dma_dac.ossfragshift = val & 0xffff;
  1484. s->dma_dac.ossmaxfrags = (val >> 16) & 0xffff;
  1485. if (s->dma_dac.ossfragshift < 4)
  1486. s->dma_dac.ossfragshift = 4;
  1487. if (s->dma_dac.ossfragshift > 15)
  1488. s->dma_dac.ossfragshift = 15;
  1489. if (s->dma_dac.ossmaxfrags < 4)
  1490. s->dma_dac.ossmaxfrags = 4;
  1491. if ((ret = prog_dmabuf_dac(s)))
  1492. return ret;
  1493. }
  1494. return 0;
  1495. case SNDCTL_DSP_SUBDIVIDE:
  1496. if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
  1497. (file->f_mode & FMODE_WRITE && s->dma_dac.subdivision))
  1498. return -EINVAL;
  1499. if (get_user(val, (int *)arg))
  1500. return -EFAULT;
  1501. if (val != 1 && val != 2 && val != 4)
  1502. return -EINVAL;
  1503. if (file->f_mode & FMODE_READ) {
  1504. stop_adc(s);
  1505. s->dma_adc.subdivision = val;
  1506. if ((ret = prog_dmabuf_adc(s)))
  1507. return ret;
  1508. }
  1509. if (file->f_mode & FMODE_WRITE) {
  1510. stop_dac(s);
  1511. s->dma_dac.subdivision = val;
  1512. if ((ret = prog_dmabuf_dac(s)))
  1513. return ret;
  1514. }
  1515. return 0;
  1516. case SOUND_PCM_READ_RATE:
  1517. return put_user((file->f_mode & FMODE_READ) ?
  1518. s->adcrate : s->dacrate, (int *)arg);
  1519. case SOUND_PCM_READ_CHANNELS:
  1520. if (file->f_mode & FMODE_READ)
  1521. return put_user((s->capcc & CC_SM) ? 2 : 1,
  1522. (int *)arg);
  1523. else
  1524. return put_user((s->pcc & CC_SM) ? 2 : 1,
  1525. (int *)arg);
  1526. case SOUND_PCM_READ_BITS:
  1527. if (file->f_mode & FMODE_READ)
  1528. return put_user((s->capcc & CC_DF) ? 16 : 8,
  1529. (int *)arg);
  1530. else
  1531. return put_user((s->pcc & CC_DF) ? 16 : 8,
  1532. (int *)arg);
  1533. case SOUND_PCM_WRITE_FILTER:
  1534. case SNDCTL_DSP_SETSYNCRO:
  1535. case SOUND_PCM_READ_FILTER:
  1536. return -EINVAL;
  1537. }
  1538. return mixdev_ioctl(&s->codec, cmd, arg);
  1539. }
  1540. static int it8172_open(struct inode *inode, struct file *file)
  1541. {
  1542. int minor = iminor(inode);
  1543. DECLARE_WAITQUEUE(wait, current);
  1544. unsigned long flags;
  1545. struct list_head *list;
  1546. struct it8172_state *s;
  1547. int ret;
  1548. #ifdef IT8172_VERBOSE_DEBUG
  1549. if (file->f_flags & O_NONBLOCK)
  1550. dbg("%s: non-blocking", __FUNCTION__);
  1551. else
  1552. dbg("%s: blocking", __FUNCTION__);
  1553. #endif
  1554. for (list = devs.next; ; list = list->next) {
  1555. if (list == &devs)
  1556. return -ENODEV;
  1557. s = list_entry(list, struct it8172_state, devs);
  1558. if (!((s->dev_audio ^ minor) & ~0xf))
  1559. break;
  1560. }
  1561. file->private_data = s;
  1562. /* wait for device to become free */
  1563. down(&s->open_sem);
  1564. while (s->open_mode & file->f_mode) {
  1565. if (file->f_flags & O_NONBLOCK) {
  1566. up(&s->open_sem);
  1567. return -EBUSY;
  1568. }
  1569. add_wait_queue(&s->open_wait, &wait);
  1570. __set_current_state(TASK_INTERRUPTIBLE);
  1571. up(&s->open_sem);
  1572. schedule();
  1573. remove_wait_queue(&s->open_wait, &wait);
  1574. set_current_state(TASK_RUNNING);
  1575. if (signal_pending(current))
  1576. return -ERESTARTSYS;
  1577. down(&s->open_sem);
  1578. }
  1579. spin_lock_irqsave(&s->lock, flags);
  1580. if (file->f_mode & FMODE_READ) {
  1581. s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags =
  1582. s->dma_adc.subdivision = s->dma_adc.total_bytes = 0;
  1583. s->capcc &= ~(CC_SM | CC_DF);
  1584. set_adc_rate(s, 8000);
  1585. if ((minor & 0xf) == SND_DEV_DSP16)
  1586. s->capcc |= CC_DF;
  1587. outw(s->capcc, s->io+IT_AC_CAPCC);
  1588. if ((ret = prog_dmabuf_adc(s))) {
  1589. spin_unlock_irqrestore(&s->lock, flags);
  1590. return ret;
  1591. }
  1592. }
  1593. if (file->f_mode & FMODE_WRITE) {
  1594. s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags =
  1595. s->dma_dac.subdivision = s->dma_dac.total_bytes = 0;
  1596. s->pcc &= ~(CC_SM | CC_DF);
  1597. set_dac_rate(s, 8000);
  1598. if ((minor & 0xf) == SND_DEV_DSP16)
  1599. s->pcc |= CC_DF;
  1600. outw(s->pcc, s->io+IT_AC_PCC);
  1601. if ((ret = prog_dmabuf_dac(s))) {
  1602. spin_unlock_irqrestore(&s->lock, flags);
  1603. return ret;
  1604. }
  1605. }
  1606. spin_unlock_irqrestore(&s->lock, flags);
  1607. s->open_mode |= (file->f_mode & (FMODE_READ | FMODE_WRITE));
  1608. up(&s->open_sem);
  1609. return nonseekable_open(inode, file);
  1610. }
  1611. static int it8172_release(struct inode *inode, struct file *file)
  1612. {
  1613. struct it8172_state *s = (struct it8172_state *)file->private_data;
  1614. #ifdef IT8172_VERBOSE_DEBUG
  1615. dbg("%s", __FUNCTION__);
  1616. #endif
  1617. lock_kernel();
  1618. if (file->f_mode & FMODE_WRITE)
  1619. drain_dac(s, file->f_flags & O_NONBLOCK);
  1620. down(&s->open_sem);
  1621. if (file->f_mode & FMODE_WRITE) {
  1622. stop_dac(s);
  1623. dealloc_dmabuf(s, &s->dma_dac);
  1624. }
  1625. if (file->f_mode & FMODE_READ) {
  1626. stop_adc(s);
  1627. dealloc_dmabuf(s, &s->dma_adc);
  1628. }
  1629. s->open_mode &= ((~file->f_mode) & (FMODE_READ|FMODE_WRITE));
  1630. up(&s->open_sem);
  1631. wake_up(&s->open_wait);
  1632. unlock_kernel();
  1633. return 0;
  1634. }
  1635. static /*const*/ struct file_operations it8172_audio_fops = {
  1636. .owner = THIS_MODULE,
  1637. .llseek = no_llseek,
  1638. .read = it8172_read,
  1639. .write = it8172_write,
  1640. .poll = it8172_poll,
  1641. .ioctl = it8172_ioctl,
  1642. .mmap = it8172_mmap,
  1643. .open = it8172_open,
  1644. .release = it8172_release,
  1645. };
  1646. /* --------------------------------------------------------------------- */
  1647. /* --------------------------------------------------------------------- */
  1648. /*
  1649. * for debugging purposes, we'll create a proc device that dumps the
  1650. * CODEC chipstate
  1651. */
  1652. #ifdef IT8172_DEBUG
  1653. static int proc_it8172_dump (char *buf, char **start, off_t fpos,
  1654. int length, int *eof, void *data)
  1655. {
  1656. struct it8172_state *s;
  1657. int cnt, len = 0;
  1658. if (list_empty(&devs))
  1659. return 0;
  1660. s = list_entry(devs.next, struct it8172_state, devs);
  1661. /* print out header */
  1662. len += sprintf(buf + len, "\n\t\tIT8172 Audio Debug\n\n");
  1663. // print out digital controller state
  1664. len += sprintf (buf + len, "IT8172 Audio Controller registers\n");
  1665. len += sprintf (buf + len, "---------------------------------\n");
  1666. cnt=0;
  1667. while (cnt < 0x72) {
  1668. if (cnt == IT_AC_PCB1STA || cnt == IT_AC_PCB2STA ||
  1669. cnt == IT_AC_CAPB1STA || cnt == IT_AC_CAPB2STA ||
  1670. cnt == IT_AC_PFDP) {
  1671. len+= sprintf (buf + len, "reg %02x = %08x\n",
  1672. cnt, inl(s->io+cnt));
  1673. cnt += 4;
  1674. } else {
  1675. len+= sprintf (buf + len, "reg %02x = %04x\n",
  1676. cnt, inw(s->io+cnt));
  1677. cnt += 2;
  1678. }
  1679. }
  1680. /* print out CODEC state */
  1681. len += sprintf (buf + len, "\nAC97 CODEC registers\n");
  1682. len += sprintf (buf + len, "----------------------\n");
  1683. for (cnt=0; cnt <= 0x7e; cnt = cnt +2)
  1684. len+= sprintf (buf + len, "reg %02x = %04x\n",
  1685. cnt, rdcodec(&s->codec, cnt));
  1686. if (fpos >=len){
  1687. *start = buf;
  1688. *eof =1;
  1689. return 0;
  1690. }
  1691. *start = buf + fpos;
  1692. if ((len -= fpos) > length)
  1693. return length;
  1694. *eof =1;
  1695. return len;
  1696. }
  1697. #endif /* IT8172_DEBUG */
  1698. /* --------------------------------------------------------------------- */
  1699. /* maximum number of devices; only used for command line params */
  1700. #define NR_DEVICE 5
  1701. static int spdif[NR_DEVICE];
  1702. static int i2s_fmt[NR_DEVICE];
  1703. static unsigned int devindex;
  1704. MODULE_PARM(spdif, "1-" __MODULE_STRING(NR_DEVICE) "i");
  1705. MODULE_PARM_DESC(spdif, "if 1 the S/PDIF digital output is enabled");
  1706. MODULE_PARM(i2s_fmt, "1-" __MODULE_STRING(NR_DEVICE) "i");
  1707. MODULE_PARM_DESC(i2s_fmt, "the format of I2S");
  1708. MODULE_AUTHOR("Monta Vista Software, stevel@mvista.com");
  1709. MODULE_DESCRIPTION("IT8172 Audio Driver");
  1710. /* --------------------------------------------------------------------- */
  1711. static int __devinit it8172_probe(struct pci_dev *pcidev,
  1712. const struct pci_device_id *pciid)
  1713. {
  1714. struct it8172_state *s;
  1715. int i, val;
  1716. unsigned short pcisr, vol;
  1717. unsigned char legacy, imc;
  1718. char proc_str[80];
  1719. if (pcidev->irq == 0)
  1720. return -1;
  1721. if (!(s = kmalloc(sizeof(struct it8172_state), GFP_KERNEL))) {
  1722. err("alloc of device struct failed");
  1723. return -1;
  1724. }
  1725. memset(s, 0, sizeof(struct it8172_state));
  1726. init_waitqueue_head(&s->dma_adc.wait);
  1727. init_waitqueue_head(&s->dma_dac.wait);
  1728. init_waitqueue_head(&s->open_wait);
  1729. init_MUTEX(&s->open_sem);
  1730. spin_lock_init(&s->lock);
  1731. s->dev = pcidev;
  1732. s->io = pci_resource_start(pcidev, 0);
  1733. s->irq = pcidev->irq;
  1734. s->vendor = pcidev->vendor;
  1735. s->device = pcidev->device;
  1736. pci_read_config_byte(pcidev, PCI_REVISION_ID, &s->rev);
  1737. s->codec.private_data = s;
  1738. s->codec.id = 0;
  1739. s->codec.codec_read = rdcodec;
  1740. s->codec.codec_write = wrcodec;
  1741. s->codec.codec_wait = waitcodec;
  1742. if (!request_region(s->io, pci_resource_len(pcidev,0),
  1743. IT8172_MODULE_NAME)) {
  1744. err("io ports %#lx->%#lx in use",
  1745. s->io, s->io + pci_resource_len(pcidev,0)-1);
  1746. goto err_region;
  1747. }
  1748. if (request_irq(s->irq, it8172_interrupt, SA_INTERRUPT,
  1749. IT8172_MODULE_NAME, s)) {
  1750. err("irq %u in use", s->irq);
  1751. goto err_irq;
  1752. }
  1753. info("IO at %#lx, IRQ %d", s->io, s->irq);
  1754. /* register devices */
  1755. if ((s->dev_audio = register_sound_dsp(&it8172_audio_fops, -1)) < 0)
  1756. goto err_dev1;
  1757. if ((s->codec.dev_mixer =
  1758. register_sound_mixer(&it8172_mixer_fops, -1)) < 0)
  1759. goto err_dev2;
  1760. #ifdef IT8172_DEBUG
  1761. /* initialize the debug proc device */
  1762. s->ps = create_proc_read_entry(IT8172_MODULE_NAME, 0, NULL,
  1763. proc_it8172_dump, NULL);
  1764. #endif /* IT8172_DEBUG */
  1765. /*
  1766. * Reset the Audio device using the IT8172 PCI Reset register. This
  1767. * creates an audible double click on a speaker connected to Line-out.
  1768. */
  1769. IT_IO_READ16(IT_PM_PCISR, pcisr);
  1770. pcisr |= IT_PM_PCISR_ACSR;
  1771. IT_IO_WRITE16(IT_PM_PCISR, pcisr);
  1772. /* wait up to 100msec for reset to complete */
  1773. for (i=0; pcisr & IT_PM_PCISR_ACSR; i++) {
  1774. it8172_delay(10);
  1775. if (i == 10)
  1776. break;
  1777. IT_IO_READ16(IT_PM_PCISR, pcisr);
  1778. }
  1779. if (i == 10) {
  1780. err("chip reset timeout!");
  1781. goto err_dev3;
  1782. }
  1783. /* enable pci io and bus mastering */
  1784. if (pci_enable_device(pcidev))
  1785. goto err_dev3;
  1786. pci_set_master(pcidev);
  1787. /* get out of legacy mode */
  1788. pci_read_config_byte (pcidev, 0x40, &legacy);
  1789. pci_write_config_byte (pcidev, 0x40, legacy & ~1);
  1790. s->spdif_volume = -1;
  1791. /* check to see if s/pdif mode is being requested */
  1792. if (spdif[devindex]) {
  1793. info("enabling S/PDIF output");
  1794. s->spdif_volume = 0;
  1795. outb(GC_SOE, s->io+IT_AC_GC);
  1796. } else {
  1797. info("disabling S/PDIF output");
  1798. outb(0, s->io+IT_AC_GC);
  1799. }
  1800. /* check to see if I2S format requested */
  1801. if (i2s_fmt[devindex]) {
  1802. info("setting I2S format to 0x%02x", i2s_fmt[devindex]);
  1803. outb(i2s_fmt[devindex], s->io+IT_AC_I2SMC);
  1804. } else {
  1805. outb(I2SMC_I2SF_I2S, s->io+IT_AC_I2SMC);
  1806. }
  1807. /* cold reset the AC97 */
  1808. outw(CODECC_CR, s->io+IT_AC_CODECC);
  1809. udelay(1000);
  1810. outw(0, s->io+IT_AC_CODECC);
  1811. /* need to delay around 500msec(bleech) to give
  1812. some CODECs enough time to wakeup */
  1813. it8172_delay(500);
  1814. /* AC97 warm reset to start the bitclk */
  1815. outw(CODECC_WR, s->io+IT_AC_CODECC);
  1816. udelay(1000);
  1817. outw(0, s->io+IT_AC_CODECC);
  1818. /* codec init */
  1819. if (!ac97_probe_codec(&s->codec))
  1820. goto err_dev3;
  1821. /* add I2S as allowable recording source */
  1822. s->codec.record_sources |= SOUND_MASK_I2S;
  1823. /* Enable Volume button interrupts */
  1824. imc = inb(s->io+IT_AC_IMC);
  1825. outb(imc & ~IMC_VCIM, s->io+IT_AC_IMC);
  1826. /* Un-mute PCM and FM out on the controller */
  1827. vol = inw(s->io+IT_AC_PCMOV);
  1828. outw(vol & ~PCMOV_PCMOM, s->io+IT_AC_PCMOV);
  1829. vol = inw(s->io+IT_AC_FMOV);
  1830. outw(vol & ~FMOV_FMOM, s->io+IT_AC_FMOV);
  1831. /* set channel defaults to 8-bit, mono, 8 Khz */
  1832. s->pcc = 0;
  1833. s->capcc = 0;
  1834. set_dac_rate(s, 8000);
  1835. set_adc_rate(s, 8000);
  1836. /* set mic to be the recording source */
  1837. val = SOUND_MASK_MIC;
  1838. mixdev_ioctl(&s->codec, SOUND_MIXER_WRITE_RECSRC,
  1839. (unsigned long)&val);
  1840. /* mute AC'97 master and PCM when in S/PDIF mode */
  1841. if (s->spdif_volume != -1) {
  1842. val = 0x0000;
  1843. s->codec.mixer_ioctl(&s->codec, SOUND_MIXER_WRITE_VOLUME,
  1844. (unsigned long)&val);
  1845. s->codec.mixer_ioctl(&s->codec, SOUND_MIXER_WRITE_PCM,
  1846. (unsigned long)&val);
  1847. }
  1848. #ifdef IT8172_DEBUG
  1849. sprintf(proc_str, "driver/%s/%d/ac97", IT8172_MODULE_NAME,
  1850. s->codec.id);
  1851. s->ac97_ps = create_proc_read_entry (proc_str, 0, NULL,
  1852. ac97_read_proc, &s->codec);
  1853. #endif
  1854. /* store it in the driver field */
  1855. pci_set_drvdata(pcidev, s);
  1856. pcidev->dma_mask = 0xffffffff;
  1857. /* put it into driver list */
  1858. list_add_tail(&s->devs, &devs);
  1859. /* increment devindex */
  1860. if (devindex < NR_DEVICE-1)
  1861. devindex++;
  1862. return 0;
  1863. err_dev3:
  1864. unregister_sound_mixer(s->codec.dev_mixer);
  1865. err_dev2:
  1866. unregister_sound_dsp(s->dev_audio);
  1867. err_dev1:
  1868. err("cannot register misc device");
  1869. free_irq(s->irq, s);
  1870. err_irq:
  1871. release_region(s->io, pci_resource_len(pcidev,0));
  1872. err_region:
  1873. kfree(s);
  1874. return -1;
  1875. }
  1876. static void __devexit it8172_remove(struct pci_dev *dev)
  1877. {
  1878. struct it8172_state *s = pci_get_drvdata(dev);
  1879. if (!s)
  1880. return;
  1881. list_del(&s->devs);
  1882. #ifdef IT8172_DEBUG
  1883. if (s->ps)
  1884. remove_proc_entry(IT8172_MODULE_NAME, NULL);
  1885. #endif /* IT8172_DEBUG */
  1886. synchronize_irq(s->irq);
  1887. free_irq(s->irq, s);
  1888. release_region(s->io, pci_resource_len(dev,0));
  1889. unregister_sound_dsp(s->dev_audio);
  1890. unregister_sound_mixer(s->codec.dev_mixer);
  1891. kfree(s);
  1892. pci_set_drvdata(dev, NULL);
  1893. }
  1894. static struct pci_device_id id_table[] = {
  1895. { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_IT8172G_AUDIO, PCI_ANY_ID,
  1896. PCI_ANY_ID, 0, 0 },
  1897. { 0, }
  1898. };
  1899. MODULE_DEVICE_TABLE(pci, id_table);
  1900. static struct pci_driver it8172_driver = {
  1901. .name = IT8172_MODULE_NAME,
  1902. .id_table = id_table,
  1903. .probe = it8172_probe,
  1904. .remove = __devexit_p(it8172_remove)
  1905. };
  1906. static int __init init_it8172(void)
  1907. {
  1908. info("version v0.5 time " __TIME__ " " __DATE__);
  1909. return pci_register_driver(&it8172_driver);
  1910. }
  1911. static void __exit cleanup_it8172(void)
  1912. {
  1913. info("unloading");
  1914. pci_unregister_driver(&it8172_driver);
  1915. }
  1916. module_init(init_it8172);
  1917. module_exit(cleanup_it8172);
  1918. /* --------------------------------------------------------------------- */
  1919. #ifndef MODULE
  1920. /* format is: it8172=[spdif],[i2s:<I2S format>] */
  1921. static int __init it8172_setup(char *options)
  1922. {
  1923. char* this_opt;
  1924. static unsigned __initdata nr_dev = 0;
  1925. if (nr_dev >= NR_DEVICE)
  1926. return 0;
  1927. if (!options || !*options)
  1928. return 0;
  1929. while (this_opt = strsep(&options, ",")) {
  1930. if (!*this_opt)
  1931. continue;
  1932. if (!strncmp(this_opt, "spdif", 5)) {
  1933. spdif[nr_dev] = 1;
  1934. } else if (!strncmp(this_opt, "i2s:", 4)) {
  1935. if (!strncmp(this_opt+4, "dac", 3))
  1936. i2s_fmt[nr_dev] = I2SMC_I2SF_DAC;
  1937. else if (!strncmp(this_opt+4, "adc", 3))
  1938. i2s_fmt[nr_dev] = I2SMC_I2SF_ADC;
  1939. else if (!strncmp(this_opt+4, "i2s", 3))
  1940. i2s_fmt[nr_dev] = I2SMC_I2SF_I2S;
  1941. }
  1942. }
  1943. nr_dev++;
  1944. return 1;
  1945. }
  1946. __setup("it8172=", it8172_setup);
  1947. #endif /* MODULE */