diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/alpha/conf/GENERIC | 9 | ||||
-rw-r--r-- | sys/arch/amd64/conf/GENERIC | 9 | ||||
-rw-r--r-- | sys/arch/armish/conf/GENERIC | 9 | ||||
-rw-r--r-- | sys/arch/cats/conf/GENERIC | 9 | ||||
-rw-r--r-- | sys/arch/hppa/conf/GENERIC | 9 | ||||
-rw-r--r-- | sys/arch/hppa64/conf/GENERIC | 9 | ||||
-rw-r--r-- | sys/arch/i386/conf/GENERIC | 11 | ||||
-rw-r--r-- | sys/arch/macppc/conf/GENERIC | 9 | ||||
-rw-r--r-- | sys/arch/sparc64/conf/GENERIC | 9 | ||||
-rw-r--r-- | sys/arch/zaurus/conf/GENERIC | 9 | ||||
-rw-r--r-- | sys/dev/usb/files.usb | 6 | ||||
-rw-r--r-- | sys/dev/usb/uow.c | 311 | ||||
-rw-r--r-- | sys/dev/usb/uowreg.h | 108 |
13 files changed, 503 insertions, 14 deletions
diff --git a/sys/arch/alpha/conf/GENERIC b/sys/arch/alpha/conf/GENERIC index 11a7567d79b..a426da5dddb 100644 --- a/sys/arch/alpha/conf/GENERIC +++ b/sys/arch/alpha/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.183 2006/09/27 04:48:34 brad Exp $ +# $OpenBSD: GENERIC,v 1.184 2006/09/27 08:54:44 grange Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -124,6 +124,8 @@ radio* at udsbr? # USB radio ugen* at uhub? # USB Generic driver ural* at uhub? # Ralink RT2500USB rum* at uhub? # Ralink RT2501USB/RT2601USB +uow* at uhub? # Maxim/Dallas DS2490 1-Wire adapter +onewire* at uow? # EV6 Tsunami Core Logic tsc* at mainbus0 @@ -417,6 +419,11 @@ ubsec* at pci? # Bluesteel Networks 5xxx crypto card safe* at pci? # SafeNet SafeXcel 1141/1741 #ises* at pci? # Pijnenburg PCC-ISES +# 1-Wire devices +option ONEWIREVERBOSE +owid* at onewire? # ID +owtemp* at onewire? # Temperature + #pseudo-device raid 4 # RAIDframe disk driver pseudo-device crypto 1 pseudo-device sequencer 1 diff --git a/sys/arch/amd64/conf/GENERIC b/sys/arch/amd64/conf/GENERIC index af90636f505..39dcd52ad10 100644 --- a/sys/arch/amd64/conf/GENERIC +++ b/sys/arch/amd64/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.156 2006/09/19 22:11:19 mglocker Exp $ +# $OpenBSD: GENERIC,v 1.157 2006/09/27 08:54:44 grange Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -195,6 +195,8 @@ radio* at udsbr? # USB radio ugen* at uhub? # USB Generic driver ural* at uhub? # Ralink RT2500USB rum* at uhub? # Ralink RT2501USB/RT2601USB +uow* at uhub? # Maxim/Dallas DS2490 1-Wire adapter +onewire* at uow? puc* at pci? # PCI "universal" communication device #puc* at cardbus? @@ -488,6 +490,11 @@ scsibus* at ioprbs? iopsp* at iop? # I2O SCSI pass-through scsibus* at iopsp? +# 1-Wire devices +option ONEWIREVERBOSE +owid* at onewire? # ID +owtemp* at onewire? # Temperature + pseudo-device sequencer 1 #pseudo-device raid 4 # RAIDframe disk driver pseudo-device bio 1 # ioctl multiplexing device diff --git a/sys/arch/armish/conf/GENERIC b/sys/arch/armish/conf/GENERIC index 8ee8af7a0c1..210941951b7 100644 --- a/sys/arch/armish/conf/GENERIC +++ b/sys/arch/armish/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.11 2006/08/26 10:47:34 kettenis Exp $ +# $OpenBSD: GENERIC,v 1.12 2006/09/27 08:54:44 grange Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -144,6 +144,8 @@ ugen* at uhub? # USB Generic driver ural* at uhub? # Ralink RT2500USB rum* at uhub? # Ralink RT2501USB/RT2601USB #udcf* at uhub? # Gude Expert mouseCLOCK +uow* at uhub? # Maxim/Dallas DS2490 1-Wire adapter +onewire* at uow? amphy* at mii? # AMD 79C873 PHYs dcphy* at mii? # Digital Clone PHYs @@ -171,6 +173,11 @@ rlphy* at mii? # Realtek 8139 internal PHYs ciphy* at mii? # Cicada CS8201 10/100/1000 copper PHY ukphy* at mii? # generic unknown PHYs +# 1-Wire devices +option ONEWIREVERBOSE +owid* at onewire? # ID +owtemp* at onewire? # Temperature + # mouse & keyboard multiplexor pseudo-devices #pseudo-device wsmux 2 pseudo-device crypto 1 diff --git a/sys/arch/cats/conf/GENERIC b/sys/arch/cats/conf/GENERIC index 6337a3adbb4..e0d49db6b27 100644 --- a/sys/arch/cats/conf/GENERIC +++ b/sys/arch/cats/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.34 2006/08/18 23:14:43 jason Exp $ +# $OpenBSD: GENERIC,v 1.35 2006/09/27 08:54:44 grange Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -217,6 +217,8 @@ udsbr* at uhub? # D-Link DSB-R100 radio radio* at udsbr? # USB radio #ubt* at uhub? # USB Bluetooth ugen* at uhub? # USB Generic driver +uow* at uhub? # Maxim/Dallas DS2490 1-Wire adapter +onewire* at uow? # Audio Devices @@ -304,6 +306,11 @@ midi* at pcppi? # MIDI interface to the PC speaker hifn* at pci? # Hi/fn 7751 crypto card +# 1-Wire devices +option ONEWIREVERBOSE +owid* at onewire? # ID +owtemp* at onewire? # Temperature + # Pseudo-Devices pseudo-device wsmux 2 # mouse & keyboard multiplexor pseudo-device crypto 1 diff --git a/sys/arch/hppa/conf/GENERIC b/sys/arch/hppa/conf/GENERIC index 85e6974d17a..3a6dc93f630 100644 --- a/sys/arch/hppa/conf/GENERIC +++ b/sys/arch/hppa/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.88 2006/08/18 23:14:43 jason Exp $ +# $OpenBSD: GENERIC,v 1.89 2006/09/27 08:54:44 grange Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -156,6 +156,8 @@ radio* at udsbr? # USB radio ugen* at uhub? # USB Generic driver ural* at uhub? # Ralink RT2500USB rum* at uhub? # Ralink RT2501USB/RT2601USB +uow* at uhub? # Maxim/Dallas DS2490 1-Wire adapter +onewire* at uow? sti0 at mainbus0 irq 11 # [H]CRX-{8,24,48}[Z] graphics sti0 at phantomas0 irq 11 # builtin graphics on BC* @@ -315,5 +317,10 @@ safte* at scsibus? ses* at scsibus? uk* at scsibus? +# 1-Wire devices +option ONEWIREVERBOSE +owid* at onewire? # ID +owtemp* at onewire? # Temperature + pseudo-device hotplug 1 # devices hot plugging pseudo-device wsmux 2 # mouse and keyboard multiplexor diff --git a/sys/arch/hppa64/conf/GENERIC b/sys/arch/hppa64/conf/GENERIC index 3c9935ba5e9..dbb2a28c592 100644 --- a/sys/arch/hppa64/conf/GENERIC +++ b/sys/arch/hppa64/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.11 2006/08/14 08:34:21 jsg Exp $ +# $OpenBSD: GENERIC,v 1.12 2006/09/27 08:54:44 grange Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -118,6 +118,8 @@ pci* at ppb? #udsbr* at uhub? # D-Link DSB-R100 radio #radio* at udsbr? # USB radio #ugen* at uhub? # USB Generic driver +#uow* at uhub? # Maxim/Dallas DS2490 1-Wire adapter +#onewire* at uow? #sti* at pci? # EG-PCI, FX* #wsdisplay* at sti? @@ -190,4 +192,9 @@ ukphy* at mii? # generic unknown PHYs #safte* at scsibus? #ses* at scsibus? +# 1-Wire devices +#option ONEWIREVERBOSE +#owid* at onewire? # ID +#owtemp* at onewire? # Temperature + #pseudo-device wsmux 2 # mouse and keyboard multiplexor diff --git a/sys/arch/i386/conf/GENERIC b/sys/arch/i386/conf/GENERIC index a892cf1c2cf..4cf6779b8a1 100644 --- a/sys/arch/i386/conf/GENERIC +++ b/sys/arch/i386/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.525 2006/09/16 13:21:24 damien Exp $ +# $OpenBSD: GENERIC,v 1.526 2006/09/27 08:54:44 grange Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -73,7 +73,6 @@ pci* at mainbus0 option PCIVERBOSE option EISAVERBOSE option USBVERBOSE -option ONEWIREVERBOSE pchb* at pci? # PCI-Host bridges ppb* at pci? # PCI-PCI bridges @@ -248,6 +247,9 @@ rum* at uhub? # Ralink RT2501USB/RT2601USB #option NATM #ueagle* at uhub? # Analog Devices Eagle ADSL udcf* at uhub? # Gude Expert mouseCLOCK +uow* at uhub? # Maxim/Dallas DS2490 1-Wire adapter +onewire* at uow? + puc* at pci? # PCI "universal" communication device #puc* at cardbus? @@ -680,8 +682,9 @@ scsibus* at iopsp? #onewire* at gpioow? # 1-Wire devices -#owid* at onewire? # ID -#owtemp* at onewire? # Temperature +option ONEWIREVERBOSE +owid* at onewire? # ID +owtemp* at onewire? # Temperature pseudo-device pctr 1 pseudo-device mtrr 1 # Memory range attributes control diff --git a/sys/arch/macppc/conf/GENERIC b/sys/arch/macppc/conf/GENERIC index 8c41a664b60..7703bf23776 100644 --- a/sys/arch/macppc/conf/GENERIC +++ b/sys/arch/macppc/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.150 2006/08/18 23:14:43 jason Exp $g +# $OpenBSD: GENERIC,v 1.151 2006/09/27 08:54:44 grange Exp $g # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -271,6 +271,8 @@ ugen* at uhub? # USB Generic driver ural* at uhub? # Ralink RT2500USB rum* at uhub? # Ralink RT2501USB/RT2601USB udcf* at uhub? # Gude Expert mouseCLOCK +uow* at uhub? # Maxim/Dallas DS2490 1-Wire adapter +onewire* at uow? # I2C bus support iic* at ki2c? @@ -333,5 +335,10 @@ safte* at scsibus? ses* at scsibus? uk* at scsibus? +# 1-Wire devices +option ONEWIREVERBOSE +owid* at onewire? # ID +owtemp* at onewire? # Temperature + pseudo-device hotplug 1 # devices hot plugging pseudo-device wsmux 2 # mouse & keyboard multiplexor diff --git a/sys/arch/sparc64/conf/GENERIC b/sys/arch/sparc64/conf/GENERIC index 6710f804957..b24906937b2 100644 --- a/sys/arch/sparc64/conf/GENERIC +++ b/sys/arch/sparc64/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.158 2006/09/27 07:18:14 brad Exp $ +# $OpenBSD: GENERIC,v 1.159 2006/09/27 08:54:44 grange Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -185,6 +185,8 @@ radio* at udsbr? # USB radio #ubt* at uhub? # USB Bluetooth ugen* at uhub? # USB Generic driver udcf* at uhub? # Gude Expert mouseCLOCK +uow* at uhub? # Maxim/Dallas DS2490 1-Wire adapter +onewire* at uow? #### Standard system devices -- all required for a given architecture @@ -396,6 +398,11 @@ fdc* at sbus? #fdc* at ebus? fd* at fdc? +# 1-Wire devices +option ONEWIREVERBOSE +owid* at onewire? # ID +owtemp* at onewire? # Temperature + pseudo-device hotplug 1 # devices hot plugging # mouse & keyboard multiplexor pseudo-devices diff --git a/sys/arch/zaurus/conf/GENERIC b/sys/arch/zaurus/conf/GENERIC index 6a8d34b3c27..a4a7b1d265f 100644 --- a/sys/arch/zaurus/conf/GENERIC +++ b/sys/arch/zaurus/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.53 2006/08/18 23:14:43 jason Exp $ +# $OpenBSD: GENERIC,v 1.54 2006/09/27 08:54:44 grange Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -127,6 +127,8 @@ udsbr* at uhub? # D-Link DSB-R100 radio radio* at udsbr? # USB radio #ubt* at uhub? # USB Bluetooth ugen* at uhub? # USB Generic driver +uow* at uhub? # Maxim/Dallas DS2490 1-Wire adapter +onewire* at uow? sd* at scsibus? # SCSI disk drives #st* at scsibus? # SCSI tape drives @@ -194,6 +196,11 @@ audio* at zaudio? zrc0 at pxaip? # Zaurus remote control wskbd* at zrc? mux 1 +# 1-Wire devices +option ONEWIREVERBOSE +owid* at onewire? # ID +owtemp* at onewire? # Temperature + # Pseudo-Devices pseudo-device wsmux 2 # mouse & keyboard multiplexor pseudo-device hotplug 1 # devices hot plugging diff --git a/sys/dev/usb/files.usb b/sys/dev/usb/files.usb index f838a9cb94e..fbc792f5f7e 100644 --- a/sys/dev/usb/files.usb +++ b/sys/dev/usb/files.usb @@ -1,4 +1,4 @@ -# $OpenBSD: files.usb,v 1.63 2006/09/16 13:21:23 damien Exp $ +# $OpenBSD: files.usb,v 1.64 2006/09/27 08:54:44 grange Exp $ # $NetBSD: files.usb,v 1.16 2000/02/14 20:29:54 augustss Exp $ # # Config file and device description for machine-independent USB code. @@ -272,3 +272,7 @@ device uath: ether, ifnet, ifmedia, wlan, firmload attach uath at uhub file dev/usb/if_uath.c uath +# Maxim/Dallas DS2490 1-Wire adapter +device uow: onewirebus +attach uow at uhub +file dev/usb/uow.c uow diff --git a/sys/dev/usb/uow.c b/sys/dev/usb/uow.c new file mode 100644 index 00000000000..35f71f0e516 --- /dev/null +++ b/sys/dev/usb/uow.c @@ -0,0 +1,311 @@ +/* $OpenBSD: uow.c,v 1.1 2006/09/27 08:54:44 grange Exp $ */ + +/* + * Copyright (c) 2006 Alexander Yurchenko <grange@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Maxim/Dallas DS2490 USB 1-Wire adapter driver. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/proc.h> + +#include <dev/onewire/onewirevar.h> + +#include <dev/usb/usb.h> +#include <dev/usb/usbdevs.h> +#include <dev/usb/usbdi.h> +#include <dev/usb/usbdi_util.h> + +#include <dev/usb/uowreg.h> + +#ifdef UOW_DEBUG +#define DPRINTF(x) printf x +#else +#define DPRINTF(x) +#endif + +#define UOW_TIMEOUT 1000 /* ms */ + +struct uow_softc { + USBBASEDEVICE sc_dev; + + struct onewire_bus sc_ow_bus; + struct device * sc_ow_dev; + + usbd_device_handle sc_udev; + usbd_interface_handle sc_iface; + usbd_pipe_handle sc_ph_ibulk; + usbd_pipe_handle sc_ph_obulk; + usbd_pipe_handle sc_ph_intr; + u_int8_t sc_regs[DS2490_NREGS]; +}; + +USB_DECLARE_DRIVER(uow); + +/* List of supported devices */ +static const struct usb_devno uow_devs[] = { + { USB_VENDOR_DALLAS, USB_PRODUCT_DALLAS_USB_FOB_IBUTTON } +}; + +Static int uow_ow_reset(void *); +Static int uow_ow_bit(void *, int); + +Static int uow_cmd(struct uow_softc *, int, int); +Static void uow_intr(usbd_xfer_handle, usbd_private_handle, usbd_status); + +USB_MATCH(uow) +{ + USB_MATCH_START(uow, uaa); + + if (uaa->iface != NULL) + return (UMATCH_NONE); + + return ((usb_lookup(uow_devs, uaa->vendor, uaa->product) != NULL) ? + UMATCH_VENDOR_PRODUCT : UMATCH_NONE); +} + +USB_ATTACH(uow) +{ + USB_ATTACH_START(uow, sc, uaa); + usb_interface_descriptor_t *id; + usb_endpoint_descriptor_t *ed; + char *devinfop; + int ep_ibulk = -1, ep_obulk = -1, ep_intr = -1; + struct onewirebus_attach_args oba; + usbd_status error; + int i; + + sc->sc_udev = uaa->device; + + /* Display device info string */ + USB_ATTACH_SETUP; + if ((devinfop = usbd_devinfo_alloc(uaa->device, 0)) != NULL) { + printf("%s: %s\n", USBDEVNAME(sc->sc_dev), devinfop); + usbd_devinfo_free(devinfop); + } + + /* Set USB configuration */ + if ((error = usbd_set_config_no(sc->sc_udev, + DS2490_USB_CONFIG, 0)) != 0) { + printf("%s: failed to set config %d: %s\n", + USBDEVNAME(sc->sc_dev), DS2490_USB_CONFIG, + usbd_errstr(error)); + USB_ATTACH_ERROR_RETURN; + } + + /* Get interface handle */ + if ((error = usbd_device2interface_handle(sc->sc_udev, + DS2490_USB_IFACE, &sc->sc_iface)) != 0) { + printf("%s: failed to get iface %d: %s\n", + USBDEVNAME(sc->sc_dev), DS2490_USB_IFACE, + usbd_errstr(error)); + USB_ATTACH_ERROR_RETURN; + } + + /* Find endpoints */ + id = usbd_get_interface_descriptor(sc->sc_iface); + for (i = 0; i < id->bNumEndpoints; i++) { + ed = usbd_interface2endpoint_descriptor(sc->sc_iface, i); + if (ed == NULL) { + printf("%s: failed to get endpoint %d descriptor\n", + USBDEVNAME(sc->sc_dev), i); + USB_ATTACH_ERROR_RETURN; + } + + if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && + UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) + ep_ibulk = ed->bEndpointAddress; + if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && + UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) + ep_obulk = ed->bEndpointAddress; + if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && + UE_GET_XFERTYPE(ed->bmAttributes) == UE_INTERRUPT) + ep_intr = ed->bEndpointAddress; + } + if (ep_ibulk == -1 || ep_obulk == -1 || ep_intr == -1) { + printf("%s: missing endpoint: ibulk %d, obulk %d, intr %d\n", + USBDEVNAME(sc->sc_dev), ep_ibulk, ep_obulk, ep_intr); + USB_ATTACH_ERROR_RETURN; + } + + /* Open pipes */ + if ((error = usbd_open_pipe(sc->sc_iface, ep_ibulk, USBD_EXCLUSIVE_USE, + &sc->sc_ph_ibulk)) != 0) { + printf("%s: failed to open bulk-in pipe: %s\n", + USBDEVNAME(sc->sc_dev), usbd_errstr(error)); + USB_ATTACH_ERROR_RETURN; + } + if ((error = usbd_open_pipe(sc->sc_iface, ep_obulk, USBD_EXCLUSIVE_USE, + &sc->sc_ph_obulk)) != 0) { + printf("%s: failed to open bulk-out pipe: %s\n", + USBDEVNAME(sc->sc_dev), usbd_errstr(error)); + goto fail; + } + if ((error = usbd_open_pipe_intr(sc->sc_iface, ep_intr, + USBD_SHORT_XFER_OK, &sc->sc_ph_intr, sc, + sc->sc_regs, sizeof(sc->sc_regs), uow_intr, + USBD_DEFAULT_INTERVAL)) != 0) { + printf("%s: failed to open intr pipe: %s\n", + USBDEVNAME(sc->sc_dev), usbd_errstr(error)); + goto fail; + } + + /* Attach 1-Wire bus */ + sc->sc_ow_bus.bus_cookie = sc; + sc->sc_ow_bus.bus_reset = uow_ow_reset; + sc->sc_ow_bus.bus_bit = uow_ow_bit; + + bzero(&oba, sizeof(oba)); + oba.oba_bus = &sc->sc_ow_bus; + sc->sc_ow_dev = config_found(self, &oba, onewirebus_print); + + USB_ATTACH_SUCCESS_RETURN; + +fail: + if (sc->sc_ph_ibulk != NULL) + usbd_close_pipe(sc->sc_ph_ibulk); + if (sc->sc_ph_obulk != NULL) + usbd_close_pipe(sc->sc_ph_obulk); + if (sc->sc_ph_intr != NULL) + usbd_close_pipe(sc->sc_ph_intr); + USB_ATTACH_ERROR_RETURN; +} + +USB_DETACH(uow) +{ + USB_DETACH_START(uow, sc); + int rv = 0; + + if (sc->sc_ph_ibulk != NULL) + usbd_close_pipe(sc->sc_ph_ibulk); + if (sc->sc_ph_obulk != NULL) + usbd_close_pipe(sc->sc_ph_obulk); + if (sc->sc_ph_intr != NULL) + usbd_close_pipe(sc->sc_ph_intr); + + if (sc->sc_ow_dev != NULL) + rv = config_detach(sc->sc_ow_dev, flags); + + usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, + USBDEV(sc->sc_dev)); + + return (rv); +} + +int +uow_activate(device_ptr_t self, enum devact act) +{ + struct uow_softc *sc = (struct uow_softc *)self; + int rv = 0; + + switch (act) { + case DVACT_ACTIVATE: + break; + case DVACT_DEACTIVATE: + if (sc->sc_ow_dev != NULL) + rv = config_deactivate(sc->sc_ow_dev); + break; + } + + return (rv); +} + +Static int +uow_ow_reset(void *arg) +{ + struct uow_softc *sc = arg; + + if (uow_cmd(sc, DS2490_COMM_1WIRE_RESET | DS2490_BIT_IM, 0) != 0) + return (1); + + /* XXX: check presence pulse */ + return (0); +} + +Static int +uow_ow_bit(void *arg, int value) +{ + struct uow_softc *sc = arg; + usbd_xfer_handle xfer; + u_int8_t data; + usbd_status error; + + if (uow_cmd(sc, DS2490_COMM_BIT_IO | DS2490_BIT_IM | + (value ? DS2490_BIT_D : 0), 0) != 0) + return (1); + + if ((xfer = usbd_alloc_xfer(sc->sc_udev)) == NULL) { + printf("%s: failed to alloc xfer\n", USBDEVNAME(sc->sc_dev)); + return (1); + } + usbd_setup_xfer(xfer, sc->sc_ph_ibulk, sc, &data, sizeof(data), 0, + UOW_TIMEOUT, NULL); + error = usbd_sync_transfer(xfer); + usbd_free_xfer(xfer); + if (error != 0) { + printf("%s: failed to do xfer: %s\n", + USBDEVNAME(sc->sc_dev), usbd_errstr(error)); + return (1); + } + + return (data); +} + +Static int +uow_cmd(struct uow_softc *sc, int cmd, int param) +{ + usb_device_request_t req; + usbd_status error; + + req.bmRequestType = UT_WRITE_VENDOR_DEVICE; + req.bRequest = DS2490_COMM_CMD; + USETW(req.wValue, cmd); + USETW(req.wIndex, param); + USETW(req.wLength, 0); + if ((error = usbd_do_request(sc->sc_udev, &req, NULL)) != 0) { + printf("%s: failed to do request: %s\n", + USBDEVNAME(sc->sc_dev), usbd_errstr(error)); + return (1); + } + + bzero(sc->sc_regs, sizeof(sc->sc_regs)); + if (tsleep(sc->sc_regs, PRIBIO, "uowcmd", + (UOW_TIMEOUT * hz) / 1000) != 0) { + printf("%s: request timeout\n", USBDEVNAME(sc->sc_dev)); + return (1); + } + + return (0); +} + +Static void +uow_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status) +{ + struct uow_softc *sc = priv; + + if (status != USBD_NORMAL_COMPLETION) { + if (status == USBD_NOT_STARTED || status == USBD_CANCELLED) + return; + if (status == USBD_STALLED) + usbd_clear_endpoint_stall_async(sc->sc_ph_intr); + return; + } + + wakeup(sc->sc_regs); +} diff --git a/sys/dev/usb/uowreg.h b/sys/dev/usb/uowreg.h new file mode 100644 index 00000000000..57327d0efdd --- /dev/null +++ b/sys/dev/usb/uowreg.h @@ -0,0 +1,108 @@ +/* $OpenBSD: uowreg.h,v 1.1 2006/09/27 08:54:44 grange Exp $ */ + +/* + * Copyright (c) 2006 Alexander Yurchenko <grange@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _DEV_USB_UOWREG_H_ +#define _DEV_USB_UOWREG_H_ + +/* + * Maxim/Dallas DS2490 USB 1-Wire adapter register definitions. + */ + +/* USB core interface */ +#define DS2490_USB_CONFIG 1 /* configuration */ +#define DS2490_USB_IFACE 0 /* interface */ + +/* Command type codes */ +#define DS2490_CONTROL_CMD 0x00 /* control */ +#define DS2490_COMM_CMD 0x01 /* communication */ +#define DS2490_MODE_CMD 0x02 /* mode */ + +/* Control command codes */ +#define DS2490_CTL_RESET_DEVICE 0x0000 +#define DS2490_CTL_START_EXE 0x0001 +#define DS2490_CTL_RESUME_EXE 0x0002 +#define DS2490_CTL_HALT_EXE_IDLE 0x0003 +#define DS2490_CTL_HALT_EXE_DONE 0x0004 +#define DS2490_CTL_FLUSH_COMM_CMDS 0x0007 +#define DS2490_CTL_FLUSH_RCV_BUFFER 0x0008 +#define DS2490_CTL_FLUSH_XMT_BUFFER 0x0009 +#define DS2490_CTL_GET_COMM_CMDS 0x000a + +/* Communication command codes */ +#define DS2490_COMM_SET_DURATION 0x0012 +#define DS2490_COMM_PULSE 0x0030 +#define DS2490_COMM_1WIRE_RESET 0x0042 +#define DS2490_COMM_BIT_IO 0x0020 + +/* Communication command embedded command parameter bits */ +#define DS2490_BIT_IM (1 << 0) +#define DS2490_BIT_D (1 << 3) +#define DS2490_BIT_SE (1 << 3) +#define DS2490_BIT_TYPE (1 << 3) +#define DS2490_BIT_ICP (1 << 9) +#define DS2490_BIT_NTF (1 << 10) +#define DS2490_BIT_F (1 << 11) +#define DS2490_BIT_SPU (1 << 12) +#define DS2490_BIT_CIB (1 << 14) +#define DS2490_BIT_PST (1 << 14) + +/* Mode command codes */ +#define DS2490_MOD_PULSE_EN 0x0000 +#define DS2490_MOD_SPEED_CHANGE_EN 0x0001 +#define DS2490_MOD_1WIRE_SPEED 0x0002 +#define DS2490_MOD_STRONG_PU_DURATION 0x0003 +#define DS2490_MOD_PULLDOWN_SLEWRATE 0x0004 +#define DS2490_MOD_PROG_PULSE_DURATION 0x0005 +#define DS2490_MOD_WRITE1_LOWTIME 0x0006 +#define DS2490_MOD_DSOW0_TREC 0x0007 + +/* State registers */ +#define DS2490_ST_BEGIN 0x00 +#define DS2490_ST_ENFL 0x00 /* enabled flags */ +#define DS2490_ST_ENFL_SPUE (1 << 0) /* strong pullup */ +#define DS2490_ST_ENFL_PRGE (1 << 1) /* programming pulse */ +#define DS2490_ST_ENFL_SPCE (1 << 2) /* speed change */ +#define DS2490_ST_SPEED 0x01 /* bus speed */ +#define DS2490_ST_SPUDUR 0x02 /* strong pullup duration */ +#define DS2490_ST_PRGDUR 0x03 /* programming pullup duration */ +#define DS2490_ST_PDSRC 0x04 /* pulldown slew rate control */ +#define DS2490_ST_W1LT 0x05 /* write-1 low time */ +#define DS2490_ST_DSO 0x06 /* data sample offset */ +#define DS2490_ST_STFL 0x08 /* status flags */ +#define DS2490_ST_STFL_SPUA (1 << 0) /* strong pullup */ +#define DS2490_ST_STFL_PRGA (1 << 1) /* programming pulse */ +#define DS2490_ST_STFL_12VP (1 << 2) /* 12V prog voltage */ +#define DS2490_ST_STFL_PMOD (1 << 3) /* ext power */ +#define DS2490_ST_STFL_HALT (1 << 4) /* halted */ +#define DS2490_ST_STFL_IDLE (1 << 5) /* idle */ +#define DS2490_ST_STFL_EP0F (1 << 7) /* EP0 FIFO status */ +#define DS2490_ST_CC1 0x09 /* communication command byte 1 */ +#define DS2490_ST_CC2 0x0a /* communication command byte 2 */ +#define DS2490_ST_CCBUF 0x0b /* communication command buf status */ +#define DS2490_ST_OBUF 0x0c /* data out buf status */ +#define DS2490_ST_IBUF 0x0d /* data in buf status */ +#define DS2490_ST_END 0x0f + +/* Result registers */ +#define DS2490_RES_BEGIN 0x10 +#define DS2490_RES_END 0x1f +#define DS2490_RES_DETECT 0xa5 /* device detect */ + +#define DS2490_NREGS (DS2490_RES_END + 1) + +#endif /* !_DEV_USB_UOWREG_H_ */ |