Skip to content

Commit 9229bc1

Browse files
Ondrej Zarytiwai
authored andcommitted
ALSA: cs8427: separate HW initialization
Separate HW initialization from device creation. This is needed for suspend/resume support. Signed-off-by: Ondrej Zary <linux@rainbow-software.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 415d555 commit 9229bc1

2 files changed

Lines changed: 39 additions & 19 deletions

File tree

‎include/sound/cs8427.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188

189189
struct snd_pcm_substream;
190190

191+
int snd_cs8427_init(struct snd_i2c_bus *bus, struct snd_i2c_device *device);
191192
int snd_cs8427_create(struct snd_i2c_bus *bus, unsigned char addr,
192193
unsigned int reset_timeout, struct snd_i2c_device **r_cs8427);
193194
int snd_cs8427_reg_write(struct snd_i2c_device *device, unsigned char reg,

‎sound/i2c/cs8427.c‎

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,8 @@ static void snd_cs8427_free(struct snd_i2c_device *device)
150150
kfree(device->private_data);
151151
}
152152

153-
int snd_cs8427_create(struct snd_i2c_bus *bus,
154-
unsigned char addr,
155-
unsigned int reset_timeout,
156-
struct snd_i2c_device **r_cs8427)
153+
int snd_cs8427_init(struct snd_i2c_bus *bus,
154+
struct snd_i2c_device *device)
157155
{
158156
static unsigned char initvals1[] = {
159157
CS8427_REG_CONTROL1 | CS8427_REG_AUTOINC,
@@ -200,22 +198,10 @@ int snd_cs8427_create(struct snd_i2c_bus *bus,
200198
Inhibit E->F transfers. */
201199
CS8427_UD | CS8427_EFTUI | CS8427_DETUI,
202200
};
201+
struct cs8427 *chip = device->private_data;
203202
int err;
204-
struct cs8427 *chip;
205-
struct snd_i2c_device *device;
206203
unsigned char buf[24];
207204

208-
if ((err = snd_i2c_device_create(bus, "CS8427",
209-
CS8427_ADDR | (addr & 7),
210-
&device)) < 0)
211-
return err;
212-
chip = device->private_data = kzalloc(sizeof(*chip), GFP_KERNEL);
213-
if (chip == NULL) {
214-
snd_i2c_device_free(device);
215-
return -ENOMEM;
216-
}
217-
device->private_free = snd_cs8427_free;
218-
219205
snd_i2c_lock(bus);
220206
err = snd_cs8427_reg_read(device, CS8427_REG_ID_AND_VER);
221207
if (err != CS8427_VER8427A) {
@@ -264,10 +250,44 @@ int snd_cs8427_create(struct snd_i2c_bus *bus,
264250
snd_i2c_unlock(bus);
265251

266252
/* turn on run bit and rock'n'roll */
253+
snd_cs8427_reset(device);
254+
255+
return 0;
256+
257+
__fail:
258+
snd_i2c_unlock(bus);
259+
260+
return err;
261+
}
262+
EXPORT_SYMBOL(snd_cs8427_init);
263+
264+
int snd_cs8427_create(struct snd_i2c_bus *bus,
265+
unsigned char addr,
266+
unsigned int reset_timeout,
267+
struct snd_i2c_device **r_cs8427)
268+
{
269+
int err;
270+
struct cs8427 *chip;
271+
struct snd_i2c_device *device;
272+
273+
err = snd_i2c_device_create(bus, "CS8427", CS8427_ADDR | (addr & 7),
274+
&device);
275+
if (err < 0)
276+
return err;
277+
chip = device->private_data = kzalloc(sizeof(*chip), GFP_KERNEL);
278+
if (chip == NULL) {
279+
snd_i2c_device_free(device);
280+
return -ENOMEM;
281+
}
282+
device->private_free = snd_cs8427_free;
283+
267284
if (reset_timeout < 1)
268285
reset_timeout = 1;
269286
chip->reset_timeout = reset_timeout;
270-
snd_cs8427_reset(device);
287+
288+
err = snd_cs8427_init(bus, device);
289+
if (err)
290+
goto __fail;
271291

272292
#if 0 // it's nice for read tests
273293
{
@@ -286,7 +306,6 @@ int snd_cs8427_create(struct snd_i2c_bus *bus,
286306
return 0;
287307

288308
__fail:
289-
snd_i2c_unlock(bus);
290309
snd_i2c_device_free(device);
291310
return err < 0 ? err : -EIO;
292311
}

0 commit comments

Comments
 (0)