mixer_oss.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383
  1. /*
  2. * OSS emulation layer for the mixer interface
  3. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  4. *
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. *
  20. */
  21. #include <linux/init.h>
  22. #include <linux/slab.h>
  23. #include <linux/time.h>
  24. #include <linux/string.h>
  25. #include <sound/core.h>
  26. #include <sound/minors.h>
  27. #include <sound/control.h>
  28. #include <sound/info.h>
  29. #include <sound/mixer_oss.h>
  30. #include <linux/soundcard.h>
  31. #define OSS_ALSAEMULVER _SIOR ('M', 249, int)
  32. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
  33. MODULE_DESCRIPTION("Mixer OSS emulation for ALSA.");
  34. MODULE_LICENSE("GPL");
  35. MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_MIXER);
  36. static int snd_mixer_oss_open(struct inode *inode, struct file *file)
  37. {
  38. struct snd_card *card;
  39. struct snd_mixer_oss_file *fmixer;
  40. int err;
  41. card = snd_lookup_oss_minor_data(iminor(inode),
  42. SNDRV_OSS_DEVICE_TYPE_MIXER);
  43. if (card == NULL)
  44. return -ENODEV;
  45. if (card->mixer_oss == NULL)
  46. return -ENODEV;
  47. err = snd_card_file_add(card, file);
  48. if (err < 0)
  49. return err;
  50. fmixer = kzalloc(sizeof(*fmixer), GFP_KERNEL);
  51. if (fmixer == NULL) {
  52. snd_card_file_remove(card, file);
  53. return -ENOMEM;
  54. }
  55. fmixer->card = card;
  56. fmixer->mixer = card->mixer_oss;
  57. file->private_data = fmixer;
  58. if (!try_module_get(card->module)) {
  59. kfree(fmixer);
  60. snd_card_file_remove(card, file);
  61. return -EFAULT;
  62. }
  63. return 0;
  64. }
  65. static int snd_mixer_oss_release(struct inode *inode, struct file *file)
  66. {
  67. struct snd_mixer_oss_file *fmixer;
  68. if (file->private_data) {
  69. fmixer = (struct snd_mixer_oss_file *) file->private_data;
  70. module_put(fmixer->card->module);
  71. snd_card_file_remove(fmixer->card, file);
  72. kfree(fmixer);
  73. }
  74. return 0;
  75. }
  76. static int snd_mixer_oss_info(struct snd_mixer_oss_file *fmixer,
  77. mixer_info __user *_info)
  78. {
  79. struct snd_card *card = fmixer->card;
  80. struct snd_mixer_oss *mixer = fmixer->mixer;
  81. struct mixer_info info;
  82. memset(&info, 0, sizeof(info));
  83. strlcpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id));
  84. strlcpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name));
  85. info.modify_counter = card->mixer_oss_change_count;
  86. if (copy_to_user(_info, &info, sizeof(info)))
  87. return -EFAULT;
  88. return 0;
  89. }
  90. static int snd_mixer_oss_info_obsolete(struct snd_mixer_oss_file *fmixer,
  91. _old_mixer_info __user *_info)
  92. {
  93. struct snd_card *card = fmixer->card;
  94. struct snd_mixer_oss *mixer = fmixer->mixer;
  95. _old_mixer_info info;
  96. memset(&info, 0, sizeof(info));
  97. strlcpy(info.id, mixer && mixer->id[0] ? mixer->id : card->driver, sizeof(info.id));
  98. strlcpy(info.name, mixer && mixer->name[0] ? mixer->name : card->mixername, sizeof(info.name));
  99. if (copy_to_user(_info, &info, sizeof(info)))
  100. return -EFAULT;
  101. return 0;
  102. }
  103. static int snd_mixer_oss_caps(struct snd_mixer_oss_file *fmixer)
  104. {
  105. struct snd_mixer_oss *mixer = fmixer->mixer;
  106. int result = 0;
  107. if (mixer == NULL)
  108. return -EIO;
  109. if (mixer->get_recsrc && mixer->put_recsrc)
  110. result |= SOUND_CAP_EXCL_INPUT;
  111. return result;
  112. }
  113. static int snd_mixer_oss_devmask(struct snd_mixer_oss_file *fmixer)
  114. {
  115. struct snd_mixer_oss *mixer = fmixer->mixer;
  116. struct snd_mixer_oss_slot *pslot;
  117. int result = 0, chn;
  118. if (mixer == NULL)
  119. return -EIO;
  120. for (chn = 0; chn < 31; chn++) {
  121. pslot = &mixer->slots[chn];
  122. if (pslot->put_volume || pslot->put_recsrc)
  123. result |= 1 << chn;
  124. }
  125. return result;
  126. }
  127. static int snd_mixer_oss_stereodevs(struct snd_mixer_oss_file *fmixer)
  128. {
  129. struct snd_mixer_oss *mixer = fmixer->mixer;
  130. struct snd_mixer_oss_slot *pslot;
  131. int result = 0, chn;
  132. if (mixer == NULL)
  133. return -EIO;
  134. for (chn = 0; chn < 31; chn++) {
  135. pslot = &mixer->slots[chn];
  136. if (pslot->put_volume && pslot->stereo)
  137. result |= 1 << chn;
  138. }
  139. return result;
  140. }
  141. static int snd_mixer_oss_recmask(struct snd_mixer_oss_file *fmixer)
  142. {
  143. struct snd_mixer_oss *mixer = fmixer->mixer;
  144. int result = 0;
  145. if (mixer == NULL)
  146. return -EIO;
  147. if (mixer->put_recsrc && mixer->get_recsrc) { /* exclusive */
  148. result = mixer->mask_recsrc;
  149. } else {
  150. struct snd_mixer_oss_slot *pslot;
  151. int chn;
  152. for (chn = 0; chn < 31; chn++) {
  153. pslot = &mixer->slots[chn];
  154. if (pslot->put_recsrc)
  155. result |= 1 << chn;
  156. }
  157. }
  158. return result;
  159. }
  160. static int snd_mixer_oss_get_recsrc(struct snd_mixer_oss_file *fmixer)
  161. {
  162. struct snd_mixer_oss *mixer = fmixer->mixer;
  163. int result = 0;
  164. if (mixer == NULL)
  165. return -EIO;
  166. if (mixer->put_recsrc && mixer->get_recsrc) { /* exclusive */
  167. int err;
  168. if ((err = mixer->get_recsrc(fmixer, &result)) < 0)
  169. return err;
  170. result = 1 << result;
  171. } else {
  172. struct snd_mixer_oss_slot *pslot;
  173. int chn;
  174. for (chn = 0; chn < 31; chn++) {
  175. pslot = &mixer->slots[chn];
  176. if (pslot->get_recsrc) {
  177. int active = 0;
  178. pslot->get_recsrc(fmixer, pslot, &active);
  179. if (active)
  180. result |= 1 << chn;
  181. }
  182. }
  183. }
  184. return mixer->oss_recsrc = result;
  185. }
  186. static int snd_mixer_oss_set_recsrc(struct snd_mixer_oss_file *fmixer, int recsrc)
  187. {
  188. struct snd_mixer_oss *mixer = fmixer->mixer;
  189. struct snd_mixer_oss_slot *pslot;
  190. int chn, active;
  191. int result = 0;
  192. if (mixer == NULL)
  193. return -EIO;
  194. if (mixer->get_recsrc && mixer->put_recsrc) { /* exclusive input */
  195. if (recsrc & ~mixer->oss_recsrc)
  196. recsrc &= ~mixer->oss_recsrc;
  197. mixer->put_recsrc(fmixer, ffz(~recsrc));
  198. mixer->get_recsrc(fmixer, &result);
  199. result = 1 << result;
  200. }
  201. for (chn = 0; chn < 31; chn++) {
  202. pslot = &mixer->slots[chn];
  203. if (pslot->put_recsrc) {
  204. active = (recsrc & (1 << chn)) ? 1 : 0;
  205. pslot->put_recsrc(fmixer, pslot, active);
  206. }
  207. }
  208. if (! result) {
  209. for (chn = 0; chn < 31; chn++) {
  210. pslot = &mixer->slots[chn];
  211. if (pslot->get_recsrc) {
  212. active = 0;
  213. pslot->get_recsrc(fmixer, pslot, &active);
  214. if (active)
  215. result |= 1 << chn;
  216. }
  217. }
  218. }
  219. return result;
  220. }
  221. static int snd_mixer_oss_get_volume(struct snd_mixer_oss_file *fmixer, int slot)
  222. {
  223. struct snd_mixer_oss *mixer = fmixer->mixer;
  224. struct snd_mixer_oss_slot *pslot;
  225. int result = 0, left, right;
  226. if (mixer == NULL || slot > 30)
  227. return -EIO;
  228. pslot = &mixer->slots[slot];
  229. left = pslot->volume[0];
  230. right = pslot->volume[1];
  231. if (pslot->get_volume)
  232. result = pslot->get_volume(fmixer, pslot, &left, &right);
  233. if (!pslot->stereo)
  234. right = left;
  235. snd_assert(left >= 0 && left <= 100, return -EIO);
  236. snd_assert(right >= 0 && right <= 100, return -EIO);
  237. if (result >= 0) {
  238. pslot->volume[0] = left;
  239. pslot->volume[1] = right;
  240. result = (left & 0xff) | ((right & 0xff) << 8);
  241. }
  242. return result;
  243. }
  244. static int snd_mixer_oss_set_volume(struct snd_mixer_oss_file *fmixer,
  245. int slot, int volume)
  246. {
  247. struct snd_mixer_oss *mixer = fmixer->mixer;
  248. struct snd_mixer_oss_slot *pslot;
  249. int result = 0, left = volume & 0xff, right = (volume >> 8) & 0xff;
  250. if (mixer == NULL || slot > 30)
  251. return -EIO;
  252. pslot = &mixer->slots[slot];
  253. if (left > 100)
  254. left = 100;
  255. if (right > 100)
  256. right = 100;
  257. if (!pslot->stereo)
  258. right = left;
  259. if (pslot->put_volume)
  260. result = pslot->put_volume(fmixer, pslot, left, right);
  261. if (result < 0)
  262. return result;
  263. pslot->volume[0] = left;
  264. pslot->volume[1] = right;
  265. return (left & 0xff) | ((right & 0xff) << 8);
  266. }
  267. static int snd_mixer_oss_ioctl1(struct snd_mixer_oss_file *fmixer, unsigned int cmd, unsigned long arg)
  268. {
  269. void __user *argp = (void __user *)arg;
  270. int __user *p = argp;
  271. int tmp;
  272. snd_assert(fmixer != NULL, return -ENXIO);
  273. if (((cmd >> 8) & 0xff) == 'M') {
  274. switch (cmd) {
  275. case SOUND_MIXER_INFO:
  276. return snd_mixer_oss_info(fmixer, argp);
  277. case SOUND_OLD_MIXER_INFO:
  278. return snd_mixer_oss_info_obsolete(fmixer, argp);
  279. case SOUND_MIXER_WRITE_RECSRC:
  280. if (get_user(tmp, p))
  281. return -EFAULT;
  282. tmp = snd_mixer_oss_set_recsrc(fmixer, tmp);
  283. if (tmp < 0)
  284. return tmp;
  285. return put_user(tmp, p);
  286. case OSS_GETVERSION:
  287. return put_user(SNDRV_OSS_VERSION, p);
  288. case OSS_ALSAEMULVER:
  289. return put_user(1, p);
  290. case SOUND_MIXER_READ_DEVMASK:
  291. tmp = snd_mixer_oss_devmask(fmixer);
  292. if (tmp < 0)
  293. return tmp;
  294. return put_user(tmp, p);
  295. case SOUND_MIXER_READ_STEREODEVS:
  296. tmp = snd_mixer_oss_stereodevs(fmixer);
  297. if (tmp < 0)
  298. return tmp;
  299. return put_user(tmp, p);
  300. case SOUND_MIXER_READ_RECMASK:
  301. tmp = snd_mixer_oss_recmask(fmixer);
  302. if (tmp < 0)
  303. return tmp;
  304. return put_user(tmp, p);
  305. case SOUND_MIXER_READ_CAPS:
  306. tmp = snd_mixer_oss_caps(fmixer);
  307. if (tmp < 0)
  308. return tmp;
  309. return put_user(tmp, p);
  310. case SOUND_MIXER_READ_RECSRC:
  311. tmp = snd_mixer_oss_get_recsrc(fmixer);
  312. if (tmp < 0)
  313. return tmp;
  314. return put_user(tmp, p);
  315. }
  316. }
  317. if (cmd & SIOC_IN) {
  318. if (get_user(tmp, p))
  319. return -EFAULT;
  320. tmp = snd_mixer_oss_set_volume(fmixer, cmd & 0xff, tmp);
  321. if (tmp < 0)
  322. return tmp;
  323. return put_user(tmp, p);
  324. } else if (cmd & SIOC_OUT) {
  325. tmp = snd_mixer_oss_get_volume(fmixer, cmd & 0xff);
  326. if (tmp < 0)
  327. return tmp;
  328. return put_user(tmp, p);
  329. }
  330. return -ENXIO;
  331. }
  332. static long snd_mixer_oss_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  333. {
  334. return snd_mixer_oss_ioctl1((struct snd_mixer_oss_file *) file->private_data, cmd, arg);
  335. }
  336. int snd_mixer_oss_ioctl_card(struct snd_card *card, unsigned int cmd, unsigned long arg)
  337. {
  338. struct snd_mixer_oss_file fmixer;
  339. snd_assert(card != NULL, return -ENXIO);
  340. if (card->mixer_oss == NULL)
  341. return -ENXIO;
  342. memset(&fmixer, 0, sizeof(fmixer));
  343. fmixer.card = card;
  344. fmixer.mixer = card->mixer_oss;
  345. return snd_mixer_oss_ioctl1(&fmixer, cmd, arg);
  346. }
  347. #ifdef CONFIG_COMPAT
  348. /* all compatible */
  349. #define snd_mixer_oss_ioctl_compat snd_mixer_oss_ioctl
  350. #else
  351. #define snd_mixer_oss_ioctl_compat NULL
  352. #endif
  353. /*
  354. * REGISTRATION PART
  355. */
  356. static const struct file_operations snd_mixer_oss_f_ops =
  357. {
  358. .owner = THIS_MODULE,
  359. .open = snd_mixer_oss_open,
  360. .release = snd_mixer_oss_release,
  361. .unlocked_ioctl = snd_mixer_oss_ioctl,
  362. .compat_ioctl = snd_mixer_oss_ioctl_compat,
  363. };
  364. /*
  365. * utilities
  366. */
  367. static long snd_mixer_oss_conv(long val, long omin, long omax, long nmin, long nmax)
  368. {
  369. long orange = omax - omin, nrange = nmax - nmin;
  370. if (orange == 0)
  371. return 0;
  372. return ((nrange * (val - omin)) + (orange / 2)) / orange + nmin;
  373. }
  374. /* convert from alsa native to oss values (0-100) */
  375. static long snd_mixer_oss_conv1(long val, long min, long max, int *old)
  376. {
  377. if (val == snd_mixer_oss_conv(*old, 0, 100, min, max))
  378. return *old;
  379. return snd_mixer_oss_conv(val, min, max, 0, 100);
  380. }
  381. /* convert from oss to alsa native values */
  382. static long snd_mixer_oss_conv2(long val, long min, long max)
  383. {
  384. return snd_mixer_oss_conv(val, 0, 100, min, max);
  385. }
  386. #if 0
  387. static void snd_mixer_oss_recsrce_set(struct snd_card *card, int slot)
  388. {
  389. struct snd_mixer_oss *mixer = card->mixer_oss;
  390. if (mixer)
  391. mixer->mask_recsrc |= 1 << slot;
  392. }
  393. static int snd_mixer_oss_recsrce_get(struct snd_card *card, int slot)
  394. {
  395. struct snd_mixer_oss *mixer = card->mixer_oss;
  396. if (mixer && (mixer->mask_recsrc & (1 << slot)))
  397. return 1;
  398. return 0;
  399. }
  400. #endif
  401. #define SNDRV_MIXER_OSS_SIGNATURE 0x65999250
  402. #define SNDRV_MIXER_OSS_ITEM_GLOBAL 0
  403. #define SNDRV_MIXER_OSS_ITEM_GSWITCH 1
  404. #define SNDRV_MIXER_OSS_ITEM_GROUTE 2
  405. #define SNDRV_MIXER_OSS_ITEM_GVOLUME 3
  406. #define SNDRV_MIXER_OSS_ITEM_PSWITCH 4
  407. #define SNDRV_MIXER_OSS_ITEM_PROUTE 5
  408. #define SNDRV_MIXER_OSS_ITEM_PVOLUME 6
  409. #define SNDRV_MIXER_OSS_ITEM_CSWITCH 7
  410. #define SNDRV_MIXER_OSS_ITEM_CROUTE 8
  411. #define SNDRV_MIXER_OSS_ITEM_CVOLUME 9
  412. #define SNDRV_MIXER_OSS_ITEM_CAPTURE 10
  413. #define SNDRV_MIXER_OSS_ITEM_COUNT 11
  414. #define SNDRV_MIXER_OSS_PRESENT_GLOBAL (1<<0)
  415. #define SNDRV_MIXER_OSS_PRESENT_GSWITCH (1<<1)
  416. #define SNDRV_MIXER_OSS_PRESENT_GROUTE (1<<2)
  417. #define SNDRV_MIXER_OSS_PRESENT_GVOLUME (1<<3)
  418. #define SNDRV_MIXER_OSS_PRESENT_PSWITCH (1<<4)
  419. #define SNDRV_MIXER_OSS_PRESENT_PROUTE (1<<5)
  420. #define SNDRV_MIXER_OSS_PRESENT_PVOLUME (1<<6)
  421. #define SNDRV_MIXER_OSS_PRESENT_CSWITCH (1<<7)
  422. #define SNDRV_MIXER_OSS_PRESENT_CROUTE (1<<8)
  423. #define SNDRV_MIXER_OSS_PRESENT_CVOLUME (1<<9)
  424. #define SNDRV_MIXER_OSS_PRESENT_CAPTURE (1<<10)
  425. struct slot {
  426. unsigned int signature;
  427. unsigned int present;
  428. unsigned int channels;
  429. unsigned int numid[SNDRV_MIXER_OSS_ITEM_COUNT];
  430. unsigned int capture_item;
  431. struct snd_mixer_oss_assign_table *assigned;
  432. unsigned int allocated: 1;
  433. };
  434. #define ID_UNKNOWN ((unsigned int)-1)
  435. static struct snd_kcontrol *snd_mixer_oss_test_id(struct snd_mixer_oss *mixer, const char *name, int index)
  436. {
  437. struct snd_card *card = mixer->card;
  438. struct snd_ctl_elem_id id;
  439. memset(&id, 0, sizeof(id));
  440. id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  441. strcpy(id.name, name);
  442. id.index = index;
  443. return snd_ctl_find_id(card, &id);
  444. }
  445. static void snd_mixer_oss_get_volume1_vol(struct snd_mixer_oss_file *fmixer,
  446. struct snd_mixer_oss_slot *pslot,
  447. unsigned int numid,
  448. int *left, int *right)
  449. {
  450. struct snd_ctl_elem_info *uinfo;
  451. struct snd_ctl_elem_value *uctl;
  452. struct snd_kcontrol *kctl;
  453. struct snd_card *card = fmixer->card;
  454. if (numid == ID_UNKNOWN)
  455. return;
  456. down_read(&card->controls_rwsem);
  457. if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) {
  458. up_read(&card->controls_rwsem);
  459. return;
  460. }
  461. uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
  462. uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
  463. if (uinfo == NULL || uctl == NULL)
  464. goto __unalloc;
  465. if (kctl->info(kctl, uinfo))
  466. goto __unalloc;
  467. if (kctl->get(kctl, uctl))
  468. goto __unalloc;
  469. if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN &&
  470. uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1)
  471. goto __unalloc;
  472. *left = snd_mixer_oss_conv1(uctl->value.integer.value[0], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[0]);
  473. if (uinfo->count > 1)
  474. *right = snd_mixer_oss_conv1(uctl->value.integer.value[1], uinfo->value.integer.min, uinfo->value.integer.max, &pslot->volume[1]);
  475. __unalloc:
  476. up_read(&card->controls_rwsem);
  477. kfree(uctl);
  478. kfree(uinfo);
  479. }
  480. static void snd_mixer_oss_get_volume1_sw(struct snd_mixer_oss_file *fmixer,
  481. struct snd_mixer_oss_slot *pslot,
  482. unsigned int numid,
  483. int *left, int *right,
  484. int route)
  485. {
  486. struct snd_ctl_elem_info *uinfo;
  487. struct snd_ctl_elem_value *uctl;
  488. struct snd_kcontrol *kctl;
  489. struct snd_card *card = fmixer->card;
  490. if (numid == ID_UNKNOWN)
  491. return;
  492. down_read(&card->controls_rwsem);
  493. if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) {
  494. up_read(&card->controls_rwsem);
  495. return;
  496. }
  497. uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
  498. uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
  499. if (uinfo == NULL || uctl == NULL)
  500. goto __unalloc;
  501. if (kctl->info(kctl, uinfo))
  502. goto __unalloc;
  503. if (kctl->get(kctl, uctl))
  504. goto __unalloc;
  505. if (!uctl->value.integer.value[0]) {
  506. *left = 0;
  507. if (uinfo->count == 1)
  508. *right = 0;
  509. }
  510. if (uinfo->count > 1 && !uctl->value.integer.value[route ? 3 : 1])
  511. *right = 0;
  512. __unalloc:
  513. up_read(&card->controls_rwsem);
  514. kfree(uctl);
  515. kfree(uinfo);
  516. }
  517. static int snd_mixer_oss_get_volume1(struct snd_mixer_oss_file *fmixer,
  518. struct snd_mixer_oss_slot *pslot,
  519. int *left, int *right)
  520. {
  521. struct slot *slot = (struct slot *)pslot->private_data;
  522. *left = *right = 100;
  523. if (slot->present & SNDRV_MIXER_OSS_PRESENT_PVOLUME) {
  524. snd_mixer_oss_get_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PVOLUME], left, right);
  525. } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GVOLUME) {
  526. snd_mixer_oss_get_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GVOLUME], left, right);
  527. } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GLOBAL) {
  528. snd_mixer_oss_get_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GLOBAL], left, right);
  529. }
  530. if (slot->present & SNDRV_MIXER_OSS_PRESENT_PSWITCH) {
  531. snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PSWITCH], left, right, 0);
  532. } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GSWITCH) {
  533. snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GSWITCH], left, right, 0);
  534. } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_PROUTE) {
  535. snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PROUTE], left, right, 1);
  536. } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GROUTE) {
  537. snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GROUTE], left, right, 1);
  538. }
  539. return 0;
  540. }
  541. static void snd_mixer_oss_put_volume1_vol(struct snd_mixer_oss_file *fmixer,
  542. struct snd_mixer_oss_slot *pslot,
  543. unsigned int numid,
  544. int left, int right)
  545. {
  546. struct snd_ctl_elem_info *uinfo;
  547. struct snd_ctl_elem_value *uctl;
  548. struct snd_kcontrol *kctl;
  549. struct snd_card *card = fmixer->card;
  550. int res;
  551. if (numid == ID_UNKNOWN)
  552. return;
  553. down_read(&card->controls_rwsem);
  554. if ((kctl = snd_ctl_find_numid(card, numid)) == NULL)
  555. return;
  556. uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
  557. uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
  558. if (uinfo == NULL || uctl == NULL)
  559. goto __unalloc;
  560. if (kctl->info(kctl, uinfo))
  561. goto __unalloc;
  562. if (uinfo->type == SNDRV_CTL_ELEM_TYPE_BOOLEAN &&
  563. uinfo->value.integer.min == 0 && uinfo->value.integer.max == 1)
  564. goto __unalloc;
  565. uctl->value.integer.value[0] = snd_mixer_oss_conv2(left, uinfo->value.integer.min, uinfo->value.integer.max);
  566. if (uinfo->count > 1)
  567. uctl->value.integer.value[1] = snd_mixer_oss_conv2(right, uinfo->value.integer.min, uinfo->value.integer.max);
  568. if ((res = kctl->put(kctl, uctl)) < 0)
  569. goto __unalloc;
  570. if (res > 0)
  571. snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
  572. __unalloc:
  573. up_read(&card->controls_rwsem);
  574. kfree(uctl);
  575. kfree(uinfo);
  576. }
  577. static void snd_mixer_oss_put_volume1_sw(struct snd_mixer_oss_file *fmixer,
  578. struct snd_mixer_oss_slot *pslot,
  579. unsigned int numid,
  580. int left, int right,
  581. int route)
  582. {
  583. struct snd_ctl_elem_info *uinfo;
  584. struct snd_ctl_elem_value *uctl;
  585. struct snd_kcontrol *kctl;
  586. struct snd_card *card = fmixer->card;
  587. int res;
  588. if (numid == ID_UNKNOWN)
  589. return;
  590. down_read(&card->controls_rwsem);
  591. if ((kctl = snd_ctl_find_numid(card, numid)) == NULL) {
  592. up_read(&fmixer->card->controls_rwsem);
  593. return;
  594. }
  595. uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
  596. uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
  597. if (uinfo == NULL || uctl == NULL)
  598. goto __unalloc;
  599. if (kctl->info(kctl, uinfo))
  600. goto __unalloc;
  601. if (uinfo->count > 1) {
  602. uctl->value.integer.value[0] = left > 0 ? 1 : 0;
  603. uctl->value.integer.value[route ? 3 : 1] = right > 0 ? 1 : 0;
  604. if (route) {
  605. uctl->value.integer.value[1] =
  606. uctl->value.integer.value[2] = 0;
  607. }
  608. } else {
  609. uctl->value.integer.value[0] = (left > 0 || right > 0) ? 1 : 0;
  610. }
  611. if ((res = kctl->put(kctl, uctl)) < 0)
  612. goto __unalloc;
  613. if (res > 0)
  614. snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
  615. __unalloc:
  616. up_read(&card->controls_rwsem);
  617. kfree(uctl);
  618. kfree(uinfo);
  619. }
  620. static int snd_mixer_oss_put_volume1(struct snd_mixer_oss_file *fmixer,
  621. struct snd_mixer_oss_slot *pslot,
  622. int left, int right)
  623. {
  624. struct slot *slot = (struct slot *)pslot->private_data;
  625. if (slot->present & SNDRV_MIXER_OSS_PRESENT_PVOLUME) {
  626. snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PVOLUME], left, right);
  627. if (slot->present & SNDRV_MIXER_OSS_PRESENT_CVOLUME)
  628. snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CVOLUME], left, right);
  629. } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GVOLUME) {
  630. snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GVOLUME], left, right);
  631. } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GLOBAL) {
  632. snd_mixer_oss_put_volume1_vol(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GLOBAL], left, right);
  633. }
  634. if (left || right) {
  635. if (slot->present & SNDRV_MIXER_OSS_PRESENT_PSWITCH)
  636. snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PSWITCH], left, right, 0);
  637. if (slot->present & SNDRV_MIXER_OSS_PRESENT_GSWITCH)
  638. snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GSWITCH], left, right, 0);
  639. if (slot->present & SNDRV_MIXER_OSS_PRESENT_PROUTE)
  640. snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PROUTE], left, right, 1);
  641. if (slot->present & SNDRV_MIXER_OSS_PRESENT_GROUTE)
  642. snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GROUTE], left, right, 1);
  643. } else {
  644. if (slot->present & SNDRV_MIXER_OSS_PRESENT_PSWITCH) {
  645. snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PSWITCH], left, right, 0);
  646. } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GSWITCH) {
  647. snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GSWITCH], left, right, 0);
  648. } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_PROUTE) {
  649. snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_PROUTE], left, right, 1);
  650. } else if (slot->present & SNDRV_MIXER_OSS_PRESENT_GROUTE) {
  651. snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_GROUTE], left, right, 1);
  652. }
  653. }
  654. return 0;
  655. }
  656. static int snd_mixer_oss_get_recsrc1_sw(struct snd_mixer_oss_file *fmixer,
  657. struct snd_mixer_oss_slot *pslot,
  658. int *active)
  659. {
  660. struct slot *slot = (struct slot *)pslot->private_data;
  661. int left, right;
  662. left = right = 1;
  663. snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CSWITCH], &left, &right, 0);
  664. *active = (left || right) ? 1 : 0;
  665. return 0;
  666. }
  667. static int snd_mixer_oss_get_recsrc1_route(struct snd_mixer_oss_file *fmixer,
  668. struct snd_mixer_oss_slot *pslot,
  669. int *active)
  670. {
  671. struct slot *slot = (struct slot *)pslot->private_data;
  672. int left, right;
  673. left = right = 1;
  674. snd_mixer_oss_get_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CROUTE], &left, &right, 1);
  675. *active = (left || right) ? 1 : 0;
  676. return 0;
  677. }
  678. static int snd_mixer_oss_put_recsrc1_sw(struct snd_mixer_oss_file *fmixer,
  679. struct snd_mixer_oss_slot *pslot,
  680. int active)
  681. {
  682. struct slot *slot = (struct slot *)pslot->private_data;
  683. snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CSWITCH], active, active, 0);
  684. return 0;
  685. }
  686. static int snd_mixer_oss_put_recsrc1_route(struct snd_mixer_oss_file *fmixer,
  687. struct snd_mixer_oss_slot *pslot,
  688. int active)
  689. {
  690. struct slot *slot = (struct slot *)pslot->private_data;
  691. snd_mixer_oss_put_volume1_sw(fmixer, pslot, slot->numid[SNDRV_MIXER_OSS_ITEM_CROUTE], active, active, 1);
  692. return 0;
  693. }
  694. static int snd_mixer_oss_get_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned int *active_index)
  695. {
  696. struct snd_card *card = fmixer->card;
  697. struct snd_mixer_oss *mixer = fmixer->mixer;
  698. struct snd_kcontrol *kctl;
  699. struct snd_mixer_oss_slot *pslot;
  700. struct slot *slot;
  701. struct snd_ctl_elem_info *uinfo;
  702. struct snd_ctl_elem_value *uctl;
  703. int err, idx;
  704. uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
  705. uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
  706. if (uinfo == NULL || uctl == NULL) {
  707. err = -ENOMEM;
  708. goto __unlock;
  709. }
  710. down_read(&card->controls_rwsem);
  711. kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
  712. if (! kctl) {
  713. err = -ENOENT;
  714. goto __unlock;
  715. }
  716. if ((err = kctl->info(kctl, uinfo)) < 0)
  717. goto __unlock;
  718. if ((err = kctl->get(kctl, uctl)) < 0)
  719. goto __unlock;
  720. for (idx = 0; idx < 32; idx++) {
  721. if (!(mixer->mask_recsrc & (1 << idx)))
  722. continue;
  723. pslot = &mixer->slots[idx];
  724. slot = (struct slot *)pslot->private_data;
  725. if (slot->signature != SNDRV_MIXER_OSS_SIGNATURE)
  726. continue;
  727. if (!(slot->present & SNDRV_MIXER_OSS_PRESENT_CAPTURE))
  728. continue;
  729. if (slot->capture_item == uctl->value.enumerated.item[0]) {
  730. *active_index = idx;
  731. break;
  732. }
  733. }
  734. err = 0;
  735. __unlock:
  736. up_read(&card->controls_rwsem);
  737. kfree(uctl);
  738. kfree(uinfo);
  739. return err;
  740. }
  741. static int snd_mixer_oss_put_recsrc2(struct snd_mixer_oss_file *fmixer, unsigned int active_index)
  742. {
  743. struct snd_card *card = fmixer->card;
  744. struct snd_mixer_oss *mixer = fmixer->mixer;
  745. struct snd_kcontrol *kctl;
  746. struct snd_mixer_oss_slot *pslot;
  747. struct slot *slot = NULL;
  748. struct snd_ctl_elem_info *uinfo;
  749. struct snd_ctl_elem_value *uctl;
  750. int err;
  751. unsigned int idx;
  752. uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
  753. uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
  754. if (uinfo == NULL || uctl == NULL) {
  755. err = -ENOMEM;
  756. goto __unlock;
  757. }
  758. down_read(&card->controls_rwsem);
  759. kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0);
  760. if (! kctl) {
  761. err = -ENOENT;
  762. goto __unlock;
  763. }
  764. if ((err = kctl->info(kctl, uinfo)) < 0)
  765. goto __unlock;
  766. for (idx = 0; idx < 32; idx++) {
  767. if (!(mixer->mask_recsrc & (1 << idx)))
  768. continue;
  769. pslot = &mixer->slots[idx];
  770. slot = (struct slot *)pslot->private_data;
  771. if (slot->signature != SNDRV_MIXER_OSS_SIGNATURE)
  772. continue;
  773. if (!(slot->present & SNDRV_MIXER_OSS_PRESENT_CAPTURE))
  774. continue;
  775. if (idx == active_index)
  776. break;
  777. slot = NULL;
  778. }
  779. if (! slot)
  780. goto __unlock;
  781. for (idx = 0; idx < uinfo->count; idx++)
  782. uctl->value.enumerated.item[idx] = slot->capture_item;
  783. err = kctl->put(kctl, uctl);
  784. if (err > 0)
  785. snd_ctl_notify(fmixer->card, SNDRV_CTL_EVENT_MASK_VALUE, &kctl->id);
  786. err = 0;
  787. __unlock:
  788. up_read(&card->controls_rwsem);
  789. kfree(uctl);
  790. kfree(uinfo);
  791. return err;
  792. }
  793. struct snd_mixer_oss_assign_table {
  794. int oss_id;
  795. const char *name;
  796. int index;
  797. };
  798. static int snd_mixer_oss_build_test(struct snd_mixer_oss *mixer, struct slot *slot, const char *name, int index, int item)
  799. {
  800. struct snd_ctl_elem_info *info;
  801. struct snd_kcontrol *kcontrol;
  802. struct snd_card *card = mixer->card;
  803. int err;
  804. down_read(&card->controls_rwsem);
  805. kcontrol = snd_mixer_oss_test_id(mixer, name, index);
  806. if (kcontrol == NULL) {
  807. up_read(&card->controls_rwsem);
  808. return 0;
  809. }
  810. info = kmalloc(sizeof(*info), GFP_KERNEL);
  811. if (! info) {
  812. up_read(&card->controls_rwsem);
  813. return -ENOMEM;
  814. }
  815. if ((err = kcontrol->info(kcontrol, info)) < 0) {
  816. up_read(&card->controls_rwsem);
  817. kfree(info);
  818. return err;
  819. }
  820. slot->numid[item] = kcontrol->id.numid;
  821. up_read(&card->controls_rwsem);
  822. if (info->count > slot->channels)
  823. slot->channels = info->count;
  824. slot->present |= 1 << item;
  825. kfree(info);
  826. return 0;
  827. }
  828. static void snd_mixer_oss_slot_free(struct snd_mixer_oss_slot *chn)
  829. {
  830. struct slot *p = (struct slot *)chn->private_data;
  831. if (p) {
  832. if (p->allocated && p->assigned) {
  833. kfree(p->assigned->name);
  834. kfree(p->assigned);
  835. }
  836. kfree(p);
  837. }
  838. }
  839. static void mixer_slot_clear(struct snd_mixer_oss_slot *rslot)
  840. {
  841. int idx = rslot->number; /* remember this */
  842. if (rslot->private_free)
  843. rslot->private_free(rslot);
  844. memset(rslot, 0, sizeof(*rslot));
  845. rslot->number = idx;
  846. }
  847. /* In a separate function to keep gcc 3.2 happy - do NOT merge this in
  848. snd_mixer_oss_build_input! */
  849. static int snd_mixer_oss_build_test_all(struct snd_mixer_oss *mixer,
  850. struct snd_mixer_oss_assign_table *ptr,
  851. struct slot *slot)
  852. {
  853. char str[64];
  854. int err;
  855. err = snd_mixer_oss_build_test(mixer, slot, ptr->name, ptr->index,
  856. SNDRV_MIXER_OSS_ITEM_GLOBAL);
  857. if (err)
  858. return err;
  859. sprintf(str, "%s Switch", ptr->name);
  860. err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
  861. SNDRV_MIXER_OSS_ITEM_GSWITCH);
  862. if (err)
  863. return err;
  864. sprintf(str, "%s Route", ptr->name);
  865. err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
  866. SNDRV_MIXER_OSS_ITEM_GROUTE);
  867. if (err)
  868. return err;
  869. sprintf(str, "%s Volume", ptr->name);
  870. err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
  871. SNDRV_MIXER_OSS_ITEM_GVOLUME);
  872. if (err)
  873. return err;
  874. sprintf(str, "%s Playback Switch", ptr->name);
  875. err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
  876. SNDRV_MIXER_OSS_ITEM_PSWITCH);
  877. if (err)
  878. return err;
  879. sprintf(str, "%s Playback Route", ptr->name);
  880. err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
  881. SNDRV_MIXER_OSS_ITEM_PROUTE);
  882. if (err)
  883. return err;
  884. sprintf(str, "%s Playback Volume", ptr->name);
  885. err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
  886. SNDRV_MIXER_OSS_ITEM_PVOLUME);
  887. if (err)
  888. return err;
  889. sprintf(str, "%s Capture Switch", ptr->name);
  890. err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
  891. SNDRV_MIXER_OSS_ITEM_CSWITCH);
  892. if (err)
  893. return err;
  894. sprintf(str, "%s Capture Route", ptr->name);
  895. err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
  896. SNDRV_MIXER_OSS_ITEM_CROUTE);
  897. if (err)
  898. return err;
  899. sprintf(str, "%s Capture Volume", ptr->name);
  900. err = snd_mixer_oss_build_test(mixer, slot, str, ptr->index,
  901. SNDRV_MIXER_OSS_ITEM_CVOLUME);
  902. if (err)
  903. return err;
  904. return 0;
  905. }
  906. /*
  907. * build an OSS mixer element.
  908. * ptr_allocated means the entry is dynamically allocated (change via proc file).
  909. * when replace_old = 1, the old entry is replaced with the new one.
  910. */
  911. static int snd_mixer_oss_build_input(struct snd_mixer_oss *mixer, struct snd_mixer_oss_assign_table *ptr, int ptr_allocated, int replace_old)
  912. {
  913. struct slot slot;
  914. struct slot *pslot;
  915. struct snd_kcontrol *kctl;
  916. struct snd_mixer_oss_slot *rslot;
  917. char str[64];
  918. /* check if already assigned */
  919. if (mixer->slots[ptr->oss_id].get_volume && ! replace_old)
  920. return 0;
  921. memset(&slot, 0, sizeof(slot));
  922. memset(slot.numid, 0xff, sizeof(slot.numid)); /* ID_UNKNOWN */
  923. if (snd_mixer_oss_build_test_all(mixer, ptr, &slot))
  924. return 0;
  925. down_read(&mixer->card->controls_rwsem);
  926. if (ptr->index == 0 && (kctl = snd_mixer_oss_test_id(mixer, "Capture Source", 0)) != NULL) {
  927. struct snd_ctl_elem_info *uinfo;
  928. uinfo = kzalloc(sizeof(*uinfo), GFP_KERNEL);
  929. if (! uinfo) {
  930. up_read(&mixer->card->controls_rwsem);
  931. return -ENOMEM;
  932. }
  933. if (kctl->info(kctl, uinfo)) {
  934. up_read(&mixer->card->controls_rwsem);
  935. return 0;
  936. }
  937. strcpy(str, ptr->name);
  938. if (!strcmp(str, "Master"))
  939. strcpy(str, "Mix");
  940. if (!strcmp(str, "Master Mono"))
  941. strcpy(str, "Mix Mono");
  942. slot.capture_item = 0;
  943. if (!strcmp(uinfo->value.enumerated.name, str)) {
  944. slot.present |= SNDRV_MIXER_OSS_PRESENT_CAPTURE;
  945. } else {
  946. for (slot.capture_item = 1; slot.capture_item < uinfo->value.enumerated.items; slot.capture_item++) {
  947. uinfo->value.enumerated.item = slot.capture_item;
  948. if (kctl->info(kctl, uinfo)) {
  949. up_read(&mixer->card->controls_rwsem);
  950. return 0;
  951. }
  952. if (!strcmp(uinfo->value.enumerated.name, str)) {
  953. slot.present |= SNDRV_MIXER_OSS_PRESENT_CAPTURE;
  954. break;
  955. }
  956. }
  957. }
  958. kfree(uinfo);
  959. }
  960. up_read(&mixer->card->controls_rwsem);
  961. if (slot.present != 0) {
  962. pslot = kmalloc(sizeof(slot), GFP_KERNEL);
  963. if (! pslot)
  964. return -ENOMEM;
  965. *pslot = slot;
  966. pslot->signature = SNDRV_MIXER_OSS_SIGNATURE;
  967. pslot->assigned = ptr;
  968. pslot->allocated = ptr_allocated;
  969. rslot = &mixer->slots[ptr->oss_id];
  970. mixer_slot_clear(rslot);
  971. rslot->stereo = slot.channels > 1 ? 1 : 0;
  972. rslot->get_volume = snd_mixer_oss_get_volume1;
  973. rslot->put_volume = snd_mixer_oss_put_volume1;
  974. /* note: ES18xx have both Capture Source and XX Capture Volume !!! */
  975. if (slot.present & SNDRV_MIXER_OSS_PRESENT_CSWITCH) {
  976. rslot->get_recsrc = snd_mixer_oss_get_recsrc1_sw;
  977. rslot->put_recsrc = snd_mixer_oss_put_recsrc1_sw;
  978. } else if (slot.present & SNDRV_MIXER_OSS_PRESENT_CROUTE) {
  979. rslot->get_recsrc = snd_mixer_oss_get_recsrc1_route;
  980. rslot->put_recsrc = snd_mixer_oss_put_recsrc1_route;
  981. } else if (slot.present & SNDRV_MIXER_OSS_PRESENT_CAPTURE) {
  982. mixer->mask_recsrc |= 1 << ptr->oss_id;
  983. }
  984. rslot->private_data = pslot;
  985. rslot->private_free = snd_mixer_oss_slot_free;
  986. return 1;
  987. }
  988. return 0;
  989. }
  990. #ifdef CONFIG_PROC_FS
  991. /*
  992. */
  993. #define MIXER_VOL(name) [SOUND_MIXER_##name] = #name
  994. static char *oss_mixer_names[SNDRV_OSS_MAX_MIXERS] = {
  995. MIXER_VOL(VOLUME),
  996. MIXER_VOL(BASS),
  997. MIXER_VOL(TREBLE),
  998. MIXER_VOL(SYNTH),
  999. MIXER_VOL(PCM),
  1000. MIXER_VOL(SPEAKER),
  1001. MIXER_VOL(LINE),
  1002. MIXER_VOL(MIC),
  1003. MIXER_VOL(CD),
  1004. MIXER_VOL(IMIX),
  1005. MIXER_VOL(ALTPCM),
  1006. MIXER_VOL(RECLEV),
  1007. MIXER_VOL(IGAIN),
  1008. MIXER_VOL(OGAIN),
  1009. MIXER_VOL(LINE1),
  1010. MIXER_VOL(LINE2),
  1011. MIXER_VOL(LINE3),
  1012. MIXER_VOL(DIGITAL1),
  1013. MIXER_VOL(DIGITAL2),
  1014. MIXER_VOL(DIGITAL3),
  1015. MIXER_VOL(PHONEIN),
  1016. MIXER_VOL(PHONEOUT),
  1017. MIXER_VOL(VIDEO),
  1018. MIXER_VOL(RADIO),
  1019. MIXER_VOL(MONITOR),
  1020. };
  1021. /*
  1022. * /proc interface
  1023. */
  1024. static void snd_mixer_oss_proc_read(struct snd_info_entry *entry,
  1025. struct snd_info_buffer *buffer)
  1026. {
  1027. struct snd_mixer_oss *mixer = entry->private_data;
  1028. int i;
  1029. mutex_lock(&mixer->reg_mutex);
  1030. for (i = 0; i < SNDRV_OSS_MAX_MIXERS; i++) {
  1031. struct slot *p;
  1032. if (! oss_mixer_names[i])
  1033. continue;
  1034. p = (struct slot *)mixer->slots[i].private_data;
  1035. snd_iprintf(buffer, "%s ", oss_mixer_names[i]);
  1036. if (p && p->assigned)
  1037. snd_iprintf(buffer, "\"%s\" %d\n",
  1038. p->assigned->name,
  1039. p->assigned->index);
  1040. else
  1041. snd_iprintf(buffer, "\"\" 0\n");
  1042. }
  1043. mutex_unlock(&mixer->reg_mutex);
  1044. }
  1045. static void snd_mixer_oss_proc_write(struct snd_info_entry *entry,
  1046. struct snd_info_buffer *buffer)
  1047. {
  1048. struct snd_mixer_oss *mixer = entry->private_data;
  1049. char line[128], str[32], idxstr[16], *cptr;
  1050. int ch, idx;
  1051. struct snd_mixer_oss_assign_table *tbl;
  1052. struct slot *slot;
  1053. while (!snd_info_get_line(buffer, line, sizeof(line))) {
  1054. cptr = snd_info_get_str(str, line, sizeof(str));
  1055. for (ch = 0; ch < SNDRV_OSS_MAX_MIXERS; ch++)
  1056. if (oss_mixer_names[ch] && strcmp(oss_mixer_names[ch], str) == 0)
  1057. break;
  1058. if (ch >= SNDRV_OSS_MAX_MIXERS) {
  1059. snd_printk(KERN_ERR "mixer_oss: invalid OSS volume '%s'\n", str);
  1060. continue;
  1061. }
  1062. cptr = snd_info_get_str(str, cptr, sizeof(str));
  1063. if (! *str) {
  1064. /* remove the entry */
  1065. mutex_lock(&mixer->reg_mutex);
  1066. mixer_slot_clear(&mixer->slots[ch]);
  1067. mutex_unlock(&mixer->reg_mutex);
  1068. continue;
  1069. }
  1070. snd_info_get_str(idxstr, cptr, sizeof(idxstr));
  1071. idx = simple_strtoul(idxstr, NULL, 10);
  1072. if (idx >= 0x4000) { /* too big */
  1073. snd_printk(KERN_ERR "mixer_oss: invalid index %d\n", idx);
  1074. continue;
  1075. }
  1076. mutex_lock(&mixer->reg_mutex);
  1077. slot = (struct slot *)mixer->slots[ch].private_data;
  1078. if (slot && slot->assigned &&
  1079. slot->assigned->index == idx && ! strcmp(slot->assigned->name, str))
  1080. /* not changed */
  1081. goto __unlock;
  1082. tbl = kmalloc(sizeof(*tbl), GFP_KERNEL);
  1083. if (! tbl) {
  1084. snd_printk(KERN_ERR "mixer_oss: no memory\n");
  1085. goto __unlock;
  1086. }
  1087. tbl->oss_id = ch;
  1088. tbl->name = kstrdup(str, GFP_KERNEL);
  1089. if (! tbl->name) {
  1090. kfree(tbl);
  1091. goto __unlock;
  1092. }
  1093. tbl->index = idx;
  1094. if (snd_mixer_oss_build_input(mixer, tbl, 1, 1) <= 0) {
  1095. kfree(tbl->name);
  1096. kfree(tbl);
  1097. }
  1098. __unlock:
  1099. mutex_unlock(&mixer->reg_mutex);
  1100. }
  1101. }
  1102. static void snd_mixer_oss_proc_init(struct snd_mixer_oss *mixer)
  1103. {
  1104. struct snd_info_entry *entry;
  1105. entry = snd_info_create_card_entry(mixer->card, "oss_mixer",
  1106. mixer->card->proc_root);
  1107. if (! entry)
  1108. return;
  1109. entry->content = SNDRV_INFO_CONTENT_TEXT;
  1110. entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
  1111. entry->c.text.read = snd_mixer_oss_proc_read;
  1112. entry->c.text.write = snd_mixer_oss_proc_write;
  1113. entry->private_data = mixer;
  1114. if (snd_info_register(entry) < 0) {
  1115. snd_info_free_entry(entry);
  1116. entry = NULL;
  1117. }
  1118. mixer->proc_entry = entry;
  1119. }
  1120. static void snd_mixer_oss_proc_done(struct snd_mixer_oss *mixer)
  1121. {
  1122. snd_info_free_entry(mixer->proc_entry);
  1123. mixer->proc_entry = NULL;
  1124. }
  1125. #else /* !CONFIG_PROC_FS */
  1126. #define snd_mixer_oss_proc_init(mix)
  1127. #define snd_mixer_oss_proc_done(mix)
  1128. #endif /* CONFIG_PROC_FS */
  1129. static void snd_mixer_oss_build(struct snd_mixer_oss *mixer)
  1130. {
  1131. static struct snd_mixer_oss_assign_table table[] = {
  1132. { SOUND_MIXER_VOLUME, "Master", 0 },
  1133. { SOUND_MIXER_VOLUME, "Front", 0 }, /* fallback */
  1134. { SOUND_MIXER_BASS, "Tone Control - Bass", 0 },
  1135. { SOUND_MIXER_TREBLE, "Tone Control - Treble", 0 },
  1136. { SOUND_MIXER_SYNTH, "Synth", 0 },
  1137. { SOUND_MIXER_SYNTH, "FM", 0 }, /* fallback */
  1138. { SOUND_MIXER_SYNTH, "Music", 0 }, /* fallback */
  1139. { SOUND_MIXER_PCM, "PCM", 0 },
  1140. { SOUND_MIXER_SPEAKER, "PC Speaker", 0 },
  1141. { SOUND_MIXER_LINE, "Line", 0 },
  1142. { SOUND_MIXER_MIC, "Mic", 0 },
  1143. { SOUND_MIXER_CD, "CD", 0 },
  1144. { SOUND_MIXER_IMIX, "Monitor Mix", 0 },
  1145. { SOUND_MIXER_ALTPCM, "PCM", 1 },
  1146. { SOUND_MIXER_ALTPCM, "Headphone", 0 }, /* fallback */
  1147. { SOUND_MIXER_ALTPCM, "Wave", 0 }, /* fallback */
  1148. { SOUND_MIXER_RECLEV, "-- nothing --", 0 },
  1149. { SOUND_MIXER_IGAIN, "Capture", 0 },
  1150. { SOUND_MIXER_OGAIN, "Playback", 0 },
  1151. { SOUND_MIXER_LINE1, "Aux", 0 },
  1152. { SOUND_MIXER_LINE2, "Aux", 1 },
  1153. { SOUND_MIXER_LINE3, "Aux", 2 },
  1154. { SOUND_MIXER_DIGITAL1, "Digital", 0 },
  1155. { SOUND_MIXER_DIGITAL1, "IEC958", 0 }, /* fallback */
  1156. { SOUND_MIXER_DIGITAL1, "IEC958 Optical", 0 }, /* fallback */
  1157. { SOUND_MIXER_DIGITAL1, "IEC958 Coaxial", 0 }, /* fallback */
  1158. { SOUND_MIXER_DIGITAL2, "Digital", 1 },
  1159. { SOUND_MIXER_DIGITAL3, "Digital", 2 },
  1160. { SOUND_MIXER_PHONEIN, "Phone", 0 },
  1161. { SOUND_MIXER_PHONEOUT, "Master Mono", 0 },
  1162. { SOUND_MIXER_PHONEOUT, "Speaker", 0 }, /*fallback*/
  1163. { SOUND_MIXER_PHONEOUT, "Mono", 0 }, /*fallback*/
  1164. { SOUND_MIXER_PHONEOUT, "Phone", 0 }, /* fallback */
  1165. { SOUND_MIXER_VIDEO, "Video", 0 },
  1166. { SOUND_MIXER_RADIO, "Radio", 0 },
  1167. { SOUND_MIXER_MONITOR, "Monitor", 0 }
  1168. };
  1169. unsigned int idx;
  1170. for (idx = 0; idx < ARRAY_SIZE(table); idx++)
  1171. snd_mixer_oss_build_input(mixer, &table[idx], 0, 0);
  1172. if (mixer->mask_recsrc) {
  1173. mixer->get_recsrc = snd_mixer_oss_get_recsrc2;
  1174. mixer->put_recsrc = snd_mixer_oss_put_recsrc2;
  1175. }
  1176. }
  1177. /*
  1178. *
  1179. */
  1180. static int snd_mixer_oss_free1(void *private)
  1181. {
  1182. struct snd_mixer_oss *mixer = private;
  1183. struct snd_card *card;
  1184. int idx;
  1185. snd_assert(mixer != NULL, return -ENXIO);
  1186. card = mixer->card;
  1187. snd_assert(mixer == card->mixer_oss, return -ENXIO);
  1188. card->mixer_oss = NULL;
  1189. for (idx = 0; idx < SNDRV_OSS_MAX_MIXERS; idx++) {
  1190. struct snd_mixer_oss_slot *chn = &mixer->slots[idx];
  1191. if (chn->private_free)
  1192. chn->private_free(chn);
  1193. }
  1194. kfree(mixer);
  1195. return 0;
  1196. }
  1197. static int snd_mixer_oss_notify_handler(struct snd_card *card, int cmd)
  1198. {
  1199. struct snd_mixer_oss *mixer;
  1200. if (cmd == SND_MIXER_OSS_NOTIFY_REGISTER) {
  1201. char name[128];
  1202. int idx, err;
  1203. mixer = kcalloc(2, sizeof(*mixer), GFP_KERNEL);
  1204. if (mixer == NULL)
  1205. return -ENOMEM;
  1206. mutex_init(&mixer->reg_mutex);
  1207. sprintf(name, "mixer%i%i", card->number, 0);
  1208. if ((err = snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER,
  1209. card, 0,
  1210. &snd_mixer_oss_f_ops, card,
  1211. name)) < 0) {
  1212. snd_printk(KERN_ERR "unable to register OSS mixer device %i:%i\n",
  1213. card->number, 0);
  1214. kfree(mixer);
  1215. return err;
  1216. }
  1217. mixer->oss_dev_alloc = 1;
  1218. mixer->card = card;
  1219. if (*card->mixername)
  1220. strlcpy(mixer->name, card->mixername, sizeof(mixer->name));
  1221. else
  1222. strlcpy(mixer->name, name, sizeof(mixer->name));
  1223. #ifdef SNDRV_OSS_INFO_DEV_MIXERS
  1224. snd_oss_info_register(SNDRV_OSS_INFO_DEV_MIXERS,
  1225. card->number,
  1226. mixer->name);
  1227. #endif
  1228. for (idx = 0; idx < SNDRV_OSS_MAX_MIXERS; idx++)
  1229. mixer->slots[idx].number = idx;
  1230. card->mixer_oss = mixer;
  1231. snd_mixer_oss_build(mixer);
  1232. snd_mixer_oss_proc_init(mixer);
  1233. } else {
  1234. mixer = card->mixer_oss;
  1235. if (mixer == NULL)
  1236. return 0;
  1237. if (mixer->oss_dev_alloc) {
  1238. #ifdef SNDRV_OSS_INFO_DEV_MIXERS
  1239. snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_MIXERS, mixer->card->number);
  1240. #endif
  1241. snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_MIXER, mixer->card, 0);
  1242. mixer->oss_dev_alloc = 0;
  1243. }
  1244. if (cmd == SND_MIXER_OSS_NOTIFY_DISCONNECT)
  1245. return 0;
  1246. snd_mixer_oss_proc_done(mixer);
  1247. return snd_mixer_oss_free1(mixer);
  1248. }
  1249. return 0;
  1250. }
  1251. static int __init alsa_mixer_oss_init(void)
  1252. {
  1253. int idx;
  1254. snd_mixer_oss_notify_callback = snd_mixer_oss_notify_handler;
  1255. for (idx = 0; idx < SNDRV_CARDS; idx++) {
  1256. if (snd_cards[idx])
  1257. snd_mixer_oss_notify_handler(snd_cards[idx], SND_MIXER_OSS_NOTIFY_REGISTER);
  1258. }
  1259. return 0;
  1260. }
  1261. static void __exit alsa_mixer_oss_exit(void)
  1262. {
  1263. int idx;
  1264. snd_mixer_oss_notify_callback = NULL;
  1265. for (idx = 0; idx < SNDRV_CARDS; idx++) {
  1266. if (snd_cards[idx])
  1267. snd_mixer_oss_notify_handler(snd_cards[idx], SND_MIXER_OSS_NOTIFY_FREE);
  1268. }
  1269. }
  1270. module_init(alsa_mixer_oss_init)
  1271. module_exit(alsa_mixer_oss_exit)
  1272. EXPORT_SYMBOL(snd_mixer_oss_ioctl_card);