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> |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 10 | #include <device/pci_def.h> |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 11 | #include "chip.h" |
| 12 | |
Matt Delco | c3a83bf | 2020-06-16 12:02:34 +0530 | [diff] [blame^] | 13 | static void camera_fill_nvm(const struct device *dev) |
| 14 | { |
| 15 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
| 16 | struct acpi_dp *dsd = acpi_dp_new_table("_DSD"); |
| 17 | |
| 18 | /* It might be possible to default size or width based on type. */ |
| 19 | if (!config->disable_nvm_defaults && !config->nvm_pagesize) |
| 20 | config->nvm_pagesize = 1; |
| 21 | |
| 22 | if (!config->disable_nvm_defaults && !config->nvm_readonly) |
| 23 | config->nvm_readonly = 1; |
| 24 | |
| 25 | if (config->nvm_size) |
| 26 | acpi_dp_add_integer(dsd, "size", config->nvm_size); |
| 27 | |
| 28 | if (config->nvm_pagesize) |
| 29 | acpi_dp_add_integer(dsd, "pagesize", config->nvm_pagesize); |
| 30 | |
| 31 | if (config->nvm_readonly) |
| 32 | acpi_dp_add_integer(dsd, "read-only", config->nvm_readonly); |
| 33 | |
| 34 | if (config->nvm_width) |
| 35 | acpi_dp_add_integer(dsd, "address-width", config->nvm_width); |
| 36 | |
| 37 | acpi_dp_write(dsd); |
| 38 | } |
| 39 | |
| 40 | static void camera_fill_vcm(const struct device *dev) |
| 41 | { |
| 42 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
| 43 | struct acpi_dp *dsd; |
| 44 | |
| 45 | if (!config->vcm_compat) |
| 46 | return; |
| 47 | |
| 48 | dsd = acpi_dp_new_table("_DSD"); |
| 49 | acpi_dp_add_string(dsd, "compatible", config->vcm_compat); |
| 50 | acpi_dp_write(dsd); |
| 51 | } |
| 52 | |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 53 | static void write_pci_camera_device(const struct device *dev) |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 54 | { |
| 55 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 56 | |
| 57 | if (dev->path.type != DEVICE_PATH_PCI) { |
| 58 | printk(BIOS_ERR, "CIO2/IMGU devices require PCI\n"); |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | acpigen_write_device(acpi_device_name(dev)); |
| 63 | acpigen_write_ADR_pci_device(dev); |
| 64 | acpigen_write_name_string("_DDN", config->device_type == INTEL_ACPI_CAMERA_CIO2 ? |
| 65 | "Camera and Imaging Subsystem" : "Imaging Unit"); |
| 66 | } |
| 67 | |
| 68 | static void write_i2c_camera_device(const struct device *dev, const char *scope) |
| 69 | { |
| 70 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 71 | struct acpi_i2c i2c = { |
| 72 | .address = dev->path.i2c.device, |
| 73 | .mode_10bit = dev->path.i2c.mode_10bit, |
| 74 | .speed = I2C_SPEED_FAST, |
| 75 | .resource = scope, |
| 76 | }; |
| 77 | |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 78 | if (dev->path.type != DEVICE_PATH_I2C) { |
| 79 | printk(BIOS_ERR, "Non-CIO2/IMGU devices require I2C\n"); |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 80 | return; |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 81 | } |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 82 | |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 83 | acpigen_write_device(acpi_device_name(dev)); |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 84 | |
| 85 | if (config->device_type == INTEL_ACPI_CAMERA_SENSOR) |
| 86 | acpigen_write_name_integer("_ADR", 0); |
| 87 | |
| 88 | if (config->acpi_hid) |
| 89 | acpigen_write_name_string("_HID", config->acpi_hid); |
| 90 | else if (config->device_type == INTEL_ACPI_CAMERA_VCM) |
| 91 | acpigen_write_name_string("_HID", ACPI_DT_NAMESPACE_HID); |
| 92 | else if (config->device_type == INTEL_ACPI_CAMERA_NVM) |
| 93 | acpigen_write_name_string("_HID", "INT3499"); |
| 94 | |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 95 | acpigen_write_name_integer("_UID", config->acpi_uid); |
| 96 | acpigen_write_name_string("_DDN", config->chip_name); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 97 | acpigen_write_STA(acpi_device_status(dev)); |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 98 | |
| 99 | /* Resources */ |
| 100 | acpigen_write_name("_CRS"); |
| 101 | acpigen_write_resourcetemplate_header(); |
| 102 | acpi_device_write_i2c(&i2c); |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 103 | |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 104 | /* |
| 105 | * The optional vcm/nvram devices are presumed to be on the same I2C bus as the camera |
| 106 | * sensor. |
| 107 | */ |
| 108 | if (config->device_type == INTEL_ACPI_CAMERA_SENSOR && |
| 109 | config->ssdb.vcm_type && config->vcm_address) { |
| 110 | struct acpi_i2c i2c_vcm = i2c; |
| 111 | i2c_vcm.address = config->vcm_address; |
| 112 | acpi_device_write_i2c(&i2c_vcm); |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 113 | } |
| 114 | |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 115 | if (config->device_type == INTEL_ACPI_CAMERA_SENSOR && |
| 116 | config->ssdb.rom_type && config->rom_address) { |
| 117 | struct acpi_i2c i2c_rom = i2c; |
| 118 | i2c_rom.address = config->rom_address; |
| 119 | acpi_device_write_i2c(&i2c_rom); |
| 120 | } |
| 121 | |
| 122 | acpigen_write_resourcetemplate_footer(); |
| 123 | } |
| 124 | |
| 125 | static void write_camera_device_common(const struct device *dev) |
| 126 | { |
| 127 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
| 128 | |
| 129 | /* Mark it as Camera related device */ |
| 130 | if (config->device_type == INTEL_ACPI_CAMERA_CIO2 || |
| 131 | config->device_type == INTEL_ACPI_CAMERA_IMGU || |
| 132 | config->device_type == INTEL_ACPI_CAMERA_SENSOR || |
| 133 | config->device_type == INTEL_ACPI_CAMERA_VCM) { |
| 134 | acpigen_write_name_integer("CAMD", config->device_type); |
| 135 | } |
Matt Delco | c3a83bf | 2020-06-16 12:02:34 +0530 | [diff] [blame^] | 136 | |
| 137 | switch (config->device_type) { |
| 138 | case INTEL_ACPI_CAMERA_VCM: |
| 139 | camera_fill_vcm(dev); |
| 140 | break; |
| 141 | case INTEL_ACPI_CAMERA_NVM: |
| 142 | camera_fill_nvm(dev); |
| 143 | break; |
| 144 | default: |
| 145 | break; |
| 146 | } |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static void camera_fill_ssdt(const struct device *dev) |
| 150 | { |
| 151 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
| 152 | const char *scope = acpi_device_scope(dev); |
| 153 | |
| 154 | if (!dev->enabled || !scope) |
| 155 | return; |
| 156 | |
| 157 | /* Device */ |
| 158 | acpigen_write_scope(scope); |
| 159 | |
| 160 | if (config->device_type == INTEL_ACPI_CAMERA_CIO2 || |
| 161 | config->device_type == INTEL_ACPI_CAMERA_IMGU) |
| 162 | write_pci_camera_device(dev); |
| 163 | else |
| 164 | write_i2c_camera_device(dev, scope); |
| 165 | |
| 166 | write_camera_device_common(dev); |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 167 | |
| 168 | acpigen_pop_len(); /* Device */ |
| 169 | acpigen_pop_len(); /* Scope */ |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 170 | |
| 171 | if (dev->path.type == DEVICE_PATH_PCI) { |
| 172 | printk(BIOS_INFO, "%s: %s PCI address 0%x\n", acpi_device_path(dev), |
| 173 | dev->chip_ops->name, dev->path.pci.devfn); |
| 174 | } else { |
| 175 | printk(BIOS_INFO, "%s: %s I2C address 0%xh\n", acpi_device_path(dev), |
| 176 | dev->chip_ops->name, dev->path.i2c.device); |
| 177 | } |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 178 | } |
| 179 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 180 | static const char *camera_acpi_name(const struct device *dev) |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 181 | { |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 182 | const char *prefix = NULL; |
| 183 | static char name[5]; |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 184 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 185 | |
| 186 | if (config->acpi_name) |
| 187 | return config->acpi_name; |
| 188 | |
| 189 | switch (config->device_type) { |
| 190 | case INTEL_ACPI_CAMERA_CIO2: |
| 191 | return "CIO2"; |
| 192 | case INTEL_ACPI_CAMERA_IMGU: |
| 193 | return "IMGU"; |
| 194 | case INTEL_ACPI_CAMERA_PMIC: |
| 195 | return "PMIC"; |
| 196 | case INTEL_ACPI_CAMERA_SENSOR: |
| 197 | prefix = "CAM"; |
| 198 | break; |
| 199 | case INTEL_ACPI_CAMERA_VCM: |
| 200 | prefix = "VCM"; |
| 201 | break; |
| 202 | case INTEL_ACPI_CAMERA_NVM: |
| 203 | prefix = "NVM"; |
| 204 | break; |
| 205 | default: |
| 206 | printk(BIOS_ERR, "Invalid device type: %x\n", config->device_type); |
| 207 | return NULL; |
| 208 | } |
| 209 | |
| 210 | /* |
| 211 | * The camera # knows which link # they use, so that's used as the basis for the |
| 212 | * instance #. The VCM and NVM don't have this information, so the best we can go on is |
| 213 | * the _UID. |
| 214 | */ |
| 215 | snprintf(name, sizeof(name), "%s%1u", prefix, |
| 216 | config->device_type == INTEL_ACPI_CAMERA_SENSOR ? |
| 217 | config->ssdb.link_used : config->acpi_uid); |
| 218 | return name; |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | static struct device_operations camera_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 222 | .read_resources = noop_read_resources, |
| 223 | .set_resources = noop_set_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 224 | .acpi_name = camera_acpi_name, |
| 225 | .acpi_fill_ssdt = camera_fill_ssdt, |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 226 | }; |
| 227 | |
| 228 | static void camera_enable(struct device *dev) |
| 229 | { |
| 230 | dev->ops = &camera_ops; |
| 231 | } |
| 232 | |
| 233 | struct chip_operations drivers_intel_mipi_camera_ops = { |
| 234 | CHIP_NAME("Intel MIPI Camera Device") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 235 | .enable_dev = camera_enable |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 236 | }; |