Debian Codegraph @

src/drivers/intel/touch/touch.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <acpi/acpi_device.h>
4 #include <acpi/acpigen.h>
5 #include <acpi/acpigen_pci.h>
6 #include <console/console.h>
7 #include <device/pci.h>
8 #include <device/pci_ids.h>
9
10 #include "chip.h"
11 #include "elan.h"
12 #include "hynitron.h"
13 #include "wacom.h"
14
15 /* _DSM Method UUIDs */
16 #define TOUCH_HIDI2C_UUID "3cdff6f7-4267-4555-ad05-b30a3d8938de"
17 #define TOUCH_HID_UUID "6e2ac436-0fcf-41af-a265-b32a220dcfab"
18 #define TOUCH_INTF_UUID "300d35b7-ac20-413e-8e9c-92e4dafd0afe"
19 #define TOUCH_LTR_UUID "84005682-5b71-41a4-8d66-8130f787a138"
20
21 /* _DSD UUIDs */
22 #define ACPI_DP_UUID "daffd814-6eba-4d8c-8a91-bc9bbf4aa301"
23 #define ACPI_DP_CHILD_UUID "dbb8e3e6-5886-4ba6-8795-1319f52a966b"
24 #define ACPI_DSD_DMA_PROPERTY_UUID "70d24161-6dd5-4c9e-8070-705531292865"
25 #define ACPI_DSD_DMA_PROPERTY_NAME "DmaProperty"
26
27 #define TOUCH_MUTEX "THMX"
28
29 static const struct intel_thc_hidi2c_info *_soc_hidi2c_info;
30 static const struct intel_thc_hidspi_info *_soc_hidspi_info;
31
32 __weak const struct intel_thc_hidi2c_info *soc_get_thc_hidi2c_info(void) { return NULL; }
33 __weak const struct intel_thc_hidspi_info *soc_get_thc_hidspi_info(void) { return NULL; }
34
35 /*
36 * This function returns a pointer to the correct drivers_intel_touch_config structure based on
37 * the device tree configuration and the connected device type.
38 */
39 static const struct drivers_intel_touch_config *get_driver_config(const struct device *dev)
40
41 {
42 const struct drivers_intel_touch_config none_driver_config;
43 const struct drivers_intel_touch_config *config = dev->chip_info;
44 const struct drivers_intel_touch_config *devices[TH_SENSOR_MAX] = {
45 [TH_SENSOR_NONE] = &none_driver_config,
46 [TH_SENSOR_WACOM] = &wacom_touch_config,
47 [TH_SENSOR_ELAN] = &elan_touch_config,
48 [TH_SENSOR_HYNITRON] = &hynitron_touch_config,
49 [TH_SENSOR_GENERIC] = config
50 };
51 return devices[config->connected_device];
52 }
53
54 /* Use only Device-tree definition. */
55 #define touch_config_get(device, field) \
56 (((const struct drivers_intel_touch_config *)(device)->chip_info)->field)
57
58 /* Device-tree definition takes precedence over static drivers definition. */
59 #define touch_get(device, field) \
60 ((((const struct drivers_intel_touch_config *)(device)->chip_info)->field) ? \
61 (((const struct drivers_intel_touch_config *)(device)->chip_info)->field) : \
62 get_driver_config(dev)->field)
63
64 /* Device-tree definition takes precedence over static drivers SoC-specific definition. */
65 #define touch_soc_get(device, intf, field) \
66 ((((const struct drivers_intel_touch_config *)(device)->chip_info)->soc_## intf .field) ? \
67 (((const struct drivers_intel_touch_config *)(device)->chip_info)->soc_## intf .field) : \
68 (_soc_## intf ##_info->field))
69
70 static const char *touch_acpi_name(const struct device *dev)
71 {
72 return touch_get(dev, name) ? : INTEL_THC0_NAME;
73 }
74
75 /*
76 * Functions prefixed with touch_acpigen_ are utilized within the Device Specific Method (DSM)
77 * ACPI code generation framework.
78 */
79
80 #define touch_config_acpigen(field, fmt) \
81 static void touch_acpigen_##field(void *arg) \
82 { \
83 const struct device *dev = (const struct device *)arg; \
84 uint32_t value = touch_config_get(dev, field); \
85 acpigen_write_debug_sprintf(fmt, touch_acpi_name(dev), value); \
86 acpigen_write_return_integer(value); \
87 }
88
89 #define touch_dev_acpigen(field, interface, type, fmt) \
90 static void touch_acpigen_## interface ## _ ## field(void *arg) \
91 { \
92 const struct device *dev = (const struct device *)arg; \
93 uint32_t value = touch_get(dev, dev_##interface.intf.interface.field); \
94 acpigen_write_debug_sprintf(fmt, touch_acpi_name(dev), value); \
95 acpigen_write_return_ ## type(value); \
96 }
97
98 #define touch_soc_acpigen(field, intf, type, fmt) \
99 static void touch_acpigen_## intf ## _ ## field(void *arg) \
100 { \
101 const struct device *dev = (const struct device *)arg; \
102 uint32_t value = touch_soc_get(dev, intf, field); \
103 acpigen_write_debug_sprintf(fmt, touch_acpi_name(dev), value); \
104 acpigen_write_return_ ## type(value); \
105 }
106
107 touch_soc_acpigen(connection_speed, hidspi, integer, "%s: connection speed = %d\n");
108 touch_soc_acpigen(limit_packet_size, hidspi, integer, "%s: limit packet size = %d\n");
109 touch_soc_acpigen(performance_limit, hidspi, integer, "%s: performance limit = %d\n");
110
111 static void (*touch_intf[])(void *) = {
112 NULL, /* Enumerate functions (auto-generated) */
113 touch_acpigen_hidspi_connection_speed,
114 touch_acpigen_hidspi_limit_packet_size,
115 touch_acpigen_hidspi_performance_limit
116 };
117
118 touch_config_acpigen(idle_ltr, "%s: Idle LTR = %d\n");
119 touch_config_acpigen(active_ltr, "%s: Active LTR = %d\n");
120
121 static void (*touch_ltr[])(void *) = {
122 NULL, /* Enumerate functions (auto-generated) */
123 touch_acpigen_active_ltr,
124 touch_acpigen_idle_ltr
125 };
126
127 touch_dev_acpigen(input_report_header_address, hidspi, integer,
128 "%s: HID SPI Input Report Header Address = %d\n");
129 touch_dev_acpigen(input_report_body_address, hidspi, integer,
130 "%s: HID SPI Input Report Body Address = %d\n");
131 touch_dev_acpigen(output_report_address, hidspi, integer,
132 "%s: HID SPI Output Report Address = %d\n");
133 touch_dev_acpigen(read_opcode, hidspi, singleton_buffer, "%s: HID SPI Read Opcode = %d\n");
134 touch_dev_acpigen(write_opcode, hidspi, singleton_buffer, "%s: HID SPI Write Opcode = %d\n");
135
136 touch_soc_acpigen(write_mode, hidspi, integer, "%s: HID SPI Write Mode (flags) = 0x%x\n");
137
138 static void (*touch_hidspi[])(void *) = {
139 NULL, /* Enumerate functions (auto-generated) */
140 touch_acpigen_hidspi_input_report_header_address,
141 touch_acpigen_hidspi_input_report_body_address,
142 touch_acpigen_hidspi_output_report_address,
143 touch_acpigen_hidspi_read_opcode,
144 touch_acpigen_hidspi_write_opcode,
145 touch_acpigen_hidspi_write_mode
146 };
147
148 touch_dev_acpigen(descriptor_address, hidi2c, integer,
149 "%s: HID I2C device descriptor address = 0x%x\n");
150
151 static void (*touch_hidi2c[])(void *) = {
152 NULL, /* Enumerate functions (auto-generated) */
153 touch_acpigen_hidi2c_descriptor_address
154 };
155
156 static void touch_generate_acpi_dsm(const struct drivers_intel_touch_config *config,
157 const struct device *dev)
158 {
159 struct dsm_uuid spi_dsm_uuids[] = {
160 DSM_UUID(TOUCH_INTF_UUID, touch_intf, ARRAY_SIZE(touch_intf), (void *)dev),
161 DSM_UUID(TOUCH_LTR_UUID, touch_ltr, ARRAY_SIZE(touch_ltr), (void *)dev),
162 DSM_UUID(TOUCH_HID_UUID, touch_hidspi, ARRAY_SIZE(touch_hidspi), (void *)dev)
163 };
164 struct dsm_uuid i2c_dsm_uuids[] = {
165 DSM_UUID(TOUCH_LTR_UUID, touch_ltr, ARRAY_SIZE(touch_ltr), (void *)dev),
166 DSM_UUID(TOUCH_HIDI2C_UUID, touch_hidi2c, ARRAY_SIZE(touch_hidi2c), (void *)dev)
167 };
168
169 if (config->connected_device == TH_SENSOR_NONE || config->mode == THC_IPTS_MODE)
170 return;
171
172 if (config->mode == THC_HID_SPI_MODE)
173 acpigen_write_dsm_uuid_arr(spi_dsm_uuids, ARRAY_SIZE(spi_dsm_uuids));
174 else if (config->mode == THC_HID_I2C_MODE)
175 acpigen_write_dsm_uuid_arr(i2c_dsm_uuids, ARRAY_SIZE(i2c_dsm_uuids));
176 }
177
178 static void touch_generate_acpi_ini(const struct device *dev)
179 {
180 acpigen_write_method_serialized("_INI", 0);
181 {
182 acpigen_write_debug_sprintf("%s: _INI()\n", touch_acpi_name(dev));
183 }
184 acpigen_write_method_end(); /* Method */
185 }
186
187 static void touch_generate_acpi_crs(const struct drivers_intel_touch_config *config,
188 const struct device *dev)
189 {
190 if (config->mode == THC_IPTS_MODE || !config->wake_on_touch)
191 return;
192
193 printk(BIOS_DEBUG, "%s Creating _CRS for HID SPI/I2C touch wake\n",
194 touch_acpi_name(dev));
195 acpigen_write_name("_CRS");
196 acpigen_write_resourcetemplate_header();
197 /*
198 * NOTE: config->wake_gpio: uses GpioInt() in _CRS; PAD needs to be Driver Mode
199 * config->wake_irq: uses Interrupt() in _CRS; use GPE; PAD needs to be ACPI Mode
200 */
201 if (config->wake_gpio.pin_count)
202 acpi_device_write_gpio(&config->wake_gpio);
203 else if (config->wake_irq.pin)
204 acpi_device_write_interrupt(&config->wake_irq);
205 acpigen_write_resourcetemplate_footer();
206
207 acpigen_write_name_integer("_S0W", ACPI_DEVICE_SLEEP_D3_HOT);
208 if (config->wake_irq.pin)
209 acpigen_write_PRW(config->wake_gpe, 3);
210 }
211
212 static void touch_generate_acpi_i2cdev_dsd(const struct device *dev)
213 {
214 int dsd_pkg_cnt;
215
216 acpigen_write_name("ICRS");
217 acpigen_emit_byte(BUFFER_OP);
218 acpigen_write_len_f();
219 acpigen_write_integer(12);
220 acpigen_pop_len(); /* Name */
221 acpigen_write_create_buffer_word_field("ICRS", 0x00, "DADR");
222 acpigen_write_create_buffer_qword_field("ICRS", 0x02, "DSPD");
223 acpigen_write_create_buffer_byte_field("ICRS", 0x0a, "DADM");
224
225 acpigen_write_name("ISUB");
226 acpigen_emit_byte(BUFFER_OP);
227 acpigen_write_len_f();
228 acpigen_write_integer(145);
229 acpigen_pop_len();
230 acpigen_write_create_buffer_qword_field("ISUB", 0x00, "SMHX");
231 acpigen_write_create_buffer_qword_field("ISUB", 0x08, "SMLX");
232 acpigen_write_create_buffer_qword_field("ISUB", 0x10, "SMTD");
233 acpigen_write_create_buffer_qword_field("ISUB", 0x18, "SMRD");
234 acpigen_write_create_buffer_qword_field("ISUB", 0x20, "FMHX");
235 acpigen_write_create_buffer_qword_field("ISUB", 0x28, "FMLX");
236 acpigen_write_create_buffer_qword_field("ISUB", 0x30, "FMTD");
237 acpigen_write_create_buffer_qword_field("ISUB", 0x38, "FMRD");
238 acpigen_write_create_buffer_qword_field("ISUB", 0x40, "FMSL");
239 acpigen_write_create_buffer_qword_field("ISUB", 0x48, "FPHX");
240 acpigen_write_create_buffer_qword_field("ISUB", 0x50, "FPLX");
241 acpigen_write_create_buffer_qword_field("ISUB", 0x58, "FPTD");
242 acpigen_write_create_buffer_qword_field("ISUB", 0x60, "FPRD");
243 acpigen_write_create_buffer_qword_field("ISUB", 0x68, "HMHX");
244 acpigen_write_create_buffer_qword_field("ISUB", 0x70, "HMLX");
245 acpigen_write_create_buffer_qword_field("ISUB", 0x78, "HMTD");
246 acpigen_write_create_buffer_qword_field("ISUB", 0x80, "HMRD");
247 acpigen_write_create_buffer_qword_field("ISUB", 0x88, "HMSL");
248
249 acpigen_write_store_int_to_namestr(touch_get(dev, dev_hidi2c.intf.hidi2c.addr), "DADR");
250 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, connection_speed), "DSPD");
251 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, addr_mode), "DADM");
252 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, sm_scl_high_period), "SMHX");
253 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, sm_scl_low_period), "SMLX");
254 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, sm_sda_hold_tx_period), "SMTD");
255 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, sm_sda_hold_rx_period), "SMRD");
256 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, fm_scl_high_period), "FMHX");
257 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, fm_scl_low_period), "FMLX");
258 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, fm_sda_hold_tx_period), "FMTD");
259 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, fm_sda_hold_rx_period), "FMRD");
260 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, suppressed_spikes_s_f_fp), "FMSL");
261 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, fmp_scl_high_period), "FPHX");
262 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, fmp_scl_low_period), "FPLX");
263 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, fmp_sda_hold_tx_period), "FPTD");
264 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, fmp_sda_hold_rx_period), "FPRD");
265 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, hm_scl_high_period), "HMHX");
266 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, hm_scl_low_period), "HMLX");
267 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, hm_sda_hold_tx_period), "HMTD");
268 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, hm_sda_hold_rx_period), "HMRD");
269 acpigen_write_store_int_to_namestr(touch_soc_get(dev, hidi2c, suppressed_spikes_h_fp), "HMSL");
270
271 dsd_pkg_cnt = 4;
272 if (touch_get(dev, add_acpi_dma_property))
273 dsd_pkg_cnt += 2;
274
275 acpigen_write_name("_DSD");
276 acpigen_write_package(dsd_pkg_cnt);
277 {
278 acpigen_write_uuid(ACPI_DP_UUID);
279 acpigen_write_package(1);
280 {
281 acpigen_write_package(2);
282 {
283 acpigen_write_string("ICRS");
284 acpigen_emit_namestring("ICRS");
285 }
286 acpigen_pop_len();
287 }
288 acpigen_pop_len();
289 if (touch_get(dev, add_acpi_dma_property)) {
290 acpigen_write_uuid(ACPI_DSD_DMA_PROPERTY_UUID);
291 acpigen_write_package(1);
292 {
293 acpigen_write_package(2);
294 {
295 acpigen_write_string(ACPI_DSD_DMA_PROPERTY_NAME);
296 acpigen_write_integer(1);
297 }
298 acpigen_pop_len();
299 }
300 acpigen_pop_len();
301 }
302 acpigen_write_uuid(ACPI_DP_CHILD_UUID);
303 acpigen_write_package(1);
304 {
305 acpigen_write_package(2);
306 {
307 acpigen_write_string("ISUB");
308 acpigen_emit_namestring("ISUB");
309 }
310 acpigen_pop_len();
311 }
312 acpigen_pop_len();
313 }
314 acpigen_pop_len(); /* Name */
315 }
316
317 static void touch_generate_acpi_method_status(const struct drivers_intel_touch_config *config,
318 const struct device *dev)
319 {
320 const struct acpi_gpio *gpio;
321
322 acpigen_write_method("_STA", 0);
323 {
324 if (config->connected_device != TH_SENSOR_NONE) {
325 /* Use enable GPIO for status if provided, otherwise use reset GPIO. */
326 if (config->enable_gpio.pin_count) {
327 gpio = &config->enable_gpio;
328 /* Read current GPIO state into Local0. */
329 acpigen_get_tx_gpio(gpio);
330 } else {
331 gpio = &config->reset_gpio;
332 /* Read current GPIO state into Local0. */
333 acpigen_get_tx_gpio(gpio);
334 acpigen_write_not(LOCAL0_OP, LOCAL0_OP);
335 }
336 acpigen_write_return_op(LOCAL0_OP);
337 } else {
338 acpigen_write_integer(0);
339 }
340 }
341 acpigen_write_method_end(); /* Method */
342 }
343
344 static void touch_generate_acpi_method_on(const struct drivers_intel_touch_config *config,
345 const struct device *dev)
346 {
347 const struct device *parent_dev = dev->upstream->dev;
348 const char *mutex_path = acpi_device_path_join(parent_dev, TOUCH_MUTEX);
349
350 printk(BIOS_DEBUG, "%s: generating _ON() mutex = %s\n", touch_acpi_name(dev),
351 mutex_path);
352 acpigen_write_method_serialized("_ON", 0);
353 {
354 acpigen_write_debug_sprintf("%s: _ON()\n", touch_acpi_name(dev));
355 if (config->connected_device != TH_SENSOR_GENERIC) {
356 /* if wake is enabled, we don't manage power enabling and reset */
357 if (config->wake_on_touch) {
358 acpigen_write_debug_sprintf("%s: empty _ON() since wake is enabled.\n",
359 touch_acpi_name(dev));
360 } else {
361 acpigen_write_acquire(mutex_path, ACPI_MUTEX_NO_TIMEOUT);
362 acpigen_write_debug_sprintf("%s: _ON() mutex acquired.\n",
363 touch_acpi_name(dev));
364 /* ex: SOC_TCHSCR_RST_R_L */
365 if (config->reset_gpio.pin_count) {
366 acpigen_enable_tx_gpio(&config->reset_gpio);
367 }
368 /* ex: EN_TCHSCR_PWR */
369 if (config->enable_gpio.pin_count) {
370 acpigen_enable_tx_gpio(&config->enable_gpio);
371 if (config->enable_delay_ms)
372 acpigen_write_sleep(config->enable_delay_ms);
373 }
374 /* ex: SOC_TCHSCR_RST_R_L */
375 if (config->reset_gpio.pin_count) {
376 acpigen_disable_tx_gpio(&config->reset_gpio);
377 if (config->reset_delay_ms)
378 acpigen_write_sleep(config->reset_delay_ms);
379 }
380 /* ex: SOC_TCHSCR_RPT_EN */
381 if (config->report_gpio.pin_count) {
382 acpigen_enable_tx_gpio(&config->report_gpio);
383 if (config->report_delay_ms)
384 acpigen_write_sleep(config->report_delay_ms);
385 }
386 acpigen_write_release(mutex_path);
387 }
388 }
389 acpigen_write_debug_sprintf("%s: _ON() completed\n", touch_acpi_name(dev));
390 }
391 acpigen_write_method_end();
392 }
393
394 static void touch_generate_acpi_method_off(const struct drivers_intel_touch_config *config,
395 const struct device *dev)
396 {
397 const struct device *parent_dev = dev->upstream->dev;
398 const char *mutex_path = acpi_device_path_join(parent_dev, TOUCH_MUTEX);
399
400 acpigen_write_method_serialized("_OFF", 0);
401 {
402 acpigen_write_debug_sprintf("%s: _OFF()\n", touch_acpi_name(dev));
403 if (config->connected_device != TH_SENSOR_GENERIC) {
404 /* if wake is enabled, we don't manage power enabling and reset */
405 if (config->wake_on_touch) {
406 acpigen_write_debug_sprintf("%s: empty _OFF() since wake is enabled.\n",
407 touch_acpi_name(dev));
408 } else {
409 acpigen_write_acquire(mutex_path, ACPI_MUTEX_NO_TIMEOUT);
410 acpigen_write_debug_sprintf("%s: _OFF() mutex acquired.\n",
411 touch_acpi_name(dev));
412 /* ex: SOC_TCHSCR_RPT_EN */
413 if (config->report_gpio.pin_count) {
414 acpigen_disable_tx_gpio(&config->report_gpio);
415 if (config->report_off_delay_ms)
416 acpigen_write_sleep(config->report_off_delay_ms);
417 }
418 /* ex: SOC_TCHSCR_RST_R_L */
419 if (config->reset_gpio.pin_count) {
420 acpigen_enable_tx_gpio(&config->reset_gpio);
421 if (config->reset_off_delay_ms)
422 acpigen_write_sleep(config->reset_off_delay_ms);
423 }
424 /* ex: ==> EN_TCHSCR_PWR */
425 if (config->enable_gpio.pin_count) {
426 acpigen_disable_tx_gpio(&config->enable_gpio);
427 if (config->enable_off_delay_ms)
428 acpigen_write_sleep(config->enable_off_delay_ms);
429 }
430 acpigen_write_release(mutex_path);
431 }
432 }
433 acpigen_write_debug_sprintf("%s: _OFF() completed\n", touch_acpi_name(dev));
434 }
435 acpigen_write_method_end();
436 }
437
438 static void touch_generate_acpi_spidev_rst(const struct drivers_intel_touch_config *config,
439 const struct device *dev)
440 {
441 acpigen_write_method_serialized("_RST", 0);
442 {
443 acpigen_write_debug_sprintf("%s: _RST()\n", touch_acpi_name(dev));
444 if (config->soc_hidspi.reset_gpio.pin_count) {
445 acpigen_write_acquire(TOUCH_MUTEX, ACPI_MUTEX_NO_TIMEOUT);
446 acpigen_write_debug_sprintf("%s: _RST() mutex acquired.\n",
447 touch_acpi_name(dev));
448 /* Assert RESET# GPIO. */
449 acpigen_enable_tx_gpio(&config->soc_hidspi.reset_gpio);
450 /* Note: use 300 for debug */
451 acpigen_write_sleep(touch_soc_get(dev, hidspi, reset_sequencing_delay));
452 /* De-assert RESET# GPIO. */
453 acpigen_disable_tx_gpio(&config->soc_hidspi.reset_gpio);
454 acpigen_write_sleep(100); /* Note: use 100 for now */
455 acpigen_write_release(TOUCH_MUTEX);
456 } else
457 acpigen_write_debug_sprintf("%s: _RST() empty method\n",
458 touch_acpi_name(dev));
459 acpigen_write_debug_sprintf("%s: _RST() completed\n", touch_acpi_name(dev));
460 }
461 acpigen_write_method_end(); /* Method */
462 }
463
464 static void touch_dev_fill_ssdt_generator(const struct device *dev)
465 {
466 _soc_hidi2c_info = soc_get_thc_hidi2c_info();
467 _soc_hidspi_info = soc_get_thc_hidspi_info();
468
469 const struct drivers_intel_touch_config *config = dev->chip_info;
470 const struct device *parent = dev->upstream->dev;
471 DEVTREE_CONST struct device *domain = dev_find_path(NULL, DEVICE_PATH_DOMAIN);
472 const char *scope = acpi_device_path(parent);
473 const char *domain_scope = acpi_device_path(domain);
474
475 static const char *const power_res_states[] = {"_PR0", "_PR3"};
476
477 if (!config)
478 return;
479
480 if (!is_dev_enabled(parent)) {
481 printk(BIOS_ERR, "%s: touch controller is not enabled\n", __func__);
482 return;
483 }
484 if (!scope) {
485 printk(BIOS_ERR, "%s: touch controller scope not found\n", __func__);
486 return;
487 }
488 if (config->mode == THC_HID_I2C_MODE && !_soc_hidi2c_info) {
489 printk(BIOS_ERR, "%s: %s Missing THC SoC-specific config for HID-I2C.\n",
490 __func__, touch_acpi_name(dev));
491 return;
492 }
493 if (config->mode == THC_HID_SPI_MODE && !_soc_hidspi_info) {
494 printk(BIOS_ERR, "%s: %s Missing THC SoC-specific config for HID-SPI.\n",
495 __func__, touch_acpi_name(dev));
496 return;
497 }
498 printk(BIOS_DEBUG, "Fill touch ACPIs: domain scope=%s scope=%s touch dev=%s type=%d\n",
499 domain_scope, scope, touch_acpi_name(dev), dev->path.type);
500
501 acpigen_write_scope(domain_scope);
502 {
503 acpigen_write_device(touch_acpi_name(dev));
504 {
505 acpigen_write_ADR_pci_device(parent);
506 acpigen_write_mutex(TOUCH_MUTEX, 0);
507
508 if (config->connected_device != TH_SENSOR_NONE)
509 touch_generate_acpi_crs(config, dev);
510 touch_generate_acpi_ini(dev);
511 touch_generate_acpi_dsm(config, dev);
512 /* When only THC1 is used, both THC0/1 need to be enabled since THC0's
513 device function is '0'. In this case, THC0 should set
514 connected_device to TH_SENSOR_NONE so that when the driver detects
515 THC0, the _DSM will be available for it to check and exit without
516 error. */
517 if (config->connected_device == TH_SENSOR_NONE)
518 return;
519
520 if (config->mode == THC_HID_I2C_MODE) {
521 touch_generate_acpi_i2cdev_dsd(dev);
522 } else {
523 /* Create _DSD with only DmaProperty */
524 if (touch_get(dev, add_acpi_dma_property))
525 acpi_device_add_dma_property(NULL);
526 }
527 if (config->enable_gpio.pin_count || config->reset_gpio.pin_count) {
528 printk(BIOS_DEBUG, "%s generating ACPI power resource.\n",
529 touch_acpi_name(dev));
530 /* ACPI Power Resource for controlling the attached device
531 power. */
532 acpigen_write_power_res("THPR", 0, 0, power_res_states,
533 ARRAY_SIZE(power_res_states));
534 {
535 touch_generate_acpi_method_status(config, dev);
536 touch_generate_acpi_method_on(config, dev);
537 touch_generate_acpi_method_off(config, dev);
538 }
539 acpigen_write_power_res_end(); /* PowerResource */
540 }
541 if (config->mode == THC_HID_SPI_MODE)
542 touch_generate_acpi_spidev_rst(config, dev);
543 }
544 acpigen_write_device_end(); /* Device */
545 }
546 acpigen_write_scope_end(); /* Scope */
547 }
548
549 static struct device_operations touch_dev_ops = {
550 .read_resources = noop_read_resources,
551 .set_resources = noop_set_resources,
552 .acpi_fill_ssdt = touch_dev_fill_ssdt_generator,
553 .acpi_name = touch_acpi_name
554 };
555
556 static void touch_dev_enable(struct device *dev)
557 {
558 /* This dev is a generic device that is a child to the THC device */
559 dev->ops = &touch_dev_ops;
560 }
561
562 /* Copy of default_pci_ops_dev with scan_bus addition */
563 static const struct device_operations pci_thc_device_ops = {
564 .read_resources = pci_dev_read_resources,
565 .set_resources = pci_dev_set_resources,
566 .enable_resources = pci_dev_enable_resources,
567 .init = pci_dev_init,
568 .scan_bus = scan_generic_bus, /* Non-default */
569 .ops_pci = &pci_dev_ops_pci
570 };
571
572 static const unsigned short pci_device_ids[] = {
573 PCI_DID_INTEL_MTL_THC0_SPI,
574 PCI_DID_INTEL_MTL_THC1_SPI,
575 PCI_DID_INTEL_PTL_U_H_THC0_I2C,
576 PCI_DID_INTEL_PTL_U_H_THC0_SPI,
577 PCI_DID_INTEL_PTL_U_H_THC1_I2C,
578 PCI_DID_INTEL_PTL_U_H_THC1_SPI,
579 PCI_DID_INTEL_PTL_H_THC0_I2C,
580 PCI_DID_INTEL_PTL_H_THC0_SPI,
581 PCI_DID_INTEL_PTL_H_THC1_I2C,
582 PCI_DID_INTEL_PTL_H_THC1_SPI,
583 PCI_DID_INTEL_WCL_THC0_I2C,
584 PCI_DID_INTEL_WCL_THC0_SPI,
585 PCI_DID_INTEL_WCL_THC1_I2C,
586 PCI_DID_INTEL_WCL_THC1_SPI,
587 0
588 };
589
590 static const struct pci_driver intel_touch_driver __pci_driver = {
591 .ops = &pci_thc_device_ops,
592 .vendor = PCI_VID_INTEL,
593 .devices = pci_device_ids
594 };
595
596 struct chip_operations drivers_intel_touch_ops = {
597 .name = "Intel Touch Controller & Sensor Device",
598 .enable_dev = touch_dev_enable
599 };