Skip to content

Commit aa9007e

Browse files
kaecheledtor
authored andcommitted
Input: himax_hx83112b - add himax_chip struct for multi-chip support
In preparation for HX83100A support allow defining separate functions for specific chip operations. Signed-off-by: Felix Kaechele <felix@kaechele.ca> Link: https://lore.kernel.org/r/20240620145019.156187-5-felix@kaechele.ca Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 0944829 commit aa9007e

1 file changed

Lines changed: 35 additions & 16 deletions

File tree

drivers/input/touchscreen/himax_hx83112b.c

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include <linux/kernel.h>
2121
#include <linux/regmap.h>
2222

23-
#define HIMAX_ID_83112B 0x83112b
24-
2523
#define HIMAX_MAX_POINTS 10
2624

2725
#define HIMAX_AHB_ADDR_BYTE_0 0x00
@@ -55,7 +53,16 @@ struct himax_event {
5553

5654
static_assert(sizeof(struct himax_event) == 56);
5755

56+
struct himax_ts_data;
57+
struct himax_chip {
58+
u32 id;
59+
int (*check_id)(struct himax_ts_data *ts);
60+
int (*read_events)(struct himax_ts_data *ts, struct himax_event *event,
61+
size_t length);
62+
};
63+
5864
struct himax_ts_data {
65+
const struct himax_chip *chip;
5966
struct gpio_desc *gpiod_rst;
6067
struct input_dev *input_dev;
6168
struct i2c_client *client;
@@ -167,15 +174,12 @@ static int himax_check_product_id(struct himax_ts_data *ts)
167174

168175
dev_dbg(&ts->client->dev, "Product id: %x\n", product_id);
169176

170-
switch (product_id) {
171-
case HIMAX_ID_83112B:
177+
if (product_id == ts->chip->id)
172178
return 0;
173179

174-
default:
175-
dev_err(&ts->client->dev,
176-
"Unknown product id: %x\n", product_id);
177-
return -EINVAL;
178-
}
180+
dev_err(&ts->client->dev, "Unknown product id: %x\n",
181+
product_id);
182+
return -EINVAL;
179183
}
180184

181185
static int himax_input_register(struct himax_ts_data *ts)
@@ -277,13 +281,19 @@ static bool himax_verify_checksum(struct himax_ts_data *ts,
277281
return true;
278282
}
279283

284+
static int himax_read_events(struct himax_ts_data *ts,
285+
struct himax_event *event, size_t length)
286+
{
287+
return regmap_raw_read(ts->regmap, HIMAX_AHB_ADDR_EVENT_STACK, event,
288+
length);
289+
}
290+
280291
static int himax_handle_input(struct himax_ts_data *ts)
281292
{
282293
int error;
283294
struct himax_event event;
284295

285-
error = regmap_raw_read(ts->regmap, HIMAX_AHB_ADDR_EVENT_STACK, &event,
286-
sizeof(event));
296+
error = ts->chip->read_events(ts, &event, sizeof(event));
287297
if (error) {
288298
dev_err(&ts->client->dev, "Failed to read input event: %d\n",
289299
error);
@@ -329,6 +339,7 @@ static int himax_probe(struct i2c_client *client)
329339

330340
i2c_set_clientdata(client, ts);
331341
ts->client = client;
342+
ts->chip = i2c_get_match_data(client);
332343

333344
ts->regmap = devm_regmap_init_i2c(client, &himax_regmap_config);
334345
error = PTR_ERR_OR_ZERO(ts->regmap);
@@ -346,9 +357,11 @@ static int himax_probe(struct i2c_client *client)
346357

347358
himax_reset(ts);
348359

349-
error = himax_check_product_id(ts);
350-
if (error)
351-
return error;
360+
if (ts->chip->check_id) {
361+
error = himax_check_product_id(ts);
362+
if (error)
363+
return error;
364+
}
352365

353366
error = himax_input_register(ts);
354367
if (error)
@@ -381,15 +394,21 @@ static int himax_resume(struct device *dev)
381394

382395
static DEFINE_SIMPLE_DEV_PM_OPS(himax_pm_ops, himax_suspend, himax_resume);
383396

397+
static const struct himax_chip hx83112b_chip = {
398+
.id = 0x83112b,
399+
.check_id = himax_check_product_id,
400+
.read_events = himax_read_events,
401+
};
402+
384403
static const struct i2c_device_id himax_ts_id[] = {
385-
{ "hx83112b" },
404+
{ "hx83112b", (kernel_ulong_t)&hx83112b_chip },
386405
{ /* sentinel */ }
387406
};
388407
MODULE_DEVICE_TABLE(i2c, himax_ts_id);
389408

390409
#ifdef CONFIG_OF
391410
static const struct of_device_id himax_of_match[] = {
392-
{ .compatible = "himax,hx83112b" },
411+
{ .compatible = "himax,hx83112b", .data = &hx83112b_chip },
393412
{ /* sentinel */ }
394413
};
395414
MODULE_DEVICE_TABLE(of, himax_of_match);

0 commit comments

Comments
 (0)