LKML Archive on lore.kernel.org help / color / mirror / Atom feed
From: Denis Pauk <pauk.denis@gmail.com> To: unlisted-recipients:; (no To-header on input) Cc: eugene.shalygin@gmail.com, andy.shevchenko@gmail.com, pauk.denis@gmail.com, platform-driver-x86@vger.kernel.org, thomas@weissschuh.net, Guenter Roeck <linux@roeck-us.net>, Jean Delvare <jdelvare@suse.com>, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] hwmon: (nct6775) Implement custom lock by ACPI mutex. Date: Mon, 22 Nov 2021 23:28:49 +0200 [thread overview] Message-ID: <20211122212850.321542-3-pauk.denis@gmail.com> (raw) In-Reply-To: <20211122212850.321542-1-pauk.denis@gmail.com> Use ACPI lock when board has separate lock for monitoring IO. BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=204807 Signed-off-by: Denis Pauk <pauk.denis@gmail.com> --- drivers/hwmon/nct6775.c | 46 +++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c index 049c42ea66bb..3aeb32093c35 100644 --- a/drivers/hwmon/nct6775.c +++ b/drivers/hwmon/nct6775.c @@ -140,6 +140,7 @@ struct nct6775_sio_data { int ld; enum kinds kind; enum sensor_access access; + acpi_handle acpi_wmi_mutex; /* superio_() callbacks */ void (*sio_outb)(struct nct6775_sio_data *sio_data, int reg, int val); @@ -155,6 +156,7 @@ struct nct6775_sio_data { #define ASUSWMI_METHODID_RHWM 0x5248574D #define ASUSWMI_METHODID_WHWM 0x5748574D #define ASUSWMI_UNSUPPORTED_METHOD 0xFFFFFFFE +#define ASUSWMI_DELAY_MSEC_LOCK 500 /* Wait 0.5 s max. to get the lock */ static int nct6775_asuswmi_evaluate_method(u32 method_id, u8 bank, u8 reg, u8 val, u32 *retval) { @@ -1243,7 +1245,9 @@ struct nct6775_data { unsigned int (*fan_from_reg)(u16 reg, unsigned int divreg); unsigned int (*fan_from_reg_min)(u16 reg, unsigned int divreg); - struct mutex update_lock; + struct mutex update_lock; /* non ACPI lock */ + acpi_handle acpi_wmi_mutex; /* ACPI lock */ + bool valid; /* true if following fields are valid */ unsigned long last_updated; /* In jiffies */ @@ -1563,6 +1567,20 @@ static int nct6775_wmi_write_value(struct nct6775_data *data, u16 reg, u16 value return res; } +static int nct6775_wmi_lock(struct nct6775_data *data) +{ + if (ACPI_FAILURE(acpi_acquire_mutex(data->acpi_wmi_mutex, NULL, ASUSWMI_DELAY_MSEC_LOCK))) + return -EIO; + + return 0; +} + +static void nct6775_wmi_unlock(struct nct6775_data *data, struct device *dev) +{ + if (ACPI_FAILURE(acpi_release_mutex(data->acpi_wmi_mutex, NULL))) + dev_err(dev, "Failed to release mutex."); +} + /* * On older chips, only registers 0x50-0x5f are banked. * On more recent chips, all registers are banked. @@ -4051,6 +4069,7 @@ static int nct6775_probe(struct platform_device *pdev) data->kind = sio_data->kind; data->sioreg = sio_data->sioreg; + data->acpi_wmi_mutex = sio_data->acpi_wmi_mutex; if (sio_data->access == access_direct) { data->addr = res->start; @@ -4061,9 +4080,14 @@ static int nct6775_probe(struct platform_device *pdev) data->write_value = nct6775_wmi_write_value; } - mutex_init(&data->update_lock); - data->lock = nct6775_lock; - data->unlock = nct6775_unlock; + if (data->acpi_wmi_mutex) { + data->lock = nct6775_wmi_lock; + data->unlock = nct6775_wmi_unlock; + } else { + mutex_init(&data->update_lock); + data->lock = nct6775_lock; + data->unlock = nct6775_unlock; + } data->name = nct6775_device_names[data->kind]; data->bank = 0xff; /* Force initial bank selection */ @@ -5114,6 +5138,7 @@ static int __init sensors_nct6775_init(void) int sioaddr[2] = { 0x2e, 0x4e }; enum sensor_access access = access_direct; const char *board_vendor, *board_name; + acpi_handle acpi_wmi_mutex = NULL; u8 tmp; err = platform_driver_register(&nct6775_driver); @@ -5159,6 +5184,7 @@ static int __init sensors_nct6775_init(void) found = true; sio_data.access = access; + sio_data.acpi_wmi_mutex = acpi_wmi_mutex; if (access == access_asuswmi) { sio_data.sio_outb = superio_wmi_outb; @@ -5186,11 +5212,13 @@ static int __init sensors_nct6775_init(void) res.end = address + IOREGION_OFFSET + IOREGION_LENGTH - 1; res.flags = IORESOURCE_IO; - err = acpi_check_resource_conflict(&res); - if (err) { - platform_device_put(pdev[i]); - pdev[i] = NULL; - continue; + if (!acpi_wmi_mutex) { + err = acpi_check_resource_conflict(&res); + if (err) { + platform_device_put(pdev[i]); + pdev[i] = NULL; + continue; + } } err = platform_device_add_resources(pdev[i], &res, 1); -- 2.33.0
next prev parent reply other threads:[~2021-11-22 21:29 UTC|newest] Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-11-22 21:28 [PATCH 0/3] hwmon: (nct6775) Support lock by ACPI mutex Denis Pauk 2021-11-22 21:28 ` [PATCH 1/3] hwmon: (nct6775) Use nct6775_*() lock function pointers in nct6775_data Denis Pauk 2021-11-24 16:03 ` Andy Shevchenko 2021-11-25 21:07 ` Denis Pauk 2021-11-25 21:50 ` Andy Shevchenko 2021-11-22 21:28 ` Denis Pauk [this message] 2021-11-24 16:10 ` [PATCH 2/3] hwmon: (nct6775) Implement custom lock by ACPI mutex Andy Shevchenko 2021-11-25 13:14 ` Eugene Shalygin 2021-11-25 13:16 ` Eugene Shalygin 2021-11-25 13:51 ` Guenter Roeck 2021-11-25 13:54 ` Eugene Shalygin 2021-11-25 13:51 ` Andy Shevchenko 2021-11-25 14:00 ` Eugene Shalygin 2021-11-25 19:54 ` Guenter Roeck 2021-11-25 20:05 ` Eugene Shalygin 2021-11-25 20:09 ` Andy Shevchenko 2021-11-25 20:25 ` Denis Pauk 2021-11-25 20:33 ` Eugene Shalygin 2021-11-25 21:52 ` Andy Shevchenko 2021-11-25 20:28 ` Eugene Shalygin 2021-11-22 21:28 ` [PATCH 3/3] hwmon: (nct6775) add MAXIMUS VII HERO Denis Pauk 2021-11-24 16:21 ` Andy Shevchenko 2021-11-24 16:24 ` Andy Shevchenko
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211122212850.321542-3-pauk.denis@gmail.com \ --to=pauk.denis@gmail.com \ --cc=andy.shevchenko@gmail.com \ --cc=eugene.shalygin@gmail.com \ --cc=jdelvare@suse.com \ --cc=linux-hwmon@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux@roeck-us.net \ --cc=platform-driver-x86@vger.kernel.org \ --cc=thomas@weissschuh.net \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).