From: Hans de Goede <hdegoede@redhat.com>
To: Mark Gross <mgross@linux.intel.com>,
Andy Shevchenko <andy@kernel.org>,
Linus Walleij <linus.walleij@linaro.org>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Daniel Scally <djrscally@gmail.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Hans de Goede <hdegoede@redhat.com>,
platform-driver-x86@vger.kernel.org, linux-gpio@vger.kernel.org,
Kate Hsuan <hpa@redhat.com>,
Mark Pearson <markpearson@lenovo.com>,
Andy Yeh <andy.yeh@intel.com>, Hao Yao <hao.yao@intel.com>,
linux-media@vger.kernel.org
Subject: [PATCH v6 2/5] platform/x86: int3472/discrete: Refactor GPIO to sensor mapping
Date: Fri, 27 Jan 2023 21:37:26 +0100 [thread overview]
Message-ID: <20230127203729.10205-3-hdegoede@redhat.com> (raw)
In-Reply-To: <20230127203729.10205-1-hdegoede@redhat.com>
Add a helper function to map the type returned by the _DSM
method to a function name + the default polarity for that function.
And fold the INT3472_GPIO_TYPE_RESET and INT3472_GPIO_TYPE_POWERDOWN
cases into a single generic case.
This is a preparation patch for further GPIO mapping changes.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Changes in v3:
- Add break to default case
Changes in v2:
- Make the helper function doing the type -> function mapping,
also return a default polarity for the function.
---
drivers/platform/x86/intel/int3472/discrete.c | 45 +++++++++++++++----
1 file changed, 36 insertions(+), 9 deletions(-)
diff --git a/drivers/platform/x86/intel/int3472/discrete.c b/drivers/platform/x86/intel/int3472/discrete.c
index c42c3faa2c32..708d51f9b41d 100644
--- a/drivers/platform/x86/intel/int3472/discrete.c
+++ b/drivers/platform/x86/intel/int3472/discrete.c
@@ -188,6 +188,36 @@ static int skl_int3472_map_gpio_to_clk(struct int3472_discrete_device *int3472,
return 0;
}
+static void int3472_get_func_and_polarity(u8 type, const char **func, u32 *polarity)
+{
+ switch (type) {
+ case INT3472_GPIO_TYPE_RESET:
+ *func = "reset";
+ *polarity = GPIO_ACTIVE_LOW;
+ break;
+ case INT3472_GPIO_TYPE_POWERDOWN:
+ *func = "powerdown";
+ *polarity = GPIO_ACTIVE_LOW;
+ break;
+ case INT3472_GPIO_TYPE_CLK_ENABLE:
+ *func = "clk-enable";
+ *polarity = GPIO_ACTIVE_HIGH;
+ break;
+ case INT3472_GPIO_TYPE_PRIVACY_LED:
+ *func = "privacy-led";
+ *polarity = GPIO_ACTIVE_HIGH;
+ break;
+ case INT3472_GPIO_TYPE_POWER_ENABLE:
+ *func = "power-enable";
+ *polarity = GPIO_ACTIVE_HIGH;
+ break;
+ default:
+ *func = "unknown";
+ *polarity = GPIO_ACTIVE_HIGH;
+ break;
+ }
+}
+
/**
* skl_int3472_handle_gpio_resources: Map PMIC resources to consuming sensor
* @ares: A pointer to a &struct acpi_resource
@@ -227,6 +257,8 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
struct acpi_resource_gpio *agpio;
union acpi_object *obj;
const char *err_msg;
+ const char *func;
+ u32 polarity;
int ret;
u8 type;
@@ -250,19 +282,14 @@ static int skl_int3472_handle_gpio_resources(struct acpi_resource *ares,
type = obj->integer.value & 0xff;
+ int3472_get_func_and_polarity(type, &func, &polarity);
+
switch (type) {
case INT3472_GPIO_TYPE_RESET:
- ret = skl_int3472_map_gpio_to_sensor(int3472, agpio, "reset",
- GPIO_ACTIVE_LOW);
- if (ret)
- err_msg = "Failed to map reset pin to sensor\n";
-
- break;
case INT3472_GPIO_TYPE_POWERDOWN:
- ret = skl_int3472_map_gpio_to_sensor(int3472, agpio, "powerdown",
- GPIO_ACTIVE_LOW);
+ ret = skl_int3472_map_gpio_to_sensor(int3472, agpio, func, polarity);
if (ret)
- err_msg = "Failed to map powerdown pin to sensor\n";
+ err_msg = "Failed to map GPIO pin to sensor\n";
break;
case INT3472_GPIO_TYPE_CLK_ENABLE:
--
2.39.1
next prev parent reply other threads:[~2023-01-27 20:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-27 20:37 [PATCH v6 0/5] int3472/media privacy LED support Hans de Goede
2023-01-27 20:37 ` [PATCH v6 1/5] media: v4l2-core: Make the v4l2-core code enable/disable the privacy LED if present Hans de Goede
2023-01-28 7:35 ` kernel test robot
2023-01-28 9:41 ` Hans de Goede
2023-01-28 13:42 ` Laurent Pinchart
2023-01-28 13:46 ` Hans de Goede
2023-01-28 8:47 ` kernel test robot
2023-01-30 10:17 ` Sakari Ailus
2023-01-30 21:00 ` Hans de Goede
2023-01-30 22:35 ` Linus Walleij
2023-01-27 20:37 ` Hans de Goede [this message]
2023-01-27 20:37 ` [PATCH v6 3/5] platform/x86: int3472/discrete: Create a LED class device for the privacy LED Hans de Goede
2023-01-28 7:24 ` kernel test robot
2023-01-28 9:41 ` Hans de Goede
2023-01-28 10:10 ` kernel test robot
2023-01-30 10:12 ` Sakari Ailus
2023-01-30 20:54 ` Hans de Goede
2023-01-27 20:37 ` [PATCH v6 4/5] platform/x86: int3472/discrete: Move GPIO request to skl_int3472_register_clock() Hans de Goede
2023-01-27 20:37 ` [PATCH v6 5/5] platform/x86: int3472/discrete: Get the polarity from the _DSM entry Hans de Goede
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=20230127203729.10205-3-hdegoede@redhat.com \
--to=hdegoede@redhat.com \
--cc=andy.yeh@intel.com \
--cc=andy@kernel.org \
--cc=djrscally@gmail.com \
--cc=hao.yao@intel.com \
--cc=hpa@redhat.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=markpearson@lenovo.com \
--cc=mchehab@kernel.org \
--cc=mgross@linux.intel.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=sakari.ailus@linux.intel.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;
as well as URLs for NNTP newsgroup(s).