Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Duncan Laurie | a12fc81 | 2016-12-13 16:43:40 -0800 | [diff] [blame] | 3 | |
| 4 | #include <arch/acpigen_dsm.h> |
| 5 | #include <device/device.h> |
| 6 | #include <stdint.h> |
| 7 | #include <string.h> |
| 8 | #include "chip.h" |
Eric Lai | 18060d7 | 2019-04-24 14:21:04 +0800 | [diff] [blame] | 9 | #include <gpio.h> |
| 10 | #include <console/console.h> |
Duncan Laurie | a12fc81 | 2016-12-13 16:43:40 -0800 | [diff] [blame] | 11 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 12 | #if CONFIG(HAVE_ACPI_TABLES) |
Duncan Laurie | a12fc81 | 2016-12-13 16:43:40 -0800 | [diff] [blame] | 13 | static void i2c_hid_fill_dsm(struct device *dev) |
| 14 | { |
| 15 | struct drivers_i2c_hid_config *config = dev->chip_info; |
| 16 | struct dsm_i2c_hid_config dsm_config = { |
| 17 | .hid_desc_reg_offset = config->hid_desc_reg_offset, |
| 18 | }; |
| 19 | |
| 20 | acpigen_write_dsm_i2c_hid(&dsm_config); |
| 21 | } |
| 22 | |
| 23 | static void i2c_hid_fill_ssdt_generator(struct device *dev) |
| 24 | { |
| 25 | struct drivers_i2c_hid_config *config = dev->chip_info; |
| 26 | config->generic.cid = I2C_HID_CID; |
| 27 | i2c_generic_fill_ssdt(dev, &i2c_hid_fill_dsm, &config->generic); |
| 28 | } |
| 29 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 30 | static const char *i2c_hid_acpi_name(const struct device *dev) |
Duncan Laurie | a12fc81 | 2016-12-13 16:43:40 -0800 | [diff] [blame] | 31 | { |
| 32 | static char name[5]; |
| 33 | snprintf(name, sizeof(name), "H%03.3X", dev->path.i2c.device); |
| 34 | name[4] = '\0'; |
| 35 | return name; |
| 36 | } |
| 37 | #endif |
| 38 | |
| 39 | static struct device_operations i2c_hid_ops = { |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 40 | .read_resources = DEVICE_NOOP, |
| 41 | .set_resources = DEVICE_NOOP, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 42 | #if CONFIG(HAVE_ACPI_TABLES) |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 43 | .acpi_name = i2c_hid_acpi_name, |
| 44 | .acpi_fill_ssdt = i2c_hid_fill_ssdt_generator, |
Duncan Laurie | a12fc81 | 2016-12-13 16:43:40 -0800 | [diff] [blame] | 45 | #endif |
| 46 | }; |
| 47 | |
| 48 | static void i2c_hid_enable(struct device *dev) |
| 49 | { |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 50 | struct drivers_i2c_hid_config *config = dev->chip_info; |
| 51 | |
Eric Lai | 18060d7 | 2019-04-24 14:21:04 +0800 | [diff] [blame] | 52 | if (!config) |
| 53 | return; |
| 54 | |
| 55 | /* Check if device is present by reading GPIO */ |
| 56 | if (config->generic.device_present_gpio) { |
| 57 | int present = gpio_get(config->generic.device_present_gpio); |
| 58 | present ^= config->generic.device_present_gpio_invert; |
| 59 | |
| 60 | printk(BIOS_INFO, "%s is %spresent\n", |
| 61 | dev->chip_ops->name, present ? "" : "not "); |
| 62 | |
| 63 | if (!present) { |
| 64 | dev->enabled = 0; |
| 65 | return; |
| 66 | } |
| 67 | } |
| 68 | |
Duncan Laurie | a12fc81 | 2016-12-13 16:43:40 -0800 | [diff] [blame] | 69 | dev->ops = &i2c_hid_ops; |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame] | 70 | |
| 71 | if (config && config->generic.desc) { |
| 72 | dev->name = config->generic.desc; |
| 73 | } |
Duncan Laurie | a12fc81 | 2016-12-13 16:43:40 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | struct chip_operations drivers_i2c_hid_ops = { |
| 77 | CHIP_NAME("I2C HID Device") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 78 | .enable_dev = i2c_hid_enable |
Duncan Laurie | a12fc81 | 2016-12-13 16:43:40 -0800 | [diff] [blame] | 79 | }; |