0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0021
0022 #define TOSHIBA_ACPI_VERSION "0.24"
0023 #define PROC_INTERFACE_VERSION 1
0024
0025 #include <linux/compiler.h>
0026 #include <linux/kernel.h>
0027 #include <linux/module.h>
0028 #include <linux/moduleparam.h>
0029 #include <linux/init.h>
0030 #include <linux/types.h>
0031 #include <linux/proc_fs.h>
0032 #include <linux/seq_file.h>
0033 #include <linux/backlight.h>
0034 #include <linux/input.h>
0035 #include <linux/input/sparse-keymap.h>
0036 #include <linux/leds.h>
0037 #include <linux/slab.h>
0038 #include <linux/workqueue.h>
0039 #include <linux/i8042.h>
0040 #include <linux/acpi.h>
0041 #include <linux/dmi.h>
0042 #include <linux/uaccess.h>
0043 #include <linux/miscdevice.h>
0044 #include <linux/rfkill.h>
0045 #include <linux/iio/iio.h>
0046 #include <linux/toshiba.h>
0047 #include <acpi/video.h>
0048
0049 MODULE_AUTHOR("John Belmonte");
0050 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
0051 MODULE_LICENSE("GPL");
0052
0053 #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
0054
0055
0056 #define TOS1900_FN_SCAN 0x6e
0057
0058
0059 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 #define TCI_WORDS 6
0077
0078
0079 #define HCI_SET 0xff00
0080 #define HCI_GET 0xfe00
0081 #define SCI_OPEN 0xf100
0082 #define SCI_CLOSE 0xf200
0083 #define SCI_GET 0xf300
0084 #define SCI_SET 0xf400
0085
0086
0087 #define TOS_SUCCESS 0x0000
0088 #define TOS_SUCCESS2 0x0001
0089 #define TOS_OPEN_CLOSE_OK 0x0044
0090 #define TOS_FAILURE 0x1000
0091 #define TOS_NOT_SUPPORTED 0x8000
0092 #define TOS_ALREADY_OPEN 0x8100
0093 #define TOS_NOT_OPENED 0x8200
0094 #define TOS_INPUT_DATA_ERROR 0x8300
0095 #define TOS_WRITE_PROTECTED 0x8400
0096 #define TOS_NOT_PRESENT 0x8600
0097 #define TOS_FIFO_EMPTY 0x8c00
0098 #define TOS_DATA_NOT_AVAILABLE 0x8d20
0099 #define TOS_NOT_INITIALIZED 0x8d50
0100 #define TOS_NOT_INSTALLED 0x8e00
0101
0102
0103 #define HCI_FAN 0x0004
0104 #define HCI_TR_BACKLIGHT 0x0005
0105 #define HCI_SYSTEM_EVENT 0x0016
0106 #define HCI_VIDEO_OUT 0x001c
0107 #define HCI_HOTKEY_EVENT 0x001e
0108 #define HCI_LCD_BRIGHTNESS 0x002a
0109 #define HCI_WIRELESS 0x0056
0110 #define HCI_ACCELEROMETER 0x006d
0111 #define HCI_COOLING_METHOD 0x007f
0112 #define HCI_KBD_ILLUMINATION 0x0095
0113 #define HCI_ECO_MODE 0x0097
0114 #define HCI_ACCELEROMETER2 0x00a6
0115 #define HCI_SYSTEM_INFO 0xc000
0116 #define SCI_PANEL_POWER_ON 0x010d
0117 #define SCI_ILLUMINATION 0x014e
0118 #define SCI_USB_SLEEP_CHARGE 0x0150
0119 #define SCI_KBD_ILLUM_STATUS 0x015c
0120 #define SCI_USB_SLEEP_MUSIC 0x015e
0121 #define SCI_USB_THREE 0x0169
0122 #define SCI_TOUCHPAD 0x050e
0123 #define SCI_KBD_FUNCTION_KEYS 0x0522
0124
0125
0126 #define HCI_ACCEL_MASK 0x7fff
0127 #define HCI_ACCEL_DIRECTION_MASK 0x8000
0128 #define HCI_HOTKEY_DISABLE 0x0b
0129 #define HCI_HOTKEY_ENABLE 0x09
0130 #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
0131 #define HCI_LCD_BRIGHTNESS_BITS 3
0132 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
0133 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
0134 #define HCI_MISC_SHIFT 0x10
0135 #define HCI_SYSTEM_TYPE1 0x10
0136 #define HCI_SYSTEM_TYPE2 0x11
0137 #define HCI_VIDEO_OUT_LCD 0x1
0138 #define HCI_VIDEO_OUT_CRT 0x2
0139 #define HCI_VIDEO_OUT_TV 0x4
0140 #define SCI_KBD_MODE_MASK 0x1f
0141 #define SCI_KBD_MODE_FNZ 0x1
0142 #define SCI_KBD_MODE_AUTO 0x2
0143 #define SCI_KBD_MODE_ON 0x8
0144 #define SCI_KBD_MODE_OFF 0x10
0145 #define SCI_KBD_TIME_MAX 0x3c001a
0146 #define HCI_WIRELESS_STATUS 0x1
0147 #define HCI_WIRELESS_WWAN 0x3
0148 #define HCI_WIRELESS_WWAN_STATUS 0x2000
0149 #define HCI_WIRELESS_WWAN_POWER 0x4000
0150 #define SCI_USB_CHARGE_MODE_MASK 0xff
0151 #define SCI_USB_CHARGE_DISABLED 0x00
0152 #define SCI_USB_CHARGE_ALTERNATE 0x09
0153 #define SCI_USB_CHARGE_TYPICAL 0x11
0154 #define SCI_USB_CHARGE_AUTO 0x21
0155 #define SCI_USB_CHARGE_BAT_MASK 0x7
0156 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
0157 #define SCI_USB_CHARGE_BAT_LVL_ON 0x4
0158 #define SCI_USB_CHARGE_BAT_LVL 0x0200
0159 #define SCI_USB_CHARGE_RAPID_DSP 0x0300
0160
0161 struct toshiba_acpi_dev {
0162 struct acpi_device *acpi_dev;
0163 const char *method_hci;
0164 struct input_dev *hotkey_dev;
0165 struct work_struct hotkey_work;
0166 struct backlight_device *backlight_dev;
0167 struct led_classdev led_dev;
0168 struct led_classdev kbd_led;
0169 struct led_classdev eco_led;
0170 struct miscdevice miscdev;
0171 struct rfkill *wwan_rfk;
0172 struct iio_dev *indio_dev;
0173
0174 int force_fan;
0175 int last_key_event;
0176 int key_event_valid;
0177 int kbd_type;
0178 int kbd_mode;
0179 int kbd_time;
0180 int usbsc_bat_level;
0181 int usbsc_mode_base;
0182 int hotkey_event_type;
0183 int max_cooling_method;
0184
0185 unsigned int illumination_supported:1;
0186 unsigned int video_supported:1;
0187 unsigned int fan_supported:1;
0188 unsigned int system_event_supported:1;
0189 unsigned int ntfy_supported:1;
0190 unsigned int info_supported:1;
0191 unsigned int tr_backlight_supported:1;
0192 unsigned int kbd_illum_supported:1;
0193 unsigned int touchpad_supported:1;
0194 unsigned int eco_supported:1;
0195 unsigned int accelerometer_supported:1;
0196 unsigned int usb_sleep_charge_supported:1;
0197 unsigned int usb_rapid_charge_supported:1;
0198 unsigned int usb_sleep_music_supported:1;
0199 unsigned int kbd_function_keys_supported:1;
0200 unsigned int panel_power_on_supported:1;
0201 unsigned int usb_three_supported:1;
0202 unsigned int wwan_supported:1;
0203 unsigned int cooling_method_supported:1;
0204 unsigned int sysfs_created:1;
0205 unsigned int special_functions;
0206
0207 bool kbd_event_generated;
0208 bool killswitch;
0209 };
0210
0211 static struct toshiba_acpi_dev *toshiba_acpi;
0212
0213 static bool disable_hotkeys;
0214 module_param(disable_hotkeys, bool, 0444);
0215 MODULE_PARM_DESC(disable_hotkeys, "Disables the hotkeys activation");
0216
0217 static const struct acpi_device_id toshiba_device_ids[] = {
0218 {"TOS6200", 0},
0219 {"TOS6207", 0},
0220 {"TOS6208", 0},
0221 {"TOS1900", 0},
0222 {"", 0},
0223 };
0224 MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
0225
0226 static const struct key_entry toshiba_acpi_keymap[] = {
0227 { KE_KEY, 0x9e, { KEY_RFKILL } },
0228 { KE_KEY, 0x101, { KEY_MUTE } },
0229 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
0230 { KE_KEY, 0x103, { KEY_ZOOMIN } },
0231 { KE_KEY, 0x10f, { KEY_TAB } },
0232 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
0233 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
0234 { KE_KEY, 0x13b, { KEY_COFFEE } },
0235 { KE_KEY, 0x13c, { KEY_BATTERY } },
0236 { KE_KEY, 0x13d, { KEY_SLEEP } },
0237 { KE_KEY, 0x13e, { KEY_SUSPEND } },
0238 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
0239 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
0240 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
0241 { KE_KEY, 0x142, { KEY_WLAN } },
0242 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
0243 { KE_KEY, 0x17f, { KEY_FN } },
0244 { KE_KEY, 0xb05, { KEY_PROG2 } },
0245 { KE_KEY, 0xb06, { KEY_WWW } },
0246 { KE_KEY, 0xb07, { KEY_MAIL } },
0247 { KE_KEY, 0xb30, { KEY_STOP } },
0248 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
0249 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
0250 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
0251 { KE_KEY, 0xb5a, { KEY_MEDIA } },
0252 { KE_IGNORE, 0x1430, { KEY_RESERVED } },
0253 { KE_IGNORE, 0x1501, { KEY_RESERVED } },
0254 { KE_IGNORE, 0x1502, { KEY_RESERVED } },
0255 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } },
0256 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } },
0257 { KE_END, 0 },
0258 };
0259
0260 static const struct key_entry toshiba_acpi_alt_keymap[] = {
0261 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
0262 { KE_KEY, 0x103, { KEY_ZOOMIN } },
0263 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
0264 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
0265 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
0266 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
0267 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
0268 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
0269 { KE_KEY, 0x157, { KEY_MUTE } },
0270 { KE_KEY, 0x158, { KEY_WLAN } },
0271 { KE_END, 0 },
0272 };
0273
0274
0275
0276
0277
0278 static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = {
0279 {}
0280 };
0281
0282
0283
0284
0285
0286 static inline void _set_bit(u32 *word, u32 mask, int value)
0287 {
0288 *word = (*word & ~mask) | (mask * value);
0289 }
0290
0291
0292
0293
0294
0295 static int write_acpi_int(const char *methodName, int val)
0296 {
0297 acpi_status status;
0298
0299 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
0300 return (status == AE_OK) ? 0 : -EIO;
0301 }
0302
0303
0304
0305
0306
0307 static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
0308 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
0309 {
0310 union acpi_object in_objs[TCI_WORDS], out_objs[TCI_WORDS + 1];
0311 struct acpi_object_list params;
0312 struct acpi_buffer results;
0313 acpi_status status;
0314 int i;
0315
0316 params.count = TCI_WORDS;
0317 params.pointer = in_objs;
0318 for (i = 0; i < TCI_WORDS; ++i) {
0319 in_objs[i].type = ACPI_TYPE_INTEGER;
0320 in_objs[i].integer.value = in[i];
0321 }
0322
0323 results.length = sizeof(out_objs);
0324 results.pointer = out_objs;
0325
0326 status = acpi_evaluate_object(dev->acpi_dev->handle,
0327 (char *)dev->method_hci, ¶ms,
0328 &results);
0329 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
0330 for (i = 0; i < out_objs->package.count; ++i)
0331 out[i] = out_objs->package.elements[i].integer.value;
0332 }
0333
0334 return status;
0335 }
0336
0337
0338
0339
0340
0341
0342
0343
0344 static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
0345 {
0346 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
0347 u32 out[TCI_WORDS];
0348 acpi_status status = tci_raw(dev, in, out);
0349
0350 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
0351 }
0352
0353 static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
0354 {
0355 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
0356 u32 out[TCI_WORDS];
0357 acpi_status status = tci_raw(dev, in, out);
0358
0359 if (ACPI_FAILURE(status))
0360 return TOS_FAILURE;
0361
0362 *out1 = out[2];
0363
0364 return out[0];
0365 }
0366
0367
0368
0369
0370
0371 static int sci_open(struct toshiba_acpi_dev *dev)
0372 {
0373 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
0374 u32 out[TCI_WORDS];
0375 acpi_status status = tci_raw(dev, in, out);
0376
0377 if (ACPI_FAILURE(status)) {
0378 pr_err("ACPI call to open SCI failed\n");
0379 return 0;
0380 }
0381
0382 if (out[0] == TOS_OPEN_CLOSE_OK) {
0383 return 1;
0384 } else if (out[0] == TOS_ALREADY_OPEN) {
0385 pr_info("Toshiba SCI already opened\n");
0386 return 1;
0387 } else if (out[0] == TOS_NOT_SUPPORTED) {
0388
0389
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400 return 1;
0401 } else if (out[0] == TOS_NOT_PRESENT) {
0402 pr_info("Toshiba SCI is not present\n");
0403 }
0404
0405 return 0;
0406 }
0407
0408 static void sci_close(struct toshiba_acpi_dev *dev)
0409 {
0410 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
0411 u32 out[TCI_WORDS];
0412 acpi_status status = tci_raw(dev, in, out);
0413
0414 if (ACPI_FAILURE(status)) {
0415 pr_err("ACPI call to close SCI failed\n");
0416 return;
0417 }
0418
0419 if (out[0] == TOS_OPEN_CLOSE_OK)
0420 return;
0421 else if (out[0] == TOS_NOT_OPENED)
0422 pr_info("Toshiba SCI not opened\n");
0423 else if (out[0] == TOS_NOT_PRESENT)
0424 pr_info("Toshiba SCI is not present\n");
0425 }
0426
0427 static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
0428 {
0429 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
0430 u32 out[TCI_WORDS];
0431 acpi_status status = tci_raw(dev, in, out);
0432
0433 if (ACPI_FAILURE(status))
0434 return TOS_FAILURE;
0435
0436 *out1 = out[2];
0437
0438 return out[0];
0439 }
0440
0441 static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
0442 {
0443 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
0444 u32 out[TCI_WORDS];
0445 acpi_status status = tci_raw(dev, in, out);
0446
0447 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
0448 }
0449
0450
0451 static void toshiba_illumination_available(struct toshiba_acpi_dev *dev)
0452 {
0453 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
0454 u32 out[TCI_WORDS];
0455 acpi_status status;
0456
0457 dev->illumination_supported = 0;
0458
0459 if (!sci_open(dev))
0460 return;
0461
0462 status = tci_raw(dev, in, out);
0463 sci_close(dev);
0464 if (ACPI_FAILURE(status)) {
0465 pr_err("ACPI call to query Illumination support failed\n");
0466 return;
0467 }
0468
0469 if (out[0] != TOS_SUCCESS)
0470 return;
0471
0472 dev->illumination_supported = 1;
0473 }
0474
0475 static void toshiba_illumination_set(struct led_classdev *cdev,
0476 enum led_brightness brightness)
0477 {
0478 struct toshiba_acpi_dev *dev = container_of(cdev,
0479 struct toshiba_acpi_dev, led_dev);
0480 u32 result;
0481 u32 state;
0482
0483
0484 if (!sci_open(dev))
0485 return;
0486
0487
0488 state = brightness ? 1 : 0;
0489 result = sci_write(dev, SCI_ILLUMINATION, state);
0490 sci_close(dev);
0491 if (result == TOS_FAILURE)
0492 pr_err("ACPI call for illumination failed\n");
0493 }
0494
0495 static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
0496 {
0497 struct toshiba_acpi_dev *dev = container_of(cdev,
0498 struct toshiba_acpi_dev, led_dev);
0499 u32 result;
0500 u32 state;
0501
0502
0503 if (!sci_open(dev))
0504 return LED_OFF;
0505
0506
0507 result = sci_read(dev, SCI_ILLUMINATION, &state);
0508 sci_close(dev);
0509 if (result == TOS_FAILURE) {
0510 pr_err("ACPI call for illumination failed\n");
0511 return LED_OFF;
0512 } else if (result != TOS_SUCCESS) {
0513 return LED_OFF;
0514 }
0515
0516 return state ? LED_FULL : LED_OFF;
0517 }
0518
0519
0520 static void toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
0521 {
0522 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
0523 u32 out[TCI_WORDS];
0524 acpi_status status;
0525
0526 dev->kbd_illum_supported = 0;
0527 dev->kbd_event_generated = false;
0528
0529 if (!sci_open(dev))
0530 return;
0531
0532 status = tci_raw(dev, in, out);
0533 sci_close(dev);
0534 if (ACPI_FAILURE(status)) {
0535 pr_err("ACPI call to query kbd illumination support failed\n");
0536 return;
0537 }
0538
0539 if (out[0] != TOS_SUCCESS)
0540 return;
0541
0542
0543
0544
0545
0546
0547
0548 if (out[3] == SCI_KBD_TIME_MAX)
0549 dev->kbd_type = 2;
0550 else
0551 dev->kbd_type = 1;
0552
0553 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
0554
0555 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
0556
0557 dev->kbd_illum_supported = 1;
0558 }
0559
0560 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
0561 {
0562 u32 result;
0563
0564 if (!sci_open(dev))
0565 return -EIO;
0566
0567 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
0568 sci_close(dev);
0569 if (result == TOS_FAILURE)
0570 pr_err("ACPI call to set KBD backlight status failed\n");
0571 else if (result == TOS_NOT_SUPPORTED)
0572 return -ENODEV;
0573
0574 return result == TOS_SUCCESS ? 0 : -EIO;
0575 }
0576
0577 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
0578 {
0579 u32 result;
0580
0581 if (!sci_open(dev))
0582 return -EIO;
0583
0584 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
0585 sci_close(dev);
0586 if (result == TOS_FAILURE)
0587 pr_err("ACPI call to get KBD backlight status failed\n");
0588 else if (result == TOS_NOT_SUPPORTED)
0589 return -ENODEV;
0590
0591 return result == TOS_SUCCESS ? 0 : -EIO;
0592 }
0593
0594 static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
0595 {
0596 struct toshiba_acpi_dev *dev = container_of(cdev,
0597 struct toshiba_acpi_dev, kbd_led);
0598 u32 result;
0599 u32 state;
0600
0601
0602 result = hci_read(dev, HCI_KBD_ILLUMINATION, &state);
0603 if (result == TOS_FAILURE) {
0604 pr_err("ACPI call to get the keyboard backlight failed\n");
0605 return LED_OFF;
0606 } else if (result != TOS_SUCCESS) {
0607 return LED_OFF;
0608 }
0609
0610 return state ? LED_FULL : LED_OFF;
0611 }
0612
0613 static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
0614 enum led_brightness brightness)
0615 {
0616 struct toshiba_acpi_dev *dev = container_of(cdev,
0617 struct toshiba_acpi_dev, kbd_led);
0618 u32 result;
0619 u32 state;
0620
0621
0622 state = brightness ? 1 : 0;
0623 result = hci_write(dev, HCI_KBD_ILLUMINATION, state);
0624 if (result == TOS_FAILURE)
0625 pr_err("ACPI call to set KBD Illumination mode failed\n");
0626 }
0627
0628
0629 static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
0630 {
0631 u32 result;
0632
0633 if (!sci_open(dev))
0634 return -EIO;
0635
0636 result = sci_write(dev, SCI_TOUCHPAD, state);
0637 sci_close(dev);
0638 if (result == TOS_FAILURE)
0639 pr_err("ACPI call to set the touchpad failed\n");
0640 else if (result == TOS_NOT_SUPPORTED)
0641 return -ENODEV;
0642
0643 return result == TOS_SUCCESS ? 0 : -EIO;
0644 }
0645
0646 static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
0647 {
0648 u32 result;
0649
0650 if (!sci_open(dev))
0651 return -EIO;
0652
0653 result = sci_read(dev, SCI_TOUCHPAD, state);
0654 sci_close(dev);
0655 if (result == TOS_FAILURE)
0656 pr_err("ACPI call to query the touchpad failed\n");
0657 else if (result == TOS_NOT_SUPPORTED)
0658 return -ENODEV;
0659
0660 return result == TOS_SUCCESS ? 0 : -EIO;
0661 }
0662
0663
0664 static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
0665 {
0666 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
0667 u32 out[TCI_WORDS];
0668 acpi_status status;
0669
0670 dev->eco_supported = 0;
0671
0672 status = tci_raw(dev, in, out);
0673 if (ACPI_FAILURE(status)) {
0674 pr_err("ACPI call to get ECO led failed\n");
0675 return;
0676 }
0677
0678 if (out[0] == TOS_INPUT_DATA_ERROR) {
0679
0680
0681
0682
0683
0684
0685
0686
0687
0688 in[3] = 1;
0689 status = tci_raw(dev, in, out);
0690 if (ACPI_FAILURE(status)) {
0691 pr_err("ACPI call to get ECO led failed\n");
0692 return;
0693 }
0694
0695 if (out[0] != TOS_SUCCESS)
0696 return;
0697
0698 dev->eco_supported = 1;
0699 }
0700 }
0701
0702 static enum led_brightness
0703 toshiba_eco_mode_get_status(struct led_classdev *cdev)
0704 {
0705 struct toshiba_acpi_dev *dev = container_of(cdev,
0706 struct toshiba_acpi_dev, eco_led);
0707 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
0708 u32 out[TCI_WORDS];
0709 acpi_status status;
0710
0711 status = tci_raw(dev, in, out);
0712 if (ACPI_FAILURE(status)) {
0713 pr_err("ACPI call to get ECO led failed\n");
0714 return LED_OFF;
0715 }
0716
0717 if (out[0] != TOS_SUCCESS)
0718 return LED_OFF;
0719
0720 return out[2] ? LED_FULL : LED_OFF;
0721 }
0722
0723 static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
0724 enum led_brightness brightness)
0725 {
0726 struct toshiba_acpi_dev *dev = container_of(cdev,
0727 struct toshiba_acpi_dev, eco_led);
0728 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
0729 u32 out[TCI_WORDS];
0730 acpi_status status;
0731
0732
0733 in[2] = (brightness) ? 1 : 0;
0734 status = tci_raw(dev, in, out);
0735 if (ACPI_FAILURE(status))
0736 pr_err("ACPI call to set ECO led failed\n");
0737 }
0738
0739
0740 static void toshiba_accelerometer_available(struct toshiba_acpi_dev *dev)
0741 {
0742 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
0743 u32 out[TCI_WORDS];
0744 acpi_status status;
0745
0746 dev->accelerometer_supported = 0;
0747
0748
0749
0750
0751
0752 status = tci_raw(dev, in, out);
0753 if (ACPI_FAILURE(status)) {
0754 pr_err("ACPI call to query the accelerometer failed\n");
0755 return;
0756 }
0757
0758 if (out[0] != TOS_SUCCESS)
0759 return;
0760
0761 dev->accelerometer_supported = 1;
0762 }
0763
0764 static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
0765 u32 *xy, u32 *z)
0766 {
0767 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
0768 u32 out[TCI_WORDS];
0769 acpi_status status;
0770
0771
0772 status = tci_raw(dev, in, out);
0773 if (ACPI_FAILURE(status)) {
0774 pr_err("ACPI call to query the accelerometer failed\n");
0775 return -EIO;
0776 }
0777
0778 if (out[0] == TOS_NOT_SUPPORTED)
0779 return -ENODEV;
0780
0781 if (out[0] != TOS_SUCCESS)
0782 return -EIO;
0783
0784 *xy = out[2];
0785 *z = out[4];
0786
0787 return 0;
0788 }
0789
0790
0791 static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
0792 {
0793 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
0794 u32 out[TCI_WORDS];
0795 acpi_status status;
0796
0797 dev->usb_sleep_charge_supported = 0;
0798
0799 if (!sci_open(dev))
0800 return;
0801
0802 status = tci_raw(dev, in, out);
0803 if (ACPI_FAILURE(status)) {
0804 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
0805 sci_close(dev);
0806 return;
0807 }
0808
0809 if (out[0] != TOS_SUCCESS) {
0810 sci_close(dev);
0811 return;
0812 }
0813
0814 dev->usbsc_mode_base = out[4];
0815
0816 in[5] = SCI_USB_CHARGE_BAT_LVL;
0817 status = tci_raw(dev, in, out);
0818 sci_close(dev);
0819 if (ACPI_FAILURE(status)) {
0820 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
0821 return;
0822 }
0823
0824 if (out[0] != TOS_SUCCESS)
0825 return;
0826
0827 dev->usbsc_bat_level = out[2];
0828
0829 dev->usb_sleep_charge_supported = 1;
0830 }
0831
0832 static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
0833 u32 *mode)
0834 {
0835 u32 result;
0836
0837 if (!sci_open(dev))
0838 return -EIO;
0839
0840 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
0841 sci_close(dev);
0842 if (result == TOS_FAILURE)
0843 pr_err("ACPI call to set USB S&C mode failed\n");
0844 else if (result == TOS_NOT_SUPPORTED)
0845 return -ENODEV;
0846
0847 return result == TOS_SUCCESS ? 0 : -EIO;
0848 }
0849
0850 static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
0851 u32 mode)
0852 {
0853 u32 result;
0854
0855 if (!sci_open(dev))
0856 return -EIO;
0857
0858 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
0859 sci_close(dev);
0860 if (result == TOS_FAILURE)
0861 pr_err("ACPI call to set USB S&C mode failed\n");
0862 else if (result == TOS_NOT_SUPPORTED)
0863 return -ENODEV;
0864
0865 return result == TOS_SUCCESS ? 0 : -EIO;
0866 }
0867
0868 static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
0869 u32 *mode)
0870 {
0871 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
0872 u32 out[TCI_WORDS];
0873 acpi_status status;
0874
0875 if (!sci_open(dev))
0876 return -EIO;
0877
0878 in[5] = SCI_USB_CHARGE_BAT_LVL;
0879 status = tci_raw(dev, in, out);
0880 sci_close(dev);
0881 if (ACPI_FAILURE(status)) {
0882 pr_err("ACPI call to get USB S&C battery level failed\n");
0883 return -EIO;
0884 }
0885
0886 if (out[0] == TOS_NOT_SUPPORTED)
0887 return -ENODEV;
0888
0889 if (out[0] != TOS_SUCCESS)
0890 return -EIO;
0891
0892 *mode = out[2];
0893
0894 return 0;
0895
0896 }
0897
0898 static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
0899 u32 mode)
0900 {
0901 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
0902 u32 out[TCI_WORDS];
0903 acpi_status status;
0904
0905 if (!sci_open(dev))
0906 return -EIO;
0907
0908 in[2] = mode;
0909 in[5] = SCI_USB_CHARGE_BAT_LVL;
0910 status = tci_raw(dev, in, out);
0911 sci_close(dev);
0912 if (ACPI_FAILURE(status)) {
0913 pr_err("ACPI call to set USB S&C battery level failed\n");
0914 return -EIO;
0915 }
0916
0917 if (out[0] == TOS_NOT_SUPPORTED)
0918 return -ENODEV;
0919
0920 return out[0] == TOS_SUCCESS ? 0 : -EIO;
0921 }
0922
0923 static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
0924 u32 *state)
0925 {
0926 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
0927 u32 out[TCI_WORDS];
0928 acpi_status status;
0929
0930 if (!sci_open(dev))
0931 return -EIO;
0932
0933 in[5] = SCI_USB_CHARGE_RAPID_DSP;
0934 status = tci_raw(dev, in, out);
0935 sci_close(dev);
0936 if (ACPI_FAILURE(status)) {
0937 pr_err("ACPI call to get USB Rapid Charge failed\n");
0938 return -EIO;
0939 }
0940
0941 if (out[0] == TOS_NOT_SUPPORTED)
0942 return -ENODEV;
0943
0944 if (out[0] != TOS_SUCCESS && out[0] != TOS_SUCCESS2)
0945 return -EIO;
0946
0947 *state = out[2];
0948
0949 return 0;
0950 }
0951
0952 static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
0953 u32 state)
0954 {
0955 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
0956 u32 out[TCI_WORDS];
0957 acpi_status status;
0958
0959 if (!sci_open(dev))
0960 return -EIO;
0961
0962 in[2] = state;
0963 in[5] = SCI_USB_CHARGE_RAPID_DSP;
0964 status = tci_raw(dev, in, out);
0965 sci_close(dev);
0966 if (ACPI_FAILURE(status)) {
0967 pr_err("ACPI call to set USB Rapid Charge failed\n");
0968 return -EIO;
0969 }
0970
0971 if (out[0] == TOS_NOT_SUPPORTED)
0972 return -ENODEV;
0973
0974 return (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) ? 0 : -EIO;
0975 }
0976
0977 static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
0978 {
0979 u32 result;
0980
0981 if (!sci_open(dev))
0982 return -EIO;
0983
0984 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
0985 sci_close(dev);
0986 if (result == TOS_FAILURE)
0987 pr_err("ACPI call to get Sleep and Music failed\n");
0988 else if (result == TOS_NOT_SUPPORTED)
0989 return -ENODEV;
0990
0991 return result == TOS_SUCCESS ? 0 : -EIO;
0992 }
0993
0994 static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
0995 {
0996 u32 result;
0997
0998 if (!sci_open(dev))
0999 return -EIO;
1000
1001 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
1002 sci_close(dev);
1003 if (result == TOS_FAILURE)
1004 pr_err("ACPI call to set Sleep and Music failed\n");
1005 else if (result == TOS_NOT_SUPPORTED)
1006 return -ENODEV;
1007
1008 return result == TOS_SUCCESS ? 0 : -EIO;
1009 }
1010
1011
1012 static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
1013 {
1014 u32 result;
1015
1016 if (!sci_open(dev))
1017 return -EIO;
1018
1019 result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
1020 sci_close(dev);
1021 if (result == TOS_FAILURE)
1022 pr_err("ACPI call to get KBD function keys failed\n");
1023 else if (result == TOS_NOT_SUPPORTED)
1024 return -ENODEV;
1025
1026 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
1027 }
1028
1029 static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
1030 {
1031 u32 result;
1032
1033 if (!sci_open(dev))
1034 return -EIO;
1035
1036 result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
1037 sci_close(dev);
1038 if (result == TOS_FAILURE)
1039 pr_err("ACPI call to set KBD function keys failed\n");
1040 else if (result == TOS_NOT_SUPPORTED)
1041 return -ENODEV;
1042
1043 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
1044 }
1045
1046
1047 static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
1048 {
1049 u32 result;
1050
1051 if (!sci_open(dev))
1052 return -EIO;
1053
1054 result = sci_read(dev, SCI_PANEL_POWER_ON, state);
1055 sci_close(dev);
1056 if (result == TOS_FAILURE)
1057 pr_err("ACPI call to get Panel Power ON failed\n");
1058 else if (result == TOS_NOT_SUPPORTED)
1059 return -ENODEV;
1060
1061 return result == TOS_SUCCESS ? 0 : -EIO;
1062 }
1063
1064 static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
1065 {
1066 u32 result;
1067
1068 if (!sci_open(dev))
1069 return -EIO;
1070
1071 result = sci_write(dev, SCI_PANEL_POWER_ON, state);
1072 sci_close(dev);
1073 if (result == TOS_FAILURE)
1074 pr_err("ACPI call to set Panel Power ON failed\n");
1075 else if (result == TOS_NOT_SUPPORTED)
1076 return -ENODEV;
1077
1078 return result == TOS_SUCCESS ? 0 : -EIO;
1079 }
1080
1081
1082 static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
1083 {
1084 u32 result;
1085
1086 if (!sci_open(dev))
1087 return -EIO;
1088
1089 result = sci_read(dev, SCI_USB_THREE, state);
1090 sci_close(dev);
1091 if (result == TOS_FAILURE)
1092 pr_err("ACPI call to get USB 3 failed\n");
1093 else if (result == TOS_NOT_SUPPORTED)
1094 return -ENODEV;
1095
1096 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
1097 }
1098
1099 static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
1100 {
1101 u32 result;
1102
1103 if (!sci_open(dev))
1104 return -EIO;
1105
1106 result = sci_write(dev, SCI_USB_THREE, state);
1107 sci_close(dev);
1108 if (result == TOS_FAILURE)
1109 pr_err("ACPI call to set USB 3 failed\n");
1110 else if (result == TOS_NOT_SUPPORTED)
1111 return -ENODEV;
1112
1113 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
1114 }
1115
1116
1117 static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
1118 u32 *type)
1119 {
1120 u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 };
1121 u32 out[TCI_WORDS];
1122 acpi_status status;
1123
1124 status = tci_raw(dev, in, out);
1125 if (ACPI_FAILURE(status)) {
1126 pr_err("ACPI call to get System type failed\n");
1127 return -EIO;
1128 }
1129
1130 if (out[0] == TOS_NOT_SUPPORTED)
1131 return -ENODEV;
1132
1133 if (out[0] != TOS_SUCCESS)
1134 return -EIO;
1135
1136 *type = out[3];
1137
1138 return 0;
1139 }
1140
1141
1142 static int toshiba_wireless_status(struct toshiba_acpi_dev *dev)
1143 {
1144 u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
1145 u32 out[TCI_WORDS];
1146 acpi_status status;
1147
1148 in[3] = HCI_WIRELESS_STATUS;
1149 status = tci_raw(dev, in, out);
1150
1151 if (ACPI_FAILURE(status)) {
1152 pr_err("ACPI call to get Wireless status failed\n");
1153 return -EIO;
1154 }
1155
1156 if (out[0] == TOS_NOT_SUPPORTED)
1157 return -ENODEV;
1158
1159 if (out[0] != TOS_SUCCESS)
1160 return -EIO;
1161
1162 dev->killswitch = !!(out[2] & HCI_WIRELESS_STATUS);
1163
1164 return 0;
1165 }
1166
1167
1168 static void toshiba_wwan_available(struct toshiba_acpi_dev *dev)
1169 {
1170 u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
1171 u32 out[TCI_WORDS];
1172 acpi_status status;
1173
1174 dev->wwan_supported = 0;
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186 in[3] = HCI_WIRELESS_WWAN;
1187 status = tci_raw(dev, in, out);
1188 if (ACPI_FAILURE(status)) {
1189 pr_err("ACPI call to get WWAN status failed\n");
1190 return;
1191 }
1192
1193 if (out[0] != TOS_SUCCESS)
1194 return;
1195
1196 dev->wwan_supported = (out[2] == HCI_WIRELESS_WWAN_STATUS);
1197 }
1198
1199 static int toshiba_wwan_set(struct toshiba_acpi_dev *dev, u32 state)
1200 {
1201 u32 in[TCI_WORDS] = { HCI_SET, HCI_WIRELESS, state, 0, 0, 0 };
1202 u32 out[TCI_WORDS];
1203 acpi_status status;
1204
1205 in[3] = HCI_WIRELESS_WWAN_STATUS;
1206 status = tci_raw(dev, in, out);
1207 if (ACPI_FAILURE(status)) {
1208 pr_err("ACPI call to set WWAN status failed\n");
1209 return -EIO;
1210 }
1211
1212 if (out[0] == TOS_NOT_SUPPORTED)
1213 return -ENODEV;
1214
1215 if (out[0] != TOS_SUCCESS)
1216 return -EIO;
1217
1218
1219
1220
1221
1222
1223 in[3] = HCI_WIRELESS_WWAN_POWER;
1224 status = tci_raw(dev, in, out);
1225 if (ACPI_FAILURE(status)) {
1226 pr_err("ACPI call to set WWAN power failed\n");
1227 return -EIO;
1228 }
1229
1230 if (out[0] == TOS_NOT_SUPPORTED)
1231 return -ENODEV;
1232
1233 return out[0] == TOS_SUCCESS ? 0 : -EIO;
1234 }
1235
1236
1237 static void toshiba_cooling_method_available(struct toshiba_acpi_dev *dev)
1238 {
1239 u32 in[TCI_WORDS] = { HCI_GET, HCI_COOLING_METHOD, 0, 0, 0, 0 };
1240 u32 out[TCI_WORDS];
1241 acpi_status status;
1242
1243 dev->cooling_method_supported = 0;
1244 dev->max_cooling_method = 0;
1245
1246 status = tci_raw(dev, in, out);
1247 if (ACPI_FAILURE(status)) {
1248 pr_err("ACPI call to get Cooling Method failed\n");
1249 return;
1250 }
1251
1252 if (out[0] != TOS_SUCCESS && out[0] != TOS_SUCCESS2)
1253 return;
1254
1255 dev->cooling_method_supported = 1;
1256 dev->max_cooling_method = out[3];
1257 }
1258
1259 static int toshiba_cooling_method_get(struct toshiba_acpi_dev *dev, u32 *state)
1260 {
1261 u32 result = hci_read(dev, HCI_COOLING_METHOD, state);
1262
1263 if (result == TOS_FAILURE)
1264 pr_err("ACPI call to get Cooling Method failed\n");
1265
1266 if (result == TOS_NOT_SUPPORTED)
1267 return -ENODEV;
1268
1269 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
1270 }
1271
1272 static int toshiba_cooling_method_set(struct toshiba_acpi_dev *dev, u32 state)
1273 {
1274 u32 result = hci_write(dev, HCI_COOLING_METHOD, state);
1275
1276 if (result == TOS_FAILURE)
1277 pr_err("ACPI call to set Cooling Method failed\n");
1278
1279 if (result == TOS_NOT_SUPPORTED)
1280 return -ENODEV;
1281
1282 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
1283 }
1284
1285
1286 static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status)
1287 {
1288 u32 result = hci_read(dev, HCI_TR_BACKLIGHT, status);
1289
1290 if (result == TOS_FAILURE)
1291 pr_err("ACPI call to get Transflective Backlight failed\n");
1292 else if (result == TOS_NOT_SUPPORTED)
1293 return -ENODEV;
1294
1295 return result == TOS_SUCCESS ? 0 : -EIO;
1296 }
1297
1298 static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 status)
1299 {
1300 u32 result = hci_write(dev, HCI_TR_BACKLIGHT, !status);
1301
1302 if (result == TOS_FAILURE)
1303 pr_err("ACPI call to set Transflective Backlight failed\n");
1304 else if (result == TOS_NOT_SUPPORTED)
1305 return -ENODEV;
1306
1307 return result == TOS_SUCCESS ? 0 : -EIO;
1308 }
1309
1310 static struct proc_dir_entry *toshiba_proc_dir;
1311
1312
1313 static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
1314 {
1315 int brightness = 0;
1316 u32 result;
1317 u32 value;
1318
1319 if (dev->tr_backlight_supported) {
1320 int ret = get_tr_backlight_status(dev, &value);
1321
1322 if (ret)
1323 return ret;
1324 if (value)
1325 return 0;
1326 brightness++;
1327 }
1328
1329 result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value);
1330 if (result == TOS_FAILURE)
1331 pr_err("ACPI call to get LCD Brightness failed\n");
1332 else if (result == TOS_NOT_SUPPORTED)
1333 return -ENODEV;
1334
1335 return result == TOS_SUCCESS ?
1336 brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT) :
1337 -EIO;
1338 }
1339
1340 static int get_lcd_brightness(struct backlight_device *bd)
1341 {
1342 struct toshiba_acpi_dev *dev = bl_get_data(bd);
1343
1344 return __get_lcd_brightness(dev);
1345 }
1346
1347 static int lcd_proc_show(struct seq_file *m, void *v)
1348 {
1349 struct toshiba_acpi_dev *dev = m->private;
1350 int levels;
1351 int value;
1352
1353 if (!dev->backlight_dev)
1354 return -ENODEV;
1355
1356 levels = dev->backlight_dev->props.max_brightness + 1;
1357 value = get_lcd_brightness(dev->backlight_dev);
1358 if (value < 0) {
1359 pr_err("Error reading LCD brightness\n");
1360 return value;
1361 }
1362
1363 seq_printf(m, "brightness: %d\n", value);
1364 seq_printf(m, "brightness_levels: %d\n", levels);
1365
1366 return 0;
1367 }
1368
1369 static int lcd_proc_open(struct inode *inode, struct file *file)
1370 {
1371 return single_open(file, lcd_proc_show, pde_data(inode));
1372 }
1373
1374 static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
1375 {
1376 u32 result;
1377
1378 if (dev->tr_backlight_supported) {
1379 int ret = set_tr_backlight_status(dev, !value);
1380
1381 if (ret)
1382 return ret;
1383 if (value)
1384 value--;
1385 }
1386
1387 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
1388 result = hci_write(dev, HCI_LCD_BRIGHTNESS, value);
1389 if (result == TOS_FAILURE)
1390 pr_err("ACPI call to set LCD Brightness failed\n");
1391 else if (result == TOS_NOT_SUPPORTED)
1392 return -ENODEV;
1393
1394 return result == TOS_SUCCESS ? 0 : -EIO;
1395 }
1396
1397 static int set_lcd_status(struct backlight_device *bd)
1398 {
1399 struct toshiba_acpi_dev *dev = bl_get_data(bd);
1400
1401 return set_lcd_brightness(dev, bd->props.brightness);
1402 }
1403
1404 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1405 size_t count, loff_t *pos)
1406 {
1407 struct toshiba_acpi_dev *dev = pde_data(file_inode(file));
1408 char cmd[42];
1409 size_t len;
1410 int levels;
1411 int value;
1412
1413 len = min(count, sizeof(cmd) - 1);
1414 if (copy_from_user(cmd, buf, len))
1415 return -EFAULT;
1416 cmd[len] = '\0';
1417
1418 levels = dev->backlight_dev->props.max_brightness + 1;
1419 if (sscanf(cmd, " brightness : %i", &value) != 1 &&
1420 value < 0 && value > levels)
1421 return -EINVAL;
1422
1423 if (set_lcd_brightness(dev, value))
1424 return -EIO;
1425
1426 return count;
1427 }
1428
1429 static const struct proc_ops lcd_proc_ops = {
1430 .proc_open = lcd_proc_open,
1431 .proc_read = seq_read,
1432 .proc_lseek = seq_lseek,
1433 .proc_release = single_release,
1434 .proc_write = lcd_proc_write,
1435 };
1436
1437
1438 static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1439 {
1440 u32 result = hci_read(dev, HCI_VIDEO_OUT, status);
1441
1442 if (result == TOS_FAILURE)
1443 pr_err("ACPI call to get Video-Out failed\n");
1444 else if (result == TOS_NOT_SUPPORTED)
1445 return -ENODEV;
1446
1447 return result == TOS_SUCCESS ? 0 : -EIO;
1448 }
1449
1450 static int video_proc_show(struct seq_file *m, void *v)
1451 {
1452 struct toshiba_acpi_dev *dev = m->private;
1453 int is_lcd, is_crt, is_tv;
1454 u32 value;
1455
1456 if (get_video_status(dev, &value))
1457 return -EIO;
1458
1459 is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1460 is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
1461 is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
1462
1463 seq_printf(m, "lcd_out: %d\n", is_lcd);
1464 seq_printf(m, "crt_out: %d\n", is_crt);
1465 seq_printf(m, "tv_out: %d\n", is_tv);
1466
1467 return 0;
1468 }
1469
1470 static int video_proc_open(struct inode *inode, struct file *file)
1471 {
1472 return single_open(file, video_proc_show, pde_data(inode));
1473 }
1474
1475 static ssize_t video_proc_write(struct file *file, const char __user *buf,
1476 size_t count, loff_t *pos)
1477 {
1478 struct toshiba_acpi_dev *dev = pde_data(file_inode(file));
1479 char *buffer;
1480 char *cmd;
1481 int lcd_out = -1, crt_out = -1, tv_out = -1;
1482 int remain = count;
1483 int value;
1484 int ret;
1485 u32 video_out;
1486
1487 cmd = memdup_user_nul(buf, count);
1488 if (IS_ERR(cmd))
1489 return PTR_ERR(cmd);
1490
1491 buffer = cmd;
1492
1493
1494
1495
1496
1497 while (remain) {
1498 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1499 lcd_out = value & 1;
1500 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1501 crt_out = value & 1;
1502 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1503 tv_out = value & 1;
1504
1505 do {
1506 ++buffer;
1507 --remain;
1508 } while (remain && *(buffer - 1) != ';');
1509 }
1510
1511 kfree(cmd);
1512
1513 ret = get_video_status(dev, &video_out);
1514 if (!ret) {
1515 unsigned int new_video_out = video_out;
1516
1517 if (lcd_out != -1)
1518 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1519 if (crt_out != -1)
1520 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1521 if (tv_out != -1)
1522 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
1523
1524
1525
1526
1527 if (new_video_out != video_out)
1528 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
1529 }
1530
1531 return ret ? -EIO : count;
1532 }
1533
1534 static const struct proc_ops video_proc_ops = {
1535 .proc_open = video_proc_open,
1536 .proc_read = seq_read,
1537 .proc_lseek = seq_lseek,
1538 .proc_release = single_release,
1539 .proc_write = video_proc_write,
1540 };
1541
1542
1543 static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1544 {
1545 u32 result = hci_read(dev, HCI_FAN, status);
1546
1547 if (result == TOS_FAILURE)
1548 pr_err("ACPI call to get Fan status failed\n");
1549 else if (result == TOS_NOT_SUPPORTED)
1550 return -ENODEV;
1551
1552 return result == TOS_SUCCESS ? 0 : -EIO;
1553 }
1554
1555 static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status)
1556 {
1557 u32 result = hci_write(dev, HCI_FAN, status);
1558
1559 if (result == TOS_FAILURE)
1560 pr_err("ACPI call to set Fan status failed\n");
1561 else if (result == TOS_NOT_SUPPORTED)
1562 return -ENODEV;
1563
1564 return result == TOS_SUCCESS ? 0 : -EIO;
1565 }
1566
1567 static int fan_proc_show(struct seq_file *m, void *v)
1568 {
1569 struct toshiba_acpi_dev *dev = m->private;
1570 u32 value;
1571
1572 if (get_fan_status(dev, &value))
1573 return -EIO;
1574
1575 seq_printf(m, "running: %d\n", (value > 0));
1576 seq_printf(m, "force_on: %d\n", dev->force_fan);
1577
1578 return 0;
1579 }
1580
1581 static int fan_proc_open(struct inode *inode, struct file *file)
1582 {
1583 return single_open(file, fan_proc_show, pde_data(inode));
1584 }
1585
1586 static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1587 size_t count, loff_t *pos)
1588 {
1589 struct toshiba_acpi_dev *dev = pde_data(file_inode(file));
1590 char cmd[42];
1591 size_t len;
1592 int value;
1593
1594 len = min(count, sizeof(cmd) - 1);
1595 if (copy_from_user(cmd, buf, len))
1596 return -EFAULT;
1597 cmd[len] = '\0';
1598
1599 if (sscanf(cmd, " force_on : %i", &value) != 1 &&
1600 value != 0 && value != 1)
1601 return -EINVAL;
1602
1603 if (set_fan_status(dev, value))
1604 return -EIO;
1605
1606 dev->force_fan = value;
1607
1608 return count;
1609 }
1610
1611 static const struct proc_ops fan_proc_ops = {
1612 .proc_open = fan_proc_open,
1613 .proc_read = seq_read,
1614 .proc_lseek = seq_lseek,
1615 .proc_release = single_release,
1616 .proc_write = fan_proc_write,
1617 };
1618
1619 static int keys_proc_show(struct seq_file *m, void *v)
1620 {
1621 struct toshiba_acpi_dev *dev = m->private;
1622
1623 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1624 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
1625
1626 return 0;
1627 }
1628
1629 static int keys_proc_open(struct inode *inode, struct file *file)
1630 {
1631 return single_open(file, keys_proc_show, pde_data(inode));
1632 }
1633
1634 static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1635 size_t count, loff_t *pos)
1636 {
1637 struct toshiba_acpi_dev *dev = pde_data(file_inode(file));
1638 char cmd[42];
1639 size_t len;
1640 int value;
1641
1642 len = min(count, sizeof(cmd) - 1);
1643 if (copy_from_user(cmd, buf, len))
1644 return -EFAULT;
1645 cmd[len] = '\0';
1646
1647 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
1648 dev->key_event_valid = 0;
1649 else
1650 return -EINVAL;
1651
1652 return count;
1653 }
1654
1655 static const struct proc_ops keys_proc_ops = {
1656 .proc_open = keys_proc_open,
1657 .proc_read = seq_read,
1658 .proc_lseek = seq_lseek,
1659 .proc_release = single_release,
1660 .proc_write = keys_proc_write,
1661 };
1662
1663 static int __maybe_unused version_proc_show(struct seq_file *m, void *v)
1664 {
1665 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1666 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1667 return 0;
1668 }
1669
1670
1671
1672
1673
1674 #define PROC_TOSHIBA "toshiba"
1675
1676 static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1677 {
1678 if (dev->backlight_dev)
1679 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1680 &lcd_proc_ops, dev);
1681 if (dev->video_supported)
1682 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1683 &video_proc_ops, dev);
1684 if (dev->fan_supported)
1685 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1686 &fan_proc_ops, dev);
1687 if (dev->hotkey_dev)
1688 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1689 &keys_proc_ops, dev);
1690 proc_create_single_data("version", S_IRUGO, toshiba_proc_dir,
1691 version_proc_show, dev);
1692 }
1693
1694 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1695 {
1696 if (dev->backlight_dev)
1697 remove_proc_entry("lcd", toshiba_proc_dir);
1698 if (dev->video_supported)
1699 remove_proc_entry("video", toshiba_proc_dir);
1700 if (dev->fan_supported)
1701 remove_proc_entry("fan", toshiba_proc_dir);
1702 if (dev->hotkey_dev)
1703 remove_proc_entry("keys", toshiba_proc_dir);
1704 remove_proc_entry("version", toshiba_proc_dir);
1705 }
1706
1707 static const struct backlight_ops toshiba_backlight_data = {
1708 .options = BL_CORE_SUSPENDRESUME,
1709 .get_brightness = get_lcd_brightness,
1710 .update_status = set_lcd_status,
1711 };
1712
1713
1714 static void toshiba_acpi_kbd_bl_work(struct work_struct *work);
1715
1716 static DECLARE_WORK(kbd_bl_work, toshiba_acpi_kbd_bl_work);
1717
1718
1719
1720
1721 static ssize_t version_show(struct device *dev,
1722 struct device_attribute *attr, char *buf)
1723 {
1724 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1725 }
1726 static DEVICE_ATTR_RO(version);
1727
1728 static ssize_t fan_store(struct device *dev,
1729 struct device_attribute *attr,
1730 const char *buf, size_t count)
1731 {
1732 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1733 int state;
1734 int ret;
1735
1736 ret = kstrtoint(buf, 0, &state);
1737 if (ret)
1738 return ret;
1739
1740 if (state != 0 && state != 1)
1741 return -EINVAL;
1742
1743 ret = set_fan_status(toshiba, state);
1744 if (ret)
1745 return ret;
1746
1747 return count;
1748 }
1749
1750 static ssize_t fan_show(struct device *dev,
1751 struct device_attribute *attr, char *buf)
1752 {
1753 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1754 u32 value;
1755 int ret;
1756
1757 ret = get_fan_status(toshiba, &value);
1758 if (ret)
1759 return ret;
1760
1761 return sprintf(buf, "%d\n", value);
1762 }
1763 static DEVICE_ATTR_RW(fan);
1764
1765 static ssize_t kbd_backlight_mode_store(struct device *dev,
1766 struct device_attribute *attr,
1767 const char *buf, size_t count)
1768 {
1769 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1770 int mode;
1771 int ret;
1772
1773
1774 ret = kstrtoint(buf, 0, &mode);
1775 if (ret)
1776 return ret;
1777
1778
1779 if (toshiba->kbd_type == 1) {
1780
1781 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1782 return -EINVAL;
1783 } else if (toshiba->kbd_type == 2) {
1784
1785 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1786 mode != SCI_KBD_MODE_OFF)
1787 return -EINVAL;
1788 }
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799 if (toshiba->kbd_mode != mode) {
1800
1801 int time = toshiba->kbd_time << HCI_MISC_SHIFT;
1802
1803
1804 if (toshiba->kbd_type == 1) {
1805
1806 time |= toshiba->kbd_mode;
1807 } else if (toshiba->kbd_type == 2) {
1808
1809 time |= mode;
1810 }
1811
1812 ret = toshiba_kbd_illum_status_set(toshiba, time);
1813 if (ret)
1814 return ret;
1815
1816 toshiba->kbd_mode = mode;
1817 toshiba_acpi->kbd_mode = mode;
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833 if (toshiba->kbd_type == 2 &&
1834 !toshiba->kbd_event_generated)
1835 schedule_work(&kbd_bl_work);
1836 }
1837
1838 return count;
1839 }
1840
1841 static ssize_t kbd_backlight_mode_show(struct device *dev,
1842 struct device_attribute *attr,
1843 char *buf)
1844 {
1845 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1846 u32 time;
1847
1848 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1849 return -EIO;
1850
1851 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1852 }
1853 static DEVICE_ATTR_RW(kbd_backlight_mode);
1854
1855 static ssize_t kbd_type_show(struct device *dev,
1856 struct device_attribute *attr, char *buf)
1857 {
1858 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1859
1860 return sprintf(buf, "%d\n", toshiba->kbd_type);
1861 }
1862 static DEVICE_ATTR_RO(kbd_type);
1863
1864 static ssize_t available_kbd_modes_show(struct device *dev,
1865 struct device_attribute *attr,
1866 char *buf)
1867 {
1868 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1869
1870 if (toshiba->kbd_type == 1)
1871 return sprintf(buf, "0x%x 0x%x\n",
1872 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1873
1874 return sprintf(buf, "0x%x 0x%x 0x%x\n",
1875 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
1876 }
1877 static DEVICE_ATTR_RO(available_kbd_modes);
1878
1879 static ssize_t kbd_backlight_timeout_store(struct device *dev,
1880 struct device_attribute *attr,
1881 const char *buf, size_t count)
1882 {
1883 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1884 int time;
1885 int ret;
1886
1887 ret = kstrtoint(buf, 0, &time);
1888 if (ret)
1889 return ret;
1890
1891
1892 if (toshiba->kbd_type == 1) {
1893 if (time < 0 || time > 60)
1894 return -EINVAL;
1895 } else if (toshiba->kbd_type == 2) {
1896 if (time < 1 || time > 60)
1897 return -EINVAL;
1898 }
1899
1900
1901
1902
1903 if (toshiba->kbd_time != time) {
1904
1905 time = time << HCI_MISC_SHIFT;
1906
1907 if (toshiba->kbd_type == 1)
1908 time |= SCI_KBD_MODE_FNZ;
1909 else if (toshiba->kbd_type == 2)
1910 time |= SCI_KBD_MODE_AUTO;
1911
1912 ret = toshiba_kbd_illum_status_set(toshiba, time);
1913 if (ret)
1914 return ret;
1915
1916 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1917 }
1918
1919 return count;
1920 }
1921
1922 static ssize_t kbd_backlight_timeout_show(struct device *dev,
1923 struct device_attribute *attr,
1924 char *buf)
1925 {
1926 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1927 u32 time;
1928
1929 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1930 return -EIO;
1931
1932 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1933 }
1934 static DEVICE_ATTR_RW(kbd_backlight_timeout);
1935
1936 static ssize_t touchpad_store(struct device *dev,
1937 struct device_attribute *attr,
1938 const char *buf, size_t count)
1939 {
1940 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1941 int state;
1942 int ret;
1943
1944
1945 ret = kstrtoint(buf, 0, &state);
1946 if (ret)
1947 return ret;
1948 if (state != 0 && state != 1)
1949 return -EINVAL;
1950
1951 ret = toshiba_touchpad_set(toshiba, state);
1952 if (ret)
1953 return ret;
1954
1955 return count;
1956 }
1957
1958 static ssize_t touchpad_show(struct device *dev,
1959 struct device_attribute *attr, char *buf)
1960 {
1961 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1962 u32 state;
1963 int ret;
1964
1965 ret = toshiba_touchpad_get(toshiba, &state);
1966 if (ret < 0)
1967 return ret;
1968
1969 return sprintf(buf, "%i\n", state);
1970 }
1971 static DEVICE_ATTR_RW(touchpad);
1972
1973 static ssize_t usb_sleep_charge_show(struct device *dev,
1974 struct device_attribute *attr, char *buf)
1975 {
1976 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1977 u32 mode;
1978 int ret;
1979
1980 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
1981 if (ret < 0)
1982 return ret;
1983
1984 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
1985 }
1986
1987 static ssize_t usb_sleep_charge_store(struct device *dev,
1988 struct device_attribute *attr,
1989 const char *buf, size_t count)
1990 {
1991 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1992 int state;
1993 u32 mode;
1994 int ret;
1995
1996 ret = kstrtoint(buf, 0, &state);
1997 if (ret)
1998 return ret;
1999
2000
2001
2002
2003
2004
2005
2006 if (state != 0 && state != 1 && state != 2 && state != 3)
2007 return -EINVAL;
2008
2009
2010 mode = toshiba->usbsc_mode_base;
2011 if (state == 0)
2012 mode |= SCI_USB_CHARGE_DISABLED;
2013 else if (state == 1)
2014 mode |= SCI_USB_CHARGE_ALTERNATE;
2015 else if (state == 2)
2016 mode |= SCI_USB_CHARGE_AUTO;
2017 else if (state == 3)
2018 mode |= SCI_USB_CHARGE_TYPICAL;
2019
2020 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
2021 if (ret)
2022 return ret;
2023
2024 return count;
2025 }
2026 static DEVICE_ATTR_RW(usb_sleep_charge);
2027
2028 static ssize_t sleep_functions_on_battery_show(struct device *dev,
2029 struct device_attribute *attr,
2030 char *buf)
2031 {
2032 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2033 int bat_lvl, status;
2034 u32 state;
2035 int ret;
2036 int tmp;
2037
2038 ret = toshiba_sleep_functions_status_get(toshiba, &state);
2039 if (ret < 0)
2040 return ret;
2041
2042
2043 tmp = state & SCI_USB_CHARGE_BAT_MASK;
2044 status = (tmp == 0x4) ? 1 : 0;
2045
2046 bat_lvl = state >> HCI_MISC_SHIFT;
2047
2048 return sprintf(buf, "%d %d\n", status, bat_lvl);
2049 }
2050
2051 static ssize_t sleep_functions_on_battery_store(struct device *dev,
2052 struct device_attribute *attr,
2053 const char *buf, size_t count)
2054 {
2055 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2056 u32 status;
2057 int value;
2058 int ret;
2059 int tmp;
2060
2061 ret = kstrtoint(buf, 0, &value);
2062 if (ret)
2063 return ret;
2064
2065
2066
2067
2068
2069
2070 if (value < 0 || value > 100)
2071 return -EINVAL;
2072
2073 if (value == 0) {
2074 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
2075 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
2076 } else {
2077 tmp = value << HCI_MISC_SHIFT;
2078 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
2079 }
2080 ret = toshiba_sleep_functions_status_set(toshiba, status);
2081 if (ret < 0)
2082 return ret;
2083
2084 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
2085
2086 return count;
2087 }
2088 static DEVICE_ATTR_RW(sleep_functions_on_battery);
2089
2090 static ssize_t usb_rapid_charge_show(struct device *dev,
2091 struct device_attribute *attr, char *buf)
2092 {
2093 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2094 u32 state;
2095 int ret;
2096
2097 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
2098 if (ret < 0)
2099 return ret;
2100
2101 return sprintf(buf, "%d\n", state);
2102 }
2103
2104 static ssize_t usb_rapid_charge_store(struct device *dev,
2105 struct device_attribute *attr,
2106 const char *buf, size_t count)
2107 {
2108 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2109 int state;
2110 int ret;
2111
2112 ret = kstrtoint(buf, 0, &state);
2113 if (ret)
2114 return ret;
2115 if (state != 0 && state != 1)
2116 return -EINVAL;
2117
2118 ret = toshiba_usb_rapid_charge_set(toshiba, state);
2119 if (ret)
2120 return ret;
2121
2122 return count;
2123 }
2124 static DEVICE_ATTR_RW(usb_rapid_charge);
2125
2126 static ssize_t usb_sleep_music_show(struct device *dev,
2127 struct device_attribute *attr, char *buf)
2128 {
2129 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2130 u32 state;
2131 int ret;
2132
2133 ret = toshiba_usb_sleep_music_get(toshiba, &state);
2134 if (ret < 0)
2135 return ret;
2136
2137 return sprintf(buf, "%d\n", state);
2138 }
2139
2140 static ssize_t usb_sleep_music_store(struct device *dev,
2141 struct device_attribute *attr,
2142 const char *buf, size_t count)
2143 {
2144 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2145 int state;
2146 int ret;
2147
2148 ret = kstrtoint(buf, 0, &state);
2149 if (ret)
2150 return ret;
2151 if (state != 0 && state != 1)
2152 return -EINVAL;
2153
2154 ret = toshiba_usb_sleep_music_set(toshiba, state);
2155 if (ret)
2156 return ret;
2157
2158 return count;
2159 }
2160 static DEVICE_ATTR_RW(usb_sleep_music);
2161
2162 static ssize_t kbd_function_keys_show(struct device *dev,
2163 struct device_attribute *attr, char *buf)
2164 {
2165 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2166 int mode;
2167 int ret;
2168
2169 ret = toshiba_function_keys_get(toshiba, &mode);
2170 if (ret < 0)
2171 return ret;
2172
2173 return sprintf(buf, "%d\n", mode);
2174 }
2175
2176 static ssize_t kbd_function_keys_store(struct device *dev,
2177 struct device_attribute *attr,
2178 const char *buf, size_t count)
2179 {
2180 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2181 int mode;
2182 int ret;
2183
2184 ret = kstrtoint(buf, 0, &mode);
2185 if (ret)
2186 return ret;
2187
2188
2189
2190
2191
2192 if (mode != 0 && mode != 1)
2193 return -EINVAL;
2194
2195 ret = toshiba_function_keys_set(toshiba, mode);
2196 if (ret)
2197 return ret;
2198
2199 pr_info("Reboot for changes to KBD Function Keys to take effect");
2200
2201 return count;
2202 }
2203 static DEVICE_ATTR_RW(kbd_function_keys);
2204
2205 static ssize_t panel_power_on_show(struct device *dev,
2206 struct device_attribute *attr, char *buf)
2207 {
2208 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2209 u32 state;
2210 int ret;
2211
2212 ret = toshiba_panel_power_on_get(toshiba, &state);
2213 if (ret < 0)
2214 return ret;
2215
2216 return sprintf(buf, "%d\n", state);
2217 }
2218
2219 static ssize_t panel_power_on_store(struct device *dev,
2220 struct device_attribute *attr,
2221 const char *buf, size_t count)
2222 {
2223 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2224 int state;
2225 int ret;
2226
2227 ret = kstrtoint(buf, 0, &state);
2228 if (ret)
2229 return ret;
2230 if (state != 0 && state != 1)
2231 return -EINVAL;
2232
2233 ret = toshiba_panel_power_on_set(toshiba, state);
2234 if (ret)
2235 return ret;
2236
2237 pr_info("Reboot for changes to Panel Power ON to take effect");
2238
2239 return count;
2240 }
2241 static DEVICE_ATTR_RW(panel_power_on);
2242
2243 static ssize_t usb_three_show(struct device *dev,
2244 struct device_attribute *attr, char *buf)
2245 {
2246 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2247 u32 state;
2248 int ret;
2249
2250 ret = toshiba_usb_three_get(toshiba, &state);
2251 if (ret < 0)
2252 return ret;
2253
2254 return sprintf(buf, "%d\n", state);
2255 }
2256
2257 static ssize_t usb_three_store(struct device *dev,
2258 struct device_attribute *attr,
2259 const char *buf, size_t count)
2260 {
2261 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2262 int state;
2263 int ret;
2264
2265 ret = kstrtoint(buf, 0, &state);
2266 if (ret)
2267 return ret;
2268
2269
2270
2271
2272
2273 if (state != 0 && state != 1)
2274 return -EINVAL;
2275
2276 ret = toshiba_usb_three_set(toshiba, state);
2277 if (ret)
2278 return ret;
2279
2280 pr_info("Reboot for changes to USB 3 to take effect");
2281
2282 return count;
2283 }
2284 static DEVICE_ATTR_RW(usb_three);
2285
2286 static ssize_t cooling_method_show(struct device *dev,
2287 struct device_attribute *attr, char *buf)
2288 {
2289 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2290 int state;
2291 int ret;
2292
2293 ret = toshiba_cooling_method_get(toshiba, &state);
2294 if (ret < 0)
2295 return ret;
2296
2297 return sprintf(buf, "%d %d\n", state, toshiba->max_cooling_method);
2298 }
2299
2300 static ssize_t cooling_method_store(struct device *dev,
2301 struct device_attribute *attr,
2302 const char *buf, size_t count)
2303 {
2304 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2305 int state;
2306 int ret;
2307
2308 ret = kstrtoint(buf, 0, &state);
2309 if (ret)
2310 return ret;
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323 if (state < 0 || state > toshiba->max_cooling_method)
2324 return -EINVAL;
2325
2326 ret = toshiba_cooling_method_set(toshiba, state);
2327 if (ret)
2328 return ret;
2329
2330 return count;
2331 }
2332 static DEVICE_ATTR_RW(cooling_method);
2333
2334 static struct attribute *toshiba_attributes[] = {
2335 &dev_attr_version.attr,
2336 &dev_attr_fan.attr,
2337 &dev_attr_kbd_backlight_mode.attr,
2338 &dev_attr_kbd_type.attr,
2339 &dev_attr_available_kbd_modes.attr,
2340 &dev_attr_kbd_backlight_timeout.attr,
2341 &dev_attr_touchpad.attr,
2342 &dev_attr_usb_sleep_charge.attr,
2343 &dev_attr_sleep_functions_on_battery.attr,
2344 &dev_attr_usb_rapid_charge.attr,
2345 &dev_attr_usb_sleep_music.attr,
2346 &dev_attr_kbd_function_keys.attr,
2347 &dev_attr_panel_power_on.attr,
2348 &dev_attr_usb_three.attr,
2349 &dev_attr_cooling_method.attr,
2350 NULL,
2351 };
2352
2353 static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2354 struct attribute *attr, int idx)
2355 {
2356 struct device *dev = kobj_to_dev(kobj);
2357 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2358 bool exists = true;
2359
2360 if (attr == &dev_attr_fan.attr)
2361 exists = (drv->fan_supported) ? true : false;
2362 else if (attr == &dev_attr_kbd_backlight_mode.attr)
2363 exists = (drv->kbd_illum_supported) ? true : false;
2364 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2365 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
2366 else if (attr == &dev_attr_touchpad.attr)
2367 exists = (drv->touchpad_supported) ? true : false;
2368 else if (attr == &dev_attr_usb_sleep_charge.attr)
2369 exists = (drv->usb_sleep_charge_supported) ? true : false;
2370 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2371 exists = (drv->usb_sleep_charge_supported) ? true : false;
2372 else if (attr == &dev_attr_usb_rapid_charge.attr)
2373 exists = (drv->usb_rapid_charge_supported) ? true : false;
2374 else if (attr == &dev_attr_usb_sleep_music.attr)
2375 exists = (drv->usb_sleep_music_supported) ? true : false;
2376 else if (attr == &dev_attr_kbd_function_keys.attr)
2377 exists = (drv->kbd_function_keys_supported) ? true : false;
2378 else if (attr == &dev_attr_panel_power_on.attr)
2379 exists = (drv->panel_power_on_supported) ? true : false;
2380 else if (attr == &dev_attr_usb_three.attr)
2381 exists = (drv->usb_three_supported) ? true : false;
2382 else if (attr == &dev_attr_cooling_method.attr)
2383 exists = (drv->cooling_method_supported) ? true : false;
2384
2385 return exists ? attr->mode : 0;
2386 }
2387
2388 static const struct attribute_group toshiba_attr_group = {
2389 .is_visible = toshiba_sysfs_is_visible,
2390 .attrs = toshiba_attributes,
2391 };
2392
2393 static void toshiba_acpi_kbd_bl_work(struct work_struct *work)
2394 {
2395
2396 if (sysfs_update_group(&toshiba_acpi->acpi_dev->dev.kobj,
2397 &toshiba_attr_group))
2398 pr_err("Unable to update sysfs entries\n");
2399
2400
2401 if (toshiba_acpi->kbd_type == 2 &&
2402 toshiba_acpi->kbd_mode != SCI_KBD_MODE_AUTO)
2403 led_classdev_notify_brightness_hw_changed(&toshiba_acpi->kbd_led,
2404 (toshiba_acpi->kbd_mode == SCI_KBD_MODE_ON) ?
2405 LED_FULL : LED_OFF);
2406
2407
2408 acpi_bus_generate_netlink_event(toshiba_acpi->acpi_dev->pnp.device_class,
2409 dev_name(&toshiba_acpi->acpi_dev->dev),
2410 0x92, 0);
2411 }
2412
2413
2414
2415
2416
2417 enum toshiba_iio_accel_chan {
2418 AXIS_X,
2419 AXIS_Y,
2420 AXIS_Z
2421 };
2422
2423 static int toshiba_iio_accel_get_axis(enum toshiba_iio_accel_chan chan)
2424 {
2425 u32 xyval, zval;
2426 int ret;
2427
2428 ret = toshiba_accelerometer_get(toshiba_acpi, &xyval, &zval);
2429 if (ret < 0)
2430 return ret;
2431
2432 switch (chan) {
2433 case AXIS_X:
2434 return xyval & HCI_ACCEL_DIRECTION_MASK ?
2435 -(xyval & HCI_ACCEL_MASK) : xyval & HCI_ACCEL_MASK;
2436 case AXIS_Y:
2437 return (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_DIRECTION_MASK ?
2438 -((xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK) :
2439 (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK;
2440 case AXIS_Z:
2441 return zval & HCI_ACCEL_DIRECTION_MASK ?
2442 -(zval & HCI_ACCEL_MASK) : zval & HCI_ACCEL_MASK;
2443 }
2444
2445 return ret;
2446 }
2447
2448 static int toshiba_iio_accel_read_raw(struct iio_dev *indio_dev,
2449 struct iio_chan_spec const *chan,
2450 int *val, int *val2, long mask)
2451 {
2452 int ret;
2453
2454 switch (mask) {
2455 case IIO_CHAN_INFO_RAW:
2456 ret = toshiba_iio_accel_get_axis(chan->channel);
2457 if (ret == -EIO || ret == -ENODEV)
2458 return ret;
2459
2460 *val = ret;
2461
2462 return IIO_VAL_INT;
2463 }
2464
2465 return -EINVAL;
2466 }
2467
2468 #define TOSHIBA_IIO_ACCEL_CHANNEL(axis, chan) { \
2469 .type = IIO_ACCEL, \
2470 .modified = 1, \
2471 .channel = chan, \
2472 .channel2 = IIO_MOD_##axis, \
2473 .output = 1, \
2474 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
2475 }
2476
2477 static const struct iio_chan_spec toshiba_iio_accel_channels[] = {
2478 TOSHIBA_IIO_ACCEL_CHANNEL(X, AXIS_X),
2479 TOSHIBA_IIO_ACCEL_CHANNEL(Y, AXIS_Y),
2480 TOSHIBA_IIO_ACCEL_CHANNEL(Z, AXIS_Z),
2481 };
2482
2483 static const struct iio_info toshiba_iio_accel_info = {
2484 .read_raw = &toshiba_iio_accel_read_raw,
2485 };
2486
2487
2488
2489
2490 static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
2491 {
2492 u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx,
2493 regs->edx, regs->esi, regs->edi };
2494 u32 out[TCI_WORDS];
2495 acpi_status status;
2496
2497 status = tci_raw(toshiba_acpi, in, out);
2498 if (ACPI_FAILURE(status)) {
2499 pr_err("ACPI call to query SMM registers failed\n");
2500 return -EIO;
2501 }
2502
2503
2504 regs->eax = out[0];
2505 regs->ebx = out[1];
2506 regs->ecx = out[2];
2507 regs->edx = out[3];
2508 regs->esi = out[4];
2509 regs->edi = out[5];
2510
2511 return 0;
2512 }
2513
2514 static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd,
2515 unsigned long arg)
2516 {
2517 SMMRegisters __user *argp = (SMMRegisters __user *)arg;
2518 SMMRegisters regs;
2519 int ret;
2520
2521 if (!argp)
2522 return -EINVAL;
2523
2524 switch (cmd) {
2525 case TOSH_SMM:
2526 if (copy_from_user(®s, argp, sizeof(SMMRegisters)))
2527 return -EFAULT;
2528 ret = toshiba_acpi_smm_bridge(®s);
2529 if (ret)
2530 return ret;
2531 if (copy_to_user(argp, ®s, sizeof(SMMRegisters)))
2532 return -EFAULT;
2533 break;
2534 case TOSHIBA_ACPI_SCI:
2535 if (copy_from_user(®s, argp, sizeof(SMMRegisters)))
2536 return -EFAULT;
2537
2538 if (regs.eax != SCI_GET && regs.eax != SCI_SET)
2539 return -EINVAL;
2540 if (!sci_open(toshiba_acpi))
2541 return -EIO;
2542 ret = toshiba_acpi_smm_bridge(®s);
2543 sci_close(toshiba_acpi);
2544 if (ret)
2545 return ret;
2546 if (copy_to_user(argp, ®s, sizeof(SMMRegisters)))
2547 return -EFAULT;
2548 break;
2549 default:
2550 return -EINVAL;
2551 }
2552
2553 return 0;
2554 }
2555
2556 static const struct file_operations toshiba_acpi_fops = {
2557 .owner = THIS_MODULE,
2558 .unlocked_ioctl = toshiba_acpi_ioctl,
2559 .llseek = noop_llseek,
2560 };
2561
2562
2563
2564
2565 static int toshiba_acpi_wwan_set_block(void *data, bool blocked)
2566 {
2567 struct toshiba_acpi_dev *dev = data;
2568 int ret;
2569
2570 ret = toshiba_wireless_status(dev);
2571 if (ret)
2572 return ret;
2573
2574 if (!dev->killswitch)
2575 return 0;
2576
2577 return toshiba_wwan_set(dev, !blocked);
2578 }
2579
2580 static void toshiba_acpi_wwan_poll(struct rfkill *rfkill, void *data)
2581 {
2582 struct toshiba_acpi_dev *dev = data;
2583
2584 if (toshiba_wireless_status(dev))
2585 return;
2586
2587 rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
2588 }
2589
2590 static const struct rfkill_ops wwan_rfk_ops = {
2591 .set_block = toshiba_acpi_wwan_set_block,
2592 .poll = toshiba_acpi_wwan_poll,
2593 };
2594
2595 static int toshiba_acpi_setup_wwan_rfkill(struct toshiba_acpi_dev *dev)
2596 {
2597 int ret = toshiba_wireless_status(dev);
2598
2599 if (ret)
2600 return ret;
2601
2602 dev->wwan_rfk = rfkill_alloc("Toshiba WWAN",
2603 &dev->acpi_dev->dev,
2604 RFKILL_TYPE_WWAN,
2605 &wwan_rfk_ops,
2606 dev);
2607 if (!dev->wwan_rfk) {
2608 pr_err("Unable to allocate WWAN rfkill device\n");
2609 return -ENOMEM;
2610 }
2611
2612 rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
2613
2614 ret = rfkill_register(dev->wwan_rfk);
2615 if (ret) {
2616 pr_err("Unable to register WWAN rfkill device\n");
2617 rfkill_destroy(dev->wwan_rfk);
2618 }
2619
2620 return ret;
2621 }
2622
2623
2624
2625
2626 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2627 {
2628 acpi_status status;
2629 u32 result;
2630
2631 status = acpi_evaluate_object(dev->acpi_dev->handle,
2632 "ENAB", NULL, NULL);
2633 if (ACPI_FAILURE(status))
2634 return -ENODEV;
2635
2636
2637
2638
2639
2640 if (dev->kbd_function_keys_supported && dev->special_functions)
2641 result = hci_write(dev, HCI_HOTKEY_EVENT,
2642 HCI_HOTKEY_SPECIAL_FUNCTIONS);
2643 else
2644 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
2645
2646 if (result == TOS_FAILURE)
2647 return -EIO;
2648 else if (result == TOS_NOT_SUPPORTED)
2649 return -ENODEV;
2650
2651 return 0;
2652 }
2653
2654 static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2655 struct serio *port)
2656 {
2657 if (str & I8042_STR_AUXDATA)
2658 return false;
2659
2660 if (unlikely(data == 0xe0))
2661 return false;
2662
2663 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2664 schedule_work(&toshiba_acpi->hotkey_work);
2665 return true;
2666 }
2667
2668 return false;
2669 }
2670
2671 static void toshiba_acpi_hotkey_work(struct work_struct *work)
2672 {
2673 acpi_handle ec_handle = ec_get_handle();
2674 acpi_status status;
2675
2676 if (!ec_handle)
2677 return;
2678
2679 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2680 if (ACPI_FAILURE(status))
2681 pr_err("ACPI NTFY method execution failed\n");
2682 }
2683
2684
2685
2686
2687 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2688 {
2689 unsigned long long value;
2690 acpi_status status;
2691
2692 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2693 NULL, &value);
2694 if (ACPI_FAILURE(status)) {
2695 pr_err("ACPI INFO method execution failed\n");
2696 return -EIO;
2697 }
2698
2699 return value;
2700 }
2701
2702 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2703 int scancode)
2704 {
2705 if (scancode == 0x100)
2706 return;
2707
2708
2709 if (scancode & 0x80)
2710 return;
2711
2712 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2713 pr_info("Unknown key %x\n", scancode);
2714 }
2715
2716 static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2717 {
2718 if (dev->info_supported) {
2719 int scancode = toshiba_acpi_query_hotkey(dev);
2720
2721 if (scancode < 0) {
2722 pr_err("Failed to query hotkey event\n");
2723 } else if (scancode != 0) {
2724 toshiba_acpi_report_hotkey(dev, scancode);
2725 dev->key_event_valid = 1;
2726 dev->last_key_event = scancode;
2727 }
2728 } else if (dev->system_event_supported) {
2729 u32 result;
2730 u32 value;
2731 int retries = 3;
2732
2733 do {
2734 result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
2735 switch (result) {
2736 case TOS_SUCCESS:
2737 toshiba_acpi_report_hotkey(dev, (int)value);
2738 dev->key_event_valid = 1;
2739 dev->last_key_event = value;
2740 break;
2741 case TOS_NOT_SUPPORTED:
2742
2743
2744
2745
2746
2747 result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
2748 if (result == TOS_SUCCESS)
2749 pr_notice("Re-enabled hotkeys\n");
2750 fallthrough;
2751 default:
2752 retries--;
2753 break;
2754 }
2755 } while (retries && result != TOS_FIFO_EMPTY);
2756 }
2757 }
2758
2759 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
2760 {
2761 const struct key_entry *keymap = toshiba_acpi_keymap;
2762 acpi_handle ec_handle;
2763 int error;
2764
2765 if (disable_hotkeys) {
2766 pr_info("Hotkeys disabled by module parameter\n");
2767 return 0;
2768 }
2769
2770 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
2771 pr_info("WMI event detected, hotkeys will not be monitored\n");
2772 return 0;
2773 }
2774
2775 error = toshiba_acpi_enable_hotkeys(dev);
2776 if (error)
2777 return error;
2778
2779 if (toshiba_hotkey_event_type_get(dev, &dev->hotkey_event_type))
2780 pr_notice("Unable to query Hotkey Event Type\n");
2781
2782 dev->hotkey_dev = input_allocate_device();
2783 if (!dev->hotkey_dev)
2784 return -ENOMEM;
2785
2786 dev->hotkey_dev->name = "Toshiba input device";
2787 dev->hotkey_dev->phys = "toshiba_acpi/input0";
2788 dev->hotkey_dev->id.bustype = BUS_HOST;
2789
2790 if (dev->hotkey_event_type == HCI_SYSTEM_TYPE1 ||
2791 !dev->kbd_function_keys_supported)
2792 keymap = toshiba_acpi_keymap;
2793 else if (dev->hotkey_event_type == HCI_SYSTEM_TYPE2 ||
2794 dev->kbd_function_keys_supported)
2795 keymap = toshiba_acpi_alt_keymap;
2796 else
2797 pr_info("Unknown event type received %x\n",
2798 dev->hotkey_event_type);
2799 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
2800 if (error)
2801 goto err_free_dev;
2802
2803
2804
2805
2806
2807
2808
2809
2810 ec_handle = ec_get_handle();
2811 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
2812 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2813
2814 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2815 if (error) {
2816 pr_err("Error installing key filter\n");
2817 goto err_free_dev;
2818 }
2819
2820 dev->ntfy_supported = 1;
2821 }
2822
2823
2824
2825
2826
2827 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
2828 dev->info_supported = 1;
2829 else if (hci_write(dev, HCI_SYSTEM_EVENT, 1) == TOS_SUCCESS)
2830 dev->system_event_supported = 1;
2831
2832 if (!dev->info_supported && !dev->system_event_supported) {
2833 pr_warn("No hotkey query interface found\n");
2834 error = -EINVAL;
2835 goto err_remove_filter;
2836 }
2837
2838 error = input_register_device(dev->hotkey_dev);
2839 if (error) {
2840 pr_info("Unable to register input device\n");
2841 goto err_remove_filter;
2842 }
2843
2844 return 0;
2845
2846 err_remove_filter:
2847 if (dev->ntfy_supported)
2848 i8042_remove_filter(toshiba_acpi_i8042_filter);
2849 err_free_dev:
2850 input_free_device(dev->hotkey_dev);
2851 dev->hotkey_dev = NULL;
2852 return error;
2853 }
2854
2855 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
2856 {
2857 struct backlight_properties props;
2858 int brightness;
2859 int ret;
2860
2861
2862
2863
2864
2865
2866
2867 brightness = __get_lcd_brightness(dev);
2868 if (brightness < 0)
2869 return 0;
2870
2871
2872
2873
2874
2875
2876 if (dev->tr_backlight_supported && brightness == 0)
2877 brightness++;
2878 ret = set_lcd_brightness(dev, brightness);
2879 if (ret) {
2880 pr_debug("Backlight method is read-only, disabling backlight support\n");
2881 return 0;
2882 }
2883
2884
2885
2886
2887
2888 if (dev->tr_backlight_supported ||
2889 dmi_check_system(toshiba_vendor_backlight_dmi))
2890 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
2891
2892 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
2893 return 0;
2894
2895 memset(&props, 0, sizeof(props));
2896 props.type = BACKLIGHT_PLATFORM;
2897 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
2898
2899
2900 if (dev->tr_backlight_supported)
2901 props.max_brightness++;
2902
2903 dev->backlight_dev = backlight_device_register("toshiba",
2904 &dev->acpi_dev->dev,
2905 dev,
2906 &toshiba_backlight_data,
2907 &props);
2908 if (IS_ERR(dev->backlight_dev)) {
2909 ret = PTR_ERR(dev->backlight_dev);
2910 pr_err("Could not register toshiba backlight device\n");
2911 dev->backlight_dev = NULL;
2912 return ret;
2913 }
2914
2915 dev->backlight_dev->props.brightness = brightness;
2916 return 0;
2917 }
2918
2919 static void print_supported_features(struct toshiba_acpi_dev *dev)
2920 {
2921 pr_info("Supported laptop features:");
2922
2923 if (dev->hotkey_dev)
2924 pr_cont(" hotkeys");
2925 if (dev->backlight_dev)
2926 pr_cont(" backlight");
2927 if (dev->video_supported)
2928 pr_cont(" video-out");
2929 if (dev->fan_supported)
2930 pr_cont(" fan");
2931 if (dev->tr_backlight_supported)
2932 pr_cont(" transflective-backlight");
2933 if (dev->illumination_supported)
2934 pr_cont(" illumination");
2935 if (dev->kbd_illum_supported)
2936 pr_cont(" keyboard-backlight");
2937 if (dev->touchpad_supported)
2938 pr_cont(" touchpad");
2939 if (dev->eco_supported)
2940 pr_cont(" eco-led");
2941 if (dev->accelerometer_supported)
2942 pr_cont(" accelerometer-axes");
2943 if (dev->usb_sleep_charge_supported)
2944 pr_cont(" usb-sleep-charge");
2945 if (dev->usb_rapid_charge_supported)
2946 pr_cont(" usb-rapid-charge");
2947 if (dev->usb_sleep_music_supported)
2948 pr_cont(" usb-sleep-music");
2949 if (dev->kbd_function_keys_supported)
2950 pr_cont(" special-function-keys");
2951 if (dev->panel_power_on_supported)
2952 pr_cont(" panel-power-on");
2953 if (dev->usb_three_supported)
2954 pr_cont(" usb3");
2955 if (dev->wwan_supported)
2956 pr_cont(" wwan");
2957 if (dev->cooling_method_supported)
2958 pr_cont(" cooling-method");
2959
2960 pr_cont("\n");
2961 }
2962
2963 static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
2964 {
2965 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2966
2967 misc_deregister(&dev->miscdev);
2968
2969 remove_toshiba_proc_entries(dev);
2970
2971 if (dev->accelerometer_supported && dev->indio_dev) {
2972 iio_device_unregister(dev->indio_dev);
2973 iio_device_free(dev->indio_dev);
2974 }
2975
2976 if (dev->sysfs_created)
2977 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2978 &toshiba_attr_group);
2979
2980 if (dev->ntfy_supported) {
2981 i8042_remove_filter(toshiba_acpi_i8042_filter);
2982 cancel_work_sync(&dev->hotkey_work);
2983 }
2984
2985 if (dev->hotkey_dev)
2986 input_unregister_device(dev->hotkey_dev);
2987
2988 backlight_device_unregister(dev->backlight_dev);
2989
2990 led_classdev_unregister(&dev->led_dev);
2991 led_classdev_unregister(&dev->kbd_led);
2992 led_classdev_unregister(&dev->eco_led);
2993
2994 if (dev->wwan_rfk) {
2995 rfkill_unregister(dev->wwan_rfk);
2996 rfkill_destroy(dev->wwan_rfk);
2997 }
2998
2999 if (toshiba_acpi)
3000 toshiba_acpi = NULL;
3001
3002 kfree(dev);
3003
3004 return 0;
3005 }
3006
3007 static const char *find_hci_method(acpi_handle handle)
3008 {
3009 if (acpi_has_method(handle, "GHCI"))
3010 return "GHCI";
3011
3012 if (acpi_has_method(handle, "SPFC"))
3013 return "SPFC";
3014
3015 return NULL;
3016 }
3017
3018 static int toshiba_acpi_add(struct acpi_device *acpi_dev)
3019 {
3020 struct toshiba_acpi_dev *dev;
3021 const char *hci_method;
3022 u32 dummy;
3023 int ret = 0;
3024
3025 if (toshiba_acpi)
3026 return -EBUSY;
3027
3028 pr_info("Toshiba Laptop ACPI Extras version %s\n",
3029 TOSHIBA_ACPI_VERSION);
3030
3031 hci_method = find_hci_method(acpi_dev->handle);
3032 if (!hci_method) {
3033 pr_err("HCI interface not found\n");
3034 return -ENODEV;
3035 }
3036
3037 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
3038 if (!dev)
3039 return -ENOMEM;
3040 dev->acpi_dev = acpi_dev;
3041 dev->method_hci = hci_method;
3042 dev->miscdev.minor = MISC_DYNAMIC_MINOR;
3043 dev->miscdev.name = "toshiba_acpi";
3044 dev->miscdev.fops = &toshiba_acpi_fops;
3045
3046 ret = misc_register(&dev->miscdev);
3047 if (ret) {
3048 pr_err("Failed to register miscdevice\n");
3049 kfree(dev);
3050 return ret;
3051 }
3052
3053 acpi_dev->driver_data = dev;
3054 dev_set_drvdata(&acpi_dev->dev, dev);
3055
3056
3057
3058
3059
3060
3061
3062
3063 ret = toshiba_function_keys_get(dev, &dev->special_functions);
3064 dev->kbd_function_keys_supported = !ret;
3065
3066 dev->hotkey_event_type = 0;
3067 if (toshiba_acpi_setup_keyboard(dev))
3068 pr_info("Unable to activate hotkeys\n");
3069
3070
3071 ret = get_tr_backlight_status(dev, &dummy);
3072 dev->tr_backlight_supported = !ret;
3073
3074 ret = toshiba_acpi_setup_backlight(dev);
3075 if (ret)
3076 goto error;
3077
3078 toshiba_illumination_available(dev);
3079 if (dev->illumination_supported) {
3080 dev->led_dev.name = "toshiba::illumination";
3081 dev->led_dev.max_brightness = 1;
3082 dev->led_dev.brightness_set = toshiba_illumination_set;
3083 dev->led_dev.brightness_get = toshiba_illumination_get;
3084 led_classdev_register(&acpi_dev->dev, &dev->led_dev);
3085 }
3086
3087 toshiba_eco_mode_available(dev);
3088 if (dev->eco_supported) {
3089 dev->eco_led.name = "toshiba::eco_mode";
3090 dev->eco_led.max_brightness = 1;
3091 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
3092 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
3093 led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led);
3094 }
3095
3096 toshiba_kbd_illum_available(dev);
3097
3098
3099
3100
3101
3102 if (dev->kbd_illum_supported &&
3103 (dev->kbd_mode == SCI_KBD_MODE_FNZ || dev->kbd_type == 2)) {
3104 dev->kbd_led.name = "toshiba::kbd_backlight";
3105 dev->kbd_led.flags = LED_BRIGHT_HW_CHANGED;
3106 dev->kbd_led.max_brightness = 1;
3107 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
3108 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
3109 led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led);
3110 }
3111
3112 ret = toshiba_touchpad_get(dev, &dummy);
3113 dev->touchpad_supported = !ret;
3114
3115 toshiba_accelerometer_available(dev);
3116 if (dev->accelerometer_supported) {
3117 dev->indio_dev = iio_device_alloc(&acpi_dev->dev, sizeof(*dev));
3118 if (!dev->indio_dev) {
3119 pr_err("Unable to allocate iio device\n");
3120 goto iio_error;
3121 }
3122
3123 pr_info("Registering Toshiba accelerometer iio device\n");
3124
3125 dev->indio_dev->info = &toshiba_iio_accel_info;
3126 dev->indio_dev->name = "Toshiba accelerometer";
3127 dev->indio_dev->modes = INDIO_DIRECT_MODE;
3128 dev->indio_dev->channels = toshiba_iio_accel_channels;
3129 dev->indio_dev->num_channels =
3130 ARRAY_SIZE(toshiba_iio_accel_channels);
3131
3132 ret = iio_device_register(dev->indio_dev);
3133 if (ret < 0) {
3134 pr_err("Unable to register iio device\n");
3135 iio_device_free(dev->indio_dev);
3136 }
3137 }
3138 iio_error:
3139
3140 toshiba_usb_sleep_charge_available(dev);
3141
3142 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
3143 dev->usb_rapid_charge_supported = !ret;
3144
3145 ret = toshiba_usb_sleep_music_get(dev, &dummy);
3146 dev->usb_sleep_music_supported = !ret;
3147
3148 ret = toshiba_panel_power_on_get(dev, &dummy);
3149 dev->panel_power_on_supported = !ret;
3150
3151 ret = toshiba_usb_three_get(dev, &dummy);
3152 dev->usb_three_supported = !ret;
3153
3154 ret = get_video_status(dev, &dummy);
3155 dev->video_supported = !ret;
3156
3157 ret = get_fan_status(dev, &dummy);
3158 dev->fan_supported = !ret;
3159
3160 toshiba_wwan_available(dev);
3161 if (dev->wwan_supported)
3162 toshiba_acpi_setup_wwan_rfkill(dev);
3163
3164 toshiba_cooling_method_available(dev);
3165
3166 print_supported_features(dev);
3167
3168 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
3169 &toshiba_attr_group);
3170 if (ret) {
3171 dev->sysfs_created = 0;
3172 goto error;
3173 }
3174 dev->sysfs_created = !ret;
3175
3176 create_toshiba_proc_entries(dev);
3177
3178 toshiba_acpi = dev;
3179
3180 return 0;
3181
3182 error:
3183 toshiba_acpi_remove(acpi_dev);
3184 return ret;
3185 }
3186
3187 static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
3188 {
3189 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
3190
3191 switch (event) {
3192 case 0x80:
3193
3194
3195
3196
3197
3198
3199 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
3200 return;
3201 toshiba_acpi_process_hotkeys(dev);
3202 break;
3203 case 0x81:
3204 case 0x82:
3205 case 0x83:
3206 pr_info("Dock event received %x\n", event);
3207 break;
3208 case 0x88:
3209 pr_info("Thermal event received\n");
3210 break;
3211 case 0x8f:
3212 case 0x90:
3213 break;
3214 case 0x8c:
3215 case 0x8b:
3216 pr_info("SATA power event received %x\n", event);
3217 break;
3218 case 0x92:
3219 dev->kbd_event_generated = true;
3220
3221 if (sysfs_update_group(&acpi_dev->dev.kobj,
3222 &toshiba_attr_group))
3223 pr_err("Unable to update sysfs entries\n");
3224
3225 if (dev->kbd_type == 2 && dev->kbd_mode != SCI_KBD_MODE_AUTO)
3226 led_classdev_notify_brightness_hw_changed(&dev->kbd_led,
3227 (dev->kbd_mode == SCI_KBD_MODE_ON) ?
3228 LED_FULL : LED_OFF);
3229 break;
3230 case 0x85:
3231 case 0x8d:
3232 case 0x8e:
3233 case 0x94:
3234 case 0x95:
3235 default:
3236 pr_info("Unknown event received %x\n", event);
3237 break;
3238 }
3239
3240 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
3241 dev_name(&acpi_dev->dev),
3242 event, (event == 0x80) ?
3243 dev->last_key_event : 0);
3244 }
3245
3246 #ifdef CONFIG_PM_SLEEP
3247 static int toshiba_acpi_suspend(struct device *device)
3248 {
3249 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
3250
3251 if (dev->hotkey_dev) {
3252 u32 result;
3253
3254 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
3255 if (result != TOS_SUCCESS)
3256 pr_info("Unable to disable hotkeys\n");
3257 }
3258
3259 return 0;
3260 }
3261
3262 static int toshiba_acpi_resume(struct device *device)
3263 {
3264 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
3265
3266 if (dev->hotkey_dev) {
3267 if (toshiba_acpi_enable_hotkeys(dev))
3268 pr_info("Unable to re-enable hotkeys\n");
3269 }
3270
3271 if (dev->wwan_rfk) {
3272 if (!toshiba_wireless_status(dev))
3273 rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
3274 }
3275
3276 return 0;
3277 }
3278 #endif
3279
3280 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
3281 toshiba_acpi_suspend, toshiba_acpi_resume);
3282
3283 static struct acpi_driver toshiba_acpi_driver = {
3284 .name = "Toshiba ACPI driver",
3285 .owner = THIS_MODULE,
3286 .ids = toshiba_device_ids,
3287 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
3288 .ops = {
3289 .add = toshiba_acpi_add,
3290 .remove = toshiba_acpi_remove,
3291 .notify = toshiba_acpi_notify,
3292 },
3293 .drv.pm = &toshiba_acpi_pm,
3294 };
3295
3296 static int __init toshiba_acpi_init(void)
3297 {
3298 int ret;
3299
3300 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
3301 if (!toshiba_proc_dir) {
3302 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
3303 return -ENODEV;
3304 }
3305
3306 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
3307 if (ret) {
3308 pr_err("Failed to register ACPI driver: %d\n", ret);
3309 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
3310 }
3311
3312 return ret;
3313 }
3314
3315 static void __exit toshiba_acpi_exit(void)
3316 {
3317 acpi_bus_unregister_driver(&toshiba_acpi_driver);
3318 if (toshiba_proc_dir)
3319 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
3320 }
3321
3322 module_init(toshiba_acpi_init);
3323 module_exit(toshiba_acpi_exit);