Commit d767aba2 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: usb-audio: Pass snd_usb_audio object to quirk functions

A preliminary patch for the later big change.  Just a minor code
refactoring.
Tested-by: default avatarKeith Milner <kamilner@superlative.org>
Tested-by: default avatarDylan Robinson <dylan_robinson@motu.com>
Link: https://lore.kernel.org/r/20201123085347.19667-19-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent c7f90201
...@@ -658,9 +658,9 @@ static int set_sample_rate_v2v3(struct snd_usb_audio *chip, int iface, ...@@ -658,9 +658,9 @@ static int set_sample_rate_v2v3(struct snd_usb_audio *chip, int iface,
* interface is active. */ * interface is active. */
if (rate != prev_rate) { if (rate != prev_rate) {
usb_set_interface(dev, iface, 0); usb_set_interface(dev, iface, 0);
snd_usb_set_interface_quirk(dev); snd_usb_set_interface_quirk(chip);
usb_set_interface(dev, iface, fmt->altsetting); usb_set_interface(dev, iface, fmt->altsetting);
snd_usb_set_interface_quirk(dev); snd_usb_set_interface_quirk(chip);
} }
validation: validation:
......
...@@ -553,6 +553,7 @@ static int set_sync_endpoint(struct snd_usb_substream *subs, ...@@ -553,6 +553,7 @@ static int set_sync_endpoint(struct snd_usb_substream *subs,
{ {
struct usb_device *dev = subs->dev; struct usb_device *dev = subs->dev;
struct usb_host_interface *alts; struct usb_host_interface *alts;
struct snd_usb_audio *chip = subs->stream->chip;
int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK; int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK;
unsigned int ep; unsigned int ep;
int err; int err;
...@@ -569,7 +570,7 @@ static int set_sync_endpoint(struct snd_usb_substream *subs, ...@@ -569,7 +570,7 @@ static int set_sync_endpoint(struct snd_usb_substream *subs,
if (!alts) if (!alts)
return 0; return 0;
subs->sync_endpoint = snd_usb_get_endpoint(subs->stream->chip, ep); subs->sync_endpoint = snd_usb_get_endpoint(chip, ep);
if (!subs->sync_endpoint) { if (!subs->sync_endpoint) {
if (is_playback && if (is_playback &&
(fmt->ep_attr & USB_ENDPOINT_SYNCTYPE) == USB_ENDPOINT_SYNC_NONE) (fmt->ep_attr & USB_ENDPOINT_SYNCTYPE) == USB_ENDPOINT_SYNC_NONE)
...@@ -596,7 +597,7 @@ static int set_sync_endpoint(struct snd_usb_substream *subs, ...@@ -596,7 +597,7 @@ static int set_sync_endpoint(struct snd_usb_substream *subs,
dev_dbg(&dev->dev, "setting usb interface %d:%d\n", dev_dbg(&dev->dev, "setting usb interface %d:%d\n",
subs->sync_endpoint->iface, subs->sync_endpoint->iface,
subs->sync_endpoint->altsetting); subs->sync_endpoint->altsetting);
snd_usb_set_interface_quirk(dev); snd_usb_set_interface_quirk(chip);
} }
return 0; return 0;
...@@ -608,6 +609,7 @@ static int set_sync_endpoint(struct snd_usb_substream *subs, ...@@ -608,6 +609,7 @@ static int set_sync_endpoint(struct snd_usb_substream *subs,
static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
{ {
struct usb_device *dev = subs->dev; struct usb_device *dev = subs->dev;
struct snd_usb_audio *chip = subs->stream->chip;
struct usb_host_interface *alts; struct usb_host_interface *alts;
struct usb_interface *iface; struct usb_interface *iface;
struct snd_usb_endpoint *ep; struct snd_usb_endpoint *ep;
...@@ -625,7 +627,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) ...@@ -625,7 +627,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
/* shared EP with implicit fb */ /* shared EP with implicit fb */
if (fmt->implicit_fb && !subs->need_setup_fmt) { if (fmt->implicit_fb && !subs->need_setup_fmt) {
ep = snd_usb_get_endpoint(subs->stream->chip, fmt->endpoint); ep = snd_usb_get_endpoint(chip, fmt->endpoint);
if (ep && ep->use_count > 0) if (ep && ep->use_count > 0)
goto add_data_ep; goto add_data_ep;
} }
...@@ -648,7 +650,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) ...@@ -648,7 +650,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
/* set interface */ /* set interface */
if (iface->cur_altsetting != alts) { if (iface->cur_altsetting != alts) {
err = snd_usb_select_mode_quirk(subs, fmt); err = snd_usb_select_mode_quirk(chip, fmt);
if (err < 0) if (err < 0)
return -EIO; return -EIO;
...@@ -661,7 +663,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) ...@@ -661,7 +663,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
} }
dev_dbg(&dev->dev, "setting usb interface %d:%d\n", dev_dbg(&dev->dev, "setting usb interface %d:%d\n",
fmt->iface, fmt->altsetting); fmt->iface, fmt->altsetting);
snd_usb_set_interface_quirk(dev); snd_usb_set_interface_quirk(chip);
} }
subs->need_setup_ep = true; subs->need_setup_ep = true;
...@@ -669,8 +671,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) ...@@ -669,8 +671,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
add_data_ep: add_data_ep:
subs->interface = fmt->iface; subs->interface = fmt->iface;
subs->altset_idx = fmt->altset_idx; subs->altset_idx = fmt->altset_idx;
subs->data_endpoint = snd_usb_get_endpoint(subs->stream->chip, subs->data_endpoint = snd_usb_get_endpoint(chip, fmt->endpoint);
fmt->endpoint);
if (!subs->data_endpoint) if (!subs->data_endpoint)
return -EINVAL; return -EINVAL;
subs->data_endpoint->iface = fmt->iface; subs->data_endpoint->iface = fmt->iface;
...@@ -681,7 +682,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt) ...@@ -681,7 +682,7 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
return err; return err;
if (subs->need_setup_ep) { if (subs->need_setup_ep) {
err = snd_usb_init_pitch(subs->stream->chip, fmt->iface, alts, fmt); err = snd_usb_init_pitch(chip, fmt->iface, alts, fmt);
if (err < 0) if (err < 0)
return err; return err;
} }
......
...@@ -1553,13 +1553,13 @@ static bool is_itf_usb_dsd_dac(unsigned int id) ...@@ -1553,13 +1553,13 @@ static bool is_itf_usb_dsd_dac(unsigned int id)
return false; return false;
} }
int snd_usb_select_mode_quirk(struct snd_usb_substream *subs, int snd_usb_select_mode_quirk(struct snd_usb_audio *chip,
struct audioformat *fmt) struct audioformat *fmt)
{ {
struct usb_device *dev = subs->dev; struct usb_device *dev = chip->dev;
int err; int err;
if (is_itf_usb_dsd_dac(subs->stream->chip->usb_id)) { if (is_itf_usb_dsd_dac(chip->usb_id)) {
/* First switch to alt set 0, otherwise the mode switch cmd /* First switch to alt set 0, otherwise the mode switch cmd
* will not be accepted by the DAC * will not be accepted by the DAC
*/ */
...@@ -1622,10 +1622,8 @@ void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep) ...@@ -1622,10 +1622,8 @@ void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep)
ep->tenor_fb_quirk = 1; ep->tenor_fb_quirk = 1;
} }
void snd_usb_set_interface_quirk(struct usb_device *dev) void snd_usb_set_interface_quirk(struct snd_usb_audio *chip)
{ {
struct snd_usb_audio *chip = dev_get_drvdata(&dev->dev);
if (!chip) if (!chip)
return; return;
/* /*
......
...@@ -35,12 +35,12 @@ int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, ...@@ -35,12 +35,12 @@ int snd_usb_is_big_endian_format(struct snd_usb_audio *chip,
void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep); void snd_usb_endpoint_start_quirk(struct snd_usb_endpoint *ep);
void snd_usb_set_interface_quirk(struct usb_device *dev); void snd_usb_set_interface_quirk(struct snd_usb_audio *chip);
void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe, void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
__u8 request, __u8 requesttype, __u16 value, __u8 request, __u8 requesttype, __u16 value,
__u16 index, void *data, __u16 size); __u16 index, void *data, __u16 size);
int snd_usb_select_mode_quirk(struct snd_usb_substream *subs, int snd_usb_select_mode_quirk(struct snd_usb_audio *chip,
struct audioformat *fmt); struct audioformat *fmt);
u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip, u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment