All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org,
	Sakari Ailus <sakari.ailus@linux.intel.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v2 03/15] media: atomisp: Use proper APIs to find I²C client device by ACPI HID
Date: Fri, 26 Jun 2020 15:19:13 +0300	[thread overview]
Message-ID: <20200626121925.14365-4-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20200626121925.14365-1-andriy.shevchenko@linux.intel.com>

There are specific ACPI and I²C APIs to match device by different parameters,
such as ACPI HID, and retrieve an I²C client. Use them instead of home grown
approach. Note, it fixes a resource leak as well.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 .../media/atomisp/pci/atomisp_gmin_platform.c | 43 ++++++++-----------
 1 file changed, 18 insertions(+), 25 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
index 1af9da8acf4c..8acceae189a2 100644
--- a/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
+++ b/drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c
@@ -90,9 +90,9 @@ struct gmin_subdev {
 static struct gmin_subdev gmin_subdevs[MAX_SUBDEVS];
 
 /* ACPI HIDs for the PMICs that could be used by this driver */
-#define PMIC_ACPI_AXP		"INT33F4:00"	/* XPower AXP288 PMIC */
-#define PMIC_ACPI_TI		"INT33F5:00"	/* Dollar Cove TI PMIC */
-#define PMIC_ACPI_CRYSTALCOVE	"INT33FD:00"	/* Crystal Cove PMIC */
+#define PMIC_ACPI_AXP		"INT33F4"	/* XPower AXP288 PMIC */
+#define PMIC_ACPI_TI		"INT33F5"	/* Dollar Cove TI PMIC */
+#define PMIC_ACPI_CRYSTALCOVE	"INT33FD"	/* Crystal Cove PMIC */
 
 #define PMIC_PLATFORM_TI	"intel_soc_pmic_chtdc_ti"
 
@@ -381,34 +381,27 @@ static const guid_t atomisp_dsm_guid = GUID_INIT(0xdc2f6c4f, 0x045b, 0x4f1d,
 #define GMIN_PMC_CLK_NAME 14 /* "pmc_plt_clk_[0..5]" */
 static char gmin_pmc_clk_name[GMIN_PMC_CLK_NAME];
 
-static int gmin_i2c_match_one(struct device *dev, const void *data)
-{
-	const char *name = data;
-	struct i2c_client *client;
-
-	if (dev->type != &i2c_client_type)
-		return 0;
-
-	client = to_i2c_client(dev);
-
-	return (!strcmp(name, client->name));
-}
-
 static struct i2c_client *gmin_i2c_dev_exists(struct device *dev, char *name,
 					      struct i2c_client **client)
 {
+	struct acpi_device *adev;
 	struct device *d;
 
-	while ((d = bus_find_device(&i2c_bus_type, NULL, name,
-				    gmin_i2c_match_one))) {
-		*client = to_i2c_client(d);
-		dev_dbg(dev, "found '%s' at address 0x%02x, adapter %d\n",
-			(*client)->name, (*client)->addr,
-			(*client)->adapter->nr);
-		return *client;
-	}
+	adev = acpi_dev_get_first_match_dev(name, NULL, -1);
+	if (!adev)
+		return NULL;
 
-	return NULL;
+	d = bus_find_device_by_acpi_dev(&i2c_bus_type, adev);
+	acpi_dev_put(adev);
+	if (!d)
+		return NULL;
+
+	*client = i2c_verify_client(d);
+	put_device(d);
+
+	dev_dbg(dev, "found '%s' at address 0x%02x, adapter %d\n",
+		(*client)->name, (*client)->addr, (*client)->adapter->nr);
+	return *client;
 }
 
 static int gmin_i2c_write(struct device *dev, u16 i2c_addr, u8 reg,
-- 
2.27.0


  parent reply	other threads:[~2020-06-26 12:19 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-26 12:19 [PATCH v2 00/15] media: atomisp: Clean ups and fixes to make it load on Baytrail Andy Shevchenko
2020-06-26 12:19 ` [PATCH v2 01/15] media: atomisp: Replace last use of Intel MID APIs Andy Shevchenko
2020-06-26 12:19 ` [PATCH v2 02/15] media: atomisp: move CCK endpoint address to generic header Andy Shevchenko
2020-06-26 12:19 ` Andy Shevchenko [this message]
2020-06-26 12:19 ` [PATCH v2 04/15] media: atomisp: don't pass struct device_driver as parameter Andy Shevchenko
2020-06-26 12:19 ` [PATCH v2 05/15] media: atomisp: Get rid of struct pci_dev in struct atomisp_device Andy Shevchenko
2020-06-26 12:19 ` [PATCH v2 06/15] media: atomisp: Unify pdev to be pointer to struct pci_device Andy Shevchenko
2020-06-26 12:19 ` [PATCH v2 07/15] media: atomisp: Replace direct access to MMIO with proper helpers Andy Shevchenko
2020-06-26 12:19 ` [PATCH v2 08/15] media: atomisp: Drop global atomisp_dev variable (easy cases) Andy Shevchenko
2020-06-26 12:19 ` [PATCH v2 09/15] media: atomisp: make platform data more readable Andy Shevchenko
2020-06-26 12:19 ` [PATCH v2 10/15] media: atomisp: Don't try to parse unexpected ACPI object type Andy Shevchenko
2020-06-26 12:19 ` [PATCH v2 11/15] media: atomisp: Make pointer to PMIC client global Andy Shevchenko
2020-06-26 12:19 ` [PATCH v2 12/15] media: atomisp: Refactor PMIC detection to a separate function Andy Shevchenko
2020-06-26 12:19 ` [PATCH v2 13/15] media: atomisp: Provide Gmin subdev as parameter to gmin_subdev_add() Andy Shevchenko
2020-06-26 12:19 ` [PATCH v2 14/15] media: atomisp: Get rid of ugly and leaky ACPI handling in gmin_subdev_add() Andy Shevchenko
2020-06-26 12:19 ` [PATCH v2 15/15] media: atomisp: Deduplicate return ret in gmin_i2c_write() Andy Shevchenko
2020-06-26 13:29 ` [PATCH v2 00/15] media: atomisp: Clean ups and fixes to make it load on Baytrail Mauro Carvalho Chehab
2020-06-26 14:01   ` Mauro Carvalho Chehab
2020-06-29 10:53     ` 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=20200626121925.14365-4-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.