Commit 7158b57a authored by Ruslan Bilovol's avatar Ruslan Bilovol Committed by Felipe Balbi

usb: gadget: f_uac2: remove platform driver/device creation

Simplify f_uac2 by removing platform driver/device
creation; use composite's usb_gadget device as
parent for sound card and for debug prints.
This removes extra layer of code without any functional
change.
Signed-off-by: default avatarRuslan Bilovol <ruslan.bilovol@gmail.com>
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent 1fc4926d
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include <linux/usb/audio.h> #include <linux/usb/audio.h>
#include <linux/usb/audio-v2.h> #include <linux/usb/audio-v2.h>
#include <linux/platform_device.h>
#include <linux/module.h> #include <linux/module.h>
#include <sound/core.h> #include <sound/core.h>
...@@ -51,8 +50,6 @@ ...@@ -51,8 +50,6 @@
#define UNFLW_CTRL 8 #define UNFLW_CTRL 8
#define OVFLW_CTRL 10 #define OVFLW_CTRL 10
static const char *uac2_name = "snd_uac2";
struct uac2_req { struct uac2_req {
struct uac2_rtd_params *pp; /* parent param */ struct uac2_rtd_params *pp; /* parent param */
struct usb_request *req; struct usb_request *req;
...@@ -81,9 +78,6 @@ struct uac2_rtd_params { ...@@ -81,9 +78,6 @@ struct uac2_rtd_params {
}; };
struct snd_uac2_chip { struct snd_uac2_chip {
struct platform_device pdev;
struct platform_driver pdrv;
struct uac2_rtd_params p_prm; struct uac2_rtd_params p_prm;
struct uac2_rtd_params c_prm; struct uac2_rtd_params c_prm;
...@@ -122,6 +116,7 @@ struct audio_dev { ...@@ -122,6 +116,7 @@ struct audio_dev {
struct usb_ep *in_ep, *out_ep; struct usb_ep *in_ep, *out_ep;
struct usb_function func; struct usb_function func;
struct usb_gadget *gadget;
/* The ALSA Sound Card it represents on the USB-Client side */ /* The ALSA Sound Card it represents on the USB-Client side */
struct snd_uac2_chip uac2; struct snd_uac2_chip uac2;
...@@ -139,12 +134,6 @@ struct audio_dev *uac2_to_agdev(struct snd_uac2_chip *u) ...@@ -139,12 +134,6 @@ struct audio_dev *uac2_to_agdev(struct snd_uac2_chip *u)
return container_of(u, struct audio_dev, uac2); return container_of(u, struct audio_dev, uac2);
} }
static inline
struct snd_uac2_chip *pdev_to_uac2(struct platform_device *p)
{
return container_of(p, struct snd_uac2_chip, pdev);
}
static inline static inline
struct f_uac2_opts *agdev_to_uac2_opts(struct audio_dev *agdev) struct f_uac2_opts *agdev_to_uac2_opts(struct audio_dev *agdev)
{ {
...@@ -254,7 +243,7 @@ agdev_iso_complete(struct usb_ep *ep, struct usb_request *req) ...@@ -254,7 +243,7 @@ agdev_iso_complete(struct usb_ep *ep, struct usb_request *req)
exit: exit:
if (usb_ep_queue(ep, req, GFP_ATOMIC)) if (usb_ep_queue(ep, req, GFP_ATOMIC))
dev_err(&uac2->pdev.dev, "%d Error!\n", __LINE__); dev_err(uac2->card->dev, "%d Error!\n", __LINE__);
if (update_alsa) if (update_alsa)
snd_pcm_period_elapsed(substream); snd_pcm_period_elapsed(substream);
...@@ -440,23 +429,22 @@ static struct snd_pcm_ops uac2_pcm_ops = { ...@@ -440,23 +429,22 @@ static struct snd_pcm_ops uac2_pcm_ops = {
.prepare = uac2_pcm_null, .prepare = uac2_pcm_null,
}; };
static int snd_uac2_probe(struct platform_device *pdev) static int snd_uac2_probe(struct audio_dev *audio_dev)
{ {
struct snd_uac2_chip *uac2 = pdev_to_uac2(pdev); struct snd_uac2_chip *uac2 = &audio_dev->uac2;
struct snd_card *card; struct snd_card *card;
struct snd_pcm *pcm; struct snd_pcm *pcm;
struct audio_dev *audio_dev;
struct f_uac2_opts *opts; struct f_uac2_opts *opts;
int err; int err;
int p_chmask, c_chmask; int p_chmask, c_chmask;
audio_dev = uac2_to_agdev(uac2);
opts = container_of(audio_dev->func.fi, struct f_uac2_opts, func_inst); opts = container_of(audio_dev->func.fi, struct f_uac2_opts, func_inst);
p_chmask = opts->p_chmask; p_chmask = opts->p_chmask;
c_chmask = opts->c_chmask; c_chmask = opts->c_chmask;
/* Choose any slot, with no id */ /* Choose any slot, with no id */
err = snd_card_new(&pdev->dev, -1, NULL, THIS_MODULE, 0, &card); err = snd_card_new(&audio_dev->gadget->dev,
-1, NULL, THIS_MODULE, 0, &card);
if (err < 0) if (err < 0)
return err; return err;
...@@ -481,16 +469,15 @@ static int snd_uac2_probe(struct platform_device *pdev) ...@@ -481,16 +469,15 @@ static int snd_uac2_probe(struct platform_device *pdev)
strcpy(card->driver, "UAC2_Gadget"); strcpy(card->driver, "UAC2_Gadget");
strcpy(card->shortname, "UAC2_Gadget"); strcpy(card->shortname, "UAC2_Gadget");
sprintf(card->longname, "UAC2_Gadget %i", pdev->id); sprintf(card->longname, "UAC2_Gadget %i", card->dev->id);
snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS, snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
snd_dma_continuous_data(GFP_KERNEL), 0, BUFF_SIZE_MAX); snd_dma_continuous_data(GFP_KERNEL), 0, BUFF_SIZE_MAX);
err = snd_card_register(card); err = snd_card_register(card);
if (!err) {
platform_set_drvdata(pdev, card); if (!err)
return 0; return 0;
}
snd_fail: snd_fail:
snd_card_free(card); snd_card_free(card);
...@@ -501,9 +488,9 @@ static int snd_uac2_probe(struct platform_device *pdev) ...@@ -501,9 +488,9 @@ static int snd_uac2_probe(struct platform_device *pdev)
return err; return err;
} }
static int snd_uac2_remove(struct platform_device *pdev) static int snd_uac2_remove(struct audio_dev *audio_dev)
{ {
struct snd_card *card = platform_get_drvdata(pdev); struct snd_card *card = audio_dev->uac2.card;
if (card) if (card)
return snd_card_free(card); return snd_card_free(card);
...@@ -511,45 +498,6 @@ static int snd_uac2_remove(struct platform_device *pdev) ...@@ -511,45 +498,6 @@ static int snd_uac2_remove(struct platform_device *pdev)
return 0; return 0;
} }
static void snd_uac2_release(struct device *dev)
{
dev_dbg(dev, "releasing '%s'\n", dev_name(dev));
}
static int alsa_uac2_init(struct audio_dev *agdev)
{
struct snd_uac2_chip *uac2 = &agdev->uac2;
int err;
uac2->pdrv.probe = snd_uac2_probe;
uac2->pdrv.remove = snd_uac2_remove;
uac2->pdrv.driver.name = uac2_name;
uac2->pdev.id = 0;
uac2->pdev.name = uac2_name;
uac2->pdev.dev.release = snd_uac2_release;
/* Register snd_uac2 driver */
err = platform_driver_register(&uac2->pdrv);
if (err)
return err;
/* Register snd_uac2 device */
err = platform_device_register(&uac2->pdev);
if (err)
platform_driver_unregister(&uac2->pdrv);
return err;
}
static void alsa_uac2_exit(struct audio_dev *agdev)
{
struct snd_uac2_chip *uac2 = &agdev->uac2;
platform_driver_unregister(&uac2->pdrv);
platform_device_unregister(&uac2->pdev);
}
/* --------- USB Function Interface ------------- */ /* --------- USB Function Interface ------------- */
...@@ -960,7 +908,7 @@ free_ep(struct uac2_rtd_params *prm, struct usb_ep *ep) ...@@ -960,7 +908,7 @@ free_ep(struct uac2_rtd_params *prm, struct usb_ep *ep)
} }
if (usb_ep_disable(ep)) if (usb_ep_disable(ep))
dev_err(&uac2->pdev.dev, dev_err(uac2->card->dev,
"%s:%d Error!\n", __func__, __LINE__); "%s:%d Error!\n", __func__, __LINE__);
} }
...@@ -994,7 +942,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) ...@@ -994,7 +942,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
struct snd_uac2_chip *uac2 = &agdev->uac2; struct snd_uac2_chip *uac2 = &agdev->uac2;
struct usb_composite_dev *cdev = cfg->cdev; struct usb_composite_dev *cdev = cfg->cdev;
struct usb_gadget *gadget = cdev->gadget; struct usb_gadget *gadget = cdev->gadget;
struct device *dev = &uac2->pdev.dev; struct device *dev = &gadget->dev;
struct uac2_rtd_params *prm; struct uac2_rtd_params *prm;
struct f_uac2_opts *uac2_opts; struct f_uac2_opts *uac2_opts;
struct usb_string *us; struct usb_string *us;
...@@ -1094,6 +1042,8 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) ...@@ -1094,6 +1042,8 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
if (ret) if (ret)
return ret; return ret;
agdev->gadget = gadget;
prm = &agdev->uac2.c_prm; prm = &agdev->uac2.c_prm;
prm->max_psize = hs_epout_desc.wMaxPacketSize; prm->max_psize = hs_epout_desc.wMaxPacketSize;
prm->ureq = kcalloc(uac2_opts->req_number, sizeof(struct uac2_req), prm->ureq = kcalloc(uac2_opts->req_number, sizeof(struct uac2_req),
...@@ -1124,7 +1074,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) ...@@ -1124,7 +1074,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
goto err_no_memory; goto err_no_memory;
} }
ret = alsa_uac2_init(agdev); ret = snd_uac2_probe(agdev);
if (ret) if (ret)
goto err_no_memory; goto err_no_memory;
return 0; return 0;
...@@ -1136,6 +1086,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn) ...@@ -1136,6 +1086,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
kfree(agdev->uac2.c_prm.rbuf); kfree(agdev->uac2.c_prm.rbuf);
err_free_descs: err_free_descs:
usb_free_all_descriptors(fn); usb_free_all_descriptors(fn);
agdev->gadget = NULL;
return ret; return ret;
} }
...@@ -1147,7 +1098,7 @@ afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt) ...@@ -1147,7 +1098,7 @@ afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt)
struct f_uac2_opts *opts = agdev_to_uac2_opts(agdev); struct f_uac2_opts *opts = agdev_to_uac2_opts(agdev);
struct snd_uac2_chip *uac2 = &agdev->uac2; struct snd_uac2_chip *uac2 = &agdev->uac2;
struct usb_gadget *gadget = cdev->gadget; struct usb_gadget *gadget = cdev->gadget;
struct device *dev = &uac2->pdev.dev; struct device *dev = &gadget->dev;
struct usb_request *req; struct usb_request *req;
struct usb_ep *ep; struct usb_ep *ep;
struct uac2_rtd_params *prm; struct uac2_rtd_params *prm;
...@@ -1247,7 +1198,6 @@ static int ...@@ -1247,7 +1198,6 @@ static int
afunc_get_alt(struct usb_function *fn, unsigned intf) afunc_get_alt(struct usb_function *fn, unsigned intf)
{ {
struct audio_dev *agdev = func_to_agdev(fn); struct audio_dev *agdev = func_to_agdev(fn);
struct snd_uac2_chip *uac2 = &agdev->uac2;
if (intf == agdev->ac_intf) if (intf == agdev->ac_intf)
return agdev->ac_alt; return agdev->ac_alt;
...@@ -1256,7 +1206,7 @@ afunc_get_alt(struct usb_function *fn, unsigned intf) ...@@ -1256,7 +1206,7 @@ afunc_get_alt(struct usb_function *fn, unsigned intf)
else if (intf == agdev->as_in_intf) else if (intf == agdev->as_in_intf)
return agdev->as_in_alt; return agdev->as_in_alt;
else else
dev_err(&uac2->pdev.dev, dev_err(&agdev->gadget->dev,
"%s:%d Invalid Interface %d!\n", "%s:%d Invalid Interface %d!\n",
__func__, __LINE__, intf); __func__, __LINE__, intf);
...@@ -1281,7 +1231,6 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr) ...@@ -1281,7 +1231,6 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
{ {
struct usb_request *req = fn->config->cdev->req; struct usb_request *req = fn->config->cdev->req;
struct audio_dev *agdev = func_to_agdev(fn); struct audio_dev *agdev = func_to_agdev(fn);
struct snd_uac2_chip *uac2 = &agdev->uac2;
struct f_uac2_opts *opts; struct f_uac2_opts *opts;
u16 w_length = le16_to_cpu(cr->wLength); u16 w_length = le16_to_cpu(cr->wLength);
u16 w_index = le16_to_cpu(cr->wIndex); u16 w_index = le16_to_cpu(cr->wIndex);
...@@ -1310,7 +1259,7 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr) ...@@ -1310,7 +1259,7 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
*(u8 *)req->buf = 1; *(u8 *)req->buf = 1;
value = min_t(unsigned, w_length, 1); value = min_t(unsigned, w_length, 1);
} else { } else {
dev_err(&uac2->pdev.dev, dev_err(&agdev->gadget->dev,
"%s:%d control_selector=%d TODO!\n", "%s:%d control_selector=%d TODO!\n",
__func__, __LINE__, control_selector); __func__, __LINE__, control_selector);
} }
...@@ -1323,7 +1272,6 @@ in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr) ...@@ -1323,7 +1272,6 @@ in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr)
{ {
struct usb_request *req = fn->config->cdev->req; struct usb_request *req = fn->config->cdev->req;
struct audio_dev *agdev = func_to_agdev(fn); struct audio_dev *agdev = func_to_agdev(fn);
struct snd_uac2_chip *uac2 = &agdev->uac2;
struct f_uac2_opts *opts; struct f_uac2_opts *opts;
u16 w_length = le16_to_cpu(cr->wLength); u16 w_length = le16_to_cpu(cr->wLength);
u16 w_index = le16_to_cpu(cr->wIndex); u16 w_index = le16_to_cpu(cr->wIndex);
...@@ -1353,7 +1301,7 @@ in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr) ...@@ -1353,7 +1301,7 @@ in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr)
value = min_t(unsigned, w_length, sizeof r); value = min_t(unsigned, w_length, sizeof r);
memcpy(req->buf, &r, value); memcpy(req->buf, &r, value);
} else { } else {
dev_err(&uac2->pdev.dev, dev_err(&agdev->gadget->dev,
"%s:%d control_selector=%d TODO!\n", "%s:%d control_selector=%d TODO!\n",
__func__, __LINE__, control_selector); __func__, __LINE__, control_selector);
} }
...@@ -1389,12 +1337,11 @@ static int ...@@ -1389,12 +1337,11 @@ static int
setup_rq_inf(struct usb_function *fn, const struct usb_ctrlrequest *cr) setup_rq_inf(struct usb_function *fn, const struct usb_ctrlrequest *cr)
{ {
struct audio_dev *agdev = func_to_agdev(fn); struct audio_dev *agdev = func_to_agdev(fn);
struct snd_uac2_chip *uac2 = &agdev->uac2;
u16 w_index = le16_to_cpu(cr->wIndex); u16 w_index = le16_to_cpu(cr->wIndex);
u8 intf = w_index & 0xff; u8 intf = w_index & 0xff;
if (intf != agdev->ac_intf) { if (intf != agdev->ac_intf) {
dev_err(&uac2->pdev.dev, dev_err(&agdev->gadget->dev,
"%s:%d Error!\n", __func__, __LINE__); "%s:%d Error!\n", __func__, __LINE__);
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
...@@ -1412,7 +1359,6 @@ afunc_setup(struct usb_function *fn, const struct usb_ctrlrequest *cr) ...@@ -1412,7 +1359,6 @@ afunc_setup(struct usb_function *fn, const struct usb_ctrlrequest *cr)
{ {
struct usb_composite_dev *cdev = fn->config->cdev; struct usb_composite_dev *cdev = fn->config->cdev;
struct audio_dev *agdev = func_to_agdev(fn); struct audio_dev *agdev = func_to_agdev(fn);
struct snd_uac2_chip *uac2 = &agdev->uac2;
struct usb_request *req = cdev->req; struct usb_request *req = cdev->req;
u16 w_length = le16_to_cpu(cr->wLength); u16 w_length = le16_to_cpu(cr->wLength);
int value = -EOPNOTSUPP; int value = -EOPNOTSUPP;
...@@ -1424,14 +1370,15 @@ afunc_setup(struct usb_function *fn, const struct usb_ctrlrequest *cr) ...@@ -1424,14 +1370,15 @@ afunc_setup(struct usb_function *fn, const struct usb_ctrlrequest *cr)
if ((cr->bRequestType & USB_RECIP_MASK) == USB_RECIP_INTERFACE) if ((cr->bRequestType & USB_RECIP_MASK) == USB_RECIP_INTERFACE)
value = setup_rq_inf(fn, cr); value = setup_rq_inf(fn, cr);
else else
dev_err(&uac2->pdev.dev, "%s:%d Error!\n", __func__, __LINE__); dev_err(&agdev->gadget->dev, "%s:%d Error!\n",
__func__, __LINE__);
if (value >= 0) { if (value >= 0) {
req->length = value; req->length = value;
req->zero = value < w_length; req->zero = value < w_length;
value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC); value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
if (value < 0) { if (value < 0) {
dev_err(&uac2->pdev.dev, dev_err(&agdev->gadget->dev,
"%s:%d Error!\n", __func__, __LINE__); "%s:%d Error!\n", __func__, __LINE__);
req->status = 0; req->status = 0;
} }
...@@ -1573,7 +1520,7 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f) ...@@ -1573,7 +1520,7 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f)
struct audio_dev *agdev = func_to_agdev(f); struct audio_dev *agdev = func_to_agdev(f);
struct uac2_rtd_params *prm; struct uac2_rtd_params *prm;
alsa_uac2_exit(agdev); snd_uac2_remove(agdev);
prm = &agdev->uac2.p_prm; prm = &agdev->uac2.p_prm;
kfree(prm->rbuf); kfree(prm->rbuf);
...@@ -1582,6 +1529,8 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f) ...@@ -1582,6 +1529,8 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f)
kfree(prm->rbuf); kfree(prm->rbuf);
kfree(prm->ureq); kfree(prm->ureq);
usb_free_all_descriptors(f); usb_free_all_descriptors(f);
agdev->gadget = NULL;
} }
static struct usb_function *afunc_alloc(struct usb_function_instance *fi) static struct usb_function *afunc_alloc(struct usb_function_instance *fi)
......
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