Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #include <arch/acpi_device.h> |
| 15 | #include <arch/acpigen.h> |
Eric Lai | b90739d | 2019-06-13 15:21:20 +0800 | [diff] [blame] | 16 | #include <console/console.h> |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 17 | #include <device/i2c_simple.h> |
| 18 | #include <device/device.h> |
| 19 | #include <device/path.h> |
| 20 | #include <stdint.h> |
| 21 | #include <string.h> |
| 22 | #include "chip.h" |
| 23 | |
Gwendal Grignou | 145ef87 | 2018-07-03 14:31:31 -0700 | [diff] [blame] | 24 | #define I2C_SX9310_ACPI_ID "STH9310" |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 25 | #define I2C_SX9310_ACPI_NAME "Semtech SX9310" |
| 26 | |
| 27 | #define REGISTER(NAME) acpi_dp_add_integer(dsd, \ |
| 28 | I2C_SX9310_ACPI_ID "," #NAME, \ |
| 29 | config->NAME) |
| 30 | |
| 31 | static void i2c_sx9310_fill_ssdt(struct device *dev) |
| 32 | { |
| 33 | struct drivers_i2c_sx9310_config *config = dev->chip_info; |
| 34 | const char *scope = acpi_device_scope(dev); |
| 35 | struct acpi_i2c i2c = { |
| 36 | .address = dev->path.i2c.device, |
| 37 | .mode_10bit = dev->path.i2c.mode_10bit, |
Furquan Shaikh | a7e9250 | 2018-06-22 10:15:04 -0700 | [diff] [blame] | 38 | .speed = I2C_SPEED_FAST, |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 39 | .resource = scope, |
| 40 | }; |
| 41 | struct acpi_dp *dsd; |
| 42 | |
| 43 | if (!dev->enabled || !scope || !config) |
| 44 | return; |
| 45 | |
Furquan Shaikh | a7e9250 | 2018-06-22 10:15:04 -0700 | [diff] [blame] | 46 | if (config->speed) |
| 47 | i2c.speed = config->speed; |
| 48 | |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 49 | /* Device */ |
| 50 | acpigen_write_scope(scope); |
| 51 | acpigen_write_device(acpi_device_name(dev)); |
| 52 | acpigen_write_name_string("_HID", I2C_SX9310_ACPI_ID); |
| 53 | acpigen_write_name_integer("_UID", config->uid); |
| 54 | acpigen_write_name_string("_DDN", config->desc); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 55 | acpigen_write_STA(acpi_device_status(dev)); |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 56 | |
| 57 | /* Resources */ |
| 58 | acpigen_write_name("_CRS"); |
| 59 | acpigen_write_resourcetemplate_header(); |
| 60 | acpi_device_write_i2c(&i2c); |
Furquan Shaikh | aea9871 | 2019-04-10 10:22:06 -0700 | [diff] [blame] | 61 | |
| 62 | if (config->irq_gpio.pin_count) |
| 63 | acpi_device_write_gpio(&config->irq_gpio); |
| 64 | else |
| 65 | acpi_device_write_interrupt(&config->irq); |
| 66 | |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 67 | acpigen_write_resourcetemplate_footer(); |
| 68 | |
| 69 | /* DSD */ |
| 70 | dsd = acpi_dp_new_table("_DSD"); |
| 71 | #include "registers.h" |
| 72 | acpi_dp_write(dsd); |
| 73 | |
| 74 | acpigen_pop_len(); /* Device */ |
| 75 | acpigen_pop_len(); /* Scope */ |
Eric Lai | b90739d | 2019-06-13 15:21:20 +0800 | [diff] [blame] | 76 | |
| 77 | printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev), |
| 78 | config->desc ? : dev->chip_ops->name, dev_path(dev)); |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | #undef REGISTER |
| 82 | |
| 83 | static const char *i2c_sx9310_acpi_name(const struct device *dev) |
| 84 | { |
| 85 | static char name[5]; |
| 86 | |
| 87 | snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device); |
| 88 | return name; |
| 89 | } |
| 90 | |
| 91 | static struct device_operations i2c_sx9310_ops = { |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame^] | 92 | .read_resources = DEVICE_NOOP, |
| 93 | .set_resources = DEVICE_NOOP, |
| 94 | .enable_resources = DEVICE_NOOP, |
| 95 | .acpi_name = i2c_sx9310_acpi_name, |
| 96 | .acpi_fill_ssdt = i2c_sx9310_fill_ssdt, |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | static void i2c_sx9310_enable(struct device *dev) |
| 100 | { |
| 101 | struct drivers_i2c_sx9310_config *config = dev->chip_info; |
| 102 | |
| 103 | if (!config) { |
| 104 | dev->enabled = 0; |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | dev->ops = &i2c_sx9310_ops; |
| 109 | |
| 110 | if (config->desc) |
| 111 | dev->name = config->desc; |
| 112 | } |
| 113 | |
| 114 | struct chip_operations drivers_i2c_sx9310_ops = { |
| 115 | CHIP_NAME(I2C_SX9310_ACPI_NAME) |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 116 | .enable_dev = i2c_sx9310_enable |
Enrico Granata | 76a1f49 | 2018-06-20 13:01:45 -0700 | [diff] [blame] | 117 | }; |