Lines Matching +full:broken +full:- +full:save +full:- +full:restore +full:- +full:fw
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * thinkpad_acpi.c - ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2009 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
16 * 2007-10-20 changelog trimmed down
18 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
21 * 2006-11-22 0.13 new maintainer
23 * not be updated further in-file.
25 * 2005-03-17 0.11 support for 600e, 770x
28 * 2005-01-16 0.9 use MODULE_VERSION
33 * 2004-11-08 0.8 fix init error case, don't return from a macro
45 #include <linux/hwmon-sysfs.h>
120 /* Misc NVRAM-related */
140 TP_ACPI_WGSV_SAVE_STATE = 0x04, /* Save state for S4/S5 */
159 /* Hotkey-related */
178 /* Auto-sleep after eject request */
195 /* User-interface events */
207 /* Key-related user-interface events */
224 /* AC-related events */
227 /* Further user-interface events */
242 #define TPACPI_URL "http://ibm-acpi.sf.net/"
243 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
270 * Driver-wide structs and misc. variables
367 char *ec_version_str; /* Something like 1ZHT51WW-1.04a */
375 char *nummodel_str; /* 9384A9C for a 9384-A9C model */
456 * two or three characters from the set [0-9A-Z], i.e. base 36.
508 * tpacpi_check_quirks() - search BIOS/EC version on a list
525 if ((qlist->vendor == thinkpad_id.vendor || in tpacpi_check_quirks()
526 qlist->vendor == TPACPI_MATCH_ANY) && in tpacpi_check_quirks()
527 (qlist->bios == thinkpad_id.bios_model || in tpacpi_check_quirks()
528 qlist->bios == TPACPI_MATCH_ANY) && in tpacpi_check_quirks()
529 (qlist->ec == thinkpad_id.ec_model || in tpacpi_check_quirks()
530 qlist->ec == TPACPI_MATCH_ANY)) in tpacpi_check_quirks()
531 return qlist->quirks; in tpacpi_check_quirks()
533 qlist_size--; in tpacpi_check_quirks()
575 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
701 return -ENXIO; in issue_thinkpad_cmos_command()
704 return -EIO; in issue_thinkpad_cmos_command()
793 if (!ibm || !ibm->acpi || !ibm->acpi->notify) in dispatch_acpi_notify()
796 ibm->acpi->notify(ibm, event); in dispatch_acpi_notify()
803 BUG_ON(!ibm->acpi); in setup_acpi_notify()
805 if (!*ibm->acpi->handle) in setup_acpi_notify()
809 "setting up ACPI notify for %s\n", ibm->name); in setup_acpi_notify()
811 ibm->acpi->device = acpi_fetch_acpi_dev(*ibm->acpi->handle); in setup_acpi_notify()
812 if (!ibm->acpi->device) { in setup_acpi_notify()
813 pr_err("acpi_fetch_acpi_dev(%s) failed\n", ibm->name); in setup_acpi_notify()
814 return -ENODEV; in setup_acpi_notify()
817 ibm->acpi->device->driver_data = ibm; in setup_acpi_notify()
818 sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", in setup_acpi_notify()
820 ibm->name); in setup_acpi_notify()
822 status = acpi_install_notify_handler(*ibm->acpi->handle, in setup_acpi_notify()
823 ibm->acpi->type, dispatch_acpi_notify, ibm); in setup_acpi_notify()
827 ibm->name); in setup_acpi_notify()
830 ibm->name, acpi_format_exception(status)); in setup_acpi_notify()
832 return -ENODEV; in setup_acpi_notify()
834 ibm->flags.acpi_notify_installed = 1; in setup_acpi_notify()
848 "registering %s as an ACPI driver\n", ibm->name); in register_tpacpi_subdriver()
850 BUG_ON(!ibm->acpi); in register_tpacpi_subdriver()
852 ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); in register_tpacpi_subdriver()
853 if (!ibm->acpi->driver) { in register_tpacpi_subdriver()
854 pr_err("failed to allocate memory for ibm->acpi->driver\n"); in register_tpacpi_subdriver()
855 return -ENOMEM; in register_tpacpi_subdriver()
858 sprintf(ibm->acpi->driver->name, "%s_%s", TPACPI_NAME, ibm->name); in register_tpacpi_subdriver()
859 ibm->acpi->driver->ids = ibm->acpi->hid; in register_tpacpi_subdriver()
861 ibm->acpi->driver->ops.add = &tpacpi_device_add; in register_tpacpi_subdriver()
863 rc = acpi_bus_register_driver(ibm->acpi->driver); in register_tpacpi_subdriver()
866 ibm->name, rc); in register_tpacpi_subdriver()
867 kfree(ibm->acpi->driver); in register_tpacpi_subdriver()
868 ibm->acpi->driver = NULL; in register_tpacpi_subdriver()
870 ibm->flags.acpi_driver_registered = 1; in register_tpacpi_subdriver()
886 struct ibm_struct *ibm = m->private; in dispatch_proc_show()
888 if (!ibm || !ibm->read) in dispatch_proc_show()
889 return -EINVAL; in dispatch_proc_show()
890 return ibm->read(m); in dispatch_proc_show()
906 if (!ibm || !ibm->write) in dispatch_proc_write()
907 return -EINVAL; in dispatch_proc_write()
908 if (count > PAGE_SIZE - 1) in dispatch_proc_write()
909 return -EINVAL; in dispatch_proc_write()
914 ret = ibm->write(kernbuf); in dispatch_proc_write()
954 if (ibm->suspend) in tpacpi_suspend_handler()
955 (ibm->suspend)(); in tpacpi_suspend_handler()
968 if (ibm->resume) in tpacpi_resume_handler()
969 (ibm->resume)(); in tpacpi_resume_handler()
986 if (ibm->shutdown) in tpacpi_shutdown_handler()
987 (ibm->shutdown)(); in tpacpi_shutdown_handler()
1003 return -EINVAL; in parse_strtoul()
1027 * ThinkPad-ACPI firmware handling model:
1029 * WLSW (master wireless switch) is event-driven, and is common to all
1030 * firmware-controlled radios. It cannot be controlled, just monitored,
1033 * The kernel, a masked-off hotkey, and WLSW can change the radio state
1037 * masked-off hotkeys are used.
1066 /* ThinkPad-ACPI rfkill subdriver */
1081 /* Query FW and update rfkill sw state for a given rfkill switch */
1087 return -ENODEV; in tpacpi_rfk_update_swstate()
1089 status = (tp_rfk->ops->get_status)(); in tpacpi_rfk_update_swstate()
1093 rfkill_set_sw_state(tp_rfk->rfkill, in tpacpi_rfk_update_swstate()
1100 * Sync the HW-blocking state of all rfkill switches,
1111 if (rfkill_set_hw_state(tp_rfk->rfkill, in tpacpi_rfk_update_hwblock_state()
1113 /* ignore -- we track sw block */ in tpacpi_rfk_update_hwblock_state()
1148 res = (tp_rfk->ops->set_status)(blocked ? in tpacpi_rfk_hook_set_block()
1151 /* and update the rfkill core with whatever the FW really did */ in tpacpi_rfk_hook_set_block()
1177 atp_rfk->rfkill = rfkill_alloc(name, in tpacpi_new_rfkill()
1178 &tpacpi_pdev->dev, in tpacpi_new_rfkill()
1182 if (!atp_rfk || !atp_rfk->rfkill) { in tpacpi_new_rfkill()
1185 return -ENOMEM; in tpacpi_new_rfkill()
1188 atp_rfk->id = id; in tpacpi_new_rfkill()
1189 atp_rfk->ops = tp_rfkops; in tpacpi_new_rfkill()
1191 sw_status = (tp_rfkops->get_status)(); in tpacpi_new_rfkill()
1200 rfkill_init_sw_state(atp_rfk->rfkill, sw_state); in tpacpi_new_rfkill()
1204 rfkill_set_hw_state(atp_rfk->rfkill, hw_state); in tpacpi_new_rfkill()
1206 res = rfkill_register(atp_rfk->rfkill); in tpacpi_new_rfkill()
1209 rfkill_destroy(atp_rfk->rfkill); in tpacpi_new_rfkill()
1229 rfkill_unregister(tp_rfk->rfkill); in tpacpi_destroy_rfkill()
1230 rfkill_destroy(tp_rfk->rfkill); in tpacpi_destroy_rfkill()
1242 /* sysfs <radio> enable ------------------------------------------------ */
1249 printk_deprecated_rfkill_attribute(attr->attr.name); in tpacpi_rfk_sysfs_enable_show()
1271 printk_deprecated_rfkill_attribute(attr->attr.name); in tpacpi_rfk_sysfs_enable_store()
1274 return -EINVAL; in tpacpi_rfk_sysfs_enable_store()
1276 tpacpi_disclose_usertask(attr->attr.name, "set to %ld\n", t); in tpacpi_rfk_sysfs_enable_store()
1280 return -EPERM; in tpacpi_rfk_sysfs_enable_store()
1282 res = tpacpi_rfkill_switches[id]->ops->set_status((!!t) ? in tpacpi_rfk_sysfs_enable_store()
1289 /* procfs -------------------------------------------------------------- */
1317 int status = -1; in tpacpi_rfk_procfs_write()
1321 return -ENODEV; in tpacpi_rfk_procfs_write()
1329 return -EINVAL; in tpacpi_rfk_procfs_write()
1332 if (status != -1) { in tpacpi_rfk_procfs_write()
1336 res = (tpacpi_rfkill_switches[id]->ops->set_status)(status); in tpacpi_rfk_procfs_write()
1344 * thinkpad-acpi driver attributes
1347 /* interface_version --------------------------------------------------- */
1354 /* debug_level --------------------------------------------------------- */
1366 return -EINVAL; in debug_level_store()
1374 /* version ------------------------------------------------------------- */
1382 /* --------------------------------------------------------------------- */
1386 /* wlsw_emulstate ------------------------------------------------------ */
1398 return -EINVAL; in wlsw_emulstate_store()
1409 /* bluetooth_emulstate ------------------------------------------------- */
1421 return -EINVAL; in bluetooth_emulstate_store()
1429 /* wwan_emulstate ------------------------------------------------- */
1441 return -EINVAL; in wwan_emulstate_store()
1449 /* uwb_emulstate ------------------------------------------------- */
1461 return -EINVAL; in uwb_emulstate_store()
1481 * 2. BIOS or EC fw with known bugs that trigger on Linux
1486 * We only support the latest BIOS and EC fw version as a rule.
1547 /* Numeric models ------------------ */
1548 /* FW MODEL BIOS VERS */
1559 /* A-series ------------------------- */
1560 /* FW MODEL BIOS VERS EC VERS */
1573 /* G-series ------------------------- */
1574 /* FW MODEL BIOS VERS */
1578 /* R-series, T-series --------------- */
1579 /* FW MODEL BIOS VERS EC VERS */
1604 /* BIOS FW BIOS VERS EC FW EC VERS */
1608 /* X-series ------------------------- */
1609 /* FW MODEL BIOS VERS EC VERS */
1621 /* (0) - older versions lack DMI EC fw string and functionality */
1622 /* (1) - older versions known to lack functionality */
1655 * broken, or really stable to begin with, so it is in tpacpi_check_outdated_fw()
1678 * thinkpad-acpi metadata subdriver
1713 * Unlike other classes, hotkey-class events have mask/unmask control on
1714 * non-ancient firmware. However, how it behaves changes a lot with the
1895 static u32 hotkey_all_mask; /* all events supported in fw */
1896 static u32 hotkey_adaptive_all_mask; /* all adaptive events supported in fw */
1938 return -ENODEV; in hotkey_get_wlsw()
1947 return -EIO; in hotkey_get_wlsw()
2041 return -EIO; in hotkey_get_tablet_mode()
2047 return -EIO; in hotkey_get_tablet_mode()
2072 return -EIO; in hotkey_mask_get()
2080 /* sync userspace-visible mask */ in hotkey_mask_get()
2118 rc = -EIO; in hotkey_mask_set()
2159 …pr_notice("please consider using the driver defaults, and refer to up-to-date thinkpad-acpi docume… in hotkey_user_mask_set()
2208 return -EIO; in hotkey_status_get()
2216 return -EIO; in hotkey_status_set()
2280 n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); in hotkey_read_nvram()
2281 n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); in hotkey_read_nvram()
2282 n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); in hotkey_read_nvram()
2283 n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); in hotkey_read_nvram()
2287 n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); in hotkey_read_nvram()
2291 n->displayexp_toggle = in hotkey_read_nvram()
2296 n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) in hotkey_read_nvram()
2298 n->brightness_toggle = in hotkey_read_nvram()
2303 n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) in hotkey_read_nvram()
2305 n->mute = !!(d & TP_NVRAM_MASK_MUTE); in hotkey_read_nvram()
2306 n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); in hotkey_read_nvram()
2313 oldn->__member != newn->__member) \
2331 i--; in issue_volchange()
2347 i--; in issue_brightnesschange()
2373 * - Pressing MUTE issues mute hotkey message, even when already mute in hotkey_compare_and_issue_event()
2374 * - Pressing Volume up/down issues volume up/down hotkey messages, in hotkey_compare_and_issue_event()
2376 * - The act of unmuting issues volume up/down notification, in hotkey_compare_and_issue_event()
2386 if (newn->mute) { in hotkey_compare_and_issue_event()
2388 if (!oldn->mute || in hotkey_compare_and_issue_event()
2389 oldn->volume_toggle != newn->volume_toggle || in hotkey_compare_and_issue_event()
2390 oldn->volume_level != newn->volume_level) { in hotkey_compare_and_issue_event()
2393 issue_volchange(oldn->volume_level, newn->volume_level, in hotkey_compare_and_issue_event()
2399 if (oldn->mute) { in hotkey_compare_and_issue_event()
2403 if (oldn->volume_level != newn->volume_level) { in hotkey_compare_and_issue_event()
2404 issue_volchange(oldn->volume_level, newn->volume_level, in hotkey_compare_and_issue_event()
2406 } else if (oldn->volume_toggle != newn->volume_toggle) { in hotkey_compare_and_issue_event()
2408 if (newn->volume_level == 0) in hotkey_compare_and_issue_event()
2410 else if (newn->volume_level >= TP_NVRAM_LEVEL_VOLUME_MAX) in hotkey_compare_and_issue_event()
2416 if (oldn->brightness_level != newn->brightness_level) { in hotkey_compare_and_issue_event()
2417 issue_brightnesschange(oldn->brightness_level, in hotkey_compare_and_issue_event()
2418 newn->brightness_level, event_mask); in hotkey_compare_and_issue_event()
2419 } else if (oldn->brightness_toggle != newn->brightness_toggle) { in hotkey_compare_and_issue_event()
2421 if (newn->brightness_level == 0) in hotkey_compare_and_issue_event()
2423 else if (newn->brightness_level >= bright_maxlvl in hotkey_compare_and_issue_event()
2436 * most of them are edge-based. We only issue those requested by
2530 (poll_user_mask && tpacpi_inputdev->users > 0))) { in hotkey_poll_setup()
2586 return -EBUSY; in hotkey_inputdev_open()
2591 return -EBUSY; in hotkey_inputdev_open()
2602 /* sysfs hotkey enable ------------------------------------------------- */
2629 return -EINVAL; in hotkey_enable_store()
2632 return -EPERM; in hotkey_enable_store()
2639 /* sysfs hotkey mask --------------------------------------------------- */
2655 return -EINVAL; in hotkey_mask_store()
2658 return -ERESTARTSYS; in hotkey_mask_store()
2675 /* sysfs hotkey bios_enabled ------------------------------------------- */
2685 /* sysfs hotkey bios_mask ---------------------------------------------- */
2697 /* sysfs hotkey all_mask ----------------------------------------------- */
2708 /* sysfs hotkey all_mask ----------------------------------------------- */
2719 /* sysfs hotkey recommended_mask --------------------------------------- */
2733 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2751 return -EINVAL; in hotkey_source_mask_store()
2754 return -ERESTARTSYS; in hotkey_source_mask_store()
2784 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2799 return -EINVAL; in hotkey_poll_freq_store()
2802 return -ERESTARTSYS; in hotkey_poll_freq_store()
2818 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2840 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, in hotkey_radio_sw_notify_change()
2844 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2862 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, in hotkey_tablet_mode_notify_change()
2866 /* sysfs wakeup reason (pollable) -------------------------------------- */
2878 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, in hotkey_wakeup_reason_notify_change()
2882 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2895 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, in hotkey_wakeup_hotunplug_complete_notify_change()
2899 /* sysfs adaptive kbd mode --------------------------------------------- */
2933 return -EINVAL; in adaptive_kbd_mode_store()
2949 return tp_features.has_adaptive_kbd ? attr->mode : 0; in hadaptive_kbd_attr_is_visible()
2957 /* --------------------------------------------------------------------- */
2989 return attr->mode; in hotkey_attr_is_visible()
3017 /* Sync hw blocking state first if it is hw-blocked */ in tpacpi_send_radiosw_update()
3021 /* Sync hw blocking state last if it is hw-unblocked */ in tpacpi_send_radiosw_update()
3057 pr_err("failed to restore hot key mask to BIOS defaults\n"); in hotkey_exit()
3064 tpacpi_inputdev->keybit); in hotkey_unmap()
3148 * firmware at driver load time, which means the firm- in hotkey_init()
3152 * 2. You must be subscribed to the linux-thinkpad and in hotkey_init()
3153 * ibm-acpi-devel mailing lists, and you should read the in hotkey_init()
3156 * know the past history of problems with the thinkpad- in hotkey_init()
3160 * 3. Do not send thinkpad-acpi specific patches directly to in hotkey_init()
3161 * for merging, *ever*. Send them to the linux-acpi in hotkey_init()
3163 * through acpi-test and the ACPI maintainer. in hotkey_init()
3166 * Ask the thinkpad-acpi maintainer to do it, instead. in hotkey_init()
3198 * the built-in *extra* mixer. Never map it to control in hotkey_init()
3239 /* These should be enabled --only-- when ACPI video in hotkey_init()
3251 * react to it and reprograms the built-in *extra* mixer. in hotkey_init()
3255 * these over the regular keyboard, so these are no-ops, in hotkey_init()
3370 BUG_ON(tpacpi_inputdev->open != NULL || in hotkey_init()
3371 tpacpi_inputdev->close != NULL); in hotkey_init()
3388 return -ENODEV; in hotkey_init()
3396 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking in hotkey_init()
3415 /* Fallback: pre-init for FN+F3,F4,F12 */ in hotkey_init()
3432 /* Fallback: pre-init for FN+F3,F4,F12 */ in hotkey_init()
3512 return -ENOMEM; in hotkey_init()
3516 tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; in hotkey_init()
3517 tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; in hotkey_init()
3518 tpacpi_inputdev->keycode = hotkey_keycode_map; in hotkey_init()
3545 pr_notice("Disabling thinkpad-acpi brightness events by default...\n"); in hotkey_init()
3579 if (res < 0 && res != -ENXIO) { in hotkey_init()
3586 "initial masks: user=0x%08x, fw=0x%08x, poll=0x%08x\n", in hotkey_init()
3589 tpacpi_inputdev->open = &hotkey_inputdev_open; in hotkey_init()
3590 tpacpi_inputdev->close = &hotkey_inputdev_close; in hotkey_init()
3598 * mode, Web conference mode, Function mode and Lay-flat mode.
3627 return -EIO; in adaptive_keyboard_get_mode()
3637 return -EINVAL; in adaptive_keyboard_set_mode()
3641 return -EIO; in adaptive_keyboard_set_mode()
3650 size_t max_mode = ARRAY_SIZE(adaptive_keyboard_modes) - 1; in adaptive_keyboard_get_next_mode()
3704 TP_ACPI_HOTKEYSCAN_EXTENDED_START - in adaptive_keyboard_hotkey_notify_hotkey()
3710 keycode = hotkey_keycode_map[scancode - FIRST_ADAPTIVE_KEY + in adaptive_keyboard_hotkey_notify_hotkey()
3742 scancode = (hkey & 0xfff) - (0x300 - TP_ACPI_HOTKEYSCAN_EXTENDED_START); in hotkey_notify_extended_hotkey()
3756 /* 0x1000-0x1FFF: key presses */ in hotkey_notify_hotkey()
3771 scancode--; in hotkey_notify_hotkey()
3796 /* 0x2000-0x2FFF: Wakeup reason */ in hotkey_notify_wakeup()
3816 /* how to auto-heal: */ in hotkey_notify_wakeup()
3826 pr_info("woke up due to a hot-unplug request...\n"); in hotkey_notify_wakeup()
3836 /* 0x4000-0x4FFF: dock-related events */ in hotkey_notify_dockevent()
3857 * duplicates from intel-vbtn, which already emits SW_TABLET_MODE events in hotkey_notify_dockevent()
3864 * https://lore.kernel.org/platform-driver-x86/38cb8265-1e30-d547-9e12-b4ae290be737@a-kobel.de/ in hotkey_notify_dockevent()
3881 /* 0x5000-0x5FFF: human interface helpers */ in hotkey_notify_usrevent()
3890 case TP_HKEY_EV_TABLET_TABLET: /* X41t-X61t: tablet mode */ in hotkey_notify_usrevent()
3891 case TP_HKEY_EV_TABLET_NOTEBOOK: /* X41t-X61t: normal mode */ in hotkey_notify_usrevent()
3916 /* 0x6000-0x6FFF: thermal alarms/notices and keyboard events */ in hotkey_notify_6xxx()
3928 /* Thermal event - pass on to event handler */ in hotkey_notify_6xxx()
3983 /* palm detected - pass on to event handler */ in hotkey_notify_6xxx()
4007 ibm->acpi->device->pnp.device_class, in hotkey_notify()
4008 dev_name(&ibm->acpi->device->dev), in hotkey_notify()
4029 /* 0x1000-0x1FFF: key presses */ in hotkey_notify()
4034 /* 0x2000-0x2FFF: Wakeup reason */ in hotkey_notify()
4039 /* 0x3000-0x3FFF: bay-related wakeups */ in hotkey_notify()
4056 /* 0x4000-0x4FFF: dock-related events */ in hotkey_notify()
4061 /* 0x5000-0x5FFF: human interface helpers */ in hotkey_notify()
4066 /* 0x6000-0x6FFF: thermal alarms/notices and in hotkey_notify()
4072 /* 0x7000-0x7FFF: misc */ in hotkey_notify()
4093 ibm->acpi->device->pnp.device_class, in hotkey_notify()
4094 dev_name(&ibm->acpi->device->dev), in hotkey_notify()
4106 /* save previous mode of adaptive keyboard of X1 Carbon */ in hotkey_suspend()
4132 /* restore previous mode of adapive keyboard of X1 Carbon */ in hotkey_resume()
4141 /* procfs -------------------------------------------------------------- */
4152 return -ERESTARTSYS; in hotkey_read()
4187 return -ENODEV; in hotkey_write()
4190 return -ERESTARTSYS; in hotkey_write()
4200 res = -EPERM; in hotkey_write()
4209 res = -EINVAL; in hotkey_write()
4264 TP_ACPI_BLTH_GET_PWR_ON_RESUME = 0x01, /* Get power-on-resume state */
4267 TP_ACPI_BLTH_SAVE_STATE = 0x05, /* Save state for S4/S5 */
4283 return -EIO; in bluetooth_get_status()
4310 return -EIO; in bluetooth_set_status()
4315 /* sysfs bluetooth enable ---------------------------------------------- */
4334 /* --------------------------------------------------------------------- */
4344 return tp_features.bluetooth ? attr->mode : 0; in bluetooth_attr_is_visible()
4359 /* Order firmware to save current state to NVRAM */ in bluetooth_shutdown()
4362 pr_notice("failed to save bluetooth state to NVRAM\n"); in bluetooth_shutdown()
4392 .ident = "ThinkPad A285 - 20MW",
4400 .ident = "ThinkPad A285 - 20MX",
4408 .ident = "ThinkPad A485 - 20MU",
4416 .ident = "ThinkPad A485 - 20MV",
4440 if (tp_features.quirks && tp_features.quirks->btusb_bug && in have_bt_fwbug()
4460 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ in bluetooth_init()
4484 return -ENODEV; in bluetooth_init()
4494 /* procfs -------------------------------------------------------------- */
4538 return -EIO; in wan_get_status()
4565 return -EIO; in wan_set_status()
4570 /* sysfs wan enable ---------------------------------------------------- */
4590 /* --------------------------------------------------------------------- */
4600 return tp_features.wan ? attr->mode : 0; in wan_attr_is_visible()
4615 /* Order firmware to save current state to NVRAM */ in wan_shutdown()
4618 pr_notice("failed to save WWAN state to NVRAM\n"); in wan_shutdown()
4663 return -ENODEV; in wan_init()
4673 /* procfs -------------------------------------------------------------- */
4715 return -EIO; in uwb_get_status()
4741 return -EIO; in uwb_set_status()
4746 /* --------------------------------------------------------------------- */
4791 return -ENODEV; in uwb_init()
4884 return (video_supported != TPACPI_VIDEO_NONE) ? 0 : -ENODEV; in video_init()
4892 pr_err("error while trying to restore original video autoswitch mode\n"); in video_exit()
4904 return -EIO; in video_outputsw_get()
4909 return -EIO; in video_outputsw_get()
4913 return -EIO; in video_outputsw_get()
4920 return -EIO; in video_outputsw_get()
4926 return -EIO; in video_outputsw_get()
4930 return -EIO; in video_outputsw_get()
4935 return -ENOSYS; in video_outputsw_get()
4964 pr_err("video auto-switch left enabled due to error\n"); in video_outputsw_set()
4965 return -EIO; in video_outputsw_set()
4973 return -ENOSYS; in video_outputsw_set()
4976 return (res) ? 0 : -EIO; in video_outputsw_set()
4986 return -EIO; in video_autosw_get()
4991 return -EIO; in video_autosw_get()
4994 return -ENOSYS; in video_autosw_get()
5003 return -EIO; in video_autosw_set()
5030 return -ENOSYS; in video_outputsw_cycle()
5033 pr_err("video auto-switch left enabled due to error\n"); in video_outputsw_cycle()
5034 return -EIO; in video_outputsw_cycle()
5037 return (res) ? 0 : -EIO; in video_outputsw_cycle()
5045 0 : -EIO; in video_expand_toggle()
5048 0 : -EIO; in video_expand_toggle()
5051 0 : -EIO; in video_expand_toggle()
5053 return -ENOSYS; in video_expand_toggle()
5069 return -EPERM; in video_read()
5102 return -ENODEV; in video_write()
5106 return -EPERM; in video_write()
5143 return -EINVAL; in video_write()
5179 return -ENXIO; in kbdlight_set_level()
5184 ret = -EIO; in kbdlight_set_level()
5198 return -ENXIO; in kbdlight_get_level()
5201 return -EIO; in kbdlight_get_level()
5236 * b010100000010000000XX - ThinkPad X1 Carbon 3rd in kbdlight_is_supported()
5237 * b110100010010000000XX - ThinkPad x230 in kbdlight_is_supported()
5238 * b010100000010000000XX - ThinkPad x240 in kbdlight_is_supported()
5239 * b010100000010000000XX - ThinkPad W541 in kbdlight_is_supported()
5243 * b10100001000000000000 - ThinkPad x230 in kbdlight_is_supported()
5244 * b10110001000000000000 - ThinkPad E430 in kbdlight_is_supported()
5245 * b00000000000000000000 - ThinkPad E450 in kbdlight_is_supported()
5292 return -ENODEV; in kbdlight_init()
5298 rc = led_classdev_register(&tpacpi_pdev->dev, in kbdlight_init()
5323 if (ret == 0 && !(led_cdev->flags & LED_SUSPENDED)) in kbdlight_set_level_and_update()
5324 led_cdev->brightness = level; in kbdlight_set_level_and_update()
5350 int res, level = -EINVAL; in kbdlight_write()
5353 return -ENODEV; in kbdlight_write()
5362 return -EINVAL; in kbdlight_write()
5400 TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
5409 return -EIO; in light_get_status()
5413 return -ENXIO; in light_get_status()
5430 return (rc) ? 0 : -EIO; in light_set_status()
5433 return -ENXIO; in light_set_status()
5483 return -ENODEV; in light_init()
5485 rc = led_classdev_register(&tpacpi_pdev->dev, in light_init()
5529 return -ENODEV; in light_write()
5537 return -EINVAL; in light_write()
5554 /* sysfs cmos_command -------------------------------------------------- */
5563 return -EINVAL; in cmos_command_store()
5579 return cmos_handle ? attr->mode : 0; in cmos_attr_is_visible()
5587 /* --------------------------------------------------------------------- */
5599 return cmos_handle ? 0 : -ENODEV; in cmos_init()
5605 R30, R31, T20-22, X20-21 */ in cmos_read()
5610 seq_printf(m, "commands:\t<cmd> (<cmd> is 0-21)\n"); in cmos_read()
5626 return -EINVAL; in cmos_write()
5649 TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5702 return -EIO; in led_get_status()
5711 return -ENXIO; in led_get_status()
5730 return -EINVAL; in led_set_status()
5732 return -EPERM; in led_set_status()
5735 return -EIO; in led_set_status()
5738 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ in led_set_status()
5740 return -EINVAL; in led_set_status()
5742 return -EPERM; in led_set_status()
5754 return -EINVAL; in led_set_status()
5756 return -EPERM; in led_set_status()
5759 return -EIO; in led_set_status()
5762 return -ENXIO; in led_set_status()
5780 else if (tpacpi_led_state_cache[data->led] != TPACPI_LED_BLINK) in led_sysfs_set()
5785 return led_set_status(data->led, new_state); in led_sysfs_set()
5800 return -EINVAL; in led_sysfs_blink_set()
5802 return led_set_status(data->led, TPACPI_LED_BLINK); in led_sysfs_blink_set()
5812 rc = led_get_status(data->led); in led_sysfs_get()
5847 return led_classdev_register(&tpacpi_pdev->dev, &tpacpi_leds[led].led_classdev); in tpacpi_init_led()
5875 /* (1) - may have excess leds enabled on MSB */
5905 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ in led_init_detect_mode()
5945 return -ENODEV; in led_init()
5951 return -ENOMEM; in led_init()
5955 tpacpi_leds[i].led = -1; in led_init()
5988 return -EIO; in led_read()
5993 seq_printf(m, "commands:\t<led> on, <led> off, <led> blink (<led> is 0-15)\n"); in led_read()
6005 return -ENODEV; in led_write()
6009 return -EINVAL; in led_write()
6011 if (led < 0 || led > (TPACPI_LED_NUMLEDS - 1)) in led_write()
6012 return -ENODEV; in led_write()
6015 return -ENODEV; in led_write()
6024 return -EINVAL; in led_write()
6052 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1), /* 570E - unverified */
6071 return (beep_handle) ? 0 : -ENODEV; in beep_init()
6080 seq_printf(m, "commands:\t<cmd> (<cmd> is 0-17)\n"); in beep_read()
6092 return -ENODEV; in beep_write()
6099 return -EINVAL; in beep_write()
6103 return -EIO; in beep_write()
6107 return -EIO; in beep_write()
6126 TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
6127 TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
6136 TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */
6138 TPACPI_THERMAL_SENSOR_NA = -128000, /* Sensor not available */
6150 /* idx is zero-based */
6164 idx -= 8; in thermal_get_sensor()
6171 return -EIO; in thermal_get_sensor()
6181 return -EIO; in thermal_get_sensor()
6183 return -EIO; in thermal_get_sensor()
6184 *value = (t - 2732) * 100; in thermal_get_sensor()
6193 return -EIO; in thermal_get_sensor()
6194 if (t > 127 || t < -127) in thermal_get_sensor()
6203 return -ENOSYS; in thermal_get_sensor()
6206 return -EINVAL; in thermal_get_sensor()
6218 return -EINVAL; in thermal_get_sensors()
6224 res = thermal_get_sensor(i, &s->temp[i]); in thermal_get_sensors()
6253 /* sysfs temp##_input -------------------------------------------------- */
6261 int idx = sensor_attr->index; in thermal_temp_input_show()
6269 return -ENXIO; in thermal_temp_input_show()
6334 return attr->mode; in thermal_attr_is_visible()
6366 return thermal_use_labels ? attr->mode : 0; in temp_label_attr_is_visible()
6374 /* --------------------------------------------------------------------- */
6389 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for in thermal_init()
6390 * non-implemented, thermal sensors return 0x80 when in thermal_init()
6395 * version 3 the Lenovo firmware team confirmed that registers 0xC0-0xC7 in thermal_init()
6455 return thermal_read_mode != TPACPI_THERMAL_NONE ? 0 : -ENODEV; in thermal_init()
6470 for (i = 0; i < (n - 1); i++) in thermal_read()
6492 * CMOS NVRAM byte 0x5E, bits 0-3.
6499 * Bit 3-0: backlight brightness level
6520 TPACPI_BRGHT_MODE_UCMS_STEP, /* UCMS step-based control */
6601 return -EIO; in tpacpi_brightness_get_raw()
6605 return -ENXIO; in tpacpi_brightness_get_raw()
6617 return -EIO; in tpacpi_brightness_set_ec()
6622 return -EIO; in tpacpi_brightness_set_ec()
6642 inc = (value > current_value) ? 1 : -1; in tpacpi_brightness_set_ucmsstep()
6646 return -EIO; in tpacpi_brightness_set_ucmsstep()
6657 return -EINVAL; in brightness_set()
6675 res = -ENXIO; in brightness_set()
6682 /* sysfs backlight class ----------------------------------------------- */
6726 /* --------------------------------------------------------------------- */
6735 status = acpi_evaluate_object(adev->handle, "_BCL", NULL, &buffer); in tpacpi_evaluate_bcl()
6740 if (!obj || obj->type != ACPI_TYPE_PACKAGE) { in tpacpi_evaluate_bcl()
6741 acpi_handle_info(adev->handle, in tpacpi_evaluate_bcl()
6746 rc = obj->package.count; in tpacpi_evaluate_bcl()
6784 return (bcl_levels > 2) ? (bcl_levels - 2) : 0; in tpacpi_check_std_acpi_brightness_support()
6801 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC), /* R50,51 T40-42 */
6847 bright_maxlvl = b - 1; in tpacpi_detect_brightness_capabilities()
6869 return -ENODEV; in brightness_init()
6874 return -ENODEV; in brightness_init()
6880 return -ENODEV; in brightness_init()
6883 return -ENODEV; in brightness_init()
6887 return -ENODEV; in brightness_init()
6898 return -EINVAL; in brightness_init()
6909 "driver auto-selected brightness_mode=%d\n", in brightness_init()
6917 return -EINVAL; in brightness_init()
6920 return -ENODEV; in brightness_init()
6991 seq_printf(m, "commands:\tlevel <level> (<level> is 0-%d)\n", in brightness_read()
7014 level--; in brightness_write()
7019 return -EINVAL; in brightness_write()
7033 return (rc == -EINTR) ? -ERESTARTSYS : rc; in brightness_write()
7058 * Bit 3-0: Volume
7062 * bits 3-0 (volume). Other bits in NVRAM may have other functions,
7074 * To avoid confusing userspace, we simply disable all EC-based mute
7085 #define DEFAULT_ALSA_IDX ~((1 << (SNDRV_CARDS - 3)) - 1)
7087 #define DEFAULT_ALSA_IDX ~((1 << (32 - 3)) - 1)
7118 TPACPI_VOL_MODE_UCMS_STEP, /* UCMS step-based control: N/A */
7148 * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write
7204 return -EIO; in volume_get_status_ec()
7221 return -EIO; in volume_set_status_ec()
7246 return -EINTR; in __volume_set_mute_ec()
7291 return -EINVAL; in __volume_set_volume_ec()
7294 return -EINTR; in __volume_set_volume_ec()
7318 return -ENODEV; in volume_set_software_mute()
7323 return -EIO; in volume_set_software_mute()
7332 return -EIO; in volume_set_software_mute()
7341 * startup. Just on case there are SAUM-capable ThinkPads in volume_set_software_mute()
7361 pr_warn("Failed to restore mute mode\n"); in volume_exit_software_mute()
7375 if (alsa_card && alsa_card->private_data) { in volume_alsa_notify_change()
7376 d = alsa_card->private_data; in volume_alsa_notify_change()
7377 if (d->ctl_mute_id) in volume_alsa_notify_change()
7380 d->ctl_mute_id); in volume_alsa_notify_change()
7381 if (d->ctl_vol_id) in volume_alsa_notify_change()
7384 d->ctl_vol_id); in volume_alsa_notify_change()
7391 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in volume_alsa_vol_info()
7392 uinfo->count = 1; in volume_alsa_vol_info()
7393 uinfo->value.integer.min = 0; in volume_alsa_vol_info()
7394 uinfo->value.integer.max = TP_EC_VOLUME_MAX; in volume_alsa_vol_info()
7408 ucontrol->value.integer.value[0] = s & TP_EC_AUDIO_LVL_MSK; in volume_alsa_vol_get()
7416 ucontrol->value.integer.value[0]); in volume_alsa_vol_put()
7417 return volume_alsa_set_volume(ucontrol->value.integer.value[0]); in volume_alsa_vol_put()
7432 ucontrol->value.integer.value[0] = in volume_alsa_mute_get()
7441 ucontrol->value.integer.value[0] ? in volume_alsa_mute_put()
7443 return volume_alsa_set_mute(!ucontrol->value.integer.value[0]); in volume_alsa_mute_put()
7473 pr_warn("Failed to restore software mute\n"); in volume_resume()
7505 rc = snd_card_new(&tpacpi_pdev->dev, in volume_create_alsa_mixer()
7510 return -ENODEV; in volume_create_alsa_mixer()
7513 BUG_ON(!card->private_data); in volume_create_alsa_mixer()
7514 data = card->private_data; in volume_create_alsa_mixer()
7515 data->card = card; in volume_create_alsa_mixer()
7517 strscpy(card->driver, TPACPI_ALSA_DRVNAME, in volume_create_alsa_mixer()
7518 sizeof(card->driver)); in volume_create_alsa_mixer()
7519 strscpy(card->shortname, TPACPI_ALSA_SHRTNAME, in volume_create_alsa_mixer()
7520 sizeof(card->shortname)); in volume_create_alsa_mixer()
7521 snprintf(card->mixername, sizeof(card->mixername), "ThinkPad EC %s", in volume_create_alsa_mixer()
7524 snprintf(card->longname, sizeof(card->longname), in volume_create_alsa_mixer()
7525 "%s at EC reg 0x%02x, fw %s", card->shortname, TP_EC_AUDIO, in volume_create_alsa_mixer()
7547 data->ctl_vol_id = &ctl_vol->id; in volume_create_alsa_mixer()
7556 data->ctl_mute_id = &ctl_mute->id; in volume_create_alsa_mixer()
7569 return -ENODEV; in volume_create_alsa_mixer()
7572 #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */
7591 /* Whitelist mute-only on all Lenovo by default */
7613 return -EINVAL; in volume_init()
7618 return -ENODEV; in volume_init()
7622 return -EINVAL; in volume_init()
7631 return -ENODEV; in volume_init()
7644 return -ENODEV; /* no mixer */ in volume_init()
7653 return -ENODEV; in volume_init()
7658 "using user-supplied volume_capabilities=%d\n", in volume_init()
7666 "driver auto-selected volume_mode=%d\n", in volume_init()
7670 "using user-supplied volume_mode=%d\n", in volume_init()
7722 seq_printf(m, "commands:\tlevel <level> (<level> is 0-%d)\n", in volume_read()
7749 return -EPERM; in volume_write()
7771 new_level--; in volume_write()
7784 return -EINVAL; in volume_write()
7799 return (rc == -EINTR) ? -ERESTARTSYS : rc; in volume_write()
7824 return -ENODEV; in volume_init()
7872 * Speeds up fan to 100% duty-cycle, which is far above
7875 * 5-3 unused in some models. Extra bits for fan level
7878 * 2-0 fan level (0..7 usually)
7891 * ----
7896 * This register is present on all ThinkPads with a new-style EC, and
7902 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
7916 * ----
7928 * So far, only the firmware for the X60/X61 non-tablet versions
7929 * seem to support this (firmware TP-7M).
7954 * that are using non-standard EC locations for reporting fan speeds.
7959 #define FAN_RPM_CAL_CONST 491520 /* FAN RPM calculation offset for some non-standard ECFW */
7971 fan_status_offset_ns = 0x93, /* Special status/control offset for non-standard EC Fan1 */
7972 fan2_status_offset_ns = 0x96, /* Special status/control offset for non-standard EC Fan2 */
7973 fan_rpm_status_ns = 0x95, /* Special offset for Fan1 RPM status for non-standard EC */
7974 fan2_rpm_status_ns = 0x98, /* Special offset for Fan2 RPM status for non-standard EC */
7979 TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */
7985 TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
7986 TPACPI_FAN_RD_TPEC_NS, /* Use non-standard ACPI EC regs (eg: L13 Yoga gen2 etc.) */
8026 "JFNS", /* 770x-JL */
8041 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
8042 * TP-70 (T43, R52), which are known to be buggy.
8127 return -EIO; in fan_get_status()
8137 return -EIO; in fan_get_status()
8148 return -EIO; in fan_get_status()
8156 return -ENXIO; in fan_get_status()
8168 return -ERESTARTSYS; in fan_get_status_safe()
8191 return -EIO; in fan_get_speed()
8194 return -EIO; in fan_get_speed()
8201 return -EIO; in fan_get_speed()
8208 return -ENXIO; in fan_get_speed()
8223 return -EIO; in fan2_get_speed()
8228 return -EIO; in fan2_get_speed()
8237 return -EIO; in fan2_get_speed()
8240 return -EIO; in fan2_get_speed()
8244 return -EIO; in fan2_get_speed()
8250 return -ENXIO; in fan2_get_speed()
8259 return -EPERM; in fan_set_level()
8264 return -EINVAL; in fan_set_level()
8275 return -EIO; in fan_set_level()
8283 return -EINVAL; in fan_set_level()
8302 return -EIO; in fan_set_level()
8308 return -ENXIO; in fan_set_level()
8321 return -EPERM; in fan_set_level_safe()
8324 return -ERESTARTSYS; in fan_set_level_safe()
8343 return -EPERM; in fan_set_enable()
8346 return -ERESTARTSYS; in fan_set_enable()
8362 rc = -EIO; in fan_set_enable()
8380 rc = -EIO; in fan_set_enable()
8386 rc = -ENXIO; in fan_set_enable()
8403 return -EPERM; in fan_set_disable()
8406 return -ERESTARTSYS; in fan_set_disable()
8413 rc = -EIO; in fan_set_disable()
8422 rc = -EIO; in fan_set_disable()
8428 rc = -ENXIO; in fan_set_disable()
8444 return -EPERM; in fan_set_speed()
8447 return -ERESTARTSYS; in fan_set_speed()
8455 rc = -EIO; in fan_set_speed()
8457 rc = -EINVAL; in fan_set_speed()
8461 rc = -ENXIO; in fan_set_speed()
8519 /* sysfs fan pwm1_enable ----------------------------------------------- */
8549 return -EINVAL; in fan_pwm1_enable_store()
8565 /* reserved for software-controlled auto mode */ in fan_pwm1_enable_store()
8566 return -ENOSYS; in fan_pwm1_enable_store()
8568 return -EINVAL; in fan_pwm1_enable_store()
8572 if (res == -ENXIO) in fan_pwm1_enable_store()
8573 return -EINVAL; in fan_pwm1_enable_store()
8585 /* sysfs fan pwm1 ------------------------------------------------------ */
8616 return -EINVAL; in fan_pwm1_store()
8621 /* scale down from 0-255 to 0-7 */ in fan_pwm1_store()
8625 return -ERESTARTSYS; in fan_pwm1_store()
8631 if (rc == -ENXIO) in fan_pwm1_store()
8632 rc = -EINVAL; in fan_pwm1_store()
8645 /* sysfs fan fan1_input ------------------------------------------------ */
8662 /* sysfs fan fan2_input ------------------------------------------------ */
8679 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
8691 return -EINVAL; in fan_watchdog_store()
8694 return -EPERM; in fan_watchdog_store()
8705 /* --------------------------------------------------------------------- */
8727 return attr->mode; in fan_attr_is_visible()
8749 #define TPACPI_FAN_NS 0x0010 /* For EC with non-Standard register addresses */
8801 return -ENODEV; in fan_init()
8805 pr_info("ECFW with non-standard fan reg control found\n"); in fan_init()
8815 /* all other ThinkPads: note that even old-style in fan_init()
8831 /* It responded - so let's assume it's there */ in fan_init()
8837 /* Fan not auto-detected */ in fan_init()
8851 return -ENODEV; in fan_init()
8856 /* 570, 770x-JL */ in fan_init()
8902 return -ENODEV; in fan_init()
8927 pr_notice("failed to read fan level for later restore during resume: %d\n", in fan_suspend()
8930 /* if it is undefined, don't attempt to restore it. in fan_suspend()
8963 * So, we can safely only restore FULLSPEED or 7, anything in fan_resume()
8987 pr_notice("failed to restore fan level: %d\n", rc); in fan_resume()
9052 seq_printf(m, " (<level> is 0-7)\n"); in fan_read()
9056 seq_printf(m, " (<level> is 0-7, auto, disengaged, full-speed)\n"); in fan_read()
9063 "commands:\twatchdog <timeout> (<timeout> is 0 (off), 1-120 (seconds))\n"); in fan_read()
9066 seq_printf(m, "commands:\tspeed <speed> (<speed> is 0-65535)\n"); in fan_read()
9077 else if (strstarts(cmd, "level disengaged") || strstarts(cmd, "level full-speed")) in fan_write_cmd_level()
9083 if (*rc == -ENXIO) in fan_write_cmd_level()
9099 if (*rc == -ENXIO) in fan_write_cmd_enable()
9114 if (*rc == -ENXIO) in fan_write_cmd_disable()
9134 if (*rc == -ENXIO) in fan_write_cmd_speed()
9152 *rc = -EINVAL; in fan_write_cmd_watchdog()
9178 rc = -EINVAL; in fan_write()
9226 if (ACPI_FAILURE(acpi_get_handle(hkey_handle, t->name, &temp))) { in mute_led_on_off()
9227 pr_warn("Thinkpad ACPI has no %s interface.\n", t->name); in mute_led_on_off()
9228 return -EIO; in mute_led_on_off()
9231 if (!acpi_evalf(hkey_handle, &output, t->name, "dd", in mute_led_on_off()
9232 state ? t->on_value : t->off_value)) in mute_led_on_off()
9233 return -EIO; in mute_led_on_off()
9235 t->state = state; in mute_led_on_off()
9244 if (t->state < 0 || t->state == on) in tpacpi_led_set()
9245 return t->state; in tpacpi_led_set()
9266 .default_trigger = "audio-mute",
9272 .default_trigger = "audio-micmute",
9283 if (ACPI_FAILURE(acpi_get_handle(hkey_handle, t->name, &temp))) { in mute_led_init()
9284 t->state = -ENODEV; in mute_led_init()
9289 err = led_classdev_register(&tpacpi_pdev->dev, &mute_led_cdev[i]); in mute_led_init()
9291 while (i--) in mute_led_init()
9315 if (t->state >= 0) in mute_led_resume()
9316 mute_led_on_off(t, t->state); in mute_led_resume()
9405 return -ENODEV; in tpacpi_battery_get()
9412 return -ENODEV; in tpacpi_battery_get()
9426 return -ENODEV; in tpacpi_battery_get()
9432 return -ENODEV; in tpacpi_battery_get()
9438 return -EINVAL; in tpacpi_battery_get()
9447 /* The battery ID is in bits 8-9, 2 bits */ in tpacpi_battery_set()
9455 return -ENODEV; in tpacpi_battery_set()
9461 return -ENODEV; in tpacpi_battery_set()
9467 * battery ID is in bits 8-9, 2 bits. in tpacpi_battery_set()
9471 return -ENODEV; in tpacpi_battery_set()
9478 * The battery ID is in bits 4-5, 2 bits, in tpacpi_battery_set()
9479 * the effective time is in bits 8-23, 2 bytes. in tpacpi_battery_set()
9487 return -ENODEV; in tpacpi_battery_set()
9492 return -EINVAL; in tpacpi_battery_set()
9520 return -EIO; in tpacpi_battery_set_validate()
9543 return -ENODEV; in tpacpi_battery_probe()
9552 return -ENODEV; in tpacpi_battery_probe()
9556 return -ENODEV; in tpacpi_battery_probe()
9562 return -ENODEV; in tpacpi_battery_probe()
9568 return -ENODEV; in tpacpi_battery_probe()
9572 return -ENODEV; in tpacpi_battery_probe()
9578 return -ENODEV; in tpacpi_battery_probe()
9588 return -ENODEV; in tpacpi_battery_probe()
9649 battery = tpacpi_battery_get_id(supply->desc->name); in tpacpi_battery_store()
9660 return -ENODEV; in tpacpi_battery_store()
9663 return -EINVAL; in tpacpi_battery_store()
9665 return -EINVAL; in tpacpi_battery_store()
9667 return -ENODEV; in tpacpi_battery_store()
9673 return -ENODEV; in tpacpi_battery_store()
9676 return -EINVAL; in tpacpi_battery_store()
9678 return -EINVAL; in tpacpi_battery_store()
9688 return -EINVAL; in tpacpi_battery_store()
9692 return -EINVAL; in tpacpi_battery_store()
9716 battery = tpacpi_battery_get_id(supply->desc->name); in tpacpi_battery_show()
9720 return -ENODEV; in tpacpi_battery_show()
9747 battery = tpacpi_battery_get_id(supply->desc->name); in charge_behaviour_show()
9752 return -ENODEV; in charge_behaviour_show()
9761 return -ENODEV; in charge_behaviour_show()
9794 battery = tpacpi_battery_get_id(supply->desc->name); in charge_behaviour_store()
9826 return -EINVAL; in charge_behaviour_store()
9863 int batteryid = tpacpi_battery_get_id(battery->desc->name); in tpacpi_battery_add()
9866 return -ENODEV; in tpacpi_battery_add()
9867 if (device_add_groups(&battery->dev, tpacpi_battery_groups)) in tpacpi_battery_add()
9868 return -ENODEV; in tpacpi_battery_add()
9874 device_remove_groups(&battery->dev, tpacpi_battery_groups); in tpacpi_battery_remove()
9888 * Individual addressing is broken on models that expose the
9935 if (WARN_ON(!mutex_is_locked(&priv->lock))) in lcdshadow_set_sw_state()
9936 return -EIO; in lcdshadow_set_sw_state()
9939 return -EIO; in lcdshadow_set_sw_state()
9941 priv->hw_state = priv->sw_state = state; in lcdshadow_set_sw_state()
9952 priv->hw_state = priv->sw_state = output & 0x1; in lcdshadow_get_hw_state()
9971 return -EIO; in tpacpi_lcdshadow_init()
9976 lcdshadow_dev = drm_privacy_screen_register(&tpacpi_pdev->dev, in tpacpi_lcdshadow_init()
9994 mutex_lock(&lcdshadow_dev->lock); in lcdshadow_resume()
9995 lcdshadow_set_sw_state(lcdshadow_dev, lcdshadow_dev->sw_state); in lcdshadow_resume()
9996 mutex_unlock(&lcdshadow_dev->lock); in lcdshadow_resume()
10004 seq_printf(m, "status:\t\t%d\n", lcdshadow_dev->hw_state); in lcdshadow_read()
10014 int res, state = -EINVAL; in lcdshadow_write()
10017 return -ENODEV; in lcdshadow_write()
10026 return -EINVAL; in lcdshadow_write()
10028 mutex_lock(&lcdshadow_dev->lock); in lcdshadow_write()
10030 mutex_unlock(&lcdshadow_dev->lock); in lcdshadow_write()
10049 #define DYTC_CMD_QUERY 0 /* To get DYTC status - enable/revision */
10050 #define DYTC_QUERY_ENABLE_BIT 8 /* Bit 8 - 0 = disabled, 1 = enabled */
10051 #define DYTC_QUERY_SUBREV_BIT 16 /* Bits 16 - 27 - sub revision */
10052 #define DYTC_QUERY_REV_BIT 28 /* Bits 28 - 31 - revision */
10072 return -ENODEV; in dytc_command()
10075 return -EIO; in dytc_command()
10100 return -ENODEV; in palmsensor_get()
10102 return -EIO; in palmsensor_get()
10120 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, "dytc_lapmode"); in lapsensor_refresh()
10136 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, "palmsensor"); in palmsensor_refresh()
10182 return attr->mode; in proxsensor_attr_is_visible()
10196 /* If support isn't available for both devices return -ENODEV */ in tpacpi_proxsensor_init()
10197 if ((palm_err == -ENODEV) && (lap_err == -ENODEV)) in tpacpi_proxsensor_init()
10198 return -ENODEV; in tpacpi_proxsensor_init()
10200 if (palm_err && (palm_err != -ENODEV)) in tpacpi_proxsensor_init()
10202 if (lap_err && (lap_err != -ENODEV)) in tpacpi_proxsensor_init()
10209 .name = "proximity-sensor",
10225 #define DYTC_GET_FUNCTION_BIT 8 /* Bits 8-11 - function setting */
10226 #define DYTC_GET_MODE_BIT 12 /* Bits 12-15 - mode setting */
10228 #define DYTC_SET_FUNCTION_BIT 12 /* Bits 12-15 - function setting */
10229 #define DYTC_SET_MODE_BIT 16 /* Bits 16-19 - mode setting */
10230 #define DYTC_SET_VALID_BIT 20 /* Bit 20 - 1 = on, 0 = off */
10250 #define DYTC_ERR_MASK 0xF /* Bits 0-3 in cmd result are the error result */
10287 return -EINVAL; in convert_dytc_to_profile()
10302 return -EINVAL; in convert_dytc_to_profile()
10312 return -EOPNOTSUPP; in convert_dytc_to_profile()
10339 return -EOPNOTSUPP; in convert_profile_to_dytc()
10363 return -ENODEV; in dytc_control_amt()
10380 * Helper function - check if we are in CQL mode and if we are
10381 * - disable CQL,
10382 * - run the command
10383 * - enable CQL
10442 * Note we still need to disable CQL mode before hand and re-enable in dytc_profile_set()
10465 /* Success - update current profile */ in dytc_profile_set()
10490 err = -ENODEV; in dytc_profile_refresh()
10527 return -ENODEV; in tpacpi_dytc_profile_init()
10537 case -1: in tpacpi_dytc_profile_init()
10565 return -ENODEV; in tpacpi_dytc_profile_init()
10578 return -ENODEV; in tpacpi_dytc_profile_init()
10596 .name = "dytc-profile",
10618 {"fr-ch", 0x100c},
10638 return -ENODEV; in set_keyboard_lang_command()
10642 return -EIO; in set_keyboard_lang_command()
10654 return -ENODEV; in get_keyboard_lang()
10658 return -EIO; in get_keyboard_lang()
10662 * '(' and ')') keys which use layout dependent key-press emulation. in get_keyboard_lang()
10665 return -ENODEV; in get_keyboard_lang()
10722 dev_err(&tpacpi_pdev->dev, "Unknown Keyboard language. Ignoring\n"); in keyboard_lang_store()
10723 return -EINVAL; in keyboard_lang_store()
10726 tpacpi_disclose_usertask(attr->attr.name, in keyboard_lang_store()
10729 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, "keyboard_lang"); in keyboard_lang_store()
10743 return tp_features.kbd_lang ? attr->mode : 0; in kbdlang_attr_is_visible()
10780 return -ENODEV; in dprc_command()
10784 return -EIO; in dprc_command()
10792 return -ENODEV; in dprc_command()
10811 return -ENODEV; in get_wwan_antenna()
10827 return -ENODATA; in wwan_antenna_type_show()
10840 return has_antennatype ? attr->mode : 0; in dprc_attr_is_visible()
10868 * MAC Address Pass-through feature. In most cases, there are three
10890 return -ENODEV; in auxmac_init()
10894 if (obj->type != ACPI_TYPE_STRING || obj->string.length != AUXMAC_STRLEN) { in auxmac_init()
10895 pr_info("Invalid buffer for MAC address pass-through.\n"); in auxmac_init()
10899 if (obj->string.pointer[AUXMAC_BEGIN_MARKER] != '#' || in auxmac_init()
10900 obj->string.pointer[AUXMAC_END_MARKER] != '#') { in auxmac_init()
10901 pr_info("Invalid header for MAC address pass-through.\n"); in auxmac_init()
10905 if (strncmp(obj->string.pointer + AUXMAC_START, "XXXXXXXXXXXX", AUXMAC_LEN) != 0) in auxmac_init()
10906 strscpy(auxmac, obj->string.pointer + AUXMAC_START, sizeof(auxmac)); in auxmac_init()
10934 return auxmac[0] == 0 ? 0 : attr->mode; in auxmac_attr_is_visible()
10947 /* --------------------------------------------------------------------- */
10980 return attr->mode; in tpacpi_attr_is_visible()
11097 if (!atomic_add_unless(&dytc_ignore_event, -1, 0)) in tpacpi_driver_event()
11105 mutex_lock(&lcdshadow_dev->lock); in tpacpi_driver_event()
11106 old_hw_state = lcdshadow_dev->hw_state; in tpacpi_driver_event()
11108 changed = lcdshadow_dev->hw_state != old_hw_state; in tpacpi_driver_event()
11109 mutex_unlock(&lcdshadow_dev->lock); in tpacpi_driver_event()
11130 /* --------------------------------------------------------------------- */
11152 dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); in ibm_exit()
11154 list_del_init(&ibm->all_drivers); in ibm_exit()
11156 if (ibm->flags.acpi_notify_installed) { in ibm_exit()
11158 "%s: acpi_remove_notify_handler\n", ibm->name); in ibm_exit()
11159 BUG_ON(!ibm->acpi); in ibm_exit()
11160 acpi_remove_notify_handler(*ibm->acpi->handle, in ibm_exit()
11161 ibm->acpi->type, in ibm_exit()
11163 ibm->flags.acpi_notify_installed = 0; in ibm_exit()
11166 if (ibm->flags.proc_created) { in ibm_exit()
11168 "%s: remove_proc_entry\n", ibm->name); in ibm_exit()
11169 remove_proc_entry(ibm->name, proc_dir); in ibm_exit()
11170 ibm->flags.proc_created = 0; in ibm_exit()
11173 if (ibm->flags.acpi_driver_registered) { in ibm_exit()
11175 "%s: acpi_bus_unregister_driver\n", ibm->name); in ibm_exit()
11176 BUG_ON(!ibm->acpi); in ibm_exit()
11177 acpi_bus_unregister_driver(ibm->acpi->driver); in ibm_exit()
11178 kfree(ibm->acpi->driver); in ibm_exit()
11179 ibm->acpi->driver = NULL; in ibm_exit()
11180 ibm->flags.acpi_driver_registered = 0; in ibm_exit()
11183 if (ibm->flags.init_called && ibm->exit) { in ibm_exit()
11184 ibm->exit(); in ibm_exit()
11185 ibm->flags.init_called = 0; in ibm_exit()
11188 dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); in ibm_exit()
11194 struct ibm_struct *ibm = iibm->data; in ibm_init()
11199 INIT_LIST_HEAD(&ibm->all_drivers); in ibm_init()
11201 if (ibm->flags.experimental && !experimental) in ibm_init()
11205 "probing for %s\n", ibm->name); in ibm_init()
11207 if (iibm->init) { in ibm_init()
11208 ret = iibm->init(iibm); in ibm_init()
11209 if (ret > 0 || ret == -ENODEV) in ibm_init()
11214 ibm->flags.init_called = 1; in ibm_init()
11217 if (ibm->acpi) { in ibm_init()
11218 if (ibm->acpi->hid) { in ibm_init()
11224 if (ibm->acpi->notify) { in ibm_init()
11226 if (ret == -ENODEV) { in ibm_init()
11228 ibm->name); in ibm_init()
11238 "%s installed\n", ibm->name); in ibm_init()
11240 if (ibm->read) { in ibm_init()
11241 umode_t mode = iibm->base_procfs_mode; in ibm_init()
11245 if (ibm->write) in ibm_init()
11247 entry = proc_create_data(ibm->name, mode, proc_dir, in ibm_init()
11250 pr_err("unable to create proc entry %s\n", ibm->name); in ibm_init()
11251 ret = -ENODEV; in ibm_init()
11254 ibm->flags.proc_created = 1; in ibm_init()
11257 list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); in ibm_init()
11264 ibm->name, ret); in ibm_init()
11287 * Ancient 570/600 and -SL lacks (#.##c) in tpacpi_parse_fw_id()
11315 * ---------------------------------------------------- in find_new_ec_fwstr()
11328 if (dm->type != 140 || dm->length < 0x0F || in find_new_ec_fwstr()
11339 /* returns 0 - probe ok, or < 0 - probe error.
11341 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
11351 return -EINVAL; in get_thinkpad_model_data()
11356 tp->vendor = PCI_VENDOR_ID_IBM; in get_thinkpad_model_data()
11358 tp->vendor = PCI_VENDOR_ID_LENOVO; in get_thinkpad_model_data()
11363 tp->bios_version_str = kstrdup(s, GFP_KERNEL); in get_thinkpad_model_data()
11364 if (s && !tp->bios_version_str) in get_thinkpad_model_data()
11365 return -ENOMEM; in get_thinkpad_model_data()
11368 t = tpacpi_parse_fw_id(tp->bios_version_str, in get_thinkpad_model_data()
11369 &tp->bios_model, &tp->bios_release); in get_thinkpad_model_data()
11376 * up-to-date BIOS or they will not be detected. in get_thinkpad_model_data()
11381 if (sscanf(dev->name, in get_thinkpad_model_data()
11382 "IBM ThinkPad Embedded Controller -[%17c", in get_thinkpad_model_data()
11384 ec_fw_string[sizeof(ec_fw_string) - 1] = 0; in get_thinkpad_model_data()
11395 tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); in get_thinkpad_model_data()
11396 if (!tp->ec_version_str) in get_thinkpad_model_data()
11397 return -ENOMEM; in get_thinkpad_model_data()
11400 &tp->ec_model, &tp->ec_release); in get_thinkpad_model_data()
11410 tp->model_str = kstrdup(s, GFP_KERNEL); in get_thinkpad_model_data()
11411 if (!tp->model_str) in get_thinkpad_model_data()
11412 return -ENOMEM; in get_thinkpad_model_data()
11416 tp->model_str = kstrdup(s, GFP_KERNEL); in get_thinkpad_model_data()
11417 if (!tp->model_str) in get_thinkpad_model_data()
11418 return -ENOMEM; in get_thinkpad_model_data()
11423 tp->nummodel_str = kstrdup(s, GFP_KERNEL); in get_thinkpad_model_data()
11424 if (s && !tp->nummodel_str) in get_thinkpad_model_data()
11425 return -ENOMEM; in get_thinkpad_model_data()
11435 return -ENODEV; in probe_for_thinkpad()
11439 return -ENODEV; in probe_for_thinkpad()
11442 * Non-ancient models have better DMI tagging, but very old models in probe_for_thinkpad()
11454 return -ENODEV; in probe_for_thinkpad()
11458 return -ENODEV; in probe_for_thinkpad()
11591 if (!kp || !kp->name || !val) in set_ibm_param()
11592 return -EINVAL; in set_ibm_param()
11596 if (!ibm || !ibm->name) in set_ibm_param()
11599 if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { in set_ibm_param()
11600 if (strlen(val) > sizeof(ibms_init[i].param) - 1) in set_ibm_param()
11601 return -ENOSPC; in set_ibm_param()
11607 return -EINVAL; in set_ibm_param()
11612 "Enables experimental features when non-zero");
11615 MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
11619 "Attempts to load the driver even on a mis-identified ThinkPad when true");
11662 …MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command at module load, see documentatio…
11702 MODULE_PARM_DESC(profile_force, "Force profile mode. -1=off, 1=MMC, 2=PSC");
11757 /* Driver-level probe */ in thinkpad_acpi_module_init()
11797 return -ENOMEM; in thinkpad_acpi_module_init()
11804 return -ENODEV; in thinkpad_acpi_module_init()
11809 tp_features.quirks = dmi_id->driver_data; in thinkpad_acpi_module_init()
11836 return -ENOMEM; in thinkpad_acpi_module_init()
11839 tpacpi_inputdev->name = "ThinkPad Extra Buttons"; in thinkpad_acpi_module_init()
11840 tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; in thinkpad_acpi_module_init()
11841 tpacpi_inputdev->id.bustype = BUS_HOST; in thinkpad_acpi_module_init()
11842 tpacpi_inputdev->id.vendor = thinkpad_id.vendor; in thinkpad_acpi_module_init()
11843 tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; in thinkpad_acpi_module_init()
11844 tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; in thinkpad_acpi_module_init()
11845 tpacpi_inputdev->dev.parent = &tpacpi_pdev->dev; in thinkpad_acpi_module_init()
11855 ret = ibms_init[i].data->write(ibms_init[i].param); in thinkpad_acpi_module_init()
11881 &tpacpi_sensors_pdev->dev, TPACPI_NAME, NULL, tpacpi_hwmon_groups); in thinkpad_acpi_module_init()