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. */ |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 3 | |
| 4 | #include <arch/acpi.h> |
| 5 | #include <arch/acpi_device.h> |
| 6 | #include <arch/acpigen.h> |
| 7 | #include <console/console.h> |
Nico Huber | 0f2dd1e | 2017-08-01 14:02:40 +0200 | [diff] [blame] | 8 | #include <device/i2c_simple.h> |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 9 | #include <device/device.h> |
| 10 | #include <device/path.h> |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 11 | #include "chip.h" |
| 12 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 13 | static void camera_fill_ssdt(const struct device *dev) |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 14 | { |
| 15 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
| 16 | const char *scope = acpi_device_scope(dev); |
| 17 | struct acpi_i2c i2c = { |
| 18 | .address = dev->path.i2c.device, |
| 19 | .mode_10bit = dev->path.i2c.mode_10bit, |
| 20 | .speed = I2C_SPEED_FAST, |
| 21 | .resource = scope, |
| 22 | }; |
| 23 | |
| 24 | if (!dev->enabled || !scope) |
| 25 | return; |
| 26 | |
| 27 | /* Device */ |
| 28 | acpigen_write_scope(scope); |
| 29 | acpigen_write_device(acpi_device_name(dev)); |
| 30 | acpigen_write_name_string("_HID", config->acpi_hid); |
| 31 | acpigen_write_name_integer("_UID", config->acpi_uid); |
| 32 | acpigen_write_name_string("_DDN", config->chip_name); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 33 | acpigen_write_STA(acpi_device_status(dev)); |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 34 | |
| 35 | /* Resources */ |
| 36 | acpigen_write_name("_CRS"); |
| 37 | acpigen_write_resourcetemplate_header(); |
| 38 | acpi_device_write_i2c(&i2c); |
| 39 | acpigen_write_resourcetemplate_footer(); |
| 40 | |
| 41 | /* Mark it as Camera related device */ |
| 42 | acpigen_write_name_integer("CAMD", config->device_type); |
| 43 | |
| 44 | /* Create Device specific data */ |
| 45 | if (config->device_type == INTEL_ACPI_CAMERA_SENSOR) { |
| 46 | acpigen_write_method_serialized("SSDB", 0); |
| 47 | acpigen_write_return_byte_buffer((uint8_t *)&config->ssdb, |
| 48 | sizeof(config->ssdb)); |
| 49 | acpigen_pop_len(); /* Method */ |
| 50 | } |
| 51 | |
| 52 | /* Fill Power Sequencing Data */ |
| 53 | acpigen_write_method_serialized("PWDB", 0); |
| 54 | acpigen_write_return_byte_buffer((uint8_t *)&config->pwdb, |
| 55 | (sizeof(struct intel_pwdb) * config->num_pwdb_entries)); |
| 56 | acpigen_pop_len(); /* Method */ |
| 57 | |
| 58 | acpigen_pop_len(); /* Device */ |
| 59 | acpigen_pop_len(); /* Scope */ |
| 60 | printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev), |
| 61 | dev->chip_ops->name, dev->path.i2c.device); |
| 62 | } |
| 63 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 64 | static const char *camera_acpi_name(const struct device *dev) |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 65 | { |
| 66 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
| 67 | return config->acpi_name; |
| 68 | } |
| 69 | |
| 70 | static struct device_operations camera_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 71 | .read_resources = noop_read_resources, |
| 72 | .set_resources = noop_set_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 73 | .acpi_name = camera_acpi_name, |
| 74 | .acpi_fill_ssdt = camera_fill_ssdt, |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | static void camera_enable(struct device *dev) |
| 78 | { |
| 79 | dev->ops = &camera_ops; |
| 80 | } |
| 81 | |
| 82 | struct chip_operations drivers_intel_mipi_camera_ops = { |
| 83 | CHIP_NAME("Intel MIPI Camera Device") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 84 | .enable_dev = camera_enable |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 85 | }; |