sched: Remove double_rq_lock() from __migrate_task()
[linux/fpc-iii.git] / drivers / media / usb / stk1160 / stk1160-ac97.c
blob2dd308f9541f469b719adf7d53f01901f4525b3e
1 /*
2 * STK1160 driver
4 * Copyright (C) 2012 Ezequiel Garcia
5 * <elezegarcia--a.t--gmail.com>
7 * Based on Easycap driver by R.M. Thomas
8 * Copyright (C) 2010 R.M. Thomas
9 * <rmthomas--a.t--sciolus.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
23 #include <linux/module.h>
24 #include <sound/core.h>
25 #include <sound/initval.h>
26 #include <sound/ac97_codec.h>
28 #include "stk1160.h"
29 #include "stk1160-reg.h"
31 static struct snd_ac97 *stk1160_ac97;
33 static void stk1160_write_ac97(struct snd_ac97 *ac97, u16 reg, u16 value)
35 struct stk1160 *dev = ac97->private_data;
37 /* Set codec register address */
38 stk1160_write_reg(dev, STK1160_AC97_ADDR, reg);
40 /* Set codec command */
41 stk1160_write_reg(dev, STK1160_AC97_CMD, value & 0xff);
42 stk1160_write_reg(dev, STK1160_AC97_CMD + 1, (value & 0xff00) >> 8);
45 * Set command write bit to initiate write operation.
46 * The bit will be cleared when transfer is done.
48 stk1160_write_reg(dev, STK1160_AC97CTL_0, 0x8c);
51 static u16 stk1160_read_ac97(struct snd_ac97 *ac97, u16 reg)
53 struct stk1160 *dev = ac97->private_data;
54 u8 vall = 0;
55 u8 valh = 0;
57 /* Set codec register address */
58 stk1160_write_reg(dev, STK1160_AC97_ADDR, reg);
61 * Set command read bit to initiate read operation.
62 * The bit will be cleared when transfer is done.
64 stk1160_write_reg(dev, STK1160_AC97CTL_0, 0x8b);
66 /* Retrieve register value */
67 stk1160_read_reg(dev, STK1160_AC97_CMD, &vall);
68 stk1160_read_reg(dev, STK1160_AC97_CMD + 1, &valh);
70 return (valh << 8) | vall;
73 static void stk1160_reset_ac97(struct snd_ac97 *ac97)
75 struct stk1160 *dev = ac97->private_data;
76 /* Two-step reset AC97 interface and hardware codec */
77 stk1160_write_reg(dev, STK1160_AC97CTL_0, 0x94);
78 stk1160_write_reg(dev, STK1160_AC97CTL_0, 0x88);
80 /* Set 16-bit audio data and choose L&R channel*/
81 stk1160_write_reg(dev, STK1160_AC97CTL_1 + 2, 0x01);
84 static struct snd_ac97_bus_ops stk1160_ac97_ops = {
85 .read = stk1160_read_ac97,
86 .write = stk1160_write_ac97,
87 .reset = stk1160_reset_ac97,
90 int stk1160_ac97_register(struct stk1160 *dev)
92 struct snd_card *card = NULL;
93 struct snd_ac97_bus *ac97_bus;
94 struct snd_ac97_template ac97_template;
95 int rc;
98 * Just want a card to access ac96 controls,
99 * the actual capture interface will be handled by snd-usb-audio
101 rc = snd_card_new(dev->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
102 THIS_MODULE, 0, &card);
103 if (rc < 0)
104 return rc;
106 /* TODO: I'm not sure where should I get these names :-( */
107 snprintf(card->shortname, sizeof(card->shortname),
108 "stk1160-mixer");
109 snprintf(card->longname, sizeof(card->longname),
110 "stk1160 ac97 codec mixer control");
111 strlcpy(card->driver, dev->dev->driver->name, sizeof(card->driver));
113 rc = snd_ac97_bus(card, 0, &stk1160_ac97_ops, NULL, &ac97_bus);
114 if (rc)
115 goto err;
117 /* We must set private_data before calling snd_ac97_mixer */
118 memset(&ac97_template, 0, sizeof(ac97_template));
119 ac97_template.private_data = dev;
120 ac97_template.scaps = AC97_SCAP_SKIP_MODEM;
121 rc = snd_ac97_mixer(ac97_bus, &ac97_template, &stk1160_ac97);
122 if (rc)
123 goto err;
125 dev->snd_card = card;
126 rc = snd_card_register(card);
127 if (rc)
128 goto err;
130 return 0;
132 err:
133 dev->snd_card = NULL;
134 snd_card_free(card);
135 return rc;
138 int stk1160_ac97_unregister(struct stk1160 *dev)
140 struct snd_card *card = dev->snd_card;
143 * We need to check usb_device,
144 * because ac97 release attempts to communicate with codec
146 if (card && dev->udev)
147 snd_card_free(card);
149 return 0;