blob: 966726fc8d3ef2db832ead738552f805d801bf39 [file] [log] [blame]
Eric Laif9ed4d22020-11-16 15:38:53 +08001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <acpi/acpi_device.h>
4#include <acpi/acpigen.h>
5#include <console/console.h>
6#include <device/i2c_simple.h>
7#include <device/device.h>
Eric Laif9ed4d22020-11-16 15:38:53 +08008#include <string.h>
9#include "chip.h"
10
11#define I2C_SX9324_ACPI_ID "STH9324"
12#define I2C_SX9324_CHIP_NAME "Semtech SX9324"
13
14#define REGISTER(NAME) acpi_dp_add_integer(dsd, \
15 I2C_SX9324_ACPI_ID "," #NAME, \
16 config->NAME)
17
18static void i2c_sx9324_fill_ssdt(const struct device *dev)
19{
20 struct drivers_i2c_sx9324_config *config = dev->chip_info;
21 const char *scope = acpi_device_scope(dev);
22 struct acpi_i2c i2c = {
23 .address = dev->path.i2c.device,
24 .mode_10bit = dev->path.i2c.mode_10bit,
25 .speed = I2C_SPEED_FAST,
26 .resource = scope,
27 };
28 struct acpi_dp *dsd;
29
30 if (!scope || !config)
31 return;
32
33 if (config->speed)
34 i2c.speed = config->speed;
35
36 /* Device */
37 acpigen_write_scope(scope);
38 acpigen_write_device(acpi_device_name(dev));
39 acpigen_write_name_string("_HID", I2C_SX9324_ACPI_ID);
40 acpigen_write_name_integer("_UID", config->uid);
41 acpigen_write_name_string("_DDN", config->desc);
42 acpigen_write_STA(acpi_device_status(dev));
43
44 /* Resources */
45 acpigen_write_name("_CRS");
46 acpigen_write_resourcetemplate_header();
47 acpi_device_write_i2c(&i2c);
48
49 if (config->irq_gpio.pin_count)
50 acpi_device_write_gpio(&config->irq_gpio);
51 else
52 acpi_device_write_interrupt(&config->irq);
53
54 acpigen_write_resourcetemplate_footer();
55
56 /* DSD */
57 dsd = acpi_dp_new_table("_DSD");
Victor Ding20265b092022-11-02 08:24:41 +000058 acpi_dp_add_integer_array(dsd, "semtech,ph0-pin", config->ph0_pin, ARRAY_SIZE(config->ph0_pin));
59 acpi_dp_add_integer_array(dsd, "semtech,ph1-pin", config->ph1_pin, ARRAY_SIZE(config->ph1_pin));
60 acpi_dp_add_integer_array(dsd, "semtech,ph2-pin", config->ph2_pin, ARRAY_SIZE(config->ph2_pin));
61 acpi_dp_add_integer_array(dsd, "semtech,ph3-pin", config->ph3_pin, ARRAY_SIZE(config->ph3_pin));
62 acpi_dp_add_integer(dsd, "semtech,ph01-resolution", config->ph01_resolution);
63 acpi_dp_add_integer(dsd, "semtech,ph23-resolution", config->ph23_resolution);
64 acpi_dp_add_integer(dsd, "semtech,startup-sensor", config->startup_sensor);
65 acpi_dp_add_integer(dsd, "semtech,ph01-proxraw-strength", config->ph01_proxraw_strength);
66 acpi_dp_add_integer(dsd, "semtech,ph23-proxraw-strength", config->ph23_proxraw_strength);
67 acpi_dp_add_integer(dsd, "semtech,avg-pos-strength", config->avg_pos_strength);
68 acpi_dp_add_integer(dsd, "semtech,input-precharge-resistor-ohms", config->input_precharge_resistor_ohms);
69 acpi_dp_add_integer(dsd, "semtech,input-analog-gain", config->input_analog_gain);
70 acpi_dp_add_string(dsd, "semtech,cs-idle-sleep", config->cs_idle_sleep);
71 acpi_dp_add_string(dsd, "semtech,int-comp-resistor", config->int_comp_resistor);
72#if CONFIG(DRIVERS_I2C_SX9324_SUPPORT_LEGACY_LINUX_DRIVER)
Eric Laif9ed4d22020-11-16 15:38:53 +080073#include "registers.h"
Victor Ding20265b092022-11-02 08:24:41 +000074#endif
Eric Laif9ed4d22020-11-16 15:38:53 +080075 acpi_dp_write(dsd);
76
77 acpigen_pop_len(); /* Device */
78 acpigen_pop_len(); /* Scope */
79
80 printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev),
81 config->desc ? : dev->chip_ops->name, dev_path(dev));
82}
83
84#undef REGISTER
85
86static const char *i2c_sx9324_acpi_name(const struct device *dev)
87{
88 static char name[5];
89
90 snprintf(name, sizeof(name), "SX%02.2X", dev->path.i2c.device);
91 return name;
92}
93
94static struct device_operations i2c_sx9324_ops = {
95 .read_resources = noop_read_resources,
96 .set_resources = noop_set_resources,
97 .acpi_name = i2c_sx9324_acpi_name,
98 .acpi_fill_ssdt = i2c_sx9324_fill_ssdt,
99};
100
101static void i2c_sx9324_enable(struct device *dev)
102{
103 struct drivers_i2c_sx9324_config *config = dev->chip_info;
104
105 if (!config) {
106 dev->enabled = 0;
107 return;
108 }
109
110 dev->ops = &i2c_sx9324_ops;
111
112 if (config->desc)
113 dev->name = config->desc;
114}
115
116struct chip_operations drivers_i2c_sx9324_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900117 .name = I2C_SX9324_CHIP_NAME,
Eric Laif9ed4d22020-11-16 15:38:53 +0800118 .enable_dev = i2c_sx9324_enable
119};