FILE
wmi-other.c
File preview with syntax highlighting.
linux-6.19.14/drivers/platform/x86/lenovo/wmi-other.c
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Lenovo Other Mode WMI interface driver. 4 * 5 * This driver uses the fw_attributes class to expose the various WMI functions 6 * provided by the "Other Mode" WMI interface. This enables CPU and GPU power 7 * limit as well as various other attributes for devices that fall under the 8 * "Gaming Series" of Lenovo laptop devices. Each attribute exposed by the 9 * "Other Mode" interface has a corresponding Capability Data struct that 10 * allows the driver to probe details about the attribute such as if it is 11 * supported by the hardware, the default_value, max_value, min_value, and step 12 * increment. 13 * 14 * These attributes typically don't fit anywhere else in the sysfs and are set 15 * in Windows using one of Lenovo's multiple user applications. 16 * 17 * Copyright (C) 2025 Derek J. Clark <derekjohn.clark@gmail.com> 18 */ 19 20#include <linux/acpi.h> 21#include <linux/bitfield.h> 22#include <linux/cleanup.h> 23#include <linux/component.h> 24#include <linux/container_of.h> 25#include <linux/device.h> 26#include <linux/export.h> 27#include <linux/gfp_types.h> 28#include <linux/idr.h> 29#include <linux/kdev_t.h> 30#include <linux/kobject.h> 31#include <linux/module.h> 32#include <linux/notifier.h> 33#include <linux/platform_profile.h> 34#include <linux/types.h> 35#include <linux/wmi.h> 36 37#include "wmi-capdata01.h" 38#include "wmi-events.h" 39#include "wmi-gamezone.h" 40#include "wmi-helpers.h" 41#include "wmi-other.h" 42#include "../firmware_attributes_class.h" 43 44#define LENOVO_OTHER_MODE_GUID "DC2A8805-3A8C-41BA-A6F7-092E0089CD3B" 45 46#define LWMI_DEVICE_ID_CPU 0x01 47 48#define LWMI_FEATURE_ID_CPU_SPPT 0x01 49#define LWMI_FEATURE_ID_CPU_SPL 0x02 50#define LWMI_FEATURE_ID_CPU_FPPT 0x03 51 52#define LWMI_TYPE_ID_NONE 0x00 53 54#define LWMI_FEATURE_VALUE_GET 17 55#define LWMI_FEATURE_VALUE_SET 18 56 57#define LWMI_ATTR_DEV_ID_MASK GENMASK(31, 24) 58#define LWMI_ATTR_FEAT_ID_MASK GENMASK(23, 16) 59#define LWMI_ATTR_MODE_ID_MASK GENMASK(15, 8) 60#define LWMI_ATTR_TYPE_ID_MASK GENMASK(7, 0) 61 62#define LWMI_OM_FW_ATTR_BASE_PATH "lenovo-wmi-other" 63 64static BLOCKING_NOTIFIER_HEAD(om_chain_head); 65static DEFINE_IDA(lwmi_om_ida); 66 67enum attribute_property { 68 DEFAULT_VAL, 69 MAX_VAL, 70 MIN_VAL, 71 STEP_VAL, 72 SUPPORTED, 73}; 74 75struct lwmi_om_priv { 76 struct component_master_ops *ops; 77 struct cd01_list *cd01_list; /* only valid after capdata01 bind */ 78 struct device *fw_attr_dev; 79 struct kset *fw_attr_kset; 80 struct notifier_block nb; 81 struct wmi_device *wdev; 82 int ida_id; 83}; 84 85struct tunable_attr_01 { 86 struct capdata01 *capdata; 87 struct device *dev; 88 u32 feature_id; 89 u32 device_id; 90 u32 type_id; 91}; 92 93static struct tunable_attr_01 ppt_pl1_spl = { 94 .device_id = LWMI_DEVICE_ID_CPU, 95 .feature_id = LWMI_FEATURE_ID_CPU_SPL, 96 .type_id = LWMI_TYPE_ID_NONE, 97}; 98 99static struct tunable_attr_01 ppt_pl2_sppt = { 100 .device_id = LWMI_DEVICE_ID_CPU, 101 .feature_id = LWMI_FEATURE_ID_CPU_SPPT, 102 .type_id = LWMI_TYPE_ID_NONE, 103}; 104 105static struct tunable_attr_01 ppt_pl3_fppt = { 106 .device_id = LWMI_DEVICE_ID_CPU, 107 .feature_id = LWMI_FEATURE_ID_CPU_FPPT, 108 .type_id = LWMI_TYPE_ID_NONE, 109}; 110 111struct capdata01_attr_group { 112 const struct attribute_group *attr_group; 113 struct tunable_attr_01 *tunable_attr; 114}; 115 116/** 117 * lwmi_om_register_notifier() - Add a notifier to the blocking notifier chain 118 * @nb: The notifier_block struct to register 119 * 120 * Call blocking_notifier_chain_register to register the notifier block to the 121 * lenovo-wmi-other driver notifier chain. 122 * 123 * Return: 0 on success, %-EEXIST on error. 124 */ 125int lwmi_om_register_notifier(struct notifier_block *nb) 126{ 127 return blocking_notifier_chain_register(&om_chain_head, nb); 128} 129EXPORT_SYMBOL_NS_GPL(lwmi_om_register_notifier, "LENOVO_WMI_OTHER"); 130 131/** 132 * lwmi_om_unregister_notifier() - Remove a notifier from the blocking notifier 133 * chain. 134 * @nb: The notifier_block struct to register 135 * 136 * Call blocking_notifier_chain_unregister to unregister the notifier block from the 137 * lenovo-wmi-other driver notifier chain. 138 * 139 * Return: 0 on success, %-ENOENT on error. 140 */ 141int lwmi_om_unregister_notifier(struct notifier_block *nb) 142{ 143 return blocking_notifier_chain_unregister(&om_chain_head, nb); 144} 145EXPORT_SYMBOL_NS_GPL(lwmi_om_unregister_notifier, "LENOVO_WMI_OTHER"); 146 147/** 148 * devm_lwmi_om_unregister_notifier() - Remove a notifier from the blocking 149 * notifier chain. 150 * @data: Void pointer to the notifier_block struct to register. 151 * 152 * Call lwmi_om_unregister_notifier to unregister the notifier block from the 153 * lenovo-wmi-other driver notifier chain. 154 * 155 * Return: 0 on success, %-ENOENT on error. 156 */ 157static void devm_lwmi_om_unregister_notifier(void *data) 158{ 159 struct notifier_block *nb = data; 160 161 lwmi_om_unregister_notifier(nb); 162} 163 164/** 165 * devm_lwmi_om_register_notifier() - Add a notifier to the blocking notifier 166 * chain. 167 * @dev: The parent device of the notifier_block struct. 168 * @nb: The notifier_block struct to register 169 * 170 * Call lwmi_om_register_notifier to register the notifier block to the 171 * lenovo-wmi-other driver notifier chain. Then add devm_lwmi_om_unregister_notifier 172 * as a device managed action to automatically unregister the notifier block 173 * upon parent device removal. 174 * 175 * Return: 0 on success, or an error code. 176 */ 177int devm_lwmi_om_register_notifier(struct device *dev, 178 struct notifier_block *nb) 179{ 180 int ret; 181 182 ret = lwmi_om_register_notifier(nb); 183 if (ret < 0) 184 return ret; 185 186 return devm_add_action_or_reset(dev, devm_lwmi_om_unregister_notifier, 187 nb); 188} 189EXPORT_SYMBOL_NS_GPL(devm_lwmi_om_register_notifier, "LENOVO_WMI_OTHER"); 190 191/** 192 * lwmi_om_notifier_call() - Call functions for the notifier call chain. 193 * @mode: Pointer to a thermal mode enum to retrieve the data from. 194 * 195 * Call blocking_notifier_call_chain to retrieve the thermal mode from the 196 * lenovo-wmi-gamezone driver. 197 * 198 * Return: 0 on success, or an error code. 199 */ 200static int lwmi_om_notifier_call(enum thermal_mode *mode) 201{ 202 int ret; 203 204 ret = blocking_notifier_call_chain(&om_chain_head, 205 LWMI_GZ_GET_THERMAL_MODE, &mode); 206 if ((ret & ~NOTIFY_STOP_MASK) != NOTIFY_OK) 207 return -EINVAL; 208 209 return 0; 210} 211 212/* Attribute Methods */ 213 214/** 215 * int_type_show() - Emit the data type for an integer attribute 216 * @kobj: Pointer to the driver object. 217 * @kattr: Pointer to the attribute calling this function. 218 * @buf: The buffer to write to. 219 * 220 * Return: Number of characters written to buf. 221 */ 222static ssize_t int_type_show(struct kobject *kobj, struct kobj_attribute *kattr, 223 char *buf) 224{ 225 return sysfs_emit(buf, "integer\n"); 226} 227 228/** 229 * attr_capdata01_show() - Get the value of the specified attribute property 230 * 231 * @kobj: Pointer to the driver object. 232 * @kattr: Pointer to the attribute calling this function. 233 * @buf: The buffer to write to. 234 * @tunable_attr: The attribute to be read. 235 * @prop: The property of this attribute to be read. 236 * 237 * Retrieves the given property from the capability data 01 struct for the 238 * specified attribute's "custom" thermal mode. This function is intended 239 * to be generic so it can be called from any integer attributes "_show" 240 * function. 241 * 242 * If the WMI is success the sysfs attribute is notified. 243 * 244 * Return: Either number of characters written to buf, or an error code. 245 */ 246static ssize_t attr_capdata01_show(struct kobject *kobj, 247 struct kobj_attribute *kattr, char *buf, 248 struct tunable_attr_01 *tunable_attr, 249 enum attribute_property prop) 250{ 251 struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev); 252 struct capdata01 capdata; 253 u32 attribute_id; 254 int value, ret; 255 256 attribute_id = 257 FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) | 258 FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) | 259 FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, 260 LWMI_GZ_THERMAL_MODE_CUSTOM) | 261 FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id); 262 263 ret = lwmi_cd01_get_data(priv->cd01_list, attribute_id, &capdata); 264 if (ret) 265 return ret; 266 267 switch (prop) { 268 case DEFAULT_VAL: 269 value = capdata.default_value; 270 break; 271 case MAX_VAL: 272 value = capdata.max_value; 273 break; 274 case MIN_VAL: 275 value = capdata.min_value; 276 break; 277 case STEP_VAL: 278 value = capdata.step; 279 break; 280 default: 281 return -EINVAL; 282 } 283 284 return sysfs_emit(buf, "%d\n", value); 285} 286 287/** 288 * attr_current_value_store() - Set the current value of the given attribute 289 * @kobj: Pointer to the driver object. 290 * @kattr: Pointer to the attribute calling this function. 291 * @buf: The buffer to read from, this is parsed to `int` type. 292 * @count: Required by sysfs attribute macros, pass in from the callee attr. 293 * @tunable_attr: The attribute to be stored. 294 * 295 * Sets the value of the given attribute when operating under the "custom" 296 * smartfan profile. The current smartfan profile is retrieved from the 297 * lenovo-wmi-gamezone driver and error is returned if the result is not 298 * "custom". This function is intended to be generic so it can be called from 299 * any integer attribute's "_store" function. The integer to be sent to the WMI 300 * method is range checked and an error code is returned if out of range. 301 * 302 * If the value is valid and WMI is success, then the sysfs attribute is 303 * notified. 304 * 305 * Return: Either count, or an error code. 306 */ 307static ssize_t attr_current_value_store(struct kobject *kobj, 308 struct kobj_attribute *kattr, 309 const char *buf, size_t count, 310 struct tunable_attr_01 *tunable_attr) 311{ 312 struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev); 313 struct wmi_method_args_32 args; 314 struct capdata01 capdata; 315 enum thermal_mode mode; 316 u32 attribute_id; 317 u32 value; 318 int ret; 319 320 ret = lwmi_om_notifier_call(&mode); 321 if (ret) 322 return ret; 323 324 if (mode != LWMI_GZ_THERMAL_MODE_CUSTOM) 325 return -EBUSY; 326 327 attribute_id = 328 FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) | 329 FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) | 330 FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode) | 331 FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id); 332 333 ret = lwmi_cd01_get_data(priv->cd01_list, attribute_id, &capdata); 334 if (ret) 335 return ret; 336 337 ret = kstrtouint(buf, 10, &value); 338 if (ret) 339 return ret; 340 341 if (value < capdata.min_value || value > capdata.max_value) 342 return -EINVAL; 343 344 args.arg0 = attribute_id; 345 args.arg1 = value; 346 347 ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_SET, 348 (unsigned char *)&args, sizeof(args), NULL); 349 if (ret) 350 return ret; 351 352 return count; 353}; 354 355/** 356 * attr_current_value_show() - Get the current value of the given attribute 357 * @kobj: Pointer to the driver object. 358 * @kattr: Pointer to the attribute calling this function. 359 * @buf: The buffer to write to. 360 * @tunable_attr: The attribute to be read. 361 * 362 * Retrieves the value of the given attribute for the current smartfan profile. 363 * The current smartfan profile is retrieved from the lenovo-wmi-gamezone driver. 364 * This function is intended to be generic so it can be called from any integer 365 * attribute's "_show" function. 366 * 367 * If the WMI is success the sysfs attribute is notified. 368 * 369 * Return: Either number of characters written to buf, or an error code. 370 */ 371static ssize_t attr_current_value_show(struct kobject *kobj, 372 struct kobj_attribute *kattr, char *buf, 373 struct tunable_attr_01 *tunable_attr) 374{ 375 struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev); 376 struct wmi_method_args_32 args; 377 enum thermal_mode mode; 378 u32 attribute_id; 379 int retval; 380 int ret; 381 382 ret = lwmi_om_notifier_call(&mode); 383 if (ret) 384 return ret; 385 386 attribute_id = 387 FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) | 388 FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) | 389 FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode) | 390 FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id); 391 392 args.arg0 = attribute_id; 393 394 ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_GET, 395 (unsigned char *)&args, sizeof(args), 396 &retval); 397 if (ret) 398 return ret; 399 400 return sysfs_emit(buf, "%d\n", retval); 401} 402 403/* Lenovo WMI Other Mode Attribute macros */ 404#define __LWMI_ATTR_RO(_func, _name) \ 405 { \ 406 .attr = { .name = __stringify(_name), .mode = 0444 }, \ 407 .show = _func##_##_name##_show, \ 408 } 409 410#define __LWMI_ATTR_RO_AS(_name, _show) \ 411 { \ 412 .attr = { .name = __stringify(_name), .mode = 0444 }, \ 413 .show = _show, \ 414 } 415 416#define __LWMI_ATTR_RW(_func, _name) \ 417 __ATTR(_name, 0644, _func##_##_name##_show, _func##_##_name##_store) 418 419/* Shows a formatted static variable */ 420#define __LWMI_ATTR_SHOW_FMT(_prop, _attrname, _fmt, _val) \ 421 static ssize_t _attrname##_##_prop##_show( \ 422 struct kobject *kobj, struct kobj_attribute *kattr, char *buf) \ 423 { \ 424 return sysfs_emit(buf, _fmt, _val); \ 425 } \ 426 static struct kobj_attribute attr_##_attrname##_##_prop = \ 427 __LWMI_ATTR_RO(_attrname, _prop) 428 429/* Attribute current value read/write */ 430#define __LWMI_TUNABLE_CURRENT_VALUE_CAP01(_attrname) \ 431 static ssize_t _attrname##_current_value_store( \ 432 struct kobject *kobj, struct kobj_attribute *kattr, \ 433 const char *buf, size_t count) \ 434 { \ 435 return attr_current_value_store(kobj, kattr, buf, count, \ 436 &_attrname); \ 437 } \ 438 static ssize_t _attrname##_current_value_show( \ 439 struct kobject *kobj, struct kobj_attribute *kattr, char *buf) \ 440 { \ 441 return attr_current_value_show(kobj, kattr, buf, &_attrname); \ 442 } \ 443 static struct kobj_attribute attr_##_attrname##_current_value = \ 444 __LWMI_ATTR_RW(_attrname, current_value) 445 446/* Attribute property read only */ 447#define __LWMI_TUNABLE_RO_CAP01(_prop, _attrname, _prop_type) \ 448 static ssize_t _attrname##_##_prop##_show( \ 449 struct kobject *kobj, struct kobj_attribute *kattr, char *buf) \ 450 { \ 451 return attr_capdata01_show(kobj, kattr, buf, &_attrname, \ 452 _prop_type); \ 453 } \ 454 static struct kobj_attribute attr_##_attrname##_##_prop = \ 455 __LWMI_ATTR_RO(_attrname, _prop) 456 457#define LWMI_ATTR_GROUP_TUNABLE_CAP01(_attrname, _fsname, _dispname) \ 458 __LWMI_TUNABLE_CURRENT_VALUE_CAP01(_attrname); \ 459 __LWMI_TUNABLE_RO_CAP01(default_value, _attrname, DEFAULT_VAL); \ 460 __LWMI_ATTR_SHOW_FMT(display_name, _attrname, "%s\n", _dispname); \ 461 __LWMI_TUNABLE_RO_CAP01(max_value, _attrname, MAX_VAL); \ 462 __LWMI_TUNABLE_RO_CAP01(min_value, _attrname, MIN_VAL); \ 463 __LWMI_TUNABLE_RO_CAP01(scalar_increment, _attrname, STEP_VAL); \ 464 static struct kobj_attribute attr_##_attrname##_type = \ 465 __LWMI_ATTR_RO_AS(type, int_type_show); \ 466 static struct attribute *_attrname##_attrs[] = { \ 467 &attr_##_attrname##_current_value.attr, \ 468 &attr_##_attrname##_default_value.attr, \ 469 &attr_##_attrname##_display_name.attr, \ 470 &attr_##_attrname##_max_value.attr, \ 471 &attr_##_attrname##_min_value.attr, \ 472 &attr_##_attrname##_scalar_increment.attr, \ 473 &attr_##_attrname##_type.attr, \ 474 NULL, \ 475 }; \ 476 static const struct attribute_group _attrname##_attr_group = { \ 477 .name = _fsname, .attrs = _attrname##_attrs \ 478 } 479 480LWMI_ATTR_GROUP_TUNABLE_CAP01(ppt_pl1_spl, "ppt_pl1_spl", 481 "Set the CPU sustained power limit"); 482LWMI_ATTR_GROUP_TUNABLE_CAP01(ppt_pl2_sppt, "ppt_pl2_sppt", 483 "Set the CPU slow package power tracking limit"); 484LWMI_ATTR_GROUP_TUNABLE_CAP01(ppt_pl3_fppt, "ppt_pl3_fppt", 485 "Set the CPU fast package power tracking limit"); 486 487static struct capdata01_attr_group cd01_attr_groups[] = { 488 { &ppt_pl1_spl_attr_group, &ppt_pl1_spl }, 489 { &ppt_pl2_sppt_attr_group, &ppt_pl2_sppt }, 490 { &ppt_pl3_fppt_attr_group, &ppt_pl3_fppt }, 491 {}, 492}; 493 494/** 495 * lwmi_om_fw_attr_add() - Register all firmware_attributes_class members 496 * @priv: The Other Mode driver data. 497 * 498 * Return: Either 0, or an error code. 499 */ 500static int lwmi_om_fw_attr_add(struct lwmi_om_priv *priv) 501{ 502 unsigned int i; 503 int err; 504 505 priv->ida_id = ida_alloc(&lwmi_om_ida, GFP_KERNEL); 506 if (priv->ida_id < 0) 507 return priv->ida_id; 508 509 priv->fw_attr_dev = device_create(&firmware_attributes_class, NULL, 510 MKDEV(0, 0), NULL, "%s-%u", 511 LWMI_OM_FW_ATTR_BASE_PATH, 512 priv->ida_id); 513 if (IS_ERR(priv->fw_attr_dev)) { 514 err = PTR_ERR(priv->fw_attr_dev); 515 goto err_free_ida; 516 } 517 518 priv->fw_attr_kset = kset_create_and_add("attributes", NULL, 519 &priv->fw_attr_dev->kobj); 520 if (!priv->fw_attr_kset) { 521 err = -ENOMEM; 522 goto err_destroy_classdev; 523 } 524 525 for (i = 0; i < ARRAY_SIZE(cd01_attr_groups) - 1; i++) { 526 err = sysfs_create_group(&priv->fw_attr_kset->kobj, 527 cd01_attr_groups[i].attr_group); 528 if (err) 529 goto err_remove_groups; 530 531 cd01_attr_groups[i].tunable_attr->dev = &priv->wdev->dev; 532 } 533 return 0; 534 535err_remove_groups: 536 while (i--) 537 sysfs_remove_group(&priv->fw_attr_kset->kobj, 538 cd01_attr_groups[i].attr_group); 539 540 kset_unregister(priv->fw_attr_kset); 541 542err_destroy_classdev: 543 device_unregister(priv->fw_attr_dev); 544 545err_free_ida: 546 ida_free(&lwmi_om_ida, priv->ida_id); 547 return err; 548} 549 550/** 551 * lwmi_om_fw_attr_remove() - Unregister all capability data attribute groups 552 * @priv: the lenovo-wmi-other driver data. 553 */ 554static void lwmi_om_fw_attr_remove(struct lwmi_om_priv *priv) 555{ 556 for (unsigned int i = 0; i < ARRAY_SIZE(cd01_attr_groups) - 1; i++) 557 sysfs_remove_group(&priv->fw_attr_kset->kobj, 558 cd01_attr_groups[i].attr_group); 559 560 kset_unregister(priv->fw_attr_kset); 561 device_unregister(priv->fw_attr_dev); 562} 563 564/** 565 * lwmi_om_master_bind() - Bind all components of the other mode driver 566 * @dev: The lenovo-wmi-other driver basic device. 567 * 568 * Call component_bind_all to bind the lenovo-wmi-capdata01 driver to the 569 * lenovo-wmi-other master driver. On success, assign the capability data 01 570 * list pointer to the driver data struct for later access. This pointer 571 * is only valid while the capdata01 interface exists. Finally, register all 572 * firmware attribute groups. 573 * 574 * Return: 0 on success, or an error code. 575 */ 576static int lwmi_om_master_bind(struct device *dev) 577{ 578 struct lwmi_om_priv *priv = dev_get_drvdata(dev); 579 struct cd01_list *tmp_list; 580 int ret; 581 582 ret = component_bind_all(dev, &tmp_list); 583 if (ret) 584 return ret; 585 586 priv->cd01_list = tmp_list; 587 if (!priv->cd01_list) 588 return -ENODEV; 589 590 return lwmi_om_fw_attr_add(priv); 591} 592 593/** 594 * lwmi_om_master_unbind() - Unbind all components of the other mode driver 595 * @dev: The lenovo-wmi-other driver basic device 596 * 597 * Unregister all capability data attribute groups. Then call 598 * component_unbind_all to unbind the lenovo-wmi-capdata01 driver from the 599 * lenovo-wmi-other master driver. Finally, free the IDA for this device. 600 */ 601static void lwmi_om_master_unbind(struct device *dev) 602{ 603 struct lwmi_om_priv *priv = dev_get_drvdata(dev); 604 605 lwmi_om_fw_attr_remove(priv); 606 component_unbind_all(dev, NULL); 607} 608 609static const struct component_master_ops lwmi_om_master_ops = { 610 .bind = lwmi_om_master_bind, 611 .unbind = lwmi_om_master_unbind, 612}; 613 614static int lwmi_other_probe(struct wmi_device *wdev, const void *context) 615{ 616 struct component_match *master_match = NULL; 617 struct lwmi_om_priv *priv; 618 619 priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL); 620 if (!priv) 621 return -ENOMEM; 622 623 priv->wdev = wdev; 624 dev_set_drvdata(&wdev->dev, priv); 625 626 component_match_add(&wdev->dev, &master_match, lwmi_cd01_match, NULL); 627 if (IS_ERR(master_match)) 628 return PTR_ERR(master_match); 629 630 return component_master_add_with_match(&wdev->dev, &lwmi_om_master_ops, 631 master_match); 632} 633 634static void lwmi_other_remove(struct wmi_device *wdev) 635{ 636 struct lwmi_om_priv *priv = dev_get_drvdata(&wdev->dev); 637 638 component_master_del(&wdev->dev, &lwmi_om_master_ops); 639 ida_free(&lwmi_om_ida, priv->ida_id); 640} 641 642static const struct wmi_device_id lwmi_other_id_table[] = { 643 { LENOVO_OTHER_MODE_GUID, NULL }, 644 {} 645}; 646 647static struct wmi_driver lwmi_other_driver = { 648 .driver = { 649 .name = "lenovo_wmi_other", 650 .probe_type = PROBE_PREFER_ASYNCHRONOUS, 651 }, 652 .id_table = lwmi_other_id_table, 653 .probe = lwmi_other_probe, 654 .remove = lwmi_other_remove, 655 .no_singleton = true, 656}; 657 658module_wmi_driver(lwmi_other_driver); 659 660MODULE_IMPORT_NS("LENOVO_WMI_CD01"); 661MODULE_IMPORT_NS("LENOVO_WMI_HELPERS"); 662MODULE_DEVICE_TABLE(wmi, lwmi_other_id_table); 663MODULE_AUTHOR("Derek J. Clark <derekjohn.clark@gmail.com>"); 664MODULE_DESCRIPTION("Lenovo Other Mode WMI Driver"); 665MODULE_LICENSE("GPL");
~/
Read-only file preview.