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