linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandru Ardelean <alexandru.ardelean@analog.com>
To: <linux-input@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<devicetree@vger.kernel.org>
Cc: <lars@metafoo.de>, <dmitry.torokhov@gmail.com>,
	<robh+dt@kernel.org>,
	Alexandru Ardelean <alexandru.ardelean@analog.com>
Subject: [PATCH v3 2/4] Input: adp5589-keys - wrap device probing into chip info struct
Date: Fri, 27 Nov 2020 13:14:18 +0200	[thread overview]
Message-ID: <20201127111420.96500-2-alexandru.ardelean@analog.com> (raw)
In-Reply-To: <20201127111420.96500-1-alexandru.ardelean@analog.com>

This change wraps the devices supported by the adp5589 driver into a chip
info struct. With this, a device table can be created, and the probed
device can be selected based on the enum value provided by the i2c driver
data.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/input/keyboard/adp5589-keys.c | 60 ++++++++++++++++-----------
 1 file changed, 36 insertions(+), 24 deletions(-)

diff --git a/drivers/input/keyboard/adp5589-keys.c b/drivers/input/keyboard/adp5589-keys.c
index 742bf4b97dbb..6cb93ee3b97c 100644
--- a/drivers/input/keyboard/adp5589-keys.c
+++ b/drivers/input/keyboard/adp5589-keys.c
@@ -227,16 +227,17 @@ struct adp_constants {
 	u8 (*reg) (u8 reg);
 };
 
+struct adp5589_chip_info;
+
 struct adp5589_kpad {
 	struct i2c_client *client;
 	struct input_dev *input;
 	const struct adp_constants *var;
+	const struct adp5589_chip_info *info;
 	unsigned short keycode[ADP5589_KEYMAPSIZE];
 	const struct adp5589_gpi_map *gpimap;
 	unsigned short gpimapsize;
 	unsigned extend_cfg;
-	bool is_adp5585;
-	bool support_row5;
 #ifdef CONFIG_GPIOLIB
 	unsigned char gpiomap[ADP5589_MAXGPIO];
 	struct gpio_chip gc;
@@ -377,6 +378,28 @@ static const struct adp5589_kpad_platform_data adp5589_default_pdata = {
 	.gpio_data = &adp5589_default_gpio_pdata,
 };
 
+struct adp5589_chip_info {
+	const struct adp_constants	*constants;
+	bool				support_row5;
+	bool				is_adp5585;
+};
+
+static const struct adp5589_chip_info adp5589_chip_info_tbl[] = {
+	[ADP5589] = {
+		.constants = &const_adp5589,
+		.support_row5 = true,
+	},
+	[ADP5585_01] = {
+		.constants = &const_adp5585,
+		.is_adp5585 = true,
+	},
+	[ADP5585_02] = {
+		.constants = &const_adp5585,
+		.is_adp5585 = true,
+		.support_row5 = true,
+	},
+};
+
 static const struct adp5589_kpad_platform_data *adp5589_kpad_pdata_get(
 	struct device *dev)
 {
@@ -504,7 +527,7 @@ static int adp5589_build_gpiomap(struct adp5589_kpad *kpad,
 	if (kpad->extend_cfg & C4_EXTEND_CFG)
 		pin_used[kpad->var->c4_extend_cfg] = true;
 
-	if (!kpad->support_row5)
+	if (!kpad->info->support_row5)
 		pin_used[5] = true;
 
 	for (i = 0; i < kpad->var->maxgpio; i++)
@@ -651,11 +674,11 @@ static int adp5589_setup(struct adp5589_kpad *kpad)
 			     (pdata->keypad_en_mask >> kpad->var->col_shift) &
 			     kpad->var->col_mask);
 
-	if (!kpad->is_adp5585)
+	if (!kpad->info->is_adp5585)
 		ret |= adp5589_write(client, ADP5589_PIN_CONFIG_C,
 				     (pdata->keypad_en_mask >> 16) & 0xFF);
 
-	if (!kpad->is_adp5585 && pdata->en_keylock) {
+	if (!kpad->info->is_adp5585 && pdata->en_keylock) {
 		ret |= adp5589_write(client, ADP5589_UNLOCK1,
 				     pdata->unlock_key1);
 		ret |= adp5589_write(client, ADP5589_UNLOCK2,
@@ -676,7 +699,7 @@ static int adp5589_setup(struct adp5589_kpad *kpad)
 		} else {
 			evt_mode2 |=
 			    BIT(pin - kpad->var->gpi_pin_col_base) & 0xFF;
-			if (!kpad->is_adp5585)
+			if (!kpad->info->is_adp5585)
 				evt_mode3 |=
 				    BIT(pin - kpad->var->gpi_pin_col_base) >> 8;
 		}
@@ -687,7 +710,7 @@ static int adp5589_setup(struct adp5589_kpad *kpad)
 				     evt_mode1);
 		ret |= adp5589_write(client, reg(ADP5589_GPI_EVENT_EN_B),
 				     evt_mode2);
-		if (!kpad->is_adp5585)
+		if (!kpad->info->is_adp5585)
 			ret |= adp5589_write(client,
 					     reg(ADP5589_GPI_EVENT_EN_C),
 					     evt_mode3);
@@ -775,16 +798,16 @@ static int adp5589_setup(struct adp5589_kpad *kpad)
 			     (pdata->debounce_dis_mask >> kpad->var->col_shift)
 			     & kpad->var->col_mask);
 
-	if (!kpad->is_adp5585)
+	if (!kpad->info->is_adp5585)
 		ret |= adp5589_write(client, reg(ADP5589_DEBOUNCE_DIS_C),
 				     (pdata->debounce_dis_mask >> 16) & 0xFF);
 
 	ret |= adp5589_write(client, reg(ADP5589_POLL_PTIME_CFG),
 			     pdata->scan_cycle_time & PTIME_MASK);
 	ret |= adp5589_write(client, ADP5589_5_INT_STATUS,
-			     (kpad->is_adp5585 ? 0 : LOGIC2_INT) |
+			     (kpad->info->is_adp5585 ? 0 : LOGIC2_INT) |
 			     LOGIC1_INT | OVRFLOW_INT |
-			     (kpad->is_adp5585 ? 0 : LOCK_INT) |
+			     (kpad->info->is_adp5585 ? 0 : LOCK_INT) |
 			     GPI_INT | EVENT_INT);	/* Status is W1C */
 
 	ret |= adp5589_write(client, reg(ADP5589_GENERAL_CFG),
@@ -808,7 +831,7 @@ static void adp5589_report_switch_state(struct adp5589_kpad *kpad)
 				     kpad->var->reg(ADP5589_GPI_STATUS_A));
 	int gpi_stat2 = adp5589_read(kpad->client,
 				     kpad->var->reg(ADP5589_GPI_STATUS_B));
-	int gpi_stat3 = !kpad->is_adp5585 ?
+	int gpi_stat3 = !kpad->info->is_adp5585 ?
 			adp5589_read(kpad->client, ADP5589_GPI_STATUS_C) : 0;
 
 	for (i = 0; i < kpad->gpimapsize; i++) {
@@ -984,19 +1007,8 @@ static int adp5589_probe(struct i2c_client *client,
 
 	kpad->client = client;
 
-	switch (id->driver_data) {
-	case ADP5585_02:
-		kpad->support_row5 = true;
-		fallthrough;
-	case ADP5585_01:
-		kpad->is_adp5585 = true;
-		kpad->var = &const_adp5585;
-		break;
-	case ADP5589:
-		kpad->support_row5 = true;
-		kpad->var = &const_adp5589;
-		break;
-	}
+	kpad->info = &adp5589_chip_info_tbl[id->driver_data];
+	kpad->var = kpad->info->constants;
 
 	error = devm_add_action_or_reset(&client->dev, adp5589_clear_config,
 					 client);
-- 
2.27.0


  reply	other threads:[~2020-11-27 11:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-27 11:14 [PATCH v3 1/4] Input: adp5589-keys - add default platform data Alexandru Ardelean
2020-11-27 11:14 ` Alexandru Ardelean [this message]
2020-11-27 11:14 ` [PATCH v3 3/4] Input: adp5589-keys - add basic devicetree support Alexandru Ardelean
2020-11-27 11:14 ` [PATCH v3 4/4] dt-bindings: add ADP5585/ADP5589 entries to trivial-devices Alexandru Ardelean
2020-12-08 18:13   ` Rob Herring
2020-12-09  7:01 ` [PATCH v3 1/4] Input: adp5589-keys - add default platform data Ardelean, Alexandru
2020-12-10  7:20 ` 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=20201127111420.96500-2-alexandru.ardelean@analog.com \
    --to=alexandru.ardelean@analog.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /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).