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_SX9360_ACPI_ID "STH9360"
13 #define I2C_SX9360_CHIP_NAME "Semtech SX9360"
15 static void i2c_sx9360_fill_ssdt(const struct device
*dev
)
17 struct drivers_i2c_sx9360_config
*config
= dev
->chip_info
;
18 const char *scope
= acpi_device_scope(dev
);
19 struct acpi_i2c i2c
= {
20 .address
= dev
->path
.i2c
.device
,
21 .mode_10bit
= dev
->path
.i2c
.mode_10bit
,
22 .speed
= I2C_SPEED_FAST
,
27 if (!scope
|| !config
)
31 i2c
.speed
= config
->speed
;
34 acpigen_write_scope(scope
);
35 acpigen_write_device(acpi_device_name(dev
));
36 acpigen_write_name_string("_HID", I2C_SX9360_ACPI_ID
);
37 acpigen_write_name_integer("_UID", config
->uid
);
38 acpigen_write_name_string("_DDN", config
->desc
);
39 acpigen_write_STA(acpi_device_status(dev
));
42 acpigen_write_name("_CRS");
43 acpigen_write_resourcetemplate_header();
44 acpi_device_write_i2c(&i2c
);
46 if (config
->irq_gpio
.pin_count
)
47 acpi_device_write_gpio(&config
->irq_gpio
);
49 acpi_device_write_interrupt(&config
->irq
);
51 acpigen_write_resourcetemplate_footer();
54 dsd
= acpi_dp_new_table("_DSD");
57 * Format described in linux kernel documentation. See
58 * https://www.kernel.org/doc/Documentation/devicetree/bindings/iio/proximity/semtech%2Csx9360.yaml
60 acpi_dp_add_integer(dsd
, "semtech,proxraw-strength",
61 config
->proxraw_strength
);
62 acpi_dp_add_integer(dsd
, "semtech,avg-pos-strength",
63 config
->avg_pos_strength
);
64 acpi_dp_add_integer(dsd
, "semtech,resolution",
69 acpigen_pop_len(); /* Device */
70 acpigen_pop_len(); /* Scope */
72 printk(BIOS_INFO
, "%s: %s at %s\n", acpi_device_path(dev
),
73 config
->desc
? : dev
->chip_ops
->name
, dev_path(dev
));
76 static const char *i2c_sx9360_acpi_name(const struct device
*dev
)
80 snprintf(name
, sizeof(name
), "SX%02.2X", dev
->path
.i2c
.device
);
84 static struct device_operations i2c_sx9360_ops
= {
85 .read_resources
= noop_read_resources
,
86 .set_resources
= noop_set_resources
,
87 .acpi_name
= i2c_sx9360_acpi_name
,
88 .acpi_fill_ssdt
= i2c_sx9360_fill_ssdt
,
91 static void i2c_sx9360_enable(struct device
*dev
)
93 struct drivers_i2c_sx9360_config
*config
= config_of(dev
);
95 if (!is_dev_enabled(dev
))
98 dev
->ops
= &i2c_sx9360_ops
;
101 dev
->name
= config
->desc
;
104 struct chip_operations drivers_i2c_sx9360_ops
= {
105 .name
= I2C_SX9360_CHIP_NAME
,
106 .enable_dev
= i2c_sx9360_enable