Skip to content

Commit 8d085d3

Browse files
committed
Merge branch 'topic/hda-cleanup' into for-next
2 parents 88cacc5 + 781c7b9 commit 8d085d3

File tree

10 files changed

+493
-568
lines changed

10 files changed

+493
-568
lines changed

sound/pci/hda/hda_codec.c

Lines changed: 21 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -762,10 +762,7 @@ int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex)
762762
return 0;
763763

764764
trace_hda_unsol_event(bus, res, res_ex);
765-
unsol = bus->unsol;
766-
if (!unsol)
767-
return 0;
768-
765+
unsol = &bus->unsol;
769766
wp = (unsol->wp + 1) % HDA_UNSOL_QUEUE_SIZE;
770767
unsol->wp = wp;
771768

@@ -784,9 +781,8 @@ EXPORT_SYMBOL_GPL(snd_hda_queue_unsol_event);
784781
*/
785782
static void process_unsol_events(struct work_struct *work)
786783
{
787-
struct hda_bus_unsolicited *unsol =
788-
container_of(work, struct hda_bus_unsolicited, work);
789-
struct hda_bus *bus = unsol->bus;
784+
struct hda_bus *bus = container_of(work, struct hda_bus, unsol.work);
785+
struct hda_bus_unsolicited *unsol = &bus->unsol;
790786
struct hda_codec *codec;
791787
unsigned int rp, caddr, res;
792788

@@ -804,27 +800,6 @@ static void process_unsol_events(struct work_struct *work)
804800
}
805801
}
806802

807-
/*
808-
* initialize unsolicited queue
809-
*/
810-
static int init_unsol_queue(struct hda_bus *bus)
811-
{
812-
struct hda_bus_unsolicited *unsol;
813-
814-
if (bus->unsol) /* already initialized */
815-
return 0;
816-
817-
unsol = kzalloc(sizeof(*unsol), GFP_KERNEL);
818-
if (!unsol) {
819-
dev_err(bus->card->dev, "can't allocate unsolicited queue\n");
820-
return -ENOMEM;
821-
}
822-
INIT_WORK(&unsol->work, process_unsol_events);
823-
unsol->bus = bus;
824-
bus->unsol = unsol;
825-
return 0;
826-
}
827-
828803
/*
829804
* destructor
830805
*/
@@ -836,7 +811,6 @@ static void snd_hda_bus_free(struct hda_bus *bus)
836811
WARN_ON(!list_empty(&bus->codec_list));
837812
if (bus->workq)
838813
flush_workqueue(bus->workq);
839-
kfree(bus->unsol);
840814
if (bus->ops.private_free)
841815
bus->ops.private_free(bus);
842816
if (bus->workq)
@@ -861,14 +835,12 @@ static int snd_hda_bus_dev_disconnect(struct snd_device *device)
861835
/**
862836
* snd_hda_bus_new - create a HDA bus
863837
* @card: the card entry
864-
* @temp: the template for hda_bus information
865838
* @busp: the pointer to store the created bus instance
866839
*
867840
* Returns 0 if successful, or a negative error code.
868841
*/
869842
int snd_hda_bus_new(struct snd_card *card,
870-
const struct hda_bus_template *temp,
871-
struct hda_bus **busp)
843+
struct hda_bus **busp)
872844
{
873845
struct hda_bus *bus;
874846
int err;
@@ -877,11 +849,6 @@ int snd_hda_bus_new(struct snd_card *card,
877849
.dev_free = snd_hda_bus_dev_free,
878850
};
879851

880-
if (snd_BUG_ON(!temp))
881-
return -EINVAL;
882-
if (snd_BUG_ON(!temp->ops.command || !temp->ops.get_response))
883-
return -EINVAL;
884-
885852
if (busp)
886853
*busp = NULL;
887854

@@ -892,15 +859,10 @@ int snd_hda_bus_new(struct snd_card *card,
892859
}
893860

894861
bus->card = card;
895-
bus->private_data = temp->private_data;
896-
bus->pci = temp->pci;
897-
bus->modelname = temp->modelname;
898-
bus->power_save = temp->power_save;
899-
bus->ops = temp->ops;
900-
901862
mutex_init(&bus->cmd_mutex);
902863
mutex_init(&bus->prepare_mutex);
903864
INIT_LIST_HEAD(&bus->codec_list);
865+
INIT_WORK(&bus->unsol.work, process_unsol_events);
904866

905867
snprintf(bus->workq_name, sizeof(bus->workq_name),
906868
"hd-audio%d", card->number);
@@ -1702,12 +1664,6 @@ int snd_hda_codec_configure(struct hda_codec *codec)
17021664
return err;
17031665
}
17041666

1705-
if (codec->patch_ops.unsol_event) {
1706-
err = init_unsol_queue(codec->bus);
1707-
if (err < 0)
1708-
return err;
1709-
}
1710-
17111667
/* audio codec should override the mixer name */
17121668
if (codec->afg || !*codec->bus->card->mixername)
17131669
snprintf(codec->bus->card->mixername,
@@ -2192,11 +2148,10 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_amp_read);
21922148

21932149
static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
21942150
int direction, int idx, int mask, int val,
2195-
bool init_only)
2151+
bool init_only, bool cache_only)
21962152
{
21972153
struct hda_amp_info *info;
21982154
unsigned int caps;
2199-
unsigned int cache_only;
22002155

22012156
if (snd_BUG_ON(mask & ~0xff))
22022157
mask &= 0xff;
@@ -2214,7 +2169,7 @@ static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
22142169
return 0;
22152170
}
22162171
info->vol[ch] = val;
2217-
cache_only = info->head.dirty = codec->cached_write;
2172+
info->head.dirty |= cache_only;
22182173
caps = info->amp_caps;
22192174
mutex_unlock(&codec->hash_mutex);
22202175
if (!cache_only)
@@ -2238,7 +2193,8 @@ static int codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
22382193
int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
22392194
int direction, int idx, int mask, int val)
22402195
{
2241-
return codec_amp_update(codec, nid, ch, direction, idx, mask, val, false);
2196+
return codec_amp_update(codec, nid, ch, direction, idx, mask, val,
2197+
false, codec->cached_write);
22422198
}
22432199
EXPORT_SYMBOL_GPL(snd_hda_codec_amp_update);
22442200

@@ -2285,7 +2241,8 @@ EXPORT_SYMBOL_GPL(snd_hda_codec_amp_stereo);
22852241
int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
22862242
int dir, int idx, int mask, int val)
22872243
{
2288-
return codec_amp_update(codec, nid, ch, dir, idx, mask, val, true);
2244+
return codec_amp_update(codec, nid, ch, dir, idx, mask, val, true,
2245+
codec->cached_write);
22892246
}
22902247
EXPORT_SYMBOL_GPL(snd_hda_codec_amp_init);
22912248

@@ -2427,8 +2384,8 @@ update_amp_value(struct hda_codec *codec, hda_nid_t nid,
24272384
maxval = get_amp_max_value(codec, nid, dir, 0);
24282385
if (val > maxval)
24292386
val = maxval;
2430-
return snd_hda_codec_amp_update(codec, nid, ch, dir, idx,
2431-
HDA_AMP_VOLMASK, val);
2387+
return codec_amp_update(codec, nid, ch, dir, idx, HDA_AMP_VOLMASK, val,
2388+
false, !hda_codec_is_power_on(codec));
24322389
}
24332390

24342391
/**
@@ -2478,14 +2435,12 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
24782435
long *valp = ucontrol->value.integer.value;
24792436
int change = 0;
24802437

2481-
snd_hda_power_up(codec);
24822438
if (chs & 1) {
24832439
change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp);
24842440
valp++;
24852441
}
24862442
if (chs & 2)
24872443
change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp);
2488-
snd_hda_power_down(codec);
24892444
return change;
24902445
}
24912446
EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_volume_put);
@@ -3153,19 +3108,19 @@ int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
31533108
long *valp = ucontrol->value.integer.value;
31543109
int change = 0;
31553110

3156-
snd_hda_power_up(codec);
31573111
if (chs & 1) {
3158-
change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx,
3159-
HDA_AMP_MUTE,
3160-
*valp ? 0 : HDA_AMP_MUTE);
3112+
change = codec_amp_update(codec, nid, 0, dir, idx,
3113+
HDA_AMP_MUTE,
3114+
*valp ? 0 : HDA_AMP_MUTE, false,
3115+
!hda_codec_is_power_on(codec));
31613116
valp++;
31623117
}
31633118
if (chs & 2)
3164-
change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx,
3165-
HDA_AMP_MUTE,
3166-
*valp ? 0 : HDA_AMP_MUTE);
3119+
change |= codec_amp_update(codec, nid, 1, dir, idx,
3120+
HDA_AMP_MUTE,
3121+
*valp ? 0 : HDA_AMP_MUTE, false,
3122+
!hda_codec_is_power_on(codec));
31673123
hda_call_check_power_status(codec, nid);
3168-
snd_hda_power_down(codec);
31693124
return change;
31703125
}
31713126
EXPORT_SYMBOL_GPL(snd_hda_mixer_amp_switch_put);

sound/pci/hda/hda_codec.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ struct hda_beep;
6666
struct hda_codec;
6767
struct hda_pcm;
6868
struct hda_pcm_stream;
69-
struct hda_bus_unsolicited;
7069

7170
/* NID type */
7271
typedef u16 hda_nid_t;
@@ -101,13 +100,14 @@ struct hda_bus_ops {
101100
#endif
102101
};
103102

104-
/* template to pass to the bus constructor */
105-
struct hda_bus_template {
106-
void *private_data;
107-
struct pci_dev *pci;
108-
const char *modelname;
109-
int *power_save;
110-
struct hda_bus_ops ops;
103+
/* unsolicited event handler */
104+
#define HDA_UNSOL_QUEUE_SIZE 64
105+
struct hda_bus_unsolicited {
106+
/* ring buffer */
107+
u32 queue[HDA_UNSOL_QUEUE_SIZE * 2];
108+
unsigned int rp, wp;
109+
/* workqueue */
110+
struct work_struct work;
111111
};
112112

113113
/*
@@ -119,7 +119,6 @@ struct hda_bus_template {
119119
struct hda_bus {
120120
struct snd_card *card;
121121

122-
/* copied from template */
123122
void *private_data;
124123
struct pci_dev *pci;
125124
const char *modelname;
@@ -136,7 +135,7 @@ struct hda_bus {
136135
struct mutex prepare_mutex;
137136

138137
/* unsolicited event queue */
139-
struct hda_bus_unsolicited *unsol;
138+
struct hda_bus_unsolicited unsol;
140139
char workq_name[16];
141140
struct workqueue_struct *workq; /* common workqueue for codecs */
142141

@@ -420,8 +419,7 @@ enum {
420419
/*
421420
* constructors
422421
*/
423-
int snd_hda_bus_new(struct snd_card *card, const struct hda_bus_template *temp,
424-
struct hda_bus **busp);
422+
int snd_hda_bus_new(struct snd_card *card, struct hda_bus **busp);
425423
int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
426424
struct hda_codec **codecp);
427425
int snd_hda_codec_configure(struct hda_codec *codec);

0 commit comments

Comments
 (0)