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