Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi_device.h> |
| 4 | #include <acpi/acpigen.h> |
Eric Lai | b90739d | 2019-06-13 15:21:20 +0800 | [diff] [blame] | 5 | #include <console/console.h> |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 6 | #include <device/i2c_simple.h> |
| 7 | #include <device/device.h> |
| 8 | #include <device/path.h> |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 9 | #include <string.h> |
| 10 | #include "chip.h" |
| 11 | |
Gwendal Grignou | 145ef87 | 2018-07-03 14:31:31 -0700 | [diff] [blame] | 12 | #define I2C_SX9310_ACPI_ID "STH9310" |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 13 | #define I2C_SX9310_ACPI_NAME "Semtech SX9310" |
| 14 | |
| 15 | #define REGISTER(NAME) acpi_dp_add_integer(dsd, \ |
| 16 | I2C_SX9310_ACPI_ID "," #NAME, \ |
| 17 | config->NAME) |
| 18 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 19 | static void i2c_sx9310_fill_ssdt(const struct device *dev) |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 20 | { |
| 21 | struct drivers_i2c_sx9310_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, |
Furquan Shaikh | a7e9250 | 2018-06-22 10:15:04 -0700 | [diff] [blame] | 26 | .speed = I2C_SPEED_FAST, |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 27 | .resource = scope, |
| 28 | }; |
| 29 | struct acpi_dp *dsd; |
| 30 | |
Karthikeyan Ramasubramanian | d1c0f95 | 2020-11-02 16:26:52 -0700 | [diff] [blame] | 31 | if (!scope || !config) |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 32 | return; |
| 33 | |
Furquan Shaikh | a7e9250 | 2018-06-22 10:15:04 -0700 | [diff] [blame] | 34 | if (config->speed) |
| 35 | i2c.speed = config->speed; |
| 36 | |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 37 | /* Device */ |
| 38 | acpigen_write_scope(scope); |
| 39 | acpigen_write_device(acpi_device_name(dev)); |
| 40 | acpigen_write_name_string("_HID", I2C_SX9310_ACPI_ID); |
| 41 | acpigen_write_name_integer("_UID", config->uid); |
| 42 | acpigen_write_name_string("_DDN", config->desc); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 43 | acpigen_write_STA(acpi_device_status(dev)); |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 44 | |
| 45 | /* Resources */ |
| 46 | acpigen_write_name("_CRS"); |
| 47 | acpigen_write_resourcetemplate_header(); |
| 48 | acpi_device_write_i2c(&i2c); |
Furquan Shaikh | aea9871 | 2019-04-10 10:22:06 -0700 | [diff] [blame] | 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 | |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 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 */ |
Eric Lai | b90739d | 2019-06-13 15:21:20 +0800 | [diff] [blame] | 64 | |
| 65 | printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), |
| 66 | config->desc ? : dev->chip_ops->name, dev_path(dev)); |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | #undef REGISTER |
| 70 | |
| 71 | static const char *i2c_sx9310_acpi_name(const struct device *dev) |
| 72 | { |
| 73 | static char name[5]; |
| 74 | |
| 75 | snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device); |
| 76 | return name; |
| 77 | } |
| 78 | |
| 79 | static struct device_operations i2c_sx9310_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 80 | .read_resources = noop_read_resources, |
| 81 | .set_resources = noop_set_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 82 | .acpi_name = i2c_sx9310_acpi_name, |
| 83 | .acpi_fill_ssdt = i2c_sx9310_fill_ssdt, |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | static void i2c_sx9310_enable(struct device *dev) |
| 87 | { |
| 88 | struct drivers_i2c_sx9310_config *config = dev->chip_info; |
| 89 | |
| 90 | if (!config) { |
| 91 | dev->enabled = 0; |
| 92 | return; |
| 93 | } |
| 94 | |
| 95 | dev->ops = &i2c_sx9310_ops; |
| 96 | |
| 97 | if (config->desc) |
| 98 | dev->name = config->desc; |
| 99 | } |
| 100 | |
| 101 | struct chip_operations drivers_i2c_sx9310_ops = { |
| 102 | CHIP_NAME(I2C_SX9310_ACPI_NAME) |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 103 | .enable_dev = i2c_sx9310_enable |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 104 | }; |