Advertisement
Coproscefalo

toshiba_acpi

Oct 25th, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 77.75 KB | None | 0 0
  1. /*
  2.  *  toshiba_acpi.c - Toshiba Laptop ACPI Extras
  3.  *
  4.  *  Copyright (C) 2002-2004 John Belmonte
  5.  *  Copyright (C) 2008 Philip Langdale
  6.  *  Copyright (C) 2010 Pierre Ducroquet
  7.  *  Copyright (C) 2014-2015 Azael Avalos
  8.  *
  9.  *  This program is free software; you can redistribute it and/or modify
  10.  *  it under the terms of the GNU General Public License as published by
  11.  *  the Free Software Foundation; either version 2 of the License, or
  12.  *  (at your option) any later version.
  13.  *
  14.  *  This program is distributed in the hope that it will be useful,
  15.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  *  GNU General Public License for more details.
  18.  *
  19.  *  The full GNU General Public License is included in this distribution in
  20.  *  the file called "COPYING".
  21.  *
  22.  *  The devolpment page for this driver is located at
  23.  *  http://memebeam.org/toys/ToshibaAcpiDriver.
  24.  *
  25.  *  Credits:
  26.  *  Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
  27.  *      engineering the Windows drivers
  28.  *  Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
  29.  *  Rob Miller - TV out and hotkeys help
  30.  */
  31.  
  32. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  33.  
  34. #define TOSHIBA_ACPI_VERSION    "0.23"
  35. #define PROC_INTERFACE_VERSION  1
  36.  
  37. #include <linux/kernel.h>
  38. #include <linux/module.h>
  39. #include <linux/init.h>
  40. #include <linux/types.h>
  41. #include <linux/proc_fs.h>
  42. #include <linux/seq_file.h>
  43. #include <linux/backlight.h>
  44. #include <linux/input.h>
  45. #include <linux/input/sparse-keymap.h>
  46. #include <linux/leds.h>
  47. #include <linux/slab.h>
  48. #include <linux/workqueue.h>
  49. #include <linux/i8042.h>
  50. #include <linux/acpi.h>
  51. #include <linux/dmi.h>
  52. #include <linux/uaccess.h>
  53. #include <linux/miscdevice.h>
  54. #include <linux/toshiba.h>
  55. #include <linux/delay.h>
  56. #include <acpi/video.h>
  57.  
  58. MODULE_AUTHOR("John Belmonte");
  59. MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
  60. MODULE_LICENSE("GPL");
  61.  
  62. #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
  63.  
  64. /* Scan code for Fn key on TOS1900 models */
  65. #define TOS1900_FN_SCAN     0x6e
  66.  
  67. /* Toshiba ACPI method paths */
  68. #define METHOD_VIDEO_OUT    "\\_SB_.VALX.DSSX"
  69.  
  70. #define TOSHIBA_ACPI_SCI    _IOWR('t', 0x91, SMMRegisters)
  71.  
  72. /*
  73.  * The Toshiba configuration interface is composed of the HCI and the SCI,
  74.  * which are defined as follows:
  75.  *
  76.  * HCI is Toshiba's "Hardware Control Interface" which is supposed to
  77.  * be uniform across all their models.  Ideally we would just call
  78.  * dedicated ACPI methods instead of using this primitive interface.
  79.  * However the ACPI methods seem to be incomplete in some areas (for
  80.  * example they allow setting, but not reading, the LCD brightness value),
  81.  * so this is still useful.
  82.  *
  83.  * SCI stands for "System Configuration Interface" which aim is to
  84.  * conceal differences in hardware between different models.
  85.  */
  86.  
  87. #define TCI_WORDS           6
  88.  
  89. /* Operations */
  90. #define HCI_SET             0xff00
  91. #define HCI_GET             0xfe00
  92. #define SCI_OPEN            0xf100
  93. #define SCI_CLOSE           0xf200
  94. #define SCI_GET             0xf300
  95. #define SCI_SET             0xf400
  96.  
  97. /* Return codes */
  98. #define TOS_SUCCESS         0x0000
  99. #define TOS_SUCCESS2            0x0001
  100. #define TOS_OPEN_CLOSE_OK       0x0044
  101. #define TOS_FAILURE         0x1000
  102. #define TOS_NOT_SUPPORTED       0x8000
  103. #define TOS_ALREADY_OPEN        0x8100
  104. #define TOS_NOT_OPENED          0x8200
  105. #define TOS_INPUT_DATA_ERROR        0x8300
  106. #define TOS_WRITE_PROTECTED     0x8400
  107. #define TOS_NOT_PRESENT         0x8600
  108. #define TOS_FIFO_EMPTY          0x8c00
  109. #define TOS_DATA_NOT_AVAILABLE      0x8d20
  110. #define TOS_NOT_INITIALIZED     0x8d50
  111. #define TOS_NOT_INSTALLED       0x8e00
  112.  
  113. /* Registers */
  114. #define HCI_FAN             0x0004
  115. #define HCI_TR_BACKLIGHT        0x0005
  116. #define HCI_SYSTEM_EVENT        0x0016
  117. #define HCI_VIDEO_OUT           0x001c
  118. #define HCI_HOTKEY_EVENT        0x001e
  119. #define HCI_LCD_BRIGHTNESS      0x002a
  120. #define HCI_ACCELEROMETER       0x006d
  121. #define HCI_COOLING_METHOD      0x007f
  122. #define HCI_KBD_ILLUMINATION        0x0095
  123. #define HCI_ECO_MODE            0x0097
  124. #define HCI_ACCELEROMETER2      0x00a6
  125. #define HCI_SYSTEM_INFO         0xc000
  126. #define SCI_PANEL_POWER_ON      0x010d
  127. #define SCI_ILLUMINATION        0x014e
  128. #define SCI_USB_SLEEP_CHARGE        0x0150
  129. #define SCI_KBD_ILLUM_STATUS        0x015c
  130. #define SCI_USB_SLEEP_MUSIC     0x015e
  131. #define SCI_USB_THREE           0x0169
  132. #define SCI_TOUCHPAD            0x050e
  133. #define SCI_KBD_FUNCTION_KEYS       0x0522
  134.  
  135. /* Field definitions */
  136. #define HCI_ACCEL_MASK          0x7fff
  137. #define HCI_HOTKEY_DISABLE      0x0b
  138. #define HCI_HOTKEY_ENABLE       0x01
  139. #define HCI_HOTKEY_SPECIAL_FUNCTIONS    0x10
  140. #define HCI_LCD_BRIGHTNESS_BITS     3
  141. #define HCI_LCD_BRIGHTNESS_SHIFT    (16-HCI_LCD_BRIGHTNESS_BITS)
  142. #define HCI_LCD_BRIGHTNESS_LEVELS   (1 << HCI_LCD_BRIGHTNESS_BITS)
  143. #define HCI_MISC_SHIFT          0x10
  144. #define HCI_SYSTEM_TYPE1        0x10
  145. #define HCI_SYSTEM_TYPE2        0x11
  146. #define HCI_VIDEO_OUT_LCD       0x1
  147. #define HCI_VIDEO_OUT_CRT       0x2
  148. #define HCI_VIDEO_OUT_TV        0x4
  149. #define SCI_KBD_MODE_MASK       0x1f
  150. #define SCI_KBD_MODE_FNZ        0x1
  151. #define SCI_KBD_MODE_AUTO       0x2
  152. #define SCI_KBD_MODE_ON         0x8
  153. #define SCI_KBD_MODE_OFF        0x10
  154. #define SCI_KBD_TIME_MAX        0x3c001a
  155. #define SCI_USB_CHARGE_MODE_MASK    0xff
  156. #define SCI_USB_CHARGE_DISABLED     0x00
  157. #define SCI_USB_CHARGE_ALTERNATE    0x09
  158. #define SCI_USB_CHARGE_TYPICAL      0x11
  159. #define SCI_USB_CHARGE_AUTO     0x21
  160. #define SCI_USB_CHARGE_BAT_MASK     0x7
  161. #define SCI_USB_CHARGE_BAT_LVL_OFF  0x1
  162. #define SCI_USB_CHARGE_BAT_LVL_ON   0x4
  163. #define SCI_USB_CHARGE_BAT_LVL      0x0200
  164. #define SCI_USB_CHARGE_RAPID_DSP    0x0300
  165.  
  166. struct toshiba_acpi_dev {
  167.     struct acpi_device *acpi_dev;
  168.     const char *method_hci;
  169.     struct input_dev *hotkey_dev;
  170.     struct work_struct hotkey_work;
  171.     struct backlight_device *backlight_dev;
  172.     struct led_classdev led_dev;
  173.     struct led_classdev kbd_led;
  174.     struct led_classdev eco_led;
  175.     struct miscdevice miscdev;
  176.  
  177.     int force_fan;
  178.     int last_key_event;
  179.     int key_event_valid;
  180.     int kbd_type;
  181.     int kbd_mode;
  182.     int kbd_time;
  183.     int usbsc_bat_level;
  184.     int usbsc_mode_base;
  185.     int hotkey_event_type;
  186.     int max_cooling_method;
  187.  
  188.     unsigned int illumination_supported:1;
  189.     unsigned int video_supported:1;
  190.     unsigned int fan_supported:1;
  191.     unsigned int system_event_supported:1;
  192.     unsigned int ntfy_supported:1;
  193.     unsigned int info_supported:1;
  194.     unsigned int tr_backlight_supported:1;
  195.     unsigned int kbd_illum_supported:1;
  196.     unsigned int touchpad_supported:1;
  197.     unsigned int eco_supported:1;
  198.     unsigned int accelerometer_supported:1;
  199.     unsigned int usb_sleep_charge_supported:1;
  200.     unsigned int usb_rapid_charge_supported:1;
  201.     unsigned int usb_sleep_music_supported:1;
  202.     unsigned int kbd_function_keys_supported:1;
  203.     unsigned int panel_power_on_supported:1;
  204.     unsigned int usb_three_supported:1;
  205.     unsigned int cooling_method_supported:1;
  206.     unsigned int sysfs_created:1;
  207.     unsigned int special_functions;
  208.  
  209.     bool kbd_led_registered;
  210.     bool illumination_led_registered;
  211.     bool eco_led_registered;
  212.     bool kbd_mode_changed;
  213. };
  214.  
  215. static struct toshiba_acpi_dev *toshiba_acpi;
  216.  
  217. static const struct acpi_device_id toshiba_device_ids[] = {
  218.     {"TOS6200", 0},
  219.     {"TOS6207", 0},
  220.     {"TOS6208", 0},
  221.     {"TOS1900", 0},
  222.     {"", 0},
  223. };
  224. MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
  225.  
  226. static const struct key_entry toshiba_acpi_keymap[] = {
  227.     { KE_KEY, 0x9e, { KEY_RFKILL } },
  228.     { KE_KEY, 0x101, { KEY_MUTE } },
  229.     { KE_KEY, 0x102, { KEY_ZOOMOUT } },
  230.     { KE_KEY, 0x103, { KEY_ZOOMIN } },
  231.     { KE_KEY, 0x10f, { KEY_TAB } },
  232.     { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
  233.     { KE_KEY, 0x139, { KEY_ZOOMRESET } },
  234.     { KE_KEY, 0x13b, { KEY_COFFEE } },
  235.     { KE_KEY, 0x13c, { KEY_BATTERY } },
  236.     { KE_KEY, 0x13d, { KEY_SLEEP } },
  237.     { KE_KEY, 0x13e, { KEY_SUSPEND } },
  238.     { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
  239.     { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
  240.     { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
  241.     { KE_KEY, 0x142, { KEY_WLAN } },
  242.     { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
  243.     { KE_KEY, 0x17f, { KEY_FN } },
  244.     { KE_KEY, 0xb05, { KEY_PROG2 } },
  245.     { KE_KEY, 0xb06, { KEY_WWW } },
  246.     { KE_KEY, 0xb07, { KEY_MAIL } },
  247.     { KE_KEY, 0xb30, { KEY_STOP } },
  248.     { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
  249.     { KE_KEY, 0xb32, { KEY_NEXTSONG } },
  250.     { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
  251.     { KE_KEY, 0xb5a, { KEY_MEDIA } },
  252.     { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
  253.     { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
  254.     { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
  255.     { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
  256.     { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
  257.     { KE_END, 0 },
  258. };
  259.  
  260. static const struct key_entry toshiba_acpi_alt_keymap[] = {
  261.     { KE_KEY, 0x102, { KEY_ZOOMOUT } },
  262.     { KE_KEY, 0x103, { KEY_ZOOMIN } },
  263.     { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
  264.     { KE_KEY, 0x139, { KEY_ZOOMRESET } },
  265.     { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
  266.     { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
  267.     { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
  268.     { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
  269.     { KE_KEY, 0x157, { KEY_MUTE } },
  270.     { KE_KEY, 0x158, { KEY_WLAN } },
  271.     { KE_END, 0 },
  272. };
  273.  
  274. /*
  275.  * List of models which have a broken acpi-video backlight interface and thus
  276.  * need to use the toshiba (vendor) interface instead.
  277.  */
  278. static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = {
  279.     {}
  280. };
  281.  
  282. /*
  283.  * Utility
  284.  */
  285.  
  286. static inline void _set_bit(u32 *word, u32 mask, int value)
  287. {
  288.     *word = (*word & ~mask) | (mask * value);
  289. }
  290.  
  291. /*
  292.  * ACPI interface wrappers
  293.  */
  294.  
  295. static int write_acpi_int(const char *methodName, int val)
  296. {
  297.     acpi_status status;
  298.  
  299.     status = acpi_execute_simple_method(NULL, (char *)methodName, val);
  300.     return (status == AE_OK) ? 0 : -EIO;
  301. }
  302.  
  303. /*
  304.  * Perform a raw configuration call.  Here we don't care about input or output
  305.  * buffer format.
  306.  */
  307. static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
  308.                const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
  309. {
  310.     struct acpi_object_list params;
  311.     union acpi_object in_objs[TCI_WORDS];
  312.     struct acpi_buffer results;
  313.     union acpi_object out_objs[TCI_WORDS + 1];
  314.     acpi_status status;
  315.     int i;
  316.  
  317.     params.count = TCI_WORDS;
  318.     params.pointer = in_objs;
  319.     for (i = 0; i < TCI_WORDS; ++i) {
  320.         in_objs[i].type = ACPI_TYPE_INTEGER;
  321.         in_objs[i].integer.value = in[i];
  322.     }
  323.  
  324.     results.length = sizeof(out_objs);
  325.     results.pointer = out_objs;
  326.  
  327.     status = acpi_evaluate_object(dev->acpi_dev->handle,
  328.                       (char *)dev->method_hci, &params,
  329.                       &results);
  330.     if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
  331.         for (i = 0; i < out_objs->package.count; ++i)
  332.             out[i] = out_objs->package.elements[i].integer.value;
  333.     }
  334.  
  335.     return status;
  336. }
  337.  
  338. /*
  339.  * Common hci tasks
  340.  *
  341.  * In addition to the ACPI status, the HCI system returns a result which
  342.  * may be useful (such as "not supported").
  343.  */
  344.  
  345. static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
  346. {
  347.     u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
  348.     u32 out[TCI_WORDS];
  349.     acpi_status status = tci_raw(dev, in, out);
  350.  
  351.     return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
  352. }
  353.  
  354. static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
  355. {
  356.     u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
  357.     u32 out[TCI_WORDS];
  358.     acpi_status status = tci_raw(dev, in, out);
  359.  
  360.     if (ACPI_FAILURE(status))
  361.         return TOS_FAILURE;
  362.  
  363.     *out1 = out[2];
  364.  
  365.     return out[0];
  366. }
  367.  
  368. /*
  369.  * Common sci tasks
  370.  */
  371.  
  372. static int sci_open(struct toshiba_acpi_dev *dev)
  373. {
  374.     u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
  375.     u32 out[TCI_WORDS];
  376.     acpi_status status;
  377.  
  378.     status = tci_raw(dev, in, out);
  379.     if  (ACPI_FAILURE(status)) {
  380.         pr_err("ACPI call to open SCI failed\n");
  381.         return 0;
  382.     }
  383.  
  384.     if (out[0] == TOS_OPEN_CLOSE_OK) {
  385.         return 1;
  386.     } else if (out[0] == TOS_ALREADY_OPEN) {
  387.         pr_info("Toshiba SCI already opened\n");
  388.         return 1;
  389.     } else if (out[0] == TOS_NOT_SUPPORTED) {
  390.         /*
  391.          * Some BIOSes do not have the SCI open/close functions
  392.          * implemented and return 0x8000 (Not Supported), failing to
  393.          * register some supported features.
  394.          *
  395.          * Simply return 1 if we hit those affected laptops to make the
  396.          * supported features work.
  397.          *
  398.          * In the case that some laptops really do not support the SCI,
  399.          * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
  400.          * and thus, not registering support for the queried feature.
  401.          */
  402.         return 1;
  403.     } else if (out[0] == TOS_NOT_PRESENT) {
  404.         pr_info("Toshiba SCI is not present\n");
  405.     }
  406.  
  407.     return 0;
  408. }
  409.  
  410. static void sci_close(struct toshiba_acpi_dev *dev)
  411. {
  412.     u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
  413.     u32 out[TCI_WORDS];
  414.     acpi_status status;
  415.  
  416.     status = tci_raw(dev, in, out);
  417.     if (ACPI_FAILURE(status)) {
  418.         pr_err("ACPI call to close SCI failed\n");
  419.         return;
  420.     }
  421.  
  422.     if (out[0] == TOS_OPEN_CLOSE_OK)
  423.         return;
  424.     else if (out[0] == TOS_NOT_OPENED)
  425.         pr_info("Toshiba SCI not opened\n");
  426.     else if (out[0] == TOS_NOT_PRESENT)
  427.         pr_info("Toshiba SCI is not present\n");
  428. }
  429.  
  430. static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
  431. {
  432.     u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
  433.     u32 out[TCI_WORDS];
  434.     acpi_status status = tci_raw(dev, in, out);
  435.  
  436.     if (ACPI_FAILURE(status))
  437.         return TOS_FAILURE;
  438.  
  439.     *out1 = out[2];
  440.  
  441.     return out[0];
  442. }
  443.  
  444. static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
  445. {
  446.     u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
  447.     u32 out[TCI_WORDS];
  448.     acpi_status status = tci_raw(dev, in, out);
  449.  
  450.     return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
  451. }
  452.  
  453. /* Illumination support */
  454. static void toshiba_illumination_available(struct toshiba_acpi_dev *dev)
  455. {
  456.     u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
  457.     u32 out[TCI_WORDS];
  458.     acpi_status status;
  459.  
  460.     dev->illumination_supported = 0;
  461.     dev->illumination_led_registered = false;
  462.  
  463.     if (!sci_open(dev))
  464.         return;
  465.  
  466.     status = tci_raw(dev, in, out);
  467.     sci_close(dev);
  468.     if (ACPI_FAILURE(status))
  469.         pr_err("ACPI call to query Illumination support failed\n");
  470.     else if (out[0] == TOS_SUCCESS)
  471.         dev->illumination_supported = 1;
  472. }
  473.  
  474. static void toshiba_illumination_set(struct led_classdev *cdev,
  475.                      enum led_brightness brightness)
  476. {
  477.     struct toshiba_acpi_dev *dev = container_of(cdev,
  478.             struct toshiba_acpi_dev, led_dev);
  479.     u32 result;
  480.     u32 state;
  481.  
  482.     /* First request : initialize communication. */
  483.     if (!sci_open(dev))
  484.         return;
  485.  
  486.     /* Switch the illumination on/off */
  487.     state = brightness ? 1 : 0;
  488.     result = sci_write(dev, SCI_ILLUMINATION, state);
  489.     sci_close(dev);
  490.     if (result == TOS_FAILURE)
  491.         pr_err("ACPI call for illumination failed\n");
  492. }
  493.  
  494. static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
  495. {
  496.     struct toshiba_acpi_dev *dev = container_of(cdev,
  497.             struct toshiba_acpi_dev, led_dev);
  498.     u32 state, result;
  499.  
  500.     /* First request : initialize communication. */
  501.     if (!sci_open(dev))
  502.         return LED_OFF;
  503.  
  504.     /* Check the illumination */
  505.     result = sci_read(dev, SCI_ILLUMINATION, &state);
  506.     sci_close(dev);
  507.     if (result == TOS_FAILURE) {
  508.         pr_err("ACPI call for illumination failed\n");
  509.         return LED_OFF;
  510.     } else if (result != TOS_SUCCESS) {
  511.         return LED_OFF;
  512.     }
  513.  
  514.     return state ? LED_FULL : LED_OFF;
  515. }
  516.  
  517. /* KBD Illumination */
  518. static void toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
  519. {
  520.     u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
  521.     u32 out[TCI_WORDS];
  522.     acpi_status status;
  523.  
  524.     dev->kbd_illum_supported = 0;
  525.     dev->kbd_led_registered = false;
  526.     dev->kbd_mode_changed = false;
  527.  
  528.     if (!sci_open(dev))
  529.         return;
  530.  
  531.     status = tci_raw(dev, in, out);
  532.     sci_close(dev);
  533.     if (ACPI_FAILURE(status)) {
  534.         pr_err("ACPI call to query kbd illumination support failed\n");
  535.     } else if (out[0] == TOS_SUCCESS) {
  536.         /*
  537.          * Check for keyboard backlight timeout max value,
  538.          * previous kbd backlight implementation set this to
  539.          * 0x3c0003, and now the new implementation set this
  540.          * to 0x3c001a, use this to distinguish between them.
  541.          */
  542.         if (out[3] == SCI_KBD_TIME_MAX)
  543.             dev->kbd_type = 2;
  544.         else
  545.             dev->kbd_type = 1;
  546.         /* Get the current keyboard backlight mode */
  547.         dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
  548.         /* Get the current time (1-60 seconds) */
  549.         dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
  550.         /* Flag as supported */
  551.         dev->kbd_illum_supported = 1;
  552.     }
  553. }
  554.  
  555. static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
  556. {
  557.     u32 result;
  558.  
  559.     if (!sci_open(dev))
  560.         return -EIO;
  561.  
  562.     result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
  563.     sci_close(dev);
  564.     if (result == TOS_FAILURE)
  565.         pr_err("ACPI call to set KBD backlight status failed\n");
  566.     else if (result == TOS_NOT_SUPPORTED)
  567.         return -ENODEV;
  568.  
  569.     return result == TOS_SUCCESS ? 0 : -EIO;
  570. }
  571.  
  572. static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
  573. {
  574.     u32 result;
  575.  
  576.     if (!sci_open(dev))
  577.         return -EIO;
  578.  
  579.     result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
  580.     sci_close(dev);
  581.     if (result == TOS_FAILURE)
  582.         pr_err("ACPI call to get KBD backlight status failed\n");
  583.     else if (result == TOS_NOT_SUPPORTED)
  584.         return -ENODEV;
  585.  
  586.     return result == TOS_SUCCESS ? 0 : -EIO;
  587. }
  588.  
  589. static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
  590. {
  591.     struct toshiba_acpi_dev *dev = container_of(cdev,
  592.             struct toshiba_acpi_dev, kbd_led);
  593.     u32 result;
  594.     u32 state;
  595.  
  596.     /* Check the keyboard backlight state */
  597.     result = hci_read(dev, HCI_KBD_ILLUMINATION, &state);
  598.     if (result == TOS_FAILURE) {
  599.         pr_err("ACPI call to get the keyboard backlight failed\n");
  600.         return LED_OFF;
  601.     } else if (result != TOS_SUCCESS) {
  602.         return LED_OFF;
  603.     }
  604.  
  605.     return state ? LED_FULL : LED_OFF;
  606. }
  607.  
  608. static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
  609.                      enum led_brightness brightness)
  610. {
  611.     struct toshiba_acpi_dev *dev = container_of(cdev,
  612.             struct toshiba_acpi_dev, kbd_led);
  613.     u32 result;
  614.     u32 state;
  615.  
  616.     /* Set the keyboard backlight state */
  617.     state = brightness ? 1 : 0;
  618.     result = hci_write(dev, HCI_KBD_ILLUMINATION, state);
  619.     if (result == TOS_FAILURE)
  620.         pr_err("ACPI call to set KBD Illumination mode failed\n");
  621. }
  622.  
  623. /* TouchPad support */
  624. static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
  625. {
  626.     u32 result;
  627.  
  628.     if (!sci_open(dev))
  629.         return -EIO;
  630.  
  631.     result = sci_write(dev, SCI_TOUCHPAD, state);
  632.     sci_close(dev);
  633.     if (result == TOS_FAILURE)
  634.         pr_err("ACPI call to set the touchpad failed\n");
  635.     else if (result == TOS_NOT_SUPPORTED)
  636.         return -ENODEV;
  637.  
  638.     return result == TOS_SUCCESS ? 0 : -EIO;
  639. }
  640.  
  641. static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
  642. {
  643.     u32 result;
  644.  
  645.     if (!sci_open(dev))
  646.         return -EIO;
  647.  
  648.     result = sci_read(dev, SCI_TOUCHPAD, state);
  649.     sci_close(dev);
  650.     if (result == TOS_FAILURE)
  651.         pr_err("ACPI call to query the touchpad failed\n");
  652.     else if (result == TOS_NOT_SUPPORTED)
  653.         return -ENODEV;
  654.  
  655.     return result == TOS_SUCCESS ? 0 : -EIO;
  656. }
  657.  
  658. /* Eco Mode support */
  659. static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
  660. {
  661.     acpi_status status;
  662.     u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
  663.     u32 out[TCI_WORDS];
  664.  
  665.     dev->eco_supported = 0;
  666.     dev->eco_led_registered = false;
  667.  
  668.     status = tci_raw(dev, in, out);
  669.     if (ACPI_FAILURE(status)) {
  670.         pr_err("ACPI call to get ECO led failed\n");
  671.     } else if (out[0] == TOS_INPUT_DATA_ERROR) {
  672.         /*
  673.          * If we receive 0x8300 (Input Data Error), it means that the
  674.          * LED device is present, but that we just screwed the input
  675.          * parameters.
  676.          *
  677.          * Let's query the status of the LED to see if we really have a
  678.          * success response, indicating the actual presense of the LED,
  679.          * bail out otherwise.
  680.          */
  681.         in[3] = 1;
  682.         status = tci_raw(dev, in, out);
  683.         if (ACPI_FAILURE(status))
  684.             pr_err("ACPI call to get ECO led failed\n");
  685.         else if (out[0] == TOS_SUCCESS)
  686.             dev->eco_supported = 1;
  687.     }
  688. }
  689.  
  690. static enum led_brightness
  691. toshiba_eco_mode_get_status(struct led_classdev *cdev)
  692. {
  693.     struct toshiba_acpi_dev *dev = container_of(cdev,
  694.             struct toshiba_acpi_dev, eco_led);
  695.     u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
  696.     u32 out[TCI_WORDS];
  697.     acpi_status status;
  698.  
  699.     status = tci_raw(dev, in, out);
  700.     if (ACPI_FAILURE(status)) {
  701.         pr_err("ACPI call to get ECO led failed\n");
  702.         return LED_OFF;
  703.     } else if (out[0] != TOS_SUCCESS) {
  704.         return LED_OFF;
  705.     }
  706.  
  707.     return out[2] ? LED_FULL : LED_OFF;
  708. }
  709.  
  710. static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
  711.                      enum led_brightness brightness)
  712. {
  713.     struct toshiba_acpi_dev *dev = container_of(cdev,
  714.             struct toshiba_acpi_dev, eco_led);
  715.     u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
  716.     u32 out[TCI_WORDS];
  717.     acpi_status status;
  718.  
  719.     /* Switch the Eco Mode led on/off */
  720.     in[2] = (brightness) ? 1 : 0;
  721.     status = tci_raw(dev, in, out);
  722.     if (ACPI_FAILURE(status))
  723.         pr_err("ACPI call to set ECO led failed\n");
  724. }
  725.  
  726. /* Accelerometer support */
  727. static void toshiba_accelerometer_available(struct toshiba_acpi_dev *dev)
  728. {
  729.     u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
  730.     u32 out[TCI_WORDS];
  731.     acpi_status status;
  732.  
  733.     dev->accelerometer_supported = 0;
  734.  
  735.     /*
  736.      * Check if the accelerometer call exists,
  737.      * this call also serves as initialization
  738.      */
  739.     status = tci_raw(dev, in, out);
  740.     if (ACPI_FAILURE(status))
  741.         pr_err("ACPI call to query the accelerometer failed\n");
  742.     else if (out[0] == TOS_SUCCESS)
  743.         dev->accelerometer_supported = 1;
  744. }
  745.  
  746. static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
  747.                      u32 *xy, u32 *z)
  748. {
  749.     u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
  750.     u32 out[TCI_WORDS];
  751.     acpi_status status;
  752.  
  753.     /* Check the Accelerometer status */
  754.     status = tci_raw(dev, in, out);
  755.     if (ACPI_FAILURE(status)) {
  756.         pr_err("ACPI call to query the accelerometer failed\n");
  757.         return -EIO;
  758.     } else if (out[0] == TOS_NOT_SUPPORTED) {
  759.         return -ENODEV;
  760.     } else if (out[0] == TOS_SUCCESS) {
  761.         *xy = out[2];
  762.         *z = out[4];
  763.         return 0;
  764.     }
  765.  
  766.     return -EIO;
  767. }
  768.  
  769. /* Sleep (Charge and Music) utilities support */
  770. static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
  771. {
  772.     u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
  773.     u32 out[TCI_WORDS];
  774.     acpi_status status;
  775.  
  776.     dev->usb_sleep_charge_supported = 0;
  777.  
  778.     if (!sci_open(dev))
  779.         return;
  780.  
  781.     status = tci_raw(dev, in, out);
  782.     if (ACPI_FAILURE(status)) {
  783.         pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
  784.         sci_close(dev);
  785.         return;
  786.     } else if (out[0] == TOS_NOT_SUPPORTED) {
  787.         sci_close(dev);
  788.         return;
  789.     } else if (out[0] == TOS_SUCCESS) {
  790.         dev->usbsc_mode_base = out[4];
  791.     }
  792.  
  793.     in[5] = SCI_USB_CHARGE_BAT_LVL;
  794.     status = tci_raw(dev, in, out);
  795.     sci_close(dev);
  796.     if (ACPI_FAILURE(status)) {
  797.         pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
  798.     } else if (out[0] == TOS_SUCCESS) {
  799.         dev->usbsc_bat_level = out[2];
  800.         /* Flag as supported */
  801.         dev->usb_sleep_charge_supported = 1;
  802.     }
  803.  
  804. }
  805.  
  806. static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
  807.                     u32 *mode)
  808. {
  809.     u32 result;
  810.  
  811.     if (!sci_open(dev))
  812.         return -EIO;
  813.  
  814.     result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
  815.     sci_close(dev);
  816.     if (result == TOS_FAILURE)
  817.         pr_err("ACPI call to set USB S&C mode failed\n");
  818.     else if (result == TOS_NOT_SUPPORTED)
  819.         return -ENODEV;
  820.  
  821.     return result == TOS_SUCCESS ? 0 : -EIO;
  822. }
  823.  
  824. static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
  825.                     u32 mode)
  826. {
  827.     u32 result;
  828.  
  829.     if (!sci_open(dev))
  830.         return -EIO;
  831.  
  832.     result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
  833.     sci_close(dev);
  834.     if (result == TOS_FAILURE)
  835.         pr_err("ACPI call to set USB S&C mode failed\n");
  836.     else if (result == TOS_NOT_SUPPORTED)
  837.         return -ENODEV;
  838.  
  839.     return result == TOS_SUCCESS ? 0 : -EIO;
  840. }
  841.  
  842. static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
  843.                           u32 *mode)
  844. {
  845.     u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
  846.     u32 out[TCI_WORDS];
  847.     acpi_status status;
  848.  
  849.     if (!sci_open(dev))
  850.         return -EIO;
  851.  
  852.     in[5] = SCI_USB_CHARGE_BAT_LVL;
  853.     status = tci_raw(dev, in, out);
  854.     sci_close(dev);
  855.     if (ACPI_FAILURE(status)) {
  856.         pr_err("ACPI call to get USB S&C battery level failed\n");
  857.     } else if (out[0] == TOS_NOT_SUPPORTED) {
  858.         return -ENODEV;
  859.     } else if (out[0] == TOS_SUCCESS) {
  860.         *mode = out[2];
  861.         return 0;
  862.     }
  863.  
  864.     return -EIO;
  865. }
  866.  
  867. static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
  868.                           u32 mode)
  869. {
  870.     u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
  871.     u32 out[TCI_WORDS];
  872.     acpi_status status;
  873.  
  874.     if (!sci_open(dev))
  875.         return -EIO;
  876.  
  877.     in[2] = mode;
  878.     in[5] = SCI_USB_CHARGE_BAT_LVL;
  879.     status = tci_raw(dev, in, out);
  880.     sci_close(dev);
  881.     if (ACPI_FAILURE(status))
  882.         pr_err("ACPI call to set USB S&C battery level failed\n");
  883.     else if (out[0] == TOS_NOT_SUPPORTED)
  884.         return -ENODEV;
  885.  
  886.     return out[0] == TOS_SUCCESS ? 0 : -EIO;
  887. }
  888.  
  889. static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
  890.                     u32 *state)
  891. {
  892.     u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
  893.     u32 out[TCI_WORDS];
  894.     acpi_status status;
  895.  
  896.     if (!sci_open(dev))
  897.         return -EIO;
  898.  
  899.     in[5] = SCI_USB_CHARGE_RAPID_DSP;
  900.     status = tci_raw(dev, in, out);
  901.     sci_close(dev);
  902.     if (ACPI_FAILURE(status)) {
  903.         pr_err("ACPI call to get USB Rapid Charge failed\n");
  904.     } else if (out[0] == TOS_NOT_SUPPORTED) {
  905.         return -ENODEV;
  906.     } else if (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) {
  907.         *state = out[2];
  908.         return 0;
  909.     }
  910.  
  911.     return -EIO;
  912. }
  913.  
  914. static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
  915.                     u32 state)
  916. {
  917.     u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
  918.     u32 out[TCI_WORDS];
  919.     acpi_status status;
  920.  
  921.     if (!sci_open(dev))
  922.         return -EIO;
  923.  
  924.     in[2] = state;
  925.     in[5] = SCI_USB_CHARGE_RAPID_DSP;
  926.     status = tci_raw(dev, in, out);
  927.     sci_close(dev);
  928.     if (ACPI_FAILURE(status))
  929.         pr_err("ACPI call to set USB Rapid Charge failed\n");
  930.     else if (out[0] == TOS_NOT_SUPPORTED)
  931.         return -ENODEV;
  932.  
  933.     return (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) ? 0 : -EIO;
  934. }
  935.  
  936. static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
  937. {
  938.     u32 result;
  939.  
  940.     if (!sci_open(dev))
  941.         return -EIO;
  942.  
  943.     result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
  944.     sci_close(dev);
  945.     if (result == TOS_FAILURE)
  946.         pr_err("ACPI call to get Sleep and Music failed\n");
  947.     else if (result == TOS_NOT_SUPPORTED)
  948.         return -ENODEV;
  949.  
  950.     return result = TOS_SUCCESS ? 0 : -EIO;
  951. }
  952.  
  953. static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
  954. {
  955.     u32 result;
  956.  
  957.     if (!sci_open(dev))
  958.         return -EIO;
  959.  
  960.     result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
  961.     sci_close(dev);
  962.     if (result == TOS_FAILURE)
  963.         pr_err("ACPI call to set Sleep and Music failed\n");
  964.     else if (result == TOS_NOT_SUPPORTED)
  965.         return -ENODEV;
  966.  
  967.     return result == TOS_SUCCESS ? 0 : -EIO;
  968. }
  969.  
  970. /* Keyboard function keys */
  971. static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
  972. {
  973.     u32 result;
  974.  
  975.     if (!sci_open(dev))
  976.         return -EIO;
  977.  
  978.     result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
  979.     sci_close(dev);
  980.     if (result == TOS_FAILURE)
  981.         pr_err("ACPI call to get KBD function keys failed\n");
  982.     else if (result == TOS_NOT_SUPPORTED)
  983.         return -ENODEV;
  984.  
  985.     return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
  986. }
  987.  
  988. static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
  989. {
  990.     u32 result;
  991.  
  992.     if (!sci_open(dev))
  993.         return -EIO;
  994.  
  995.     result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
  996.     sci_close(dev);
  997.     if (result == TOS_FAILURE)
  998.         pr_err("ACPI call to set KBD function keys failed\n");
  999.     else if (result == TOS_NOT_SUPPORTED)
  1000.         return -ENODEV;
  1001.  
  1002.     return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
  1003. }
  1004.  
  1005. /* Panel Power ON */
  1006. static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
  1007. {
  1008.     u32 result;
  1009.  
  1010.     if (!sci_open(dev))
  1011.         return -EIO;
  1012.  
  1013.     result = sci_read(dev, SCI_PANEL_POWER_ON, state);
  1014.     sci_close(dev);
  1015.     if (result == TOS_FAILURE)
  1016.         pr_err("ACPI call to get Panel Power ON failed\n");
  1017.     else if (result == TOS_NOT_SUPPORTED)
  1018.         return -ENODEV;
  1019.  
  1020.     return result == TOS_SUCCESS ? 0 : -EIO;
  1021. }
  1022.  
  1023. static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
  1024. {
  1025.     u32 result;
  1026.  
  1027.     if (!sci_open(dev))
  1028.         return -EIO;
  1029.  
  1030.     result = sci_write(dev, SCI_PANEL_POWER_ON, state);
  1031.     sci_close(dev);
  1032.     if (result == TOS_FAILURE)
  1033.         pr_err("ACPI call to set Panel Power ON failed\n");
  1034.     else if (result == TOS_NOT_SUPPORTED)
  1035.         return -ENODEV;
  1036.  
  1037.     return result == TOS_SUCCESS ? 0 : -EIO;
  1038. }
  1039.  
  1040. /* USB Three */
  1041. static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
  1042. {
  1043.     u32 result;
  1044.  
  1045.     if (!sci_open(dev))
  1046.         return -EIO;
  1047.  
  1048.     result = sci_read(dev, SCI_USB_THREE, state);
  1049.     sci_close(dev);
  1050.     if (result == TOS_FAILURE)
  1051.         pr_err("ACPI call to get USB 3 failed\n");
  1052.     else if (result == TOS_NOT_SUPPORTED)
  1053.         return -ENODEV;
  1054.  
  1055.     return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
  1056. }
  1057.  
  1058. static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
  1059. {
  1060.     u32 result;
  1061.  
  1062.     if (!sci_open(dev))
  1063.         return -EIO;
  1064.  
  1065.     result = sci_write(dev, SCI_USB_THREE, state);
  1066.     sci_close(dev);
  1067.     if (result == TOS_FAILURE)
  1068.         pr_err("ACPI call to set USB 3 failed\n");
  1069.     else if (result == TOS_NOT_SUPPORTED)
  1070.         return -ENODEV;
  1071.  
  1072.     return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
  1073. }
  1074.  
  1075. /* Cooling Method */
  1076. static void toshiba_cooling_method_available(struct toshiba_acpi_dev *dev)
  1077. {
  1078.     u32 in[TCI_WORDS] = { HCI_GET, HCI_COOLING_METHOD, 0, 0, 0, 0 };
  1079.     u32 out[TCI_WORDS];
  1080.     acpi_status status;
  1081.  
  1082.     dev->cooling_method_supported = 0;
  1083.     dev->max_cooling_method = 0;
  1084.  
  1085.     status = tci_raw(dev, in, out);
  1086.     if (ACPI_FAILURE(status)) {
  1087.         pr_err("ACPI call to get Cooling Method failed\n");
  1088.     } else if (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) {
  1089.         dev->cooling_method_supported = 1;
  1090.         dev->max_cooling_method = out[3];
  1091.     }
  1092. }
  1093.  
  1094. static int toshiba_cooling_method_get(struct toshiba_acpi_dev *dev, u32 *state)
  1095. {
  1096.     u32 result = hci_read(dev, HCI_COOLING_METHOD, state);
  1097.  
  1098.     if (result == TOS_FAILURE)
  1099.         pr_err("ACPI call to get Cooling Method failed\n");
  1100.     else if (result == TOS_NOT_SUPPORTED)
  1101.         return -ENODEV;
  1102.  
  1103.     return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
  1104. }
  1105.  
  1106. static int toshiba_cooling_method_set(struct toshiba_acpi_dev *dev, u32 state)
  1107. {
  1108.     u32 result = hci_write(dev, HCI_COOLING_METHOD, state);
  1109.  
  1110.     if (result == TOS_FAILURE)
  1111.         pr_err("ACPI call to get Cooling Method failed\n");
  1112.     else if (result == TOS_NOT_SUPPORTED)
  1113.         return -ENODEV;
  1114.  
  1115.     return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
  1116. }
  1117.  
  1118. /* Hotkey Event type */
  1119. static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
  1120.                      u32 *type)
  1121. {
  1122.     u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 };
  1123.     u32 out[TCI_WORDS];
  1124.     acpi_status status;
  1125.  
  1126.     status = tci_raw(dev, in, out);
  1127.     if (ACPI_FAILURE(status)) {
  1128.         pr_err("ACPI call to get System type failed\n");
  1129.     } else if (out[0] == TOS_NOT_SUPPORTED) {
  1130.         return -ENODEV;
  1131.     } else if (out[0] == TOS_SUCCESS) {
  1132.         *type = out[3];
  1133.         return 0;
  1134.     }
  1135.  
  1136.     return -EIO;
  1137. }
  1138.  
  1139. /* Transflective Backlight */
  1140. static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status)
  1141. {
  1142.     u32 result = hci_read(dev, HCI_TR_BACKLIGHT, status);
  1143.  
  1144.     if (result == TOS_FAILURE)
  1145.         pr_err("ACPI call to get Transflective Backlight failed\n");
  1146.     else if (result == TOS_NOT_SUPPORTED)
  1147.         return -ENODEV;
  1148.  
  1149.     return result == TOS_SUCCESS ? 0 : -EIO;
  1150. }
  1151.  
  1152. static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 status)
  1153. {
  1154.     u32 result = hci_write(dev, HCI_TR_BACKLIGHT, !status);
  1155.  
  1156.     if (result == TOS_FAILURE)
  1157.         pr_err("ACPI call to set Transflective Backlight failed\n");
  1158.     else if (result == TOS_NOT_SUPPORTED)
  1159.         return -ENODEV;
  1160.  
  1161.     return result == TOS_SUCCESS ? 0 : -EIO;
  1162. }
  1163.  
  1164. static struct proc_dir_entry *toshiba_proc_dir;
  1165.  
  1166. /* LCD Brightness */
  1167. static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
  1168. {
  1169.     u32 result;
  1170.     u32 value;
  1171.     int brightness = 0;
  1172.  
  1173.     if (dev->tr_backlight_supported) {
  1174.         int ret = get_tr_backlight_status(dev, &value);
  1175.  
  1176.         if (ret)
  1177.             return ret;
  1178.         if (value)
  1179.             return 0;
  1180.         brightness++;
  1181.     }
  1182.  
  1183.     result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value);
  1184.     if (result == TOS_FAILURE)
  1185.         pr_err("ACPI call to get LCD Brightness failed\n");
  1186.     else if (result == TOS_NOT_SUPPORTED)
  1187.         return -ENODEV;
  1188.     if (result == TOS_SUCCESS)
  1189.         return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
  1190.  
  1191.     return -EIO;
  1192. }
  1193.  
  1194. static int get_lcd_brightness(struct backlight_device *bd)
  1195. {
  1196.     struct toshiba_acpi_dev *dev = bl_get_data(bd);
  1197.  
  1198.     return __get_lcd_brightness(dev);
  1199. }
  1200.  
  1201. static int lcd_proc_show(struct seq_file *m, void *v)
  1202. {
  1203.     struct toshiba_acpi_dev *dev = m->private;
  1204.     int levels;
  1205.     int value;
  1206.  
  1207.     if (!dev->backlight_dev)
  1208.         return -ENODEV;
  1209.  
  1210.     levels = dev->backlight_dev->props.max_brightness + 1;
  1211.     value = get_lcd_brightness(dev->backlight_dev);
  1212.     if (value >= 0) {
  1213.         seq_printf(m, "brightness:              %d\n", value);
  1214.         seq_printf(m, "brightness_levels:       %d\n", levels);
  1215.         return 0;
  1216.     }
  1217.  
  1218.     pr_err("Error reading LCD brightness\n");
  1219.  
  1220.     return -EIO;
  1221. }
  1222.  
  1223. static int lcd_proc_open(struct inode *inode, struct file *file)
  1224. {
  1225.     return single_open(file, lcd_proc_show, PDE_DATA(inode));
  1226. }
  1227.  
  1228. static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
  1229. {
  1230.     u32 result;
  1231.  
  1232.     if (dev->tr_backlight_supported) {
  1233.         int ret = set_tr_backlight_status(dev, !value);
  1234.  
  1235.         if (ret)
  1236.             return ret;
  1237.         if (value)
  1238.             value--;
  1239.     }
  1240.  
  1241.     value = value << HCI_LCD_BRIGHTNESS_SHIFT;
  1242.     result = hci_write(dev, HCI_LCD_BRIGHTNESS, value);
  1243.     if (result == TOS_FAILURE)
  1244.         pr_err("ACPI call to set LCD Brightness failed\n");
  1245.     else if (result == TOS_NOT_SUPPORTED)
  1246.         return -ENODEV;
  1247.  
  1248.     return result == TOS_SUCCESS ? 0 : -EIO;
  1249. }
  1250.  
  1251. static int set_lcd_status(struct backlight_device *bd)
  1252. {
  1253.     struct toshiba_acpi_dev *dev = bl_get_data(bd);
  1254.  
  1255.     return set_lcd_brightness(dev, bd->props.brightness);
  1256. }
  1257.  
  1258. static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
  1259.                   size_t count, loff_t *pos)
  1260. {
  1261.     struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
  1262.     char cmd[42];
  1263.     size_t len;
  1264.     int levels = dev->backlight_dev->props.max_brightness + 1;
  1265.     int value;
  1266.  
  1267.     len = min(count, sizeof(cmd) - 1);
  1268.     if (copy_from_user(cmd, buf, len))
  1269.         return -EFAULT;
  1270.     cmd[len] = '\0';
  1271.  
  1272.     if (sscanf(cmd, " brightness : %i", &value) != 1 &&
  1273.         value < 0 && value > levels)
  1274.         return -EINVAL;
  1275.  
  1276.     if (set_lcd_brightness(dev, value))
  1277.         return -EIO;
  1278.  
  1279.     return count;
  1280. }
  1281.  
  1282. static const struct file_operations lcd_proc_fops = {
  1283.     .owner      = THIS_MODULE,
  1284.     .open       = lcd_proc_open,
  1285.     .read       = seq_read,
  1286.     .llseek     = seq_lseek,
  1287.     .release    = single_release,
  1288.     .write      = lcd_proc_write,
  1289. };
  1290.  
  1291. /* Video-Out */
  1292. static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
  1293. {
  1294.     u32 result = hci_read(dev, HCI_VIDEO_OUT, status);
  1295.  
  1296.     if (result == TOS_FAILURE)
  1297.         pr_err("ACPI call to get Video-Out failed\n");
  1298.     else if (result == TOS_NOT_SUPPORTED)
  1299.         return -ENODEV;
  1300.  
  1301.     return result == TOS_SUCCESS ? 0 : -EIO;
  1302. }
  1303.  
  1304. static int video_proc_show(struct seq_file *m, void *v)
  1305. {
  1306.     struct toshiba_acpi_dev *dev = m->private;
  1307.     u32 value;
  1308.  
  1309.     if (!get_video_status(dev, &value)) {
  1310.         int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
  1311.         int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
  1312.         int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
  1313.  
  1314.         seq_printf(m, "lcd_out:                 %d\n", is_lcd);
  1315.         seq_printf(m, "crt_out:                 %d\n", is_crt);
  1316.         seq_printf(m, "tv_out:                  %d\n", is_tv);
  1317.         return 0;
  1318.     }
  1319.  
  1320.     return -EIO;
  1321. }
  1322.  
  1323. static int video_proc_open(struct inode *inode, struct file *file)
  1324. {
  1325.     return single_open(file, video_proc_show, PDE_DATA(inode));
  1326. }
  1327.  
  1328. static ssize_t video_proc_write(struct file *file, const char __user *buf,
  1329.                 size_t count, loff_t *pos)
  1330. {
  1331.     struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
  1332.     char *buffer;
  1333.     char *cmd;
  1334.     int remain = count;
  1335.     int lcd_out = -1;
  1336.     int crt_out = -1;
  1337.     int tv_out = -1;
  1338.     int value;
  1339.     int ret;
  1340.     u32 video_out;
  1341.  
  1342.     cmd = kmalloc(count + 1, GFP_KERNEL);
  1343.     if (!cmd)
  1344.         return -ENOMEM;
  1345.     if (copy_from_user(cmd, buf, count)) {
  1346.         kfree(cmd);
  1347.         return -EFAULT;
  1348.     }
  1349.     cmd[count] = '\0';
  1350.  
  1351.     buffer = cmd;
  1352.  
  1353.     /*
  1354.      * Scan expression.  Multiple expressions may be delimited with ;
  1355.      * NOTE: To keep scanning simple, invalid fields are ignored.
  1356.      */
  1357.     while (remain) {
  1358.         if (sscanf(buffer, " lcd_out : %i", &value) == 1)
  1359.             lcd_out = value & 1;
  1360.         else if (sscanf(buffer, " crt_out : %i", &value) == 1)
  1361.             crt_out = value & 1;
  1362.         else if (sscanf(buffer, " tv_out : %i", &value) == 1)
  1363.             tv_out = value & 1;
  1364.         /* Advance to one character past the next ; */
  1365.         do {
  1366.             ++buffer;
  1367.             --remain;
  1368.         } while (remain && *(buffer - 1) != ';');
  1369.     }
  1370.  
  1371.     kfree(cmd);
  1372.  
  1373.     ret = get_video_status(dev, &video_out);
  1374.     if (!ret) {
  1375.         unsigned int new_video_out = video_out;
  1376.  
  1377.         if (lcd_out != -1)
  1378.             _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
  1379.         if (crt_out != -1)
  1380.             _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
  1381.         if (tv_out != -1)
  1382.             _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
  1383.         /*
  1384.          * To avoid unnecessary video disruption, only write the new
  1385.          * video setting if something changed.
  1386.          */
  1387.         if (new_video_out != video_out)
  1388.             ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
  1389.     }
  1390.  
  1391.     return ret ? -EIO : count;
  1392. }
  1393.  
  1394. static const struct file_operations video_proc_fops = {
  1395.     .owner      = THIS_MODULE,
  1396.     .open       = video_proc_open,
  1397.     .read       = seq_read,
  1398.     .llseek     = seq_lseek,
  1399.     .release    = single_release,
  1400.     .write      = video_proc_write,
  1401. };
  1402.  
  1403. /* Fan status */
  1404. static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
  1405. {
  1406.     u32 result = hci_read(dev, HCI_FAN, status);
  1407.  
  1408.     if (result == TOS_FAILURE)
  1409.         pr_err("ACPI call to get Fan status failed\n");
  1410.     else if (result == TOS_NOT_SUPPORTED)
  1411.         return -ENODEV;
  1412.  
  1413.     return result == TOS_SUCCESS ? 0 : -EIO;
  1414. }
  1415.  
  1416. static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status)
  1417. {
  1418.     u32 result = hci_write(dev, HCI_FAN, status);
  1419.  
  1420.     if (result == TOS_FAILURE)
  1421.         pr_err("ACPI call to set Fan status failed\n");
  1422.     else if (result == TOS_NOT_SUPPORTED)
  1423.         return -ENODEV;
  1424.  
  1425.     return result == TOS_SUCCESS ? 0 : -EIO;
  1426. }
  1427.  
  1428. static int fan_proc_show(struct seq_file *m, void *v)
  1429. {
  1430.     struct toshiba_acpi_dev *dev = m->private;
  1431.     u32 value;
  1432.  
  1433.     if (get_fan_status(dev, &value))
  1434.         return -EIO;
  1435.  
  1436.     seq_printf(m, "running:                 %d\n", (value > 0));
  1437.     seq_printf(m, "force_on:                %d\n", dev->force_fan);
  1438.  
  1439.     return 0;
  1440. }
  1441.  
  1442. static int fan_proc_open(struct inode *inode, struct file *file)
  1443. {
  1444.     return single_open(file, fan_proc_show, PDE_DATA(inode));
  1445. }
  1446.  
  1447. static ssize_t fan_proc_write(struct file *file, const char __user *buf,
  1448.                   size_t count, loff_t *pos)
  1449. {
  1450.     struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
  1451.     char cmd[42];
  1452.     size_t len;
  1453.     int value;
  1454.  
  1455.     len = min(count, sizeof(cmd) - 1);
  1456.     if (copy_from_user(cmd, buf, len))
  1457.         return -EFAULT;
  1458.     cmd[len] = '\0';
  1459.  
  1460.     if (sscanf(cmd, " force_on : %i", &value) != 1 &&
  1461.         value != 0 && value != 1)
  1462.         return -EINVAL;
  1463.  
  1464.     if (set_fan_status(dev, value))
  1465.         return -EIO;
  1466.  
  1467.     dev->force_fan = value;
  1468.  
  1469.     return count;
  1470. }
  1471.  
  1472. static const struct file_operations fan_proc_fops = {
  1473.     .owner      = THIS_MODULE,
  1474.     .open       = fan_proc_open,
  1475.     .read       = seq_read,
  1476.     .llseek     = seq_lseek,
  1477.     .release    = single_release,
  1478.     .write      = fan_proc_write,
  1479. };
  1480.  
  1481. static int keys_proc_show(struct seq_file *m, void *v)
  1482. {
  1483.     struct toshiba_acpi_dev *dev = m->private;
  1484.  
  1485.     seq_printf(m, "hotkey_ready:            %d\n", dev->key_event_valid);
  1486.     seq_printf(m, "hotkey:                  0x%04x\n", dev->last_key_event);
  1487.  
  1488.     return 0;
  1489. }
  1490.  
  1491. static int keys_proc_open(struct inode *inode, struct file *file)
  1492. {
  1493.     return single_open(file, keys_proc_show, PDE_DATA(inode));
  1494. }
  1495.  
  1496. static ssize_t keys_proc_write(struct file *file, const char __user *buf,
  1497.                    size_t count, loff_t *pos)
  1498. {
  1499.     struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
  1500.     char cmd[42];
  1501.     size_t len;
  1502.     int value;
  1503.  
  1504.     len = min(count, sizeof(cmd) - 1);
  1505.     if (copy_from_user(cmd, buf, len))
  1506.         return -EFAULT;
  1507.     cmd[len] = '\0';
  1508.  
  1509.     if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
  1510.         dev->key_event_valid = 0;
  1511.     else
  1512.         return -EINVAL;
  1513.  
  1514.     return count;
  1515. }
  1516.  
  1517. static const struct file_operations keys_proc_fops = {
  1518.     .owner      = THIS_MODULE,
  1519.     .open       = keys_proc_open,
  1520.     .read       = seq_read,
  1521.     .llseek     = seq_lseek,
  1522.     .release    = single_release,
  1523.     .write      = keys_proc_write,
  1524. };
  1525.  
  1526. static int version_proc_show(struct seq_file *m, void *v)
  1527. {
  1528.     seq_printf(m, "driver:                  %s\n", TOSHIBA_ACPI_VERSION);
  1529.     seq_printf(m, "proc_interface:          %d\n", PROC_INTERFACE_VERSION);
  1530.     return 0;
  1531. }
  1532.  
  1533. static int version_proc_open(struct inode *inode, struct file *file)
  1534. {
  1535.     return single_open(file, version_proc_show, PDE_DATA(inode));
  1536. }
  1537.  
  1538. static const struct file_operations version_proc_fops = {
  1539.     .owner      = THIS_MODULE,
  1540.     .open       = version_proc_open,
  1541.     .read       = seq_read,
  1542.     .llseek     = seq_lseek,
  1543.     .release    = single_release,
  1544. };
  1545.  
  1546. /*
  1547.  * Proc and module init
  1548.  */
  1549.  
  1550. #define PROC_TOSHIBA        "toshiba"
  1551.  
  1552. static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
  1553. {
  1554.     if (dev->backlight_dev)
  1555.         proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  1556.                  &lcd_proc_fops, dev);
  1557.     if (dev->video_supported)
  1558.         proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  1559.                  &video_proc_fops, dev);
  1560.     if (dev->fan_supported)
  1561.         proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  1562.                  &fan_proc_fops, dev);
  1563.     if (dev->hotkey_dev)
  1564.         proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  1565.                  &keys_proc_fops, dev);
  1566.     proc_create_data("version", S_IRUGO, toshiba_proc_dir,
  1567.              &version_proc_fops, dev);
  1568. }
  1569.  
  1570. static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
  1571. {
  1572.     if (dev->backlight_dev)
  1573.         remove_proc_entry("lcd", toshiba_proc_dir);
  1574.     if (dev->video_supported)
  1575.         remove_proc_entry("video", toshiba_proc_dir);
  1576.     if (dev->fan_supported)
  1577.         remove_proc_entry("fan", toshiba_proc_dir);
  1578.     if (dev->hotkey_dev)
  1579.         remove_proc_entry("keys", toshiba_proc_dir);
  1580.     remove_proc_entry("version", toshiba_proc_dir);
  1581. }
  1582.  
  1583. static const struct backlight_ops toshiba_backlight_data = {
  1584.     .options = BL_CORE_SUSPENDRESUME,
  1585.     .get_brightness = get_lcd_brightness,
  1586.     .update_status  = set_lcd_status,
  1587. };
  1588.  
  1589. /* Keyboard backlight work */
  1590. static void toshiba_acpi_update_sysfs(void);
  1591.  
  1592. static void toshiba_acpi_kbd_bl_work(struct work_struct *work)
  1593. {
  1594.     /*
  1595.      * Sleep a bit to avoid a race between the keyboard backlight notify
  1596.      * event signal and the workqueue, this will assure this function will
  1597.      * never be called before the keyboard notify event.
  1598.      */
  1599.     msleep(1);
  1600.  
  1601.     if (toshiba_acpi->kbd_mode_changed)
  1602.         toshiba_acpi_update_sysfs();
  1603. }
  1604.  
  1605. static DECLARE_WORK(kbd_bl_work, toshiba_acpi_kbd_bl_work);
  1606.  
  1607. /*
  1608.  * Sysfs files
  1609.  */
  1610. static ssize_t version_show(struct device *dev,
  1611.                 struct device_attribute *attr, char *buf)
  1612. {
  1613.     return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
  1614. }
  1615. static DEVICE_ATTR_RO(version);
  1616.  
  1617. static ssize_t fan_store(struct device *dev,
  1618.              struct device_attribute *attr,
  1619.              const char *buf, size_t count)
  1620. {
  1621.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1622.     int state;
  1623.     int ret;
  1624.  
  1625.     ret = kstrtoint(buf, 0, &state);
  1626.     if (ret)
  1627.         return ret;
  1628.  
  1629.     if (state != 0 && state != 1)
  1630.         return -EINVAL;
  1631.  
  1632.     ret = set_fan_status(toshiba, state);
  1633.     if (ret)
  1634.         return ret;
  1635.  
  1636.     return count;
  1637. }
  1638.  
  1639. static ssize_t fan_show(struct device *dev,
  1640.             struct device_attribute *attr, char *buf)
  1641. {
  1642.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1643.     u32 value;
  1644.     int ret;
  1645.  
  1646.     ret = get_fan_status(toshiba, &value);
  1647.     if (ret)
  1648.         return ret;
  1649.  
  1650.     return sprintf(buf, "%d\n", value);
  1651. }
  1652. static DEVICE_ATTR_RW(fan);
  1653.  
  1654. static ssize_t kbd_backlight_mode_store(struct device *dev,
  1655.                     struct device_attribute *attr,
  1656.                     const char *buf, size_t count)
  1657. {
  1658.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1659.     int mode;
  1660.     int ret;
  1661.  
  1662.  
  1663.     ret = kstrtoint(buf, 0, &mode);
  1664.     if (ret)
  1665.         return ret;
  1666.  
  1667.     /* Check for supported modes depending on keyboard backlight type */
  1668.     if (toshiba->kbd_type == 1) {
  1669.         /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
  1670.         if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
  1671.             return -EINVAL;
  1672.     } else if (toshiba->kbd_type == 2) {
  1673.         /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
  1674.         if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
  1675.             mode != SCI_KBD_MODE_OFF)
  1676.             return -EINVAL;
  1677.     }
  1678.  
  1679.     /*
  1680.      * Set the Keyboard Backlight Mode where:
  1681.      *  Auto - KBD backlight turns off automatically in given time
  1682.      *  FN-Z - KBD backlight "toggles" when hotkey pressed
  1683.      *  ON   - KBD backlight is always on
  1684.      *  OFF  - KBD backlight is always off
  1685.      */
  1686.  
  1687.     /* Only make a change if the actual mode has changed */
  1688.     if (toshiba->kbd_mode != mode) {
  1689.         /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
  1690.         int time = toshiba->kbd_time << HCI_MISC_SHIFT;
  1691.  
  1692.         /* OR the "base time" to the actual method format */
  1693.         if (toshiba->kbd_type == 1) {
  1694.             /* Type 1 requires the current mode */
  1695.             time |= toshiba->kbd_mode;
  1696.         } else if (toshiba->kbd_type == 2) {
  1697.             /* Type 2 requires the desired mode */
  1698.             time |= mode;
  1699.         }
  1700.  
  1701.         ret = toshiba_kbd_illum_status_set(toshiba, time);
  1702.         if (ret)
  1703.             return ret;
  1704.  
  1705.         /* Only get through if its a type 2 keyboard */
  1706.         if (toshiba->kbd_type == 2) {
  1707.             toshiba_acpi->kbd_mode_changed = true;
  1708.             schedule_work(&kbd_bl_work);
  1709.         }
  1710.     }
  1711.  
  1712.     return count;
  1713. }
  1714.  
  1715. static ssize_t kbd_backlight_mode_show(struct device *dev,
  1716.                        struct device_attribute *attr,
  1717.                        char *buf)
  1718. {
  1719.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1720.     u32 time;
  1721.  
  1722.     if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
  1723.         return -EIO;
  1724.  
  1725.     return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
  1726. }
  1727. static DEVICE_ATTR_RW(kbd_backlight_mode);
  1728.  
  1729. static ssize_t kbd_type_show(struct device *dev,
  1730.                  struct device_attribute *attr, char *buf)
  1731. {
  1732.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1733.  
  1734.     return sprintf(buf, "%d\n", toshiba->kbd_type);
  1735. }
  1736. static DEVICE_ATTR_RO(kbd_type);
  1737.  
  1738. static ssize_t available_kbd_modes_show(struct device *dev,
  1739.                     struct device_attribute *attr,
  1740.                     char *buf)
  1741. {
  1742.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1743.  
  1744.     if (toshiba->kbd_type == 1)
  1745.         return sprintf(buf, "%x %x\n",
  1746.                    SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
  1747.  
  1748.     return sprintf(buf, "%x %x %x\n",
  1749.                SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
  1750. }
  1751. static DEVICE_ATTR_RO(available_kbd_modes);
  1752.  
  1753. static ssize_t kbd_backlight_timeout_store(struct device *dev,
  1754.                        struct device_attribute *attr,
  1755.                        const char *buf, size_t count)
  1756. {
  1757.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1758.     int time;
  1759.     int ret;
  1760.  
  1761.     ret = kstrtoint(buf, 0, &time);
  1762.     if (ret)
  1763.         return ret;
  1764.  
  1765.     /* Check for supported values depending on kbd_type */
  1766.     if (toshiba->kbd_type == 1) {
  1767.         if (time < 0 || time > 60)
  1768.             return -EINVAL;
  1769.     } else if (toshiba->kbd_type == 2) {
  1770.         if (time < 1 || time > 60)
  1771.             return -EINVAL;
  1772.     }
  1773.  
  1774.     /* Set the Keyboard Backlight Timeout */
  1775.  
  1776.     /* Only make a change if the actual timeout has changed */
  1777.     if (toshiba->kbd_time != time) {
  1778.         /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
  1779.         time = time << HCI_MISC_SHIFT;
  1780.         /* OR the "base time" to the actual method format */
  1781.         if (toshiba->kbd_type == 1)
  1782.             time |= SCI_KBD_MODE_FNZ;
  1783.         else if (toshiba->kbd_type == 2)
  1784.             time |= SCI_KBD_MODE_AUTO;
  1785.  
  1786.         ret = toshiba_kbd_illum_status_set(toshiba, time);
  1787.         if (ret)
  1788.             return ret;
  1789.  
  1790.         toshiba->kbd_time = time >> HCI_MISC_SHIFT;
  1791.     }
  1792.  
  1793.     return count;
  1794. }
  1795.  
  1796. static ssize_t kbd_backlight_timeout_show(struct device *dev,
  1797.                       struct device_attribute *attr,
  1798.                       char *buf)
  1799. {
  1800.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1801.     u32 time;
  1802.  
  1803.     if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
  1804.         return -EIO;
  1805.  
  1806.     return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
  1807. }
  1808. static DEVICE_ATTR_RW(kbd_backlight_timeout);
  1809.  
  1810. static ssize_t touchpad_store(struct device *dev,
  1811.                   struct device_attribute *attr,
  1812.                   const char *buf, size_t count)
  1813. {
  1814.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1815.     int state;
  1816.     int ret;
  1817.  
  1818.     /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
  1819.     ret = kstrtoint(buf, 0, &state);
  1820.     if (ret)
  1821.         return ret;
  1822.     if (state != 0 && state != 1)
  1823.         return -EINVAL;
  1824.  
  1825.     ret = toshiba_touchpad_set(toshiba, state);
  1826.     if (ret)
  1827.         return ret;
  1828.  
  1829.     return count;
  1830. }
  1831.  
  1832. static ssize_t touchpad_show(struct device *dev,
  1833.                  struct device_attribute *attr, char *buf)
  1834. {
  1835.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1836.     u32 state;
  1837.     int ret;
  1838.  
  1839.     ret = toshiba_touchpad_get(toshiba, &state);
  1840.     if (ret < 0)
  1841.         return ret;
  1842.  
  1843.     return sprintf(buf, "%i\n", state);
  1844. }
  1845. static DEVICE_ATTR_RW(touchpad);
  1846.  
  1847. static ssize_t position_show(struct device *dev,
  1848.                  struct device_attribute *attr, char *buf)
  1849. {
  1850.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1851.     u32 xyval, zval, tmp;
  1852.     u16 x, y, z;
  1853.     int ret;
  1854.  
  1855.     xyval = zval = 0;
  1856.     ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
  1857.     if (ret < 0)
  1858.         return ret;
  1859.  
  1860.     x = xyval & HCI_ACCEL_MASK;
  1861.     tmp = xyval >> HCI_MISC_SHIFT;
  1862.     y = tmp & HCI_ACCEL_MASK;
  1863.     z = zval & HCI_ACCEL_MASK;
  1864.  
  1865.     return sprintf(buf, "%d %d %d\n", x, y, z);
  1866. }
  1867. static DEVICE_ATTR_RO(position);
  1868.  
  1869. static ssize_t usb_sleep_charge_show(struct device *dev,
  1870.                      struct device_attribute *attr, char *buf)
  1871. {
  1872.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1873.     u32 mode;
  1874.     int ret;
  1875.  
  1876.     ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
  1877.     if (ret < 0)
  1878.         return ret;
  1879.  
  1880.     return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
  1881. }
  1882.  
  1883. static ssize_t usb_sleep_charge_store(struct device *dev,
  1884.                       struct device_attribute *attr,
  1885.                       const char *buf, size_t count)
  1886. {
  1887.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1888.     u32 mode;
  1889.     int state;
  1890.     int ret;
  1891.  
  1892.     ret = kstrtoint(buf, 0, &state);
  1893.     if (ret)
  1894.         return ret;
  1895.     /*
  1896.      * Check for supported values, where:
  1897.      * 0 - Disabled
  1898.      * 1 - Alternate (Non USB conformant devices that require more power)
  1899.      * 2 - Auto (USB conformant devices)
  1900.      * 3 - Typical
  1901.      */
  1902.     if (state != 0 && state != 1 && state != 2 && state != 3)
  1903.         return -EINVAL;
  1904.  
  1905.     /* Set the USB charging mode to internal value */
  1906.     mode = toshiba->usbsc_mode_base;
  1907.     if (state == 0)
  1908.         mode |= SCI_USB_CHARGE_DISABLED;
  1909.     else if (state == 1)
  1910.         mode |= SCI_USB_CHARGE_ALTERNATE;
  1911.     else if (state == 2)
  1912.         mode |= SCI_USB_CHARGE_AUTO;
  1913.     else if (state == 3)
  1914.         mode |= SCI_USB_CHARGE_TYPICAL;
  1915.  
  1916.     ret = toshiba_usb_sleep_charge_set(toshiba, mode);
  1917.     if (ret)
  1918.         return ret;
  1919.  
  1920.     return count;
  1921. }
  1922. static DEVICE_ATTR_RW(usb_sleep_charge);
  1923.  
  1924. static ssize_t sleep_functions_on_battery_show(struct device *dev,
  1925.                            struct device_attribute *attr,
  1926.                            char *buf)
  1927. {
  1928.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1929.     u32 state;
  1930.     int bat_lvl;
  1931.     int status;
  1932.     int ret;
  1933.     int tmp;
  1934.  
  1935.     ret = toshiba_sleep_functions_status_get(toshiba, &state);
  1936.     if (ret < 0)
  1937.         return ret;
  1938.  
  1939.     /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
  1940.     tmp = state & SCI_USB_CHARGE_BAT_MASK;
  1941.     status = (tmp == 0x4) ? 1 : 0;
  1942.     /* Determine the battery level set */
  1943.     bat_lvl = state >> HCI_MISC_SHIFT;
  1944.  
  1945.     return sprintf(buf, "%d %d\n", status, bat_lvl);
  1946. }
  1947.  
  1948. static ssize_t sleep_functions_on_battery_store(struct device *dev,
  1949.                         struct device_attribute *attr,
  1950.                         const char *buf, size_t count)
  1951. {
  1952.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1953.     u32 status;
  1954.     int value;
  1955.     int ret;
  1956.     int tmp;
  1957.  
  1958.     ret = kstrtoint(buf, 0, &value);
  1959.     if (ret)
  1960.         return ret;
  1961.  
  1962.     /*
  1963.      * Set the status of the function:
  1964.      * 0 - Disabled
  1965.      * 1-100 - Enabled
  1966.      */
  1967.     if (value < 0 || value > 100)
  1968.         return -EINVAL;
  1969.  
  1970.     if (value == 0) {
  1971.         tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
  1972.         status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
  1973.     } else {
  1974.         tmp = value << HCI_MISC_SHIFT;
  1975.         status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
  1976.     }
  1977.     ret = toshiba_sleep_functions_status_set(toshiba, status);
  1978.     if (ret < 0)
  1979.         return ret;
  1980.  
  1981.     toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
  1982.  
  1983.     return count;
  1984. }
  1985. static DEVICE_ATTR_RW(sleep_functions_on_battery);
  1986.  
  1987. static ssize_t usb_rapid_charge_show(struct device *dev,
  1988.                      struct device_attribute *attr, char *buf)
  1989. {
  1990.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  1991.     u32 state;
  1992.     int ret;
  1993.  
  1994.     ret = toshiba_usb_rapid_charge_get(toshiba, &state);
  1995.     if (ret < 0)
  1996.         return ret;
  1997.  
  1998.     return sprintf(buf, "%d\n", state);
  1999. }
  2000.  
  2001. static ssize_t usb_rapid_charge_store(struct device *dev,
  2002.                       struct device_attribute *attr,
  2003.                       const char *buf, size_t count)
  2004. {
  2005.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  2006.     int state;
  2007.     int ret;
  2008.  
  2009.     ret = kstrtoint(buf, 0, &state);
  2010.     if (ret)
  2011.         return ret;
  2012.     if (state != 0 && state != 1)
  2013.         return -EINVAL;
  2014.  
  2015.     ret = toshiba_usb_rapid_charge_set(toshiba, state);
  2016.     if (ret)
  2017.         return ret;
  2018.  
  2019.     return count;
  2020. }
  2021. static DEVICE_ATTR_RW(usb_rapid_charge);
  2022.  
  2023. static ssize_t usb_sleep_music_show(struct device *dev,
  2024.                     struct device_attribute *attr, char *buf)
  2025. {
  2026.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  2027.     u32 state;
  2028.     int ret;
  2029.  
  2030.     ret = toshiba_usb_sleep_music_get(toshiba, &state);
  2031.     if (ret < 0)
  2032.         return ret;
  2033.  
  2034.     return sprintf(buf, "%d\n", state);
  2035. }
  2036.  
  2037. static ssize_t usb_sleep_music_store(struct device *dev,
  2038.                      struct device_attribute *attr,
  2039.                      const char *buf, size_t count)
  2040. {
  2041.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  2042.     int state;
  2043.     int ret;
  2044.  
  2045.     ret = kstrtoint(buf, 0, &state);
  2046.     if (ret)
  2047.         return ret;
  2048.     if (state != 0 && state != 1)
  2049.         return -EINVAL;
  2050.  
  2051.     ret = toshiba_usb_sleep_music_set(toshiba, state);
  2052.     if (ret)
  2053.         return ret;
  2054.  
  2055.     return count;
  2056. }
  2057. static DEVICE_ATTR_RW(usb_sleep_music);
  2058.  
  2059. static ssize_t kbd_function_keys_show(struct device *dev,
  2060.                       struct device_attribute *attr, char *buf)
  2061. {
  2062.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  2063.     int mode;
  2064.     int ret;
  2065.  
  2066.     ret = toshiba_function_keys_get(toshiba, &mode);
  2067.     if (ret < 0)
  2068.         return ret;
  2069.  
  2070.     return sprintf(buf, "%d\n", mode);
  2071. }
  2072.  
  2073. static ssize_t kbd_function_keys_store(struct device *dev,
  2074.                        struct device_attribute *attr,
  2075.                        const char *buf, size_t count)
  2076. {
  2077.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  2078.     int mode;
  2079.     int ret;
  2080.  
  2081.     ret = kstrtoint(buf, 0, &mode);
  2082.     if (ret)
  2083.         return ret;
  2084.     /*
  2085.      * Check for the function keys mode where:
  2086.      * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
  2087.      * 1 - Special functions (Opposite of the above setting)
  2088.      */
  2089.     if (mode != 0 && mode != 1)
  2090.         return -EINVAL;
  2091.  
  2092.     ret = toshiba_function_keys_set(toshiba, mode);
  2093.     if (ret)
  2094.         return ret;
  2095.  
  2096.     pr_info("Reboot for changes to KBD Function Keys to take effect");
  2097.  
  2098.     return count;
  2099. }
  2100. static DEVICE_ATTR_RW(kbd_function_keys);
  2101.  
  2102. static ssize_t panel_power_on_show(struct device *dev,
  2103.                    struct device_attribute *attr, char *buf)
  2104. {
  2105.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  2106.     u32 state;
  2107.     int ret;
  2108.  
  2109.     ret = toshiba_panel_power_on_get(toshiba, &state);
  2110.     if (ret < 0)
  2111.         return ret;
  2112.  
  2113.     return sprintf(buf, "%d\n", state);
  2114. }
  2115.  
  2116. static ssize_t panel_power_on_store(struct device *dev,
  2117.                     struct device_attribute *attr,
  2118.                     const char *buf, size_t count)
  2119. {
  2120.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  2121.     int state;
  2122.     int ret;
  2123.  
  2124.     ret = kstrtoint(buf, 0, &state);
  2125.     if (ret)
  2126.         return ret;
  2127.     if (state != 0 && state != 1)
  2128.         return -EINVAL;
  2129.  
  2130.     ret = toshiba_panel_power_on_set(toshiba, state);
  2131.     if (ret)
  2132.         return ret;
  2133.  
  2134.     pr_info("Reboot for changes to Panel Power ON to take effect");
  2135.  
  2136.     return count;
  2137. }
  2138. static DEVICE_ATTR_RW(panel_power_on);
  2139.  
  2140. static ssize_t usb_three_show(struct device *dev,
  2141.                   struct device_attribute *attr, char *buf)
  2142. {
  2143.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  2144.     u32 state;
  2145.     int ret;
  2146.  
  2147.     ret = toshiba_usb_three_get(toshiba, &state);
  2148.     if (ret < 0)
  2149.         return ret;
  2150.  
  2151.     return sprintf(buf, "%d\n", state);
  2152. }
  2153.  
  2154. static ssize_t usb_three_store(struct device *dev,
  2155.                    struct device_attribute *attr,
  2156.                    const char *buf, size_t count)
  2157. {
  2158.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  2159.     int state;
  2160.     int ret;
  2161.  
  2162.     ret = kstrtoint(buf, 0, &state);
  2163.     if (ret)
  2164.         return ret;
  2165.     /*
  2166.      * Check for USB 3 mode where:
  2167.      * 0 - Disabled (Acts like a USB 2 port, saving power)
  2168.      * 1 - Enabled
  2169.      */
  2170.     if (state != 0 && state != 1)
  2171.         return -EINVAL;
  2172.  
  2173.     ret = toshiba_usb_three_set(toshiba, state);
  2174.     if (ret)
  2175.         return ret;
  2176.  
  2177.     pr_info("Reboot for changes to USB 3 to take effect");
  2178.  
  2179.     return count;
  2180. }
  2181. static DEVICE_ATTR_RW(usb_three);
  2182.  
  2183. static ssize_t cooling_method_show(struct device *dev,
  2184.                    struct device_attribute *attr, char *buf)
  2185. {
  2186.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  2187.     int state;
  2188.     int ret;
  2189.  
  2190.     ret = toshiba_cooling_method_get(toshiba, &state);
  2191.     if (ret < 0)
  2192.         return ret;
  2193.  
  2194.     return sprintf(buf, "%d %d\n", state, toshiba->max_cooling_method);
  2195. }
  2196.  
  2197. static ssize_t cooling_method_store(struct device *dev,
  2198.                     struct device_attribute *attr,
  2199.                     const char *buf, size_t count)
  2200. {
  2201.     struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
  2202.     int state;
  2203.     int ret;
  2204.  
  2205.     ret = kstrtoint(buf, 0, &state);
  2206.     if (ret)
  2207.         return ret;
  2208.     /* Check for supported values */
  2209.     if (state < 0 || state > toshiba->max_cooling_method)
  2210.         return -EINVAL;
  2211.  
  2212.     ret = toshiba_cooling_method_set(toshiba, state);
  2213.     if (ret)
  2214.         return ret;
  2215.  
  2216.     return count;
  2217. }
  2218. static DEVICE_ATTR_RW(cooling_method);
  2219.  
  2220. static struct attribute *toshiba_attributes[] = {
  2221.     &dev_attr_version.attr,
  2222.     &dev_attr_fan.attr,
  2223.     &dev_attr_kbd_backlight_mode.attr,
  2224.     &dev_attr_kbd_type.attr,
  2225.     &dev_attr_available_kbd_modes.attr,
  2226.     &dev_attr_kbd_backlight_timeout.attr,
  2227.     &dev_attr_touchpad.attr,
  2228.     &dev_attr_position.attr,
  2229.     &dev_attr_usb_sleep_charge.attr,
  2230.     &dev_attr_sleep_functions_on_battery.attr,
  2231.     &dev_attr_usb_rapid_charge.attr,
  2232.     &dev_attr_usb_sleep_music.attr,
  2233.     &dev_attr_kbd_function_keys.attr,
  2234.     &dev_attr_panel_power_on.attr,
  2235.     &dev_attr_usb_three.attr,
  2236.     &dev_attr_cooling_method.attr,
  2237.     NULL,
  2238. };
  2239.  
  2240. static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
  2241.                     struct attribute *attr, int idx)
  2242. {
  2243.     struct device *dev = container_of(kobj, struct device, kobj);
  2244.     struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
  2245.     bool exists = true;
  2246.  
  2247.     if (attr == &dev_attr_fan.attr)
  2248.         exists = (drv->fan_supported) ? true : false;
  2249.     else if (attr == &dev_attr_kbd_backlight_mode.attr)
  2250.         exists = (drv->kbd_illum_supported) ? true : false;
  2251.     else if (attr == &dev_attr_kbd_backlight_timeout.attr)
  2252.         exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
  2253.     else if (attr == &dev_attr_touchpad.attr)
  2254.         exists = (drv->touchpad_supported) ? true : false;
  2255.     else if (attr == &dev_attr_position.attr)
  2256.         exists = (drv->accelerometer_supported) ? true : false;
  2257.     else if (attr == &dev_attr_usb_sleep_charge.attr)
  2258.         exists = (drv->usb_sleep_charge_supported) ? true : false;
  2259.     else if (attr == &dev_attr_sleep_functions_on_battery.attr)
  2260.         exists = (drv->usb_sleep_charge_supported) ? true : false;
  2261.     else if (attr == &dev_attr_usb_rapid_charge.attr)
  2262.         exists = (drv->usb_rapid_charge_supported) ? true : false;
  2263.     else if (attr == &dev_attr_usb_sleep_music.attr)
  2264.         exists = (drv->usb_sleep_music_supported) ? true : false;
  2265.     else if (attr == &dev_attr_kbd_function_keys.attr)
  2266.         exists = (drv->kbd_function_keys_supported) ? true : false;
  2267.     else if (attr == &dev_attr_panel_power_on.attr)
  2268.         exists = (drv->panel_power_on_supported) ? true : false;
  2269.     else if (attr == &dev_attr_usb_three.attr)
  2270.         exists = (drv->usb_three_supported) ? true : false;
  2271.     else if (attr == &dev_attr_cooling_method.attr)
  2272.         exists = (drv->cooling_method_supported) ? true : false;
  2273.  
  2274.     return exists ? attr->mode : 0;
  2275. }
  2276.  
  2277. static struct attribute_group toshiba_attr_group = {
  2278.     .is_visible = toshiba_sysfs_is_visible,
  2279.     .attrs = toshiba_attributes,
  2280. };
  2281.  
  2282. static void toshiba_acpi_update_sysfs(void)
  2283. {
  2284.     if (sysfs_update_group(&toshiba_acpi->acpi_dev->dev.kobj,
  2285.                    &toshiba_attr_group))
  2286.         pr_err("Unable to update sysfs entries\n");
  2287. }
  2288.  
  2289. /*
  2290.  * Misc device
  2291.  */
  2292. static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
  2293. {
  2294.     u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx,
  2295.                   regs->edx, regs->esi, regs->edi };
  2296.     u32 out[TCI_WORDS];
  2297.     acpi_status status;
  2298.  
  2299.     status = tci_raw(toshiba_acpi, in, out);
  2300.     if (ACPI_FAILURE(status)) {
  2301.         pr_err("ACPI call to query SMM registers failed\n");
  2302.         return -EIO;
  2303.     }
  2304.  
  2305.     /* Fillout the SMM struct with the TCI call results */
  2306.     regs->eax = out[0];
  2307.     regs->ebx = out[1];
  2308.     regs->ecx = out[2];
  2309.     regs->edx = out[3];
  2310.     regs->esi = out[4];
  2311.     regs->edi = out[5];
  2312.  
  2313.     return 0;
  2314. }
  2315.  
  2316. static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd,
  2317.                    unsigned long arg)
  2318. {
  2319.     SMMRegisters __user *argp = (SMMRegisters __user *)arg;
  2320.     SMMRegisters regs;
  2321.     int ret;
  2322.  
  2323.     if (!argp)
  2324.         return -EINVAL;
  2325.  
  2326.     switch (cmd) {
  2327.     case TOSH_SMM:
  2328.         if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
  2329.             return -EFAULT;
  2330.         ret = toshiba_acpi_smm_bridge(&regs);
  2331.         if (ret)
  2332.             return ret;
  2333.         if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
  2334.             return -EFAULT;
  2335.         break;
  2336.     case TOSHIBA_ACPI_SCI:
  2337.         if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
  2338.             return -EFAULT;
  2339.         /* Ensure we are being called with a SCI_{GET, SET} register */
  2340.         if (regs.eax != SCI_GET && regs.eax != SCI_SET)
  2341.             return -EINVAL;
  2342.         if (!sci_open(toshiba_acpi))
  2343.             return -EIO;
  2344.         ret = toshiba_acpi_smm_bridge(&regs);
  2345.         sci_close(toshiba_acpi);
  2346.         if (ret)
  2347.             return ret;
  2348.         if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
  2349.             return -EFAULT;
  2350.         break;
  2351.     default:
  2352.         return -EINVAL;
  2353.     }
  2354.  
  2355.     return 0;
  2356. }
  2357.  
  2358. static const struct file_operations toshiba_acpi_fops = {
  2359.     .owner      = THIS_MODULE,
  2360.     .unlocked_ioctl = toshiba_acpi_ioctl,
  2361.     .llseek     = noop_llseek,
  2362. };
  2363.  
  2364. /*
  2365.  * Hotkeys
  2366.  */
  2367. static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
  2368. {
  2369.     acpi_status status;
  2370.     u32 result;
  2371.  
  2372.     status = acpi_evaluate_object(dev->acpi_dev->handle,
  2373.                       "ENAB", NULL, NULL);
  2374.     if (ACPI_FAILURE(status))
  2375.         return -ENODEV;
  2376.  
  2377.     /*
  2378.      * Enable the "Special Functions" mode only if they are
  2379.      * supported and if they are activated.
  2380.      */
  2381.     if (dev->kbd_function_keys_supported && dev->special_functions)
  2382.         result = hci_write(dev, HCI_HOTKEY_EVENT,
  2383.                    HCI_HOTKEY_SPECIAL_FUNCTIONS);
  2384.     else
  2385.         result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
  2386.  
  2387.     if (result == TOS_FAILURE)
  2388.         return -EIO;
  2389.     else if (result == TOS_NOT_SUPPORTED)
  2390.         return -ENODEV;
  2391.  
  2392.     return 0;
  2393. }
  2394.  
  2395. static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
  2396.                       struct serio *port)
  2397. {
  2398.     if (str & I8042_STR_AUXDATA)
  2399.         return false;
  2400.  
  2401.     if (unlikely(data == 0xe0))
  2402.         return false;
  2403.  
  2404.     if ((data & 0x7f) == TOS1900_FN_SCAN) {
  2405.         schedule_work(&toshiba_acpi->hotkey_work);
  2406.         return true;
  2407.     }
  2408.  
  2409.     return false;
  2410. }
  2411.  
  2412. static void toshiba_acpi_hotkey_work(struct work_struct *work)
  2413. {
  2414.     acpi_handle ec_handle = ec_get_handle();
  2415.     acpi_status status;
  2416.  
  2417.     if (!ec_handle)
  2418.         return;
  2419.  
  2420.     status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
  2421.     if (ACPI_FAILURE(status))
  2422.         pr_err("ACPI NTFY method execution failed\n");
  2423. }
  2424.  
  2425. /*
  2426.  * Returns hotkey scancode, or < 0 on failure.
  2427.  */
  2428. static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
  2429. {
  2430.     unsigned long long value;
  2431.     acpi_status status;
  2432.  
  2433.     status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
  2434.                       NULL, &value);
  2435.     if (ACPI_FAILURE(status)) {
  2436.         pr_err("ACPI INFO method execution failed\n");
  2437.         return -EIO;
  2438.     }
  2439.  
  2440.     return value;
  2441. }
  2442.  
  2443. static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
  2444.                        int scancode)
  2445. {
  2446.     if (scancode == 0x100)
  2447.         return;
  2448.  
  2449.     /* Act on key press; ignore key release */
  2450.     if (scancode & 0x80)
  2451.         return;
  2452.  
  2453.     if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
  2454.         pr_info("Unknown key %x\n", scancode);
  2455. }
  2456.  
  2457. static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
  2458. {
  2459.     if (dev->info_supported) {
  2460.         int scancode = toshiba_acpi_query_hotkey(dev);
  2461.  
  2462.         if (scancode < 0) {
  2463.             pr_err("Failed to query hotkey event\n");
  2464.         } else if (scancode != 0) {
  2465.             toshiba_acpi_report_hotkey(dev, scancode);
  2466.             dev->key_event_valid = 1;
  2467.             dev->last_key_event = scancode;
  2468.         }
  2469.     } else if (dev->system_event_supported) {
  2470.         u32 result;
  2471.         u32 value;
  2472.         int retries = 3;
  2473.  
  2474.         do {
  2475.             result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
  2476.             switch (result) {
  2477.             case TOS_SUCCESS:
  2478.                 toshiba_acpi_report_hotkey(dev, (int)value);
  2479.                 dev->key_event_valid = 1;
  2480.                 dev->last_key_event = value;
  2481.                 break;
  2482.             case TOS_NOT_SUPPORTED:
  2483.                 /*
  2484.                  * This is a workaround for an unresolved
  2485.                  * issue on some machines where system events
  2486.                  * sporadically become disabled.
  2487.                  */
  2488.                 result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
  2489.                 if (result == TOS_SUCCESS)
  2490.                     pr_notice("Re-enabled hotkeys\n");
  2491.                 /* Fall through */
  2492.             default:
  2493.                 retries--;
  2494.                 break;
  2495.             }
  2496.         } while (retries && result != TOS_FIFO_EMPTY);
  2497.     }
  2498. }
  2499.  
  2500. static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
  2501. {
  2502.     const struct key_entry *keymap = toshiba_acpi_keymap;
  2503.     acpi_handle ec_handle;
  2504.     u32 hci_result;
  2505.     int error;
  2506.  
  2507.     if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
  2508.         pr_info("WMI event detected, hotkeys will not be monitored\n");
  2509.         return 0;
  2510.     }
  2511.  
  2512.     error = toshiba_acpi_enable_hotkeys(dev);
  2513.     if (error)
  2514.         return error;
  2515.  
  2516.     if (toshiba_hotkey_event_type_get(dev, &dev->hotkey_event_type))
  2517.         pr_err("Unable to query Hotkey Event Type\n");
  2518.  
  2519.     dev->hotkey_dev = input_allocate_device();
  2520.     if (!dev->hotkey_dev)
  2521.         return -ENOMEM;
  2522.  
  2523.     dev->hotkey_dev->name = "Toshiba input device";
  2524.     dev->hotkey_dev->phys = "toshiba_acpi/input0";
  2525.     dev->hotkey_dev->id.bustype = BUS_HOST;
  2526.  
  2527.     if (dev->hotkey_event_type == HCI_SYSTEM_TYPE1 ||
  2528.         !dev->kbd_function_keys_supported)
  2529.         keymap = toshiba_acpi_keymap;
  2530.     else if (dev->hotkey_event_type == HCI_SYSTEM_TYPE2 ||
  2531.          dev->kbd_function_keys_supported)
  2532.         keymap = toshiba_acpi_alt_keymap;
  2533.     else
  2534.         pr_info("Unknown event type received %x\n",
  2535.             dev->hotkey_event_type);
  2536.     error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
  2537.     if (error)
  2538.         goto err_free_dev;
  2539.  
  2540.     /*
  2541.      * For some machines the SCI responsible for providing hotkey
  2542.      * notification doesn't fire. We can trigger the notification
  2543.      * whenever the Fn key is pressed using the NTFY method, if
  2544.      * supported, so if it's present set up an i8042 key filter
  2545.      * for this purpose.
  2546.      */
  2547.     ec_handle = ec_get_handle();
  2548.     if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
  2549.         INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
  2550.  
  2551.         error = i8042_install_filter(toshiba_acpi_i8042_filter);
  2552.         if (error) {
  2553.             pr_err("Error installing key filter\n");
  2554.             goto err_free_keymap;
  2555.         }
  2556.  
  2557.         dev->ntfy_supported = 1;
  2558.     }
  2559.  
  2560.     /*
  2561.      * Determine hotkey query interface. Prefer using the INFO
  2562.      * method when it is available.
  2563.      */
  2564.     if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
  2565.         dev->info_supported = 1;
  2566.     else {
  2567.         hci_result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
  2568.         if (hci_result == TOS_SUCCESS)
  2569.             dev->system_event_supported = 1;
  2570.     }
  2571.  
  2572.     if (!dev->info_supported && !dev->system_event_supported) {
  2573.         pr_warn("No hotkey query interface found\n");
  2574.         goto err_remove_filter;
  2575.     }
  2576.  
  2577.     error = input_register_device(dev->hotkey_dev);
  2578.     if (error) {
  2579.         pr_info("Unable to register input device\n");
  2580.         goto err_remove_filter;
  2581.     }
  2582.  
  2583.     return 0;
  2584.  
  2585.  err_remove_filter:
  2586.     if (dev->ntfy_supported)
  2587.         i8042_remove_filter(toshiba_acpi_i8042_filter);
  2588.  err_free_keymap:
  2589.     sparse_keymap_free(dev->hotkey_dev);
  2590.  err_free_dev:
  2591.     input_free_device(dev->hotkey_dev);
  2592.     dev->hotkey_dev = NULL;
  2593.     return error;
  2594. }
  2595.  
  2596. static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
  2597. {
  2598.     struct backlight_properties props;
  2599.     int brightness;
  2600.     int ret;
  2601.  
  2602.     /*
  2603.      * Some machines don't support the backlight methods at all, and
  2604.      * others support it read-only. Either of these is pretty useless,
  2605.      * so only register the backlight device if the backlight method
  2606.      * supports both reads and writes.
  2607.      */
  2608.     brightness = __get_lcd_brightness(dev);
  2609.     if (brightness < 0)
  2610.         return 0;
  2611.     ret = set_lcd_brightness(dev, brightness);
  2612.     if (ret) {
  2613.         pr_debug("Backlight method is read-only, disabling backlight support\n");
  2614.         return 0;
  2615.     }
  2616.  
  2617.     /*
  2618.      * Tell acpi-video-detect code to prefer vendor backlight on all
  2619.      * systems with transflective backlight and on dmi matched systems.
  2620.      */
  2621.     if (dev->tr_backlight_supported ||
  2622.         dmi_check_system(toshiba_vendor_backlight_dmi))
  2623.         acpi_video_dmi_promote_vendor();
  2624.  
  2625.     if (acpi_video_backlight_support())
  2626.         return 0;
  2627.  
  2628.     /* acpi-video may have loaded before we called dmi_promote_vendor() */
  2629.     acpi_video_unregister_backlight();
  2630.  
  2631.     memset(&props, 0, sizeof(props));
  2632.     props.type = BACKLIGHT_PLATFORM;
  2633.     props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
  2634.  
  2635.     /* Adding an extra level and having 0 change to transflective mode */
  2636.     if (dev->tr_backlight_supported)
  2637.         props.max_brightness++;
  2638.  
  2639.     dev->backlight_dev = backlight_device_register("toshiba",
  2640.                                &dev->acpi_dev->dev,
  2641.                                dev,
  2642.                                &toshiba_backlight_data,
  2643.                                &props);
  2644.     if (IS_ERR(dev->backlight_dev)) {
  2645.         ret = PTR_ERR(dev->backlight_dev);
  2646.         pr_err("Could not register toshiba backlight device\n");
  2647.         dev->backlight_dev = NULL;
  2648.         return ret;
  2649.     }
  2650.  
  2651.     dev->backlight_dev->props.brightness = brightness;
  2652.     return 0;
  2653. }
  2654.  
  2655. static void print_supported_features(struct toshiba_acpi_dev *dev)
  2656. {
  2657.     pr_info("Supported laptop features:");
  2658.  
  2659.     if (dev->hotkey_dev)
  2660.         pr_cont(" hotkeys");
  2661.     if (dev->backlight_dev)
  2662.         pr_cont(" backlight");
  2663.     if (dev->video_supported)
  2664.         pr_cont(" video-out");
  2665.     if (dev->fan_supported)
  2666.         pr_cont(" fan");
  2667.     if (dev->tr_backlight_supported)
  2668.         pr_cont(" transflective-backlight");
  2669.     if (dev->illumination_supported)
  2670.         pr_cont(" illumination");
  2671.     if (dev->kbd_illum_supported)
  2672.         pr_cont(" keyboard-backlight");
  2673.     if (dev->touchpad_supported)
  2674.         pr_cont(" touchpad");
  2675.     if (dev->eco_supported)
  2676.         pr_cont(" eco-led");
  2677.     if (dev->accelerometer_supported)
  2678.         pr_cont(" accelerometer-axes");
  2679.     if (dev->usb_sleep_charge_supported)
  2680.         pr_cont(" usb-sleep-charge");
  2681.     if (dev->usb_rapid_charge_supported)
  2682.         pr_cont(" usb-rapid-charge");
  2683.     if (dev->usb_sleep_music_supported)
  2684.         pr_cont(" usb-sleep-music");
  2685.     if (dev->kbd_function_keys_supported)
  2686.         pr_cont(" special-function-keys");
  2687.     if (dev->panel_power_on_supported)
  2688.         pr_cont(" panel-power-on");
  2689.     if (dev->usb_three_supported)
  2690.         pr_cont(" usb3");
  2691.     if (dev->cooling_method_supported)
  2692.         pr_cont(" cooling-method");
  2693.  
  2694.     pr_cont("\n");
  2695. }
  2696.  
  2697. static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
  2698. {
  2699.     struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
  2700.  
  2701.     misc_deregister(&dev->miscdev);
  2702.  
  2703.     remove_toshiba_proc_entries(dev);
  2704.  
  2705.     if (dev->sysfs_created)
  2706.         sysfs_remove_group(&dev->acpi_dev->dev.kobj,
  2707.                    &toshiba_attr_group);
  2708.  
  2709.     if (dev->ntfy_supported) {
  2710.         i8042_remove_filter(toshiba_acpi_i8042_filter);
  2711.         cancel_work_sync(&dev->hotkey_work);
  2712.     }
  2713.  
  2714.     if (dev->hotkey_dev) {
  2715.         input_unregister_device(dev->hotkey_dev);
  2716.         sparse_keymap_free(dev->hotkey_dev);
  2717.     }
  2718.  
  2719.     backlight_device_unregister(dev->backlight_dev);
  2720.  
  2721.     if (dev->illumination_led_registered)
  2722.         led_classdev_unregister(&dev->led_dev);
  2723.  
  2724.     if (dev->kbd_led_registered)
  2725.         led_classdev_unregister(&dev->kbd_led);
  2726.  
  2727.     if (dev->eco_led_registered)
  2728.         led_classdev_unregister(&dev->eco_led);
  2729.  
  2730.     if (toshiba_acpi)
  2731.         toshiba_acpi = NULL;
  2732.  
  2733.     kfree(dev);
  2734.  
  2735.     return 0;
  2736. }
  2737.  
  2738. static const char *find_hci_method(acpi_handle handle)
  2739. {
  2740.     if (acpi_has_method(handle, "GHCI"))
  2741.         return "GHCI";
  2742.  
  2743.     if (acpi_has_method(handle, "SPFC"))
  2744.         return "SPFC";
  2745.  
  2746.     return NULL;
  2747. }
  2748.  
  2749. static int toshiba_acpi_add(struct acpi_device *acpi_dev)
  2750. {
  2751.     struct toshiba_acpi_dev *dev;
  2752.     const char *hci_method;
  2753.     u32 dummy;
  2754.     int ret = 0;
  2755.  
  2756.     if (toshiba_acpi)
  2757.         return -EBUSY;
  2758.  
  2759.     pr_info("Toshiba Laptop ACPI Extras version %s\n",
  2760.            TOSHIBA_ACPI_VERSION);
  2761.  
  2762.     hci_method = find_hci_method(acpi_dev->handle);
  2763.     if (!hci_method) {
  2764.         pr_err("HCI interface not found\n");
  2765.         return -ENODEV;
  2766.     }
  2767.  
  2768.     dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  2769.     if (!dev)
  2770.         return -ENOMEM;
  2771.     dev->acpi_dev = acpi_dev;
  2772.     dev->method_hci = hci_method;
  2773.     dev->miscdev.minor = MISC_DYNAMIC_MINOR;
  2774.     dev->miscdev.name = "toshiba_acpi";
  2775.     dev->miscdev.fops = &toshiba_acpi_fops;
  2776.  
  2777.     ret = misc_register(&dev->miscdev);
  2778.     if (ret) {
  2779.         pr_err("Failed to register miscdevice\n");
  2780.         kfree(dev);
  2781.         return ret;
  2782.     }
  2783.  
  2784.     acpi_dev->driver_data = dev;
  2785.     dev_set_drvdata(&acpi_dev->dev, dev);
  2786.  
  2787.     /* Query the BIOS for supported features */
  2788.  
  2789.     /*
  2790.      * The "Special Functions" are always supported by the laptops
  2791.      * with the new keyboard layout, query for its presence to help
  2792.      * determine the keymap layout to use.
  2793.      */
  2794.     ret = toshiba_function_keys_get(dev, &dev->special_functions);
  2795.     dev->kbd_function_keys_supported = !ret;
  2796.  
  2797.     if (toshiba_acpi_setup_keyboard(dev))
  2798.         pr_info("Unable to activate hotkeys\n");
  2799.  
  2800.     /* Determine whether or not BIOS supports transflective backlight */
  2801.     ret = get_tr_backlight_status(dev, &dummy);
  2802.     dev->tr_backlight_supported = !ret;
  2803.  
  2804.     ret = toshiba_acpi_setup_backlight(dev);
  2805.     if (ret)
  2806.         goto error;
  2807.  
  2808.     toshiba_illumination_available(dev);
  2809.     if (dev->illumination_supported) {
  2810.         dev->led_dev.name = "toshiba::illumination";
  2811.         dev->led_dev.max_brightness = 1;
  2812.         dev->led_dev.brightness_set = toshiba_illumination_set;
  2813.         dev->led_dev.brightness_get = toshiba_illumination_get;
  2814.         if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
  2815.             dev->illumination_led_registered = true;
  2816.     }
  2817.  
  2818.     toshiba_eco_mode_available(dev);
  2819.     if (dev->eco_supported) {
  2820.         dev->eco_led.name = "toshiba::eco_mode";
  2821.         dev->eco_led.max_brightness = 1;
  2822.         dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
  2823.         dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
  2824.         if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
  2825.             dev->eco_led_registered = true;
  2826.     }
  2827.  
  2828.     toshiba_kbd_illum_available(dev);
  2829.     /*
  2830.      * Only register the LED if KBD illumination is supported
  2831.      * and the keyboard backlight operation mode is set to FN-Z
  2832.      */
  2833.     if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
  2834.         dev->kbd_led.name = "toshiba::kbd_backlight";
  2835.         dev->kbd_led.max_brightness = 1;
  2836.         dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
  2837.         dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
  2838.         if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
  2839.             dev->kbd_led_registered = true;
  2840.     }
  2841.  
  2842.     ret = toshiba_touchpad_get(dev, &dummy);
  2843.     dev->touchpad_supported = !ret;
  2844.  
  2845.     toshiba_accelerometer_available(dev);
  2846.  
  2847.     toshiba_usb_sleep_charge_available(dev);
  2848.  
  2849.     ret = toshiba_usb_rapid_charge_get(dev, &dummy);
  2850.     dev->usb_rapid_charge_supported = !ret;
  2851.  
  2852.     ret = toshiba_usb_sleep_music_get(dev, &dummy);
  2853.     dev->usb_sleep_music_supported = !ret;
  2854.  
  2855.     ret = toshiba_panel_power_on_get(dev, &dummy);
  2856.     dev->panel_power_on_supported = !ret;
  2857.  
  2858.     ret = toshiba_usb_three_get(dev, &dummy);
  2859.     dev->usb_three_supported = !ret;
  2860.  
  2861.     ret = get_video_status(dev, &dummy);
  2862.     dev->video_supported = !ret;
  2863.  
  2864.     ret = get_fan_status(dev, &dummy);
  2865.     dev->fan_supported = !ret;
  2866.  
  2867.     toshiba_cooling_method_available(dev);
  2868.  
  2869.     print_supported_features(dev);
  2870.  
  2871.     ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
  2872.                  &toshiba_attr_group);
  2873.     if (ret) {
  2874.         dev->sysfs_created = 0;
  2875.         goto error;
  2876.     }
  2877.     dev->sysfs_created = !ret;
  2878.  
  2879.     create_toshiba_proc_entries(dev);
  2880.  
  2881.     toshiba_acpi = dev;
  2882.  
  2883.     return 0;
  2884.  
  2885. error:
  2886.     toshiba_acpi_remove(acpi_dev);
  2887.     return ret;
  2888. }
  2889.  
  2890. static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
  2891. {
  2892.     struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
  2893.  
  2894.     switch (event) {
  2895.     case 0x80: /* Hotkeys and some system events */
  2896.         /*
  2897.          * Machines with this WMI GUID aren't supported due to bugs in
  2898.          * their AML.
  2899.          *
  2900.          * Return silently to avoid triggering a netlink event.
  2901.          */
  2902.         if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
  2903.             return;
  2904.         toshiba_acpi_process_hotkeys(dev);
  2905.         break;
  2906.     case 0x81: /* Dock events */
  2907.     case 0x82:
  2908.     case 0x83:
  2909.         pr_info("Dock event received %x\n", event);
  2910.         break;
  2911.     case 0x88: /* Thermal events */
  2912.         pr_info("Thermal event received\n");
  2913.         break;
  2914.     case 0x8f: /* LID closed */
  2915.     case 0x90: /* LID is closed and Dock has been ejected */
  2916.         break;
  2917.     case 0x8c: /* SATA power events */
  2918.     case 0x8b:
  2919.         pr_info("SATA power event received %x\n", event);
  2920.         break;
  2921.     case 0x92: /* Keyboard backlight mode changed */
  2922.         toshiba_acpi->kbd_mode_changed = false;
  2923.         /* Update sysfs entries */
  2924.         toshiba_acpi_update_sysfs();
  2925.         break;
  2926.     case 0x85: /* Unknown */
  2927.     case 0x8d: /* Unknown */
  2928.     case 0x8e: /* Unknown */
  2929.     case 0x94: /* Unknown */
  2930.     case 0x95: /* Unknown */
  2931.     default:
  2932.         pr_info("Unknown event received %x\n", event);
  2933.         break;
  2934.     }
  2935.  
  2936.     acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
  2937.                     dev_name(&acpi_dev->dev),
  2938.                     event, (event == 0x80)?
  2939.                     dev->last_key_event : 0);
  2940. }
  2941.  
  2942. #ifdef CONFIG_PM_SLEEP
  2943. static int toshiba_acpi_suspend(struct device *device)
  2944. {
  2945.     struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
  2946.  
  2947.     if (dev->hotkey_dev) {
  2948.         u32 result;
  2949.  
  2950.         result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
  2951.         if (result != TOS_SUCCESS)
  2952.             pr_info("Unable to disable hotkeys\n");
  2953.     }
  2954.  
  2955.     return 0;
  2956. }
  2957.  
  2958. static int toshiba_acpi_resume(struct device *device)
  2959. {
  2960.     struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
  2961.  
  2962.     if (dev->hotkey_dev) {
  2963.         int error = toshiba_acpi_enable_hotkeys(dev);
  2964.  
  2965.         if (error)
  2966.             pr_info("Unable to re-enable hotkeys\n");
  2967.     }
  2968.  
  2969.     return 0;
  2970. }
  2971. #endif
  2972.  
  2973. static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
  2974.              toshiba_acpi_suspend, toshiba_acpi_resume);
  2975.  
  2976. static struct acpi_driver toshiba_acpi_driver = {
  2977.     .name   = "Toshiba ACPI driver",
  2978.     .owner  = THIS_MODULE,
  2979.     .ids    = toshiba_device_ids,
  2980.     .flags  = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
  2981.     .ops    = {
  2982.         .add        = toshiba_acpi_add,
  2983.         .remove     = toshiba_acpi_remove,
  2984.         .notify     = toshiba_acpi_notify,
  2985.     },
  2986.     .drv.pm = &toshiba_acpi_pm,
  2987. };
  2988.  
  2989. static int __init toshiba_acpi_init(void)
  2990. {
  2991.     int ret;
  2992.  
  2993.     toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
  2994.     if (!toshiba_proc_dir) {
  2995.         pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
  2996.         return -ENODEV;
  2997.     }
  2998.  
  2999.     ret = acpi_bus_register_driver(&toshiba_acpi_driver);
  3000.     if (ret) {
  3001.         pr_err("Failed to register ACPI driver: %d\n", ret);
  3002.         remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
  3003.     }
  3004.  
  3005.     return ret;
  3006. }
  3007.  
  3008. static void __exit toshiba_acpi_exit(void)
  3009. {
  3010.     acpi_bus_unregister_driver(&toshiba_acpi_driver);
  3011.     if (toshiba_proc_dir)
  3012.         remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
  3013. }
  3014.  
  3015. module_init(toshiba_acpi_init);
  3016. module_exit(toshiba_acpi_exit);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement