* [PATCH v2] applesmc: Cleanups on top of re-work comms
@ 2020-11-12 22:38 Brad Campbell
2020-11-13 1:17 ` Guenter Roeck
0 siblings, 1 reply; 2+ messages in thread
From: Brad Campbell @ 2020-11-12 22:38 UTC (permalink / raw)
To: linux-hwmon
A couple of small cleanups on top of the comms changes for applesmc.c :
send_byte() is always called with APPLESMC_CMD_PORT.
Consolidate writing length with other setup parameters.
Consolidate read and write error messages to a single statement each.
Suggested-by: Henrik Rydberg <rydberg@bitmath.org>
Signed-off-by: Brad Campbell <brad@fnarfbargle.com>
---
Changelog :
v1 : Initial cleanup
v2 : Re-work to suit smc-comms rework v6
Index: linux-stable/drivers/hwmon/applesmc.c
===================================================================
--- linux-stable.orig/drivers/hwmon/applesmc.c
+++ linux-stable/drivers/hwmon/applesmc.c
@@ -182,7 +182,7 @@ static int wait_status(u8 val, u8 mask)
/* send_byte - Write to SMC data port. Callers must hold applesmc_lock. */
-static int send_byte(u8 cmd, u16 port)
+static int send_byte(u8 cmd)
{
int status;
@@ -199,7 +199,7 @@ static int send_byte(u8 cmd, u16 port)
if (status)
return status;
- outb(cmd, port);
+ outb(cmd, APPLESMC_DATA_PORT);
return 0;
}
@@ -240,7 +240,7 @@ static int send_argument(const char *key
int i;
for (i = 0; i < 4; i++)
- if (send_byte(key[i], APPLESMC_DATA_PORT))
+ if (send_byte(key[i]))
return -EIO;
return 0;
}
@@ -255,23 +255,13 @@ static int read_smc(u8 cmd, const char *
if (ret)
return ret;
- if (send_command(cmd) || send_argument(key)) {
- pr_warn("%.4s: read arg fail\n", key);
- return -EIO;
- }
-
- /* This has no effect on newer (2012) SMCs */
- if (send_byte(len, APPLESMC_DATA_PORT)) {
- pr_warn("%.4s: read len fail\n", key);
- return -EIO;
- }
+ if (send_command(cmd) || send_argument(key) || send_byte(len))
+ goto err;
for (i = 0; i < len; i++) {
if (wait_status(SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY,
- SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY)) {
- pr_warn("%.4s: read data[%d] fail\n", key, i);
- return -EIO;
- }
+ SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY))
+ goto err;
buffer[i] = inb(APPLESMC_DATA_PORT);
}
@@ -287,6 +277,9 @@ static int read_smc(u8 cmd, const char *
pr_warn("flushed %d bytes, last value is: %d\n", i, data);
return wait_status(0, SMC_STATUS_BUSY);
+err:
+ pr_warn("read cmd fail: %x %.4s %d\n", cmd, key, len);
+ return -EIO;
}
static int write_smc(u8 cmd, const char *key, const u8 *buffer, u8 len)
@@ -298,24 +291,17 @@ static int write_smc(u8 cmd, const char
if (ret)
return ret;
- if (send_command(cmd) || send_argument(key)) {
- pr_warn("%s: write arg fail\n", key);
- return -EIO;
- }
-
- if (send_byte(len, APPLESMC_DATA_PORT)) {
- pr_warn("%.4s: write len fail\n", key);
- return -EIO;
- }
+ if (send_command(cmd) || send_argument(key) || send_byte(len))
+ goto err;
- for (i = 0; i < len; i++) {
- if (send_byte(buffer[i], APPLESMC_DATA_PORT)) {
- pr_warn("%s: write data fail\n", key);
- return -EIO;
- }
- }
+ for (i = 0; i < len; i++)
+ if (send_byte(buffer[i]))
+ goto err;
return wait_status(0, SMC_STATUS_BUSY);
+err:
+ pr_warn("write cmd fail: %x %.4s %d\n", cmd, key, len);
+ return -EIO;
}
static int read_register_count(unsigned int *count)
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH v2] applesmc: Cleanups on top of re-work comms
2020-11-12 22:38 [PATCH v2] applesmc: Cleanups on top of re-work comms Brad Campbell
@ 2020-11-13 1:17 ` Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2020-11-13 1:17 UTC (permalink / raw)
To: Brad Campbell; +Cc: linux-hwmon
On Fri, Nov 13, 2020 at 09:38:07AM +1100, Brad Campbell wrote:
> A couple of small cleanups on top of the comms changes for applesmc.c :
>
> send_byte() is always called with APPLESMC_CMD_PORT.
> Consolidate writing length with other setup parameters.
> Consolidate read and write error messages to a single statement each.
>
> Suggested-by: Henrik Rydberg <rydberg@bitmath.org>
> Signed-off-by: Brad Campbell <brad@fnarfbargle.com>
Changes are ok with me. Can I get some Reviewed-by: / Tested-by: tags ?
Thanks,
Guenter
> ---
> Changelog :
> v1 : Initial cleanup
> v2 : Re-work to suit smc-comms rework v6
>
> Index: linux-stable/drivers/hwmon/applesmc.c
> ===================================================================
> --- linux-stable.orig/drivers/hwmon/applesmc.c
> +++ linux-stable/drivers/hwmon/applesmc.c
> @@ -182,7 +182,7 @@ static int wait_status(u8 val, u8 mask)
>
> /* send_byte - Write to SMC data port. Callers must hold applesmc_lock. */
>
> -static int send_byte(u8 cmd, u16 port)
> +static int send_byte(u8 cmd)
> {
> int status;
>
> @@ -199,7 +199,7 @@ static int send_byte(u8 cmd, u16 port)
> if (status)
> return status;
>
> - outb(cmd, port);
> + outb(cmd, APPLESMC_DATA_PORT);
> return 0;
> }
>
> @@ -240,7 +240,7 @@ static int send_argument(const char *key
> int i;
>
> for (i = 0; i < 4; i++)
> - if (send_byte(key[i], APPLESMC_DATA_PORT))
> + if (send_byte(key[i]))
> return -EIO;
> return 0;
> }
> @@ -255,23 +255,13 @@ static int read_smc(u8 cmd, const char *
> if (ret)
> return ret;
>
> - if (send_command(cmd) || send_argument(key)) {
> - pr_warn("%.4s: read arg fail\n", key);
> - return -EIO;
> - }
> -
> - /* This has no effect on newer (2012) SMCs */
> - if (send_byte(len, APPLESMC_DATA_PORT)) {
> - pr_warn("%.4s: read len fail\n", key);
> - return -EIO;
> - }
> + if (send_command(cmd) || send_argument(key) || send_byte(len))
> + goto err;
>
> for (i = 0; i < len; i++) {
> if (wait_status(SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY,
> - SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY)) {
> - pr_warn("%.4s: read data[%d] fail\n", key, i);
> - return -EIO;
> - }
> + SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY))
> + goto err;
> buffer[i] = inb(APPLESMC_DATA_PORT);
> }
>
> @@ -287,6 +277,9 @@ static int read_smc(u8 cmd, const char *
> pr_warn("flushed %d bytes, last value is: %d\n", i, data);
>
> return wait_status(0, SMC_STATUS_BUSY);
> +err:
> + pr_warn("read cmd fail: %x %.4s %d\n", cmd, key, len);
> + return -EIO;
> }
>
> static int write_smc(u8 cmd, const char *key, const u8 *buffer, u8 len)
> @@ -298,24 +291,17 @@ static int write_smc(u8 cmd, const char
> if (ret)
> return ret;
>
> - if (send_command(cmd) || send_argument(key)) {
> - pr_warn("%s: write arg fail\n", key);
> - return -EIO;
> - }
> -
> - if (send_byte(len, APPLESMC_DATA_PORT)) {
> - pr_warn("%.4s: write len fail\n", key);
> - return -EIO;
> - }
> + if (send_command(cmd) || send_argument(key) || send_byte(len))
> + goto err;
>
> - for (i = 0; i < len; i++) {
> - if (send_byte(buffer[i], APPLESMC_DATA_PORT)) {
> - pr_warn("%s: write data fail\n", key);
> - return -EIO;
> - }
> - }
> + for (i = 0; i < len; i++)
> + if (send_byte(buffer[i]))
> + goto err;
>
> return wait_status(0, SMC_STATUS_BUSY);
> +err:
> + pr_warn("write cmd fail: %x %.4s %d\n", cmd, key, len);
> + return -EIO;
> }
>
> static int read_register_count(unsigned int *count)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-11-13 1:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-12 22:38 [PATCH v2] applesmc: Cleanups on top of re-work comms Brad Campbell
2020-11-13 1:17 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox