aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLen Brown <len.brown@intel.com>2007-04-28 23:09:57 -0400
committerLen Brown <len.brown@intel.com>2007-04-28 23:09:57 -0400
commitcfaae3ee4a0d00c6b22780057e958d625499e90c (patch)
treec9be12f3657a7f5ac7c7d45589f2e1592479ac0e
parenteaf60d6924759eb2a249c0b568533a90c238061b (diff)
parentc6c60106b9584f17c55e4c5e0ce9b905a1a6cdb6 (diff)
Pull sony into release branch
-rw-r--r--Documentation/sony-laptop.txt25
-rw-r--r--Documentation/video4linux/meye.txt7
-rw-r--r--drivers/char/sonypi.c53
-rw-r--r--drivers/media/video/Kconfig6
-rw-r--r--drivers/media/video/meye.c62
-rw-r--r--drivers/media/video/meye.h2
-rw-r--r--drivers/misc/Kconfig15
-rw-r--r--drivers/misc/sony-laptop.c2131
-rw-r--r--include/linux/sony-laptop.h34
9 files changed, 2072 insertions, 263 deletions
diff --git a/Documentation/sony-laptop.txt b/Documentation/sony-laptop.txt
index dfd26df056f4..7a5c1a81905c 100644
--- a/Documentation/sony-laptop.txt
+++ b/Documentation/sony-laptop.txt
@@ -3,12 +3,18 @@ Sony Notebook Control Driver (SNC) Readme
3 Copyright (C) 2004- 2005 Stelian Pop <stelian@popies.net> 3 Copyright (C) 2004- 2005 Stelian Pop <stelian@popies.net>
4 Copyright (C) 2007 Mattia Dongili <malattia@linux.it> 4 Copyright (C) 2007 Mattia Dongili <malattia@linux.it>
5 5
6This mini-driver drives the SNC device present in the ACPI BIOS of 6This mini-driver drives the SNC and SPIC device present in the ACPI BIOS of the
7the Sony Vaio laptops. 7Sony Vaio laptops. This driver mixes both devices functions under the same
8(hopefully consistent) interface. This also means that the sonypi driver is
9obsoleted by sony-laptop now.
8 10
9It gives access to some extra laptop functionalities. In its current 11Fn keys (hotkeys):
10form, this driver let the user set or query the screen brightness 12------------------
11through the backlight subsystem and remove/apply power to some devices. 13Some models report hotkeys through the SNC or SPIC devices, such events are
14reported both through the ACPI subsystem as acpi events and through the INPUT
15subsystem. See the logs of acpid or /proc/acpi/event and
16/proc/bus/input/devices to find out what those events are and which input
17devices are created by the driver.
12 18
13Backlight control: 19Backlight control:
14------------------ 20------------------
@@ -39,6 +45,8 @@ The files are:
39 audiopower power on/off the internal sound card 45 audiopower power on/off the internal sound card
40 lanpower power on/off the internal ethernet card 46 lanpower power on/off the internal ethernet card
41 (only in debug mode) 47 (only in debug mode)
48 bluetoothpower power on/off the internal bluetooth device
49 fanspeed get/set the fan speed
42 50
43Note that some files may be missing if they are not supported 51Note that some files may be missing if they are not supported
44by your particular laptop model. 52by your particular laptop model.
@@ -76,9 +84,9 @@ The sony-laptop driver creates, for some of those methods (the most
76current ones found on several Vaio models), an entry under 84current ones found on several Vaio models), an entry under
77/sys/devices/platform/sony-laptop, just like the 'cdpower' one. 85/sys/devices/platform/sony-laptop, just like the 'cdpower' one.
78You can create other entries corresponding to your own laptop methods by 86You can create other entries corresponding to your own laptop methods by
79further editing the source (see the 'sony_acpi_values' table, and add a new 87further editing the source (see the 'sony_nc_values' table, and add a new
80entry to this table with your get/set method names using the 88entry to this table with your get/set method names using the
81HANDLE_NAMES macro). 89SNC_HANDLE_NAMES macro).
82 90
83Your mission, should you accept it, is to try finding out what 91Your mission, should you accept it, is to try finding out what
84those entries are for, by reading/writing random values from/to those 92those entries are for, by reading/writing random values from/to those
@@ -87,6 +95,9 @@ files and find out what is the impact on your laptop.
87Should you find anything interesting, please report it back to me, 95Should you find anything interesting, please report it back to me,
88I will not disavow all knowledge of your actions :) 96I will not disavow all knowledge of your actions :)
89 97
98See also http://www.linux.it/~malattia/wiki/index.php/Sony_drivers for other
99useful info.
100
90Bugs/Limitations: 101Bugs/Limitations:
91----------------- 102-----------------
92 103
diff --git a/Documentation/video4linux/meye.txt b/Documentation/video4linux/meye.txt
index ecb34160e61d..5e51c59bf2b0 100644
--- a/Documentation/video4linux/meye.txt
+++ b/Documentation/video4linux/meye.txt
@@ -5,10 +5,9 @@ Vaio Picturebook Motion Eye Camera Driver Readme
5 Copyright (C) 2000 Andrew Tridgell <tridge@samba.org> 5 Copyright (C) 2000 Andrew Tridgell <tridge@samba.org>
6 6
7This driver enable the use of video4linux compatible applications with the 7This driver enable the use of video4linux compatible applications with the
8Motion Eye camera. This driver requires the "Sony Vaio Programmable I/O 8Motion Eye camera. This driver requires the "Sony Laptop Extras" driver (which
9Control Device" driver (which can be found in the "Character drivers" 9can be found in the "Misc devices" section of the kernel configuration utility)
10section of the kernel configuration utility) to be compiled and installed 10to be compiled and installed (using its "camera=1" parameter).
11(using its "camera=1" parameter).
12 11
13It can do at maximum 30 fps @ 320x240 or 15 fps @ 640x480. 12It can do at maximum 30 fps @ 320x240 or 15 fps @ 640x480.
14 13
diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
index 78237577b05a..3ef593a9015f 100644
--- a/drivers/char/sonypi.c
+++ b/drivers/char/sonypi.c
@@ -1,6 +1,8 @@
1/* 1/*
2 * Sony Programmable I/O Control Device driver for VAIO 2 * Sony Programmable I/O Control Device driver for VAIO
3 * 3 *
4 * Copyright (C) 2007 Mattia Dongili <malattia@linux.it>
5 *
4 * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net> 6 * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net>
5 * 7 *
6 * Copyright (C) 2005 Narayanan R S <nars@kadamba.org> 8 * Copyright (C) 2005 Narayanan R S <nars@kadamba.org>
@@ -95,6 +97,11 @@ module_param(useinput, int, 0444);
95MODULE_PARM_DESC(useinput, 97MODULE_PARM_DESC(useinput,
96 "set this if you would like sonypi to feed events to the input subsystem"); 98 "set this if you would like sonypi to feed events to the input subsystem");
97 99
100static int check_ioport = 1;
101module_param(check_ioport, int, 0444);
102MODULE_PARM_DESC(check_ioport,
103 "set this to 0 if you think the automatic ioport check for sony-laptop is wrong");
104
98#define SONYPI_DEVICE_MODEL_TYPE1 1 105#define SONYPI_DEVICE_MODEL_TYPE1 1
99#define SONYPI_DEVICE_MODEL_TYPE2 2 106#define SONYPI_DEVICE_MODEL_TYPE2 2
100#define SONYPI_DEVICE_MODEL_TYPE3 3 107#define SONYPI_DEVICE_MODEL_TYPE3 3
@@ -477,7 +484,7 @@ static struct sonypi_device {
477 u16 evtype_offset; 484 u16 evtype_offset;
478 int camera_power; 485 int camera_power;
479 int bluetooth_power; 486 int bluetooth_power;
480 struct semaphore lock; 487 struct mutex lock;
481 struct kfifo *fifo; 488 struct kfifo *fifo;
482 spinlock_t fifo_lock; 489 spinlock_t fifo_lock;
483 wait_queue_head_t fifo_proc_list; 490 wait_queue_head_t fifo_proc_list;
@@ -884,7 +891,7 @@ int sonypi_camera_command(int command, u8 value)
884 if (!camera) 891 if (!camera)
885 return -EIO; 892 return -EIO;
886 893
887 down(&sonypi_device.lock); 894 mutex_lock(&sonypi_device.lock);
888 895
889 switch (command) { 896 switch (command) {
890 case SONYPI_COMMAND_SETCAMERA: 897 case SONYPI_COMMAND_SETCAMERA:
@@ -919,7 +926,7 @@ int sonypi_camera_command(int command, u8 value)
919 command); 926 command);
920 break; 927 break;
921 } 928 }
922 up(&sonypi_device.lock); 929 mutex_unlock(&sonypi_device.lock);
923 return 0; 930 return 0;
924} 931}
925 932
@@ -938,20 +945,20 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
938static int sonypi_misc_release(struct inode *inode, struct file *file) 945static int sonypi_misc_release(struct inode *inode, struct file *file)
939{ 946{
940 sonypi_misc_fasync(-1, file, 0); 947 sonypi_misc_fasync(-1, file, 0);
941 down(&sonypi_device.lock); 948 mutex_lock(&sonypi_device.lock);
942 sonypi_device.open_count--; 949 sonypi_device.open_count--;
943 up(&sonypi_device.lock); 950 mutex_unlock(&sonypi_device.lock);
944 return 0; 951 return 0;
945} 952}
946 953
947static int sonypi_misc_open(struct inode *inode, struct file *file) 954static int sonypi_misc_open(struct inode *inode, struct file *file)
948{ 955{
949 down(&sonypi_device.lock); 956 mutex_lock(&sonypi_device.lock);
950 /* Flush input queue on first open */ 957 /* Flush input queue on first open */
951 if (!sonypi_device.open_count) 958 if (!sonypi_device.open_count)
952 kfifo_reset(sonypi_device.fifo); 959 kfifo_reset(sonypi_device.fifo);
953 sonypi_device.open_count++; 960 sonypi_device.open_count++;
954 up(&sonypi_device.lock); 961 mutex_unlock(&sonypi_device.lock);
955 return 0; 962 return 0;
956} 963}
957 964
@@ -1001,7 +1008,7 @@ static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
1001 u8 val8; 1008 u8 val8;
1002 u16 val16; 1009 u16 val16;
1003 1010
1004 down(&sonypi_device.lock); 1011 mutex_lock(&sonypi_device.lock);
1005 switch (cmd) { 1012 switch (cmd) {
1006 case SONYPI_IOCGBRT: 1013 case SONYPI_IOCGBRT:
1007 if (sonypi_ec_read(SONYPI_LCD_LIGHT, &val8)) { 1014 if (sonypi_ec_read(SONYPI_LCD_LIGHT, &val8)) {
@@ -1101,7 +1108,7 @@ static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
1101 default: 1108 default:
1102 ret = -EINVAL; 1109 ret = -EINVAL;
1103 } 1110 }
1104 up(&sonypi_device.lock); 1111 mutex_unlock(&sonypi_device.lock);
1105 return ret; 1112 return ret;
1106} 1113}
1107 1114
@@ -1260,6 +1267,28 @@ static int __devinit sonypi_create_input_devices(void)
1260static int __devinit sonypi_setup_ioports(struct sonypi_device *dev, 1267static int __devinit sonypi_setup_ioports(struct sonypi_device *dev,
1261 const struct sonypi_ioport_list *ioport_list) 1268 const struct sonypi_ioport_list *ioport_list)
1262{ 1269{
1270 /* try to detect if sony-laptop is being used and thus
1271 * has already requested one of the known ioports.
1272 * As in the deprecated check_region this is racy has we have
1273 * multiple ioports available and one of them can be requested
1274 * between this check and the subsequent request. Anyway, as an
1275 * attempt to be some more user-friendly as we currently are,
1276 * this is enough.
1277 */
1278 const struct sonypi_ioport_list *check = ioport_list;
1279 while (check_ioport && check->port1) {
1280 if (!request_region(check->port1,
1281 sonypi_device.region_size,
1282 "Sony Programable I/O Device Check")) {
1283 printk(KERN_ERR "sonypi: ioport 0x%.4x busy, using sony-laptop? "
1284 "if not use check_ioport=0\n",
1285 check->port1);
1286 return -EBUSY;
1287 }
1288 release_region(check->port1, sonypi_device.region_size);
1289 check++;
1290 }
1291
1263 while (ioport_list->port1) { 1292 while (ioport_list->port1) {
1264 1293
1265 if (request_region(ioport_list->port1, 1294 if (request_region(ioport_list->port1,
@@ -1321,6 +1350,10 @@ static int __devinit sonypi_probe(struct platform_device *dev)
1321 struct pci_dev *pcidev; 1350 struct pci_dev *pcidev;
1322 int error; 1351 int error;
1323 1352
1353 printk(KERN_WARNING "sonypi: please try the sony-laptop module instead "
1354 "and report failures, see also "
1355 "http://www.linux.it/~malattia/wiki/index.php/Sony_drivers\n");
1356
1324 spin_lock_init(&sonypi_device.fifo_lock); 1357 spin_lock_init(&sonypi_device.fifo_lock);
1325 sonypi_device.fifo = kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL, 1358 sonypi_device.fifo = kfifo_alloc(SONYPI_BUF_SIZE, GFP_KERNEL,
1326 &sonypi_device.fifo_lock); 1359 &sonypi_device.fifo_lock);
@@ -1330,7 +1363,7 @@ static int __devinit sonypi_probe(struct platform_device *dev)
1330 } 1363 }
1331 1364
1332 init_waitqueue_head(&sonypi_device.fifo_proc_list); 1365 init_waitqueue_head(&sonypi_device.fifo_proc_list);
1333 init_MUTEX(&sonypi_device.lock); 1366 mutex_init(&sonypi_device.lock);
1334 sonypi_device.bluetooth_power = -1; 1367 sonypi_device.bluetooth_power = -1;
1335 1368
1336 if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL, 1369 if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 7a6105153f23..ff6aefde10df 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -577,14 +577,14 @@ config VIDEO_ZORAN_AVS6EYES
577 577
578config VIDEO_MEYE 578config VIDEO_MEYE
579 tristate "Sony Vaio Picturebook Motion Eye Video For Linux" 579 tristate "Sony Vaio Picturebook Motion Eye Video For Linux"
580 depends on PCI && SONYPI && VIDEO_V4L1 580 depends on PCI && SONY_LAPTOP && VIDEO_V4L1
581 ---help--- 581 ---help---
582 This is the video4linux driver for the Motion Eye camera found 582 This is the video4linux driver for the Motion Eye camera found
583 in the Vaio Picturebook laptops. Please read the material in 583 in the Vaio Picturebook laptops. Please read the material in
584 <file:Documentation/video4linux/meye.txt> for more information. 584 <file:Documentation/video4linux/meye.txt> for more information.
585 585
586 If you say Y or M here, you need to say Y or M to "Sony Programmable 586 If you say Y or M here, you need to say Y or M to "Sony Laptop
587 I/O Control Device" in the character device section. 587 Extras" in the misc device section.
588 588
589 To compile this driver as a module, choose M here: the 589 To compile this driver as a module, choose M here: the
590 module will be called meye. 590 module will be called meye.
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
index 98681da5e3b9..664aba8b4d85 100644
--- a/drivers/media/video/meye.c
+++ b/drivers/media/video/meye.c
@@ -925,13 +925,13 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
925 if (p->palette != VIDEO_PALETTE_YUV422 && p->palette != VIDEO_PALETTE_YUYV) 925 if (p->palette != VIDEO_PALETTE_YUV422 && p->palette != VIDEO_PALETTE_YUYV)
926 return -EINVAL; 926 return -EINVAL;
927 mutex_lock(&meye.lock); 927 mutex_lock(&meye.lock);
928 sonypi_camera_command(SONYPI_COMMAND_SETCAMERABRIGHTNESS, 928 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERABRIGHTNESS,
929 p->brightness >> 10); 929 p->brightness >> 10);
930 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAHUE, 930 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAHUE,
931 p->hue >> 10); 931 p->hue >> 10);
932 sonypi_camera_command(SONYPI_COMMAND_SETCAMERACOLOR, 932 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACOLOR,
933 p->colour >> 10); 933 p->colour >> 10);
934 sonypi_camera_command(SONYPI_COMMAND_SETCAMERACONTRAST, 934 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACONTRAST,
935 p->contrast >> 10); 935 p->contrast >> 10);
936 meye.picture = *p; 936 meye.picture = *p;
937 mutex_unlock(&meye.lock); 937 mutex_unlock(&meye.lock);
@@ -1043,11 +1043,11 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1043 meye.params.quality != jp->quality) 1043 meye.params.quality != jp->quality)
1044 mchip_hic_stop(); /* need restart */ 1044 mchip_hic_stop(); /* need restart */
1045 meye.params = *jp; 1045 meye.params = *jp;
1046 sonypi_camera_command(SONYPI_COMMAND_SETCAMERASHARPNESS, 1046 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERASHARPNESS,
1047 meye.params.sharpness); 1047 meye.params.sharpness);
1048 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAAGC, 1048 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAAGC,
1049 meye.params.agc); 1049 meye.params.agc);
1050 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAPICTURE, 1050 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAPICTURE,
1051 meye.params.picture); 1051 meye.params.picture);
1052 mutex_unlock(&meye.lock); 1052 mutex_unlock(&meye.lock);
1053 break; 1053 break;
@@ -1287,38 +1287,38 @@ static int meye_do_ioctl(struct inode *inode, struct file *file,
1287 mutex_lock(&meye.lock); 1287 mutex_lock(&meye.lock);
1288 switch (c->id) { 1288 switch (c->id) {
1289 case V4L2_CID_BRIGHTNESS: 1289 case V4L2_CID_BRIGHTNESS:
1290 sonypi_camera_command( 1290 sony_pic_camera_command(
1291 SONYPI_COMMAND_SETCAMERABRIGHTNESS, c->value); 1291 SONY_PIC_COMMAND_SETCAMERABRIGHTNESS, c->value);
1292 meye.picture.brightness = c->value << 10; 1292 meye.picture.brightness = c->value << 10;
1293 break; 1293 break;
1294 case V4L2_CID_HUE: 1294 case V4L2_CID_HUE:
1295 sonypi_camera_command( 1295 sony_pic_camera_command(
1296 SONYPI_COMMAND_SETCAMERAHUE, c->value); 1296 SONY_PIC_COMMAND_SETCAMERAHUE, c->value);
1297 meye.picture.hue = c->value << 10; 1297 meye.picture.hue = c->value << 10;
1298 break; 1298 break;
1299 case V4L2_CID_CONTRAST: 1299 case V4L2_CID_CONTRAST:
1300 sonypi_camera_command( 1300 sony_pic_camera_command(
1301 SONYPI_COMMAND_SETCAMERACONTRAST, c->value); 1301 SONY_PIC_COMMAND_SETCAMERACONTRAST, c->value);
1302 meye.picture.contrast = c->value << 10; 1302 meye.picture.contrast = c->value << 10;
1303 break; 1303 break;
1304 case V4L2_CID_SATURATION: 1304 case V4L2_CID_SATURATION:
1305 sonypi_camera_command( 1305 sony_pic_camera_command(
1306 SONYPI_COMMAND_SETCAMERACOLOR, c->value); 1306 SONY_PIC_COMMAND_SETCAMERACOLOR, c->value);
1307 meye.picture.colour = c->value << 10; 1307 meye.picture.colour = c->value << 10;
1308 break; 1308 break;
1309 case V4L2_CID_AGC: 1309 case V4L2_CID_AGC:
1310 sonypi_camera_command( 1310 sony_pic_camera_command(
1311 SONYPI_COMMAND_SETCAMERAAGC, c->value); 1311 SONY_PIC_COMMAND_SETCAMERAAGC, c->value);
1312 meye.params.agc = c->value; 1312 meye.params.agc = c->value;
1313 break; 1313 break;
1314 case V4L2_CID_SHARPNESS: 1314 case V4L2_CID_SHARPNESS:
1315 sonypi_camera_command( 1315 sony_pic_camera_command(
1316 SONYPI_COMMAND_SETCAMERASHARPNESS, c->value); 1316 SONY_PIC_COMMAND_SETCAMERASHARPNESS, c->value);
1317 meye.params.sharpness = c->value; 1317 meye.params.sharpness = c->value;
1318 break; 1318 break;
1319 case V4L2_CID_PICTURE: 1319 case V4L2_CID_PICTURE:
1320 sonypi_camera_command( 1320 sony_pic_camera_command(
1321 SONYPI_COMMAND_SETCAMERAPICTURE, c->value); 1321 SONY_PIC_COMMAND_SETCAMERAPICTURE, c->value);
1322 meye.params.picture = c->value; 1322 meye.params.picture = c->value;
1323 break; 1323 break;
1324 case V4L2_CID_JPEGQUAL: 1324 case V4L2_CID_JPEGQUAL:
@@ -1848,7 +1848,7 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
1848 memcpy(meye.video_dev, &meye_template, sizeof(meye_template)); 1848 memcpy(meye.video_dev, &meye_template, sizeof(meye_template));
1849 meye.video_dev->dev = &meye.mchip_dev->dev; 1849 meye.video_dev->dev = &meye.mchip_dev->dev;
1850 1850
1851 if ((ret = sonypi_camera_command(SONYPI_COMMAND_SETCAMERA, 1))) { 1851 if ((ret = sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERA, 1))) {
1852 printk(KERN_ERR "meye: unable to power on the camera\n"); 1852 printk(KERN_ERR "meye: unable to power on the camera\n");
1853 printk(KERN_ERR "meye: did you enable the camera in " 1853 printk(KERN_ERR "meye: did you enable the camera in "
1854 "sonypi using the module options ?\n"); 1854 "sonypi using the module options ?\n");
@@ -1928,13 +1928,13 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
1928 meye.params.picture = 0; 1928 meye.params.picture = 0;
1929 meye.params.framerate = 0; 1929 meye.params.framerate = 0;
1930 1930
1931 sonypi_camera_command(SONYPI_COMMAND_SETCAMERABRIGHTNESS, 32); 1931 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERABRIGHTNESS, 32);
1932 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAHUE, 32); 1932 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAHUE, 32);
1933 sonypi_camera_command(SONYPI_COMMAND_SETCAMERACOLOR, 32); 1933 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACOLOR, 32);
1934 sonypi_camera_command(SONYPI_COMMAND_SETCAMERACONTRAST, 32); 1934 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACONTRAST, 32);
1935 sonypi_camera_command(SONYPI_COMMAND_SETCAMERASHARPNESS, 32); 1935 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERASHARPNESS, 32);
1936 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAPICTURE, 0); 1936 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAPICTURE, 0);
1937 sonypi_camera_command(SONYPI_COMMAND_SETCAMERAAGC, 48); 1937 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAAGC, 48);
1938 1938
1939 printk(KERN_INFO "meye: Motion Eye Camera Driver v%s.\n", 1939 printk(KERN_INFO "meye: Motion Eye Camera Driver v%s.\n",
1940 MEYE_DRIVER_VERSION); 1940 MEYE_DRIVER_VERSION);
@@ -1953,7 +1953,7 @@ outremap:
1953outregions: 1953outregions:
1954 pci_disable_device(meye.mchip_dev); 1954 pci_disable_device(meye.mchip_dev);
1955outenabledev: 1955outenabledev:
1956 sonypi_camera_command(SONYPI_COMMAND_SETCAMERA, 0); 1956 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERA, 0);
1957outsonypienable: 1957outsonypienable:
1958 kfifo_free(meye.doneq); 1958 kfifo_free(meye.doneq);
1959outkfifoalloc2: 1959outkfifoalloc2:
@@ -1986,7 +1986,7 @@ static void __devexit meye_remove(struct pci_dev *pcidev)
1986 1986
1987 pci_disable_device(meye.mchip_dev); 1987 pci_disable_device(meye.mchip_dev);
1988 1988
1989 sonypi_camera_command(SONYPI_COMMAND_SETCAMERA, 0); 1989 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERA, 0);
1990 1990
1991 kfifo_free(meye.doneq); 1991 kfifo_free(meye.doneq);
1992 kfifo_free(meye.grabq); 1992 kfifo_free(meye.grabq);
diff --git a/drivers/media/video/meye.h b/drivers/media/video/meye.h
index ea107cb5c845..323d0074120d 100644
--- a/drivers/media/video/meye.h
+++ b/drivers/media/video/meye.h
@@ -255,7 +255,7 @@
255/****************************************************************************/ 255/****************************************************************************/
256 256
257/* Sony Programmable I/O Controller for accessing the camera commands */ 257/* Sony Programmable I/O Controller for accessing the camera commands */
258#include <linux/sonypi.h> 258#include <linux/sony-laptop.h>
259 259
260/* private API definitions */ 260/* private API definitions */
261#include <linux/meye.h> 261#include <linux/meye.h>
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 80b199fa0aa9..75dbc584b574 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -112,14 +112,19 @@ config SONY_LAPTOP
112 depends on X86 && ACPI 112 depends on X86 && ACPI
113 select BACKLIGHT_CLASS_DEVICE 113 select BACKLIGHT_CLASS_DEVICE
114 ---help--- 114 ---help---
115 This mini-driver drives the SNC device present in the ACPI BIOS of 115 This mini-driver drives the SNC and SPIC devices present in the ACPI
116 the Sony Vaio laptops. 116 BIOS of the Sony Vaio laptops.
117 117
118 It gives access to some extra laptop functionalities. In its current 118 It gives access to some extra laptop functionalities like Bluetooth,
119 form, this driver let the user set or query the screen brightness 119 screen brightness control, Fn keys and allows powering on/off some
120 through the backlight subsystem and remove/apply power to some
121 devices. 120 devices.
122 121
123 Read <file:Documentation/sony-laptop.txt> for more information. 122 Read <file:Documentation/sony-laptop.txt> for more information.
124 123
124config SONY_LAPTOP_OLD
125 bool "Sonypi compatibility"
126 depends on SONY_LAPTOP
127 ---help---
128 Build the sonypi driver compatibility code into the sony-laptop driver.
129
125endmenu 130endmenu
diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c
index ac708bc2f9f3..c15c1f61bd1b 100644
--- a/drivers/misc/sony-laptop.c
+++ b/drivers/misc/sony-laptop.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * ACPI Sony Notebook Control Driver (SNC) 2 * ACPI Sony Notebook Control Driver (SNC and SPIC)
3 * 3 *
4 * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net> 4 * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net>
5 * Copyright (C) 2007 Mattia Dongili <malattia@linux.it> 5 * Copyright (C) 2007 Mattia Dongili <malattia@linux.it>
@@ -7,6 +7,25 @@
7 * Parts of this driver inspired from asus_acpi.c and ibm_acpi.c 7 * Parts of this driver inspired from asus_acpi.c and ibm_acpi.c
8 * which are copyrighted by their respective authors. 8 * which are copyrighted by their respective authors.
9 * 9 *
10 * The SNY6001 driver part is based on the sonypi driver which includes
11 * material from:
12 *
13 * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net>
14 *
15 * Copyright (C) 2005 Narayanan R S <nars@kadamba.org>
16 *
17 * Copyright (C) 2001-2002 Alcôve <www.alcove.com>
18 *
19 * Copyright (C) 2001 Michael Ashley <m.ashley@unsw.edu.au>
20 *
21 * Copyright (C) 2001 Junichi Morita <jun1m@mars.dti.ne.jp>
22 *
23 * Copyright (C) 2000 Takaya Kinjo <t-kinjo@tc4.so-net.ne.jp>
24 *
25 * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com>
26 *
27 * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras.
28 *
10 * This program is free software; you can redistribute it and/or modify 29 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 30 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or 31 * the Free Software Foundation; either version 2 of the License, or
@@ -31,40 +50,404 @@
31#include <linux/backlight.h> 50#include <linux/backlight.h>
32#include <linux/platform_device.h> 51#include <linux/platform_device.h>
33#include <linux/err.h> 52#include <linux/err.h>
53#include <linux/dmi.h>
54#include <linux/pci.h>
55#include <linux/interrupt.h>
56#include <linux/delay.h>
57#include <linux/input.h>
58#include <linux/kfifo.h>
59#include <linux/workqueue.h>
60#include <linux/acpi.h>
34#include <acpi/acpi_drivers.h> 61#include <acpi/acpi_drivers.h>
35#include <acpi/acpi_bus.h> 62#include <acpi/acpi_bus.h>
36#include <asm/uaccess.h> 63#include <asm/uaccess.h>
64#include <linux/sonypi.h>
65#include <linux/sony-laptop.h>
66#ifdef CONFIG_SONY_LAPTOP_OLD
67#include <linux/poll.h>
68#include <linux/miscdevice.h>
69#endif
37 70
38#define ACPI_SNC_CLASS "sony" 71#define DRV_PFX "sony-laptop: "
39#define ACPI_SNC_HID "SNY5001" 72#define dprintk(msg...) do { \
40#define ACPI_SNC_DRIVER_NAME "ACPI Sony Notebook Control Driver v0.4" 73 if (debug) printk(KERN_WARNING DRV_PFX msg); \
74} while (0)
41 75
42/* the device uses 1-based values, while the backlight subsystem uses 76#define SONY_LAPTOP_DRIVER_VERSION "0.5"
43 0-based values */ 77
44#define SONY_MAX_BRIGHTNESS 8 78#define SONY_NC_CLASS "sony-nc"
79#define SONY_NC_HID "SNY5001"
80#define SONY_NC_DRIVER_NAME "Sony Notebook Control Driver"
45 81
46#define LOG_PFX KERN_WARNING "sony-laptop: " 82#define SONY_PIC_CLASS "sony-pic"
83#define SONY_PIC_HID "SNY6001"
84#define SONY_PIC_DRIVER_NAME "Sony Programmable IO Control Driver"
47 85
48MODULE_AUTHOR("Stelian Pop, Mattia Dongili"); 86MODULE_AUTHOR("Stelian Pop, Mattia Dongili");
49MODULE_DESCRIPTION(ACPI_SNC_DRIVER_NAME); 87MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)");
50MODULE_LICENSE("GPL"); 88MODULE_LICENSE("GPL");
89MODULE_VERSION(SONY_LAPTOP_DRIVER_VERSION);
51 90
52static int debug; 91static int debug;
53module_param(debug, int, 0); 92module_param(debug, int, 0);
54MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help " 93MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help "
55 "the development of this driver"); 94 "the development of this driver");
56 95
57static ssize_t sony_acpi_show(struct device *, struct device_attribute *, 96static int no_spic; /* = 0 */
97module_param(no_spic, int, 0444);
98MODULE_PARM_DESC(no_spic,
99 "set this if you don't want to enable the SPIC device");
100
101static int compat; /* = 0 */
102module_param(compat, int, 0444);
103MODULE_PARM_DESC(compat,
104 "set this if you want to enable backward compatibility mode");
105
106static unsigned long mask = 0xffffffff;
107module_param(mask, ulong, 0644);
108MODULE_PARM_DESC(mask,
109 "set this to the mask of event you want to enable (see doc)");
110
111static int camera; /* = 0 */
112module_param(camera, int, 0444);
113MODULE_PARM_DESC(camera,
114 "set this to 1 to enable Motion Eye camera controls "
115 "(only use it if you have a C1VE or C1VN model)");
116
117#ifdef CONFIG_SONY_LAPTOP_OLD
118static int minor = -1;
119module_param(minor, int, 0);
120MODULE_PARM_DESC(minor,
121 "minor number of the misc device for the SPIC compatibility code, "
122 "default is -1 (automatic)");
123#endif
124
125/*********** Input Devices ***********/
126
127#define SONY_LAPTOP_BUF_SIZE 128
128struct sony_laptop_input_s {
129 atomic_t users;
130 struct input_dev *jog_dev;
131 struct input_dev *key_dev;
132 struct kfifo *fifo;
133 spinlock_t fifo_lock;
134 struct workqueue_struct *wq;
135};
136static struct sony_laptop_input_s sony_laptop_input = {
137 .users = ATOMIC_INIT(0),
138};
139
140struct sony_laptop_keypress {
141 struct input_dev *dev;
142 int key;
143};
144
145/* Correspondance table between sonypi events and input layer events */
146static struct {
147 int sonypiev;
148 int inputev;
149} sony_laptop_inputkeys[] = {
150 { SONYPI_EVENT_CAPTURE_PRESSED, KEY_CAMERA },
151 { SONYPI_EVENT_FNKEY_ONLY, KEY_FN },
152 { SONYPI_EVENT_FNKEY_ESC, KEY_FN_ESC },
153 { SONYPI_EVENT_FNKEY_F1, KEY_FN_F1 },
154 { SONYPI_EVENT_FNKEY_F2, KEY_FN_F2 },
155 { SONYPI_EVENT_FNKEY_F3, KEY_FN_F3 },
156 { SONYPI_EVENT_FNKEY_F4, KEY_FN_F4 },
157 { SONYPI_EVENT_FNKEY_F5, KEY_FN_F5 },
158 { SONYPI_EVENT_FNKEY_F6, KEY_FN_F6 },
159 { SONYPI_EVENT_FNKEY_F7, KEY_FN_F7 },
160 { SONYPI_EVENT_FNKEY_F8, KEY_FN_F8 },
161 { SONYPI_EVENT_FNKEY_F9, KEY_FN_F9 },
162 { SONYPI_EVENT_FNKEY_F10, KEY_FN_F10 },
163 { SONYPI_EVENT_FNKEY_F11, KEY_FN_F11 },
164 { SONYPI_EVENT_FNKEY_F12, KEY_FN_F12 },
165 { SONYPI_EVENT_FNKEY_1, KEY_FN_1 },
166 { SONYPI_EVENT_FNKEY_2, KEY_FN_2 },
167 { SONYPI_EVENT_FNKEY_D, KEY_FN_D },
168 { SONYPI_EVENT_FNKEY_E, KEY_FN_E },
169 { SONYPI_EVENT_FNKEY_F, KEY_FN_F },
170 { SONYPI_EVENT_FNKEY_S, KEY_FN_S },
171 { SONYPI_EVENT_FNKEY_B, KEY_FN_B },
172 { SONYPI_EVENT_BLUETOOTH_PRESSED, KEY_BLUE },
173 { SONYPI_EVENT_BLUETOOTH_ON, KEY_BLUE },
174 { SONYPI_EVENT_PKEY_P1, KEY_PROG1 },
175 { SONYPI_EVENT_PKEY_P2, KEY_PROG2 },
176 { SONYPI_EVENT_PKEY_P3, KEY_PROG3 },
177 { SONYPI_EVENT_BACK_PRESSED, KEY_BACK },
178 { SONYPI_EVENT_HELP_PRESSED, KEY_HELP },
179 { SONYPI_EVENT_ZOOM_PRESSED, KEY_ZOOM },
180 { SONYPI_EVENT_THUMBPHRASE_PRESSED, BTN_THUMB },
181 { 0, 0 },
182};
183
184/* release buttons after a short delay if pressed */
185static void do_sony_laptop_release_key(struct work_struct *work)
186{
187 struct sony_laptop_keypress kp;
188
189 while (kfifo_get(sony_laptop_input.fifo, (unsigned char *)&kp,
190 sizeof(kp)) == sizeof(kp)) {
191 msleep(10);
192 input_report_key(kp.dev, kp.key, 0);
193 input_sync(kp.dev);
194 }
195}
196static DECLARE_WORK(sony_laptop_release_key_work,
197 do_sony_laptop_release_key);
198
199/* forward event to the input subsytem */
200static void sony_laptop_report_input_event(u8 event)
201{
202 struct input_dev *jog_dev = sony_laptop_input.jog_dev;
203 struct input_dev *key_dev = sony_laptop_input.key_dev;
204 struct sony_laptop_keypress kp = { NULL };
205 int i;
206
207 if (event == SONYPI_EVENT_FNKEY_RELEASED) {
208 /* Nothing, not all VAIOs generate this event */
209 return;
210 }
211
212 /* report events */
213 switch (event) {
214 /* jog_dev events */
215 case SONYPI_EVENT_JOGDIAL_UP:
216 case SONYPI_EVENT_JOGDIAL_UP_PRESSED:
217 input_report_rel(jog_dev, REL_WHEEL, 1);
218 input_sync(jog_dev);
219 return;
220
221 case SONYPI_EVENT_JOGDIAL_DOWN:
222 case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED:
223 input_report_rel(jog_dev, REL_WHEEL, -1);
224 input_sync(jog_dev);
225 return;
226
227 /* key_dev events */
228 case SONYPI_EVENT_JOGDIAL_PRESSED:
229 kp.key = BTN_MIDDLE;
230 kp.dev = jog_dev;
231 break;
232
233 default:
234 for (i = 0; sony_laptop_inputkeys[i].sonypiev; i++)
235 if (event == sony_laptop_inputkeys[i].sonypiev) {
236 kp.dev = key_dev;
237 kp.key = sony_laptop_inputkeys[i].inputev;
238 break;
239 }
240 break;
241 }
242
243 if (kp.dev) {
244 input_report_key(kp.dev, kp.key, 1);
245 input_sync(kp.dev);
246 kfifo_put(sony_laptop_input.fifo,
247 (unsigned char *)&kp, sizeof(kp));
248
249 if (!work_pending(&sony_laptop_release_key_work))
250 queue_work(sony_laptop_input.wq,
251 &sony_laptop_release_key_work);
252 } else
253 dprintk("unknown input event %.2x\n", event);
254}
255
256static int sony_laptop_setup_input(void)
257{
258 struct input_dev *jog_dev;
259 struct input_dev *key_dev;
260 int i;
261 int error;
262
263 /* don't run again if already initialized */
264 if (atomic_add_return(1, &sony_laptop_input.users) > 1)
265 return 0;
266
267 /* kfifo */
268 spin_lock_init(&sony_laptop_input.fifo_lock);
269 sony_laptop_input.fifo =
270 kfifo_alloc(SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
271 &sony_laptop_input.fifo_lock);
272 if (IS_ERR(sony_laptop_input.fifo)) {
273 printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n");
274 error = PTR_ERR(sony_laptop_input.fifo);
275 goto err_dec_users;
276 }
277
278 /* init workqueue */
279 sony_laptop_input.wq = create_singlethread_workqueue("sony-laptop");
280 if (!sony_laptop_input.wq) {
281 printk(KERN_ERR DRV_PFX
282 "Unabe to create workqueue.\n");
283 error = -ENXIO;
284 goto err_free_kfifo;
285 }
286
287 /* input keys */
288 key_dev = input_allocate_device();
289 if (!key_dev) {
290 error = -ENOMEM;
291 goto err_destroy_wq;
292 }
293
294 key_dev->name = "Sony Vaio Keys";
295 key_dev->id.bustype = BUS_ISA;
296 key_dev->id.vendor = PCI_VENDOR_ID_SONY;
297
298 /* Initialize the Input Drivers: special keys */
299 key_dev->evbit[0] = BIT(EV_KEY);
300 for (i = 0; sony_laptop_inputkeys[i].sonypiev; i++)
301 if (sony_laptop_inputkeys[i].inputev)
302 set_bit(sony_laptop_inputkeys[i].inputev,
303 key_dev->keybit);
304
305 error = input_register_device(key_dev);
306 if (error)
307 goto err_free_keydev;
308
309 sony_laptop_input.key_dev = key_dev;
310
311 /* jogdial */
312 jog_dev = input_allocate_device();
313 if (!jog_dev) {
314 error = -ENOMEM;
315 goto err_unregister_keydev;
316 }
317
318 jog_dev->name = "Sony Vaio Jogdial";
319 jog_dev->id.bustype = BUS_ISA;
320 jog_dev->id.vendor = PCI_VENDOR_ID_SONY;
321
322 jog_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
323 jog_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_MIDDLE);
324 jog_dev->relbit[0] = BIT(REL_WHEEL);
325
326 error = input_register_device(jog_dev);
327 if (error)
328 goto err_free_jogdev;
329
330 sony_laptop_input.jog_dev = jog_dev;
331
332 return 0;
333
334err_free_jogdev:
335 input_free_device(jog_dev);
336
337err_unregister_keydev:
338 input_unregister_device(key_dev);
339 /* to avoid kref underflow below at input_free_device */
340 key_dev = NULL;
341
342err_free_keydev:
343 input_free_device(key_dev);
344
345err_destroy_wq:
346 destroy_workqueue(sony_laptop_input.wq);
347
348err_free_kfifo:
349 kfifo_free(sony_laptop_input.fifo);
350
351err_dec_users:
352 atomic_dec(&sony_laptop_input.users);
353 return error;
354}
355
356static void sony_laptop_remove_input(void)
357{
358 /* cleanup only after the last user has gone */
359 if (!atomic_dec_and_test(&sony_laptop_input.users))
360 return;
361
362 /* flush workqueue first */
363 flush_workqueue(sony_laptop_input.wq);
364
365 /* destroy input devs */
366 input_unregister_device(sony_laptop_input.key_dev);
367 sony_laptop_input.key_dev = NULL;
368
369 if (sony_laptop_input.jog_dev) {
370 input_unregister_device(sony_laptop_input.jog_dev);
371 sony_laptop_input.jog_dev = NULL;
372 }
373
374 destroy_workqueue(sony_laptop_input.wq);
375 kfifo_free(sony_laptop_input.fifo);
376}
377
378/*********** Platform Device ***********/
379
380static atomic_t sony_pf_users = ATOMIC_INIT(0);
381static struct platform_driver sony_pf_driver = {
382 .driver = {
383 .name = "sony-laptop",
384 .owner = THIS_MODULE,
385 }
386};
387static struct platform_device *sony_pf_device;
388
389static int sony_pf_add(void)
390{
391 int ret = 0;
392
393 /* don't run again if already initialized */
394 if (atomic_add_return(1, &sony_pf_users) > 1)
395 return 0;
396
397 ret = platform_driver_register(&sony_pf_driver);
398 if (ret)
399 goto out;
400
401 sony_pf_device = platform_device_alloc("sony-laptop", -1);
402 if (!sony_pf_device) {
403 ret = -ENOMEM;
404 goto out_platform_registered;
405 }
406
407 ret = platform_device_add(sony_pf_device);
408 if (ret)
409 goto out_platform_alloced;
410
411 return 0;
412
413 out_platform_alloced:
414 platform_device_put(sony_pf_device);
415 sony_pf_device = NULL;
416 out_platform_registered:
417 platform_driver_unregister(&sony_pf_driver);
418 out:
419 atomic_dec(&sony_pf_users);
420 return ret;
421}
422
423static void sony_pf_remove(void)
424{
425 /* deregister only after the last user has gone */
426 if (!atomic_dec_and_test(&sony_pf_users))
427 return;
428
429 platform_device_del(sony_pf_device);
430 platform_device_put(sony_pf_device);
431 platform_driver_unregister(&sony_pf_driver);
432}
433
434/*********** SNC (SNY5001) Device ***********/
435
436/* the device uses 1-based values, while the backlight subsystem uses
437 0-based values */
438#define SONY_MAX_BRIGHTNESS 8
439
440#define SNC_VALIDATE_IN 0
441#define SNC_VALIDATE_OUT 1
442
443static ssize_t sony_nc_sysfs_show(struct device *, struct device_attribute *,
58 char *); 444 char *);
59static ssize_t sony_acpi_store(struct device *, struct device_attribute *, 445static ssize_t sony_nc_sysfs_store(struct device *, struct device_attribute *,
60 const char *, size_t); 446 const char *, size_t);
61static int boolean_validate(const int, const int); 447static int boolean_validate(const int, const int);
62static int brightness_default_validate(const int, const int); 448static int brightness_default_validate(const int, const int);
63 449
64#define SNC_VALIDATE_IN 0 450struct sony_nc_value {
65#define SNC_VALIDATE_OUT 1
66
67struct sony_acpi_value {
68 char *name; /* name of the entry */ 451 char *name; /* name of the entry */
69 char **acpiget; /* names of the ACPI get function */ 452 char **acpiget; /* names of the ACPI get function */
70 char **acpiset; /* names of the ACPI set function */ 453 char **acpiset; /* names of the ACPI set function */
@@ -75,65 +458,65 @@ struct sony_acpi_value {
75 struct device_attribute devattr; /* sysfs atribute */ 458 struct device_attribute devattr; /* sysfs atribute */
76}; 459};
77 460
78#define HANDLE_NAMES(_name, _values...) \ 461#define SNC_HANDLE_NAMES(_name, _values...) \
79 static char *snc_##_name[] = { _values, NULL } 462 static char *snc_##_name[] = { _values, NULL }
80 463
81#define SONY_ACPI_VALUE(_name, _getters, _setters, _validate, _debug) \ 464#define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \
82 { \ 465 { \
83 .name = __stringify(_name), \ 466 .name = __stringify(_name), \
84 .acpiget = _getters, \ 467 .acpiget = _getters, \
85 .acpiset = _setters, \ 468 .acpiset = _setters, \
86 .validate = _validate, \ 469 .validate = _validate, \
87 .debug = _debug, \ 470 .debug = _debug, \
88 .devattr = __ATTR(_name, 0, sony_acpi_show, sony_acpi_store), \ 471 .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \
89 } 472 }
90 473
91#define SONY_ACPI_VALUE_NULL { .name = NULL } 474#define SNC_HANDLE_NULL { .name = NULL }
92 475
93HANDLE_NAMES(fnkey_get, "GHKE"); 476SNC_HANDLE_NAMES(fnkey_get, "GHKE");
94 477
95HANDLE_NAMES(brightness_def_get, "GPBR"); 478SNC_HANDLE_NAMES(brightness_def_get, "GPBR");
96HANDLE_NAMES(brightness_def_set, "SPBR"); 479SNC_HANDLE_NAMES(brightness_def_set, "SPBR");
97 480
98HANDLE_NAMES(cdpower_get, "GCDP"); 481SNC_HANDLE_NAMES(cdpower_get, "GCDP");
99HANDLE_NAMES(cdpower_set, "SCDP", "CDPW"); 482SNC_HANDLE_NAMES(cdpower_set, "SCDP", "CDPW");
100 483
101HANDLE_NAMES(audiopower_get, "GAZP"); 484SNC_HANDLE_NAMES(audiopower_get, "GAZP");
102HANDLE_NAMES(audiopower_set, "AZPW"); 485SNC_HANDLE_NAMES(audiopower_set, "AZPW");
103 486
104HANDLE_NAMES(lanpower_get, "GLNP"); 487SNC_HANDLE_NAMES(lanpower_get, "GLNP");
105HANDLE_NAMES(lanpower_set, "LNPW"); 488SNC_HANDLE_NAMES(lanpower_set, "LNPW");
106 489
107HANDLE_NAMES(PID_get, "GPID"); 490SNC_HANDLE_NAMES(PID_get, "GPID");
108 491
109HANDLE_NAMES(CTR_get, "GCTR"); 492SNC_HANDLE_NAMES(CTR_get, "GCTR");
110HANDLE_NAMES(CTR_set, "SCTR"); 493SNC_HANDLE_NAMES(CTR_set, "SCTR");
111 494
112HANDLE_NAMES(PCR_get, "GPCR"); 495SNC_HANDLE_NAMES(PCR_get, "GPCR");
113HANDLE_NAMES(PCR_set, "SPCR"); 496SNC_HANDLE_NAMES(PCR_set, "SPCR");
114 497
115HANDLE_NAMES(CMI_get, "GCMI"); 498SNC_HANDLE_NAMES(CMI_get, "GCMI");
116HANDLE_NAMES(CMI_set, "SCMI"); 499SNC_HANDLE_NAMES(CMI_set, "SCMI");
117 500
118static struct sony_acpi_value sony_acpi_values[] = { 501static struct sony_nc_value sony_nc_values[] = {
119 SONY_ACPI_VALUE(brightness_default, snc_brightness_def_get, 502 SNC_HANDLE(brightness_default, snc_brightness_def_get,
120 snc_brightness_def_set, brightness_default_validate, 0), 503 snc_brightness_def_set, brightness_default_validate, 0),
121 SONY_ACPI_VALUE(fnkey, snc_fnkey_get, NULL, NULL, 0), 504 SNC_HANDLE(fnkey, snc_fnkey_get, NULL, NULL, 0),
122 SONY_ACPI_VALUE(cdpower, snc_cdpower_get, snc_cdpower_set, boolean_validate, 0), 505 SNC_HANDLE(cdpower, snc_cdpower_get, snc_cdpower_set, boolean_validate, 0),
123 SONY_ACPI_VALUE(audiopower, snc_audiopower_get, snc_audiopower_set, 506 SNC_HANDLE(audiopower, snc_audiopower_get, snc_audiopower_set,
124 boolean_validate, 0), 507 boolean_validate, 0),
125 SONY_ACPI_VALUE(lanpower, snc_lanpower_get, snc_lanpower_set, 508 SNC_HANDLE(lanpower, snc_lanpower_get, snc_lanpower_set,
126 boolean_validate, 1), 509 boolean_validate, 1),
127 /* unknown methods */ 510 /* unknown methods */
128 SONY_ACPI_VALUE(PID, snc_PID_get, NULL, NULL, 1), 511 SNC_HANDLE(PID, snc_PID_get, NULL, NULL, 1),
129 SONY_ACPI_VALUE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1), 512 SNC_HANDLE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1),
130 SONY_ACPI_VALUE(PCR, snc_PCR_get, snc_PCR_set, NULL, 1), 513 SNC_HANDLE(PCR, snc_PCR_get, snc_PCR_set, NULL, 1),
131 SONY_ACPI_VALUE(CMI, snc_CMI_get, snc_CMI_set, NULL, 1), 514 SNC_HANDLE(CMI, snc_CMI_get, snc_CMI_set, NULL, 1),
132 SONY_ACPI_VALUE_NULL 515 SNC_HANDLE_NULL
133}; 516};
134 517
135static acpi_handle sony_acpi_handle; 518static acpi_handle sony_nc_acpi_handle;
136static struct acpi_device *sony_acpi_acpi_device = NULL; 519static struct acpi_device *sony_nc_acpi_device = NULL;
137 520
138/* 521/*
139 * acpi_evaluate_object wrappers 522 * acpi_evaluate_object wrappers
@@ -153,7 +536,7 @@ static int acpi_callgetfunc(acpi_handle handle, char *name, int *result)
153 return 0; 536 return 0;
154 } 537 }
155 538
156 printk(LOG_PFX "acpi_callreadfunc failed\n"); 539 printk(KERN_WARNING DRV_PFX "acpi_callreadfunc failed\n");
157 540
158 return -1; 541 return -1;
159} 542}
@@ -179,7 +562,7 @@ static int acpi_callsetfunc(acpi_handle handle, char *name, int value,
179 if (status == AE_OK) { 562 if (status == AE_OK) {
180 if (result != NULL) { 563 if (result != NULL) {
181 if (out_obj.type != ACPI_TYPE_INTEGER) { 564 if (out_obj.type != ACPI_TYPE_INTEGER) {
182 printk(LOG_PFX "acpi_evaluate_object bad " 565 printk(KERN_WARNING DRV_PFX "acpi_evaluate_object bad "
183 "return type\n"); 566 "return type\n");
184 return -1; 567 return -1;
185 } 568 }
@@ -188,13 +571,13 @@ static int acpi_callsetfunc(acpi_handle handle, char *name, int value,
188 return 0; 571 return 0;
189 } 572 }
190 573
191 printk(LOG_PFX "acpi_evaluate_object failed\n"); 574 printk(KERN_WARNING DRV_PFX "acpi_evaluate_object failed\n");
192 575
193 return -1; 576 return -1;
194} 577}
195 578
196/* 579/*
197 * sony_acpi_values input/output validate functions 580 * sony_nc_values input/output validate functions
198 */ 581 */
199 582
200/* brightness_default_validate: 583/* brightness_default_validate:
@@ -229,19 +612,19 @@ static int boolean_validate(const int direction, const int value)
229} 612}
230 613
231/* 614/*
232 * Sysfs show/store common to all sony_acpi_values 615 * Sysfs show/store common to all sony_nc_values
233 */ 616 */
234static ssize_t sony_acpi_show(struct device *dev, struct device_attribute *attr, 617static ssize_t sony_nc_sysfs_show(struct device *dev, struct device_attribute *attr,
235 char *buffer) 618 char *buffer)
236{ 619{
237 int value; 620 int value;
238 struct sony_acpi_value *item = 621 struct sony_nc_value *item =
239 container_of(attr, struct sony_acpi_value, devattr); 622 container_of(attr, struct sony_nc_value, devattr);
240 623
241 if (!*item->acpiget) 624 if (!*item->acpiget)
242 return -EIO; 625 return -EIO;
243 626
244 if (acpi_callgetfunc(sony_acpi_handle, *item->acpiget, &value) < 0) 627 if (acpi_callgetfunc(sony_nc_acpi_handle, *item->acpiget, &value) < 0)
245 return -EIO; 628 return -EIO;
246 629
247 if (item->validate) 630 if (item->validate)
@@ -250,13 +633,13 @@ static ssize_t sony_acpi_show(struct device *dev, struct device_attribute *attr,
250 return snprintf(buffer, PAGE_SIZE, "%d\n", value); 633 return snprintf(buffer, PAGE_SIZE, "%d\n", value);
251} 634}
252 635
253static ssize_t sony_acpi_store(struct device *dev, 636static ssize_t sony_nc_sysfs_store(struct device *dev,
254 struct device_attribute *attr, 637 struct device_attribute *attr,
255 const char *buffer, size_t count) 638 const char *buffer, size_t count)
256{ 639{
257 int value; 640 int value;
258 struct sony_acpi_value *item = 641 struct sony_nc_value *item =
259 container_of(attr, struct sony_acpi_value, devattr); 642 container_of(attr, struct sony_nc_value, devattr);
260 643
261 if (!item->acpiset) 644 if (!item->acpiset)
262 return -EIO; 645 return -EIO;
@@ -272,118 +655,20 @@ static ssize_t sony_acpi_store(struct device *dev,
272 if (value < 0) 655 if (value < 0)
273 return value; 656 return value;
274 657
275 if (acpi_callsetfunc(sony_acpi_handle, *item->acpiset, value, NULL) < 0) 658 if (acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset, value, NULL) < 0)
276 return -EIO; 659 return -EIO;
277 item->value = value; 660 item->value = value;
278 item->valid = 1; 661 item->valid = 1;
279 return count; 662 return count;
280} 663}
281 664
282/*
283 * Platform device
284 */
285static struct platform_driver sncpf_driver = {
286 .driver = {
287 .name = "sony-laptop",
288 .owner = THIS_MODULE,
289 }
290};
291static struct platform_device *sncpf_device;
292
293static int sony_snc_pf_add(void)
294{
295 acpi_handle handle;
296 struct sony_acpi_value *item;
297 int ret = 0;
298
299 ret = platform_driver_register(&sncpf_driver);
300 if (ret)
301 goto out;
302
303 sncpf_device = platform_device_alloc("sony-laptop", -1);
304 if (!sncpf_device) {
305 ret = -ENOMEM;
306 goto out_platform_registered;
307 }
308
309 ret = platform_device_add(sncpf_device);
310 if (ret)
311 goto out_platform_alloced;
312
313 for (item = sony_acpi_values; item->name; ++item) {
314
315 if (!debug && item->debug)
316 continue;
317
318 /* find the available acpiget as described in the DSDT */
319 for (; item->acpiget && *item->acpiget; ++item->acpiget) {
320 if (ACPI_SUCCESS(acpi_get_handle(sony_acpi_handle,
321 *item->acpiget,
322 &handle))) {
323 if (debug)
324 printk(LOG_PFX "Found %s getter: %s\n",
325 item->name, *item->acpiget);
326 item->devattr.attr.mode |= S_IRUGO;
327 break;
328 }
329 }
330
331 /* find the available acpiset as described in the DSDT */
332 for (; item->acpiset && *item->acpiset; ++item->acpiset) {
333 if (ACPI_SUCCESS(acpi_get_handle(sony_acpi_handle,
334 *item->acpiset,
335 &handle))) {
336 if (debug)
337 printk(LOG_PFX "Found %s setter: %s\n",
338 item->name, *item->acpiset);
339 item->devattr.attr.mode |= S_IWUSR;
340 break;
341 }
342 }
343
344 if (item->devattr.attr.mode != 0) {
345 ret =
346 device_create_file(&sncpf_device->dev,
347 &item->devattr);
348 if (ret)
349 goto out_sysfs;
350 }
351 }
352
353 return 0;
354
355 out_sysfs:
356 for (item = sony_acpi_values; item->name; ++item) {
357 device_remove_file(&sncpf_device->dev, &item->devattr);
358 }
359 platform_device_del(sncpf_device);
360 out_platform_alloced:
361 platform_device_put(sncpf_device);
362 out_platform_registered:
363 platform_driver_unregister(&sncpf_driver);
364 out:
365 return ret;
366}
367
368static void sony_snc_pf_remove(void)
369{
370 struct sony_acpi_value *item;
371
372 for (item = sony_acpi_values; item->name; ++item) {
373 device_remove_file(&sncpf_device->dev, &item->devattr);
374 }
375
376 platform_device_del(sncpf_device);
377 platform_device_put(sncpf_device);
378 platform_driver_unregister(&sncpf_driver);
379}
380 665
381/* 666/*
382 * Backlight device 667 * Backlight device
383 */ 668 */
384static int sony_backlight_update_status(struct backlight_device *bd) 669static int sony_backlight_update_status(struct backlight_device *bd)
385{ 670{
386 return acpi_callsetfunc(sony_acpi_handle, "SBRT", 671 return acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
387 bd->props.brightness + 1, NULL); 672 bd->props.brightness + 1, NULL);
388} 673}
389 674
@@ -391,7 +676,7 @@ static int sony_backlight_get_brightness(struct backlight_device *bd)
391{ 676{
392 int value; 677 int value;
393 678
394 if (acpi_callgetfunc(sony_acpi_handle, "GBRT", &value)) 679 if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value))
395 return 0; 680 return 0;
396 /* brightness levels are 1-based, while backlight ones are 0-based */ 681 /* brightness levels are 1-based, while backlight ones are 0-based */
397 return value - 1; 682 return value - 1;
@@ -408,9 +693,9 @@ static struct backlight_ops sony_backlight_ops = {
408 */ 693 */
409static void sony_acpi_notify(acpi_handle handle, u32 event, void *data) 694static void sony_acpi_notify(acpi_handle handle, u32 event, void *data)
410{ 695{
411 if (debug) 696 dprintk("sony_acpi_notify, event: %d\n", event);
412 printk(LOG_PFX "sony_acpi_notify, event: %d\n", event); 697 sony_laptop_report_input_event(event);
413 acpi_bus_generate_event(sony_acpi_acpi_device, 1, event); 698 acpi_bus_generate_event(sony_nc_acpi_device, 1, event);
414} 699}
415 700
416static acpi_status sony_walk_callback(acpi_handle handle, u32 level, 701static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
@@ -422,7 +707,7 @@ static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
422 node = (struct acpi_namespace_node *)handle; 707 node = (struct acpi_namespace_node *)handle;
423 operand = (union acpi_operand_object *)node->object; 708 operand = (union acpi_operand_object *)node->object;
424 709
425 printk(LOG_PFX "method: name: %4.4s, args %X\n", node->name.ascii, 710 printk(KERN_WARNING DRV_PFX "method: name: %4.4s, args %X\n", node->name.ascii,
426 (u32) operand->method.param_count); 711 (u32) operand->method.param_count);
427 712
428 return AE_OK; 713 return AE_OK;
@@ -431,16 +716,16 @@ static acpi_status sony_walk_callback(acpi_handle handle, u32 level,
431/* 716/*
432 * ACPI device 717 * ACPI device
433 */ 718 */
434static int sony_acpi_resume(struct acpi_device *device) 719static int sony_nc_resume(struct acpi_device *device)
435{ 720{
436 struct sony_acpi_value *item; 721 struct sony_nc_value *item;
437 722
438 for (item = sony_acpi_values; item->name; item++) { 723 for (item = sony_nc_values; item->name; item++) {
439 int ret; 724 int ret;
440 725
441 if (!item->valid) 726 if (!item->valid)
442 continue; 727 continue;
443 ret = acpi_callsetfunc(sony_acpi_handle, *item->acpiset, 728 ret = acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset,
444 item->value, NULL); 729 item->value, NULL);
445 if (ret < 0) { 730 if (ret < 0) {
446 printk("%s: %d\n", __FUNCTION__, ret); 731 printk("%s: %d\n", __FUNCTION__, ret);
@@ -450,42 +735,55 @@ static int sony_acpi_resume(struct acpi_device *device)
450 return 0; 735 return 0;
451} 736}
452 737
453static int sony_acpi_add(struct acpi_device *device) 738static int sony_nc_add(struct acpi_device *device)
454{ 739{
455 acpi_status status; 740 acpi_status status;
456 int result = 0; 741 int result = 0;
457 acpi_handle handle; 742 acpi_handle handle;
743 struct sony_nc_value *item;
744
745 printk(KERN_INFO DRV_PFX "%s v%s.\n",
746 SONY_NC_DRIVER_NAME, SONY_LAPTOP_DRIVER_VERSION);
458 747
459 sony_acpi_acpi_device = device; 748 sony_nc_acpi_device = device;
749 strcpy(acpi_device_class(device), "sony/hotkey");
460 750
461 sony_acpi_handle = device->handle; 751 sony_nc_acpi_handle = device->handle;
462 752
463 if (debug) { 753 if (debug) {
464 status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_acpi_handle, 754 status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_nc_acpi_handle,
465 1, sony_walk_callback, NULL, NULL); 755 1, sony_walk_callback, NULL, NULL);
466 if (ACPI_FAILURE(status)) { 756 if (ACPI_FAILURE(status)) {
467 printk(LOG_PFX "unable to walk acpi resources\n"); 757 printk(KERN_WARNING DRV_PFX "unable to walk acpi resources\n");
468 result = -ENODEV; 758 result = -ENODEV;
469 goto outwalk; 759 goto outwalk;
470 } 760 }
471 } 761 }
472 762
473 status = acpi_install_notify_handler(sony_acpi_handle, 763 /* setup input devices and helper fifo */
764 result = sony_laptop_setup_input();
765 if (result) {
766 printk(KERN_ERR DRV_PFX
767 "Unabe to create input devices.\n");
768 goto outwalk;
769 }
770
771 status = acpi_install_notify_handler(sony_nc_acpi_handle,
474 ACPI_DEVICE_NOTIFY, 772 ACPI_DEVICE_NOTIFY,
475 sony_acpi_notify, NULL); 773 sony_acpi_notify, NULL);
476 if (ACPI_FAILURE(status)) { 774 if (ACPI_FAILURE(status)) {
477 printk(LOG_PFX "unable to install notify handler\n"); 775 printk(KERN_WARNING DRV_PFX "unable to install notify handler\n");
478 result = -ENODEV; 776 result = -ENODEV;
479 goto outwalk; 777 goto outinput;
480 } 778 }
481 779
482 if (ACPI_SUCCESS(acpi_get_handle(sony_acpi_handle, "GBRT", &handle))) { 780 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "GBRT", &handle))) {
483 sony_backlight_device = backlight_device_register("sony", NULL, 781 sony_backlight_device = backlight_device_register("sony", NULL,
484 NULL, 782 NULL,
485 &sony_backlight_ops); 783 &sony_backlight_ops);
486 784
487 if (IS_ERR(sony_backlight_device)) { 785 if (IS_ERR(sony_backlight_device)) {
488 printk(LOG_PFX "unable to register backlight device\n"); 786 printk(KERN_WARNING DRV_PFX "unable to register backlight device\n");
489 sony_backlight_device = NULL; 787 sony_backlight_device = NULL;
490 } else { 788 } else {
491 sony_backlight_device->props.brightness = 789 sony_backlight_device->props.brightness =
@@ -497,68 +795,1497 @@ static int sony_acpi_add(struct acpi_device *device)
497 795
498 } 796 }
499 797
500 if (sony_snc_pf_add()) 798 result = sony_pf_add();
799 if (result)
501 goto outbacklight; 800 goto outbacklight;
502 801
503 printk(KERN_INFO ACPI_SNC_DRIVER_NAME " successfully installed\n"); 802 /* create sony_pf sysfs attributes related to the SNC device */
803 for (item = sony_nc_values; item->name; ++item) {
804
805 if (!debug && item->debug)
806 continue;
807
808 /* find the available acpiget as described in the DSDT */
809 for (; item->acpiget && *item->acpiget; ++item->acpiget) {
810 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
811 *item->acpiget,
812 &handle))) {
813 dprintk("Found %s getter: %s\n",
814 item->name, *item->acpiget);
815 item->devattr.attr.mode |= S_IRUGO;
816 break;
817 }
818 }
819
820 /* find the available acpiset as described in the DSDT */
821 for (; item->acpiset && *item->acpiset; ++item->acpiset) {
822 if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle,
823 *item->acpiset,
824 &handle))) {
825 dprintk("Found %s setter: %s\n",
826 item->name, *item->acpiset);
827 item->devattr.attr.mode |= S_IWUSR;
828 break;
829 }
830 }
831
832 if (item->devattr.attr.mode != 0) {
833 result =
834 device_create_file(&sony_pf_device->dev,
835 &item->devattr);
836 if (result)
837 goto out_sysfs;
838 }
839 }
504 840
505 return 0; 841 return 0;
506 842
843 out_sysfs:
844 for (item = sony_nc_values; item->name; ++item) {
845 device_remove_file(&sony_pf_device->dev, &item->devattr);
846 }
847 sony_pf_remove();
848
507 outbacklight: 849 outbacklight:
508 if (sony_backlight_device) 850 if (sony_backlight_device)
509 backlight_device_unregister(sony_backlight_device); 851 backlight_device_unregister(sony_backlight_device);
510 852
511 status = acpi_remove_notify_handler(sony_acpi_handle, 853 status = acpi_remove_notify_handler(sony_nc_acpi_handle,
512 ACPI_DEVICE_NOTIFY, 854 ACPI_DEVICE_NOTIFY,
513 sony_acpi_notify); 855 sony_acpi_notify);
514 if (ACPI_FAILURE(status)) 856 if (ACPI_FAILURE(status))
515 printk(LOG_PFX "unable to remove notify handler\n"); 857 printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n");
858
859 outinput:
860 sony_laptop_remove_input();
861
516 outwalk: 862 outwalk:
517 return result; 863 return result;
518} 864}
519 865
520static int sony_acpi_remove(struct acpi_device *device, int type) 866static int sony_nc_remove(struct acpi_device *device, int type)
521{ 867{
522 acpi_status status; 868 acpi_status status;
869 struct sony_nc_value *item;
523 870
524 if (sony_backlight_device) 871 if (sony_backlight_device)
525 backlight_device_unregister(sony_backlight_device); 872 backlight_device_unregister(sony_backlight_device);
526 873
527 sony_acpi_acpi_device = NULL; 874 sony_nc_acpi_device = NULL;
528 875
529 status = acpi_remove_notify_handler(sony_acpi_handle, 876 status = acpi_remove_notify_handler(sony_nc_acpi_handle,
530 ACPI_DEVICE_NOTIFY, 877 ACPI_DEVICE_NOTIFY,
531 sony_acpi_notify); 878 sony_acpi_notify);
532 if (ACPI_FAILURE(status)) 879 if (ACPI_FAILURE(status))
533 printk(LOG_PFX "unable to remove notify handler\n"); 880 printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n");
534 881
535 sony_snc_pf_remove(); 882 for (item = sony_nc_values; item->name; ++item) {
883 device_remove_file(&sony_pf_device->dev, &item->devattr);
884 }
536 885
537 printk(KERN_INFO ACPI_SNC_DRIVER_NAME " successfully removed\n"); 886 sony_pf_remove();
887 sony_laptop_remove_input();
888 dprintk(SONY_NC_DRIVER_NAME " removed.\n");
538 889
539 return 0; 890 return 0;
540} 891}
541 892
542static struct acpi_driver sony_acpi_driver = { 893static struct acpi_driver sony_nc_driver = {
543 .name = ACPI_SNC_DRIVER_NAME, 894 .name = SONY_NC_DRIVER_NAME,
544 .class = ACPI_SNC_CLASS, 895 .class = SONY_NC_CLASS,
545 .ids = ACPI_SNC_HID, 896 .ids = SONY_NC_HID,
897 .owner = THIS_MODULE,
546 .ops = { 898 .ops = {
547 .add = sony_acpi_add, 899 .add = sony_nc_add,
548 .remove = sony_acpi_remove, 900 .remove = sony_nc_remove,
549 .resume = sony_acpi_resume, 901 .resume = sony_nc_resume,
550 }, 902 },
551}; 903};
552 904
553static int __init sony_acpi_init(void) 905/*********** SPIC (SNY6001) Device ***********/
906
907#define SONYPI_DEVICE_TYPE1 0x00000001
908#define SONYPI_DEVICE_TYPE2 0x00000002
909#define SONYPI_DEVICE_TYPE3 0x00000004
910
911#define SONY_PIC_EV_MASK 0xff
912
913struct sony_pic_ioport {
914 struct acpi_resource_io io;
915 struct list_head list;
916};
917
918struct sony_pic_irq {
919 struct acpi_resource_irq irq;
920 struct list_head list;
921};
922
923struct sony_pic_dev {
924 int model;
925 u8 camera_power;
926 u8 bluetooth_power;
927 u8 wwan_power;
928 struct acpi_device *acpi_dev;
929 struct sony_pic_irq *cur_irq;
930 struct sony_pic_ioport *cur_ioport;
931 struct list_head interrupts;
932 struct list_head ioports;
933 struct mutex lock;
934};
935
936static struct sony_pic_dev spic_dev = {
937 .interrupts = LIST_HEAD_INIT(spic_dev.interrupts),
938 .ioports = LIST_HEAD_INIT(spic_dev.ioports),
939};
940
941/* Event masks */
942#define SONYPI_JOGGER_MASK 0x00000001
943#define SONYPI_CAPTURE_MASK 0x00000002
944#define SONYPI_FNKEY_MASK 0x00000004
945#define SONYPI_BLUETOOTH_MASK 0x00000008
946#define SONYPI_PKEY_MASK 0x00000010
947#define SONYPI_BACK_MASK 0x00000020
948#define SONYPI_HELP_MASK 0x00000040
949#define SONYPI_LID_MASK 0x00000080
950#define SONYPI_ZOOM_MASK 0x00000100
951#define SONYPI_THUMBPHRASE_MASK 0x00000200
952#define SONYPI_MEYE_MASK 0x00000400
953#define SONYPI_MEMORYSTICK_MASK 0x00000800
954#define SONYPI_BATTERY_MASK 0x00001000
955#define SONYPI_WIRELESS_MASK 0x00002000
956
957struct sonypi_event {
958 u8 data;
959 u8 event;
960};
961
962/* The set of possible button release events */
963static struct sonypi_event sonypi_releaseev[] = {
964 { 0x00, SONYPI_EVENT_ANYBUTTON_RELEASED },
965 { 0, 0 }
966};
967
968/* The set of possible jogger events */
969static struct sonypi_event sonypi_joggerev[] = {
970 { 0x1f, SONYPI_EVENT_JOGDIAL_UP },
971 { 0x01, SONYPI_EVENT_JOGDIAL_DOWN },
972 { 0x5f, SONYPI_EVENT_JOGDIAL_UP_PRESSED },
973 { 0x41, SONYPI_EVENT_JOGDIAL_DOWN_PRESSED },
974 { 0x1e, SONYPI_EVENT_JOGDIAL_FAST_UP },
975 { 0x02, SONYPI_EVENT_JOGDIAL_FAST_DOWN },
976 { 0x5e, SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED },
977 { 0x42, SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED },
978 { 0x1d, SONYPI_EVENT_JOGDIAL_VFAST_UP },
979 { 0x03, SONYPI_EVENT_JOGDIAL_VFAST_DOWN },
980 { 0x5d, SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED },
981 { 0x43, SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED },
982 { 0x40, SONYPI_EVENT_JOGDIAL_PRESSED },
983 { 0, 0 }
984};
985
986/* The set of possible capture button events */
987static struct sonypi_event sonypi_captureev[] = {
988 { 0x05, SONYPI_EVENT_CAPTURE_PARTIALPRESSED },
989 { 0x07, SONYPI_EVENT_CAPTURE_PRESSED },
990 { 0x01, SONYPI_EVENT_CAPTURE_PARTIALRELEASED },
991 { 0, 0 }
992};
993
994/* The set of possible fnkeys events */
995static struct sonypi_event sonypi_fnkeyev[] = {
996 { 0x10, SONYPI_EVENT_FNKEY_ESC },
997 { 0x11, SONYPI_EVENT_FNKEY_F1 },
998 { 0x12, SONYPI_EVENT_FNKEY_F2 },
999 { 0x13, SONYPI_EVENT_FNKEY_F3 },
1000 { 0x14, SONYPI_EVENT_FNKEY_F4 },
1001 { 0x15, SONYPI_EVENT_FNKEY_F5 },
1002 { 0x16, SONYPI_EVENT_FNKEY_F6 },
1003 { 0x17, SONYPI_EVENT_FNKEY_F7 },
1004 { 0x18, SONYPI_EVENT_FNKEY_F8 },
1005 { 0x19, SONYPI_EVENT_FNKEY_F9 },
1006 { 0x1a, SONYPI_EVENT_FNKEY_F10 },
1007 { 0x1b, SONYPI_EVENT_FNKEY_F11 },
1008 { 0x1c, SONYPI_EVENT_FNKEY_F12 },
1009 { 0x1f, SONYPI_EVENT_FNKEY_RELEASED },
1010 { 0x21, SONYPI_EVENT_FNKEY_1 },
1011 { 0x22, SONYPI_EVENT_FNKEY_2 },
1012 { 0x31, SONYPI_EVENT_FNKEY_D },
1013 { 0x32, SONYPI_EVENT_FNKEY_E },
1014 { 0x33, SONYPI_EVENT_FNKEY_F },
1015 { 0x34, SONYPI_EVENT_FNKEY_S },
1016 { 0x35, SONYPI_EVENT_FNKEY_B },
1017 { 0x36, SONYPI_EVENT_FNKEY_ONLY },
1018 { 0, 0 }
1019};
1020
1021/* The set of possible program key events */
1022static struct sonypi_event sonypi_pkeyev[] = {
1023 { 0x01, SONYPI_EVENT_PKEY_P1 },
1024 { 0x02, SONYPI_EVENT_PKEY_P2 },
1025 { 0x04, SONYPI_EVENT_PKEY_P3 },
1026 { 0x5c, SONYPI_EVENT_PKEY_P1 },
1027 { 0, 0 }
1028};
1029
1030/* The set of possible bluetooth events */
1031static struct sonypi_event sonypi_blueev[] = {
1032 { 0x55, SONYPI_EVENT_BLUETOOTH_PRESSED },
1033 { 0x59, SONYPI_EVENT_BLUETOOTH_ON },
1034 { 0x5a, SONYPI_EVENT_BLUETOOTH_OFF },
1035 { 0, 0 }
1036};
1037
1038/* The set of possible wireless events */
1039static struct sonypi_event sonypi_wlessev[] = {
1040 { 0x59, SONYPI_EVENT_WIRELESS_ON },
1041 { 0x5a, SONYPI_EVENT_WIRELESS_OFF },
1042 { 0, 0 }
1043};
1044
1045/* The set of possible back button events */
1046static struct sonypi_event sonypi_backev[] = {
1047 { 0x20, SONYPI_EVENT_BACK_PRESSED },
1048 { 0, 0 }
1049};
1050
1051/* The set of possible help button events */
1052static struct sonypi_event sonypi_helpev[] = {
1053 { 0x3b, SONYPI_EVENT_HELP_PRESSED },
1054 { 0, 0 }
1055};
1056
1057
1058/* The set of possible lid events */
1059static struct sonypi_event sonypi_lidev[] = {
1060 { 0x51, SONYPI_EVENT_LID_CLOSED },
1061 { 0x50, SONYPI_EVENT_LID_OPENED },
1062 { 0, 0 }
1063};
1064
1065/* The set of possible zoom events */
1066static struct sonypi_event sonypi_zoomev[] = {
1067 { 0x39, SONYPI_EVENT_ZOOM_PRESSED },
1068 { 0, 0 }
1069};
1070
1071/* The set of possible thumbphrase events */
1072static struct sonypi_event sonypi_thumbphraseev[] = {
1073 { 0x3a, SONYPI_EVENT_THUMBPHRASE_PRESSED },
1074 { 0, 0 }
1075};
1076
1077/* The set of possible motioneye camera events */
1078static struct sonypi_event sonypi_meyeev[] = {
1079 { 0x00, SONYPI_EVENT_MEYE_FACE },
1080 { 0x01, SONYPI_EVENT_MEYE_OPPOSITE },
1081 { 0, 0 }
1082};
1083
1084/* The set of possible memorystick events */
1085static struct sonypi_event sonypi_memorystickev[] = {
1086 { 0x53, SONYPI_EVENT_MEMORYSTICK_INSERT },
1087 { 0x54, SONYPI_EVENT_MEMORYSTICK_EJECT },
1088 { 0, 0 }
1089};
1090
1091/* The set of possible battery events */
1092static struct sonypi_event sonypi_batteryev[] = {
1093 { 0x20, SONYPI_EVENT_BATTERY_INSERT },
1094 { 0x30, SONYPI_EVENT_BATTERY_REMOVE },
1095 { 0, 0 }
1096};
1097
1098static struct sonypi_eventtypes {
1099 int model;
1100 u8 data;
1101 unsigned long mask;
1102 struct sonypi_event * events;
1103} sony_pic_eventtypes[] = {
1104 { SONYPI_DEVICE_TYPE1, 0, 0xffffffff, sonypi_releaseev },
1105 { SONYPI_DEVICE_TYPE1, 0x70, SONYPI_MEYE_MASK, sonypi_meyeev },
1106 { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_LID_MASK, sonypi_lidev },
1107 { SONYPI_DEVICE_TYPE1, 0x60, SONYPI_CAPTURE_MASK, sonypi_captureev },
1108 { SONYPI_DEVICE_TYPE1, 0x10, SONYPI_JOGGER_MASK, sonypi_joggerev },
1109 { SONYPI_DEVICE_TYPE1, 0x20, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
1110 { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
1111 { SONYPI_DEVICE_TYPE1, 0x40, SONYPI_PKEY_MASK, sonypi_pkeyev },
1112 { SONYPI_DEVICE_TYPE1, 0x30, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
1113 { SONYPI_DEVICE_TYPE1, 0x40, SONYPI_BATTERY_MASK, sonypi_batteryev },
1114
1115 { SONYPI_DEVICE_TYPE2, 0, 0xffffffff, sonypi_releaseev },
1116 { SONYPI_DEVICE_TYPE2, 0x38, SONYPI_LID_MASK, sonypi_lidev },
1117 { SONYPI_DEVICE_TYPE2, 0x11, SONYPI_JOGGER_MASK, sonypi_joggerev },
1118 { SONYPI_DEVICE_TYPE2, 0x61, SONYPI_CAPTURE_MASK, sonypi_captureev },
1119 { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
1120 { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_BLUETOOTH_MASK, sonypi_blueev },
1121 { SONYPI_DEVICE_TYPE2, 0x08, SONYPI_PKEY_MASK, sonypi_pkeyev },
1122 { SONYPI_DEVICE_TYPE2, 0x11, SONYPI_BACK_MASK, sonypi_backev },
1123 { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_HELP_MASK, sonypi_helpev },
1124 { SONYPI_DEVICE_TYPE2, 0x21, SONYPI_ZOOM_MASK, sonypi_zoomev },
1125 { SONYPI_DEVICE_TYPE2, 0x20, SONYPI_THUMBPHRASE_MASK, sonypi_thumbphraseev },
1126 { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
1127 { SONYPI_DEVICE_TYPE2, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
1128 { SONYPI_DEVICE_TYPE2, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
1129
1130 { SONYPI_DEVICE_TYPE3, 0, 0xffffffff, sonypi_releaseev },
1131 { SONYPI_DEVICE_TYPE3, 0x21, SONYPI_FNKEY_MASK, sonypi_fnkeyev },
1132 { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_WIRELESS_MASK, sonypi_wlessev },
1133 { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_MEMORYSTICK_MASK, sonypi_memorystickev },
1134 { SONYPI_DEVICE_TYPE3, 0x41, SONYPI_BATTERY_MASK, sonypi_batteryev },
1135 { SONYPI_DEVICE_TYPE3, 0x31, SONYPI_PKEY_MASK, sonypi_pkeyev },
1136 { 0 }
1137};
1138
1139static int sony_pic_detect_device_type(void)
1140{
1141 struct pci_dev *pcidev;
1142 int model = 0;
1143
1144 if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
1145 PCI_DEVICE_ID_INTEL_82371AB_3, NULL)))
1146 model = SONYPI_DEVICE_TYPE1;
1147
1148 else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
1149 PCI_DEVICE_ID_INTEL_ICH6_1, NULL)))
1150 model = SONYPI_DEVICE_TYPE3;
1151
1152 else if ((pcidev = pci_get_device(PCI_VENDOR_ID_INTEL,
1153 PCI_DEVICE_ID_INTEL_ICH7_1, NULL)))
1154 model = SONYPI_DEVICE_TYPE3;
1155
1156 else
1157 model = SONYPI_DEVICE_TYPE2;
1158
1159 if (pcidev)
1160 pci_dev_put(pcidev);
1161
1162 printk(KERN_INFO DRV_PFX "detected Type%d model\n",
1163 model == SONYPI_DEVICE_TYPE1 ? 1 :
1164 model == SONYPI_DEVICE_TYPE2 ? 2 : 3);
1165 return model;
1166}
1167
1168#define ITERATIONS_LONG 10000
1169#define ITERATIONS_SHORT 10
1170#define wait_on_command(command, iterations) { \
1171 unsigned int n = iterations; \
1172 while (--n && (command)) \
1173 udelay(1); \
1174 if (!n) \
1175 dprintk("command failed at %s : %s (line %d)\n", \
1176 __FILE__, __FUNCTION__, __LINE__); \
1177}
1178
1179static u8 sony_pic_call1(u8 dev)
1180{
1181 u8 v1, v2;
1182
1183 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2,
1184 ITERATIONS_LONG);
1185 outb(dev, spic_dev.cur_ioport->io.minimum + 4);
1186 v1 = inb_p(spic_dev.cur_ioport->io.minimum + 4);
1187 v2 = inb_p(spic_dev.cur_ioport->io.minimum);
1188 dprintk("sony_pic_call1: 0x%.4x\n", (v2 << 8) | v1);
1189 return v2;
1190}
1191
1192static u8 sony_pic_call2(u8 dev, u8 fn)
1193{
1194 u8 v1;
1195
1196 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2,
1197 ITERATIONS_LONG);
1198 outb(dev, spic_dev.cur_ioport->io.minimum + 4);
1199 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2,
1200 ITERATIONS_LONG);
1201 outb(fn, spic_dev.cur_ioport->io.minimum);
1202 v1 = inb_p(spic_dev.cur_ioport->io.minimum);
1203 dprintk("sony_pic_call2: 0x%.4x\n", v1);
1204 return v1;
1205}
1206
1207static u8 sony_pic_call3(u8 dev, u8 fn, u8 v)
1208{
1209 u8 v1;
1210
1211 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2, ITERATIONS_LONG);
1212 outb(dev, spic_dev.cur_ioport->io.minimum + 4);
1213 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2, ITERATIONS_LONG);
1214 outb(fn, spic_dev.cur_ioport->io.minimum);
1215 wait_on_command(inb_p(spic_dev.cur_ioport->io.minimum + 4) & 2, ITERATIONS_LONG);
1216 outb(v, spic_dev.cur_ioport->io.minimum);
1217 v1 = inb_p(spic_dev.cur_ioport->io.minimum);
1218 dprintk("sony_pic_call3: 0x%.4x\n", v1);
1219 return v1;
1220}
1221
1222/* camera tests and poweron/poweroff */
1223#define SONYPI_CAMERA_PICTURE 5
1224#define SONYPI_CAMERA_CONTROL 0x10
1225
1226#define SONYPI_CAMERA_BRIGHTNESS 0
1227#define SONYPI_CAMERA_CONTRAST 1
1228#define SONYPI_CAMERA_HUE 2
1229#define SONYPI_CAMERA_COLOR 3
1230#define SONYPI_CAMERA_SHARPNESS 4
1231
1232#define SONYPI_CAMERA_EXPOSURE_MASK 0xC
1233#define SONYPI_CAMERA_WHITE_BALANCE_MASK 0x3
1234#define SONYPI_CAMERA_PICTURE_MODE_MASK 0x30
1235#define SONYPI_CAMERA_MUTE_MASK 0x40
1236
1237/* the rest don't need a loop until not 0xff */
1238#define SONYPI_CAMERA_AGC 6
1239#define SONYPI_CAMERA_AGC_MASK 0x30
1240#define SONYPI_CAMERA_SHUTTER_MASK 0x7
1241
1242#define SONYPI_CAMERA_SHUTDOWN_REQUEST 7
1243#define SONYPI_CAMERA_CONTROL 0x10
1244
1245#define SONYPI_CAMERA_STATUS 7
1246#define SONYPI_CAMERA_STATUS_READY 0x2
1247#define SONYPI_CAMERA_STATUS_POSITION 0x4
1248
1249#define SONYPI_DIRECTION_BACKWARDS 0x4
1250
1251#define SONYPI_CAMERA_REVISION 8
1252#define SONYPI_CAMERA_ROMVERSION 9
1253
1254static int __sony_pic_camera_ready(void)
1255{
1256 u8 v;
1257
1258 v = sony_pic_call2(0x8f, SONYPI_CAMERA_STATUS);
1259 return (v != 0xff && (v & SONYPI_CAMERA_STATUS_READY));
1260}
1261
1262static int __sony_pic_camera_off(void)
1263{
1264 if (!camera) {
1265 printk(KERN_WARNING DRV_PFX "camera control not enabled\n");
1266 return -ENODEV;
1267 }
1268
1269 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE,
1270 SONYPI_CAMERA_MUTE_MASK),
1271 ITERATIONS_SHORT);
1272
1273 if (spic_dev.camera_power) {
1274 sony_pic_call2(0x91, 0);
1275 spic_dev.camera_power = 0;
1276 }
1277 return 0;
1278}
1279
1280static int __sony_pic_camera_on(void)
554{ 1281{
555 return acpi_bus_register_driver(&sony_acpi_driver); 1282 int i, j, x;
1283
1284 if (!camera) {
1285 printk(KERN_WARNING DRV_PFX "camera control not enabled\n");
1286 return -ENODEV;
1287 }
1288
1289 if (spic_dev.camera_power)
1290 return 0;
1291
1292 for (j = 5; j > 0; j--) {
1293
1294 for (x = 0; x < 100 && sony_pic_call2(0x91, 0x1); x++)
1295 msleep(10);
1296 sony_pic_call1(0x93);
1297
1298 for (i = 400; i > 0; i--) {
1299 if (__sony_pic_camera_ready())
1300 break;
1301 msleep(10);
1302 }
1303 if (i)
1304 break;
1305 }
1306
1307 if (j == 0) {
1308 printk(KERN_WARNING DRV_PFX "failed to power on camera\n");
1309 return -ENODEV;
1310 }
1311
1312 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTROL,
1313 0x5a),
1314 ITERATIONS_SHORT);
1315
1316 spic_dev.camera_power = 1;
1317 return 0;
1318}
1319
1320/* External camera command (exported to the motion eye v4l driver) */
1321int sony_pic_camera_command(int command, u8 value)
1322{
1323 if (!camera)
1324 return -EIO;
1325
1326 mutex_lock(&spic_dev.lock);
1327
1328 switch (command) {
1329 case SONY_PIC_COMMAND_SETCAMERA:
1330 if (value)
1331 __sony_pic_camera_on();
1332 else
1333 __sony_pic_camera_off();
1334 break;
1335 case SONY_PIC_COMMAND_SETCAMERABRIGHTNESS:
1336 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_BRIGHTNESS, value),
1337 ITERATIONS_SHORT);
1338 break;
1339 case SONY_PIC_COMMAND_SETCAMERACONTRAST:
1340 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_CONTRAST, value),
1341 ITERATIONS_SHORT);
1342 break;
1343 case SONY_PIC_COMMAND_SETCAMERAHUE:
1344 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_HUE, value),
1345 ITERATIONS_SHORT);
1346 break;
1347 case SONY_PIC_COMMAND_SETCAMERACOLOR:
1348 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_COLOR, value),
1349 ITERATIONS_SHORT);
1350 break;
1351 case SONY_PIC_COMMAND_SETCAMERASHARPNESS:
1352 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_SHARPNESS, value),
1353 ITERATIONS_SHORT);
1354 break;
1355 case SONY_PIC_COMMAND_SETCAMERAPICTURE:
1356 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_PICTURE, value),
1357 ITERATIONS_SHORT);
1358 break;
1359 case SONY_PIC_COMMAND_SETCAMERAAGC:
1360 wait_on_command(sony_pic_call3(0x90, SONYPI_CAMERA_AGC, value),
1361 ITERATIONS_SHORT);
1362 break;
1363 default:
1364 printk(KERN_ERR DRV_PFX "sony_pic_camera_command invalid: %d\n",
1365 command);
1366 break;
1367 }
1368 mutex_unlock(&spic_dev.lock);
1369 return 0;
1370}
1371EXPORT_SYMBOL(sony_pic_camera_command);
1372
1373/* gprs/edge modem (SZ460N and SZ210P), thanks to Joshua Wise */
1374static void sony_pic_set_wwanpower(u8 state)
1375{
1376 state = !!state;
1377 mutex_lock(&spic_dev.lock);
1378 if (spic_dev.wwan_power == state) {
1379 mutex_unlock(&spic_dev.lock);
1380 return;
1381 }
1382 sony_pic_call2(0xB0, state);
1383 spic_dev.wwan_power = state;
1384 mutex_unlock(&spic_dev.lock);
1385}
1386
1387static ssize_t sony_pic_wwanpower_store(struct device *dev,
1388 struct device_attribute *attr,
1389 const char *buffer, size_t count)
1390{
1391 unsigned long value;
1392 if (count > 31)
1393 return -EINVAL;
1394
1395 value = simple_strtoul(buffer, NULL, 10);
1396 sony_pic_set_wwanpower(value);
1397
1398 return count;
1399}
1400
1401static ssize_t sony_pic_wwanpower_show(struct device *dev,
1402 struct device_attribute *attr, char *buffer)
1403{
1404 ssize_t count;
1405 mutex_lock(&spic_dev.lock);
1406 count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.wwan_power);
1407 mutex_unlock(&spic_dev.lock);
1408 return count;
1409}
1410
1411/* bluetooth subsystem power state */
1412static void __sony_pic_set_bluetoothpower(u8 state)
1413{
1414 state = !!state;
1415 if (spic_dev.bluetooth_power == state)
1416 return;
1417 sony_pic_call2(0x96, state);
1418 sony_pic_call1(0x82);
1419 spic_dev.bluetooth_power = state;
1420}
1421
1422static ssize_t sony_pic_bluetoothpower_store(struct device *dev,
1423 struct device_attribute *attr,
1424 const char *buffer, size_t count)
1425{
1426 unsigned long value;
1427 if (count > 31)
1428 return -EINVAL;
1429
1430 value = simple_strtoul(buffer, NULL, 10);
1431 mutex_lock(&spic_dev.lock);
1432 __sony_pic_set_bluetoothpower(value);
1433 mutex_unlock(&spic_dev.lock);
1434
1435 return count;
1436}
1437
1438static ssize_t sony_pic_bluetoothpower_show(struct device *dev,
1439 struct device_attribute *attr, char *buffer)
1440{
1441 ssize_t count = 0;
1442 mutex_lock(&spic_dev.lock);
1443 count = snprintf(buffer, PAGE_SIZE, "%d\n", spic_dev.bluetooth_power);
1444 mutex_unlock(&spic_dev.lock);
1445 return count;
1446}
1447
1448/* fan speed */
1449/* FAN0 information (reverse engineered from ACPI tables) */
1450#define SONY_PIC_FAN0_STATUS 0x93
1451static int sony_pic_set_fanspeed(unsigned long value)
1452{
1453 return ec_write(SONY_PIC_FAN0_STATUS, value);
1454}
1455
1456static int sony_pic_get_fanspeed(u8 *value)
1457{
1458 return ec_read(SONY_PIC_FAN0_STATUS, value);
1459}
1460
1461static ssize_t sony_pic_fanspeed_store(struct device *dev,
1462 struct device_attribute *attr,
1463 const char *buffer, size_t count)
1464{
1465 unsigned long value;
1466 if (count > 31)
1467 return -EINVAL;
1468
1469 value = simple_strtoul(buffer, NULL, 10);
1470 if (sony_pic_set_fanspeed(value))
1471 return -EIO;
1472
1473 return count;
1474}
1475
1476static ssize_t sony_pic_fanspeed_show(struct device *dev,
1477 struct device_attribute *attr, char *buffer)
1478{
1479 u8 value = 0;
1480 if (sony_pic_get_fanspeed(&value))
1481 return -EIO;
1482
1483 return snprintf(buffer, PAGE_SIZE, "%d\n", value);
1484}
1485
1486#define SPIC_ATTR(_name, _mode) \
1487struct device_attribute spic_attr_##_name = __ATTR(_name, \
1488 _mode, sony_pic_## _name ##_show, \
1489 sony_pic_## _name ##_store)
1490
1491static SPIC_ATTR(bluetoothpower, 0644);
1492static SPIC_ATTR(wwanpower, 0644);
1493static SPIC_ATTR(fanspeed, 0644);
1494
1495static struct attribute *spic_attributes[] = {
1496 &spic_attr_bluetoothpower.attr,
1497 &spic_attr_wwanpower.attr,
1498 &spic_attr_fanspeed.attr,
1499 NULL
1500};
1501
1502static struct attribute_group spic_attribute_group = {
1503 .attrs = spic_attributes
1504};
1505
1506/******** SONYPI compatibility **********/
1507#ifdef CONFIG_SONY_LAPTOP_OLD
1508
1509/* battery / brightness / temperature addresses */
1510#define SONYPI_BAT_FLAGS 0x81
1511#define SONYPI_LCD_LIGHT 0x96
1512#define SONYPI_BAT1_PCTRM 0xa0
1513#define SONYPI_BAT1_LEFT 0xa2
1514#define SONYPI_BAT1_MAXRT 0xa4
1515#define SONYPI_BAT2_PCTRM 0xa8
1516#define SONYPI_BAT2_LEFT 0xaa
1517#define SONYPI_BAT2_MAXRT 0xac
1518#define SONYPI_BAT1_MAXTK 0xb0
1519#define SONYPI_BAT1_FULL 0xb2
1520#define SONYPI_BAT2_MAXTK 0xb8
1521#define SONYPI_BAT2_FULL 0xba
1522#define SONYPI_TEMP_STATUS 0xC1
1523
1524struct sonypi_compat_s {
1525 struct fasync_struct *fifo_async;
1526 struct kfifo *fifo;
1527 spinlock_t fifo_lock;
1528 wait_queue_head_t fifo_proc_list;
1529 atomic_t open_count;
1530};
1531static struct sonypi_compat_s sonypi_compat = {
1532 .open_count = ATOMIC_INIT(0),
1533};
1534
1535static int sonypi_misc_fasync(int fd, struct file *filp, int on)
1536{
1537 int retval;
1538
1539 retval = fasync_helper(fd, filp, on, &sonypi_compat.fifo_async);
1540 if (retval < 0)
1541 return retval;
1542 return 0;
1543}
1544
1545static int sonypi_misc_release(struct inode *inode, struct file *file)
1546{
1547 sonypi_misc_fasync(-1, file, 0);
1548 atomic_dec(&sonypi_compat.open_count);
1549 return 0;
1550}
1551
1552static int sonypi_misc_open(struct inode *inode, struct file *file)
1553{
1554 /* Flush input queue on first open */
1555 if (atomic_inc_return(&sonypi_compat.open_count) == 1)
1556 kfifo_reset(sonypi_compat.fifo);
1557 return 0;
1558}
1559
1560static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
1561 size_t count, loff_t *pos)
1562{
1563 ssize_t ret;
1564 unsigned char c;
1565
1566 if ((kfifo_len(sonypi_compat.fifo) == 0) &&
1567 (file->f_flags & O_NONBLOCK))
1568 return -EAGAIN;
1569
1570 ret = wait_event_interruptible(sonypi_compat.fifo_proc_list,
1571 kfifo_len(sonypi_compat.fifo) != 0);
1572 if (ret)
1573 return ret;
1574
1575 while (ret < count &&
1576 (kfifo_get(sonypi_compat.fifo, &c, sizeof(c)) == sizeof(c))) {
1577 if (put_user(c, buf++))
1578 return -EFAULT;
1579 ret++;
1580 }
1581
1582 if (ret > 0) {
1583 struct inode *inode = file->f_path.dentry->d_inode;
1584 inode->i_atime = current_fs_time(inode->i_sb);
1585 }
1586
1587 return ret;
1588}
1589
1590static unsigned int sonypi_misc_poll(struct file *file, poll_table *wait)
1591{
1592 poll_wait(file, &sonypi_compat.fifo_proc_list, wait);
1593 if (kfifo_len(sonypi_compat.fifo))
1594 return POLLIN | POLLRDNORM;
1595 return 0;
1596}
1597
1598static int ec_read16(u8 addr, u16 *value)
1599{
1600 u8 val_lb, val_hb;
1601 if (ec_read(addr, &val_lb))
1602 return -1;
1603 if (ec_read(addr + 1, &val_hb))
1604 return -1;
1605 *value = val_lb | (val_hb << 8);
1606 return 0;
1607}
1608
1609static int sonypi_misc_ioctl(struct inode *ip, struct file *fp,
1610 unsigned int cmd, unsigned long arg)
1611{
1612 int ret = 0;
1613 void __user *argp = (void __user *)arg;
1614 u8 val8;
1615 u16 val16;
1616 int value;
1617
1618 mutex_lock(&spic_dev.lock);
1619 switch (cmd) {
1620 case SONYPI_IOCGBRT:
1621 if (sony_backlight_device == NULL) {
1622 ret = -EIO;
1623 break;
1624 }
1625 if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value)) {
1626 ret = -EIO;
1627 break;
1628 }
1629 val8 = ((value & 0xff) - 1) << 5;
1630 if (copy_to_user(argp, &val8, sizeof(val8)))
1631 ret = -EFAULT;
1632 break;
1633 case SONYPI_IOCSBRT:
1634 if (sony_backlight_device == NULL) {
1635 ret = -EIO;
1636 break;
1637 }
1638 if (copy_from_user(&val8, argp, sizeof(val8))) {
1639 ret = -EFAULT;
1640 break;
1641 }
1642 if (acpi_callsetfunc(sony_nc_acpi_handle, "SBRT",
1643 (val8 >> 5) + 1, NULL)) {
1644 ret = -EIO;
1645 break;
1646 }
1647 /* sync the backlight device status */
1648 sony_backlight_device->props.brightness =
1649 sony_backlight_get_brightness(sony_backlight_device);
1650 break;
1651 case SONYPI_IOCGBAT1CAP:
1652 if (ec_read16(SONYPI_BAT1_FULL, &val16)) {
1653 ret = -EIO;
1654 break;
1655 }
1656 if (copy_to_user(argp, &val16, sizeof(val16)))
1657 ret = -EFAULT;
1658 break;
1659 case SONYPI_IOCGBAT1REM:
1660 if (ec_read16(SONYPI_BAT1_LEFT, &val16)) {
1661 ret = -EIO;
1662 break;
1663 }
1664 if (copy_to_user(argp, &val16, sizeof(val16)))
1665 ret = -EFAULT;
1666 break;
1667 case SONYPI_IOCGBAT2CAP:
1668 if (ec_read16(SONYPI_BAT2_FULL, &val16)) {
1669 ret = -EIO;
1670 break;
1671 }
1672 if (copy_to_user(argp, &val16, sizeof(val16)))
1673 ret = -EFAULT;
1674 break;
1675 case SONYPI_IOCGBAT2REM:
1676 if (ec_read16(SONYPI_BAT2_LEFT, &val16)) {
1677 ret = -EIO;
1678 break;
1679 }
1680 if (copy_to_user(argp, &val16, sizeof(val16)))
1681 ret = -EFAULT;
1682 break;
1683 case SONYPI_IOCGBATFLAGS:
1684 if (ec_read(SONYPI_BAT_FLAGS, &val8)) {
1685 ret = -EIO;
1686 break;
1687 }
1688 val8 &= 0x07;
1689 if (copy_to_user(argp, &val8, sizeof(val8)))
1690 ret = -EFAULT;
1691 break;
1692 case SONYPI_IOCGBLUE:
1693 val8 = spic_dev.bluetooth_power;
1694 if (copy_to_user(argp, &val8, sizeof(val8)))
1695 ret = -EFAULT;
1696 break;
1697 case SONYPI_IOCSBLUE:
1698 if (copy_from_user(&val8, argp, sizeof(val8))) {
1699 ret = -EFAULT;
1700 break;
1701 }
1702 __sony_pic_set_bluetoothpower(val8);
1703 break;
1704 /* FAN Controls */
1705 case SONYPI_IOCGFAN:
1706 if (sony_pic_get_fanspeed(&val8)) {
1707 ret = -EIO;
1708 break;
1709 }
1710 if (copy_to_user(argp, &val8, sizeof(val8)))
1711 ret = -EFAULT;
1712 break;
1713 case SONYPI_IOCSFAN:
1714 if (copy_from_user(&val8, argp, sizeof(val8))) {
1715 ret = -EFAULT;
1716 break;
1717 }
1718 if (sony_pic_set_fanspeed(val8))
1719 ret = -EIO;
1720 break;
1721 /* GET Temperature (useful under APM) */
1722 case SONYPI_IOCGTEMP:
1723 if (ec_read(SONYPI_TEMP_STATUS, &val8)) {
1724 ret = -EIO;
1725 break;
1726 }
1727 if (copy_to_user(argp, &val8, sizeof(val8)))
1728 ret = -EFAULT;
1729 break;
1730 default:
1731 ret = -EINVAL;
1732 }
1733 mutex_unlock(&spic_dev.lock);
1734 return ret;
1735}
1736
1737static const struct file_operations sonypi_misc_fops = {
1738 .owner = THIS_MODULE,
1739 .read = sonypi_misc_read,
1740 .poll = sonypi_misc_poll,
1741 .open = sonypi_misc_open,
1742 .release = sonypi_misc_release,
1743 .fasync = sonypi_misc_fasync,
1744 .ioctl = sonypi_misc_ioctl,
1745};
1746
1747static struct miscdevice sonypi_misc_device = {
1748 .minor = MISC_DYNAMIC_MINOR,
1749 .name = "sonypi",
1750 .fops = &sonypi_misc_fops,
1751};
1752
1753static void sonypi_compat_report_event(u8 event)
1754{
1755 kfifo_put(sonypi_compat.fifo, (unsigned char *)&event, sizeof(event));
1756 kill_fasync(&sonypi_compat.fifo_async, SIGIO, POLL_IN);
1757 wake_up_interruptible(&sonypi_compat.fifo_proc_list);
1758}
1759
1760static int sonypi_compat_init(void)
1761{
1762 int error;
1763
1764 spin_lock_init(&sonypi_compat.fifo_lock);
1765 sonypi_compat.fifo = kfifo_alloc(SONY_LAPTOP_BUF_SIZE, GFP_KERNEL,
1766 &sonypi_compat.fifo_lock);
1767 if (IS_ERR(sonypi_compat.fifo)) {
1768 printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n");
1769 return PTR_ERR(sonypi_compat.fifo);
1770 }
1771
1772 init_waitqueue_head(&sonypi_compat.fifo_proc_list);
1773
1774 if (minor != -1)
1775 sonypi_misc_device.minor = minor;
1776 error = misc_register(&sonypi_misc_device);
1777 if (error) {
1778 printk(KERN_ERR DRV_PFX "misc_register failed\n");
1779 goto err_free_kfifo;
1780 }
1781 if (minor == -1)
1782 printk(KERN_INFO DRV_PFX "device allocated minor is %d\n",
1783 sonypi_misc_device.minor);
1784
1785 return 0;
1786
1787err_free_kfifo:
1788 kfifo_free(sonypi_compat.fifo);
1789 return error;
1790}
1791
1792static void sonypi_compat_exit(void)
1793{
1794 misc_deregister(&sonypi_misc_device);
1795 kfifo_free(sonypi_compat.fifo);
1796}
1797#else
1798static int sonypi_compat_init(void) { return 0; }
1799static void sonypi_compat_exit(void) { }
1800static void sonypi_compat_report_event(u8 event) { }
1801#endif /* CONFIG_SONY_LAPTOP_OLD */
1802
1803/*
1804 * ACPI callbacks
1805 */
1806static acpi_status
1807sony_pic_read_possible_resource(struct acpi_resource *resource, void *context)
1808{
1809 u32 i;
1810 struct sony_pic_dev *dev = (struct sony_pic_dev *)context;
1811
1812 switch (resource->type) {
1813 case ACPI_RESOURCE_TYPE_START_DEPENDENT:
1814 case ACPI_RESOURCE_TYPE_END_DEPENDENT:
1815 return AE_OK;
1816
1817 case ACPI_RESOURCE_TYPE_IRQ:
1818 {
1819 struct acpi_resource_irq *p = &resource->data.irq;
1820 struct sony_pic_irq *interrupt = NULL;
1821 if (!p || !p->interrupt_count) {
1822 /*
1823 * IRQ descriptors may have no IRQ# bits set,
1824 * particularly those those w/ _STA disabled
1825 */
1826 dprintk("Blank IRQ resource\n");
1827 return AE_OK;
1828 }
1829 for (i = 0; i < p->interrupt_count; i++) {
1830 if (!p->interrupts[i]) {
1831 printk(KERN_WARNING DRV_PFX
1832 "Invalid IRQ %d\n",
1833 p->interrupts[i]);
1834 continue;
1835 }
1836 interrupt = kzalloc(sizeof(*interrupt),
1837 GFP_KERNEL);
1838 if (!interrupt)
1839 return AE_ERROR;
1840
1841 list_add_tail(&interrupt->list, &dev->interrupts);
1842 interrupt->irq.triggering = p->triggering;
1843 interrupt->irq.polarity = p->polarity;
1844 interrupt->irq.sharable = p->sharable;
1845 interrupt->irq.interrupt_count = 1;
1846 interrupt->irq.interrupts[0] = p->interrupts[i];
1847 }
1848 return AE_OK;
1849 }
1850 case ACPI_RESOURCE_TYPE_IO:
1851 {
1852 struct acpi_resource_io *io = &resource->data.io;
1853 struct sony_pic_ioport *ioport = NULL;
1854 if (!io) {
1855 dprintk("Blank IO resource\n");
1856 return AE_OK;
1857 }
1858
1859 ioport = kzalloc(sizeof(*ioport), GFP_KERNEL);
1860 if (!ioport)
1861 return AE_ERROR;
1862
1863 list_add_tail(&ioport->list, &dev->ioports);
1864 memcpy(&ioport->io, io, sizeof(*io));
1865 return AE_OK;
1866 }
1867 default:
1868 dprintk("Resource %d isn't an IRQ nor an IO port\n",
1869 resource->type);
1870
1871 case ACPI_RESOURCE_TYPE_END_TAG:
1872 return AE_OK;
1873 }
1874 return AE_CTRL_TERMINATE;
1875}
1876
1877static int sony_pic_possible_resources(struct acpi_device *device)
1878{
1879 int result = 0;
1880 acpi_status status = AE_OK;
1881
1882 if (!device)
1883 return -EINVAL;
1884
1885 /* get device status */
1886 /* see acpi_pci_link_get_current acpi_pci_link_get_possible */
1887 dprintk("Evaluating _STA\n");
1888 result = acpi_bus_get_status(device);
1889 if (result) {
1890 printk(KERN_WARNING DRV_PFX "Unable to read status\n");
1891 goto end;
1892 }
1893
1894 if (!device->status.enabled)
1895 dprintk("Device disabled\n");
1896 else
1897 dprintk("Device enabled\n");
1898
1899 /*
1900 * Query and parse 'method'
1901 */
1902 dprintk("Evaluating %s\n", METHOD_NAME__PRS);
1903 status = acpi_walk_resources(device->handle, METHOD_NAME__PRS,
1904 sony_pic_read_possible_resource, &spic_dev);
1905 if (ACPI_FAILURE(status)) {
1906 printk(KERN_WARNING DRV_PFX
1907 "Failure evaluating %s\n",
1908 METHOD_NAME__PRS);
1909 result = -ENODEV;
1910 }
1911end:
1912 return result;
1913}
1914
1915/*
1916 * Disable the spic device by calling its _DIS method
1917 */
1918static int sony_pic_disable(struct acpi_device *device)
1919{
1920 if (ACPI_FAILURE(acpi_evaluate_object(device->handle, "_DIS", 0, NULL)))
1921 return -ENXIO;
1922
1923 dprintk("Device disabled\n");
1924 return 0;
1925}
1926
1927
1928/*
1929 * Based on drivers/acpi/pci_link.c:acpi_pci_link_set
1930 *
1931 * Call _SRS to set current resources
1932 */
1933static int sony_pic_enable(struct acpi_device *device,
1934 struct sony_pic_ioport *ioport, struct sony_pic_irq *irq)
1935{
1936 acpi_status status;
1937 int result = 0;
1938 struct {
1939 struct acpi_resource io_res;
1940 struct acpi_resource irq_res;
1941 struct acpi_resource end;
1942 } *resource;
1943 struct acpi_buffer buffer = { 0, NULL };
1944
1945 if (!ioport || !irq)
1946 return -EINVAL;
1947
1948 /* init acpi_buffer */
1949 resource = kzalloc(sizeof(*resource) + 1, GFP_KERNEL);
1950 if (!resource)
1951 return -ENOMEM;
1952
1953 buffer.length = sizeof(*resource) + 1;
1954 buffer.pointer = resource;
1955
1956 /* setup io resource */
1957 resource->io_res.type = ACPI_RESOURCE_TYPE_IO;
1958 resource->io_res.length = sizeof(struct acpi_resource);
1959 memcpy(&resource->io_res.data.io, &ioport->io,
1960 sizeof(struct acpi_resource_io));
1961
1962 /* setup irq resource */
1963 resource->irq_res.type = ACPI_RESOURCE_TYPE_IRQ;
1964 resource->irq_res.length = sizeof(struct acpi_resource);
1965 memcpy(&resource->irq_res.data.irq, &irq->irq,
1966 sizeof(struct acpi_resource_irq));
1967 /* we requested a shared irq */
1968 resource->irq_res.data.irq.sharable = ACPI_SHARED;
1969
1970 resource->end.type = ACPI_RESOURCE_TYPE_END_TAG;
1971
1972 /* Attempt to set the resource */
1973 dprintk("Evaluating _SRS\n");
1974 status = acpi_set_current_resources(device->handle, &buffer);
1975
1976 /* check for total failure */
1977 if (ACPI_FAILURE(status)) {
1978 printk(KERN_ERR DRV_PFX "Error evaluating _SRS");
1979 result = -ENODEV;
1980 goto end;
1981 }
1982
1983 /* Necessary device initializations calls (from sonypi) */
1984 sony_pic_call1(0x82);
1985 sony_pic_call2(0x81, 0xff);
1986 sony_pic_call1(compat ? 0x92 : 0x82);
1987
1988end:
1989 kfree(resource);
1990 return result;
1991}
1992
1993/*****************
1994 *
1995 * ISR: some event is available
1996 *
1997 *****************/
1998static irqreturn_t sony_pic_irq(int irq, void *dev_id)
1999{
2000 int i, j;
2001 u32 port_val = 0;
2002 u8 ev = 0;
2003 u8 data_mask = 0;
2004 u8 device_event = 0;
2005
2006 struct sony_pic_dev *dev = (struct sony_pic_dev *) dev_id;
2007
2008 acpi_os_read_port(dev->cur_ioport->io.minimum, &port_val,
2009 dev->cur_ioport->io.address_length);
2010 ev = port_val & SONY_PIC_EV_MASK;
2011 data_mask = 0xff & (port_val >> (dev->cur_ioport->io.address_length - 8));
2012
2013 dprintk("event (0x%.8x [%.2x] [%.2x]) at port 0x%.4x\n",
2014 port_val, ev, data_mask, dev->cur_ioport->io.minimum);
2015
2016 if (ev == 0x00 || ev == 0xff)
2017 return IRQ_HANDLED;
2018
2019 for (i = 0; sony_pic_eventtypes[i].model; i++) {
2020
2021 if (spic_dev.model != sony_pic_eventtypes[i].model)
2022 continue;
2023
2024 if ((data_mask & sony_pic_eventtypes[i].data) !=
2025 sony_pic_eventtypes[i].data)
2026 continue;
2027
2028 if (!(mask & sony_pic_eventtypes[i].mask))
2029 continue;
2030
2031 for (j = 0; sony_pic_eventtypes[i].events[j].event; j++) {
2032 if (ev == sony_pic_eventtypes[i].events[j].data) {
2033 device_event =
2034 sony_pic_eventtypes[i].events[j].event;
2035 goto found;
2036 }
2037 }
2038 }
2039 return IRQ_HANDLED;
2040
2041found:
2042 sony_laptop_report_input_event(device_event);
2043 acpi_bus_generate_event(spic_dev.acpi_dev, 1, device_event);
2044 sonypi_compat_report_event(device_event);
2045
2046 return IRQ_HANDLED;
2047}
2048
2049/*****************
2050 *
2051 * ACPI driver
2052 *
2053 *****************/
2054static int sony_pic_remove(struct acpi_device *device, int type)
2055{
2056 struct sony_pic_ioport *io, *tmp_io;
2057 struct sony_pic_irq *irq, *tmp_irq;
2058
2059 sonypi_compat_exit();
2060
2061 if (sony_pic_disable(device)) {
2062 printk(KERN_ERR DRV_PFX "Couldn't disable device.\n");
2063 return -ENXIO;
2064 }
2065
2066 free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
2067 release_region(spic_dev.cur_ioport->io.minimum,
2068 spic_dev.cur_ioport->io.address_length);
2069
2070 sony_laptop_remove_input();
2071
2072 /* pf attrs */
2073 sysfs_remove_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
2074 sony_pf_remove();
2075
2076 list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
2077 list_del(&io->list);
2078 kfree(io);
2079 }
2080 list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
2081 list_del(&irq->list);
2082 kfree(irq);
2083 }
2084 spic_dev.cur_ioport = NULL;
2085 spic_dev.cur_irq = NULL;
2086
2087 dprintk(SONY_PIC_DRIVER_NAME " removed.\n");
2088 return 0;
2089}
2090
2091static int sony_pic_add(struct acpi_device *device)
2092{
2093 int result;
2094 struct sony_pic_ioport *io, *tmp_io;
2095 struct sony_pic_irq *irq, *tmp_irq;
2096
2097 printk(KERN_INFO DRV_PFX "%s v%s.\n",
2098 SONY_PIC_DRIVER_NAME, SONY_LAPTOP_DRIVER_VERSION);
2099
2100 spic_dev.acpi_dev = device;
2101 strcpy(acpi_device_class(device), "sony/hotkey");
2102 spic_dev.model = sony_pic_detect_device_type();
2103 mutex_init(&spic_dev.lock);
2104
2105 /* read _PRS resources */
2106 result = sony_pic_possible_resources(device);
2107 if (result) {
2108 printk(KERN_ERR DRV_PFX
2109 "Unabe to read possible resources.\n");
2110 goto err_free_resources;
2111 }
2112
2113 /* setup input devices and helper fifo */
2114 result = sony_laptop_setup_input();
2115 if (result) {
2116 printk(KERN_ERR DRV_PFX
2117 "Unabe to create input devices.\n");
2118 goto err_free_resources;
2119 }
2120
2121 /* request io port */
2122 list_for_each_entry(io, &spic_dev.ioports, list) {
2123 if (request_region(io->io.minimum, io->io.address_length,
2124 "Sony Programable I/O Device")) {
2125 dprintk("I/O port: 0x%.4x (0x%.4x) + 0x%.2x\n",
2126 io->io.minimum, io->io.maximum,
2127 io->io.address_length);
2128 spic_dev.cur_ioport = io;
2129 break;
2130 }
2131 }
2132 if (!spic_dev.cur_ioport) {
2133 printk(KERN_ERR DRV_PFX "Failed to request_region.\n");
2134 result = -ENODEV;
2135 goto err_remove_input;
2136 }
2137
2138 /* request IRQ */
2139 list_for_each_entry(irq, &spic_dev.interrupts, list) {
2140 if (!request_irq(irq->irq.interrupts[0], sony_pic_irq,
2141 IRQF_SHARED, "sony-laptop", &spic_dev)) {
2142 dprintk("IRQ: %d - triggering: %d - "
2143 "polarity: %d - shr: %d\n",
2144 irq->irq.interrupts[0],
2145 irq->irq.triggering,
2146 irq->irq.polarity,
2147 irq->irq.sharable);
2148 spic_dev.cur_irq = irq;
2149 break;
2150 }
2151 }
2152 if (!spic_dev.cur_irq) {
2153 printk(KERN_ERR DRV_PFX "Failed to request_irq.\n");
2154 result = -ENODEV;
2155 goto err_release_region;
2156 }
2157
2158 /* set resource status _SRS */
2159 result = sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
2160 if (result) {
2161 printk(KERN_ERR DRV_PFX "Couldn't enable device.\n");
2162 goto err_free_irq;
2163 }
2164
2165 spic_dev.bluetooth_power = -1;
2166 /* create device attributes */
2167 result = sony_pf_add();
2168 if (result)
2169 goto err_disable_device;
2170
2171 result = sysfs_create_group(&sony_pf_device->dev.kobj, &spic_attribute_group);
2172 if (result)
2173 goto err_remove_pf;
2174
2175 if (sonypi_compat_init())
2176 goto err_remove_pf;
2177
2178 return 0;
2179
2180err_remove_pf:
2181 sony_pf_remove();
2182
2183err_disable_device:
2184 sony_pic_disable(device);
2185
2186err_free_irq:
2187 free_irq(spic_dev.cur_irq->irq.interrupts[0], &spic_dev);
2188
2189err_release_region:
2190 release_region(spic_dev.cur_ioport->io.minimum,
2191 spic_dev.cur_ioport->io.address_length);
2192
2193err_remove_input:
2194 sony_laptop_remove_input();
2195
2196err_free_resources:
2197 list_for_each_entry_safe(io, tmp_io, &spic_dev.ioports, list) {
2198 list_del(&io->list);
2199 kfree(io);
2200 }
2201 list_for_each_entry_safe(irq, tmp_irq, &spic_dev.interrupts, list) {
2202 list_del(&irq->list);
2203 kfree(irq);
2204 }
2205 spic_dev.cur_ioport = NULL;
2206 spic_dev.cur_irq = NULL;
2207
2208 return result;
2209}
2210
2211static int sony_pic_suspend(struct acpi_device *device, pm_message_t state)
2212{
2213 if (sony_pic_disable(device))
2214 return -ENXIO;
2215 return 0;
2216}
2217
2218static int sony_pic_resume(struct acpi_device *device)
2219{
2220 sony_pic_enable(device, spic_dev.cur_ioport, spic_dev.cur_irq);
2221 return 0;
2222}
2223
2224static struct acpi_driver sony_pic_driver = {
2225 .name = SONY_PIC_DRIVER_NAME,
2226 .class = SONY_PIC_CLASS,
2227 .ids = SONY_PIC_HID,
2228 .owner = THIS_MODULE,
2229 .ops = {
2230 .add = sony_pic_add,
2231 .remove = sony_pic_remove,
2232 .suspend = sony_pic_suspend,
2233 .resume = sony_pic_resume,
2234 },
2235};
2236
2237static struct dmi_system_id __initdata sonypi_dmi_table[] = {
2238 {
2239 .ident = "Sony Vaio",
2240 .matches = {
2241 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
2242 DMI_MATCH(DMI_PRODUCT_NAME, "PCG-"),
2243 },
2244 },
2245 {
2246 .ident = "Sony Vaio",
2247 .matches = {
2248 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
2249 DMI_MATCH(DMI_PRODUCT_NAME, "VGN-"),
2250 },
2251 },
2252 { }
2253};
2254
2255static int __init sony_laptop_init(void)
2256{
2257 int result;
2258
2259 if (!no_spic && dmi_check_system(sonypi_dmi_table)) {
2260 result = acpi_bus_register_driver(&sony_pic_driver);
2261 if (result) {
2262 printk(KERN_ERR DRV_PFX
2263 "Unable to register SPIC driver.");
2264 goto out;
2265 }
2266 }
2267
2268 result = acpi_bus_register_driver(&sony_nc_driver);
2269 if (result) {
2270 printk(KERN_ERR DRV_PFX "Unable to register SNC driver.");
2271 goto out_unregister_pic;
2272 }
2273
2274 return 0;
2275
2276out_unregister_pic:
2277 if (!no_spic)
2278 acpi_bus_unregister_driver(&sony_pic_driver);
2279out:
2280 return result;
556} 2281}
557 2282
558static void __exit sony_acpi_exit(void) 2283static void __exit sony_laptop_exit(void)
559{ 2284{
560 acpi_bus_unregister_driver(&sony_acpi_driver); 2285 acpi_bus_unregister_driver(&sony_nc_driver);
2286 if (!no_spic)
2287 acpi_bus_unregister_driver(&sony_pic_driver);
561} 2288}
562 2289
563module_init(sony_acpi_init); 2290module_init(sony_laptop_init);
564module_exit(sony_acpi_exit); 2291module_exit(sony_laptop_exit);
diff --git a/include/linux/sony-laptop.h b/include/linux/sony-laptop.h
new file mode 100644
index 000000000000..e2e036d94e4a
--- /dev/null
+++ b/include/linux/sony-laptop.h
@@ -0,0 +1,34 @@
1#ifndef _SONYLAPTOP_H_
2#define _SONYLAPTOP_H_
3
4#include <linux/types.h>
5
6#ifdef __KERNEL__
7
8/* used only for communication between v4l and sony-laptop */
9
10#define SONY_PIC_COMMAND_GETCAMERA 1 /* obsolete */
11#define SONY_PIC_COMMAND_SETCAMERA 2
12#define SONY_PIC_COMMAND_GETCAMERABRIGHTNESS 3 /* obsolete */
13#define SONY_PIC_COMMAND_SETCAMERABRIGHTNESS 4
14#define SONY_PIC_COMMAND_GETCAMERACONTRAST 5 /* obsolete */
15#define SONY_PIC_COMMAND_SETCAMERACONTRAST 6
16#define SONY_PIC_COMMAND_GETCAMERAHUE 7 /* obsolete */
17#define SONY_PIC_COMMAND_SETCAMERAHUE 8
18#define SONY_PIC_COMMAND_GETCAMERACOLOR 9 /* obsolete */
19#define SONY_PIC_COMMAND_SETCAMERACOLOR 10
20#define SONY_PIC_COMMAND_GETCAMERASHARPNESS 11 /* obsolete */
21#define SONY_PIC_COMMAND_SETCAMERASHARPNESS 12
22#define SONY_PIC_COMMAND_GETCAMERAPICTURE 13 /* obsolete */
23#define SONY_PIC_COMMAND_SETCAMERAPICTURE 14
24#define SONY_PIC_COMMAND_GETCAMERAAGC 15 /* obsolete */
25#define SONY_PIC_COMMAND_SETCAMERAAGC 16
26#define SONY_PIC_COMMAND_GETCAMERADIRECTION 17 /* obsolete */
27#define SONY_PIC_COMMAND_GETCAMERAROMVERSION 18 /* obsolete */
28#define SONY_PIC_COMMAND_GETCAMERAREVISION 19 /* obsolete */
29
30int sony_pic_camera_command(int command, u8 value);
31
32#endif /* __KERNEL__ */
33
34#endif /* _SONYLAPTOP_H_ */