blob: 7da87c480a5910f28833472f2d77969dac15174c [file] [log] [blame]
Enrico Granata76a1f492018-06-20 13:01:45 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2018 Google LLC
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/acpi_device.h>
17#include <arch/acpigen.h>
18#include <device/i2c_simple.h>
19#include <device/device.h>
20#include <device/path.h>
21#include <stdint.h>
22#include <string.h>
23#include "chip.h"
24
25#define I2C_SX9310_ACPI_ID "SX9310"
26#define I2C_SX9310_ACPI_NAME "Semtech SX9310"
27
28#define REGISTER(NAME) acpi_dp_add_integer(dsd, \
29 I2C_SX9310_ACPI_ID "," #NAME, \
30 config->NAME)
31
32static void i2c_sx9310_fill_ssdt(struct device *dev)
33{
34 struct drivers_i2c_sx9310_config *config = dev->chip_info;
35 const char *scope = acpi_device_scope(dev);
36 struct acpi_i2c i2c = {
37 .address = dev->path.i2c.device,
38 .mode_10bit = dev->path.i2c.mode_10bit,
39 .speed = config->speed ? : I2C_SPEED_FAST,
40 .resource = scope,
41 };
42 struct acpi_dp *dsd;
43
44 if (!dev->enabled || !scope || !config)
45 return;
46
47 /* Device */
48 acpigen_write_scope(scope);
49 acpigen_write_device(acpi_device_name(dev));
50 acpigen_write_name_string("_HID", I2C_SX9310_ACPI_ID);
51 acpigen_write_name_integer("_UID", config->uid);
52 acpigen_write_name_string("_DDN", config->desc);
53 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
54
55 /* Resources */
56 acpigen_write_name("_CRS");
57 acpigen_write_resourcetemplate_header();
58 acpi_device_write_i2c(&i2c);
59 acpi_device_write_interrupt(&config->irq);
60 acpigen_write_resourcetemplate_footer();
61
62 /* DSD */
63 dsd = acpi_dp_new_table("_DSD");
64#include "registers.h"
65 acpi_dp_write(dsd);
66
67 acpigen_pop_len(); /* Device */
68 acpigen_pop_len(); /* Scope */
69}
70
71#undef REGISTER
72
73static const char *i2c_sx9310_acpi_name(const struct device *dev)
74{
75 static char name[5];
76
77 snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device);
78 return name;
79}
80
81static struct device_operations i2c_sx9310_ops = {
82 .read_resources = DEVICE_NOOP,
83 .set_resources = DEVICE_NOOP,
84 .enable_resources = DEVICE_NOOP,
85 .acpi_name = &i2c_sx9310_acpi_name,
86 .acpi_fill_ssdt_generator = &i2c_sx9310_fill_ssdt,
87};
88
89static void i2c_sx9310_enable(struct device *dev)
90{
91 struct drivers_i2c_sx9310_config *config = dev->chip_info;
92
93 if (!config) {
94 dev->enabled = 0;
95 return;
96 }
97
98 dev->ops = &i2c_sx9310_ops;
99
100 if (config->desc)
101 dev->name = config->desc;
102}
103
104struct chip_operations drivers_i2c_sx9310_ops = {
105 CHIP_NAME(I2C_SX9310_ACPI_NAME)
106 .enable_dev = &i2c_sx9310_enable
107};