blob: 9eb56c25ef8b1ab85b404a4fe94b54515239e777 [file] [log] [blame]
Duncan Lauriea12fc812016-12-13 16:43:40 -08001/*
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)
23static 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
33static 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
40static const char *i2c_hid_acpi_name(struct device *dev)
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
49static 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
59static void i2c_hid_enable(struct device *dev)
60{
61 dev->ops = &i2c_hid_ops;
62}
63
64struct chip_operations drivers_i2c_hid_ops = {
65 CHIP_NAME("I2C HID Device")
66 .enable_dev = &i2c_hid_enable
67};