diff options
Diffstat (limited to 'drivers/misc/sony-laptop.c')
-rw-r--r-- | drivers/misc/sony-laptop.c | 2781 |
1 files changed, 0 insertions, 2781 deletions
diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c deleted file mode 100644 index 571b211608d..00000000000 --- a/drivers/misc/sony-laptop.c +++ /dev/null @@ -1,2781 +0,0 @@ -/* - * ACPI Sony Notebook Control Driver (SNC and SPIC) - * - * Copyright (C) 2004-2005 Stelian Pop <stelian@popies.net> - * Copyright (C) 2007 Mattia Dongili <malattia@linux.it> - * - * Parts of this driver inspired from asus_acpi.c and ibm_acpi.c - * which are copyrighted by their respective authors. - * - * The SNY6001 driver part is based on the sonypi driver which includes - * material from: - * - * Copyright (C) 2001-2005 Stelian Pop <stelian@popies.net> - * - * Copyright (C) 2005 Narayanan R S <nars@kadamba.org> - * - * Copyright (C) 2001-2002 AlcĂ´ve <www.alcove.com> - * - * Copyright (C) 2001 Michael Ashley <m.ashley@unsw.edu.au> - * - * Copyright (C) 2001 Junichi Morita <jun1m@mars.dti.ne.jp> - * - * Copyright (C) 2000 Takaya Kinjo <t-kinjo@tc4.so-net.ne.jp> - * - * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com> - * - * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#include <linux/kernel.h> -#include <linux/module.h> -#include <linux/moduleparam.h> -#include <linux/init.h> -#include <linux/smp_lock.h> -#include <linux/types.h> -#include <linux/backlight.h> -#include <linux/platform_device.h> -#include <linux/err.h> -#include <linux/dmi.h> -#include <linux/pci.h> -#include <linux/interrupt.h> -#include <linux/delay.h> -#include <linux/input.h> -#include <linux/kfifo.h> -#include <linux/workqueue.h> -#include <linux/acpi.h> -#include <acpi/acpi_drivers.h> -#include <acpi/acpi_bus.h> -#include <asm/uaccess.h> -#include <linux/sonypi.h> -#include <linux/sony-laptop.h> -#ifdef CONFIG_SONYPI_COMPAT -#include <linux/poll.h> -#include <linux/miscdevice.h> -#endif - -#define DRV_PFX "sony-laptop: " -#define dprintk(msg...) do { \ - if (debug) printk(KERN_WARNING DRV_PFX msg); \ -} while (0) - -#define SONY_LAPTOP_DRIVER_VERSION "0.6" - -#define SONY_NC_CLASS "sony-nc" -#define SONY_NC_HID "SNY5001" -#define SONY_NC_DRIVER_NAME "Sony Notebook Control Driver" - -#define SONY_PIC_CLASS "sony-pic" -#define SONY_PIC_HID "SNY6001" -#define SONY_PIC_DRIVER_NAME "Sony Programmable IO Control Driver" - -MODULE_AUTHOR("Stelian Pop, Mattia Dongili"); -MODULE_DESCRIPTION("Sony laptop extras driver (SPIC and SNC ACPI device)"); -MODULE_LICENSE("GPL"); -MODULE_VERSION(SONY_LAPTOP_DRIVER_VERSION); - -static int debug; -module_param(debug, int, 0); -MODULE_PARM_DESC(debug, "set this to 1 (and RTFM) if you want to help " - "the development of this driver"); - -static int no_spic; /* = 0 */ -module_param(no_spic, int, 0444); -MODULE_PARM_DESC(no_spic, - "set this if you don't want to enable the SPIC device"); - -static int compat; /* = 0 */ -module_param(compat, int, 0444); -MODULE_PARM_DESC(compat, - "set this if you want to enable backward compatibility mode"); - -static unsigned long mask = 0xffffffff; -module_param(mask, ulong, 0644); -MODULE_PARM_DESC(mask, - "set this to the mask of event you want to enable (see doc)"); - -static int camera; /* = 0 */ -module_param(camera, int, 0444); -MODULE_PARM_DESC(camera, - "set this to 1 to enable Motion Eye camera controls " - "(only use it if you have a C1VE or C1VN model)"); - -#ifdef CONFIG_SONYPI_COMPAT -static int minor = -1; -module_param(minor, int, 0); -MODULE_PARM_DESC(minor, - "minor number of the misc device for the SPIC compatibility code, " - "default is -1 (automatic)"); -#endif - -/*********** Input Devices ***********/ - -#define SONY_LAPTOP_BUF_SIZE 128 -struct sony_laptop_input_s { - atomic_t users; - struct input_dev *jog_dev; - struct input_dev *key_dev; - struct kfifo *fifo; - spinlock_t fifo_lock; - struct workqueue_struct *wq; -}; -static struct sony_laptop_input_s sony_laptop_input = { - .users = ATOMIC_INIT(0), -}; - -struct sony_laptop_keypress { - struct input_dev *dev; - int key; -}; - -/* Correspondance table between sonypi events - * and input layer indexes in the keymap - */ -static int sony_laptop_input_index[] = { - -1, /* 0 no event */ - -1, /* 1 SONYPI_EVENT_JOGDIAL_DOWN */ - -1, /* 2 SONYPI_EVENT_JOGDIAL_UP */ - -1, /* 3 SONYPI_EVENT_JOGDIAL_DOWN_PRESSED */ - -1, /* 4 SONYPI_EVENT_JOGDIAL_UP_PRESSED */ - -1, /* 5 SONYPI_EVENT_JOGDIAL_PRESSED */ - -1, /* 6 SONYPI_EVENT_JOGDIAL_RELEASED */ - 0, /* 7 SONYPI_EVENT_CAPTURE_PRESSED */ - 1, /* 8 SONYPI_EVENT_CAPTURE_RELEASED */ - 2, /* 9 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */ - 3, /* 10 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */ - 4, /* 11 SONYPI_EVENT_FNKEY_ESC */ - 5, /* 12 SONYPI_EVENT_FNKEY_F1 */ - 6, /* 13 SONYPI_EVENT_FNKEY_F2 */ - 7, /* 14 SONYPI_EVENT_FNKEY_F3 */ - 8, /* 15 SONYPI_EVENT_FNKEY_F4 */ - 9, /* 16 SONYPI_EVENT_FNKEY_F5 */ - 10, /* 17 SONYPI_EVENT_FNKEY_F6 */ - 11, /* 18 SONYPI_EVENT_FNKEY_F7 */ - 12, /* 19 SONYPI_EVENT_FNKEY_F8 */ - 13, /* 20 SONYPI_EVENT_FNKEY_F9 */ - 14, /* 21 SONYPI_EVENT_FNKEY_F10 */ - 15, /* 22 SONYPI_EVENT_FNKEY_F11 */ - 16, /* 23 SONYPI_EVENT_FNKEY_F12 */ - 17, /* 24 SONYPI_EVENT_FNKEY_1 */ - 18, /* 25 SONYPI_EVENT_FNKEY_2 */ - 19, /* 26 SONYPI_EVENT_FNKEY_D */ - 20, /* 27 SONYPI_EVENT_FNKEY_E */ - 21, /* 28 SONYPI_EVENT_FNKEY_F */ - 22, /* 29 SONYPI_EVENT_FNKEY_S */ - 23, /* 30 SONYPI_EVENT_FNKEY_B */ - 24, /* 31 SONYPI_EVENT_BLUETOOTH_PRESSED */ - 25, /* 32 SONYPI_EVENT_PKEY_P1 */ - 26, /* 33 SONYPI_EVENT_PKEY_P2 */ - 27, /* 34 SONYPI_EVENT_PKEY_P3 */ - 28, /* 35 SONYPI_EVENT_BACK_PRESSED */ - -1, /* 36 SONYPI_EVENT_LID_CLOSED */ - -1, /* 37 SONYPI_EVENT_LID_OPENED */ - 29, /* 38 SONYPI_EVENT_BLUETOOTH_ON */ - 30, /* 39 SONYPI_EVENT_BLUETOOTH_OFF */ - 31, /* 40 SONYPI_EVENT_HELP_PRESSED */ - 32, /* 41 SONYPI_EVENT_FNKEY_ONLY */ - 33, /* 42 SONYPI_EVENT_JOGDIAL_FAST_DOWN */ - 34, /* 43 SONYPI_EVENT_JOGDIAL_FAST_UP */ - 35, /* 44 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */ - 36, /* 45 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */ - 37, /* 46 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */ - 38, /* 47 SONYPI_EVENT_JOGDIAL_VFAST_UP */ - 39, /* 48 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */ - 40, /* 49 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */ - 41, /* 50 SONYPI_EVENT_ZOOM_PRESSED */ - 42, /* 51 SONYPI_EVENT_THUMBPHRASE_PRESSED */ - 43, /* 52 SONYPI_EVENT_MEYE_FACE */ - 44, /* 53 SONYPI_EVENT_MEYE_OPPOSITE */ - 45, /* 54 SONYPI_EVENT_MEMORYSTICK_INSERT */ - 46, /* 55 SONYPI_EVENT_MEMORYSTICK_EJECT */ - -1, /* 56 SONYPI_EVENT_ANYBUTTON_RELEASED */ - -1, /* 57 SONYPI_EVENT_BATTERY_INSERT */ - -1, /* 58 SONYPI_EVENT_BATTERY_REMOVE */ - -1, /* 59 SONYPI_EVENT_FNKEY_RELEASED */ - 47, /* 60 SONYPI_EVENT_WIRELESS_ON */ - 48, /* 61 SONYPI_EVENT_WIRELESS_OFF */ - 49, /* 62 SONYPI_EVENT_ZOOM_IN_PRESSED */ - 50, /* 63 SONYPI_EVENT_ZOOM_OUT_PRESSED */ -}; - -static int sony_laptop_input_keycode_map[] = { - KEY_CAMERA, /* 0 SONYPI_EVENT_CAPTURE_PRESSED */ - KEY_RESERVED, /* 1 SONYPI_EVENT_CAPTURE_RELEASED */ - KEY_RESERVED, /* 2 SONYPI_EVENT_CAPTURE_PARTIALPRESSED */ - KEY_RESERVED, /* 3 SONYPI_EVENT_CAPTURE_PARTIALRELEASED */ - KEY_FN_ESC, /* 4 SONYPI_EVENT_FNKEY_ESC */ - KEY_FN_F1, /* 5 SONYPI_EVENT_FNKEY_F1 */ - KEY_FN_F2, /* 6 SONYPI_EVENT_FNKEY_F2 */ - KEY_FN_F3, /* 7 SONYPI_EVENT_FNKEY_F3 */ - KEY_FN_F4, /* 8 SONYPI_EVENT_FNKEY_F4 */ - KEY_FN_F5, /* 9 SONYPI_EVENT_FNKEY_F5 */ - KEY_FN_F6, /* 10 SONYPI_EVENT_FNKEY_F6 */ - KEY_FN_F7, /* 11 SONYPI_EVENT_FNKEY_F7 */ - KEY_FN_F8, /* 12 SONYPI_EVENT_FNKEY_F8 */ - KEY_FN_F9, /* 13 SONYPI_EVENT_FNKEY_F9 */ - KEY_FN_F10, /* 14 SONYPI_EVENT_FNKEY_F10 */ - KEY_FN_F11, /* 15 SONYPI_EVENT_FNKEY_F11 */ - KEY_FN_F12, /* 16 SONYPI_EVENT_FNKEY_F12 */ - KEY_FN_F1, /* 17 SONYPI_EVENT_FNKEY_1 */ - KEY_FN_F2, /* 18 SONYPI_EVENT_FNKEY_2 */ - KEY_FN_D, /* 19 SONYPI_EVENT_FNKEY_D */ - KEY_FN_E, /* 20 SONYPI_EVENT_FNKEY_E */ - KEY_FN_F, /* 21 SONYPI_EVENT_FNKEY_F */ - KEY_FN_S, /* 22 SONYPI_EVENT_FNKEY_S */ - KEY_FN_B, /* 23 SONYPI_EVENT_FNKEY_B */ - KEY_BLUETOOTH, /* 24 SONYPI_EVENT_BLUETOOTH_PRESSED */ - KEY_PROG1, /* 25 SONYPI_EVENT_PKEY_P1 */ - KEY_PROG2, /* 26 SONYPI_EVENT_PKEY_P2 */ - KEY_PROG3, /* 27 SONYPI_EVENT_PKEY_P3 */ - KEY_BACK, /* 28 SONYPI_EVENT_BACK_PRESSED */ - KEY_BLUETOOTH, /* 29 SONYPI_EVENT_BLUETOOTH_ON */ - KEY_BLUETOOTH, /* 30 SONYPI_EVENT_BLUETOOTH_OFF */ - KEY_HELP, /* 31 SONYPI_EVENT_HELP_PRESSED */ - KEY_FN, /* 32 SONYPI_EVENT_FNKEY_ONLY */ - KEY_RESERVED, /* 33 SONYPI_EVENT_JOGDIAL_FAST_DOWN */ - KEY_RESERVED, /* 34 SONYPI_EVENT_JOGDIAL_FAST_UP */ - KEY_RESERVED, /* 35 SONYPI_EVENT_JOGDIAL_FAST_DOWN_PRESSED */ - KEY_RESERVED, /* 36 SONYPI_EVENT_JOGDIAL_FAST_UP_PRESSED */ - KEY_RESERVED, /* 37 SONYPI_EVENT_JOGDIAL_VFAST_DOWN */ - KEY_RESERVED, /* 38 SONYPI_EVENT_JOGDIAL_VFAST_UP */ - KEY_RESERVED, /* 39 SONYPI_EVENT_JOGDIAL_VFAST_DOWN_PRESSED */ - KEY_RESERVED, /* 40 SONYPI_EVENT_JOGDIAL_VFAST_UP_PRESSED */ - KEY_ZOOM, /* 41 SONYPI_EVENT_ZOOM_PRESSED */ - BTN_THUMB, /* 42 SONYPI_EVENT_THUMBPHRASE_PRESSED */ - KEY_RESERVED, /* 43 SONYPI_EVENT_MEYE_FACE */ - KEY_RESERVED, /* 44 SONYPI_EVENT_MEYE_OPPOSITE */ - KEY_RESERVED, /* 45 SONYPI_EVENT_MEMORYSTICK_INSERT */ - KEY_RESERVED, /* 46 SONYPI_EVENT_MEMORYSTICK_EJECT */ - KEY_WLAN, /* 47 SONYPI_EVENT_WIRELESS_ON */ - KEY_WLAN, /* 48 SONYPI_EVENT_WIRELESS_OFF */ - KEY_ZOOMIN, /* 49 SONYPI_EVENT_ZOOM_IN_PRESSED */ - KEY_ZOOMOUT /* 50 SONYPI_EVENT_ZOOM_OUT_PRESSED */ -}; - -/* release buttons after a short delay if pressed */ -static void do_sony_laptop_release_key(struct work_struct *work) -{ - struct sony_laptop_keypress kp; - - while (kfifo_get(sony_laptop_input.fifo, (unsigned char *)&kp, - sizeof(kp)) == sizeof(kp)) { - msleep(10); - input_report_key(kp.dev, kp.key, 0); - input_sync(kp.dev); - } -} -static DECLARE_WORK(sony_laptop_release_key_work, - do_sony_laptop_release_key); - -/* forward event to the input subsystem */ -static void sony_laptop_report_input_event(u8 event) -{ - struct input_dev *jog_dev = sony_laptop_input.jog_dev; - struct input_dev *key_dev = sony_laptop_input.key_dev; - struct sony_laptop_keypress kp = { NULL }; - - if (event == SONYPI_EVENT_FNKEY_RELEASED) { - /* Nothing, not all VAIOs generate this event */ - return; - } - - /* report events */ - switch (event) { - /* jog_dev events */ - case SONYPI_EVENT_JOGDIAL_UP: - case SONYPI_EVENT_JOGDIAL_UP_PRESSED: - input_report_rel(jog_dev, REL_WHEEL, 1); - input_sync(jog_dev); - return; - - case SONYPI_EVENT_JOGDIAL_DOWN: - case SONYPI_EVENT_JOGDIAL_DOWN_PRESSED: - input_report_rel(jog_dev, REL_WHEEL, -1); - input_sync(jog_dev); - return; - - /* key_dev events */ - case SONYPI_EVENT_JOGDIAL_PRESSED: - kp.key = BTN_MIDDLE; - kp.dev = jog_dev; - break; - - default: - if (event >= ARRAY_SIZE(sony_laptop_input_index)) { - dprintk("sony_laptop_report_input_event, event not known: %d\n", event); - break; - } - if (sony_laptop_input_index[event] != -1) { - kp.key = sony_laptop_input_keycode_map[sony_laptop_input_index[event]]; - if (kp.key != KEY_UNKNOWN) - kp.dev = key_dev; - } - break; - } - - if (kp.dev) { - input_report_key(kp.dev, kp.key, 1); - /* we emit the scancode so we can always remap the key */ - input_event(kp.dev, EV_MSC, MSC_SCAN, event); - input_sync(kp.dev); - kfifo_put(sony_laptop_input.fifo, - (unsigned char *)&kp, sizeof(kp)); - - if (!work_pending(&sony_laptop_release_key_work)) - queue_work(sony_laptop_input.wq, - &sony_laptop_release_key_work); - } else - dprintk("unknown input event %.2x\n", event); -} - -static int sony_laptop_setup_input(struct acpi_device *acpi_device) -{ - struct input_dev *jog_dev; - struct input_dev *key_dev; - int i; - int error; - - /* don't run again if already initialized */ - if (atomic_add_return(1, &sony_laptop_input.users) > 1) - return 0; - - /* kfifo */ - spin_lock_init(&sony_laptop_input.fifo_lock); - sony_laptop_input.fifo = - kfifo_alloc(SONY_LAPTOP_BUF_SIZE, GFP_KERNEL, - &sony_laptop_input.fifo_lock); - if (IS_ERR(sony_laptop_input.fifo)) { - printk(KERN_ERR DRV_PFX "kfifo_alloc failed\n"); - error = PTR_ERR(sony_laptop_input.fifo); - goto err_dec_users; - } - - /* init workqueue */ - sony_laptop_input.wq = create_singlethread_workqueue("sony-laptop"); - if (!sony_laptop_input.wq) { - printk(KERN_ERR DRV_PFX - "Unabe to create workqueue.\n"); - error = -ENXIO; - goto err_free_kfifo; - } - - /* input keys */ - key_dev = input_allocate_device(); - if (!key_dev) { - error = -ENOMEM; - goto err_destroy_wq; - } - - key_dev->name = "Sony Vaio Keys"; - key_dev->id.bustype = BUS_ISA; - key_dev->id.vendor = PCI_VENDOR_ID_SONY; - key_dev->dev.parent = &acpi_device->dev; - - /* Initialize the Input Drivers: special keys */ - set_bit(EV_KEY, key_dev->evbit); - set_bit(EV_MSC, key_dev->evbit); - set_bit(MSC_SCAN, key_dev->mscbit); - key_dev->keycodesize = sizeof(sony_laptop_input_keycode_map[0]); - key_dev->keycodemax = ARRAY_SIZE(sony_laptop_input_keycode_map); - key_dev->keycode = &sony_laptop_input_keycode_map; - for (i = 0; i < ARRAY_SIZE(sony_laptop_input_keycode_map); i++) { - if (sony_laptop_input_keycode_map[i] != KEY_RESERVED) { - set_bit(sony_laptop_input_keycode_map[i], - key_dev->keybit); - } - } - - error = input_register_device(key_dev); - if (error) - goto err_free_keydev; - - sony_laptop_input.key_dev = key_dev; - - /* jogdial */ - jog_dev = input_allocate_device(); - if (!jog_dev) { - error = -ENOMEM; - goto err_unregister_keydev; - } - - jog_dev->name = "Sony Vaio Jogdial"; - jog_dev->id.bustype = BUS_ISA; - jog_dev->id.vendor = PCI_VENDOR_ID_SONY; - key_dev->dev.parent = &acpi_device->dev; - - jog_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); - jog_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_MIDDLE); - jog_dev->relbit[0] = BIT_MASK(REL_WHEEL); - - error = input_register_device(jog_dev); - if (error) - goto err_free_jogdev; - - sony_laptop_input.jog_dev = jog_dev; - - return 0; - -err_free_jogdev: - input_free_device(jog_dev); - -err_unregister_keydev: - input_unregister_device(key_dev); - /* to avoid kref underflow below at input_free_device */ - key_dev = NULL; - -err_free_keydev: - input_free_device(key_dev); - -err_destroy_wq: - destroy_workqueue(sony_laptop_input.wq); - -err_free_kfifo: - kfifo_free(sony_laptop_input.fifo); - -err_dec_users: - atomic_dec(&sony_laptop_input.users); - return error; -} - -static void sony_laptop_remove_input(void) -{ - /* cleanup only after the last user has gone */ - if (!atomic_dec_and_test(&sony_laptop_input.users)) - return; - - /* flush workqueue first */ - flush_workqueue(sony_laptop_input.wq); - - /* destroy input devs */ - input_unregister_device(sony_laptop_input.key_dev); - sony_laptop_input.key_dev = NULL; - - if (sony_laptop_input.jog_dev) { - input_unregister_device(sony_laptop_input.jog_dev); - sony_laptop_input.jog_dev = NULL; - } - - destroy_workqueue(sony_laptop_input.wq); - kfifo_free(sony_laptop_input.fifo); -} - -/*********** Platform Device ***********/ - -static atomic_t sony_pf_users = ATOMIC_INIT(0); -static struct platform_driver sony_pf_driver = { - .driver = { - .name = "sony-laptop", - .owner = THIS_MODULE, - } -}; -static struct platform_device *sony_pf_device; - -static int sony_pf_add(void) -{ - int ret = 0; - - /* don't run again if already initialized */ - if (atomic_add_return(1, &sony_pf_users) > 1) - return 0; - - ret = platform_driver_register(&sony_pf_driver); - if (ret) - goto out; - - sony_pf_device = platform_device_alloc("sony-laptop", -1); - if (!sony_pf_device) { - ret = -ENOMEM; - goto out_platform_registered; - } - - ret = platform_device_add(sony_pf_device); - if (ret) - goto out_platform_alloced; - - return 0; - - out_platform_alloced: - platform_device_put(sony_pf_device); - sony_pf_device = NULL; - out_platform_registered: - platform_driver_unregister(&sony_pf_driver); - out: - atomic_dec(&sony_pf_users); - return ret; -} - -static void sony_pf_remove(void) -{ - /* deregister only after the last user has gone */ - if (!atomic_dec_and_test(&sony_pf_users)) - return; - - platform_device_del(sony_pf_device); - platform_device_put(sony_pf_device); - platform_driver_unregister(&sony_pf_driver); -} - -/*********** SNC (SNY5001) Device ***********/ - -/* the device uses 1-based values, while the backlight subsystem uses - 0-based values */ -#define SONY_MAX_BRIGHTNESS 8 - -#define SNC_VALIDATE_IN 0 -#define SNC_VALIDATE_OUT 1 - -static ssize_t sony_nc_sysfs_show(struct device *, struct device_attribute *, - char *); -static ssize_t sony_nc_sysfs_store(struct device *, struct device_attribute *, - const char *, size_t); -static int boolean_validate(const int, const int); -static int brightness_default_validate(const int, const int); - -struct sony_nc_value { - char *name; /* name of the entry */ - char **acpiget; /* names of the ACPI get function */ - char **acpiset; /* names of the ACPI set function */ - int (*validate)(const int, const int); /* input/output validation */ - int value; /* current setting */ - int valid; /* Has ever been set */ - int debug; /* active only in debug mode ? */ - struct device_attribute devattr; /* sysfs atribute */ -}; - -#define SNC_HANDLE_NAMES(_name, _values...) \ - static char *snc_##_name[] = { _values, NULL } - -#define SNC_HANDLE(_name, _getters, _setters, _validate, _debug) \ - { \ - .name = __stringify(_name), \ - .acpiget = _getters, \ - .acpiset = _setters, \ - .validate = _validate, \ - .debug = _debug, \ - .devattr = __ATTR(_name, 0, sony_nc_sysfs_show, sony_nc_sysfs_store), \ - } - -#define SNC_HANDLE_NULL { .name = NULL } - -SNC_HANDLE_NAMES(fnkey_get, "GHKE"); - -SNC_HANDLE_NAMES(brightness_def_get, "GPBR"); -SNC_HANDLE_NAMES(brightness_def_set, "SPBR"); - -SNC_HANDLE_NAMES(cdpower_get, "GCDP"); -SNC_HANDLE_NAMES(cdpower_set, "SCDP", "CDPW"); - -SNC_HANDLE_NAMES(audiopower_get, "GAZP"); -SNC_HANDLE_NAMES(audiopower_set, "AZPW"); - -SNC_HANDLE_NAMES(lanpower_get, "GLNP"); -SNC_HANDLE_NAMES(lanpower_set, "LNPW"); - -SNC_HANDLE_NAMES(lidstate_get, "GLID"); - -SNC_HANDLE_NAMES(indicatorlamp_get, "GILS"); -SNC_HANDLE_NAMES(indicatorlamp_set, "SILS"); - -SNC_HANDLE_NAMES(gainbass_get, "GMGB"); -SNC_HANDLE_NAMES(gainbass_set, "CMGB"); - -SNC_HANDLE_NAMES(PID_get, "GPID"); - -SNC_HANDLE_NAMES(CTR_get, "GCTR"); -SNC_HANDLE_NAMES(CTR_set, "SCTR"); - -SNC_HANDLE_NAMES(PCR_get, "GPCR"); -SNC_HANDLE_NAMES(PCR_set, "SPCR"); - -SNC_HANDLE_NAMES(CMI_get, "GCMI"); -SNC_HANDLE_NAMES(CMI_set, "SCMI"); - -static struct sony_nc_value sony_nc_values[] = { - SNC_HANDLE(brightness_default, snc_brightness_def_get, - snc_brightness_def_set, brightness_default_validate, 0), - SNC_HANDLE(fnkey, snc_fnkey_get, NULL, NULL, 0), - SNC_HANDLE(cdpower, snc_cdpower_get, snc_cdpower_set, boolean_validate, 0), - SNC_HANDLE(audiopower, snc_audiopower_get, snc_audiopower_set, - boolean_validate, 0), - SNC_HANDLE(lanpower, snc_lanpower_get, snc_lanpower_set, - boolean_validate, 1), - SNC_HANDLE(lidstate, snc_lidstate_get, NULL, - boolean_validate, 0), - SNC_HANDLE(indicatorlamp, snc_indicatorlamp_get, snc_indicatorlamp_set, - boolean_validate, 0), - SNC_HANDLE(gainbass, snc_gainbass_get, snc_gainbass_set, - boolean_validate, 0), - /* unknown methods */ - SNC_HANDLE(PID, snc_PID_get, NULL, NULL, 1), - SNC_HANDLE(CTR, snc_CTR_get, snc_CTR_set, NULL, 1), - SNC_HANDLE(PCR, snc_PCR_get, snc_PCR_set, NULL, 1), - SNC_HANDLE(CMI, snc_CMI_get, snc_CMI_set, NULL, 1), - SNC_HANDLE_NULL -}; - -static acpi_handle sony_nc_acpi_handle; -static struct acpi_device *sony_nc_acpi_device = NULL; - -/* - * acpi_evaluate_object wrappers - */ -static int acpi_callgetfunc(acpi_handle handle, char *name, int *result) -{ - struct acpi_buffer output; - union acpi_object out_obj; - acpi_status status; - - output.length = sizeof(out_obj); - output.pointer = &out_obj; - - status = acpi_evaluate_object(handle, name, NULL, &output); - if ((status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER)) { - *result = out_obj.integer.value; - return 0; - } - - printk(KERN_WARNING DRV_PFX "acpi_callreadfunc failed\n"); - - return -1; -} - -static int acpi_callsetfunc(acpi_handle handle, char *name, int value, - int *result) -{ - struct acpi_object_list params; - union acpi_object in_obj; - struct acpi_buffer output; - union acpi_object out_obj; - acpi_status status; - - params.count = 1; - params.pointer = &in_obj; - in_obj.type = ACPI_TYPE_INTEGER; - in_obj.integer.value = value; - - output.length = sizeof(out_obj); - output.pointer = &out_obj; - - status = acpi_evaluate_object(handle, name, ¶ms, &output); - if (status == AE_OK) { - if (result != NULL) { - if (out_obj.type != ACPI_TYPE_INTEGER) { - printk(KERN_WARNING DRV_PFX "acpi_evaluate_object bad " - "return type\n"); - return -1; - } - *result = out_obj.integer.value; - } - return 0; - } - - printk(KERN_WARNING DRV_PFX "acpi_evaluate_object failed\n"); - - return -1; -} - -/* - * sony_nc_values input/output validate functions - */ - -/* brightness_default_validate: - * - * manipulate input output values to keep consistency with the - * backlight framework for which brightness values are 0-based. - */ -static int brightness_default_validate(const int direction, const int value) -{ - switch (direction) { - case SNC_VALIDATE_OUT: - return value - 1; - case SNC_VALIDATE_IN: - if (value >= 0 && value < SONY_MAX_BRIGHTNESS) - return value + 1; - } - return -EINVAL; -} - -/* boolean_validate: - * - * on input validate boolean values 0/1, on output just pass the - * received value. - */ -static int boolean_validate(const int direction, const int value) -{ - if (direction == SNC_VALIDATE_IN) { - if (value != 0 && value != 1) - return -EINVAL; - } - return value; -} - -/* - * Sysfs show/store common to all sony_nc_values - */ -static ssize_t sony_nc_sysfs_show(struct device *dev, struct device_attribute *attr, - char *buffer) -{ - int value; - struct sony_nc_value *item = - container_of(attr, struct sony_nc_value, devattr); - - if (!*item->acpiget) - return -EIO; - - if (acpi_callgetfunc(sony_nc_acpi_handle, *item->acpiget, &value) < 0) - return -EIO; - - if (item->validate) - value = item->validate(SNC_VALIDATE_OUT, value); - - return snprintf(buffer, PAGE_SIZE, "%d\n", value); -} - -static ssize_t sony_nc_sysfs_store(struct device *dev, - struct device_attribute *attr, - const char *buffer, size_t count) -{ - int value; - struct sony_nc_value *item = - container_of(attr, struct sony_nc_value, devattr); - - if (!item->acpiset) - return -EIO; - - if (count > 31) - return -EINVAL; - - value = simple_strtoul(buffer, NULL, 10); - - if (item->validate) - value = item->validate(SNC_VALIDATE_IN, value); - - if (value < 0) - return value; - - if (acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset, value, NULL) < 0) - return -EIO; - item->value = value; - item->valid = 1; - return count; -} - - -/* - * Backlight device - */ -static int sony_backlight_update_status(struct backlight_device *bd) -{ - return acpi_callsetfunc(sony_nc_acpi_handle, "SBRT", - bd->props.brightness + 1, NULL); -} - -static int sony_backlight_get_brightness(struct backlight_device *bd) -{ - int value; - - if (acpi_callgetfunc(sony_nc_acpi_handle, "GBRT", &value)) - return 0; - /* brightness levels are 1-based, while backlight ones are 0-based */ - return value - 1; -} - -static struct backlight_device *sony_backlight_device; -static struct backlight_ops sony_backlight_ops = { - .update_status = sony_backlight_update_status, - .get_brightness = sony_backlight_get_brightness, -}; - -/* - * New SNC-only Vaios event mapping to driver known keys - */ -struct sony_nc_event { - u8 data; - u8 event; -}; - -static struct sony_nc_event *sony_nc_events; - -/* Vaio C* --maybe also FE*, N* and AR* ?-- special init sequence - * for Fn keys - */ -static int sony_nc_C_enable(const struct dmi_system_id *id) -{ - int result = 0; - - printk(KERN_NOTICE DRV_PFX "detected %s\n", id->ident); - - sony_nc_events = id->driver_data; - - if (acpi_callsetfunc(sony_nc_acpi_handle, "SN02", 0x4, &result) < 0 - || acpi_callsetfunc(sony_nc_acpi_handle, "SN07", 0x2, &result) < 0 - || acpi_callsetfunc(sony_nc_acpi_handle, "SN02", 0x10, &result) < 0 - || acpi_callsetfunc(sony_nc_acpi_handle, "SN07", 0x0, &result) < 0 - || acpi_callsetfunc(sony_nc_acpi_handle, "SN03", 0x2, &result) < 0 - || acpi_callsetfunc(sony_nc_acpi_handle, "SN07", 0x101, &result) < 0) { - printk(KERN_WARNING DRV_PFX "failed to initialize SNC, some " - "functionalities may be missing\n"); - return 1; - } - return 0; -} - -static struct sony_nc_event sony_C_events[] = { - { 0x81, SONYPI_EVENT_FNKEY_F1 }, - { 0x01, SONYPI_EVENT_FNKEY_RELEASED }, - { 0x85, SONYPI_EVENT_FNKEY_F5 }, - { 0x05, SONYPI_EVENT_FNKEY_RELEASED }, - { 0x86, SONYPI_EVENT_FNKEY_F6 }, - { 0x06, SONYPI_EVENT_FNKEY_RELEASED }, - { 0x87, SONYPI_EVENT_FNKEY_F7 }, - { 0x07, SONYPI_EVENT_FNKEY_RELEASED }, - { 0x8A, SONYPI_EVENT_FNKEY_F10 }, - { 0x0A, SONYPI_EVENT_FNKEY_RELEASED }, - { 0x8C, SONYPI_EVENT_FNKEY_F12 }, - { 0x0C, SONYPI_EVENT_FNKEY_RELEASED }, - { 0, 0 }, -}; - -/* SNC-only model map */ -static const struct dmi_system_id sony_nc_ids[] = { - { - .ident = "Sony Vaio FE Series", - .callback = sony_nc_C_enable, - .driver_data = sony_C_events, - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), - DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FE"), - }, - }, - { - .ident = "Sony Vaio FZ Series", - .callback = sony_nc_C_enable, - .driver_data = sony_C_events, - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), - DMI_MATCH(DMI_PRODUCT_NAME, "VGN-FZ"), - }, - }, - { - .ident = "Sony Vaio C Series", - .callback = sony_nc_C_enable, - .driver_data = sony_C_events, - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), - DMI_MATCH(DMI_PRODUCT_NAME, "VGN-C"), - }, - }, - { - .ident = "Sony Vaio N Series", - .callback = sony_nc_C_enable, - .driver_data = sony_C_events, - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), - DMI_MATCH(DMI_PRODUCT_NAME, "VGN-N"), - }, - }, - { } -}; - -/* - * ACPI callbacks - */ -static void sony_acpi_notify(acpi_handle handle, u32 event, void *data) -{ - struct sony_nc_event *evmap; - u32 ev = event; - int result; - - if (ev == 0x92) { - /* read the key pressed from EC.GECR - * A call to SN07 with 0x0202 will do it as well respecting - * the current protocol on different OSes - * - * Note: the path for GECR may be - * \_SB.PCI0.LPCB.EC (C, FE, AR, N and friends) - * \_SB.PCI0.PIB.EC0 (VGN-FR notifications are sent directly, no GECR) - * - * TODO: we may want to do the same for the older GHKE -need - * dmi list- so this snippet may become one more callback. - */ - if (acpi_callsetfunc(handle, "SN07", 0x0202, &result) < 0) - dprintk("sony_acpi_notify, unable to decode event 0x%.2x\n", ev); - else - ev = result & 0xFF; - } - - if (sony_nc_events) - for (evmap = sony_nc_events; evmap->event; evmap++) { - if (evmap->data == ev) { - ev = evmap->event; - break; - } - } - - dprintk("sony_acpi_notify, event: 0x%.2x\n", ev); - sony_laptop_report_input_event(ev); - acpi_bus_generate_proc_event(sony_nc_acpi_device, 1, ev); -} - -static acpi_status sony_walk_callback(acpi_handle handle, u32 level, - void *context, void **return_value) -{ - struct acpi_namespace_node *node; - union acpi_operand_object *operand; - - node = (struct acpi_namespace_node *)handle; - operand = (union acpi_operand_object *)node->object; - - printk(KERN_WARNING DRV_PFX "method: name: %4.4s, args %X\n", node->name.ascii, - (u32) operand->method.param_count); - - return AE_OK; -} - -/* - * ACPI device - */ -static int sony_nc_resume(struct acpi_device *device) -{ - struct sony_nc_value *item; - - for (item = sony_nc_values; item->name; item++) { - int ret; - - if (!item->valid) - continue; - ret = acpi_callsetfunc(sony_nc_acpi_handle, *item->acpiset, - item->value, NULL); - if (ret < 0) { - printk("%s: %d\n", __func__, ret); - break; - } - } - - /* set the last requested brightness level */ - if (sony_backlight_device && - !sony_backlight_update_status(sony_backlight_device)) - printk(KERN_WARNING DRV_PFX "unable to restore brightness level\n"); - - /* re-initialize models with specific requirements */ - dmi_check_system(sony_nc_ids); - - return 0; -} - -static int sony_nc_add(struct acpi_device *device) -{ - acpi_status status; - int result = 0; - acpi_handle handle; - struct sony_nc_value *item; - - printk(KERN_INFO DRV_PFX "%s v%s.\n", - SONY_NC_DRIVER_NAME, SONY_LAPTOP_DRIVER_VERSION); - - sony_nc_acpi_device = device; - strcpy(acpi_device_class(device), "sony/hotkey"); - - sony_nc_acpi_handle = device->handle; - - /* read device status */ - result = acpi_bus_get_status(device); - /* bail IFF the above call was successful and the device is not present */ - if (!result && !device->status.present) { - dprintk("Device not present\n"); - result = -ENODEV; - goto outwalk; - } - - if (debug) { - status = acpi_walk_namespace(ACPI_TYPE_METHOD, sony_nc_acpi_handle, - 1, sony_walk_callback, NULL, NULL); - if (ACPI_FAILURE(status)) { - printk(KERN_WARNING DRV_PFX "unable to walk acpi resources\n"); - result = -ENODEV; - goto outwalk; - } - } - - /* try to _INI the device if such method exists (ACPI spec 3.0-6.5.1 - * should be respected as we already checked for the device presence above */ - if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, METHOD_NAME__INI, &handle))) { - dprintk("Invoking _INI\n"); - if (ACPI_FAILURE(acpi_evaluate_object(sony_nc_acpi_handle, METHOD_NAME__INI, - NULL, NULL))) - dprintk("_INI Method failed\n"); - } - - /* setup input devices and helper fifo */ - result = sony_laptop_setup_input(device); - if (result) { - printk(KERN_ERR DRV_PFX - "Unabe to create input devices.\n"); - goto outwalk; - } - - status = acpi_install_notify_handler(sony_nc_acpi_handle, - ACPI_DEVICE_NOTIFY, - sony_acpi_notify, NULL); - if (ACPI_FAILURE(status)) { - printk(KERN_WARNING DRV_PFX "unable to install notify handler (%u)\n", status); - result = -ENODEV; - goto outinput; - } - - if (acpi_video_backlight_support()) { - printk(KERN_INFO DRV_PFX "brightness ignored, must be " - "controlled by ACPI video driver\n"); - } else if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "GBRT", - &handle))) { - sony_backlight_device = backlight_device_register("sony", NULL, - NULL, - &sony_backlight_ops); - - if (IS_ERR(sony_backlight_device)) { - printk(KERN_WARNING DRV_PFX "unable to register backlight device\n"); - sony_backlight_device = NULL; - } else { - sony_backlight_device->props.brightness = - sony_backlight_get_brightness - (sony_backlight_device); - sony_backlight_device->props.max_brightness = - SONY_MAX_BRIGHTNESS - 1; - } - - } - - /* initialize models with specific requirements */ - dmi_check_system(sony_nc_ids); - - result = sony_pf_add(); - if (result) - goto outbacklight; - - /* create sony_pf sysfs attributes related to the SNC device */ - for (item = sony_nc_values; item->name; ++item) { - - if (!debug && item->debug) - continue; - - /* find the available acpiget as described in the DSDT */ - for (; item->acpiget && *item->acpiget; ++item->acpiget) { - if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, - *item->acpiget, - &handle))) { - dprintk("Found %s getter: %s\n", - item->name, *item->acpiget); - item->devattr.attr.mode |= S_IRUGO; - break; - } - } - - /* find the available acpiset as described in the DSDT */ - for (; item->acpiset && *item->acpiset; ++item->acpiset) { - if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, - *item->acpiset, - &handle))) { - dprintk("Found %s setter: %s\n", - item->name, *item->acpiset); - item->devattr.attr.mode |= S_IWUSR; - break; - } - } - - if (item->devattr.attr.mode != 0) { - result = - device_create_file(&sony_pf_device->dev, - &item->devattr); - if (result) - goto out_sysfs; - } - } - - return 0; - - out_sysfs: - for (item = sony_nc_values; item->name; ++item) { - device_remove_file(&sony_pf_device->dev, &item->devattr); - } - sony_pf_remove(); - - outbacklight: - if (sony_backlight_device) - backlight_device_unregister(sony_backlight_device); - - status = acpi_remove_notify_handler(sony_nc_acpi_handle, - ACPI_DEVICE_NOTIFY, - sony_acpi_notify); - if (ACPI_FAILURE(status)) - printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n"); - - outinput: - sony_laptop_remove_input(); - - outwalk: - return result; -} - -static int sony_nc_remove(struct acpi_device *device, int type) -{ - acpi_status status; - struct sony_nc_value *item; - - if (sony_backlight_device) - backlight_device_unregister(sony_backlight_device); - - sony_nc_acpi_device = NULL; - - status = acpi_remove_notify_handler(sony_nc_acpi_handle, - ACPI_DEVICE_NOTIFY, - sony_acpi_notify); - if (ACPI_FAILURE(status)) - printk(KERN_WARNING DRV_PFX "unable to remove notify handler\n"); - - for (item = sony_nc_values; item->name; ++item) { - device_remove_file(&sony_pf_device->dev, &item->devattr); - } - |