1 /* SPDX-License-Identifier: GPL-2.0-only */
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>
12 #define I2C_SX9324_ACPI_ID "STH9324"
13 #define I2C_SX9324_CHIP_NAME "Semtech SX9324"
15 #define REGISTER(NAME) acpi_dp_add_integer(dsd, \
16 I2C_SX9324_ACPI_ID "," #NAME, \
19 static void i2c_sx9324_fill_ssdt(const struct device
*dev
)
21 struct drivers_i2c_sx9324_config
*config
= dev
->chip_info
;
22 const char *scope
= acpi_device_scope(dev
);
23 struct acpi_i2c i2c
= {
24 .address
= dev
->path
.i2c
.device
,
25 .mode_10bit
= dev
->path
.i2c
.mode_10bit
,
26 .speed
= I2C_SPEED_FAST
,
31 if (!scope
|| !config
)
35 i2c
.speed
= config
->speed
;
38 acpigen_write_scope(scope
);
39 acpigen_write_device(acpi_device_name(dev
));
40 acpigen_write_name_string("_HID", I2C_SX9324_ACPI_ID
);
41 acpigen_write_name_integer("_UID", config
->uid
);
42 acpigen_write_name_string("_DDN", config
->desc
);
43 acpigen_write_STA(acpi_device_status(dev
));
46 acpigen_write_name("_CRS");
47 acpigen_write_resourcetemplate_header();
48 acpi_device_write_i2c(&i2c
);
50 if (config
->irq_gpio
.pin_count
)
51 acpi_device_write_gpio(&config
->irq_gpio
);
53 acpi_device_write_interrupt(&config
->irq
);
55 acpigen_write_resourcetemplate_footer();
58 dsd
= acpi_dp_new_table("_DSD");
59 acpi_dp_add_integer_array(dsd
, "semtech,ph0-pin", config
->ph0_pin
, ARRAY_SIZE(config
->ph0_pin
));
60 acpi_dp_add_integer_array(dsd
, "semtech,ph1-pin", config
->ph1_pin
, ARRAY_SIZE(config
->ph1_pin
));
61 acpi_dp_add_integer_array(dsd
, "semtech,ph2-pin", config
->ph2_pin
, ARRAY_SIZE(config
->ph2_pin
));
62 acpi_dp_add_integer_array(dsd
, "semtech,ph3-pin", config
->ph3_pin
, ARRAY_SIZE(config
->ph3_pin
));
63 acpi_dp_add_integer(dsd
, "semtech,ph01-resolution", config
->ph01_resolution
);
64 acpi_dp_add_integer(dsd
, "semtech,ph23-resolution", config
->ph23_resolution
);
65 acpi_dp_add_integer(dsd
, "semtech,startup-sensor", config
->startup_sensor
);
66 acpi_dp_add_integer(dsd
, "semtech,ph01-proxraw-strength", config
->ph01_proxraw_strength
);
67 acpi_dp_add_integer(dsd
, "semtech,ph23-proxraw-strength", config
->ph23_proxraw_strength
);
68 acpi_dp_add_integer(dsd
, "semtech,avg-pos-strength", config
->avg_pos_strength
);
69 acpi_dp_add_integer(dsd
, "semtech,input-precharge-resistor-ohms", config
->input_precharge_resistor_ohms
);
70 acpi_dp_add_integer(dsd
, "semtech,input-analog-gain", config
->input_analog_gain
);
71 acpi_dp_add_string(dsd
, "semtech,cs-idle-sleep", config
->cs_idle_sleep
);
72 acpi_dp_add_string(dsd
, "semtech,int-comp-resistor", config
->int_comp_resistor
);
73 #if CONFIG(DRIVERS_I2C_SX9324_SUPPORT_LEGACY_LINUX_DRIVER)
74 #include "registers.h"
78 acpigen_pop_len(); /* Device */
79 acpigen_pop_len(); /* Scope */
81 printk(BIOS_INFO
, "%s: %s at %s\n", acpi_device_path(dev
),
82 config
->desc
? : dev
->chip_ops
->name
, dev_path(dev
));
87 static const char *i2c_sx9324_acpi_name(const struct device
*dev
)
91 snprintf(name
, sizeof(name
), "SX%02.2X", dev
->path
.i2c
.device
);
95 static struct device_operations i2c_sx9324_ops
= {
96 .read_resources
= noop_read_resources
,
97 .set_resources
= noop_set_resources
,
98 .acpi_name
= i2c_sx9324_acpi_name
,
99 .acpi_fill_ssdt
= i2c_sx9324_fill_ssdt
,
102 static void i2c_sx9324_enable(struct device
*dev
)
104 struct drivers_i2c_sx9324_config
*config
= dev
->chip_info
;
111 dev
->ops
= &i2c_sx9324_ops
;
114 dev
->name
= config
->desc
;
117 struct chip_operations drivers_i2c_sx9324_ops
= {
118 .name
= I2C_SX9324_CHIP_NAME
,
119 .enable_dev
= i2c_sx9324_enable