LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: linux-input@vger.kernel.org, Benson Leung <bleung@chromium.org>
Cc: Nick Dyer <nick@shmanahar.org>, Olof Johansson <olof@lixom.net>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 02/14] Input: atmel_mxt_ts - switch from OF to generic device properties
Date: Tue, 20 Mar 2018 15:31:26 -0700	[thread overview]
Message-ID: <20180320223138.234724-3-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <20180320223138.234724-1-dmitry.torokhov@gmail.com>

Instead of using OF-specific APIs to fecth device properties, let's switch
to generic device properties API. This will allow us to use device
properties on legacy ChromeOS devices and get rid of platform data down
the road.

Acked-by: Nick Dyer <nick@shmanahar.org>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/touchscreen/atmel_mxt_ts.c | 59 ++++++++++++------------
 1 file changed, 30 insertions(+), 29 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 20e1224d1a6db..73d9c0254ad76 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -29,6 +29,7 @@
 #include <linux/of.h>
 #include <linux/slab.h>
 #include <linux/gpio/consumer.h>
+#include <linux/property.h>
 #include <asm/unaligned.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
@@ -2922,47 +2923,52 @@ static void mxt_input_close(struct input_dev *dev)
 	mxt_stop(data);
 }
 
-#ifdef CONFIG_OF
-static const struct mxt_platform_data *mxt_parse_dt(struct i2c_client *client)
+static const struct mxt_platform_data *
+mxt_parse_device_properties(struct i2c_client *client)
 {
+	static const char keymap_property[] = "linux,gpio-keymap";
 	struct mxt_platform_data *pdata;
-	struct device_node *np = client->dev.of_node;
 	u32 *keymap;
-	int proplen, ret;
-
-	if (!np)
-		return ERR_PTR(-ENOENT);
+	int n_keys;
+	int error;
 
 	pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
 		return ERR_PTR(-ENOMEM);
 
-	if (of_find_property(np, "linux,gpio-keymap", &proplen)) {
-		pdata->t19_num_keys = proplen / sizeof(u32);
+	if (device_property_present(&client->dev, keymap_property)) {
+		n_keys = device_property_read_u32_array(&client->dev,
+							keymap_property,
+							NULL, 0);
+		if (n_keys <= 0) {
+			error = n_keys < 0 ? n_keys : -EINVAL;
+			dev_err(&client->dev,
+				"invalid/malformed '%s' property: %d\n",
+				keymap_property, error);
+			return ERR_PTR(error);
+		}
 
-		keymap = devm_kzalloc(&client->dev,
-				pdata->t19_num_keys * sizeof(keymap[0]),
-				GFP_KERNEL);
+		keymap = devm_kmalloc_array(&client->dev, n_keys, sizeof(u32),
+					    GFP_KERNEL);
 		if (!keymap)
 			return ERR_PTR(-ENOMEM);
 
-		ret = of_property_read_u32_array(np, "linux,gpio-keymap",
-						 keymap, pdata->t19_num_keys);
-		if (ret)
-			dev_warn(&client->dev,
-				 "Couldn't read linux,gpio-keymap: %d\n", ret);
+		error = device_property_read_u32_array(&client->dev,
+						       keymap_property,
+						       keymap, n_keys);
+		if (error) {
+			dev_err(&client->dev,
+				"failed to parse '%s' property: %d\n",
+				keymap_property, error);
+			return ERR_PTR(error);
+		}
 
 		pdata->t19_keymap = keymap;
+		pdata->t19_num_keys = n_keys;
 	}
 
 	return pdata;
 }
-#else
-static const struct mxt_platform_data *mxt_parse_dt(struct i2c_client *client)
-{
-	return ERR_PTR(-ENOENT);
-}
-#endif
 
 #ifdef CONFIG_ACPI
 
@@ -3096,16 +3102,11 @@ mxt_get_platform_data(struct i2c_client *client)
 	if (pdata)
 		return pdata;
 
-	pdata = mxt_parse_dt(client);
-	if (!IS_ERR(pdata) || PTR_ERR(pdata) != -ENOENT)
-		return pdata;
-
 	pdata = mxt_parse_acpi(client);
 	if (!IS_ERR(pdata) || PTR_ERR(pdata) != -ENOENT)
 		return pdata;
 
-	dev_err(&client->dev, "No platform data specified\n");
-	return ERR_PTR(-EINVAL);
+	return mxt_parse_device_properties(client);
 }
 
 static const struct dmi_system_id chromebook_T9_suspend_dmi[] = {
-- 
2.16.2.804.g6dcf76e118-goog

  parent reply	other threads:[~2018-03-20 22:32 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-20 22:31 [PATCH v2 00/14] chrome_laptop: stop being a platform driver Dmitry Torokhov
2018-03-20 22:31 ` [PATCH v2 01/14] Input: atmel_mxt_ts - do not pass suspend mode in platform data Dmitry Torokhov
2018-04-10  5:44   ` Benson Leung
2018-03-20 22:31 ` Dmitry Torokhov [this message]
2018-03-20 22:31 ` [PATCH v2 03/14] Input: atmel_mxt_ts - switch ChromeOS ACPI devices to generic props Dmitry Torokhov
2018-03-20 22:31 ` [PATCH v2 04/14] platform/chrome: chromeos_laptop - add SPDX identifier Dmitry Torokhov
2018-03-20 22:31 ` [PATCH v2 05/14] platform/chrome: chromeos_laptop - stop setting suspend mode for Atmel devices Dmitry Torokhov
2018-03-22 23:34   ` Benson Leung
2018-03-20 22:31 ` [PATCH v2 06/14] platform/chrome: chromeos_laptop - introduce pr_fmt() Dmitry Torokhov
2018-03-20 22:31 ` [PATCH v2 07/14] platform/chrome: chromeos_laptop - factor out getting IRQ from DMI Dmitry Torokhov
2018-03-20 22:31 ` [PATCH v2 08/14] platform/chrome: chromeos_laptop - rework i2c peripherals initialization Dmitry Torokhov
2018-03-20 22:31 ` [PATCH v2 09/14] platform/chrome: chromeos_laptop - parse DMI IRQ data once Dmitry Torokhov
2018-03-20 22:31 ` [PATCH v2 10/14] platform/chrome: chromeos_laptop - use I2C notifier to create devices Dmitry Torokhov
2018-03-20 22:31 ` [PATCH v2 11/14] platform/chrome: chromeos_laptop - rely on I2C to set up interrupt trigger Dmitry Torokhov
2018-03-20 22:31 ` [PATCH v2 12/14] platform/chrome: chromeos_laptop - use device properties for Pixel Dmitry Torokhov
2018-03-20 22:31 ` [PATCH v2 13/14] platform/chrome: chromeos_laptop - discard data for unneeded boards Dmitry Torokhov
2018-03-20 22:31 ` [PATCH v2 14/14] Input: atmel_mxt_ts - remove platform data support Dmitry Torokhov
2018-04-11  5:44 ` [PATCH v2 00/14] chrome_laptop: stop being a platform driver Benson Leung

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=20180320223138.234724-3-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=bleung@chromium.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nick@shmanahar.org \
    --cc=olof@lixom.net \
    --subject='Re: [PATCH v2 02/14] Input: atmel_mxt_ts - switch from OF to generic device properties' \
    /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

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).