V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2017 Intel Corporation. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <arch/acpi.h> |
| 17 | #include <arch/acpi_device.h> |
| 18 | #include <arch/acpigen.h> |
| 19 | #include <console/console.h> |
Nico Huber | 0f2dd1e | 2017-08-01 14:02:40 +0200 | [diff] [blame] | 20 | #include <device/i2c_simple.h> |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 21 | #include <device/device.h> |
| 22 | #include <device/path.h> |
| 23 | #include <string.h> |
| 24 | #include "chip.h" |
| 25 | |
| 26 | static void camera_fill_ssdt(struct device *dev) |
| 27 | { |
| 28 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
| 29 | const char *scope = acpi_device_scope(dev); |
| 30 | struct acpi_i2c i2c = { |
| 31 | .address = dev->path.i2c.device, |
| 32 | .mode_10bit = dev->path.i2c.mode_10bit, |
| 33 | .speed = I2C_SPEED_FAST, |
| 34 | .resource = scope, |
| 35 | }; |
| 36 | |
| 37 | if (!dev->enabled || !scope) |
| 38 | return; |
| 39 | |
| 40 | /* Device */ |
| 41 | acpigen_write_scope(scope); |
| 42 | acpigen_write_device(acpi_device_name(dev)); |
| 43 | acpigen_write_name_string("_HID", config->acpi_hid); |
| 44 | acpigen_write_name_integer("_UID", config->acpi_uid); |
| 45 | acpigen_write_name_string("_DDN", config->chip_name); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 46 | acpigen_write_STA(acpi_device_status(dev)); |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 47 | |
| 48 | /* Resources */ |
| 49 | acpigen_write_name("_CRS"); |
| 50 | acpigen_write_resourcetemplate_header(); |
| 51 | acpi_device_write_i2c(&i2c); |
| 52 | acpigen_write_resourcetemplate_footer(); |
| 53 | |
| 54 | /* Mark it as Camera related device */ |
| 55 | acpigen_write_name_integer("CAMD", config->device_type); |
| 56 | |
| 57 | /* Create Device specific data */ |
| 58 | if (config->device_type == INTEL_ACPI_CAMERA_SENSOR) { |
| 59 | acpigen_write_method_serialized("SSDB", 0); |
| 60 | acpigen_write_return_byte_buffer((uint8_t *)&config->ssdb, |
| 61 | sizeof(config->ssdb)); |
| 62 | acpigen_pop_len(); /* Method */ |
| 63 | } |
| 64 | |
| 65 | /* Fill Power Sequencing Data */ |
| 66 | acpigen_write_method_serialized("PWDB", 0); |
| 67 | acpigen_write_return_byte_buffer((uint8_t *)&config->pwdb, |
| 68 | (sizeof(struct intel_pwdb) * config->num_pwdb_entries)); |
| 69 | acpigen_pop_len(); /* Method */ |
| 70 | |
| 71 | acpigen_pop_len(); /* Device */ |
| 72 | acpigen_pop_len(); /* Scope */ |
| 73 | printk(BIOS_INFO, "%s: %s address 0%xh\n", acpi_device_path(dev), |
| 74 | dev->chip_ops->name, dev->path.i2c.device); |
| 75 | } |
| 76 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 77 | static const char *camera_acpi_name(const struct device *dev) |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 78 | { |
| 79 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
| 80 | return config->acpi_name; |
| 81 | } |
| 82 | |
| 83 | static struct device_operations camera_ops = { |
| 84 | .read_resources = DEVICE_NOOP, |
| 85 | .set_resources = DEVICE_NOOP, |
| 86 | .enable_resources = DEVICE_NOOP, |
| 87 | .acpi_name = &camera_acpi_name, |
| 88 | .acpi_fill_ssdt_generator = &camera_fill_ssdt, |
| 89 | }; |
| 90 | |
| 91 | static void camera_enable(struct device *dev) |
| 92 | { |
| 93 | dev->ops = &camera_ops; |
| 94 | } |
| 95 | |
| 96 | struct chip_operations drivers_intel_mipi_camera_ops = { |
| 97 | CHIP_NAME("Intel MIPI Camera Device") |
| 98 | .enable_dev = &camera_enable |
| 99 | }; |