Commit 5ab9c049 authored by Dave Jones's avatar Dave Jones

[PATCH] sonypi driver update from 2.4

parent 94a0b03c
...@@ -25,7 +25,8 @@ A simple daemon which translates the jogdial movements into mouse wheel events ...@@ -25,7 +25,8 @@ A simple daemon which translates the jogdial movements into mouse wheel events
can be downloaded at: <http://www.alcove-labs.org/en/software/sonypi/> can be downloaded at: <http://www.alcove-labs.org/en/software/sonypi/>
This driver supports also some ioctl commands for setting the LCD screen This driver supports also some ioctl commands for setting the LCD screen
brightness (some more commands may be added in the future). brightness and querying the batteries charge information (some more
commands may be added in the future).
This driver can also be used to set the camera controls on Picturebook series This driver can also be used to set the camera controls on Picturebook series
(brightness, contrast etc), and is used by the video4linux driver for the (brightness, contrast etc), and is used by the video4linux driver for the
......
...@@ -109,25 +109,29 @@ static inline int sonypi_emptyq(void) { ...@@ -109,25 +109,29 @@ static inline int sonypi_emptyq(void) {
return result; return result;
} }
static void sonypi_ecrset(u16 addr, u16 value) { static void sonypi_ecrset(u8 addr, u8 value) {
wait_on_command(1, inw_p(SONYPI_CST_IOPORT) & 3); wait_on_command(1, inb_p(SONYPI_CST_IOPORT) & 3);
outw_p(0x81, SONYPI_CST_IOPORT); outb_p(0x81, SONYPI_CST_IOPORT);
wait_on_command(0, inw_p(SONYPI_CST_IOPORT) & 2); wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2);
outw_p(addr, SONYPI_DATA_IOPORT); outb_p(addr, SONYPI_DATA_IOPORT);
wait_on_command(0, inw_p(SONYPI_CST_IOPORT) & 2); wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2);
outw_p(value, SONYPI_DATA_IOPORT); outb_p(value, SONYPI_DATA_IOPORT);
wait_on_command(0, inw_p(SONYPI_CST_IOPORT) & 2); wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2);
} }
static u16 sonypi_ecrget(u16 addr) { static u8 sonypi_ecrget(u8 addr) {
wait_on_command(1, inb_p(SONYPI_CST_IOPORT) & 3);
outb_p(0x80, SONYPI_CST_IOPORT);
wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2);
outb_p(addr, SONYPI_DATA_IOPORT);
wait_on_command(0, inb_p(SONYPI_CST_IOPORT) & 2);
return inb_p(SONYPI_DATA_IOPORT);
}
wait_on_command(1, inw_p(SONYPI_CST_IOPORT) & 3); static u16 sonypi_ecrget16(u8 addr) {
outw_p(0x80, SONYPI_CST_IOPORT); return sonypi_ecrget(addr) | (sonypi_ecrget(addr + 1) << 8);
wait_on_command(0, inw_p(SONYPI_CST_IOPORT) & 2);
outw_p(addr, SONYPI_DATA_IOPORT);
wait_on_command(0, inw_p(SONYPI_CST_IOPORT) & 2);
return inw_p(SONYPI_DATA_IOPORT);
} }
/* Initializes the device - this comes from the AML code in the ACPI bios */ /* Initializes the device - this comes from the AML code in the ACPI bios */
...@@ -286,19 +290,38 @@ static void sonypi_camera_on(void) { ...@@ -286,19 +290,38 @@ static void sonypi_camera_on(void) {
sonypi_device.camera_power = 1; sonypi_device.camera_power = 1;
} }
/* sets the bluetooth subsystem power state */
static void sonypi_setbluetoothpower(u8 state) {
state = (state != 0);
if (sonypi_device.bluetooth_power && state)
return;
if (!sonypi_device.bluetooth_power && !state)
return;
sonypi_call2(0x96, state);
sonypi_call1(0x93);
sonypi_device.bluetooth_power = state;
}
/* Interrupt handler: some event is available */ /* Interrupt handler: some event is available */
void sonypi_irq(int irq, void *dev_id, struct pt_regs *regs) { void sonypi_irq(int irq, void *dev_id, struct pt_regs *regs) {
u8 v1, v2, event = 0; u8 v1, v2, event = 0;
int i; int i;
u8 sonypi_jogger_ev, sonypi_fnkey_ev; u8 sonypi_jogger_ev, sonypi_fnkey_ev;
u8 sonypi_capture_ev, sonypi_bluetooth_ev;
if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2) { if (sonypi_device.model == SONYPI_DEVICE_MODEL_TYPE2) {
sonypi_jogger_ev = SONYPI_TYPE2_JOGGER_EV; sonypi_jogger_ev = SONYPI_TYPE2_JOGGER_EV;
sonypi_fnkey_ev = SONYPI_TYPE2_FNKEY_EV; sonypi_fnkey_ev = SONYPI_TYPE2_FNKEY_EV;
sonypi_capture_ev = SONYPI_TYPE2_CAPTURE_EV;
sonypi_bluetooth_ev = SONYPI_TYPE2_BLUETOOTH_EV;
} }
else { else {
sonypi_jogger_ev = SONYPI_TYPE1_JOGGER_EV; sonypi_jogger_ev = SONYPI_TYPE1_JOGGER_EV;
sonypi_fnkey_ev = SONYPI_TYPE1_FNKEY_EV; sonypi_fnkey_ev = SONYPI_TYPE1_FNKEY_EV;
sonypi_capture_ev = SONYPI_TYPE1_CAPTURE_EV;
sonypi_bluetooth_ev = SONYPI_TYPE1_BLUETOOTH_EV;
} }
v1 = inb_p(sonypi_device.ioport1); v1 = inb_p(sonypi_device.ioport1);
...@@ -318,7 +341,7 @@ void sonypi_irq(int irq, void *dev_id, struct pt_regs *regs) { ...@@ -318,7 +341,7 @@ void sonypi_irq(int irq, void *dev_id, struct pt_regs *regs) {
goto found; goto found;
} }
} }
if ((v2 & SONYPI_CAPTURE_EV) == SONYPI_CAPTURE_EV) { if ((v2 & sonypi_capture_ev) == sonypi_capture_ev) {
for (i = 0; sonypi_captureev[i].event; i++) for (i = 0; sonypi_captureev[i].event; i++)
if (sonypi_captureev[i].data == v1) { if (sonypi_captureev[i].data == v1) {
event = sonypi_captureev[i].event; event = sonypi_captureev[i].event;
...@@ -332,7 +355,7 @@ void sonypi_irq(int irq, void *dev_id, struct pt_regs *regs) { ...@@ -332,7 +355,7 @@ void sonypi_irq(int irq, void *dev_id, struct pt_regs *regs) {
goto found; goto found;
} }
} }
if ((v2 & SONYPI_BLUETOOTH_EV) == SONYPI_BLUETOOTH_EV) { if ((v2 & sonypi_bluetooth_ev) == sonypi_bluetooth_ev) {
for (i = 0; sonypi_blueev[i].event; i++) for (i = 0; sonypi_blueev[i].event; i++)
if (sonypi_blueev[i].data == v1) { if (sonypi_blueev[i].data == v1) {
event = sonypi_blueev[i].event; event = sonypi_blueev[i].event;
...@@ -510,23 +533,73 @@ static unsigned int sonypi_misc_poll(struct file *file, poll_table * wait) { ...@@ -510,23 +533,73 @@ static unsigned int sonypi_misc_poll(struct file *file, poll_table * wait) {
static int sonypi_misc_ioctl(struct inode *ip, struct file *fp, static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
unsigned int cmd, unsigned long arg) { unsigned int cmd, unsigned long arg) {
int ret = 0; int ret = 0;
u8 val; u8 val8;
u16 val16;
down(&sonypi_device.lock); down(&sonypi_device.lock);
switch (cmd) { switch (cmd) {
case SONYPI_IOCGBRT: case SONYPI_IOCGBRT:
val = sonypi_ecrget(0x96) & 0xff; val8 = sonypi_ecrget(0x96);
if (copy_to_user((u8 *)arg, &val, sizeof(val))) { if (copy_to_user((u8 *)arg, &val8, sizeof(val8))) {
ret = -EFAULT; ret = -EFAULT;
goto out; goto out;
} }
break; break;
case SONYPI_IOCSBRT: case SONYPI_IOCSBRT:
if (copy_from_user(&val, (u8 *)arg, sizeof(val))) { if (copy_from_user(&val8, (u8 *)arg, sizeof(val8))) {
ret = -EFAULT;
goto out;
}
sonypi_ecrset(0x96, val8);
break;
case SONYPI_IOCGBAT1CAP:
val16 = sonypi_ecrget16(0xb2);
if (copy_to_user((u16 *)arg, &val16, sizeof(val16))) {
ret = -EFAULT;
goto out;
}
break;
case SONYPI_IOCGBAT1REM:
val16 = sonypi_ecrget16(0xa2);
if (copy_to_user((u16 *)arg, &val16, sizeof(val16))) {
ret = -EFAULT;
goto out;
}
break;
case SONYPI_IOCGBAT2CAP:
val16 = sonypi_ecrget16(0xba);
if (copy_to_user((u16 *)arg, &val16, sizeof(val16))) {
ret = -EFAULT;
goto out;
}
break;
case SONYPI_IOCGBAT2REM:
val16 = sonypi_ecrget16(0xaa);
if (copy_to_user((u16 *)arg, &val16, sizeof(val16))) {
ret = -EFAULT;
goto out;
}
break;
case SONYPI_IOCGBATFLAGS:
val8 = sonypi_ecrget(0x81) & 0x07;
if (copy_to_user((u8 *)arg, &val8, sizeof(val8))) {
ret = -EFAULT;
goto out;
}
break;
case SONYPI_IOCGBLUE:
val8 = sonypi_device.bluetooth_power;
if (copy_to_user((u8 *)arg, &val8, sizeof(val8))) {
ret = -EFAULT;
goto out;
}
break;
case SONYPI_IOCSBLUE:
if (copy_from_user(&val8, (u8 *)arg, sizeof(val8))) {
ret = -EFAULT; ret = -EFAULT;
goto out; goto out;
} }
sonypi_ecrset(0x96, val); sonypi_setbluetoothpower(val8);
break; break;
default: default:
ret = -EINVAL; ret = -EINVAL;
...@@ -562,6 +635,7 @@ static int __devinit sonypi_probe(struct pci_dev *pcidev) { ...@@ -562,6 +635,7 @@ static int __devinit sonypi_probe(struct pci_dev *pcidev) {
sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE2; sonypi_device.model = SONYPI_DEVICE_MODEL_TYPE2;
sonypi_initq(); sonypi_initq();
init_MUTEX(&sonypi_device.lock); init_MUTEX(&sonypi_device.lock);
sonypi_device.bluetooth_power = 0;
if (pcidev && pci_enable_device(pcidev)) { if (pcidev && pci_enable_device(pcidev)) {
printk(KERN_ERR "sonypi: pci_enable_device failed\n"); printk(KERN_ERR "sonypi: pci_enable_device failed\n");
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#ifdef __KERNEL__ #ifdef __KERNEL__
#define SONYPI_DRIVER_MAJORVERSION 1 #define SONYPI_DRIVER_MAJORVERSION 1
#define SONYPI_DRIVER_MINORVERSION 8 #define SONYPI_DRIVER_MINORVERSION 10
#include <linux/types.h> #include <linux/types.h>
#include <linux/pci.h> #include <linux/pci.h>
...@@ -134,10 +134,12 @@ static struct sonypi_irq_list sonypi_type2_irq_list[] = { ...@@ -134,10 +134,12 @@ static struct sonypi_irq_list sonypi_type2_irq_list[] = {
/* key press event data (ioport2) */ /* key press event data (ioport2) */
#define SONYPI_TYPE1_JOGGER_EV 0x10 #define SONYPI_TYPE1_JOGGER_EV 0x10
#define SONYPI_TYPE2_JOGGER_EV 0x08 #define SONYPI_TYPE2_JOGGER_EV 0x08
#define SONYPI_CAPTURE_EV 0x60 #define SONYPI_TYPE1_CAPTURE_EV 0x60
#define SONYPI_TYPE2_CAPTURE_EV 0x08
#define SONYPI_TYPE1_FNKEY_EV 0x20 #define SONYPI_TYPE1_FNKEY_EV 0x20
#define SONYPI_TYPE2_FNKEY_EV 0x08 #define SONYPI_TYPE2_FNKEY_EV 0x08
#define SONYPI_BLUETOOTH_EV 0x30 #define SONYPI_TYPE1_BLUETOOTH_EV 0x30
#define SONYPI_TYPE2_BLUETOOTH_EV 0x08
#define SONYPI_TYPE1_PKEY_EV 0x40 #define SONYPI_TYPE1_PKEY_EV 0x40
#define SONYPI_BACK_EV 0x08 #define SONYPI_BACK_EV 0x08
#define SONYPI_LID_EV 0x38 #define SONYPI_LID_EV 0x38
...@@ -203,6 +205,8 @@ static struct sonypi_event sonypi_pkeyev[] = { ...@@ -203,6 +205,8 @@ static struct sonypi_event sonypi_pkeyev[] = {
/* The set of possible bluetooth events */ /* The set of possible bluetooth events */
static struct sonypi_event sonypi_blueev[] = { static struct sonypi_event sonypi_blueev[] = {
{ 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED }, { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED },
{ 0x59, SONYPI_EVENT_BLUETOOTH_ON },
{ 0x5a, SONYPI_EVENT_BLUETOOTH_OFF },
{ 0x00, 0x00 } { 0x00, 0x00 }
}; };
...@@ -241,6 +245,7 @@ struct sonypi_device { ...@@ -241,6 +245,7 @@ struct sonypi_device {
u16 ioport2; u16 ioport2;
u16 region_size; u16 region_size;
int camera_power; int camera_power;
int bluetooth_power;
struct semaphore lock; struct semaphore lock;
struct sonypi_queue queue; struct sonypi_queue queue;
int open_count; int open_count;
......
...@@ -73,12 +73,29 @@ ...@@ -73,12 +73,29 @@
#define SONYPI_EVENT_BACK_PRESSED 35 #define SONYPI_EVENT_BACK_PRESSED 35
#define SONYPI_EVENT_LID_CLOSED 36 #define SONYPI_EVENT_LID_CLOSED 36
#define SONYPI_EVENT_LID_OPENED 37 #define SONYPI_EVENT_LID_OPENED 37
#define SONYPI_EVENT_BLUETOOTH_ON 38
#define SONYPI_EVENT_BLUETOOTH_OFF 39
/* get/set brightness */
/* brightness etc. ioctls */
#define SONYPI_IOCGBRT _IOR('v', 0, __u8) #define SONYPI_IOCGBRT _IOR('v', 0, __u8)
#define SONYPI_IOCSBRT _IOW('v', 0, __u8) #define SONYPI_IOCSBRT _IOW('v', 0, __u8)
/* get battery full capacity/remaining capacity */
#define SONYPI_IOCGBAT1CAP _IOR('v', 2, __u16)
#define SONYPI_IOCGBAT1REM _IOR('v', 3, __u16)
#define SONYPI_IOCGBAT2CAP _IOR('v', 4, __u16)
#define SONYPI_IOCGBAT2REM _IOR('v', 5, __u16)
/* get battery flags: battery1/battery2/ac adapter present */
#define SONYPI_BFLAGS_B1 0x01
#define SONYPI_BFLAGS_B2 0x02
#define SONYPI_BFLAGS_AC 0x04
#define SONYPI_IOCGBATFLAGS _IOR('v', 7, __u8)
/* get/set bluetooth subsystem state on/off */
#define SONYPI_IOCGBLUE _IOR('v', 8, __u8)
#define SONYPI_IOCSBLUE _IOW('v', 9, __u8)
#ifdef __KERNEL__ #ifdef __KERNEL__
/* used only for communication between v4l and sonypi */ /* used only for communication between v4l and sonypi */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment