Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0+
  2/*
  3 * Copyright (C) 2015 Karol Kosik <karo9@interia.eu>
  4 * Copyright (C) 2015-2016 Samsung Electronics
  5 *               Igor Kotrasinski <i.kotrasinsk@samsung.com>
  6 *               Krzysztof Opasiak <k.opasiak@samsung.com>
 
 
 
 
 
 
 
 
 
 
 
 
 
  7 */
  8
  9#include <linux/device.h>
 10#include <linux/list.h>
 11#include <linux/module.h>
 12
 13#include "vudc.h"
 14
 15static unsigned int vudc_number = 1;
 16
 17module_param_named(num, vudc_number, uint, S_IRUGO);
 18MODULE_PARM_DESC(num, "number of emulated controllers");
 19
 20static struct platform_driver vudc_driver = {
 21	.probe		= vudc_probe,
 22	.remove_new	= vudc_remove,
 23	.driver		= {
 24		.name	= GADGET_NAME,
 25		.dev_groups = vudc_groups,
 26	},
 27};
 28
 29static LIST_HEAD(vudc_devices);
 30
 31static int __init vudc_init(void)
 32{
 33	int retval = -ENOMEM;
 34	int i;
 35	struct vudc_device *udc_dev = NULL, *udc_dev2 = NULL;
 36
 37	if (usb_disabled())
 38		return -ENODEV;
 39
 40	if (vudc_number < 1) {
 41		pr_err("Number of emulated UDC must be no less than 1");
 42		return -EINVAL;
 43	}
 44
 45	retval = platform_driver_register(&vudc_driver);
 46	if (retval < 0)
 47		goto out;
 48
 49	for (i = 0; i < vudc_number; i++) {
 50		udc_dev = alloc_vudc_device(i);
 51		if (!udc_dev) {
 52			retval = -ENOMEM;
 53			goto cleanup;
 54		}
 55
 56		retval = platform_device_add(udc_dev->pdev);
 57		if (retval < 0) {
 58			put_vudc_device(udc_dev);
 59			goto cleanup;
 60		}
 61
 62		list_add_tail(&udc_dev->dev_entry, &vudc_devices);
 63		if (!platform_get_drvdata(udc_dev->pdev)) {
 64			/*
 65			 * The udc was added successfully but its probe
 66			 * function failed for some reason.
 67			 */
 68			retval = -EINVAL;
 69			goto cleanup;
 70		}
 71	}
 72	goto out;
 73
 74cleanup:
 75	list_for_each_entry_safe(udc_dev, udc_dev2, &vudc_devices, dev_entry) {
 76		list_del(&udc_dev->dev_entry);
 77		/*
 78		 * Just do platform_device_del() here, put_vudc_device()
 79		 * calls the platform_device_put()
 80		 */
 81		platform_device_del(udc_dev->pdev);
 82		put_vudc_device(udc_dev);
 83	}
 84
 85	platform_driver_unregister(&vudc_driver);
 86out:
 87	return retval;
 88}
 89module_init(vudc_init);
 90
 91static void __exit vudc_cleanup(void)
 92{
 93	struct vudc_device *udc_dev = NULL, *udc_dev2 = NULL;
 94
 95	list_for_each_entry_safe(udc_dev, udc_dev2, &vudc_devices, dev_entry) {
 96		list_del(&udc_dev->dev_entry);
 97		/*
 98		 * Just do platform_device_del() here, put_vudc_device()
 99		 * calls the platform_device_put()
100		 */
101		platform_device_del(udc_dev->pdev);
102		put_vudc_device(udc_dev);
103	}
104	platform_driver_unregister(&vudc_driver);
105}
106module_exit(vudc_cleanup);
107
108MODULE_DESCRIPTION("USB over IP Device Controller");
109MODULE_AUTHOR("Krzysztof Opasiak, Karol Kosik, Igor Kotrasinski");
110MODULE_LICENSE("GPL");
v4.10.11
 
  1/*
  2 * Copyright (C) 2015 Karol Kosik <karo9@interia.eu>
  3 * Copyright (C) 2015-2016 Samsung Electronics
  4 *               Igor Kotrasinski <i.kotrasinsk@samsung.com>
  5 *               Krzysztof Opasiak <k.opasiak@samsung.com>
  6 *
  7 * This program is free software; you can redistribute it and/or modify
  8 * it under the terms of the GNU General Public License as published by
  9 * the Free Software Foundation; either version 2 of the License, or
 10 * (at your option) any later version.
 11 *
 12 * This program is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 15 * GNU General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU General Public License
 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 19 */
 20
 21#include <linux/device.h>
 22#include <linux/list.h>
 23#include <linux/module.h>
 24
 25#include "vudc.h"
 26
 27static unsigned int vudc_number = 1;
 28
 29module_param_named(num, vudc_number, uint, S_IRUGO);
 30MODULE_PARM_DESC(num, "number of emulated controllers");
 31
 32static struct platform_driver vudc_driver = {
 33	.probe		= vudc_probe,
 34	.remove		= vudc_remove,
 35	.driver		= {
 36		.name	= GADGET_NAME,
 
 37	},
 38};
 39
 40static struct list_head vudc_devices = LIST_HEAD_INIT(vudc_devices);
 41
 42static int __init init(void)
 43{
 44	int retval = -ENOMEM;
 45	int i;
 46	struct vudc_device *udc_dev = NULL, *udc_dev2 = NULL;
 47
 48	if (usb_disabled())
 49		return -ENODEV;
 50
 51	if (vudc_number < 1) {
 52		pr_err("Number of emulated UDC must be no less than 1");
 53		return -EINVAL;
 54	}
 55
 56	retval = platform_driver_register(&vudc_driver);
 57	if (retval < 0)
 58		goto out;
 59
 60	for (i = 0; i < vudc_number; i++) {
 61		udc_dev = alloc_vudc_device(i);
 62		if (!udc_dev) {
 63			retval = -ENOMEM;
 64			goto cleanup;
 65		}
 66
 67		retval = platform_device_add(udc_dev->pdev);
 68		if (retval < 0) {
 69			put_vudc_device(udc_dev);
 70			goto cleanup;
 71		}
 72
 73		list_add_tail(&udc_dev->dev_entry, &vudc_devices);
 74		if (!platform_get_drvdata(udc_dev->pdev)) {
 75			/*
 76			 * The udc was added successfully but its probe
 77			 * function failed for some reason.
 78			 */
 79			retval = -EINVAL;
 80			goto cleanup;
 81		}
 82	}
 83	goto out;
 84
 85cleanup:
 86	list_for_each_entry_safe(udc_dev, udc_dev2, &vudc_devices, dev_entry) {
 87		list_del(&udc_dev->dev_entry);
 
 
 
 
 88		platform_device_del(udc_dev->pdev);
 89		put_vudc_device(udc_dev);
 90	}
 91
 92	platform_driver_unregister(&vudc_driver);
 93out:
 94	return retval;
 95}
 96module_init(init);
 97
 98static void __exit cleanup(void)
 99{
100	struct vudc_device *udc_dev = NULL, *udc_dev2 = NULL;
101
102	list_for_each_entry_safe(udc_dev, udc_dev2, &vudc_devices, dev_entry) {
103		list_del(&udc_dev->dev_entry);
104		platform_device_unregister(udc_dev->pdev);
 
 
 
 
105		put_vudc_device(udc_dev);
106	}
107	platform_driver_unregister(&vudc_driver);
108}
109module_exit(cleanup);
110
111MODULE_DESCRIPTION("USB over IP Device Controller");
112MODULE_AUTHOR("Krzysztof Opasiak, Karol Kosik, Igor Kotrasinski");
113MODULE_LICENSE("GPL");