blob: 3443f5cd23b6f88b350f47431014a3d2c4a12df6 [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
Gwendal Grignou145ef872018-07-03 14:31:31 -070025#define I2C_SX9310_ACPI_ID "STH9310"
Enrico Granata76a1f492018-06-20 13:01:45 -070026#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,
Furquan Shaikha7e92502018-06-22 10:15:04 -070039 .speed = I2C_SPEED_FAST,
Enrico Granata76a1f492018-06-20 13:01:45 -070040 .resource = scope,
41 };
42 struct acpi_dp *dsd;
43
44 if (!dev->enabled || !scope || !config)
45 return;
46
Furquan Shaikha7e92502018-06-22 10:15:04 -070047 if (config->speed)
48 i2c.speed = config->speed;
49
Enrico Granata76a1f492018-06-20 13:01:45 -070050 /* Device */
51 acpigen_write_scope(scope);
52 acpigen_write_device(acpi_device_name(dev));
53 acpigen_write_name_string("_HID", I2C_SX9310_ACPI_ID);
54 acpigen_write_name_integer("_UID", config->uid);
55 acpigen_write_name_string("_DDN", config->desc);
56 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
57
58 /* Resources */
59 acpigen_write_name("_CRS");
60 acpigen_write_resourcetemplate_header();
61 acpi_device_write_i2c(&i2c);
62 acpi_device_write_interrupt(&config->irq);
63 acpigen_write_resourcetemplate_footer();
64
65 /* DSD */
66 dsd = acpi_dp_new_table("_DSD");
67#include "registers.h"
68 acpi_dp_write(dsd);
69
70 acpigen_pop_len(); /* Device */
71 acpigen_pop_len(); /* Scope */
72}
73
74#undef REGISTER
75
76static const char *i2c_sx9310_acpi_name(const struct device *dev)
77{
78 static char name[5];
79
80 snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device);
81 return name;
82}
83
84static struct device_operations i2c_sx9310_ops = {
85 .read_resources = DEVICE_NOOP,
86 .set_resources = DEVICE_NOOP,
87 .enable_resources = DEVICE_NOOP,
88 .acpi_name = &i2c_sx9310_acpi_name,
89 .acpi_fill_ssdt_generator = &i2c_sx9310_fill_ssdt,
90};
91
92static void i2c_sx9310_enable(struct device *dev)
93{
94 struct drivers_i2c_sx9310_config *config = dev->chip_info;
95
96 if (!config) {
97 dev->enabled = 0;
98 return;
99 }
100
101 dev->ops = &i2c_sx9310_ops;
102
103 if (config->desc)
104 dev->name = config->desc;
105}
106
107struct chip_operations drivers_i2c_sx9310_ops = {
108 CHIP_NAME(I2C_SX9310_ACPI_NAME)
109 .enable_dev = &i2c_sx9310_enable
110};