1f9f848faSopenharmony_ci/*-
2f9f848faSopenharmony_ci * SPDX-License-Identifier: BSD-2-Clause
3f9f848faSopenharmony_ci *
4f9f848faSopenharmony_ci * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
5f9f848faSopenharmony_ci *
6f9f848faSopenharmony_ci * Redistribution and use in source and binary forms, with or without
7f9f848faSopenharmony_ci * modification, are permitted provided that the following conditions
8f9f848faSopenharmony_ci * are met:
9f9f848faSopenharmony_ci * 1. Redistributions of source code must retain the above copyright
10f9f848faSopenharmony_ci *    notice, this list of conditions and the following disclaimer.
11f9f848faSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
12f9f848faSopenharmony_ci *    notice, this list of conditions and the following disclaimer in the
13f9f848faSopenharmony_ci *    documentation and/or other materials provided with the distribution.
14f9f848faSopenharmony_ci *
15f9f848faSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16f9f848faSopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17f9f848faSopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18f9f848faSopenharmony_ci * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19f9f848faSopenharmony_ci * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20f9f848faSopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21f9f848faSopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22f9f848faSopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23f9f848faSopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24f9f848faSopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25f9f848faSopenharmony_ci * SUCH DAMAGE.
26f9f848faSopenharmony_ci */
27f9f848faSopenharmony_ci
28f9f848faSopenharmony_ci#include "implementation/global_implementation.h"
29f9f848faSopenharmony_ci
30f9f848faSopenharmony_ci/* function prototypes */
31f9f848faSopenharmony_cistatic usb_handle_req_t usb_temp_get_desc_w;
32f9f848faSopenharmony_cistatic usb_temp_setup_by_index_t usb_temp_setup_by_index_w;
33f9f848faSopenharmony_cistatic usb_temp_unsetup_t usb_temp_unsetup_w;
34f9f848faSopenharmony_cistatic usb_test_quirk_t usb_test_quirk_w;
35f9f848faSopenharmony_cistatic usb_quirk_ioctl_t usb_quirk_ioctl_w;
36f9f848faSopenharmony_ci
37f9f848faSopenharmony_ci/* global variables */
38f9f848faSopenharmony_ciusb_handle_req_t *usb_temp_get_desc_p = &usb_temp_get_desc_w;
39f9f848faSopenharmony_ciusb_temp_setup_by_index_t *usb_temp_setup_by_index_p = &usb_temp_setup_by_index_w;
40f9f848faSopenharmony_ciusb_temp_unsetup_t *usb_temp_unsetup_p = &usb_temp_unsetup_w;
41f9f848faSopenharmony_ciusb_test_quirk_t *usb_test_quirk_p = &usb_test_quirk_w;
42f9f848faSopenharmony_ciusb_quirk_ioctl_t *usb_quirk_ioctl_p = &usb_quirk_ioctl_w;
43f9f848faSopenharmony_cidevclass_t usb_devclass_ptr;
44f9f848faSopenharmony_ci
45f9f848faSopenharmony_cistatic usb_error_t
46f9f848faSopenharmony_ciusb_temp_setup_by_index_w(struct usb_device *udev, uint16_t index)
47f9f848faSopenharmony_ci{
48f9f848faSopenharmony_ci	return (USB_ERR_INVAL);
49f9f848faSopenharmony_ci}
50f9f848faSopenharmony_ci
51f9f848faSopenharmony_cistatic uint8_t
52f9f848faSopenharmony_ciusb_test_quirk_w(const struct usbd_lookup_info *info, uint16_t quirk)
53f9f848faSopenharmony_ci{
54f9f848faSopenharmony_ci	return (0);			/* no match */
55f9f848faSopenharmony_ci}
56f9f848faSopenharmony_ci
57f9f848faSopenharmony_cistatic int
58f9f848faSopenharmony_ciusb_quirk_ioctl_w(unsigned long cmd, caddr_t data, int fflag, struct thread *td)
59f9f848faSopenharmony_ci{
60f9f848faSopenharmony_ci	return (ENOIOCTL);
61f9f848faSopenharmony_ci}
62f9f848faSopenharmony_ci
63f9f848faSopenharmony_cistatic usb_error_t
64f9f848faSopenharmony_ciusb_temp_get_desc_w(struct usb_device *udev, struct usb_device_request *req, const void **pPtr, uint16_t *pLength)
65f9f848faSopenharmony_ci{
66f9f848faSopenharmony_ci	/* stall */
67f9f848faSopenharmony_ci	return (USB_ERR_STALLED);
68f9f848faSopenharmony_ci}
69f9f848faSopenharmony_ci
70f9f848faSopenharmony_cistatic void
71f9f848faSopenharmony_ciusb_temp_unsetup_w(struct usb_device *udev)
72f9f848faSopenharmony_ci{
73f9f848faSopenharmony_ci	usbd_free_config_desc(udev, udev->usb_template_ptr);
74f9f848faSopenharmony_ci	udev->usb_template_ptr = NULL;
75f9f848faSopenharmony_ci}
76f9f848faSopenharmony_ci
77f9f848faSopenharmony_civoid
78f9f848faSopenharmony_ciusb_quirk_unload(void *arg)
79f9f848faSopenharmony_ci{
80f9f848faSopenharmony_ci	/* reset function pointers */
81f9f848faSopenharmony_ci
82f9f848faSopenharmony_ci	usb_test_quirk_p = &usb_test_quirk_w;
83f9f848faSopenharmony_ci	usb_quirk_ioctl_p = &usb_quirk_ioctl_w;
84f9f848faSopenharmony_ci
85f9f848faSopenharmony_ci	/* wait for CPU to exit the loaded functions, if any */
86f9f848faSopenharmony_ci
87f9f848faSopenharmony_ci	/* XXX this is a tradeoff */
88f9f848faSopenharmony_ci
89f9f848faSopenharmony_ci	pause("WAIT", hz);
90f9f848faSopenharmony_ci}
91f9f848faSopenharmony_ci
92f9f848faSopenharmony_civoid
93f9f848faSopenharmony_ciusb_temp_unload(void *arg)
94f9f848faSopenharmony_ci{
95f9f848faSopenharmony_ci	/* reset function pointers */
96f9f848faSopenharmony_ci
97f9f848faSopenharmony_ci	usb_temp_get_desc_p = &usb_temp_get_desc_w;
98f9f848faSopenharmony_ci	usb_temp_setup_by_index_p = &usb_temp_setup_by_index_w;
99f9f848faSopenharmony_ci	usb_temp_unsetup_p = &usb_temp_unsetup_w;
100f9f848faSopenharmony_ci
101f9f848faSopenharmony_ci	/* wait for CPU to exit the loaded functions, if any */
102f9f848faSopenharmony_ci
103f9f848faSopenharmony_ci	/* XXX this is a tradeoff */
104f9f848faSopenharmony_ci
105f9f848faSopenharmony_ci	pause("WAIT", hz);
106f9f848faSopenharmony_ci}
107f9f848faSopenharmony_ci
108f9f848faSopenharmony_civoid
109f9f848faSopenharmony_ciusb_bus_unload(void *arg)
110f9f848faSopenharmony_ci{
111f9f848faSopenharmony_ci	/* reset function pointers */
112f9f848faSopenharmony_ci
113f9f848faSopenharmony_ci	usb_devclass_ptr = NULL;
114f9f848faSopenharmony_ci
115f9f848faSopenharmony_ci	/* wait for CPU to exit the loaded functions, if any */
116f9f848faSopenharmony_ci
117f9f848faSopenharmony_ci	/* XXX this is a tradeoff */
118f9f848faSopenharmony_ci
119f9f848faSopenharmony_ci	pause("WAIT", hz);
120f9f848faSopenharmony_ci}
121