public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-hwmon@vger.kernel.org
Cc: linux@roeck-us.net, samsagax@gmail.com,
	linux-kernel@vger.kernel.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 1/3] hwmon: (oxp-sensors): remove static board variable
Date: Tue,  4 Jul 2023 14:17:17 +0100	[thread overview]
Message-ID: <20230704131715.44454-6-gregkh@linuxfoundation.org> (raw)
In-Reply-To: <20230704131715.44454-5-gregkh@linuxfoundation.org>

Drivers should not have a single static variable for the type of device
they are bound to.  While this driver is really going to only have one
device at a time in the system, remove the static variable and instead,
look up the device type when needed.

Cc: Joaquín Ignacio Aramendía <samsagax@gmail.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: linux-hwmon@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/hwmon/oxp-sensors.c | 47 ++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c
index e1a907cae820..3bcba0c476c4 100644
--- a/drivers/hwmon/oxp-sensors.c
+++ b/drivers/hwmon/oxp-sensors.c
@@ -48,10 +48,9 @@ enum oxp_board {
 	oxp_mini_amd,
 	oxp_mini_amd_a07,
 	oxp_mini_amd_pro,
+	UNKNOWN,
 };
 
-static enum oxp_board board;
-
 /* Fan reading and PWM */
 #define OXP_SENSOR_FAN_REG		0x76 /* Fan reading is 2 registers long */
 #define OXP_SENSOR_PWM_ENABLE_REG	0x4A /* PWM enable is 1 register long */
@@ -136,6 +135,24 @@ static const struct dmi_system_id dmi_table[] = {
 	{},
 };
 
+static enum oxp_board get_board_type(void)
+{
+	const struct dmi_system_id *dmi_entry;
+
+	/*
+	 * Have to check for AMD processor here because DMI strings are the
+	 * same between Intel and AMD boards, the only way to tell them apart
+	 * is the CPU.
+	 * Intel boards seem to have different EC registers and values to
+	 * read/write.
+	 */
+	dmi_entry = dmi_first_match(dmi_table);
+	if (!dmi_entry || boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
+		return UNKNOWN;
+
+	return (enum oxp_board)(unsigned long)dmi_entry->driver_data;
+}
+
 /* Helper functions to handle EC read/write */
 static int read_from_ec(u8 reg, int size, long *val)
 {
@@ -182,7 +199,7 @@ static int tt_toggle_enable(void)
 	u8 reg;
 	u8 val;
 
-	switch (board) {
+	switch (get_board_type()) {
 	case oxp_mini_amd_a07:
 		reg = OXP_OLD_TURBO_SWITCH_REG;
 		val = OXP_OLD_TURBO_TAKE_VAL;
@@ -203,7 +220,7 @@ static int tt_toggle_disable(void)
 	u8 reg;
 	u8 val;
 
-	switch (board) {
+	switch (get_board_type()) {
 	case oxp_mini_amd_a07:
 		reg = OXP_OLD_TURBO_SWITCH_REG;
 		val = OXP_OLD_TURBO_RETURN_VAL;
@@ -249,7 +266,7 @@ static ssize_t tt_toggle_show(struct device *dev,
 	u8 reg;
 	long val;
 
-	switch (board) {
+	switch (get_board_type()) {
 	case oxp_mini_amd_a07:
 		reg = OXP_OLD_TURBO_SWITCH_REG;
 		break;
@@ -315,7 +332,7 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
 			ret = read_from_ec(OXP_SENSOR_PWM_REG, 1, val);
 			if (ret)
 				return ret;
-			switch (board) {
+			switch (get_board_type()) {
 			case aya_neo_2:
 			case aya_neo_air:
 			case aya_neo_air_pro:
@@ -357,7 +374,7 @@ static int oxp_platform_write(struct device *dev, enum hwmon_sensor_types type,
 		case hwmon_pwm_input:
 			if (val < 0 || val > 255)
 				return -EINVAL;
-			switch (board) {
+			switch (get_board_type()) {
 			case aya_neo_2:
 			case aya_neo_air:
 			case aya_neo_air_pro:
@@ -412,25 +429,11 @@ static const struct hwmon_chip_info oxp_ec_chip_info = {
 /* Initialization logic */
 static int oxp_platform_probe(struct platform_device *pdev)
 {
-	const struct dmi_system_id *dmi_entry;
 	struct device *dev = &pdev->dev;
 	struct device *hwdev;
 	int ret;
 
-	/*
-	 * Have to check for AMD processor here because DMI strings are the
-	 * same between Intel and AMD boards, the only way to tell them apart
-	 * is the CPU.
-	 * Intel boards seem to have different EC registers and values to
-	 * read/write.
-	 */
-	dmi_entry = dmi_first_match(dmi_table);
-	if (!dmi_entry || boot_cpu_data.x86_vendor != X86_VENDOR_AMD)
-		return -ENODEV;
-
-	board = (enum oxp_board)(unsigned long)dmi_entry->driver_data;
-
-	switch (board) {
+	switch (get_board_type()) {
 	case aok_zoe_a1:
 	case oxp_mini_amd_a07:
 	case oxp_mini_amd_pro:
-- 
2.41.0


  reply	other threads:[~2023-07-04 13:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-04 13:17 [PATCH 0/3] driver core: remove final user of devm_device_add_groups() Greg Kroah-Hartman
2023-07-04 13:17 ` Greg Kroah-Hartman [this message]
2023-07-04 13:39   ` [PATCH 1/3] hwmon: (oxp-sensors): remove static board variable Guenter Roeck
2023-07-04 13:44     ` Greg Kroah-Hartman
2023-07-04 14:14       ` Guenter Roeck
2023-07-04 16:14         ` Greg Kroah-Hartman
2023-07-04 16:43           ` Guenter Roeck
2023-07-04 16:52             ` Greg Kroah-Hartman
2023-07-04 19:44     ` Joaquin Aramendia
2023-07-04 13:17 ` [PATCH 2/3] hwmon: (oxp-sensors): move to use dev_groups from platform device Greg Kroah-Hartman
2023-07-04 13:17 ` [PATCH 3/3] driver core: remove devm_device_add_groups() Greg Kroah-Hartman
2023-07-04 16:05   ` Rafael J. Wysocki
2023-07-05 18:50   ` Dmitry Torokhov

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=20230704131715.44454-6-gregkh@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=samsagax@gmail.com \
    /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: link
Be 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