Re: Sony jog dial driver

2000-12-10 Thread Nick Sayer



On Sun, 10 Dec 2000, Michael C . Wu wrote:

> On Sun, Dec 10, 2000 at 03:19:06PM -0800, Nick Sayer scribbled:
> | Attached is a preliminary driver for the Sony jog dial. It's enough that
> | you can create a /dev/jogdial and watch letters come out.
> 
> W00t! :)  You did it!  How did you wrestle documentation out of 
> Sony? (or did you ever?)  If you managed to get a Sony contact,
> can I contact him too?

Nope. I have Andrew Tridge and Ian Dowse to thank jointly for sample code
that went into it. I am inclined to split the US$100 prize between them.

> 
> | It needs a lot of improvement:
> | 1. Use interrupts instead of polling.
> | 2. Present mouse-oriented events instead of letters.
> 
> I recall you talking about the Fn+LCD brightness and such to 
> be controlled by the same controller also.  Do you have any work in that area?

No, I'm afraid not.

> 
> 
> IMHO, we should have:
> scroll up/down : mouse 4 and 5 (just like mouse wheel)
> press down while scrolling up/down : mixer vol +/-
> press down one time : mouse middle paste

Those are tasks best done in userspace. The driver's job is simply to
report the events. My immediate task is now to have it do that reporting
in a moused compatible way.

> 
> | 3. Fix the probe routine so that it tries to detect the presence of the
> | device rather than the magic 0x10a0 port location.
> | 
> | 4. Eventual ACPIification of the driver.
> | 
> | 5. Create a 2nd device to deal with other devices like the lid switch,
> | capture button, etc.
> | 
> | But I wanted to get this much out there for people to play with.
> 
> I'll test this tonight. :)
> 



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message



Re: Sony jog dial driver

2000-12-10 Thread Michael C . Wu

On Sun, Dec 10, 2000 at 06:44:45PM -0600, Michael C . Wu scribbled:
Oops, nevermind my questions about contacts and Fn+* functions,
should have read the code before I reply. :)
-- 
+--+
| [EMAIL PROTECTED] | [EMAIL PROTECTED] |
| http://peorth.iteration.net/~keichii | Yes, BSD is a conspiracy. |
+--+


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message



Re: Sony jog dial driver

2000-12-10 Thread Michael C . Wu

On Sun, Dec 10, 2000 at 03:19:06PM -0800, Nick Sayer scribbled:
| Attached is a preliminary driver for the Sony jog dial. It's enough that
| you can create a /dev/jogdial and watch letters come out.

W00t! :)  You did it!  How did you wrestle documentation out of 
Sony? (or did you ever?)  If you managed to get a Sony contact,
can I contact him too?

| It needs a lot of improvement:
| 1. Use interrupts instead of polling.
| 2. Present mouse-oriented events instead of letters.

I recall you talking about the Fn+LCD brightness and such to 
be controlled by the same controller also.  Do you have any work in that area?


IMHO, we should have:
scroll up/down : mouse 4 and 5 (just like mouse wheel)
press down while scrolling up/down : mixer vol +/-
press down one time : mouse middle paste

| 3. Fix the probe routine so that it tries to detect the presence of the
| device rather than the magic 0x10a0 port location.
| 
| 4. Eventual ACPIification of the driver.
| 
| 5. Create a 2nd device to deal with other devices like the lid switch,
| capture button, etc.
| 
| But I wanted to get this much out there for people to play with.

I'll test this tonight. :)
-- 
+--+
| [EMAIL PROTECTED] | [EMAIL PROTECTED] |
| http://peorth.iteration.net/~keichii | Yes, BSD is a conspiracy. |
+--+


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message



Sony jog dial driver

2000-12-10 Thread Nick Sayer

Attached is a preliminary driver for the Sony jog dial. It's enough that
you can create a /dev/jogdial and watch letters come out.

It needs a lot of improvement:

1. Use interrupts instead of polling.

2. Present mouse-oriented events instead of letters.

3. Fix the probe routine so that it tries to detect the presence of the
device rather than the magic 0x10a0 port location.

4. Eventual ACPIification of the driver.

5. Create a 2nd device to deal with other devices like the lid switch,
capture button, etc.

But I wanted to get this much out there for people to play with.



/*
 * Insert standard FreeBSD Copyright notice here
 *
 * spic -- the Sony Programmable I/O Controller
 *
 * This device exists on most recent Sony laptops. It is the means by which
 * you can watch the Jog Dial and some other functions.
 *
 * At the moment, this driver merely tries to turn the jog dial into a
 * device that moused can park on, with the intent of supplying a Z axis
 * and mouse button out of the jog dial. I suspect that this device will
 * end up having to support at least 2 different minor devices: One to be
 * the jog wheel device for moused to camp out on and the other to perform
 * all of the other miscelaneous functions of this device. But for now,
 * the jog wheel is all you get.
 *
 * What documentation exists is thanks to Andrew Tridge, and his page at
 * http://samba.org/picturebook/
 *
 * $FreeBSD$
 */

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include 

static int spic_pollrate;

SYSCTL_INT(_machdep, OID_AUTO, spic_pollrate, CTLFLAG_RW, &spic_pollrate, 0, "")
;

devclass_t spic_devclass;

static d_open_t spicopen;
static d_close_tspicclose;
static d_read_t spicread;
static d_ioctl_tspicioctl;
static d_poll_t spicpoll;

static struct cdevsw spic_cdevsw = {
/* open */  spicopen,
/* close */ spicclose,
/* read */  spicread,
/* write */ nowrite,
/* ioctl */ spicioctl,
/* poll */  spicpoll,
/* mmap */  nommap,
/* strategy */  nostrategy,
/* name */  "spic",
/* maj */   CDEV_MAJOR,
/* dump */  nodump,
/* psize */ nopsize,
/* flags */ 0,
/* bmaj */  -1
};

#define SCBUFLEN 128

struct spic_softc {
u_short sc_port_addr;
u_char sc_intr;
struct resource *sc_port_res,*sc_intr_res;
int sc_port_rid,sc_intr_rid;
int sc_opened;
int sc_sleeping;
int sc_buttonlast;
struct callout_handle sc_timeout_ch;
device_t sc_dev;
struct selinfo sc_rsel;
u_char sc_buf[SCBUFLEN];
int sc_count;
};

static void
write_port1(struct spic_softc *sc, u_char val)
{
DELAY(10);
outb(sc->sc_port_addr, val);
}

static void
write_port2(struct spic_softc *sc, u_char val)
{
DELAY(10);
outb(sc->sc_port_addr + 4, val);
}

static u_char
read_port1(struct spic_softc *sc)
{
DELAY(10);
return inb(sc->sc_port_addr);
}

static u_char
read_port2(struct spic_softc *sc)
{
DELAY(10);
return inb(sc->sc_port_addr + 4);
}

static void
busy_wait(struct spic_softc *sc)
{
int i=0;

while(read_port2(sc) & 2) {
DELAY(10);
if (i++>1) {
printf("spic busy wait abort\n");
return;
}
}
}

static u_char
spic_call1(struct spic_softc *sc, u_char dev) {
busy_wait(sc);
write_port2(sc, dev);
read_port2(sc);
return read_port1(sc);
}

static u_char
spic_call2(struct spic_softc *sc, u_char dev, u_char fn)
{
busy_wait(sc);
write_port2(sc, dev);
busy_wait(sc);
write_port1(sc, fn);
return read_port1(sc);
}

static int
spic_probe(device_t dev)
{
struct spic_softc *sc;
u_char t, spic_irq;

sc = device_get_softc(dev);

bzero(sc, sizeof(struct spic_softc));

if (!(sc->sc_port_res = bus_alloc_resource(dev, SYS_RES_IOPORT,
&sc->sc_port_rid, 0, ~0, 5, RF_ACTIVE))) {
device_printf(dev,"Couldn't map I/O\n");
return ENXIO;
}
sc->sc_port_addr = (u_short)rman_get_start(sc->sc_port_res);

if (!(sc->sc_intr_res = bus_alloc_resource(dev, SYS_RES_IRQ,
&sc->sc_intr_rid, 0, ~0, 1, RF_ACTIVE))) {
device_printf(dev,"Couldn't map IRQ\n");
bus_release_resource(dev, SYS_RES_IOPORT,
sc->sc_port_rid, sc->sc_port_res);
return ENXIO;
}
sc->s