blob: 3ff70ae5785642cbdd180cab1d0e85bd8350336a [file] [log] [blame]
Hans de Goedecef9dd82017-01-23 18:35:30 +01001/*
2 * Silead touchscreen driver DMI based configuration code
3 *
4 * Copyright (c) 2017 Red Hat Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * Red Hat authors:
12 * Hans de Goede <hdegoede@redhat.com>
13 */
14
15#include <linux/acpi.h>
16#include <linux/device.h>
17#include <linux/dmi.h>
18#include <linux/i2c.h>
19#include <linux/notifier.h>
20#include <linux/property.h>
21#include <linux/string.h>
22
23struct silead_ts_dmi_data {
24 const char *acpi_name;
Hans de Goedeae311152017-03-22 16:55:53 +010025 const struct property_entry *properties;
Hans de Goedecef9dd82017-01-23 18:35:30 +010026};
27
Hans de Goedeae311152017-03-22 16:55:53 +010028static const struct property_entry cube_iwork8_air_props[] = {
Hans de Goedecef9dd82017-01-23 18:35:30 +010029 PROPERTY_ENTRY_U32("touchscreen-size-x", 1660),
30 PROPERTY_ENTRY_U32("touchscreen-size-y", 900),
31 PROPERTY_ENTRY_BOOL("touchscreen-swapped-x-y"),
32 PROPERTY_ENTRY_STRING("firmware-name", "gsl3670-cube-iwork8-air.fw"),
33 PROPERTY_ENTRY_U32("silead,max-fingers", 10),
34 { }
35};
36
37static const struct silead_ts_dmi_data cube_iwork8_air_data = {
38 .acpi_name = "MSSL1680:00",
39 .properties = cube_iwork8_air_props,
40};
41
Hans de Goedeae311152017-03-22 16:55:53 +010042static const struct property_entry jumper_ezpad_mini3_props[] = {
Hans de Goedecef9dd82017-01-23 18:35:30 +010043 PROPERTY_ENTRY_U32("touchscreen-size-x", 1700),
44 PROPERTY_ENTRY_U32("touchscreen-size-y", 1150),
45 PROPERTY_ENTRY_BOOL("touchscreen-swapped-x-y"),
46 PROPERTY_ENTRY_STRING("firmware-name", "gsl3676-jumper-ezpad-mini3.fw"),
47 PROPERTY_ENTRY_U32("silead,max-fingers", 10),
48 { }
49};
50
51static const struct silead_ts_dmi_data jumper_ezpad_mini3_data = {
52 .acpi_name = "MSSL1680:00",
53 .properties = jumper_ezpad_mini3_props,
54};
55
Hans de Goede6b8e7d82017-03-22 16:55:54 +010056static const struct property_entry dexp_ursus_7w_props[] = {
57 PROPERTY_ENTRY_U32("touchscreen-size-x", 890),
58 PROPERTY_ENTRY_U32("touchscreen-size-y", 630),
59 PROPERTY_ENTRY_STRING("firmware-name", "gsl1686-dexp-ursus-7w.fw"),
60 PROPERTY_ENTRY_U32("silead,max-fingers", 10),
61 { }
62};
63
64static const struct silead_ts_dmi_data dexp_ursus_7w_data = {
65 .acpi_name = "MSSL1680:00",
66 .properties = dexp_ursus_7w_props,
67};
68
Hans de Goedecef9dd82017-01-23 18:35:30 +010069static const struct dmi_system_id silead_ts_dmi_table[] = {
70 {
71 /* CUBE iwork8 Air */
72 .driver_data = (void *)&cube_iwork8_air_data,
73 .matches = {
74 DMI_MATCH(DMI_SYS_VENDOR, "cube"),
75 DMI_MATCH(DMI_PRODUCT_NAME, "i1-TF"),
76 DMI_MATCH(DMI_BOARD_NAME, "Cherry Trail CR"),
77 },
78 },
79 {
80 /* Jumper EZpad mini3 */
81 .driver_data = (void *)&jumper_ezpad_mini3_data,
82 .matches = {
83 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
84 /* jumperx.T87.KFBNEEA02 with the version-nr dropped */
85 DMI_MATCH(DMI_BIOS_VERSION, "jumperx.T87.KFBNEEA"),
86 },
87 },
Hans de Goede6b8e7d82017-03-22 16:55:54 +010088 {
89 /* DEXP Ursus 7W */
90 .driver_data = (void *)&dexp_ursus_7w_data,
91 .matches = {
92 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
93 DMI_MATCH(DMI_PRODUCT_NAME, "7W"),
94 },
95 },
Hans de Goedecef9dd82017-01-23 18:35:30 +010096 { },
97};
98
Dmitry Torokhovf22265b2017-04-03 20:25:14 -070099static const struct silead_ts_dmi_data *silead_ts_data;
100
Dmitry Torokhove1053962017-04-03 20:25:13 -0700101static void silead_ts_dmi_add_props(struct i2c_client *client)
Hans de Goedecef9dd82017-01-23 18:35:30 +0100102{
Dmitry Torokhove1053962017-04-03 20:25:13 -0700103 struct device *dev = &client->dev;
Hans de Goedecef9dd82017-01-23 18:35:30 +0100104 int error;
105
Hans de Goedecef9dd82017-01-23 18:35:30 +0100106 if (has_acpi_companion(dev) &&
Dmitry Torokhovf22265b2017-04-03 20:25:14 -0700107 !strncmp(silead_ts_data->acpi_name, client->name, I2C_NAME_SIZE)) {
108 error = device_add_properties(dev, silead_ts_data->properties);
Hans de Goedecef9dd82017-01-23 18:35:30 +0100109 if (error)
110 dev_err(dev, "failed to add properties: %d\n", error);
111 }
112}
113
114static int silead_ts_dmi_notifier_call(struct notifier_block *nb,
115 unsigned long action, void *data)
116{
117 struct device *dev = data;
Dmitry Torokhove1053962017-04-03 20:25:13 -0700118 struct i2c_client *client;
Hans de Goedecef9dd82017-01-23 18:35:30 +0100119
120 switch (action) {
121 case BUS_NOTIFY_ADD_DEVICE:
Dmitry Torokhove1053962017-04-03 20:25:13 -0700122 client = i2c_verify_client(dev);
123 if (client)
124 silead_ts_dmi_add_props(client);
Hans de Goedecef9dd82017-01-23 18:35:30 +0100125 break;
126
127 default:
128 break;
129 }
130
131 return 0;
132}
133
134static struct notifier_block silead_ts_dmi_notifier = {
135 .notifier_call = silead_ts_dmi_notifier_call,
136};
137
138static int __init silead_ts_dmi_init(void)
139{
Dmitry Torokhovf22265b2017-04-03 20:25:14 -0700140 const struct dmi_system_id *dmi_id;
Hans de Goedecef9dd82017-01-23 18:35:30 +0100141 int error;
142
Dmitry Torokhovf22265b2017-04-03 20:25:14 -0700143 dmi_id = dmi_first_match(silead_ts_dmi_table);
144 if (!dmi_id)
145 return 0; /* Not an error */
146
147 silead_ts_data = dmi_id->driver_data;
148
Hans de Goedecef9dd82017-01-23 18:35:30 +0100149 error = bus_register_notifier(&i2c_bus_type, &silead_ts_dmi_notifier);
150 if (error)
151 pr_err("%s: failed to register i2c bus notifier: %d\n",
152 __func__, error);
153
154 return error;
155}
156
157/*
158 * We are registering out notifier after i2c core is initialized and i2c bus
159 * itself is ready (which happens at postcore initcall level), but before
160 * ACPI starts enumerating devices (at subsys initcall level).
161 */
162arch_initcall(silead_ts_dmi_init);