From patchwork Sun Feb 5 20:54:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 52932 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1926598wrn; Sun, 5 Feb 2023 13:11:06 -0800 (PST) X-Google-Smtp-Source: AK7set/9jfOmI+QrNOAdbvclCFpWKEZw2bFsuHZq/DoNm89Ze2Rg4y4ZQ5aAB93vaC+BiRgsy5VH X-Received: by 2002:a05:6a20:8b9e:b0:b8:c6ec:a269 with SMTP id m30-20020a056a208b9e00b000b8c6eca269mr16711769pzh.16.1675631466661; Sun, 05 Feb 2023 13:11:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675631466; cv=none; d=google.com; s=arc-20160816; b=xhztLlH29atVOvrT7HiIiZplxleGgBVPFvkDcb7IY8il2wF1mg/5hLnUhDq12WCCIr 55JAODbniIJvxjkAhx/cVYId0PhC1j4bQSmtPBaSh6SGQtZh6jITPII7NbnM2fb0BfS8 z+vFRhCfqKe9qvWJZ2iRra9dMgYwKSVR9MMwSycKlMNeI7Trb+Ba0VPWOLCDhRHJssIx w0XO8olnVUtZvrPzk0ULULNyMahNWQLLIyrYhZU+nHAn16hDo10wIQAcGC8hvUx+kMF4 0EUPeMguO+fi2Dib42zvZeF8yneGT457AhJ1laHRghpq0826W+Q/9ABhxI9TI3cracYW O2yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=77J2lvndWTd7idsNNCSgN68zvJg9VwsfgYbO1mesOIw=; b=aFTOJocNwWO5QeM8NU75q08Mksc4C0yIWU4g5ZIbFaohUX4Gv7SRE85ggU9El9jE79 lk0tYRTBbsjKRhAOaPerNFgFqPHBTDrLBpyLyuxYY7cR4HoiMhhMsrD+sGRTWLpEx6nj 7kbFd4uhgI9Sj3axwwA/rY+bwRYnLwk+VoogBovkbt5eb0Ag3+jwQcUbv6Mal/SPjaRQ qCnsTdp2oklzz6+e4xQMV9DOaZzANAy46kiyk+aoROaUsb7Tybmcp8VINMTjpmplSXn5 ZbD2H8SqZ07aFTt8FKfq8iWBg2VcIxf+BF+UE4Cb8JHzllERZWwxf59S9/TBEfAnurSJ ILwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=cCc6RgCH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n23-20020a637217000000b004789f4ef89fsi9060465pgc.875.2023.02.05.13.10.54; Sun, 05 Feb 2023 13:11:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=cCc6RgCH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229612AbjBEUze (ORCPT + 99 others); Sun, 5 Feb 2023 15:55:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbjBEUz2 (ORCPT ); Sun, 5 Feb 2023 15:55:28 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43E171A4A5; Sun, 5 Feb 2023 12:55:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1675630503; bh=TfEIy4ay6/gN2mOR2Z5uRGyIBcdpAjZ0kCFdCDcg6bk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=cCc6RgCHcNoMAaQd4loNXkPvReNl2+qRGDEdBkYIooG3j9T9t8FcDWAql6PhtxajG 5AE3+UgMPdKRiK7beSbPqNkMb/mvRgmwwC6xgWR5ZiBg4oMqRDVZdkChUz7MCgdjNu tdLvM58d4WkOu3D6J/4496N9VxTVW+bbq5lBV90Xd7D/zpEWG3yGOk1iB0m72Q6W3k OzQHkWkJYwsUP5wM8eMsIvVutA0XrRs7A4QW9OY9oQzs7sou1IrRaf/EGwBadEQrjA rS8Dhne12n71la9xbSiLM/N867gkk7srt8OWaVtsh3GeoT0pr4j4OlzPhT3on/kQ5V q0gJ7XOhnkRcw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M9o21-1pUWfa2DnJ-005tir; Sun, 05 Feb 2023 21:55:03 +0100 From: Armin Wolf To: hdegoede@redhat.com, markgross@kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] platform/x86: dell-ddv: Add hwmon support Date: Sun, 5 Feb 2023 21:54:55 +0100 Message-Id: <20230205205456.2364-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230205205456.2364-1-W_Armin@gmx.de> References: <20230205205456.2364-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:2Z0o1//M2vG+qJOwT4u3VZ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+tJaEmyV+Hx/h8eFasn7i6Pe1JOjkrBKwa0N14AKHHnYv9h5+c1Tj29JGatl jUFbTZvghxz7BOYtc4Ee3J0TDdNZ99i/tZVDA7xGcPBuFFfFEsGx3YNaReu59nVqgpsVDHyUY SAEcztF2fG2RupkvvE69jj+gGSw= X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757026940734970029?= X-GMAIL-MSGID: =?utf-8?q?1757026940734970029?= Thanks to bugreport 216655 on bugzilla triggered by the dell-smm-hwmon driver, the contents of the sensor buffers could be almost completely decoded. Add an hwmon interface for exposing the fan and thermal sensor values. Since the WMI interface can be quite slow on some machines, the sensor buffers are cached for 1 second to lessen the performance impact. The debugfs interface remains in place to aid in reverse-engineering of unknown sensor types and the thermal buffer. Tested-by: AntonĂ­n Skala Tested-by: Gustavo Walbon Signed-off-by: Armin Wolf Reviewed-by: Hans de Goede --- drivers/platform/x86/dell/Kconfig | 8 +- drivers/platform/x86/dell/dell-wmi-ddv.c | 492 ++++++++++++++++++++++- 2 files changed, 495 insertions(+), 5 deletions(-) -- 2.30.2 diff --git a/drivers/platform/x86/dell/Kconfig b/drivers/platform/x86/dell/Kconfig index d319de8f2132..bdd78076b1d7 100644 --- a/drivers/platform/x86/dell/Kconfig +++ b/drivers/platform/x86/dell/Kconfig @@ -192,12 +192,12 @@ config DELL_WMI_DESCRIPTOR config DELL_WMI_DDV tristate "Dell WMI sensors Support" default m - depends on ACPI_BATTERY depends on ACPI_WMI + depends on ACPI_BATTERY || HWMON help - This option adds support for WMI-based sensors like - battery temperature sensors found on some Dell notebooks. - It also supports reading of the battery ePPID. + This option adds support for WMI-based fan and thermal sensors + found on some Dell notebooks. It also supports various WMI-based battery + extras like reading of the battery temperature and ePPID. To compile this drivers as a module, choose M here: the module will be called dell-wmi-ddv. diff --git a/drivers/platform/x86/dell/dell-wmi-ddv.c b/drivers/platform/x86/dell/dell-wmi-ddv.c index 9695bf493ea6..b7ac483eff12 100644 --- a/drivers/platform/x86/dell/dell-wmi-ddv.c +++ b/drivers/platform/x86/dell/dell-wmi-ddv.c @@ -12,19 +12,26 @@ #include #include #include +#include #include +#include #include #include +#include #include +#include #include #include #include #include #include +#include #include #include +#include + #define DRIVER_NAME "dell-wmi-ddv" #define DELL_DDV_SUPPORTED_VERSION_MIN 2 @@ -63,13 +70,63 @@ enum dell_ddv_method { DELL_DDV_THERMAL_SENSOR_INFORMATION = 0x22, }; +struct fan_sensor_entry { + u8 type; + __le16 rpm; +} __packed; + +struct thermal_sensor_entry { + u8 type; + s8 now; + s8 min; + s8 max; + u8 unknown; +} __packed; + +struct combined_channel_info { + struct hwmon_channel_info info; + u32 config[]; +}; + +struct combined_chip_info { + struct hwmon_chip_info chip; + const struct hwmon_channel_info *info[]; +}; + +struct dell_wmi_ddv_sensors { + struct mutex lock; /* protect caching */ + unsigned long timestamp; + union acpi_object *obj; + u64 entries; +}; + struct dell_wmi_ddv_data { struct acpi_battery_hook hook; struct device_attribute temp_attr; struct device_attribute eppid_attr; + struct dell_wmi_ddv_sensors fans; + struct dell_wmi_ddv_sensors temps; struct wmi_device *wdev; }; +static const char * const fan_labels[] = { + "CPU Fan", + "Chassis Motherboard Fan", + "Video Fan", + "Power Supply Fan", + "Chipset Fan", + "Memory Fan", + "PCI Fan", + "HDD Fan", +}; + +static const char * const fan_dock_labels[] = { + "Docking Chassis/Motherboard Fan", + "Docking Video Fan", + "Docking Power Supply Fan", + "Docking Chipset Fan", +}; + static int dell_wmi_ddv_query_type(struct wmi_device *wdev, enum dell_ddv_method method, u32 arg, union acpi_object **result, acpi_object_type type) { @@ -171,6 +228,427 @@ static int dell_wmi_ddv_query_string(struct wmi_device *wdev, enum dell_ddv_meth return dell_wmi_ddv_query_type(wdev, method, arg, result, ACPI_TYPE_STRING); } +/* + * Needs to be called with lock held, except during initialization. + */ +static int dell_wmi_ddv_update_sensors(struct wmi_device *wdev, enum dell_ddv_method method, + struct dell_wmi_ddv_sensors *sensors, size_t entry_size) +{ + u64 buffer_size, rem, entries; + union acpi_object *obj; + u8 *buffer; + int ret; + + if (sensors->obj) { + if (time_before(jiffies, sensors->timestamp + HZ)) + return 0; + + kfree(sensors->obj); + sensors->obj = NULL; + } + + ret = dell_wmi_ddv_query_buffer(wdev, method, 0, &obj); + if (ret < 0) + return ret; + + /* buffer format sanity check */ + buffer_size = obj->package.elements[0].integer.value; + buffer = obj->package.elements[1].buffer.pointer; + entries = div64_u64_rem(buffer_size, entry_size, &rem); + if (rem != 1 || buffer[buffer_size - 1] != 0xff) { + ret = -ENOMSG; + + goto err_free; + } + + if (!entries) { + ret = -ENODATA; + + goto err_free; + } + + sensors->obj = obj; + sensors->entries = entries; + sensors->timestamp = jiffies; + + return 0; + +err_free: + kfree(obj); + + return ret; +} + +static umode_t dell_wmi_ddv_is_visible(const void *drvdata, enum hwmon_sensor_types type, u32 attr, + int channel) +{ + return 0444; +} + +static int dell_wmi_ddv_fan_read_channel(struct dell_wmi_ddv_data *data, u32 attr, int channel, + long *val) +{ + struct fan_sensor_entry *entry; + int ret; + + ret = dell_wmi_ddv_update_sensors(data->wdev, DELL_DDV_FAN_SENSOR_INFORMATION, + &data->fans, sizeof(*entry)); + if (ret < 0) + return ret; + + if (channel >= data->fans.entries) + return -ENXIO; + + entry = (struct fan_sensor_entry *)data->fans.obj->package.elements[1].buffer.pointer; + switch (attr) { + case hwmon_fan_input: + *val = get_unaligned_le16(&entry[channel].rpm); + + return 0; + default: + break; + } + + return -EOPNOTSUPP; +} + +static int dell_wmi_ddv_temp_read_channel(struct dell_wmi_ddv_data *data, u32 attr, int channel, + long *val) +{ + struct thermal_sensor_entry *entry; + int ret; + + ret = dell_wmi_ddv_update_sensors(data->wdev, DELL_DDV_THERMAL_SENSOR_INFORMATION, + &data->temps, sizeof(*entry)); + if (ret < 0) + return ret; + + if (channel >= data->temps.entries) + return -ENXIO; + + entry = (struct thermal_sensor_entry *)data->temps.obj->package.elements[1].buffer.pointer; + switch (attr) { + case hwmon_temp_input: + *val = entry[channel].now * 1000; + + return 0; + case hwmon_temp_min: + *val = entry[channel].min * 1000; + + return 0; + case hwmon_temp_max: + *val = entry[channel].max * 1000; + + return 0; + default: + break; + } + + return -EOPNOTSUPP; +} + +static int dell_wmi_ddv_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, + int channel, long *val) +{ + struct dell_wmi_ddv_data *data = dev_get_drvdata(dev); + int ret; + + switch (type) { + case hwmon_fan: + mutex_lock(&data->fans.lock); + ret = dell_wmi_ddv_fan_read_channel(data, attr, channel, val); + mutex_unlock(&data->fans.lock); + + return ret; + case hwmon_temp: + mutex_lock(&data->temps.lock); + ret = dell_wmi_ddv_temp_read_channel(data, attr, channel, val); + mutex_unlock(&data->temps.lock); + + return ret; + default: + break; + } + + return -EOPNOTSUPP; +} + +static int dell_wmi_ddv_fan_read_string(struct dell_wmi_ddv_data *data, int channel, + const char **str) +{ + struct fan_sensor_entry *entry; + int ret; + u8 type; + + ret = dell_wmi_ddv_update_sensors(data->wdev, DELL_DDV_FAN_SENSOR_INFORMATION, + &data->fans, sizeof(*entry)); + if (ret < 0) + return ret; + + if (channel >= data->fans.entries) + return -ENXIO; + + entry = (struct fan_sensor_entry *)data->fans.obj->package.elements[1].buffer.pointer; + type = entry[channel].type; + switch (type) { + case 0x00 ... 0x07: + *str = fan_labels[type]; + + break; + case 0x11 ... 0x14: + *str = fan_dock_labels[type - 0x11]; + + break; + default: + *str = "Unknown Fan"; + + break; + } + + return 0; +} + +static int dell_wmi_ddv_temp_read_string(struct dell_wmi_ddv_data *data, int channel, + const char **str) +{ + struct thermal_sensor_entry *entry; + int ret; + + ret = dell_wmi_ddv_update_sensors(data->wdev, DELL_DDV_THERMAL_SENSOR_INFORMATION, + &data->temps, sizeof(*entry)); + if (ret < 0) + return ret; + + if (channel >= data->temps.entries) + return -ENXIO; + + entry = (struct thermal_sensor_entry *)data->temps.obj->package.elements[1].buffer.pointer; + switch (entry[channel].type) { + case 0x00: + *str = "CPU"; + + break; + case 0x11: + *str = "Video"; + + break; + case 0x22: + *str = "Memory"; /* sometimes called DIMM */ + + break; + case 0x33: + *str = "Other"; + + break; + case 0x44: + *str = "Ambient"; /* sometimes called SKIN */ + + break; + case 0x52: + *str = "SODIMM"; + + break; + case 0x55: + *str = "HDD"; + + break; + case 0x62: + *str = "SODIMM 2"; + + break; + case 0x73: + *str = "NB"; + + break; + case 0x83: + *str = "Charger"; + + break; + case 0xbb: + *str = "Memory 3"; + + break; + default: + *str = "Unknown"; + + break; + } + + return 0; +} + +static int dell_wmi_ddv_read_string(struct device *dev, enum hwmon_sensor_types type, u32 attr, + int channel, const char **str) +{ + struct dell_wmi_ddv_data *data = dev_get_drvdata(dev); + int ret; + + switch (type) { + case hwmon_fan: + switch (attr) { + case hwmon_fan_label: + mutex_lock(&data->fans.lock); + ret = dell_wmi_ddv_fan_read_string(data, channel, str); + mutex_unlock(&data->fans.lock); + + return ret; + default: + break; + } + break; + case hwmon_temp: + switch (attr) { + case hwmon_temp_label: + mutex_lock(&data->temps.lock); + ret = dell_wmi_ddv_temp_read_string(data, channel, str); + mutex_unlock(&data->temps.lock); + + return ret; + default: + break; + } + break; + default: + break; + } + + return -EOPNOTSUPP; +} + +static const struct hwmon_ops dell_wmi_ddv_ops = { + .is_visible = dell_wmi_ddv_is_visible, + .read = dell_wmi_ddv_read, + .read_string = dell_wmi_ddv_read_string, +}; + +static struct hwmon_channel_info *dell_wmi_ddv_channel_create(struct device *dev, u64 count, + enum hwmon_sensor_types type, + u32 config) +{ + struct combined_channel_info *cinfo; + int i; + + cinfo = devm_kzalloc(dev, struct_size(cinfo, config, count + 1), GFP_KERNEL); + if (!cinfo) + return ERR_PTR(-ENOMEM); + + cinfo->info.type = type; + cinfo->info.config = cinfo->config; + + for (i = 0; i < count; i++) + cinfo->config[i] = config; + + return &cinfo->info; +} + +static void dell_wmi_ddv_hwmon_cache_destroy(void *data) +{ + struct dell_wmi_ddv_sensors *sensors = data; + + mutex_destroy(&sensors->lock); + kfree(sensors->obj); +} + +static struct hwmon_channel_info *dell_wmi_ddv_channel_init(struct wmi_device *wdev, + enum dell_ddv_method method, + struct dell_wmi_ddv_sensors *sensors, + size_t entry_size, + enum hwmon_sensor_types type, + u32 config) +{ + struct hwmon_channel_info *info; + int ret; + + ret = dell_wmi_ddv_update_sensors(wdev, method, sensors, entry_size); + if (ret < 0) + return ERR_PTR(ret); + + mutex_init(&sensors->lock); + + ret = devm_add_action_or_reset(&wdev->dev, dell_wmi_ddv_hwmon_cache_destroy, sensors); + if (ret < 0) + return ERR_PTR(ret); + + info = dell_wmi_ddv_channel_create(&wdev->dev, sensors->entries, type, config); + if (IS_ERR(info)) + devm_release_action(&wdev->dev, dell_wmi_ddv_hwmon_cache_destroy, sensors); + + return info; +} + +static int dell_wmi_ddv_hwmon_add(struct dell_wmi_ddv_data *data) +{ + struct wmi_device *wdev = data->wdev; + struct combined_chip_info *cinfo; + struct hwmon_channel_info *info; + struct device *hdev; + int index = 0; + int ret; + + if (!devres_open_group(&wdev->dev, dell_wmi_ddv_hwmon_add, GFP_KERNEL)) + return -ENOMEM; + + cinfo = devm_kzalloc(&wdev->dev, struct_size(cinfo, info, 4), GFP_KERNEL); + if (!cinfo) { + ret = -ENOMEM; + + goto err_release; + } + + cinfo->chip.ops = &dell_wmi_ddv_ops; + cinfo->chip.info = cinfo->info; + + info = dell_wmi_ddv_channel_create(&wdev->dev, 1, hwmon_chip, HWMON_C_REGISTER_TZ); + if (IS_ERR(info)) { + ret = PTR_ERR(info); + + goto err_release; + } + + cinfo->info[index] = info; + index++; + + info = dell_wmi_ddv_channel_init(wdev, DELL_DDV_FAN_SENSOR_INFORMATION, &data->fans, + sizeof(struct fan_sensor_entry), hwmon_fan, + (HWMON_F_INPUT | HWMON_F_LABEL)); + if (!IS_ERR(info)) { + cinfo->info[index] = info; + index++; + } + + info = dell_wmi_ddv_channel_init(wdev, DELL_DDV_THERMAL_SENSOR_INFORMATION, &data->temps, + sizeof(struct thermal_sensor_entry), hwmon_temp, + (HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX | + HWMON_T_LABEL)); + if (!IS_ERR(info)) { + cinfo->info[index] = info; + index++; + } + + if (index < 2) { + ret = -ENODEV; + + goto err_release; + } + + hdev = devm_hwmon_device_register_with_info(&wdev->dev, "dell_ddv", data, &cinfo->chip, + NULL); + if (IS_ERR(hdev)) { + ret = PTR_ERR(hdev); + + goto err_release; + } + + devres_close_group(&wdev->dev, dell_wmi_ddv_hwmon_add); + + return 0; + +err_release: + devres_release_group(&wdev->dev, dell_wmi_ddv_hwmon_add); + + return ret; +} + static int dell_wmi_ddv_battery_index(struct acpi_device *acpi_dev, u32 *index) { const char *uid_str; @@ -370,7 +848,19 @@ static int dell_wmi_ddv_probe(struct wmi_device *wdev, const void *context) dell_wmi_ddv_debugfs_init(wdev); - return dell_wmi_ddv_battery_add(data); + if (IS_REACHABLE(CONFIG_ACPI_BATTERY)) { + ret = dell_wmi_ddv_battery_add(data); + if (ret < 0 && ret != -ENODEV) + dev_warn(&wdev->dev, "Unable to register ACPI battery hook: %d\n", ret); + } + + if (IS_REACHABLE(CONFIG_HWMON)) { + ret = dell_wmi_ddv_hwmon_add(data); + if (ret < 0 && ret != -ENODEV) + dev_warn(&wdev->dev, "Unable to register hwmon interface: %d\n", ret); + } + + return 0; } static const struct wmi_device_id dell_wmi_ddv_id_table[] = { From patchwork Sun Feb 5 20:54:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 52931 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1926479wrn; Sun, 5 Feb 2023 13:10:38 -0800 (PST) X-Google-Smtp-Source: AK7set9/TSvXG/kYO0sS5aigB7MErl64v0ec63ZRQWV5SZ2CpNocV/zaFk3n58KH1ppWk4cZNG9P X-Received: by 2002:a17:902:e5cb:b0:197:19f7:52b4 with SMTP id u11-20020a170902e5cb00b0019719f752b4mr22210977plf.42.1675631437829; Sun, 05 Feb 2023 13:10:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675631437; cv=none; d=google.com; s=arc-20160816; b=mWai4wL3Ue0BlFpAe4fH8CP2teC5Hzfijl4jzOHzXfO4oE7IjdL9olW7NcXFfyh4kB YpHLX23gpp9cYrHIictNcI3tnOoknvHuvwrgQHhZ0n2iU4ppcwUMP/NBukmItf6JNeXx AsWIst3vB5oMIdF/Wa3LYt042P0XNwJ2TNGUCLRwAqc7ZCOlp/W5oIvsv1sBDJNPDAy0 7jj+RluZ4JPaeXKMvrettJXGVBmJgOafFHNwYcXihc2dPIeDV0hgXkC/As1Cife+x3GL abd65TJ0gGuAQ1aIfdMWevLekNeTZ9el+X8iku9LFEXxkitROzClu5yDqxP40l2lGHMg d8VQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:ui-outboundreport:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5yOLIZ5AU4nRJ9cw9epblWyxfjjjFL8C0M7XEqmwvpw=; b=uF6w5IKpB8YewnvqzRQkyTxr1I3KMA1DgBmda7sqZPUtdXYrCf2YBcBlX7xpI2Xof8 vjmxJss1GqHA0PDmcHyZHxuxB6jMAVoeDtqEbgUFh8YLJvluxvXbJJr6nnnRTPdEU0ph EAIsBavr/ZymSrWB4IfWoqzIE93VlCk7BxnZKCOrWtexyJUgi0SClq9dsW46Q6aiu4/5 ViqO/I7RdpLnVYscVtTF245OOatWzH+QhbREZ8BTIxHLNtlVA4r6Lk2UJkg9wAL9K875 zyzThgoUuGFLHDBGztH4C1nGHvwIOWFWKn3cP16irg8DvZW9NyVP8V4ok2bpuqHFyskH QVYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=aRyZPOuf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j8-20020a170902690800b00198f1e1197bsi5234868plk.87.2023.02.05.13.10.26; Sun, 05 Feb 2023 13:10:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=aRyZPOuf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmx.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229606AbjBEUzc (ORCPT + 99 others); Sun, 5 Feb 2023 15:55:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229379AbjBEUza (ORCPT ); Sun, 5 Feb 2023 15:55:30 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26A241A977; Sun, 5 Feb 2023 12:55:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1675630507; bh=/T9/qsH+wQ6sC2+if7MuLmWQRgJz/xhs+XDj6+bYSB0=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=aRyZPOufPLa7cUz5uQeygdoBIHQ8xiVi3MUmImMf3OUMGDZNZOAS+Hlfhq6nlteu7 5O+vZy25DClU4kwjvnslxfIGpu2BX5Upxg9/+h1wJ0EznbHMC+EGyUYxE+K1eOpUI0 aDcqKDHTwIX3+2n5wyUchDe0mCo4sYQ6wyCf2Eo1RjG1y8tqkZh0kMEOSRxQcmz57F WmEl0o6B+VvAJVJrOYz0YEs/nLADCgOCQJgIbNANrOKD7ePdyxk0lFwfoAlqoMnXiP 4S+aFkm9bRrBkmPv/v0OCkr1pepkg+qtW5H9Z/F/z750mDsS3moKzY+N9lu4nm4V+O 2EIdDESf7tkGQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MZTmY-1p4VMS3kSE-00WSvv; Sun, 05 Feb 2023 21:55:06 +0100 From: Armin Wolf To: hdegoede@redhat.com, markgross@kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] platform/x86: dell-ddv: Prefer asynchronous probing Date: Sun, 5 Feb 2023 21:54:56 +0100 Message-Id: <20230205205456.2364-3-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230205205456.2364-1-W_Armin@gmx.de> References: <20230205205456.2364-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:NVV20JzFLnxYL1XOdNp19JGeQIG7PnYj7KJj/lUvzlx/krCzBAI FOODJLa6AkxfI3w2+F5x9Vj64HI4iL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T PW2/4m2ZOuMDaO6PFxLVuBPJBtOcdfZbStST3ivc87GSHta2RvlKhY5lJ3sFuz5aQSIltwvrm qN1snpJQS1Dhyf1Y1TY8CXIGLtk= X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757026910238561825?= X-GMAIL-MSGID: =?utf-8?q?1757026910238561825?= During probe, both sensor buffers need to be queried to initialize the hwmon channels. This might be slow on some machines, causing a unnecessary delay during boot. Mark the driver with PROBE_PREFER_ASYNCHRONOUS so that it can be probed asynchronously. Signed-off-by: Armin Wolf Reviewed-by: Hans de Goede --- drivers/platform/x86/dell/dell-wmi-ddv.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.30.2 diff --git a/drivers/platform/x86/dell/dell-wmi-ddv.c b/drivers/platform/x86/dell/dell-wmi-ddv.c index b7ac483eff12..cffbba5e2d9a 100644 --- a/drivers/platform/x86/dell/dell-wmi-ddv.c +++ b/drivers/platform/x86/dell/dell-wmi-ddv.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -872,6 +873,7 @@ MODULE_DEVICE_TABLE(wmi, dell_wmi_ddv_id_table); static struct wmi_driver dell_wmi_ddv_driver = { .driver = { .name = DRIVER_NAME, + .probe_type = PROBE_PREFER_ASYNCHRONOUS, }, .id_table = dell_wmi_ddv_id_table, .probe = dell_wmi_ddv_probe,