Karthikeyan Ramasubramanian | cbc29a2 | 2020-09-30 17:04:15 -0600 | [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/device.h> |
| 7 | #include <device/path.h> |
Karthikeyan Ramasubramanian | cbc29a2 | 2020-09-30 17:04:15 -0600 | [diff] [blame] | 8 | #include <string.h> |
Elyes HAOUAS | 84bd9dc | 2021-12-31 18:45:17 +0100 | [diff] [blame^] | 9 | |
Karthikeyan Ramasubramanian | cbc29a2 | 2020-09-30 17:04:15 -0600 | [diff] [blame] | 10 | #include "chip.h" |
| 11 | |
| 12 | static const char *i2c_gpiomux_mux_acpi_name(const struct device *dev) |
| 13 | { |
| 14 | static char name[ACPI_NAME_BUFFER_SIZE]; |
| 15 | |
| 16 | snprintf(name, ACPI_NAME_BUFFER_SIZE, "MUX%01.1X", dev->path.generic.id); |
| 17 | return name; |
| 18 | } |
| 19 | |
| 20 | static void i2c_gpiomux_mux_fill_ssdt(const struct device *dev) |
| 21 | { |
| 22 | const char *scope = acpi_device_scope(dev); |
| 23 | const char *path = acpi_device_path(dev); |
| 24 | struct drivers_i2c_gpiomux_mux_config *config = config_of(dev); |
| 25 | struct acpi_dp *dsd = NULL; |
| 26 | const char *compat_string = "i2c-mux-gpio"; |
| 27 | struct acpi_gpio_res_params param[MAX_NUM_MUX_GPIOS]; |
| 28 | int i; |
| 29 | |
Karthikeyan Ramasubramanian | d1c0f95 | 2020-11-02 16:26:52 -0700 | [diff] [blame] | 30 | if (!scope || !path) |
Karthikeyan Ramasubramanian | cbc29a2 | 2020-09-30 17:04:15 -0600 | [diff] [blame] | 31 | return; |
| 32 | |
| 33 | /* Device */ |
| 34 | acpigen_write_scope(scope); |
| 35 | acpigen_write_device(acpi_device_name(dev)); |
| 36 | acpigen_write_name_string("_HID", ACPI_DT_NAMESPACE_HID); |
| 37 | acpigen_write_STA(acpi_device_status(dev)); |
| 38 | |
| 39 | /* Resources */ |
| 40 | acpigen_write_name("_CRS"); |
| 41 | acpigen_write_resourcetemplate_header(); |
| 42 | for (i = 0; i < config->mux_gpio_count; i++) { |
| 43 | acpi_device_write_gpio(&config->mux_gpio[i]); |
| 44 | param[i].ref = path; |
| 45 | param[i].index = i; |
| 46 | param[i].pin = 0; |
| 47 | param[i].active_low = config->mux_gpio[i].active_low; |
| 48 | } |
| 49 | acpigen_write_resourcetemplate_footer(); |
| 50 | |
| 51 | /* DSD */ |
| 52 | dsd = acpi_dp_new_table("_DSD"); |
| 53 | acpi_dp_add_string(dsd, "compatible", compat_string); |
| 54 | acpi_dp_add_gpio_array(dsd, "mux-gpios", param, config->mux_gpio_count); |
| 55 | acpi_dp_write(dsd); |
| 56 | |
| 57 | acpigen_pop_len(); /* Device */ |
| 58 | acpigen_pop_len(); /* Scope */ |
| 59 | |
| 60 | printk(BIOS_INFO, "%s: %s at %s\n", path, dev->chip_ops->name, dev_path(dev)); |
| 61 | } |
| 62 | |
| 63 | static struct device_operations i2c_gpiomux_mux_ops = { |
| 64 | .read_resources = noop_read_resources, |
| 65 | .set_resources = noop_set_resources, |
| 66 | .scan_bus = scan_static_bus, |
| 67 | .acpi_name = i2c_gpiomux_mux_acpi_name, |
| 68 | .acpi_fill_ssdt = i2c_gpiomux_mux_fill_ssdt, |
| 69 | }; |
| 70 | |
| 71 | static void i2c_gpiomux_mux_enable(struct device *dev) |
| 72 | { |
| 73 | if (!dev) |
| 74 | return; |
| 75 | |
| 76 | dev->ops = &i2c_gpiomux_mux_ops; |
| 77 | } |
| 78 | |
| 79 | struct chip_operations drivers_i2c_gpiomux_mux_ops = { |
| 80 | CHIP_NAME("I2C GPIO MUX Device") |
| 81 | .enable_dev = i2c_gpiomux_mux_enable |
| 82 | }; |