Eric Lai | f9ed4d2 | 2020-11-16 15:38:53 +0800 | [diff] [blame] | 1 | /* 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> |
Elyes Haouas | bdd03c2 | 2024-05-27 11:20:07 +0200 | [diff] [blame] | 8 | #include <stdio.h> |
Elyes Haouas | 08375b5 | 2024-05-27 11:36:52 +0200 | [diff] [blame^] | 9 | |
Eric Lai | f9ed4d2 | 2020-11-16 15:38:53 +0800 | [diff] [blame] | 10 | #include "chip.h" |
| 11 | |
| 12 | #define I2C_SX9324_ACPI_ID "STH9324" |
| 13 | #define I2C_SX9324_CHIP_NAME "Semtech SX9324" |
| 14 | |
| 15 | #define REGISTER(NAME) acpi_dp_add_integer(dsd, \ |
| 16 | I2C_SX9324_ACPI_ID "," #NAME, \ |
| 17 | config->NAME) |
| 18 | |
| 19 | static void i2c_sx9324_fill_ssdt(const struct device *dev) |
| 20 | { |
| 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, |
| 27 | .resource = scope, |
| 28 | }; |
| 29 | struct acpi_dp *dsd; |
| 30 | |
| 31 | if (!scope || !config) |
| 32 | return; |
| 33 | |
| 34 | if (config->speed) |
| 35 | i2c.speed = config->speed; |
| 36 | |
| 37 | /* Device */ |
| 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)); |
| 44 | |
| 45 | /* Resources */ |
| 46 | acpigen_write_name("_CRS"); |
| 47 | acpigen_write_resourcetemplate_header(); |
| 48 | acpi_device_write_i2c(&i2c); |
| 49 | |
| 50 | if (config->irq_gpio.pin_count) |
| 51 | acpi_device_write_gpio(&config->irq_gpio); |
| 52 | else |
| 53 | acpi_device_write_interrupt(&config->irq); |
| 54 | |
| 55 | acpigen_write_resourcetemplate_footer(); |
| 56 | |
| 57 | /* DSD */ |
| 58 | dsd = acpi_dp_new_table("_DSD"); |
Victor Ding | 20265b09 | 2022-11-02 08:24:41 +0000 | [diff] [blame] | 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) |
Eric Lai | f9ed4d2 | 2020-11-16 15:38:53 +0800 | [diff] [blame] | 74 | #include "registers.h" |
Victor Ding | 20265b09 | 2022-11-02 08:24:41 +0000 | [diff] [blame] | 75 | #endif |
Eric Lai | f9ed4d2 | 2020-11-16 15:38:53 +0800 | [diff] [blame] | 76 | acpi_dp_write(dsd); |
| 77 | |
| 78 | acpigen_pop_len(); /* Device */ |
| 79 | acpigen_pop_len(); /* Scope */ |
| 80 | |
| 81 | printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), |
| 82 | config->desc ? : dev->chip_ops->name, dev_path(dev)); |
| 83 | } |
| 84 | |
| 85 | #undef REGISTER |
| 86 | |
| 87 | static const char *i2c_sx9324_acpi_name(const struct device *dev) |
| 88 | { |
| 89 | static char name[5]; |
| 90 | |
| 91 | snprintf(name, sizeof(name), "SX%02.2X", dev->path.i2c.device); |
| 92 | return name; |
| 93 | } |
| 94 | |
| 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, |
| 100 | }; |
| 101 | |
| 102 | static void i2c_sx9324_enable(struct device *dev) |
| 103 | { |
| 104 | struct drivers_i2c_sx9324_config *config = dev->chip_info; |
| 105 | |
| 106 | if (!config) { |
| 107 | dev->enabled = 0; |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | dev->ops = &i2c_sx9324_ops; |
| 112 | |
| 113 | if (config->desc) |
| 114 | dev->name = config->desc; |
| 115 | } |
| 116 | |
| 117 | struct chip_operations drivers_i2c_sx9324_ops = { |
Nicholas Sudsgaard | bfb11be | 2024-01-30 09:53:46 +0900 | [diff] [blame] | 118 | .name = I2C_SX9324_CHIP_NAME, |
Eric Lai | f9ed4d2 | 2020-11-16 15:38:53 +0800 | [diff] [blame] | 119 | .enable_dev = i2c_sx9324_enable |
| 120 | }; |