2008-04-29 00:22:51 +04:00
|
|
|
/* $NetBSD: ukyopon.c,v 1.9 2008/04/28 20:24:00 martin Exp $ */
|
2005-04-15 21:18:18 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1998, 2005 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Lennart Augustsson (lennart@augustsson.net) at
|
|
|
|
* Carlstedt Research & Technology.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by ITOH Yasufumi.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2008-04-29 00:22:51 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ukyopon.c,v 1.9 2008/04/28 20:24:00 martin Exp $");
|
2005-04-15 21:18:18 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
2005-04-15 21:18:18 +04:00
|
|
|
|
|
|
|
#include <dev/usb/usb.h>
|
|
|
|
#include <dev/usb/usbcdc.h>
|
|
|
|
|
|
|
|
#include <dev/usb/usbdi.h>
|
|
|
|
#include <dev/usb/usbdi_util.h>
|
|
|
|
#include <dev/usb/usbdivar.h>
|
|
|
|
#include <dev/usb/usbdevs.h>
|
|
|
|
#include <dev/usb/usb_quirks.h>
|
|
|
|
|
|
|
|
#include <dev/usb/ucomvar.h>
|
|
|
|
#include <dev/usb/umodemvar.h>
|
|
|
|
#include <dev/usb/ukyopon.h>
|
|
|
|
|
|
|
|
#ifdef UKYOPON_DEBUG
|
|
|
|
#define DPRINTFN(n, x) if (ukyopondebug > (n)) logprintf x
|
|
|
|
int ukyopondebug = 0;
|
|
|
|
#else
|
|
|
|
#define DPRINTFN(n, x)
|
|
|
|
#endif
|
|
|
|
#define DPRINTF(x) DPRINTFN(0, x)
|
|
|
|
|
|
|
|
struct ukyopon_softc {
|
|
|
|
/* generic umodem device */
|
|
|
|
struct umodem_softc sc_umodem;
|
|
|
|
|
|
|
|
/* ukyopon addition */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define UKYOPON_MODEM_IFACE_INDEX 0
|
|
|
|
#define UKYOPON_DATA_IFACE_INDEX 3
|
|
|
|
|
2005-09-24 16:00:18 +04:00
|
|
|
Static void ukyopon_get_status(void *, int, u_char *, u_char *);
|
2007-03-04 08:59:00 +03:00
|
|
|
Static int ukyopon_ioctl(void *, int, u_long, void *, int, usb_proc_ptr);
|
2005-04-15 21:18:18 +04:00
|
|
|
|
|
|
|
Static struct ucom_methods ukyopon_methods = {
|
2005-09-24 16:00:18 +04:00
|
|
|
ukyopon_get_status,
|
2005-04-15 21:18:18 +04:00
|
|
|
umodem_set,
|
|
|
|
umodem_param,
|
|
|
|
ukyopon_ioctl,
|
|
|
|
umodem_open,
|
|
|
|
umodem_close,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
USB_DECLARE_DRIVER(ukyopon);
|
|
|
|
|
|
|
|
USB_MATCH(ukyopon)
|
|
|
|
{
|
Introduce different autoconf interface attributes for USB drivers
matching (and handling) a whole device and those which match an
interface only. This will allow to enforce some rules, eg that
the former don't use interface information for matching or that the
latter don't modify global device state.
The previous way left too much freedom do the drivers which led to
inconsistencies and abuse.
For now, I've not changed locators and submatch rules, this will
happen later.
There should not be any change in behaviour, except in the case of
some drivers which did behave inconsistently:
if_atu, if_axe, uep: matched the configured device in the interface
stage, but did configuration again. I've converted them to match
in the device stage.
ustir, utoppy: matched in the interface stage, but only against
vendor/device information, and used any configuration/interface
without checking. Changed to match in device stage, and added
some simple code to configure and use the first interface.
If you have one of those devices, please test!
2007-03-13 16:51:53 +03:00
|
|
|
USB_IFMATCH_START(ukyopon, uaa);
|
2005-04-15 21:18:18 +04:00
|
|
|
|
Introduce different autoconf interface attributes for USB drivers
matching (and handling) a whole device and those which match an
interface only. This will allow to enforce some rules, eg that
the former don't use interface information for matching or that the
latter don't modify global device state.
The previous way left too much freedom do the drivers which led to
inconsistencies and abuse.
For now, I've not changed locators and submatch rules, this will
happen later.
There should not be any change in behaviour, except in the case of
some drivers which did behave inconsistently:
if_atu, if_axe, uep: matched the configured device in the interface
stage, but did configuration again. I've converted them to match
in the device stage.
ustir, utoppy: matched in the interface stage, but only against
vendor/device information, and used any configuration/interface
without checking. Changed to match in device stage, and added
some simple code to configure and use the first interface.
If you have one of those devices, please test!
2007-03-13 16:51:53 +03:00
|
|
|
if (uaa->vendor == USB_VENDOR_KYOCERA &&
|
|
|
|
uaa->product == USB_PRODUCT_KYOCERA_AHK3001V &&
|
2005-04-15 21:18:18 +04:00
|
|
|
(uaa->ifaceno == UKYOPON_MODEM_IFACE_INDEX ||
|
|
|
|
uaa->ifaceno == UKYOPON_DATA_IFACE_INDEX))
|
|
|
|
return (UMATCH_VENDOR_PRODUCT);
|
|
|
|
|
|
|
|
return (UMATCH_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
USB_ATTACH(ukyopon)
|
|
|
|
{
|
Introduce different autoconf interface attributes for USB drivers
matching (and handling) a whole device and those which match an
interface only. This will allow to enforce some rules, eg that
the former don't use interface information for matching or that the
latter don't modify global device state.
The previous way left too much freedom do the drivers which led to
inconsistencies and abuse.
For now, I've not changed locators and submatch rules, this will
happen later.
There should not be any change in behaviour, except in the case of
some drivers which did behave inconsistently:
if_atu, if_axe, uep: matched the configured device in the interface
stage, but did configuration again. I've converted them to match
in the device stage.
ustir, utoppy: matched in the interface stage, but only against
vendor/device information, and used any configuration/interface
without checking. Changed to match in device stage, and added
some simple code to configure and use the first interface.
If you have one of those devices, please test!
2007-03-13 16:51:53 +03:00
|
|
|
USB_IFATTACH_START(ukyopon, sc, uaa);
|
2005-04-15 21:18:18 +04:00
|
|
|
struct ucom_attach_args uca;
|
|
|
|
|
2005-09-24 15:50:25 +04:00
|
|
|
uca.portno = (uaa->ifaceno == UKYOPON_MODEM_IFACE_INDEX) ?
|
2005-04-15 21:18:18 +04:00
|
|
|
UKYOPON_PORT_MODEM : UKYOPON_PORT_DATA;
|
|
|
|
uca.methods = &ukyopon_methods;
|
|
|
|
uca.info = (uaa->ifaceno == UKYOPON_MODEM_IFACE_INDEX) ?
|
|
|
|
"modem port" : "data transfer port";
|
|
|
|
|
|
|
|
if (umodem_common_attach(self, &sc->sc_umodem, uaa, &uca))
|
|
|
|
USB_ATTACH_ERROR_RETURN;
|
|
|
|
USB_ATTACH_SUCCESS_RETURN;
|
|
|
|
}
|
|
|
|
|
2005-09-24 16:00:18 +04:00
|
|
|
Static void
|
|
|
|
ukyopon_get_status(void *addr, int portno, u_char *lsr, u_char *msr)
|
|
|
|
{
|
|
|
|
struct ukyopon_softc *sc = addr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The device doesn't set DCD (Data Carrier Detect) bit properly.
|
|
|
|
* Assume DCD is always present.
|
|
|
|
*/
|
|
|
|
if ((sc->sc_umodem.sc_msr & UMSR_DCD) == 0)
|
|
|
|
sc->sc_umodem.sc_msr |= UMSR_DCD;
|
|
|
|
|
|
|
|
return umodem_get_status(addr, portno, lsr, msr);
|
|
|
|
}
|
|
|
|
|
2005-04-15 21:18:18 +04:00
|
|
|
Static int
|
2007-03-04 08:59:00 +03:00
|
|
|
ukyopon_ioctl(void *addr, int portno, u_long cmd, void *data, int flag,
|
2005-04-15 21:18:18 +04:00
|
|
|
usb_proc_ptr p)
|
|
|
|
{
|
|
|
|
struct ukyopon_softc *sc = addr;
|
|
|
|
struct ukyopon_identify *arg_id = (void*)data;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case UKYOPON_IDENTIFY:
|
|
|
|
strncpy(arg_id->ui_name, UKYOPON_NAME, sizeof arg_id->ui_name);
|
|
|
|
arg_id->ui_busno =
|
|
|
|
USBDEVUNIT(*(device_ptr_t)sc->sc_umodem.sc_udev->bus->usbctl);
|
|
|
|
arg_id->ui_address = sc->sc_umodem.sc_udev->address;
|
|
|
|
arg_id->ui_model = UKYOPON_MODEL_UNKNOWN;
|
2005-09-24 15:50:25 +04:00
|
|
|
arg_id->ui_porttype = portno;
|
2005-04-15 21:18:18 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = umodem_ioctl(addr, portno, cmd, data, flag, p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __strong_alias
|
|
|
|
__strong_alias(ukyopon_activate,umodem_common_activate)
|
|
|
|
#else
|
|
|
|
int
|
|
|
|
ukyopon_activate(device_ptr_t self, enum devact act)
|
|
|
|
{
|
|
|
|
struct ukyopon_softc *sc = (struct ukyopon_softc *)self;
|
|
|
|
|
|
|
|
return umodem_common_activate(&sc->sc_umodem, act);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
USB_DETACH(ukyopon)
|
|
|
|
{
|
|
|
|
USB_DETACH_START(ukyopon, sc);
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
int flags = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return umodem_common_detach(&sc->sc_umodem, flags);
|
|
|
|
}
|