Duncan Laurie | a12fc81 | 2016-12-13 16:43:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2016 Google 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; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <arch/acpigen_dsm.h> |
| 17 | #include <device/device.h> |
| 18 | #include <stdint.h> |
| 19 | #include <string.h> |
| 20 | #include "chip.h" |
| 21 | |
| 22 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
| 23 | static void i2c_hid_fill_dsm(struct device *dev) |
| 24 | { |
| 25 | struct drivers_i2c_hid_config *config = dev->chip_info; |
| 26 | struct dsm_i2c_hid_config dsm_config = { |
| 27 | .hid_desc_reg_offset = config->hid_desc_reg_offset, |
| 28 | }; |
| 29 | |
| 30 | acpigen_write_dsm_i2c_hid(&dsm_config); |
| 31 | } |
| 32 | |
| 33 | static void i2c_hid_fill_ssdt_generator(struct device *dev) |
| 34 | { |
| 35 | struct drivers_i2c_hid_config *config = dev->chip_info; |
| 36 | config->generic.cid = I2C_HID_CID; |
| 37 | i2c_generic_fill_ssdt(dev, &i2c_hid_fill_dsm, &config->generic); |
| 38 | } |
| 39 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 40 | static const char *i2c_hid_acpi_name(const struct device *dev) |
Duncan Laurie | a12fc81 | 2016-12-13 16:43:40 -0800 | [diff] [blame] | 41 | { |
| 42 | static char name[5]; |
| 43 | snprintf(name, sizeof(name), "H%03.3X", dev->path.i2c.device); |
| 44 | name[4] = '\0'; |
| 45 | return name; |
| 46 | } |
| 47 | #endif |
| 48 | |
| 49 | static struct device_operations i2c_hid_ops = { |
| 50 | .read_resources = DEVICE_NOOP, |
| 51 | .set_resources = DEVICE_NOOP, |
| 52 | .enable_resources = DEVICE_NOOP, |
| 53 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
| 54 | .acpi_name = &i2c_hid_acpi_name, |
| 55 | .acpi_fill_ssdt_generator = &i2c_hid_fill_ssdt_generator, |
| 56 | #endif |
| 57 | }; |
| 58 | |
| 59 | static void i2c_hid_enable(struct device *dev) |
| 60 | { |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame^] | 61 | struct drivers_i2c_hid_config *config = dev->chip_info; |
| 62 | |
Duncan Laurie | a12fc81 | 2016-12-13 16:43:40 -0800 | [diff] [blame] | 63 | dev->ops = &i2c_hid_ops; |
Naresh G Solanki | 69e9e71 | 2018-06-04 17:45:19 +0530 | [diff] [blame^] | 64 | |
| 65 | if (config && config->generic.desc) { |
| 66 | dev->name = config->generic.desc; |
| 67 | } |
Duncan Laurie | a12fc81 | 2016-12-13 16:43:40 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | struct chip_operations drivers_i2c_hid_ops = { |
| 71 | CHIP_NAME("I2C HID Device") |
| 72 | .enable_dev = &i2c_hid_enable |
| 73 | }; |