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> |
| 8 | #include <device/path.h> |
| 9 | #include <string.h> |
| 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"); |
| 59 | #include "registers.h" |
| 60 | acpi_dp_write(dsd); |
| 61 | |
| 62 | acpigen_pop_len(); /* Device */ |
| 63 | acpigen_pop_len(); /* Scope */ |
| 64 | |
| 65 | printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), |
| 66 | config->desc ? : dev->chip_ops->name, dev_path(dev)); |
| 67 | } |
| 68 | |
| 69 | #undef REGISTER |
| 70 | |
| 71 | static const char *i2c_sx9324_acpi_name(const struct device *dev) |
| 72 | { |
| 73 | static char name[5]; |
| 74 | |
| 75 | snprintf(name, sizeof(name), "SX%02.2X", dev->path.i2c.device); |
| 76 | return name; |
| 77 | } |
| 78 | |
| 79 | static struct device_operations i2c_sx9324_ops = { |
| 80 | .read_resources = noop_read_resources, |
| 81 | .set_resources = noop_set_resources, |
| 82 | .acpi_name = i2c_sx9324_acpi_name, |
| 83 | .acpi_fill_ssdt = i2c_sx9324_fill_ssdt, |
| 84 | }; |
| 85 | |
| 86 | static void i2c_sx9324_enable(struct device *dev) |
| 87 | { |
| 88 | struct drivers_i2c_sx9324_config *config = dev->chip_info; |
| 89 | |
| 90 | if (!config) { |
| 91 | dev->enabled = 0; |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | dev->ops = &i2c_sx9324_ops; |
| 96 | |
| 97 | if (config->desc) |
| 98 | dev->name = config->desc; |
| 99 | } |
| 100 | |
| 101 | struct chip_operations drivers_i2c_sx9324_ops = { |
| 102 | CHIP_NAME(I2C_SX9324_CHIP_NAME) |
| 103 | .enable_dev = i2c_sx9324_enable |
| 104 | }; |