/*-
* Copyright (c) 2005 HAMAJIMA Katsuomi. All rights reserved.
*
* 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 AUTHOR 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 AUTHOR 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.
*/
struct optpoint_softc {
device_t sc_dev;
tx_chipset_tag_t sc_tc;
struct tx39spi_softc *sc_spi;
struct hpcio_chip *sc_hc;
device_t sc_wsmousedev;
void *sc_powerhook; /* power management hook */
char packet[4];
int index; /* number of bytes received for this packet */
u_int buttons; /* mouse button status */
int enabled;
};
static int optpoint_match(device_t, cfdata_t, void *);
static void optpoint_attach(device_t, device_t, void *);
static int optpoint_intr(void *);
static int optpoint_enable(void *);
static void optpoint_disable(void *);
static int optpoint_ioctl(void *, u_long, void *, int, struct lwp *);
static int optpoint_initialize(void *);
static void optpoint_send(struct optpoint_softc *, int);
static int optpoint_recv(struct optpoint_softc *);
static int optpoint_power(void *, int, long, void *);
/* Add a hard power hook to power saving */
sc->sc_powerhook = config_hook(CONFIG_HOOK_PMEVENT,
CONFIG_HOOK_PMEVENT_HARDPOWER,
CONFIG_HOOK_SHARE,
optpoint_power, sc);
#ifdef DIAGNOSTIC
if (sc->sc_powerhook == 0)
printf("%s: unable to establish hard power hook",
device_xname(sc->sc_dev));
#endif
}
int
optpoint_intr(void *arg)
{
struct optpoint_softc *sc = arg;
tx_chipset_tag_t tc = sc->sc_tc;
char data = optpoint_recv(sc) & 0xff;
int
optpoint_power(void *arg, int type, long id, void *msg)
{
struct optpoint_softc *sc = arg;
int why = (int)msg;
switch (why) {
case PWR_RESUME:
/* power on */
optpoint_enable(sc);
break;
case PWR_SUSPEND:
/* FALLTHROUGH */
case PWR_STANDBY:
/* power off */
optpoint_disable(sc);
break;
}