blob: 7752f0aff361fbe4e7cabb2ed7f659d38777b887 [file] [log] [blame]
V Sowmya9f8023a2017-02-28 17:52:05 +05301/*
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>
20#include <device/i2c.h>
21#include <device/device.h>
22#include <device/path.h>
23#include <string.h>
24#include "chip.h"
25
26static 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);
46 acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
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
77static const char *camera_acpi_name(struct device *dev)
78{
79 struct drivers_intel_mipi_camera_config *config = dev->chip_info;
80 return config->acpi_name;
81}
82
83static 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
91static void camera_enable(struct device *dev)
92{
93 dev->ops = &camera_ops;
94}
95
96struct chip_operations drivers_intel_mipi_camera_ops = {
97 CHIP_NAME("Intel MIPI Camera Device")
98 .enable_dev = &camera_enable
99};