1818#include <linux/init.h>
1919#include <linux/interrupt.h>
2020#include <linux/module.h>
21+ #include <linux/mutex.h>
2122#include <linux/platform_device.h>
2223#include <linux/io.h>
2324
@@ -76,8 +77,10 @@ struct snd_at73c213 {
7677 u8 spi_rbuffer [2 ];
7778 /* Image of the SPI registers in AT73C213. */
7879 u8 reg_image [18 ];
79- /* Protect registers against concurrent access. */
80+ /* Protect SSC registers against concurrent access. */
8081 spinlock_t lock ;
82+ /* Protect mixer registers against concurrent access. */
83+ struct mutex mixer_lock ;
8184};
8285
8386#define get_chip (card ) ((struct snd_at73c213 *)card->private_data)
@@ -398,7 +401,7 @@ static int snd_at73c213_mono_get(struct snd_kcontrol *kcontrol,
398401 int mask = (kcontrol -> private_value >> 16 ) & 0xff ;
399402 int invert = (kcontrol -> private_value >> 24 ) & 0xff ;
400403
401- spin_lock_irq (& chip -> lock );
404+ mutex_lock (& chip -> mixer_lock );
402405
403406 ucontrol -> value .integer .value [0 ] =
404407 (chip -> reg_image [reg ] >> shift ) & mask ;
@@ -407,7 +410,7 @@ static int snd_at73c213_mono_get(struct snd_kcontrol *kcontrol,
407410 ucontrol -> value .integer .value [0 ] =
408411 mask - ucontrol -> value .integer .value [0 ];
409412
410- spin_unlock_irq (& chip -> lock );
413+ mutex_unlock (& chip -> mixer_lock );
411414
412415 return 0 ;
413416}
@@ -428,13 +431,13 @@ static int snd_at73c213_mono_put(struct snd_kcontrol *kcontrol,
428431 val = mask - val ;
429432 val <<= shift ;
430433
431- spin_lock_irq (& chip -> lock );
434+ mutex_lock (& chip -> mixer_lock );
432435
433436 val = (chip -> reg_image [reg ] & ~(mask << shift )) | val ;
434437 change = val != chip -> reg_image [reg ];
435438 retval = snd_at73c213_write_reg (chip , reg , val );
436439
437- spin_unlock_irq (& chip -> lock );
440+ mutex_unlock (& chip -> mixer_lock );
438441
439442 if (retval )
440443 return retval ;
@@ -470,7 +473,7 @@ static int snd_at73c213_stereo_get(struct snd_kcontrol *kcontrol,
470473 int mask = (kcontrol -> private_value >> 24 ) & 0xff ;
471474 int invert = (kcontrol -> private_value >> 22 ) & 1 ;
472475
473- spin_lock_irq (& chip -> lock );
476+ mutex_lock (& chip -> mixer_lock );
474477
475478 ucontrol -> value .integer .value [0 ] =
476479 (chip -> reg_image [left_reg ] >> shift_left ) & mask ;
@@ -484,7 +487,7 @@ static int snd_at73c213_stereo_get(struct snd_kcontrol *kcontrol,
484487 mask - ucontrol -> value .integer .value [1 ];
485488 }
486489
487- spin_unlock_irq (& chip -> lock );
490+ mutex_unlock (& chip -> mixer_lock );
488491
489492 return 0 ;
490493}
@@ -511,24 +514,24 @@ static int snd_at73c213_stereo_put(struct snd_kcontrol *kcontrol,
511514 val1 <<= shift_left ;
512515 val2 <<= shift_right ;
513516
514- spin_lock_irq (& chip -> lock );
517+ mutex_lock (& chip -> mixer_lock );
515518
516519 val1 = (chip -> reg_image [left_reg ] & ~(mask << shift_left )) | val1 ;
517520 val2 = (chip -> reg_image [right_reg ] & ~(mask << shift_right )) | val2 ;
518521 change = val1 != chip -> reg_image [left_reg ]
519522 || val2 != chip -> reg_image [right_reg ];
520523 retval = snd_at73c213_write_reg (chip , left_reg , val1 );
521524 if (retval ) {
522- spin_unlock_irq (& chip -> lock );
525+ mutex_unlock (& chip -> mixer_lock );
523526 goto out ;
524527 }
525528 retval = snd_at73c213_write_reg (chip , right_reg , val2 );
526529 if (retval ) {
527- spin_unlock_irq (& chip -> lock );
530+ mutex_unlock (& chip -> mixer_lock );
528531 goto out ;
529532 }
530533
531- spin_unlock_irq (& chip -> lock );
534+ mutex_unlock (& chip -> mixer_lock );
532535
533536 return change ;
534537
@@ -546,7 +549,7 @@ static int snd_at73c213_mono_switch_get(struct snd_kcontrol *kcontrol,
546549 int shift = (kcontrol -> private_value >> 8 ) & 0xff ;
547550 int invert = (kcontrol -> private_value >> 24 ) & 0xff ;
548551
549- spin_lock_irq (& chip -> lock );
552+ mutex_lock (& chip -> mixer_lock );
550553
551554 ucontrol -> value .integer .value [0 ] =
552555 (chip -> reg_image [reg ] >> shift ) & 0x01 ;
@@ -555,7 +558,7 @@ static int snd_at73c213_mono_switch_get(struct snd_kcontrol *kcontrol,
555558 ucontrol -> value .integer .value [0 ] =
556559 0x01 - ucontrol -> value .integer .value [0 ];
557560
558- spin_unlock_irq (& chip -> lock );
561+ mutex_unlock (& chip -> mixer_lock );
559562
560563 return 0 ;
561564}
@@ -580,14 +583,14 @@ static int snd_at73c213_mono_switch_put(struct snd_kcontrol *kcontrol,
580583 val = mask - val ;
581584 val <<= shift ;
582585
583- spin_lock_irq (& chip -> lock );
586+ mutex_lock (& chip -> mixer_lock );
584587
585588 val |= (chip -> reg_image [reg ] & ~(mask << shift ));
586589 change = val != chip -> reg_image [reg ];
587590
588591 retval = snd_at73c213_write_reg (chip , reg , val );
589592
590- spin_unlock_irq (& chip -> lock );
593+ mutex_unlock (& chip -> mixer_lock );
591594
592595 if (retval )
593596 return retval ;
@@ -884,6 +887,7 @@ static int __devinit snd_at73c213_dev_init(struct snd_card *card,
884887 return irq ;
885888
886889 spin_lock_init (& chip -> lock );
890+ mutex_init (& chip -> mixer_lock );
887891 chip -> card = card ;
888892 chip -> irq = -1 ;
889893
0 commit comments