1 /* $OpenBSD: uyap.c,v 1.8 2004/12/19 15:20:13 deraadt Exp $ */
2 /* $NetBSD: uyap.c,v 1.6 2002/07/11 21:14:37 augustss Exp $ */
3
4 /*
5 * Copyright (c) 2000 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson <lennart@augustsson.net>.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/device.h>
44 #include <sys/conf.h>
45 #include <sys/tty.h>
46
47 #include <dev/usb/usb.h>
48 #include <dev/usb/usbdi.h>
49 #include <dev/usb/usbdevs.h>
50
51 #include <dev/usb/ezload.h>
52
53 struct uyap_softc {
54 USBBASEDEVICE sc_dev; /* base device */
55 usbd_device_handle sc_udev;
56 };
57
58 USB_DECLARE_DRIVER(uyap);
59 void uyap_attachhook(void *);
60
USB_MATCH(uyap)61 USB_MATCH(uyap)
62 {
63 USB_MATCH_START(uyap, uaa);
64
65 if (uaa->iface != NULL)
66 return (UMATCH_NONE);
67
68 /* Match the boot device. */
69 if (uaa->vendor == USB_VENDOR_SILICONPORTALS &&
70 uaa->product == USB_PRODUCT_SILICONPORTALS_YAPPH_NF)
71 return (UMATCH_VENDOR_PRODUCT);
72
73 return (UMATCH_NONE);
74 }
75
76 void
uyap_attachhook(void * xsc)77 uyap_attachhook(void *xsc)
78 {
79 char *firmwares[] = { "uyap", NULL };
80 struct uyap_softc *sc = xsc;
81 int err;
82
83 err = ezload_downloads_and_reset(sc->sc_udev, firmwares);
84 if (err) {
85 printf("%s: download ezdata format firmware error: %s\n",
86 USBDEVNAME(sc->sc_dev), usbd_errstr(err));
87 USB_ATTACH_ERROR_RETURN;
88 }
89
90 printf("%s: firmware download complete, disconnecting.\n",
91 USBDEVNAME(sc->sc_dev));
92 }
93
USB_ATTACH(uyap)94 USB_ATTACH(uyap)
95 {
96 USB_ATTACH_START(uyap, sc, uaa);
97 usbd_device_handle dev = uaa->device;
98 char devinfo[1024];
99
100 usbd_devinfo(dev, 0, devinfo, sizeof devinfo);
101 USB_ATTACH_SETUP;
102 printf("%s: %s\n", USBDEVNAME(sc->sc_dev), devinfo);
103 printf("%s: downloading firmware\n", USBDEVNAME(sc->sc_dev));
104
105 sc->sc_udev = dev;
106 if (rootvp == NULL)
107 mountroothook_establish(uyap_attachhook, sc);
108 else
109 uyap_attachhook(sc);
110
111 USB_ATTACH_SUCCESS_RETURN;
112 }
113
USB_DETACH(uyap)114 USB_DETACH(uyap)
115 {
116 /*USB_DETACH_START(uyap, sc);*/
117
118 return (0);
119 }
120
121 int
uyap_activate(device_ptr_t self,enum devact act)122 uyap_activate(device_ptr_t self, enum devact act)
123 {
124 return 0;
125 }
126