13
13
14
14
#include <linux/usb/audio.h>
15
15
#include <linux/usb/audio-v2.h>
16
- #include <linux/platform_device.h>
17
16
#include <linux/module.h>
18
17
19
18
#include <sound/core.h>
51
50
#define UNFLW_CTRL 8
52
51
#define OVFLW_CTRL 10
53
52
54
- static const char * uac2_name = "snd_uac2" ;
55
-
56
53
struct uac2_req {
57
54
struct uac2_rtd_params * pp ; /* parent param */
58
55
struct usb_request * req ;
@@ -81,9 +78,6 @@ struct uac2_rtd_params {
81
78
};
82
79
83
80
struct snd_uac2_chip {
84
- struct platform_device pdev ;
85
- struct platform_driver pdrv ;
86
-
87
81
struct uac2_rtd_params p_prm ;
88
82
struct uac2_rtd_params c_prm ;
89
83
@@ -122,6 +116,7 @@ struct audio_dev {
122
116
123
117
struct usb_ep * in_ep , * out_ep ;
124
118
struct usb_function func ;
119
+ struct usb_gadget * gadget ;
125
120
126
121
/* The ALSA Sound Card it represents on the USB-Client side */
127
122
struct snd_uac2_chip uac2 ;
@@ -139,12 +134,6 @@ struct audio_dev *uac2_to_agdev(struct snd_uac2_chip *u)
139
134
return container_of (u , struct audio_dev , uac2 );
140
135
}
141
136
142
- static inline
143
- struct snd_uac2_chip * pdev_to_uac2 (struct platform_device * p )
144
- {
145
- return container_of (p , struct snd_uac2_chip , pdev );
146
- }
147
-
148
137
static inline
149
138
struct f_uac2_opts * agdev_to_uac2_opts (struct audio_dev * agdev )
150
139
{
@@ -254,7 +243,7 @@ agdev_iso_complete(struct usb_ep *ep, struct usb_request *req)
254
243
255
244
exit :
256
245
if (usb_ep_queue (ep , req , GFP_ATOMIC ))
257
- dev_err (& uac2 -> pdev . dev , "%d Error!\n" , __LINE__ );
246
+ dev_err (uac2 -> card -> dev , "%d Error!\n" , __LINE__ );
258
247
259
248
if (update_alsa )
260
249
snd_pcm_period_elapsed (substream );
@@ -440,23 +429,22 @@ static struct snd_pcm_ops uac2_pcm_ops = {
440
429
.prepare = uac2_pcm_null ,
441
430
};
442
431
443
- static int snd_uac2_probe (struct platform_device * pdev )
432
+ static int snd_uac2_probe (struct audio_dev * audio_dev )
444
433
{
445
- struct snd_uac2_chip * uac2 = pdev_to_uac2 ( pdev ) ;
434
+ struct snd_uac2_chip * uac2 = & audio_dev -> uac2 ;
446
435
struct snd_card * card ;
447
436
struct snd_pcm * pcm ;
448
- struct audio_dev * audio_dev ;
449
437
struct f_uac2_opts * opts ;
450
438
int err ;
451
439
int p_chmask , c_chmask ;
452
440
453
- audio_dev = uac2_to_agdev (uac2 );
454
441
opts = container_of (audio_dev -> func .fi , struct f_uac2_opts , func_inst );
455
442
p_chmask = opts -> p_chmask ;
456
443
c_chmask = opts -> c_chmask ;
457
444
458
445
/* Choose any slot, with no id */
459
- err = snd_card_new (& pdev -> dev , -1 , NULL , THIS_MODULE , 0 , & card );
446
+ err = snd_card_new (& audio_dev -> gadget -> dev ,
447
+ -1 , NULL , THIS_MODULE , 0 , & card );
460
448
if (err < 0 )
461
449
return err ;
462
450
@@ -481,16 +469,15 @@ static int snd_uac2_probe(struct platform_device *pdev)
481
469
482
470
strcpy (card -> driver , "UAC2_Gadget" );
483
471
strcpy (card -> shortname , "UAC2_Gadget" );
484
- sprintf (card -> longname , "UAC2_Gadget %i" , pdev -> id );
472
+ sprintf (card -> longname , "UAC2_Gadget %i" , card -> dev -> id );
485
473
486
474
snd_pcm_lib_preallocate_pages_for_all (pcm , SNDRV_DMA_TYPE_CONTINUOUS ,
487
475
snd_dma_continuous_data (GFP_KERNEL ), 0 , BUFF_SIZE_MAX );
488
476
489
477
err = snd_card_register (card );
490
- if (! err ) {
491
- platform_set_drvdata ( pdev , card );
478
+
479
+ if (! err )
492
480
return 0 ;
493
- }
494
481
495
482
snd_fail :
496
483
snd_card_free (card );
@@ -501,55 +488,16 @@ static int snd_uac2_probe(struct platform_device *pdev)
501
488
return err ;
502
489
}
503
490
504
- static int snd_uac2_remove (struct platform_device * pdev )
491
+ static int snd_uac2_remove (struct audio_dev * audio_dev )
505
492
{
506
- struct snd_card * card = platform_get_drvdata ( pdev ) ;
493
+ struct snd_card * card = audio_dev -> uac2 . card ;
507
494
508
495
if (card )
509
496
return snd_card_free (card );
510
497
511
498
return 0 ;
512
499
}
513
500
514
- static void snd_uac2_release (struct device * dev )
515
- {
516
- dev_dbg (dev , "releasing '%s'\n" , dev_name (dev ));
517
- }
518
-
519
- static int alsa_uac2_init (struct audio_dev * agdev )
520
- {
521
- struct snd_uac2_chip * uac2 = & agdev -> uac2 ;
522
- int err ;
523
-
524
- uac2 -> pdrv .probe = snd_uac2_probe ;
525
- uac2 -> pdrv .remove = snd_uac2_remove ;
526
- uac2 -> pdrv .driver .name = uac2_name ;
527
-
528
- uac2 -> pdev .id = 0 ;
529
- uac2 -> pdev .name = uac2_name ;
530
- uac2 -> pdev .dev .release = snd_uac2_release ;
531
-
532
- /* Register snd_uac2 driver */
533
- err = platform_driver_register (& uac2 -> pdrv );
534
- if (err )
535
- return err ;
536
-
537
- /* Register snd_uac2 device */
538
- err = platform_device_register (& uac2 -> pdev );
539
- if (err )
540
- platform_driver_unregister (& uac2 -> pdrv );
541
-
542
- return err ;
543
- }
544
-
545
- static void alsa_uac2_exit (struct audio_dev * agdev )
546
- {
547
- struct snd_uac2_chip * uac2 = & agdev -> uac2 ;
548
-
549
- platform_driver_unregister (& uac2 -> pdrv );
550
- platform_device_unregister (& uac2 -> pdev );
551
- }
552
-
553
501
554
502
/* --------- USB Function Interface ------------- */
555
503
@@ -960,7 +908,7 @@ free_ep(struct uac2_rtd_params *prm, struct usb_ep *ep)
960
908
}
961
909
962
910
if (usb_ep_disable (ep ))
963
- dev_err (& uac2 -> pdev . dev ,
911
+ dev_err (uac2 -> card -> dev ,
964
912
"%s:%d Error!\n" , __func__ , __LINE__ );
965
913
}
966
914
@@ -994,7 +942,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
994
942
struct snd_uac2_chip * uac2 = & agdev -> uac2 ;
995
943
struct usb_composite_dev * cdev = cfg -> cdev ;
996
944
struct usb_gadget * gadget = cdev -> gadget ;
997
- struct device * dev = & uac2 -> pdev . dev ;
945
+ struct device * dev = & gadget -> dev ;
998
946
struct uac2_rtd_params * prm ;
999
947
struct f_uac2_opts * uac2_opts ;
1000
948
struct usb_string * us ;
@@ -1094,6 +1042,8 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
1094
1042
if (ret )
1095
1043
return ret ;
1096
1044
1045
+ agdev -> gadget = gadget ;
1046
+
1097
1047
prm = & agdev -> uac2 .c_prm ;
1098
1048
prm -> max_psize = hs_epout_desc .wMaxPacketSize ;
1099
1049
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
1074
goto err_no_memory ;
1125
1075
}
1126
1076
1127
- ret = alsa_uac2_init (agdev );
1077
+ ret = snd_uac2_probe (agdev );
1128
1078
if (ret )
1129
1079
goto err_no_memory ;
1130
1080
return 0 ;
@@ -1136,6 +1086,7 @@ afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
1136
1086
kfree (agdev -> uac2 .c_prm .rbuf );
1137
1087
err_free_descs :
1138
1088
usb_free_all_descriptors (fn );
1089
+ agdev -> gadget = NULL ;
1139
1090
return ret ;
1140
1091
}
1141
1092
@@ -1147,7 +1098,7 @@ afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt)
1147
1098
struct f_uac2_opts * opts = agdev_to_uac2_opts (agdev );
1148
1099
struct snd_uac2_chip * uac2 = & agdev -> uac2 ;
1149
1100
struct usb_gadget * gadget = cdev -> gadget ;
1150
- struct device * dev = & uac2 -> pdev . dev ;
1101
+ struct device * dev = & gadget -> dev ;
1151
1102
struct usb_request * req ;
1152
1103
struct usb_ep * ep ;
1153
1104
struct uac2_rtd_params * prm ;
@@ -1247,7 +1198,6 @@ static int
1247
1198
afunc_get_alt (struct usb_function * fn , unsigned intf )
1248
1199
{
1249
1200
struct audio_dev * agdev = func_to_agdev (fn );
1250
- struct snd_uac2_chip * uac2 = & agdev -> uac2 ;
1251
1201
1252
1202
if (intf == agdev -> ac_intf )
1253
1203
return agdev -> ac_alt ;
@@ -1256,7 +1206,7 @@ afunc_get_alt(struct usb_function *fn, unsigned intf)
1256
1206
else if (intf == agdev -> as_in_intf )
1257
1207
return agdev -> as_in_alt ;
1258
1208
else
1259
- dev_err (& uac2 -> pdev . dev ,
1209
+ dev_err (& agdev -> gadget -> dev ,
1260
1210
"%s:%d Invalid Interface %d!\n" ,
1261
1211
__func__ , __LINE__ , intf );
1262
1212
@@ -1281,7 +1231,6 @@ in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1281
1231
{
1282
1232
struct usb_request * req = fn -> config -> cdev -> req ;
1283
1233
struct audio_dev * agdev = func_to_agdev (fn );
1284
- struct snd_uac2_chip * uac2 = & agdev -> uac2 ;
1285
1234
struct f_uac2_opts * opts ;
1286
1235
u16 w_length = le16_to_cpu (cr -> wLength );
1287
1236
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
1259
* (u8 * )req -> buf = 1 ;
1311
1260
value = min_t (unsigned , w_length , 1 );
1312
1261
} else {
1313
- dev_err (& uac2 -> pdev . dev ,
1262
+ dev_err (& agdev -> gadget -> dev ,
1314
1263
"%s:%d control_selector=%d TODO!\n" ,
1315
1264
__func__ , __LINE__ , control_selector );
1316
1265
}
@@ -1323,7 +1272,6 @@ in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1323
1272
{
1324
1273
struct usb_request * req = fn -> config -> cdev -> req ;
1325
1274
struct audio_dev * agdev = func_to_agdev (fn );
1326
- struct snd_uac2_chip * uac2 = & agdev -> uac2 ;
1327
1275
struct f_uac2_opts * opts ;
1328
1276
u16 w_length = le16_to_cpu (cr -> wLength );
1329
1277
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
1301
value = min_t (unsigned , w_length , sizeof r );
1354
1302
memcpy (req -> buf , & r , value );
1355
1303
} else {
1356
- dev_err (& uac2 -> pdev . dev ,
1304
+ dev_err (& agdev -> gadget -> dev ,
1357
1305
"%s:%d control_selector=%d TODO!\n" ,
1358
1306
__func__ , __LINE__ , control_selector );
1359
1307
}
@@ -1389,12 +1337,11 @@ static int
1389
1337
setup_rq_inf (struct usb_function * fn , const struct usb_ctrlrequest * cr )
1390
1338
{
1391
1339
struct audio_dev * agdev = func_to_agdev (fn );
1392
- struct snd_uac2_chip * uac2 = & agdev -> uac2 ;
1393
1340
u16 w_index = le16_to_cpu (cr -> wIndex );
1394
1341
u8 intf = w_index & 0xff ;
1395
1342
1396
1343
if (intf != agdev -> ac_intf ) {
1397
- dev_err (& uac2 -> pdev . dev ,
1344
+ dev_err (& agdev -> gadget -> dev ,
1398
1345
"%s:%d Error!\n" , __func__ , __LINE__ );
1399
1346
return - EOPNOTSUPP ;
1400
1347
}
@@ -1412,7 +1359,6 @@ afunc_setup(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1412
1359
{
1413
1360
struct usb_composite_dev * cdev = fn -> config -> cdev ;
1414
1361
struct audio_dev * agdev = func_to_agdev (fn );
1415
- struct snd_uac2_chip * uac2 = & agdev -> uac2 ;
1416
1362
struct usb_request * req = cdev -> req ;
1417
1363
u16 w_length = le16_to_cpu (cr -> wLength );
1418
1364
int value = - EOPNOTSUPP ;
@@ -1424,14 +1370,15 @@ afunc_setup(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1424
1370
if ((cr -> bRequestType & USB_RECIP_MASK ) == USB_RECIP_INTERFACE )
1425
1371
value = setup_rq_inf (fn , cr );
1426
1372
else
1427
- dev_err (& uac2 -> pdev .dev , "%s:%d Error!\n" , __func__ , __LINE__ );
1373
+ dev_err (& agdev -> gadget -> dev , "%s:%d Error!\n" ,
1374
+ __func__ , __LINE__ );
1428
1375
1429
1376
if (value >= 0 ) {
1430
1377
req -> length = value ;
1431
1378
req -> zero = value < w_length ;
1432
1379
value = usb_ep_queue (cdev -> gadget -> ep0 , req , GFP_ATOMIC );
1433
1380
if (value < 0 ) {
1434
- dev_err (& uac2 -> pdev . dev ,
1381
+ dev_err (& agdev -> gadget -> dev ,
1435
1382
"%s:%d Error!\n" , __func__ , __LINE__ );
1436
1383
req -> status = 0 ;
1437
1384
}
@@ -1573,7 +1520,7 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f)
1573
1520
struct audio_dev * agdev = func_to_agdev (f );
1574
1521
struct uac2_rtd_params * prm ;
1575
1522
1576
- alsa_uac2_exit (agdev );
1523
+ snd_uac2_remove (agdev );
1577
1524
1578
1525
prm = & agdev -> uac2 .p_prm ;
1579
1526
kfree (prm -> rbuf );
@@ -1582,6 +1529,8 @@ static void afunc_unbind(struct usb_configuration *c, struct usb_function *f)
1582
1529
kfree (prm -> rbuf );
1583
1530
kfree (prm -> ureq );
1584
1531
usb_free_all_descriptors (f );
1532
+
1533
+ agdev -> gadget = NULL ;
1585
1534
}
1586
1535
1587
1536
static struct usb_function * afunc_alloc (struct usb_function_instance * fi )
0 commit comments