Lines Matching +full:keyboard +full:- +full:controller +full:- +full:style
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>
48 #include <linux/input/sparse-keymap.h>
122 /* Misc NVRAM-related */
171 /* Adaptive keyboard (2014 X1 Carbon) */
181 * hkey -> scancode translation for
183 * directly in the sparse-keymap.
198 /* Auto-sleep after eject request */
210 * when keyboard cover is attached, detached or folded onto the back
212 TP_HKEY_EV_KBD_COVER_ATTACH = 0x4012, /* keyboard cover attached */
213 TP_HKEY_EV_KBD_COVER_DETACH = 0x4013, /* keyboard cover detached or folded back */
215 /* User-interface events */
227 /* Key-related user-interface events */
244 /* AC-related events */
247 /* Further user-interface events */
248 TP_HKEY_EV_PALM_DETECTED = 0x60b0, /* palm hoveres keyboard */
265 #define TPACPI_URL "http://ibm-acpi.sf.net/"
266 #define TPACPI_MAIL "ibm-acpi-devel@lists.sourceforge.net"
293 * Driver-wide structs and misc. variables
391 char *ec_version_str; /* Something like 1ZHT51WW-1.04a */
399 char *nummodel_str; /* 9384A9C for a 9384-A9C model */
480 * two or three characters from the set [0-9A-Z], i.e. base 36.
532 * tpacpi_check_quirks() - search BIOS/EC version on a list
549 if ((qlist->vendor == thinkpad_id.vendor || in tpacpi_check_quirks()
550 qlist->vendor == TPACPI_MATCH_ANY) && in tpacpi_check_quirks()
551 (qlist->bios == thinkpad_id.bios_model || in tpacpi_check_quirks()
552 qlist->bios == TPACPI_MATCH_ANY) && in tpacpi_check_quirks()
553 (qlist->ec == thinkpad_id.ec_model || in tpacpi_check_quirks()
554 qlist->ec == TPACPI_MATCH_ANY)) in tpacpi_check_quirks()
555 return qlist->quirks; in tpacpi_check_quirks()
557 qlist_size--; in tpacpi_check_quirks()
599 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
725 return -ENXIO; in issue_thinkpad_cmos_command()
728 return -EIO; in issue_thinkpad_cmos_command()
817 if (!ibm || !ibm->acpi || !ibm->acpi->notify) in dispatch_acpi_notify()
820 ibm->acpi->notify(ibm, event); in dispatch_acpi_notify()
827 BUG_ON(!ibm->acpi); in setup_acpi_notify()
829 if (!*ibm->acpi->handle) in setup_acpi_notify()
833 "setting up ACPI notify for %s\n", ibm->name); in setup_acpi_notify()
835 ibm->acpi->device = acpi_fetch_acpi_dev(*ibm->acpi->handle); in setup_acpi_notify()
836 if (!ibm->acpi->device) { in setup_acpi_notify()
837 pr_err("acpi_fetch_acpi_dev(%s) failed\n", ibm->name); in setup_acpi_notify()
838 return -ENODEV; in setup_acpi_notify()
841 ibm->acpi->device->driver_data = ibm; in setup_acpi_notify()
842 sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", in setup_acpi_notify()
844 ibm->name); in setup_acpi_notify()
846 status = acpi_install_notify_handler(*ibm->acpi->handle, in setup_acpi_notify()
847 ibm->acpi->type, dispatch_acpi_notify, ibm); in setup_acpi_notify()
851 ibm->name); in setup_acpi_notify()
854 ibm->name, acpi_format_exception(status)); in setup_acpi_notify()
856 return -ENODEV; in setup_acpi_notify()
858 ibm->flags.acpi_notify_installed = 1; in setup_acpi_notify()
872 "registering %s as an ACPI driver\n", ibm->name); in register_tpacpi_subdriver()
874 BUG_ON(!ibm->acpi); in register_tpacpi_subdriver()
876 ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); in register_tpacpi_subdriver()
877 if (!ibm->acpi->driver) { in register_tpacpi_subdriver()
878 pr_err("failed to allocate memory for ibm->acpi->driver\n"); in register_tpacpi_subdriver()
879 return -ENOMEM; in register_tpacpi_subdriver()
882 sprintf(ibm->acpi->driver->name, "%s_%s", TPACPI_NAME, ibm->name); in register_tpacpi_subdriver()
883 ibm->acpi->driver->ids = ibm->acpi->hid; in register_tpacpi_subdriver()
885 ibm->acpi->driver->ops.add = &tpacpi_device_add; in register_tpacpi_subdriver()
887 rc = acpi_bus_register_driver(ibm->acpi->driver); in register_tpacpi_subdriver()
890 ibm->name, rc); in register_tpacpi_subdriver()
891 kfree(ibm->acpi->driver); in register_tpacpi_subdriver()
892 ibm->acpi->driver = NULL; in register_tpacpi_subdriver()
894 ibm->flags.acpi_driver_registered = 1; in register_tpacpi_subdriver()
910 struct ibm_struct *ibm = m->private; in dispatch_proc_show()
912 if (!ibm || !ibm->read) in dispatch_proc_show()
913 return -EINVAL; in dispatch_proc_show()
914 return ibm->read(m); in dispatch_proc_show()
930 if (!ibm || !ibm->write) in dispatch_proc_write()
931 return -EINVAL; in dispatch_proc_write()
932 if (count > PAGE_SIZE - 1) in dispatch_proc_write()
933 return -EINVAL; in dispatch_proc_write()
938 ret = ibm->write(kernbuf); in dispatch_proc_write()
978 if (ibm->suspend) in tpacpi_suspend_handler()
979 (ibm->suspend)(); in tpacpi_suspend_handler()
992 if (ibm->resume) in tpacpi_resume_handler()
993 (ibm->resume)(); in tpacpi_resume_handler()
1010 if (ibm->shutdown) in tpacpi_shutdown_handler()
1011 (ibm->shutdown)(); in tpacpi_shutdown_handler()
1027 return -EINVAL; in parse_strtoul()
1051 * ThinkPad-ACPI firmware handling model:
1053 * WLSW (master wireless switch) is event-driven, and is common to all
1054 * firmware-controlled radios. It cannot be controlled, just monitored,
1057 * The kernel, a masked-off hotkey, and WLSW can change the radio state
1061 * masked-off hotkeys are used.
1090 /* ThinkPad-ACPI rfkill subdriver */
1111 return -ENODEV; in tpacpi_rfk_update_swstate()
1113 status = (tp_rfk->ops->get_status)(); in tpacpi_rfk_update_swstate()
1117 rfkill_set_sw_state(tp_rfk->rfkill, in tpacpi_rfk_update_swstate()
1124 * Sync the HW-blocking state of all rfkill switches,
1135 if (rfkill_set_hw_state(tp_rfk->rfkill, in tpacpi_rfk_update_hwblock_state()
1137 /* ignore -- we track sw block */ in tpacpi_rfk_update_hwblock_state()
1172 res = (tp_rfk->ops->set_status)(blocked ? in tpacpi_rfk_hook_set_block()
1201 atp_rfk->rfkill = rfkill_alloc(name, in tpacpi_new_rfkill()
1202 &tpacpi_pdev->dev, in tpacpi_new_rfkill()
1206 if (!atp_rfk || !atp_rfk->rfkill) { in tpacpi_new_rfkill()
1209 return -ENOMEM; in tpacpi_new_rfkill()
1212 atp_rfk->id = id; in tpacpi_new_rfkill()
1213 atp_rfk->ops = tp_rfkops; in tpacpi_new_rfkill()
1215 sw_status = (tp_rfkops->get_status)(); in tpacpi_new_rfkill()
1224 rfkill_init_sw_state(atp_rfk->rfkill, sw_state); in tpacpi_new_rfkill()
1228 rfkill_set_hw_state(atp_rfk->rfkill, hw_state); in tpacpi_new_rfkill()
1230 res = rfkill_register(atp_rfk->rfkill); in tpacpi_new_rfkill()
1233 rfkill_destroy(atp_rfk->rfkill); in tpacpi_new_rfkill()
1253 rfkill_unregister(tp_rfk->rfkill); in tpacpi_destroy_rfkill()
1254 rfkill_destroy(tp_rfk->rfkill); in tpacpi_destroy_rfkill()
1266 /* sysfs <radio> enable ------------------------------------------------ */
1273 printk_deprecated_rfkill_attribute(attr->attr.name); in tpacpi_rfk_sysfs_enable_show()
1295 printk_deprecated_rfkill_attribute(attr->attr.name); in tpacpi_rfk_sysfs_enable_store()
1298 return -EINVAL; in tpacpi_rfk_sysfs_enable_store()
1300 tpacpi_disclose_usertask(attr->attr.name, "set to %ld\n", t); in tpacpi_rfk_sysfs_enable_store()
1304 return -EPERM; in tpacpi_rfk_sysfs_enable_store()
1306 res = tpacpi_rfkill_switches[id]->ops->set_status((!!t) ? in tpacpi_rfk_sysfs_enable_store()
1313 /* procfs -------------------------------------------------------------- */
1341 int status = -1; in tpacpi_rfk_procfs_write()
1345 return -ENODEV; in tpacpi_rfk_procfs_write()
1353 return -EINVAL; in tpacpi_rfk_procfs_write()
1356 if (status != -1) { in tpacpi_rfk_procfs_write()
1360 res = (tpacpi_rfkill_switches[id]->ops->set_status)(status); in tpacpi_rfk_procfs_write()
1368 * thinkpad-acpi driver attributes
1371 /* interface_version --------------------------------------------------- */
1378 /* debug_level --------------------------------------------------------- */
1390 return -EINVAL; in debug_level_store()
1398 /* version ------------------------------------------------------------- */
1406 /* --------------------------------------------------------------------- */
1410 /* wlsw_emulstate ------------------------------------------------------ */
1422 return -EINVAL; in wlsw_emulstate_store()
1433 /* bluetooth_emulstate ------------------------------------------------- */
1445 return -EINVAL; in bluetooth_emulstate_store()
1453 /* wwan_emulstate ------------------------------------------------- */
1465 return -EINVAL; in wwan_emulstate_store()
1473 /* uwb_emulstate ------------------------------------------------- */
1485 return -EINVAL; in uwb_emulstate_store()
1571 /* Numeric models ------------------ */
1583 /* A-series ------------------------- */
1597 /* G-series ------------------------- */
1602 /* R-series, T-series --------------- */
1632 /* X-series ------------------------- */
1645 /* (0) - older versions lack DMI EC fw string and functionality */
1646 /* (1) - older versions known to lack functionality */
1702 * thinkpad-acpi metadata subdriver
1737 * Unlike other classes, hotkey-class events have mask/unmask control on
1738 * non-ancient firmware. However, how it behaves changes a lot with the
1776 /* Adaptive keyboard keycodes */
1943 * keyboard.
1956 return -ENODEV; in hotkey_get_wlsw()
1965 return -EIO; in hotkey_get_wlsw()
2059 return -EIO; in hotkey_get_tablet_mode()
2065 return -EIO; in hotkey_get_tablet_mode()
2090 return -EIO; in hotkey_mask_get()
2098 /* sync userspace-visible mask */ in hotkey_mask_get()
2136 rc = -EIO; in hotkey_mask_set()
2177 …pr_notice("please consider using the driver defaults, and refer to up-to-date thinkpad-acpi docume… in hotkey_user_mask_set()
2226 return -EIO; in hotkey_status_get()
2234 return -EIO; in hotkey_status_set()
2264 * Before the conversion to using the sparse-keymap helpers the driver used to in tpacpi_input_send_key()
2265 * map the hkey event codes to 0x00 - 0x4d scancodes so that a straight scancode in tpacpi_input_send_key()
2268 * 0x1001 - 0x1020 -> 0x00 - 0x1f (Original ThinkPad events) in tpacpi_input_send_key()
2269 * 0x1103 - 0x1116 -> 0x20 - 0x33 (Adaptive keyboard, 2014 X1 Carbon) in tpacpi_input_send_key()
2270 * 0x1300 - 0x1319 -> 0x34 - 0x4d (Additional keys send in 2017+ models) in tpacpi_input_send_key()
2272 * The sparse-keymap tables still use these scancodes for these ranges to in tpacpi_input_send_key()
2277 scancode = hkey - TP_HKEY_EV_ORIG_KEY_START; in tpacpi_input_send_key()
2282 scancode = hkey - TP_HKEY_EV_ADAPTIVE_KEY_START + in tpacpi_input_send_key()
2286 scancode = hkey - TP_HKEY_EV_EXTENDED_KEY_START + in tpacpi_input_send_key()
2322 n->thinkpad_toggle = !!(d & TP_NVRAM_MASK_HKT_THINKPAD); in hotkey_read_nvram()
2323 n->zoom_toggle = !!(d & TP_NVRAM_MASK_HKT_ZOOM); in hotkey_read_nvram()
2324 n->display_toggle = !!(d & TP_NVRAM_MASK_HKT_DISPLAY); in hotkey_read_nvram()
2325 n->hibernate_toggle = !!(d & TP_NVRAM_MASK_HKT_HIBERNATE); in hotkey_read_nvram()
2329 n->thinklight_toggle = !!(d & TP_NVRAM_MASK_THINKLIGHT); in hotkey_read_nvram()
2333 n->displayexp_toggle = in hotkey_read_nvram()
2338 n->brightness_level = (d & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) in hotkey_read_nvram()
2340 n->brightness_toggle = in hotkey_read_nvram()
2345 n->volume_level = (d & TP_NVRAM_MASK_LEVEL_VOLUME) in hotkey_read_nvram()
2347 n->mute = !!(d & TP_NVRAM_MASK_MUTE); in hotkey_read_nvram()
2348 n->volume_toggle = !!(d & TP_NVRAM_MASK_HKT_VOLUME); in hotkey_read_nvram()
2355 oldn->__member != newn->__member) \
2373 i--; in issue_volchange()
2389 i--; in issue_brightnesschange()
2415 * - Pressing MUTE issues mute hotkey message, even when already mute in hotkey_compare_and_issue_event()
2416 * - Pressing Volume up/down issues volume up/down hotkey messages, in hotkey_compare_and_issue_event()
2418 * - The act of unmuting issues volume up/down notification, in hotkey_compare_and_issue_event()
2428 if (newn->mute) { in hotkey_compare_and_issue_event()
2430 if (!oldn->mute || in hotkey_compare_and_issue_event()
2431 oldn->volume_toggle != newn->volume_toggle || in hotkey_compare_and_issue_event()
2432 oldn->volume_level != newn->volume_level) { in hotkey_compare_and_issue_event()
2435 issue_volchange(oldn->volume_level, newn->volume_level, in hotkey_compare_and_issue_event()
2441 if (oldn->mute) { in hotkey_compare_and_issue_event()
2445 if (oldn->volume_level != newn->volume_level) { in hotkey_compare_and_issue_event()
2446 issue_volchange(oldn->volume_level, newn->volume_level, in hotkey_compare_and_issue_event()
2448 } else if (oldn->volume_toggle != newn->volume_toggle) { in hotkey_compare_and_issue_event()
2450 if (newn->volume_level == 0) in hotkey_compare_and_issue_event()
2452 else if (newn->volume_level >= TP_NVRAM_LEVEL_VOLUME_MAX) in hotkey_compare_and_issue_event()
2458 if (oldn->brightness_level != newn->brightness_level) { in hotkey_compare_and_issue_event()
2459 issue_brightnesschange(oldn->brightness_level, in hotkey_compare_and_issue_event()
2460 newn->brightness_level, event_mask); in hotkey_compare_and_issue_event()
2461 } else if (oldn->brightness_toggle != newn->brightness_toggle) { in hotkey_compare_and_issue_event()
2463 if (newn->brightness_level == 0) in hotkey_compare_and_issue_event()
2465 else if (newn->brightness_level >= bright_maxlvl in hotkey_compare_and_issue_event()
2478 * most of them are edge-based. We only issue those requested by
2572 (poll_user_mask && tpacpi_inputdev->users > 0))) { in hotkey_poll_setup()
2631 return -EBUSY; in hotkey_inputdev_open()
2636 return -EBUSY; in hotkey_inputdev_open()
2647 /* sysfs hotkey enable ------------------------------------------------- */
2674 return -EINVAL; in hotkey_enable_store()
2677 return -EPERM; in hotkey_enable_store()
2684 /* sysfs hotkey mask --------------------------------------------------- */
2700 return -EINVAL; in hotkey_mask_store()
2703 return -ERESTARTSYS; in hotkey_mask_store()
2720 /* sysfs hotkey bios_enabled ------------------------------------------- */
2730 /* sysfs hotkey bios_mask ---------------------------------------------- */
2742 /* sysfs hotkey all_mask ----------------------------------------------- */
2753 /* sysfs hotkey all_mask ----------------------------------------------- */
2764 /* sysfs hotkey recommended_mask --------------------------------------- */
2778 /* sysfs hotkey hotkey_source_mask ------------------------------------- */
2796 return -EINVAL; in hotkey_source_mask_store()
2799 return -ERESTARTSYS; in hotkey_source_mask_store()
2829 /* sysfs hotkey hotkey_poll_freq --------------------------------------- */
2844 return -EINVAL; in hotkey_poll_freq_store()
2847 return -ERESTARTSYS; in hotkey_poll_freq_store()
2863 /* sysfs hotkey radio_sw (pollable) ------------------------------------ */
2885 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, in hotkey_radio_sw_notify_change()
2889 /* sysfs hotkey tablet mode (pollable) --------------------------------- */
2907 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, in hotkey_tablet_mode_notify_change()
2911 /* sysfs wakeup reason (pollable) -------------------------------------- */
2923 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, in hotkey_wakeup_reason_notify_change()
2927 /* sysfs wakeup hotunplug_complete (pollable) -------------------------- */
2940 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, in hotkey_wakeup_hotunplug_complete_notify_change()
2944 /* sysfs adaptive kbd mode --------------------------------------------- */
2978 return -EINVAL; in adaptive_kbd_mode_store()
2994 return tp_features.has_adaptive_kbd ? attr->mode : 0; in hadaptive_kbd_attr_is_visible()
3002 /* --------------------------------------------------------------------- */
3034 return attr->mode; in hotkey_attr_is_visible()
3062 /* Sync hw blocking state first if it is hw-blocked */ in tpacpi_send_radiosw_update()
3066 /* Sync hw blocking state last if it is hw-unblocked */ in tpacpi_send_radiosw_update()
3170 /* Original hotkey mappings translated scancodes 0x00 - 0x1f */
3190 * Volume: firmware always reacts and reprograms the built-in *extra* mixer.
3201 /* Original hotkey mappings translated scancodes 0x00 - 0x1f */
3215 * These should be enabled --only-- when ACPI video is disabled and
3225 * reprograms the built-in *extra* mixer.
3227 * the regular keyboard (not through tpacpi). There are still weird bugs
3240 /* Adaptive keyboard mappings for Carbon X1 2014 translated scancodes 0x20 - 0x33 */
3261 /* Extended hotkeys mappings translated scancodes 0x34 - 0x4d */
3313 BUG_ON(tpacpi_inputdev->open != NULL || in hotkey_init()
3314 tpacpi_inputdev->close != NULL); in hotkey_init()
3331 return -ENODEV; in hotkey_init()
3339 A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking in hotkey_init()
3358 /* Fallback: pre-init for FN+F3,F4,F12 */ in hotkey_init()
3375 /* Fallback: pre-init for FN+F3,F4,F12 */ in hotkey_init()
3382 * Check if we have an adaptive keyboard, like on the in hotkey_init()
3487 pr_notice("Disabling thinkpad-acpi brightness events by default...\n"); in hotkey_init()
3518 if (res < 0 && res != -ENXIO) { in hotkey_init()
3528 tpacpi_inputdev->open = &hotkey_inputdev_open; in hotkey_init()
3529 tpacpi_inputdev->close = &hotkey_inputdev_close; in hotkey_init()
3540 * mode, Web conference mode, Function mode and Lay-flat mode.
3564 pr_err("Cannot read adaptive keyboard mode\n"); in adaptive_keyboard_get_mode()
3565 return -EIO; in adaptive_keyboard_get_mode()
3575 return -EINVAL; in adaptive_keyboard_set_mode()
3578 pr_err("Cannot set adaptive keyboard mode\n"); in adaptive_keyboard_set_mode()
3579 return -EIO; in adaptive_keyboard_set_mode()
3588 size_t max_mode = ARRAY_SIZE(adaptive_keyboard_modes) - 1; in adaptive_keyboard_get_next_mode()
3634 /* 0x1000-0x1FFF: key presses */
3637 /* Never send ACPI netlink events for original hotkeys (hkey: 0x1001 - 0x1020) */ in hotkey_notify_hotkey()
3642 unsigned int scancode = hkey - TP_HKEY_EV_ORIG_KEY_START; in hotkey_notify_hotkey()
3650 /* 0x2000-0x2FFF: Wakeup reason */
3669 /* how to auto-heal: */ in hotkey_notify_wakeup()
3679 pr_info("woke up due to a hot-unplug request...\n"); in hotkey_notify_wakeup()
3685 /* 0x4000-0x4FFF: dock-related events */
3705 * duplicates from intel-vbtn, which already emits SW_TABLET_MODE events in hotkey_notify_dockevent()
3712 * https://lore.kernel.org/platform-driver-x86/38cb8265-1e30-d547-9e12-b4ae290be737@a-kobel.de/ in hotkey_notify_dockevent()
3724 /* 0x5000-0x5FFF: human interface helpers */
3732 case TP_HKEY_EV_TABLET_TABLET: /* X41t-X61t: tablet mode */ in hotkey_notify_usrevent()
3733 case TP_HKEY_EV_TABLET_NOTEBOOK: /* X41t-X61t: normal mode */ in hotkey_notify_usrevent()
3754 /* 0x6000-0x6FFF: thermal alarms/notices and keyboard events */
3765 /* Thermal event - pass on to event handler */ in hotkey_notify_6xxx()
3800 * is still reporting them in the normal keyboard stream */ in hotkey_notify_6xxx()
3818 /* palm detected - pass on to event handler */ in hotkey_notify_6xxx()
3854 ibm->acpi->device->pnp.device_class, in hotkey_notify()
3855 dev_name(&ibm->acpi->device->dev), in hotkey_notify()
3876 /* 0x1000-0x1FFF: key presses */ in hotkey_notify()
3880 /* 0x2000-0x2FFF: Wakeup reason */ in hotkey_notify()
3884 /* 0x3000-0x3FFF: bay-related wakeups */ in hotkey_notify()
3899 /* 0x4000-0x4FFF: dock-related events */ in hotkey_notify()
3903 /* 0x5000-0x5FFF: human interface helpers */ in hotkey_notify()
3907 /* 0x6000-0x6FFF: thermal alarms/notices and in hotkey_notify()
3908 * keyboard events */ in hotkey_notify()
3912 /* 0x7000-0x7FFF: misc */ in hotkey_notify()
3921 /* 0x8000-0x8FFF: misc2 */ in hotkey_notify()
3934 ibm->acpi->device->pnp.device_class, in hotkey_notify()
3935 dev_name(&ibm->acpi->device->dev), in hotkey_notify()
3947 /* save previous mode of adaptive keyboard of X1 Carbon */ in hotkey_suspend()
3951 pr_err("Cannot read adaptive keyboard mode.\n"); in hotkey_suspend()
3973 /* restore previous mode of adapive keyboard of X1 Carbon */ in hotkey_resume()
3977 pr_err("Cannot set adaptive keyboard mode.\n"); in hotkey_resume()
3982 /* procfs -------------------------------------------------------------- */
3993 return -ERESTARTSYS; in hotkey_read()
4028 return -ENODEV; in hotkey_write()
4031 return -ERESTARTSYS; in hotkey_write()
4041 res = -EPERM; in hotkey_write()
4050 res = -EINVAL; in hotkey_write()
4105 TP_ACPI_BLTH_GET_PWR_ON_RESUME = 0x01, /* Get power-on-resume state */
4124 return -EIO; in bluetooth_get_status()
4151 return -EIO; in bluetooth_set_status()
4156 /* sysfs bluetooth enable ---------------------------------------------- */
4175 /* --------------------------------------------------------------------- */
4185 return tp_features.bluetooth ? attr->mode : 0; in bluetooth_attr_is_visible()
4233 .ident = "ThinkPad A285 - 20MW",
4241 .ident = "ThinkPad A285 - 20MX",
4249 .ident = "ThinkPad A485 - 20MU",
4257 .ident = "ThinkPad A485 - 20MV",
4281 if (tp_features.quirks && tp_features.quirks->btusb_bug && in have_bt_fwbug()
4301 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ in bluetooth_init()
4325 return -ENODEV; in bluetooth_init()
4335 /* procfs -------------------------------------------------------------- */
4379 return -EIO; in wan_get_status()
4406 return -EIO; in wan_set_status()
4411 /* sysfs wan enable ---------------------------------------------------- */
4431 /* --------------------------------------------------------------------- */
4441 return tp_features.wan ? attr->mode : 0; in wan_attr_is_visible()
4504 return -ENODEV; in wan_init()
4514 /* procfs -------------------------------------------------------------- */
4556 return -EIO; in uwb_get_status()
4582 return -EIO; in uwb_set_status()
4587 /* --------------------------------------------------------------------- */
4632 return -ENODEV; in uwb_init()
4725 return (video_supported != TPACPI_VIDEO_NONE) ? 0 : -ENODEV; in video_init()
4745 return -EIO; in video_outputsw_get()
4750 return -EIO; in video_outputsw_get()
4754 return -EIO; in video_outputsw_get()
4761 return -EIO; in video_outputsw_get()
4767 return -EIO; in video_outputsw_get()
4771 return -EIO; in video_outputsw_get()
4776 return -ENOSYS; in video_outputsw_get()
4805 pr_err("video auto-switch left enabled due to error\n"); in video_outputsw_set()
4806 return -EIO; in video_outputsw_set()
4814 return -ENOSYS; in video_outputsw_set()
4817 return (res) ? 0 : -EIO; in video_outputsw_set()
4827 return -EIO; in video_autosw_get()
4832 return -EIO; in video_autosw_get()
4835 return -ENOSYS; in video_autosw_get()
4844 return -EIO; in video_autosw_set()
4871 return -ENOSYS; in video_outputsw_cycle()
4874 pr_err("video auto-switch left enabled due to error\n"); in video_outputsw_cycle()
4875 return -EIO; in video_outputsw_cycle()
4878 return (res) ? 0 : -EIO; in video_outputsw_cycle()
4886 0 : -EIO; in video_expand_toggle()
4889 0 : -EIO; in video_expand_toggle()
4892 0 : -EIO; in video_expand_toggle()
4894 return -ENOSYS; in video_expand_toggle()
4910 return -EPERM; in video_read()
4943 return -ENODEV; in video_write()
4947 return -EPERM; in video_write()
4984 return -EINVAL; in video_write()
5009 * Keyboard backlight subdriver
5020 return -ENXIO; in kbdlight_set_level()
5025 ret = -EIO; in kbdlight_set_level()
5039 return -ENXIO; in kbdlight_get_level()
5042 return -EIO; in kbdlight_get_level()
5074 * Guessed test for keyboard backlight: in kbdlight_is_supported()
5076 * Machines with backlight keyboard return: in kbdlight_is_supported()
5077 * b010100000010000000XX - ThinkPad X1 Carbon 3rd in kbdlight_is_supported()
5078 * b110100010010000000XX - ThinkPad x230 in kbdlight_is_supported()
5079 * b010100000010000000XX - ThinkPad x240 in kbdlight_is_supported()
5080 * b010100000010000000XX - ThinkPad W541 in kbdlight_is_supported()
5083 * Machines without backlight keyboard return: in kbdlight_is_supported()
5084 * b10100001000000000000 - ThinkPad x230 in kbdlight_is_supported()
5085 * b10110001000000000000 - ThinkPad E430 in kbdlight_is_supported()
5086 * b00000000000000000000 - ThinkPad E450 in kbdlight_is_supported()
5133 return -ENODEV; in kbdlight_init()
5139 rc = led_classdev_register(&tpacpi_pdev->dev, in kbdlight_init()
5164 if (ret == 0 && !(led_cdev->flags & LED_SUSPENDED)) in kbdlight_set_level_and_update()
5165 led_cdev->brightness = level; in kbdlight_set_level_and_update()
5191 int res, level = -EINVAL; in kbdlight_write()
5194 return -ENODEV; in kbdlight_write()
5203 return -EINVAL; in kbdlight_write()
5241 TPACPI_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
5250 return -EIO; in light_get_status()
5254 return -ENXIO; in light_get_status()
5271 return (rc) ? 0 : -EIO; in light_set_status()
5274 return -ENXIO; in light_set_status()
5324 return -ENODEV; in light_init()
5326 rc = led_classdev_register(&tpacpi_pdev->dev, in light_init()
5370 return -ENODEV; in light_write()
5378 return -EINVAL; in light_write()
5395 /* sysfs cmos_command -------------------------------------------------- */
5404 return -EINVAL; in cmos_command_store()
5420 return cmos_handle ? attr->mode : 0; in cmos_attr_is_visible()
5428 /* --------------------------------------------------------------------- */
5440 return cmos_handle ? 0 : -ENODEV; in cmos_init()
5446 R30, R31, T20-22, X20-21 */ in cmos_read()
5451 seq_printf(m, "commands:\t<cmd> (<cmd> is 0-21)\n"); in cmos_read()
5467 return -EINVAL; in cmos_write()
5490 TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
5543 return -EIO; in led_get_status()
5552 return -ENXIO; in led_get_status()
5571 return -EINVAL; in led_set_status()
5573 return -EPERM; in led_set_status()
5576 return -EIO; in led_set_status()
5579 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ in led_set_status()
5581 return -EINVAL; in led_set_status()
5583 return -EPERM; in led_set_status()
5595 return -EINVAL; in led_set_status()
5597 return -EPERM; in led_set_status()
5600 return -EIO; in led_set_status()
5603 return -ENXIO; in led_set_status()
5621 else if (tpacpi_led_state_cache[data->led] != TPACPI_LED_BLINK) in led_sysfs_set()
5626 return led_set_status(data->led, new_state); in led_sysfs_set()
5641 return -EINVAL; in led_sysfs_blink_set()
5643 return led_set_status(data->led, TPACPI_LED_BLINK); in led_sysfs_blink_set()
5653 rc = led_get_status(data->led); in led_sysfs_get()
5688 return led_classdev_register(&tpacpi_pdev->dev, &tpacpi_leds[led].led_classdev); in tpacpi_init_led()
5716 /* (1) - may have excess leds enabled on MSB */
5746 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ in led_init_detect_mode()
5786 return -ENODEV; in led_init()
5792 return -ENOMEM; in led_init()
5796 tpacpi_leds[i].led = -1; in led_init()
5829 return -EIO; in led_read()
5834 seq_printf(m, "commands:\t<led> on, <led> off, <led> blink (<led> is 0-15)\n"); in led_read()
5846 return -ENODEV; in led_write()
5850 return -EINVAL; in led_write()
5852 if (led < 0 || led > (TPACPI_LED_NUMLEDS - 1)) in led_write()
5853 return -ENODEV; in led_write()
5856 return -ENODEV; in led_write()
5865 return -EINVAL; in led_write()
5893 TPACPI_Q_IBM('I', 'U', TPACPI_BEEP_Q1), /* 570E - unverified */
5912 return (beep_handle) ? 0 : -ENODEV; in beep_init()
5921 seq_printf(m, "commands:\t<cmd> (<cmd> is 0-17)\n"); in beep_read()
5933 return -ENODEV; in beep_write()
5940 return -EINVAL; in beep_write()
5944 return -EIO; in beep_write()
5948 return -EIO; in beep_write()
5967 TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
5968 TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
5977 TP_EC_THERMAL_TMP0_NS = 0xA8, /* ACPI EC Non-Standard regs TMP 0..7 */
5978 TP_EC_THERMAL_TMP8_NS = 0xB8, /* ACPI EC Non-standard regs TMP 8..11 */
5980 TP_EC_THERMAL_TMP_NA = -128, /* ACPI EC sensor not available */
5982 TPACPI_THERMAL_SENSOR_NA = -128000, /* Sensor not available */
5992 /* Non-standard address for thermal registers on some ThinkPads */
6000 TPACPI_Q_LNV3('R', '1', 'D', true), /* 11e Gen5 GL-R*/
6001 TPACPI_Q_LNV3('R', '0', 'V', true), /* 11e Gen5 KL-Y*/
6006 static bool thermal_with_ns_address; /* Non-standard thermal reg address */
6019 * Direct EC access mode: sensors at registers 0x78-0x7F, in thermal_read_mode_check()
6020 * 0xC0-0xC7. Registers return 0x00 for non-implemented, in thermal_read_mode_check()
6025 * determines EC version. 0xC0-0xC7 are not thermal registers in thermal_read_mode_check()
6031 /* Quirks to check non-standard EC */ in thermal_read_mode_check()
6035 /* Support for Thinkpads with non-standard address */ in thermal_read_mode_check()
6037 pr_info("ECFW with non-standard thermal registers found\n"); in thermal_read_mode_check()
6090 /* idx is zero-based */
6104 idx -= 8; in thermal_get_sensor()
6111 return -EIO; in thermal_get_sensor()
6117 /* The Non-standard EC uses 12 Thermal areas */ in thermal_get_sensor()
6120 return -EINVAL; in thermal_get_sensor()
6123 TP_EC_THERMAL_TMP8_NS + (idx - 8); in thermal_get_sensor()
6126 return -EIO; in thermal_get_sensor()
6135 return -EIO; in thermal_get_sensor()
6137 return -EIO; in thermal_get_sensor()
6138 *value = (t - 2732) * 100; in thermal_get_sensor()
6147 return -EIO; in thermal_get_sensor()
6148 if (t > 127 || t < -127) in thermal_get_sensor()
6157 return -ENOSYS; in thermal_get_sensor()
6160 return -EINVAL; in thermal_get_sensor()
6168 return -EINVAL; in thermal_get_sensors()
6178 res = thermal_get_sensor(i, &s->temp[i]); in thermal_get_sensors()
6207 /* sysfs temp##_input -------------------------------------------------- */
6215 int idx = sensor_attr->index; in thermal_temp_input_show()
6223 return -ENXIO; in thermal_temp_input_show()
6283 int idx = sensor_attr->index; in thermal_attr_is_visible()
6306 return attr->mode; in thermal_attr_is_visible()
6338 return thermal_use_labels ? attr->mode : 0; in temp_label_attr_is_visible()
6346 /* --------------------------------------------------------------------- */
6358 return thermal_read_mode != TPACPI_THERMAL_NONE ? 0 : -ENODEV; in thermal_init()
6373 for (i = 0; i < (n - 1); i++) in thermal_read()
6395 * CMOS NVRAM byte 0x5E, bits 0-3.
6402 * Bit 3-0: backlight brightness level
6423 TPACPI_BRGHT_MODE_UCMS_STEP, /* UCMS step-based control */
6504 return -EIO; in tpacpi_brightness_get_raw()
6508 return -ENXIO; in tpacpi_brightness_get_raw()
6520 return -EIO; in tpacpi_brightness_set_ec()
6525 return -EIO; in tpacpi_brightness_set_ec()
6545 inc = (value > current_value) ? 1 : -1; in tpacpi_brightness_set_ucmsstep()
6549 return -EIO; in tpacpi_brightness_set_ucmsstep()
6560 return -EINVAL; in brightness_set()
6578 res = -ENXIO; in brightness_set()
6585 /* sysfs backlight class ----------------------------------------------- */
6629 /* --------------------------------------------------------------------- */
6638 status = acpi_evaluate_object(adev->handle, "_BCL", NULL, &buffer); in tpacpi_evaluate_bcl()
6643 if (!obj || obj->type != ACPI_TYPE_PACKAGE) { in tpacpi_evaluate_bcl()
6644 acpi_handle_info(adev->handle, in tpacpi_evaluate_bcl()
6649 rc = obj->package.count; in tpacpi_evaluate_bcl()
6687 return (bcl_levels > 2) ? (bcl_levels - 2) : 0; in tpacpi_check_std_acpi_brightness_support()
6704 TPACPI_Q_IBM('1', 'R', TPACPI_BRGHT_Q_EC), /* R50,51 T40-42 */
6750 bright_maxlvl = b - 1; in tpacpi_detect_brightness_capabilities()
6772 return -ENODEV; in brightness_init()
6777 return -ENODEV; in brightness_init()
6783 return -ENODEV; in brightness_init()
6786 return -ENODEV; in brightness_init()
6790 return -ENODEV; in brightness_init()
6801 return -EINVAL; in brightness_init()
6812 "driver auto-selected brightness_mode=%d\n", in brightness_init()
6820 return -EINVAL; in brightness_init()
6823 return -ENODEV; in brightness_init()
6894 seq_printf(m, "commands:\tlevel <level> (<level> is 0-%d)\n", in brightness_read()
6917 level--; in brightness_write()
6922 return -EINVAL; in brightness_write()
6936 return (rc == -EINTR) ? -ERESTARTSYS : rc; in brightness_write()
6953 * IBM ThinkPads have a simple volume controller with MUTE gating.
6961 * Bit 3-0: Volume
6965 * bits 3-0 (volume). Other bits in NVRAM may have other functions,
6977 * To avoid confusing userspace, we simply disable all EC-based mute
6988 #define DEFAULT_ALSA_IDX ~((1 << (SNDRV_CARDS - 3)) - 1)
6990 #define DEFAULT_ALSA_IDX ~((1 << (32 - 3)) - 1)
7021 TPACPI_VOL_MODE_UCMS_STEP, /* UCMS step-based control: N/A */
7051 * TP_NVRAM_ADDR_MIXER, as we need to do read-modify-write
7107 return -EIO; in volume_get_status_ec()
7124 return -EIO; in volume_set_status_ec()
7149 return -EINTR; in __volume_set_mute_ec()
7194 return -EINVAL; in __volume_set_volume_ec()
7197 return -EINTR; in __volume_set_volume_ec()
7221 return -ENODEV; in volume_set_software_mute()
7226 return -EIO; in volume_set_software_mute()
7235 return -EIO; in volume_set_software_mute()
7244 * startup. Just on case there are SAUM-capable ThinkPads in volume_set_software_mute()
7278 if (alsa_card && alsa_card->private_data) { in volume_alsa_notify_change()
7279 d = alsa_card->private_data; in volume_alsa_notify_change()
7280 if (d->ctl_mute_id) in volume_alsa_notify_change()
7283 d->ctl_mute_id); in volume_alsa_notify_change()
7284 if (d->ctl_vol_id) in volume_alsa_notify_change()
7287 d->ctl_vol_id); in volume_alsa_notify_change()
7294 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; in volume_alsa_vol_info()
7295 uinfo->count = 1; in volume_alsa_vol_info()
7296 uinfo->value.integer.min = 0; in volume_alsa_vol_info()
7297 uinfo->value.integer.max = TP_EC_VOLUME_MAX; in volume_alsa_vol_info()
7311 ucontrol->value.integer.value[0] = s & TP_EC_AUDIO_LVL_MSK; in volume_alsa_vol_get()
7319 ucontrol->value.integer.value[0]); in volume_alsa_vol_put()
7320 return volume_alsa_set_volume(ucontrol->value.integer.value[0]); in volume_alsa_vol_put()
7335 ucontrol->value.integer.value[0] = in volume_alsa_mute_get()
7344 ucontrol->value.integer.value[0] ? in volume_alsa_mute_put()
7346 return volume_alsa_set_mute(!ucontrol->value.integer.value[0]); in volume_alsa_mute_put()
7408 rc = snd_card_new(&tpacpi_pdev->dev, in volume_create_alsa_mixer()
7413 return -ENODEV; in volume_create_alsa_mixer()
7416 BUG_ON(!card->private_data); in volume_create_alsa_mixer()
7417 data = card->private_data; in volume_create_alsa_mixer()
7418 data->card = card; in volume_create_alsa_mixer()
7420 strscpy(card->driver, TPACPI_ALSA_DRVNAME); in volume_create_alsa_mixer()
7421 strscpy(card->shortname, TPACPI_ALSA_SHRTNAME); in volume_create_alsa_mixer()
7422 snprintf(card->mixername, sizeof(card->mixername), "ThinkPad EC %s", in volume_create_alsa_mixer()
7425 snprintf(card->longname, sizeof(card->longname), in volume_create_alsa_mixer()
7426 "%s at EC reg 0x%02x, fw %s", card->shortname, TP_EC_AUDIO, in volume_create_alsa_mixer()
7448 data->ctl_vol_id = &ctl_vol->id; in volume_create_alsa_mixer()
7457 data->ctl_mute_id = &ctl_mute->id; in volume_create_alsa_mixer()
7470 return -ENODEV; in volume_create_alsa_mixer()
7473 #define TPACPI_VOL_Q_MUTEONLY 0x0001 /* Mute-only control available */
7492 /* Whitelist mute-only on all Lenovo by default */
7514 return -EINVAL; in volume_init()
7519 return -ENODEV; in volume_init()
7523 return -EINVAL; in volume_init()
7532 return -ENODEV; in volume_init()
7545 return -ENODEV; /* no mixer */ in volume_init()
7554 return -ENODEV; in volume_init()
7559 "using user-supplied volume_capabilities=%d\n", in volume_init()
7567 "driver auto-selected volume_mode=%d\n", in volume_init()
7571 "using user-supplied volume_mode=%d\n", in volume_init()
7623 seq_printf(m, "commands:\tlevel <level> (<level> is 0-%d)\n", in volume_read()
7650 return -EPERM; in volume_write()
7672 new_level--; in volume_write()
7685 return -EINVAL; in volume_write()
7700 return (rc == -EINTR) ? -ERESTARTSYS : rc; in volume_write()
7725 return -ENODEV; in volume_init()
7762 * Contains the current fan speed from 0-100%
7793 * the tachometer while the fan controller ramps up
7795 * Speeds up fan to 100% duty-cycle, which is far above
7798 * 5-3 unused in some models. Extra bits for fan level
7801 * 2-0 fan level (0..7 usually)
7814 * ----
7819 * This register is present on all ThinkPads with a new-style EC, and
7825 * Unfortunately a lot of ThinkPads with new-style ECs but whose firmware
7839 * ----
7851 * So far, only the firmware for the X60/X61 non-tablet versions
7852 * seem to support this (firmware TP-7M).
7877 * that are using non-standard EC locations for reporting fan speeds.
7882 #define FAN_RPM_CAL_CONST 491520 /* FAN RPM calculation offset for some non-standard ECFW */
7894 fan_status_offset_ns = 0x93, /* Special status/control offset for non-standard EC Fan1 */
7895 fan2_status_offset_ns = 0x96, /* Special status/control offset for non-standard EC Fan2 */
7896 fan_rpm_status_ns = 0x95, /* Special offset for Fan1 RPM status for non-standard EC */
7897 fan2_rpm_status_ns = 0x98, /* Special offset for Fan2 RPM status for non-standard EC */
7902 TPACPI_FAN_LAST_LEVEL = 0x100, /* Use cached last-seen fan level */
7909 TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
7910 TPACPI_FAN_RD_TPEC_NS, /* Use non-standard ACPI EC regs (eg: L13 Yoga gen2 etc.) */
7954 "JFNS", /* 770x-JL */
7971 * Enable for TP-1Y (T43), TP-78 (R51e), TP-76 (R52),
7972 * TP-70 (T43, R52), which are known to be buggy.
8057 return -EIO; in fan_get_status()
8069 return -EIO; in fan_get_status()
8071 return -EIO; in fan_get_status()
8084 return -EIO; in fan_get_status()
8095 return -EIO; in fan_get_status()
8103 return -ENXIO; in fan_get_status()
8115 return -ERESTARTSYS; in fan_get_status_safe()
8138 return -EIO; in fan_get_speed()
8141 return -EIO; in fan_get_speed()
8148 return -EIO; in fan_get_speed()
8155 return -ENXIO; in fan_get_speed()
8170 return -EIO; in fan2_get_speed()
8175 return -EIO; in fan2_get_speed()
8184 return -EIO; in fan2_get_speed()
8187 return -EIO; in fan2_get_speed()
8191 return -EIO; in fan2_get_speed()
8200 return -EIO; in fan2_get_speed()
8208 return -ENXIO; in fan2_get_speed()
8217 return -EPERM; in fan_set_level()
8222 return -EINVAL; in fan_set_level()
8233 return -EIO; in fan_set_level()
8241 return -EINVAL; in fan_set_level()
8260 return -EIO; in fan_set_level()
8267 return -EINVAL; in fan_set_level()
8269 return -EINVAL; in fan_set_level()
8273 return -EIO; in fan_set_level()
8276 return -EIO; in fan_set_level()
8280 return -EIO; in fan_set_level()
8283 return -EIO; in fan_set_level()
8286 return -EIO; in fan_set_level()
8292 return -ENXIO; in fan_set_level()
8305 return -EPERM; in fan_set_level_safe()
8308 return -ERESTARTSYS; in fan_set_level_safe()
8327 return -EPERM; in fan_set_enable()
8330 return -ERESTARTSYS; in fan_set_enable()
8346 rc = -EIO; in fan_set_enable()
8364 rc = -EIO; in fan_set_enable()
8371 rc = -EIO; in fan_set_enable()
8375 rc = -EIO; in fan_set_enable()
8383 rc = -ENXIO; in fan_set_enable()
8400 return -EPERM; in fan_set_disable()
8403 return -ERESTARTSYS; in fan_set_disable()
8410 rc = -EIO; in fan_set_disable()
8419 rc = -EIO; in fan_set_disable()
8426 rc = -EIO; in fan_set_disable()
8430 rc = -EIO; in fan_set_disable()
8434 rc = -EIO; in fan_set_disable()
8441 rc = -ENXIO; in fan_set_disable()
8457 return -EPERM; in fan_set_speed()
8460 return -ERESTARTSYS; in fan_set_speed()
8468 rc = -EIO; in fan_set_speed()
8470 rc = -EINVAL; in fan_set_speed()
8476 rc = -EIO; in fan_set_speed()
8480 rc = -EIO; in fan_set_speed()
8485 rc = -EIO; in fan_set_speed()
8487 rc = -EINVAL; in fan_set_speed()
8491 rc = -ENXIO; in fan_set_speed()
8549 /* sysfs fan pwm1_enable ----------------------------------------------- */
8579 return -EINVAL; in fan_pwm1_enable_store()
8595 /* reserved for software-controlled auto mode */ in fan_pwm1_enable_store()
8596 return -ENOSYS; in fan_pwm1_enable_store()
8598 return -EINVAL; in fan_pwm1_enable_store()
8602 if (res == -ENXIO) in fan_pwm1_enable_store()
8603 return -EINVAL; in fan_pwm1_enable_store()
8615 /* sysfs fan pwm1 ------------------------------------------------------ */
8646 return -EINVAL; in fan_pwm1_store()
8651 /* scale down from 0-255 to 0-7 */ in fan_pwm1_store()
8655 return -ERESTARTSYS; in fan_pwm1_store()
8661 if (rc == -ENXIO) in fan_pwm1_store()
8662 rc = -EINVAL; in fan_pwm1_store()
8675 /* sysfs fan fan1_input ------------------------------------------------ */
8696 /* sysfs fan fan2_input ------------------------------------------------ */
8717 /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
8729 return -EINVAL; in fan_watchdog_store()
8732 return -EPERM; in fan_watchdog_store()
8743 /* --------------------------------------------------------------------- */
8765 return attr->mode; in fan_attr_is_visible()
8787 #define TPACPI_FAN_NS 0x0010 /* For EC with non-Standard register addresses */
8814 TPACPI_Q_LNV3('R', '1', 'D', TPACPI_FAN_NS), /* 11e Gen5 GL-R */
8815 TPACPI_Q_LNV3('R', '0', 'V', TPACPI_FAN_NS), /* 11e Gen5 KL-Y */
8852 return -ENODEV; in fan_init()
8856 pr_info("ECFW with non-standard fan reg control found\n"); in fan_init()
8876 /* all other ThinkPads: note that even old-style in fan_init()
8892 /* It responded - so let's assume it's there */ in fan_init()
8898 /* Fan not auto-detected */ in fan_init()
8912 return -ENODEV; in fan_init()
8917 /* 570, 770x-JL */ in fan_init()
8968 return -ENODEV; in fan_init()
9123 seq_printf(m, " (<level> is 0-7)\n"); in fan_read()
9127 seq_printf(m, " (<level> is 0-7, auto, disengaged, full-speed)\n"); in fan_read()
9134 "commands:\twatchdog <timeout> (<timeout> is 0 (off), 1-120 (seconds))\n"); in fan_read()
9137 seq_printf(m, "commands:\tspeed <speed> (<speed> is 0-65535)\n"); in fan_read()
9148 else if (strstarts(cmd, "level disengaged") || strstarts(cmd, "level full-speed")) in fan_write_cmd_level()
9154 if (*rc == -ENXIO) in fan_write_cmd_level()
9170 if (*rc == -ENXIO) in fan_write_cmd_enable()
9185 if (*rc == -ENXIO) in fan_write_cmd_disable()
9205 if (*rc == -ENXIO) in fan_write_cmd_speed()
9223 *rc = -EINVAL; in fan_write_cmd_watchdog()
9249 rc = -EINVAL; in fan_write()
9297 if (ACPI_FAILURE(acpi_get_handle(hkey_handle, t->name, &temp))) { in mute_led_on_off()
9298 pr_warn("Thinkpad ACPI has no %s interface.\n", t->name); in mute_led_on_off()
9299 return -EIO; in mute_led_on_off()
9302 if (!acpi_evalf(hkey_handle, &output, t->name, "dd", in mute_led_on_off()
9303 state ? t->on_value : t->off_value)) in mute_led_on_off()
9304 return -EIO; in mute_led_on_off()
9306 t->state = state; in mute_led_on_off()
9315 if (t->state < 0 || t->state == on) in tpacpi_led_set()
9316 return t->state; in tpacpi_led_set()
9337 .default_trigger = "audio-mute",
9343 .default_trigger = "audio-micmute",
9354 if (ACPI_FAILURE(acpi_get_handle(hkey_handle, t->name, &temp))) { in mute_led_init()
9355 t->state = -ENODEV; in mute_led_init()
9359 err = led_classdev_register(&tpacpi_pdev->dev, &mute_led_cdev[i]); in mute_led_init()
9361 while (i--) in mute_led_init()
9385 if (t->state >= 0) in mute_led_resume()
9386 mute_led_on_off(t, t->state); in mute_led_resume()
9475 return -ENODEV; in tpacpi_battery_get()
9482 return -ENODEV; in tpacpi_battery_get()
9496 return -ENODEV; in tpacpi_battery_get()
9502 return -ENODEV; in tpacpi_battery_get()
9508 return -EINVAL; in tpacpi_battery_get()
9517 /* The battery ID is in bits 8-9, 2 bits */ in tpacpi_battery_set()
9525 return -ENODEV; in tpacpi_battery_set()
9531 return -ENODEV; in tpacpi_battery_set()
9537 * battery ID is in bits 8-9, 2 bits. in tpacpi_battery_set()
9541 return -ENODEV; in tpacpi_battery_set()
9548 * The battery ID is in bits 4-5, 2 bits, in tpacpi_battery_set()
9549 * the effective time is in bits 8-23, 2 bytes. in tpacpi_battery_set()
9557 return -ENODEV; in tpacpi_battery_set()
9562 return -EINVAL; in tpacpi_battery_set()
9590 return -EIO; in tpacpi_battery_set_validate()
9613 return -ENODEV; in tpacpi_battery_probe()
9622 return -ENODEV; in tpacpi_battery_probe()
9626 return -ENODEV; in tpacpi_battery_probe()
9632 return -ENODEV; in tpacpi_battery_probe()
9638 return -ENODEV; in tpacpi_battery_probe()
9642 return -ENODEV; in tpacpi_battery_probe()
9648 return -ENODEV; in tpacpi_battery_probe()
9658 return -ENODEV; in tpacpi_battery_probe()
9719 battery = tpacpi_battery_get_id(supply->desc->name); in tpacpi_battery_store()
9730 return -ENODEV; in tpacpi_battery_store()
9733 return -EINVAL; in tpacpi_battery_store()
9735 return -EINVAL; in tpacpi_battery_store()
9737 return -ENODEV; in tpacpi_battery_store()
9743 return -ENODEV; in tpacpi_battery_store()
9746 return -EINVAL; in tpacpi_battery_store()
9748 return -EINVAL; in tpacpi_battery_store()
9758 return -EINVAL; in tpacpi_battery_store()
9762 return -EINVAL; in tpacpi_battery_store()
9786 battery = tpacpi_battery_get_id(supply->desc->name); in tpacpi_battery_show()
9790 return -ENODEV; in tpacpi_battery_show()
9817 battery = tpacpi_battery_get_id(supply->desc->name); in charge_behaviour_show()
9822 return -ENODEV; in charge_behaviour_show()
9831 return -ENODEV; in charge_behaviour_show()
9864 battery = tpacpi_battery_get_id(supply->desc->name); in charge_behaviour_store()
9896 return -EINVAL; in charge_behaviour_store()
9933 int batteryid = tpacpi_battery_get_id(battery->desc->name); in tpacpi_battery_add()
9936 return -ENODEV; in tpacpi_battery_add()
9937 if (device_add_groups(&battery->dev, tpacpi_battery_groups)) in tpacpi_battery_add()
9938 return -ENODEV; in tpacpi_battery_add()
9944 device_remove_groups(&battery->dev, tpacpi_battery_groups); in tpacpi_battery_remove()
10005 if (WARN_ON(!mutex_is_locked(&priv->lock))) in lcdshadow_set_sw_state()
10006 return -EIO; in lcdshadow_set_sw_state()
10009 return -EIO; in lcdshadow_set_sw_state()
10011 priv->hw_state = priv->sw_state = state; in lcdshadow_set_sw_state()
10022 priv->hw_state = priv->sw_state = output & 0x1; in lcdshadow_get_hw_state()
10041 return -EIO; in tpacpi_lcdshadow_init()
10046 lcdshadow_dev = drm_privacy_screen_register(&tpacpi_pdev->dev, in tpacpi_lcdshadow_init()
10064 mutex_lock(&lcdshadow_dev->lock); in lcdshadow_resume()
10065 lcdshadow_set_sw_state(lcdshadow_dev, lcdshadow_dev->sw_state); in lcdshadow_resume()
10066 mutex_unlock(&lcdshadow_dev->lock); in lcdshadow_resume()
10074 seq_printf(m, "status:\t\t%d\n", lcdshadow_dev->hw_state); in lcdshadow_read()
10084 int res, state = -EINVAL; in lcdshadow_write()
10087 return -ENODEV; in lcdshadow_write()
10096 return -EINVAL; in lcdshadow_write()
10098 mutex_lock(&lcdshadow_dev->lock); in lcdshadow_write()
10100 mutex_unlock(&lcdshadow_dev->lock); in lcdshadow_write()
10119 #define DYTC_CMD_QUERY 0 /* To get DYTC status - enable/revision */
10120 #define DYTC_QUERY_ENABLE_BIT 8 /* Bit 8 - 0 = disabled, 1 = enabled */
10121 #define DYTC_QUERY_SUBREV_BIT 16 /* Bits 16 - 27 - sub revision */
10122 #define DYTC_QUERY_REV_BIT 28 /* Bits 28 - 31 - revision */
10142 return -ENODEV; in dytc_command()
10145 return -EIO; in dytc_command()
10170 return -ENODEV; in palmsensor_get()
10172 return -EIO; in palmsensor_get()
10190 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, "dytc_lapmode"); in lapsensor_refresh()
10206 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, "palmsensor"); in palmsensor_refresh()
10252 return attr->mode; in proxsensor_attr_is_visible()
10266 /* If support isn't available for both devices return -ENODEV */ in tpacpi_proxsensor_init()
10267 if ((palm_err == -ENODEV) && (lap_err == -ENODEV)) in tpacpi_proxsensor_init()
10268 return -ENODEV; in tpacpi_proxsensor_init()
10270 if (palm_err && (palm_err != -ENODEV)) in tpacpi_proxsensor_init()
10272 if (lap_err && (lap_err != -ENODEV)) in tpacpi_proxsensor_init()
10279 .name = "proximity-sensor",
10295 #define DYTC_GET_FUNCTION_BIT 8 /* Bits 8-11 - function setting */
10296 #define DYTC_GET_MODE_BIT 12 /* Bits 12-15 - mode setting */
10298 #define DYTC_SET_FUNCTION_BIT 12 /* Bits 12-15 - function setting */
10299 #define DYTC_SET_MODE_BIT 16 /* Bits 16-19 - mode setting */
10300 #define DYTC_SET_VALID_BIT 20 /* Bit 20 - 1 = on, 0 = off */
10320 #define DYTC_ERR_MASK 0xF /* Bits 0-3 in cmd result are the error result */
10357 return -EINVAL; in convert_dytc_to_profile()
10372 return -EINVAL; in convert_dytc_to_profile()
10382 return -EOPNOTSUPP; in convert_dytc_to_profile()
10409 return -EOPNOTSUPP; in convert_profile_to_dytc()
10433 return -ENODEV; in dytc_control_amt()
10450 * Helper function - check if we are in CQL mode and if we are
10451 * - disable CQL,
10452 * - run the command
10453 * - enable CQL
10512 * Note we still need to disable CQL mode before hand and re-enable in dytc_profile_set()
10535 /* Success - update current profile */ in dytc_profile_set()
10560 err = -ENODEV; in dytc_profile_refresh()
10597 return -ENODEV; in tpacpi_dytc_profile_init()
10607 case -1: in tpacpi_dytc_profile_init()
10635 return -ENODEV; in tpacpi_dytc_profile_init()
10648 return -ENODEV; in tpacpi_dytc_profile_init()
10666 .name = "dytc-profile",
10671 * Keyboard language interface
10688 {"fr-ch", 0x100c},
10708 return -ENODEV; in set_keyboard_lang_command()
10712 return -EIO; in set_keyboard_lang_command()
10724 return -ENODEV; in get_keyboard_lang()
10728 return -EIO; in get_keyboard_lang()
10732 * '(' and ')') keys which use layout dependent key-press emulation. in get_keyboard_lang()
10735 return -ENODEV; in get_keyboard_lang()
10742 /* sysfs keyboard language entry */
10792 dev_err(&tpacpi_pdev->dev, "Unknown Keyboard language. Ignoring\n"); in keyboard_lang_store()
10793 return -EINVAL; in keyboard_lang_store()
10796 tpacpi_disclose_usertask(attr->attr.name, in keyboard_lang_store()
10797 "keyboard language is set to %s\n", buf); in keyboard_lang_store()
10799 sysfs_notify(&tpacpi_pdev->dev.kobj, NULL, "keyboard_lang"); in keyboard_lang_store()
10813 return tp_features.kbd_lang ? attr->mode : 0; in kbdlang_attr_is_visible()
10850 return -ENODEV; in dprc_command()
10854 return -EIO; in dprc_command()
10862 return -ENODEV; in dprc_command()
10881 return -ENODEV; in get_wwan_antenna()
10897 return -ENODATA; in wwan_antenna_type_show()
10910 return has_antennatype ? attr->mode : 0; in dprc_attr_is_visible()
10938 * MAC Address Pass-through feature. In most cases, there are three
10960 return -ENODEV; in auxmac_init()
10964 if (obj->type != ACPI_TYPE_STRING || obj->string.length != AUXMAC_STRLEN) { in auxmac_init()
10965 pr_info("Invalid buffer for MAC address pass-through.\n"); in auxmac_init()
10969 if (obj->string.pointer[AUXMAC_BEGIN_MARKER] != '#' || in auxmac_init()
10970 obj->string.pointer[AUXMAC_END_MARKER] != '#') { in auxmac_init()
10971 pr_info("Invalid header for MAC address pass-through.\n"); in auxmac_init()
10975 if (strncmp(obj->string.pointer + AUXMAC_START, "XXXXXXXXXXXX", AUXMAC_LEN) != 0) in auxmac_init()
10976 strscpy(auxmac, obj->string.pointer + AUXMAC_START, sizeof(auxmac)); in auxmac_init()
10998 return auxmac[0] == 0 ? 0 : attr->mode; in auxmac_attr_is_visible()
11011 /* --------------------------------------------------------------------- */
11044 return attr->mode; in tpacpi_attr_is_visible()
11172 if (!atomic_add_unless(&dytc_ignore_event, -1, 0)) in tpacpi_driver_event()
11181 mutex_lock(&lcdshadow_dev->lock); in tpacpi_driver_event()
11182 old_hw_state = lcdshadow_dev->hw_state; in tpacpi_driver_event()
11184 changed = lcdshadow_dev->hw_state != old_hw_state; in tpacpi_driver_event()
11185 mutex_unlock(&lcdshadow_dev->lock); in tpacpi_driver_event()
11212 /* --------------------------------------------------------------------- */
11234 dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); in ibm_exit()
11236 list_del_init(&ibm->all_drivers); in ibm_exit()
11238 if (ibm->flags.acpi_notify_installed) { in ibm_exit()
11240 "%s: acpi_remove_notify_handler\n", ibm->name); in ibm_exit()
11241 BUG_ON(!ibm->acpi); in ibm_exit()
11242 acpi_remove_notify_handler(*ibm->acpi->handle, in ibm_exit()
11243 ibm->acpi->type, in ibm_exit()
11245 ibm->flags.acpi_notify_installed = 0; in ibm_exit()
11248 if (ibm->flags.proc_created) { in ibm_exit()
11250 "%s: remove_proc_entry\n", ibm->name); in ibm_exit()
11251 remove_proc_entry(ibm->name, proc_dir); in ibm_exit()
11252 ibm->flags.proc_created = 0; in ibm_exit()
11255 if (ibm->flags.acpi_driver_registered) { in ibm_exit()
11257 "%s: acpi_bus_unregister_driver\n", ibm->name); in ibm_exit()
11258 BUG_ON(!ibm->acpi); in ibm_exit()
11259 acpi_bus_unregister_driver(ibm->acpi->driver); in ibm_exit()
11260 kfree(ibm->acpi->driver); in ibm_exit()
11261 ibm->acpi->driver = NULL; in ibm_exit()
11262 ibm->flags.acpi_driver_registered = 0; in ibm_exit()
11265 if (ibm->flags.init_called && ibm->exit) { in ibm_exit()
11266 ibm->exit(); in ibm_exit()
11267 ibm->flags.init_called = 0; in ibm_exit()
11270 dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); in ibm_exit()
11276 struct ibm_struct *ibm = iibm->data; in ibm_init()
11281 INIT_LIST_HEAD(&ibm->all_drivers); in ibm_init()
11283 if (ibm->flags.experimental && !experimental) in ibm_init()
11287 "probing for %s\n", ibm->name); in ibm_init()
11289 if (iibm->init) { in ibm_init()
11290 ret = iibm->init(iibm); in ibm_init()
11291 if (ret > 0 || ret == -ENODEV) in ibm_init()
11296 ibm->flags.init_called = 1; in ibm_init()
11299 if (ibm->acpi) { in ibm_init()
11300 if (ibm->acpi->hid) { in ibm_init()
11306 if (ibm->acpi->notify) { in ibm_init()
11308 if (ret == -ENODEV) { in ibm_init()
11310 ibm->name); in ibm_init()
11320 "%s installed\n", ibm->name); in ibm_init()
11322 if (ibm->read) { in ibm_init()
11323 umode_t mode = iibm->base_procfs_mode; in ibm_init()
11327 if (ibm->write) in ibm_init()
11329 entry = proc_create_data(ibm->name, mode, proc_dir, in ibm_init()
11332 pr_err("unable to create proc entry %s\n", ibm->name); in ibm_init()
11333 ret = -ENODEV; in ibm_init()
11336 ibm->flags.proc_created = 1; in ibm_init()
11339 list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); in ibm_init()
11346 ibm->name, ret); in ibm_init()
11369 * Ancient 570/600 and -SL lacks (#.##c) in tpacpi_parse_fw_id()
11394 * ThinkPad Embedded Controller Program Table on newer models in find_new_ec_fwstr()
11397 * ---------------------------------------------------- in find_new_ec_fwstr()
11410 if (dm->type != 140 || dm->length < 0x0F || in find_new_ec_fwstr()
11421 /* returns 0 - probe ok, or < 0 - probe error.
11423 * On error, kfree() cleanup on tp->* is not performed, caller must do it */
11433 return -EINVAL; in get_thinkpad_model_data()
11438 tp->vendor = PCI_VENDOR_ID_IBM; in get_thinkpad_model_data()
11440 tp->vendor = PCI_VENDOR_ID_LENOVO; in get_thinkpad_model_data()
11445 tp->bios_version_str = kstrdup(s, GFP_KERNEL); in get_thinkpad_model_data()
11446 if (s && !tp->bios_version_str) in get_thinkpad_model_data()
11447 return -ENOMEM; in get_thinkpad_model_data()
11450 t = tpacpi_parse_fw_id(tp->bios_version_str, in get_thinkpad_model_data()
11451 &tp->bios_model, &tp->bios_release); in get_thinkpad_model_data()
11458 * up-to-date BIOS or they will not be detected. in get_thinkpad_model_data()
11463 if (sscanf(dev->name, in get_thinkpad_model_data()
11464 "IBM ThinkPad Embedded Controller -[%17c", in get_thinkpad_model_data()
11466 ec_fw_string[sizeof(ec_fw_string) - 1] = 0; in get_thinkpad_model_data()
11477 tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); in get_thinkpad_model_data()
11478 if (!tp->ec_version_str) in get_thinkpad_model_data()
11479 return -ENOMEM; in get_thinkpad_model_data()
11482 &tp->ec_model, &tp->ec_release); in get_thinkpad_model_data()
11492 tp->model_str = kstrdup(s, GFP_KERNEL); in get_thinkpad_model_data()
11493 if (!tp->model_str) in get_thinkpad_model_data()
11494 return -ENOMEM; in get_thinkpad_model_data()
11498 tp->model_str = kstrdup(s, GFP_KERNEL); in get_thinkpad_model_data()
11499 if (!tp->model_str) in get_thinkpad_model_data()
11500 return -ENOMEM; in get_thinkpad_model_data()
11505 tp->nummodel_str = kstrdup(s, GFP_KERNEL); in get_thinkpad_model_data()
11506 if (s && !tp->nummodel_str) in get_thinkpad_model_data()
11507 return -ENOMEM; in get_thinkpad_model_data()
11517 return -ENODEV; in probe_for_thinkpad()
11521 return -ENODEV; in probe_for_thinkpad()
11524 * Non-ancient models have better DMI tagging, but very old models in probe_for_thinkpad()
11536 return -ENODEV; in probe_for_thinkpad()
11540 return -ENODEV; in probe_for_thinkpad()
11673 if (!kp || !kp->name || !val) in set_ibm_param()
11674 return -EINVAL; in set_ibm_param()
11678 if (!ibm || !ibm->name) in set_ibm_param()
11681 if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { in set_ibm_param()
11682 if (strlen(val) > sizeof(ibms_init[i].param) - 1) in set_ibm_param()
11683 return -ENOSPC; in set_ibm_param()
11689 return -EINVAL; in set_ibm_param()
11694 "Enables experimental features when non-zero");
11697 MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
11701 "Attempts to load the driver even on a mis-identified ThinkPad when true");
11744 …MODULE_PARM_DESC(feature, "Simulates thinkpad-acpi procfs command at module load, see documentatio…
11784 MODULE_PARM_DESC(profile_force, "Force profile mode. -1=off, 1=MMC, 2=PSC");
11838 /* Driver-level probe */ in thinkpad_acpi_module_init()
11878 return -ENOMEM; in thinkpad_acpi_module_init()
11885 return -ENODEV; in thinkpad_acpi_module_init()
11890 tp_features.quirks = dmi_id->driver_data; in thinkpad_acpi_module_init()
11917 return -ENOMEM; in thinkpad_acpi_module_init()
11920 tpacpi_inputdev->name = "ThinkPad Extra Buttons"; in thinkpad_acpi_module_init()
11921 tpacpi_inputdev->phys = TPACPI_DRVR_NAME "/input0"; in thinkpad_acpi_module_init()
11922 tpacpi_inputdev->id.bustype = BUS_HOST; in thinkpad_acpi_module_init()
11923 tpacpi_inputdev->id.vendor = thinkpad_id.vendor; in thinkpad_acpi_module_init()
11924 tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; in thinkpad_acpi_module_init()
11925 tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; in thinkpad_acpi_module_init()
11926 tpacpi_inputdev->dev.parent = &tpacpi_pdev->dev; in thinkpad_acpi_module_init()
11936 ret = ibms_init[i].data->write(ibms_init[i].param); in thinkpad_acpi_module_init()
11962 &tpacpi_sensors_pdev->dev, TPACPI_NAME, NULL, tpacpi_hwmon_groups); in thinkpad_acpi_module_init()