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 | |
Matt Delco | 879b3c1 | 2020-06-17 13:10:22 +0530 | [diff] [blame] | 3 | #include <stdlib.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 4 | #include <acpi/acpi.h> |
| 5 | #include <acpi/acpi_device.h> |
| 6 | #include <acpi/acpigen.h> |
Tim Wawrzynczak | d40a4c2 | 2021-02-25 13:14:49 -0700 | [diff] [blame] | 7 | #include <acpi/acpigen_pci.h> |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 8 | #include <console/console.h> |
Nico Huber | 0f2dd1e | 2017-08-01 14:02:40 +0200 | [diff] [blame] | 9 | #include <device/i2c_simple.h> |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 10 | #include <device/device.h> |
| 11 | #include <device/path.h> |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 12 | #include <device/pci_def.h> |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 13 | #include "chip.h" |
| 14 | |
Matt Delco | 1245b1e | 2020-06-17 07:26:55 +0530 | [diff] [blame] | 15 | #define SENSOR_NAME_UUID "822ace8f-2814-4174-a56b-5f029fe079ee" |
| 16 | #define SENSOR_TYPE_UUID "26257549-9271-4ca4-bb43-c4899d5a4881" |
| 17 | #define DEFAULT_ENDPOINT 0 |
Matt Delco | 879b3c1 | 2020-06-17 13:10:22 +0530 | [diff] [blame] | 18 | #define DEFAULT_REMOTE_NAME "\\_SB.PCI0.CIO2" |
| 19 | #define CIO2_PCI_DEV 0x14 |
| 20 | #define CIO2_PCI_FN 0x3 |
Sugnan Prabhu S | b087a94 | 2020-05-21 20:41:03 +0530 | [diff] [blame] | 21 | #define POWER_RESOURCE_NAME "PRIC" |
Sugnan Prabhu S | 6d9f243 | 2020-07-02 13:02:23 +0530 | [diff] [blame] | 22 | #define GUARD_VARIABLE_FORMAT "RES%1d" |
| 23 | #define ENABLE_METHOD_FORMAT "ENB%1d" |
| 24 | #define DISABLE_METHOD_FORMAT "DSB%1d" |
| 25 | #define UNKNOWN_METHOD_FORMAT "UNK%1d" |
| 26 | #define CLK_ENABLE_METHOD "MCON" |
| 27 | #define CLK_DISABLE_METHOD "MCOF" |
| 28 | |
| 29 | static struct camera_resource_manager res_mgr; |
| 30 | |
| 31 | static void resource_set_action_type(struct resource_config *res_config, |
| 32 | enum action_type action) |
| 33 | { |
| 34 | if (res_config) |
| 35 | res_config->action = action; |
| 36 | } |
| 37 | |
| 38 | static enum action_type resource_get_action_type(const struct resource_config *res_config) |
| 39 | { |
| 40 | return res_config ? res_config->action : UNKNOWN_ACTION; |
| 41 | } |
| 42 | |
| 43 | static enum ctrl_type resource_get_ctrl_type(const struct resource_config *res_config) |
| 44 | { |
| 45 | return res_config ? res_config->type : UNKNOWN_CTRL; |
| 46 | } |
| 47 | |
| 48 | static void resource_set_clk_config(struct resource_config *res_config, |
| 49 | const struct clk_config *clk_conf) |
| 50 | { |
| 51 | if (res_config) { |
| 52 | res_config->type = IMGCLK; |
| 53 | res_config->clk_conf = clk_conf; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | static const struct clk_config *resource_clk_config(const struct resource_config *res_config) |
| 58 | { |
| 59 | return res_config ? res_config->clk_conf : NULL; |
| 60 | } |
| 61 | |
| 62 | static void resource_set_gpio_config(struct resource_config *res_config, |
| 63 | const struct gpio_config *gpio_conf) |
| 64 | { |
| 65 | if (res_config) { |
| 66 | res_config->type = GPIO; |
| 67 | res_config->gpio_conf = gpio_conf; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | static const struct gpio_config *resource_gpio_config(const struct resource_config *res_config) |
| 72 | { |
| 73 | return res_config ? res_config->gpio_conf : NULL; |
| 74 | } |
Matt Delco | 879b3c1 | 2020-06-17 13:10:22 +0530 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * This implementation assumes there is only 1 endpoint at each end of every data port. It also |
| 78 | * assumes there are no clock lanes. It also assumes that any VCM or NVM for a CAM is on the |
| 79 | * same I2C bus as the CAM. |
| 80 | */ |
| 81 | |
| 82 | /* |
| 83 | * Adds settings for a CIO2 device (typically at "\_SB.PCI0.CIO2"). A _DSD is added that |
| 84 | * specifies a child table for each port (e.g., PRT0 for "port0" and PRT1 for "port1"). Each |
| 85 | * PRTx table specifies a table for each endpoint (though only 1 endpoint is supported by this |
| 86 | * implementation so the table only has an "endpoint0" that points to a EPx0 table). The EPx0 |
| 87 | * table primarily describes the # of lanes in "data-lines" and specifies the name of the other |
| 88 | * side in "remote-endpoint" (the name is usually of the form "\_SB.PCI0.I2Cx.CAM0" for the |
| 89 | * first port/cam and "\_SB.PCI0.I2Cx.CAM1" if there's a second port/cam). |
| 90 | */ |
| 91 | static void camera_fill_cio2(const struct device *dev) |
| 92 | { |
| 93 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
| 94 | struct acpi_dp *dsd = acpi_dp_new_table("_DSD"); |
| 95 | char *ep_table_name[MAX_PORT_ENTRIES] = {NULL}; |
| 96 | char *port_table_name[MAX_PORT_ENTRIES] = {NULL}; |
| 97 | char *port_name[MAX_PORT_ENTRIES] = {NULL}; |
| 98 | unsigned int i, j; |
| 99 | char name[BUS_PATH_MAX]; |
| 100 | struct acpi_dp *ep_table = NULL; |
| 101 | struct acpi_dp *port_table = NULL; |
| 102 | struct acpi_dp *remote = NULL; |
| 103 | struct acpi_dp *lanes = NULL; |
| 104 | |
| 105 | for (i = 0; i < config->cio2_num_ports && i < MAX_PORT_ENTRIES; ++i) { |
| 106 | snprintf(name, sizeof(name), "EP%u0", i); |
| 107 | ep_table_name[i] = strdup(name); |
| 108 | ep_table = acpi_dp_new_table(ep_table_name[i]); |
| 109 | acpi_dp_add_integer(ep_table, "endpoint", 0); |
| 110 | acpi_dp_add_integer(ep_table, "clock-lanes", 0); |
| 111 | |
| 112 | if (config->cio2_lanes_used[i] > 0) { |
| 113 | lanes = acpi_dp_new_table("data-lanes"); |
| 114 | |
| 115 | for (j = 1; j <= config->cio2_lanes_used[i] && |
| 116 | j <= MAX_PORT_ENTRIES; ++j) |
| 117 | acpi_dp_add_integer(lanes, NULL, j); |
| 118 | acpi_dp_add_array(ep_table, lanes); |
| 119 | } |
| 120 | |
| 121 | if (config->cio2_lane_endpoint[i]) { |
| 122 | remote = acpi_dp_new_table("remote-endpoint"); |
| 123 | acpi_dp_add_reference(remote, NULL, config->cio2_lane_endpoint[i]); |
| 124 | acpi_dp_add_integer(remote, NULL, 0); |
| 125 | acpi_dp_add_integer(remote, NULL, 0); |
| 126 | acpi_dp_add_array(ep_table, remote); |
| 127 | } |
| 128 | |
| 129 | snprintf(name, sizeof(name), "PRT%u", i); |
| 130 | port_table_name[i] = strdup(name); |
| 131 | port_table = acpi_dp_new_table(port_table_name[i]); |
| 132 | acpi_dp_add_integer(port_table, "port", config->cio2_prt[i]); |
| 133 | acpi_dp_add_child(port_table, "endpoint0", ep_table); |
| 134 | |
| 135 | snprintf(name, sizeof(name), "port%u", i); |
| 136 | port_name[i] = strdup(name); |
| 137 | acpi_dp_add_child(dsd, port_name[i], port_table); |
| 138 | } |
| 139 | |
| 140 | acpi_dp_write(dsd); |
| 141 | |
| 142 | for (i = 0; i < config->cio2_num_ports; ++i) { |
| 143 | free(ep_table_name[i]); |
| 144 | free(port_table_name[i]); |
| 145 | free(port_name[i]); |
| 146 | } |
| 147 | } |
Matt Delco | 1245b1e | 2020-06-17 07:26:55 +0530 | [diff] [blame] | 148 | |
Matt Delco | 1ffee9d | 2020-06-17 12:55:35 +0530 | [diff] [blame] | 149 | static void apply_pld_defaults(struct drivers_intel_mipi_camera_config *config) |
| 150 | { |
| 151 | if (!config->pld.ignore_color) |
| 152 | config->pld.ignore_color = 1; |
| 153 | |
| 154 | if (!config->pld.visible) |
| 155 | config->pld.visible = 1; |
| 156 | |
| 157 | if (!config->pld.vertical_offset) |
| 158 | config->pld.vertical_offset = 0xffff; |
| 159 | |
| 160 | if (!config->pld.horizontal_offset) |
| 161 | config->pld.horizontal_offset = 0xffff; |
| 162 | |
| 163 | /* |
| 164 | * PLD_PANEL_TOP has a value of zero, so the following will change any instance of |
| 165 | * PLD_PANEL_TOP to PLD_PANEL_FRONT unless disable_pld_defaults is set. |
| 166 | */ |
| 167 | if (!config->pld.panel) |
| 168 | config->pld.panel = PLD_PANEL_FRONT; |
| 169 | |
| 170 | /* |
| 171 | * PLD_HORIZONTAL_POSITION_LEFT has a value of zero, so the following will change any |
| 172 | * instance of that value to PLD_HORIZONTAL_POSITION_CENTER unless disable_pld_defaults |
| 173 | * is set. |
| 174 | */ |
| 175 | if (!config->pld.horizontal_position) |
| 176 | config->pld.horizontal_position = PLD_HORIZONTAL_POSITION_CENTER; |
| 177 | |
| 178 | /* |
| 179 | * The desired default for |vertical_position| is PLD_VERTICAL_POSITION_UPPER, which |
| 180 | * has a value of zero so no work is needed to set a default. The same applies for |
| 181 | * setting |shape| to PLD_SHAPE_ROUND. |
| 182 | */ |
| 183 | } |
| 184 | |
| 185 | static void camera_generate_pld(const struct device *dev) |
| 186 | { |
| 187 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
| 188 | |
| 189 | if (config->use_pld) { |
| 190 | if (!config->disable_pld_defaults) |
| 191 | apply_pld_defaults(config); |
| 192 | |
| 193 | acpigen_write_pld(&config->pld); |
| 194 | } |
| 195 | } |
| 196 | |
Matt Delco | 964033f | 2020-06-17 12:49:43 +0530 | [diff] [blame] | 197 | static uint32_t address_for_dev_type(const struct device *dev, uint8_t dev_type) |
| 198 | { |
| 199 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
| 200 | uint16_t i2c_bus = dev->bus ? dev->bus->secondary : 0xFFFF; |
| 201 | uint16_t i2c_addr; |
| 202 | |
| 203 | switch (dev_type) { |
| 204 | case DEV_TYPE_SENSOR: |
| 205 | i2c_addr = dev->path.i2c.device; |
| 206 | break; |
| 207 | case DEV_TYPE_VCM: |
| 208 | i2c_addr = config->vcm_address; |
| 209 | break; |
| 210 | case DEV_TYPE_ROM: |
| 211 | i2c_addr = config->rom_address; |
| 212 | break; |
| 213 | default: |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | return (((uint32_t)i2c_bus) << 24 | ((uint32_t)i2c_addr) << 8 | dev_type); |
| 218 | } |
| 219 | |
| 220 | static void camera_generate_dsm(const struct device *dev) |
| 221 | { |
| 222 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
| 223 | int local1_ret = 1 + (config->ssdb.vcm_type ? 1 : 0) + (config->ssdb.rom_type ? 1 : 0); |
| 224 | int next_local1 = 1; |
| 225 | /* Method (_DSM, 4, NotSerialized) */ |
| 226 | acpigen_write_method("_DSM", 4); |
| 227 | |
| 228 | /* ToBuffer (Arg0, Local0) */ |
| 229 | acpigen_write_to_buffer(ARG0_OP, LOCAL0_OP); |
| 230 | |
| 231 | /* If (LEqual (Local0, ToUUID(uuid))) */ |
| 232 | acpigen_write_if(); |
| 233 | acpigen_emit_byte(LEQUAL_OP); |
| 234 | acpigen_emit_byte(LOCAL0_OP); |
| 235 | acpigen_write_uuid(SENSOR_NAME_UUID); |
| 236 | acpigen_write_return_string(config->sensor_name ? config->sensor_name : "UNKNOWN"); |
| 237 | acpigen_pop_len(); /* If */ |
| 238 | |
| 239 | /* If (LEqual (Local0, ToUUID(uuid))) */ |
| 240 | acpigen_write_if(); |
| 241 | acpigen_emit_byte(LEQUAL_OP); |
| 242 | acpigen_emit_byte(LOCAL0_OP); |
| 243 | acpigen_write_uuid(SENSOR_TYPE_UUID); |
| 244 | /* ToInteger (Arg2, Local1) */ |
| 245 | acpigen_write_to_integer(ARG2_OP, LOCAL1_OP); |
| 246 | |
| 247 | /* If (LEqual (Local1, 1)) */ |
| 248 | acpigen_write_if_lequal_op_int(LOCAL1_OP, next_local1++); |
| 249 | acpigen_write_return_integer(local1_ret); |
| 250 | acpigen_pop_len(); /* If Arg2=1 */ |
| 251 | |
| 252 | /* If (LEqual (Local1, 2)) */ |
| 253 | acpigen_write_if_lequal_op_int(LOCAL1_OP, next_local1++); |
| 254 | acpigen_write_return_integer(address_for_dev_type(dev, DEV_TYPE_SENSOR)); |
| 255 | acpigen_pop_len(); /* If Arg2=2 */ |
| 256 | |
| 257 | if (config->ssdb.vcm_type) { |
| 258 | /* If (LEqual (Local1, 3)) */ |
| 259 | acpigen_write_if_lequal_op_int(LOCAL1_OP, next_local1++); |
| 260 | acpigen_write_return_integer(address_for_dev_type(dev, DEV_TYPE_VCM)); |
| 261 | acpigen_pop_len(); /* If Arg2=3 */ |
| 262 | } |
| 263 | |
| 264 | if (config->ssdb.rom_type) { |
| 265 | /* If (LEqual (Local1, 3 or 4)) */ |
| 266 | acpigen_write_if_lequal_op_int(LOCAL1_OP, next_local1); |
| 267 | acpigen_write_return_integer(address_for_dev_type(dev, DEV_TYPE_ROM)); |
| 268 | acpigen_pop_len(); /* If Arg2=3 or 4 */ |
| 269 | } |
| 270 | |
| 271 | acpigen_pop_len(); /* If uuid */ |
| 272 | |
| 273 | /* Return (Buffer (One) { 0x0 }) */ |
| 274 | acpigen_write_return_singleton_buffer(0x0); |
| 275 | |
| 276 | acpigen_pop_len(); /* Method _DSM */ |
| 277 | } |
| 278 | |
Matt Delco | 879b3c1 | 2020-06-17 13:10:22 +0530 | [diff] [blame] | 279 | static void camera_fill_ssdb_defaults(struct drivers_intel_mipi_camera_config *config) |
Matt Delco | 1245b1e | 2020-06-17 07:26:55 +0530 | [diff] [blame] | 280 | { |
Matt Delco | 879b3c1 | 2020-06-17 13:10:22 +0530 | [diff] [blame] | 281 | struct device *cio2 = pcidev_on_root(CIO2_PCI_DEV, CIO2_PCI_FN); |
| 282 | struct drivers_intel_mipi_camera_config *cio2_config; |
| 283 | |
Matt Delco | 1245b1e | 2020-06-17 07:26:55 +0530 | [diff] [blame] | 284 | if (config->disable_ssdb_defaults) |
| 285 | return; |
| 286 | |
Matt Delco | 879b3c1 | 2020-06-17 13:10:22 +0530 | [diff] [blame] | 287 | if (!config->ssdb.bdf_value) |
| 288 | config->ssdb.bdf_value = PCI_DEVFN(CIO2_PCI_DEV, CIO2_PCI_FN); |
| 289 | |
Matt Delco | 1245b1e | 2020-06-17 07:26:55 +0530 | [diff] [blame] | 290 | if (!config->ssdb.platform) |
| 291 | config->ssdb.platform = PLATFORM_SKC; |
| 292 | |
| 293 | if (!config->ssdb.flash_support) |
| 294 | config->ssdb.flash_support = FLASH_DISABLE; |
| 295 | |
| 296 | if (!config->ssdb.privacy_led) |
| 297 | config->ssdb.privacy_led = PRIVACY_LED_A_16mA; |
| 298 | |
| 299 | if (!config->ssdb.mipi_define) |
| 300 | config->ssdb.mipi_define = MIPI_INFO_ACPI_DEFINED; |
| 301 | |
| 302 | if (!config->ssdb.mclk_speed) |
| 303 | config->ssdb.mclk_speed = CLK_FREQ_19_2MHZ; |
Matt Delco | 879b3c1 | 2020-06-17 13:10:22 +0530 | [diff] [blame] | 304 | |
| 305 | if (!config->ssdb.lanes_used) { |
| 306 | cio2_config = cio2 ? cio2->chip_info : NULL; |
| 307 | |
| 308 | if (!cio2_config) { |
| 309 | printk(BIOS_ERR, "Failed to get CIO2 config\n"); |
| 310 | } else if (cio2_config->device_type != INTEL_ACPI_CAMERA_CIO2) { |
| 311 | printk(BIOS_ERR, "Device type isn't CIO2: %u\n", |
| 312 | (u32)cio2_config->device_type); |
| 313 | } else if (config->ssdb.link_used >= cio2_config->cio2_num_ports) { |
| 314 | printk(BIOS_ERR, "%u exceeds CIO2's %u links\n", |
| 315 | (u32)config->ssdb.link_used, |
| 316 | (u32)cio2_config->cio2_num_ports); |
| 317 | } else { |
| 318 | config->ssdb.lanes_used = |
| 319 | cio2_config->cio2_lanes_used[config->ssdb.link_used]; |
| 320 | } |
| 321 | } |
Matt Delco | 1245b1e | 2020-06-17 07:26:55 +0530 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /* |
| 325 | * Adds settings for a camera sensor device (typically at "\_SB.PCI0.I2Cx.CAMy"). The drivers |
| 326 | * for Linux tends to expect the camera sensor device and any related nvram / vcm devices to be |
| 327 | * separate ACPI devices, while the drivers for Windows want all of these to be grouped |
| 328 | * together in the camera sensor ACPI device. This implementation tries to satisfy both, |
| 329 | * though the unfortunate tradeoff is that the same I2C address for nvram and vcm is advertised |
| 330 | * by multiple devices in ACPI (via "_CRS"). The Windows driver can use the "_DSM" method to |
| 331 | * disambiguate the I2C resources in the camera sensor ACPI device. Drivers for Windows |
| 332 | * typically query "SSDB" for configuration information (represented as a binary blob dump of |
| 333 | * struct), while Linux drivers typically consult individual parameters in "_DSD". |
| 334 | * |
| 335 | * The tree of tables in "_DSD" is analogous to what's used for the "CIO2" device. The _DSD |
| 336 | * specifies a child table for the sensor's port (e.g., PRT0 for "port0"--this implementation |
| 337 | * assumes a camera only has 1 port). The PRT0 table specifies a table for each endpoint |
| 338 | * (though only 1 endpoint is supported by this implementation so the table only has an |
| 339 | * "endpoint0" that points to a EP00 table). The EP00 table primarily describes the # of lanes |
| 340 | * in "data-lines", a list of frequencies in "list-frequencies", and specifies the name of the |
| 341 | * other side in "remote-endpoint" (typically "\_SB.PCI0.CIO2"). |
| 342 | */ |
| 343 | static void camera_fill_sensor(const struct device *dev) |
| 344 | { |
| 345 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
| 346 | struct acpi_dp *ep00 = NULL; |
| 347 | struct acpi_dp *prt0 = NULL; |
| 348 | struct acpi_dp *dsd = NULL; |
| 349 | struct acpi_dp *remote = NULL; |
| 350 | const char *vcm_name = NULL; |
| 351 | struct acpi_dp *lens_focus = NULL; |
Matt Delco | 879b3c1 | 2020-06-17 13:10:22 +0530 | [diff] [blame] | 352 | const char *remote_name; |
| 353 | struct device *cio2 = pcidev_on_root(CIO2_PCI_DEV, CIO2_PCI_FN); |
Matt Delco | 1245b1e | 2020-06-17 07:26:55 +0530 | [diff] [blame] | 354 | |
Matt Delco | 1ffee9d | 2020-06-17 12:55:35 +0530 | [diff] [blame] | 355 | camera_generate_pld(dev); |
| 356 | |
Matt Delco | 879b3c1 | 2020-06-17 13:10:22 +0530 | [diff] [blame] | 357 | camera_fill_ssdb_defaults(config); |
Matt Delco | 1245b1e | 2020-06-17 07:26:55 +0530 | [diff] [blame] | 358 | |
Matt Delco | 964033f | 2020-06-17 12:49:43 +0530 | [diff] [blame] | 359 | /* _DSM */ |
| 360 | camera_generate_dsm(dev); |
| 361 | |
Matt Delco | 1245b1e | 2020-06-17 07:26:55 +0530 | [diff] [blame] | 362 | ep00 = acpi_dp_new_table("EP00"); |
| 363 | acpi_dp_add_integer(ep00, "endpoint", DEFAULT_ENDPOINT); |
| 364 | acpi_dp_add_integer(ep00, "clock-lanes", 0); |
| 365 | |
| 366 | if (config->ssdb.lanes_used > 0) { |
| 367 | struct acpi_dp *lanes = acpi_dp_new_table("data-lanes"); |
| 368 | uint32_t i; |
| 369 | for (i = 1; i <= config->ssdb.lanes_used; ++i) |
| 370 | acpi_dp_add_integer(lanes, NULL, i); |
| 371 | acpi_dp_add_array(ep00, lanes); |
| 372 | } |
| 373 | |
| 374 | if (config->num_freq_entries) { |
| 375 | struct acpi_dp *freq = acpi_dp_new_table("link-frequencies"); |
| 376 | uint32_t i; |
| 377 | for (i = 0; i < config->num_freq_entries && i < MAX_LINK_FREQ_ENTRIES; ++i) |
| 378 | acpi_dp_add_integer(freq, NULL, config->link_freq[i]); |
| 379 | acpi_dp_add_array(ep00, freq); |
| 380 | } |
| 381 | |
| 382 | remote = acpi_dp_new_table("remote-endpoint"); |
| 383 | |
Matt Delco | 879b3c1 | 2020-06-17 13:10:22 +0530 | [diff] [blame] | 384 | if (config->remote_name) { |
| 385 | remote_name = config->remote_name; |
| 386 | } else { |
| 387 | if (cio2) |
| 388 | remote_name = acpi_device_path(cio2); |
| 389 | else |
| 390 | remote_name = DEFAULT_REMOTE_NAME; |
| 391 | } |
| 392 | |
| 393 | acpi_dp_add_reference(remote, NULL, remote_name); |
Matt Delco | 1245b1e | 2020-06-17 07:26:55 +0530 | [diff] [blame] | 394 | acpi_dp_add_integer(remote, NULL, config->ssdb.link_used); |
| 395 | acpi_dp_add_integer(remote, NULL, DEFAULT_ENDPOINT); |
| 396 | acpi_dp_add_array(ep00, remote); |
| 397 | |
| 398 | prt0 = acpi_dp_new_table("PRT0"); |
| 399 | |
| 400 | acpi_dp_add_integer(prt0, "port", 0); |
| 401 | acpi_dp_add_child(prt0, "endpoint0", ep00); |
| 402 | dsd = acpi_dp_new_table("_DSD"); |
| 403 | |
| 404 | acpi_dp_add_integer(dsd, "clock-frequency", config->ssdb.mclk_speed); |
| 405 | |
| 406 | if (config->ssdb.degree) |
| 407 | acpi_dp_add_integer(dsd, "rotation", 180); |
| 408 | |
| 409 | if (config->ssdb.vcm_type) { |
| 410 | if (config->vcm_name) { |
| 411 | vcm_name = config->vcm_name; |
| 412 | } else { |
| 413 | const struct device_path path = { |
| 414 | .type = DEVICE_PATH_I2C, |
| 415 | .i2c.device = config->vcm_address, |
| 416 | }; |
| 417 | struct device *vcm_dev = find_dev_path(dev->bus, &path); |
| 418 | struct drivers_intel_mipi_camera_config *vcm_config; |
| 419 | vcm_config = vcm_dev ? vcm_dev->chip_info : NULL; |
| 420 | |
| 421 | if (!vcm_config) |
| 422 | printk(BIOS_ERR, "Failed to get VCM\n"); |
| 423 | else if (vcm_config->device_type != INTEL_ACPI_CAMERA_VCM) |
| 424 | printk(BIOS_ERR, "Device isn't VCM\n"); |
| 425 | else |
| 426 | vcm_name = acpi_device_path(vcm_dev); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | if (vcm_name) { |
| 431 | lens_focus = acpi_dp_new_table("lens-focus"); |
| 432 | acpi_dp_add_reference(lens_focus, NULL, vcm_name); |
| 433 | acpi_dp_add_array(dsd, lens_focus); |
| 434 | } |
| 435 | |
| 436 | acpi_dp_add_child(dsd, "port0", prt0); |
| 437 | acpi_dp_write(dsd); |
| 438 | |
| 439 | acpigen_write_method_serialized("SSDB", 0); |
| 440 | acpigen_write_return_byte_buffer((uint8_t *)&config->ssdb, sizeof(config->ssdb)); |
| 441 | acpigen_pop_len(); /* Method */ |
| 442 | |
| 443 | /* Fill Power Sequencing Data */ |
| 444 | if (config->num_pwdb_entries > 0) { |
| 445 | acpigen_write_method_serialized("PWDB", 0); |
| 446 | acpigen_write_return_byte_buffer((uint8_t *)&config->pwdb, |
| 447 | sizeof(struct intel_pwdb) * |
| 448 | config->num_pwdb_entries); |
| 449 | acpigen_pop_len(); /* Method */ |
| 450 | } |
| 451 | } |
| 452 | |
Matt Delco | c3a83bf | 2020-06-16 12:02:34 +0530 | [diff] [blame] | 453 | static void camera_fill_nvm(const struct device *dev) |
| 454 | { |
| 455 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
John Zhao | 388e551 | 2020-09-18 11:54:05 -0700 | [diff] [blame] | 456 | struct acpi_dp *dsd; |
Matt Delco | c3a83bf | 2020-06-16 12:02:34 +0530 | [diff] [blame] | 457 | |
Pandya, Varshit B | cd91db9 | 2020-09-03 20:38:46 +0530 | [diff] [blame] | 458 | if (!config->nvm_compat) |
| 459 | return; |
| 460 | |
John Zhao | 388e551 | 2020-09-18 11:54:05 -0700 | [diff] [blame] | 461 | dsd = acpi_dp_new_table("_DSD"); |
| 462 | |
Matt Delco | c3a83bf | 2020-06-16 12:02:34 +0530 | [diff] [blame] | 463 | /* It might be possible to default size or width based on type. */ |
| 464 | if (!config->disable_nvm_defaults && !config->nvm_pagesize) |
| 465 | config->nvm_pagesize = 1; |
| 466 | |
| 467 | if (!config->disable_nvm_defaults && !config->nvm_readonly) |
| 468 | config->nvm_readonly = 1; |
| 469 | |
| 470 | if (config->nvm_size) |
| 471 | acpi_dp_add_integer(dsd, "size", config->nvm_size); |
| 472 | |
| 473 | if (config->nvm_pagesize) |
| 474 | acpi_dp_add_integer(dsd, "pagesize", config->nvm_pagesize); |
| 475 | |
| 476 | if (config->nvm_readonly) |
| 477 | acpi_dp_add_integer(dsd, "read-only", config->nvm_readonly); |
| 478 | |
| 479 | if (config->nvm_width) |
| 480 | acpi_dp_add_integer(dsd, "address-width", config->nvm_width); |
| 481 | |
Pandya, Varshit B | cd91db9 | 2020-09-03 20:38:46 +0530 | [diff] [blame] | 482 | acpi_dp_add_string(dsd, "compatible", config->nvm_compat); |
Matt Delco | c3a83bf | 2020-06-16 12:02:34 +0530 | [diff] [blame] | 483 | acpi_dp_write(dsd); |
| 484 | } |
| 485 | |
| 486 | static void camera_fill_vcm(const struct device *dev) |
| 487 | { |
| 488 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
| 489 | struct acpi_dp *dsd; |
| 490 | |
| 491 | if (!config->vcm_compat) |
| 492 | return; |
| 493 | |
| 494 | dsd = acpi_dp_new_table("_DSD"); |
| 495 | acpi_dp_add_string(dsd, "compatible", config->vcm_compat); |
| 496 | acpi_dp_write(dsd); |
| 497 | } |
| 498 | |
Sugnan Prabhu S | 6d9f243 | 2020-07-02 13:02:23 +0530 | [diff] [blame] | 499 | static int get_resource_index(const struct resource_config *res_config) |
| 500 | { |
| 501 | enum ctrl_type type = resource_get_ctrl_type(res_config); |
| 502 | const struct clk_config *clk_config; |
| 503 | const struct gpio_config *gpio_config; |
| 504 | unsigned int i; |
| 505 | uint8_t res_id; |
| 506 | |
| 507 | switch (type) { |
| 508 | case IMGCLK: |
| 509 | clk_config = resource_clk_config(res_config); |
| 510 | res_id = clk_config->clknum; |
| 511 | break; |
| 512 | case GPIO: |
| 513 | gpio_config = resource_gpio_config(res_config); |
| 514 | res_id = gpio_config->gpio_num; |
| 515 | break; |
| 516 | default: |
| 517 | printk(BIOS_ERR, "Unsupported power operation: %x\n" |
| 518 | "OS camera driver will likely not work", type); |
| 519 | return -1; |
| 520 | } |
| 521 | |
| 522 | for (i = 0; i < res_mgr.cnt; i++) |
| 523 | if (res_mgr.resource[i].type == type && res_mgr.resource[i].id == res_id) |
| 524 | return i; |
| 525 | |
| 526 | return -1; |
| 527 | } |
| 528 | |
| 529 | static void add_guarded_method_namestring(struct resource_config *res_config, int res_index) |
| 530 | { |
| 531 | char method_name[ACPI_NAME_BUFFER_SIZE]; |
| 532 | enum action_type action = resource_get_action_type(res_config); |
| 533 | |
| 534 | switch (action) { |
| 535 | case ENABLE: |
| 536 | snprintf(method_name, sizeof(method_name), ENABLE_METHOD_FORMAT, res_index); |
| 537 | break; |
| 538 | case DISABLE: |
| 539 | snprintf(method_name, sizeof(method_name), DISABLE_METHOD_FORMAT, res_index); |
| 540 | break; |
| 541 | default: |
| 542 | snprintf(method_name, sizeof(method_name), UNKNOWN_METHOD_FORMAT, res_index); |
| 543 | printk(BIOS_ERR, "Unsupported resource action: %x\n", action); |
| 544 | } |
| 545 | |
| 546 | acpigen_emit_namestring(method_name); |
| 547 | } |
| 548 | |
| 549 | static void call_guarded_method(struct resource_config *res_config) |
| 550 | { |
| 551 | int res_index; |
| 552 | |
| 553 | if (res_config == NULL) |
| 554 | return; |
| 555 | |
| 556 | res_index = get_resource_index(res_config); |
| 557 | |
| 558 | if (res_index != -1) |
| 559 | add_guarded_method_namestring(res_config, res_index); |
| 560 | } |
| 561 | |
| 562 | static void add_clk_op(const struct clk_config *clk_config, enum action_type action) |
| 563 | { |
| 564 | if (clk_config == NULL) |
| 565 | return; |
| 566 | |
| 567 | switch (action) { |
| 568 | case ENABLE: |
| 569 | acpigen_write_if(); |
| 570 | acpigen_emit_ext_op(COND_REFOF_OP); |
| 571 | acpigen_emit_string(CLK_ENABLE_METHOD); |
| 572 | acpigen_emit_namestring(CLK_ENABLE_METHOD); |
| 573 | acpigen_write_integer(clk_config->clknum); |
| 574 | acpigen_write_integer(clk_config->freq); |
| 575 | acpigen_pop_len(); /* CondRefOf */ |
| 576 | break; |
| 577 | case DISABLE: |
| 578 | acpigen_write_if(); |
| 579 | acpigen_emit_ext_op(COND_REFOF_OP); |
| 580 | acpigen_emit_string(CLK_DISABLE_METHOD); |
| 581 | acpigen_emit_namestring(CLK_DISABLE_METHOD); |
| 582 | acpigen_write_integer(clk_config->clknum); |
| 583 | acpigen_pop_len(); /* CondRefOf */ |
| 584 | break; |
| 585 | default: |
| 586 | acpigen_write_debug_string("Unsupported clock action"); |
| 587 | printk(BIOS_ERR, "Unsupported clock action: %x\n" |
| 588 | "OS camera driver will likely not work", action); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | static void add_gpio_op(const struct gpio_config *gpio_config, enum action_type action) |
| 593 | { |
| 594 | if (gpio_config == NULL) |
| 595 | return; |
| 596 | |
| 597 | switch (action) { |
| 598 | case ENABLE: |
| 599 | acpigen_soc_set_tx_gpio(gpio_config->gpio_num); |
| 600 | break; |
| 601 | case DISABLE: |
| 602 | acpigen_soc_clear_tx_gpio(gpio_config->gpio_num); |
| 603 | break; |
| 604 | default: |
| 605 | acpigen_write_debug_string("Unsupported GPIO action"); |
| 606 | printk(BIOS_ERR, "Unsupported GPIO action: %x\n" |
| 607 | "OS camera driver will likely not work\n", action); |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | static void add_power_operation(const struct resource_config *res_config) |
| 612 | { |
| 613 | const struct clk_config *clk_config; |
| 614 | const struct gpio_config *gpio_config; |
| 615 | enum ctrl_type type = resource_get_ctrl_type(res_config); |
| 616 | enum action_type action = resource_get_action_type(res_config); |
| 617 | |
| 618 | if (res_config == NULL) |
| 619 | return; |
| 620 | |
| 621 | switch (type) { |
| 622 | case IMGCLK: |
| 623 | clk_config = resource_clk_config(res_config); |
| 624 | add_clk_op(clk_config, action); |
| 625 | break; |
| 626 | case GPIO: |
| 627 | gpio_config = resource_gpio_config(res_config); |
| 628 | add_gpio_op(gpio_config, action); |
| 629 | break; |
| 630 | default: |
| 631 | printk(BIOS_ERR, "Unsupported power operation: %x\n" |
| 632 | "OS camera driver will likely not work\n", type); |
| 633 | break; |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | static void write_guard_variable(uint8_t res_index) |
| 638 | { |
| 639 | char varname[ACPI_NAME_BUFFER_SIZE]; |
| 640 | |
| 641 | snprintf(varname, sizeof(varname), GUARD_VARIABLE_FORMAT, res_index); |
| 642 | acpigen_write_name_integer(varname, 0); |
| 643 | } |
| 644 | |
| 645 | static void write_enable_method(struct resource_config *res_config, uint8_t res_index) |
| 646 | { |
| 647 | char method_name[ACPI_NAME_BUFFER_SIZE]; |
| 648 | char varname[ACPI_NAME_BUFFER_SIZE]; |
| 649 | |
| 650 | snprintf(varname, sizeof(varname), GUARD_VARIABLE_FORMAT, res_index); |
| 651 | |
| 652 | snprintf(method_name, sizeof(method_name), ENABLE_METHOD_FORMAT, res_index); |
| 653 | |
| 654 | acpigen_write_method_serialized(method_name, 0); |
| 655 | acpigen_write_if_lequal_namestr_int(varname, 0); |
| 656 | resource_set_action_type(res_config, ENABLE); |
| 657 | add_power_operation(res_config); |
| 658 | acpigen_pop_len(); /* if */ |
| 659 | |
| 660 | acpigen_emit_byte(INCREMENT_OP); |
| 661 | acpigen_emit_namestring(varname); |
| 662 | acpigen_pop_len(); /* method_name */ |
| 663 | } |
| 664 | |
| 665 | static void write_disable_method(struct resource_config *res_config, uint8_t res_index) |
| 666 | { |
| 667 | char method_name[ACPI_NAME_BUFFER_SIZE]; |
| 668 | char varname[ACPI_NAME_BUFFER_SIZE]; |
| 669 | |
| 670 | snprintf(varname, sizeof(varname), GUARD_VARIABLE_FORMAT, res_index); |
| 671 | |
| 672 | snprintf(method_name, sizeof(method_name), DISABLE_METHOD_FORMAT, res_index); |
| 673 | |
| 674 | acpigen_write_method_serialized(method_name, 0); |
| 675 | acpigen_write_if(); |
| 676 | acpigen_emit_byte(LGREATER_OP); |
| 677 | acpigen_emit_namestring(varname); |
| 678 | acpigen_write_integer(0x0); |
| 679 | acpigen_emit_byte(DECREMENT_OP); |
| 680 | acpigen_emit_namestring(varname); |
| 681 | acpigen_pop_len(); /* if */ |
| 682 | |
| 683 | acpigen_write_if_lequal_namestr_int(varname, 0); |
| 684 | resource_set_action_type(res_config, DISABLE); |
| 685 | add_power_operation(res_config); |
| 686 | acpigen_pop_len(); /* if */ |
| 687 | acpigen_pop_len(); /* method_name */ |
| 688 | } |
| 689 | |
| 690 | static void add_guarded_operations(const struct drivers_intel_mipi_camera_config *config, |
| 691 | const struct operation_seq *seq) |
Sugnan Prabhu S | b087a94 | 2020-05-21 20:41:03 +0530 | [diff] [blame] | 692 | { |
| 693 | unsigned int i; |
| 694 | uint8_t index; |
Sugnan Prabhu S | 6d9f243 | 2020-07-02 13:02:23 +0530 | [diff] [blame] | 695 | uint8_t res_id; |
| 696 | struct resource_config res_config; |
| 697 | int res_index; |
Sugnan Prabhu S | b087a94 | 2020-05-21 20:41:03 +0530 | [diff] [blame] | 698 | |
Sugnan Prabhu S | 6d9f243 | 2020-07-02 13:02:23 +0530 | [diff] [blame] | 699 | for (i = 0; i < seq->ops_cnt && i < MAX_PWR_OPS; i++) { |
| 700 | index = seq->ops[i].index; |
Sugnan Prabhu S | b087a94 | 2020-05-21 20:41:03 +0530 | [diff] [blame] | 701 | switch (seq->ops[i].type) { |
| 702 | case IMGCLK: |
Sugnan Prabhu S | 6d9f243 | 2020-07-02 13:02:23 +0530 | [diff] [blame] | 703 | res_id = config->clk_panel.clks[index].clknum; |
| 704 | resource_set_clk_config(&res_config, &config->clk_panel.clks[index]); |
Sugnan Prabhu S | b087a94 | 2020-05-21 20:41:03 +0530 | [diff] [blame] | 705 | break; |
| 706 | case GPIO: |
Sugnan Prabhu S | 6d9f243 | 2020-07-02 13:02:23 +0530 | [diff] [blame] | 707 | res_id = config->gpio_panel.gpio[index].gpio_num; |
| 708 | resource_set_gpio_config(&res_config, &config->gpio_panel.gpio[index]); |
Sugnan Prabhu S | b087a94 | 2020-05-21 20:41:03 +0530 | [diff] [blame] | 709 | break; |
| 710 | default: |
Sugnan Prabhu S | 6d9f243 | 2020-07-02 13:02:23 +0530 | [diff] [blame] | 711 | printk(BIOS_ERR, "Unsupported power operation: %x\n" |
| 712 | "OS camera driver will likely not work\n", |
| 713 | seq->ops[i].type); |
| 714 | return; |
Sugnan Prabhu S | b087a94 | 2020-05-21 20:41:03 +0530 | [diff] [blame] | 715 | } |
| 716 | |
Sugnan Prabhu S | 6d9f243 | 2020-07-02 13:02:23 +0530 | [diff] [blame] | 717 | res_index = get_resource_index(&res_config); |
| 718 | |
| 719 | if (res_index == -1) { |
| 720 | if (res_mgr.cnt >= MAX_GUARDED_RESOURCES) { |
| 721 | printk(BIOS_ERR, "Unable to add guarded camera resource\n" |
| 722 | "OS camera driver will likely not work\n"); |
| 723 | return; |
| 724 | } |
| 725 | |
| 726 | res_mgr.resource[res_mgr.cnt].id = res_id; |
| 727 | res_mgr.resource[res_mgr.cnt].type = seq->ops[i].type; |
| 728 | |
| 729 | write_guard_variable(res_mgr.cnt); |
| 730 | write_enable_method(&res_config, res_mgr.cnt); |
| 731 | write_disable_method(&res_config, res_mgr.cnt); |
| 732 | |
| 733 | res_mgr.cnt++; |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | static void fill_power_res_sequence(struct drivers_intel_mipi_camera_config *config, |
| 739 | struct operation_seq *seq) |
| 740 | { |
| 741 | struct resource_config res_config; |
| 742 | unsigned int i; |
| 743 | uint8_t index; |
| 744 | |
| 745 | for (i = 0; i < seq->ops_cnt && i < MAX_PWR_OPS; i++) { |
| 746 | index = seq->ops[i].index; |
| 747 | |
| 748 | switch (seq->ops[i].type) { |
| 749 | case IMGCLK: |
| 750 | resource_set_clk_config(&res_config, &config->clk_panel.clks[index]); |
| 751 | break; |
| 752 | case GPIO: |
| 753 | resource_set_gpio_config(&res_config, &config->gpio_panel.gpio[index]); |
| 754 | break; |
| 755 | default: |
| 756 | printk(BIOS_ERR, "Unsupported power operation: %x\n" |
| 757 | "OS camera driver will likely not work\n", |
| 758 | seq->ops[i].type); |
| 759 | return; |
| 760 | } |
| 761 | |
| 762 | resource_set_action_type(&res_config, seq->ops[i].action); |
| 763 | call_guarded_method(&res_config); |
Sugnan Prabhu S | b087a94 | 2020-05-21 20:41:03 +0530 | [diff] [blame] | 764 | if (seq->ops[i].delay_ms) |
| 765 | acpigen_write_sleep(seq->ops[i].delay_ms); |
| 766 | } |
| 767 | } |
| 768 | |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 769 | static void write_pci_camera_device(const struct device *dev) |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 770 | { |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 771 | if (dev->path.type != DEVICE_PATH_PCI) { |
| 772 | printk(BIOS_ERR, "CIO2/IMGU devices require PCI\n"); |
| 773 | return; |
| 774 | } |
| 775 | |
| 776 | acpigen_write_device(acpi_device_name(dev)); |
| 777 | acpigen_write_ADR_pci_device(dev); |
Sugnan Prabhu S | 3ea036f | 2020-07-29 23:18:46 +0530 | [diff] [blame] | 778 | acpigen_write_name_string("_DDN", "Camera and Imaging Subsystem"); |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | static void write_i2c_camera_device(const struct device *dev, const char *scope) |
| 782 | { |
| 783 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 784 | struct acpi_i2c i2c = { |
| 785 | .address = dev->path.i2c.device, |
| 786 | .mode_10bit = dev->path.i2c.mode_10bit, |
| 787 | .speed = I2C_SPEED_FAST, |
| 788 | .resource = scope, |
| 789 | }; |
| 790 | |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 791 | acpigen_write_device(acpi_device_name(dev)); |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 792 | |
Sugnan Prabhu S | b087a94 | 2020-05-21 20:41:03 +0530 | [diff] [blame] | 793 | /* add power resource */ |
| 794 | if (config->has_power_resource) { |
| 795 | acpigen_write_power_res(POWER_RESOURCE_NAME, 0, 0, NULL, 0); |
| 796 | acpigen_write_name_integer("STA", 0); |
| 797 | acpigen_write_STA_ext("STA"); |
| 798 | |
| 799 | acpigen_write_method_serialized("_ON", 0); |
| 800 | acpigen_write_if(); |
| 801 | acpigen_emit_byte(LEQUAL_OP); |
| 802 | acpigen_emit_namestring("STA"); |
| 803 | acpigen_write_integer(0); |
| 804 | |
| 805 | fill_power_res_sequence(config, &config->on_seq); |
| 806 | |
| 807 | acpigen_write_store_op_to_namestr(1, "STA"); |
| 808 | acpigen_pop_len(); /* if */ |
| 809 | acpigen_pop_len(); /* _ON */ |
| 810 | |
| 811 | /* _OFF operations */ |
| 812 | acpigen_write_method_serialized("_OFF", 0); |
| 813 | acpigen_write_if(); |
| 814 | acpigen_emit_byte(LEQUAL_OP); |
| 815 | acpigen_emit_namestring("STA"); |
| 816 | acpigen_write_integer(1); |
| 817 | |
| 818 | fill_power_res_sequence(config, &config->off_seq); |
| 819 | |
| 820 | acpigen_write_store_op_to_namestr(0, "STA"); |
| 821 | acpigen_pop_len(); /* if */ |
| 822 | acpigen_pop_len(); /* _ON */ |
| 823 | |
| 824 | acpigen_pop_len(); /* Power Resource */ |
| 825 | } |
| 826 | |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 827 | if (config->device_type == INTEL_ACPI_CAMERA_SENSOR) |
| 828 | acpigen_write_name_integer("_ADR", 0); |
| 829 | |
| 830 | if (config->acpi_hid) |
| 831 | acpigen_write_name_string("_HID", config->acpi_hid); |
Pandya, Varshit B | cd91db9 | 2020-09-03 20:38:46 +0530 | [diff] [blame] | 832 | else if (config->device_type == INTEL_ACPI_CAMERA_VCM || |
| 833 | config->device_type == INTEL_ACPI_CAMERA_NVM) |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 834 | acpigen_write_name_string("_HID", ACPI_DT_NAMESPACE_HID); |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 835 | |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 836 | acpigen_write_name_integer("_UID", config->acpi_uid); |
| 837 | acpigen_write_name_string("_DDN", config->chip_name); |
Hung-Te Lin | b4be50c | 2018-09-10 10:55:49 +0800 | [diff] [blame] | 838 | acpigen_write_STA(acpi_device_status(dev)); |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 839 | |
| 840 | /* Resources */ |
| 841 | acpigen_write_name("_CRS"); |
| 842 | acpigen_write_resourcetemplate_header(); |
| 843 | acpi_device_write_i2c(&i2c); |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 844 | |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 845 | /* |
| 846 | * The optional vcm/nvram devices are presumed to be on the same I2C bus as the camera |
| 847 | * sensor. |
| 848 | */ |
| 849 | if (config->device_type == INTEL_ACPI_CAMERA_SENSOR && |
| 850 | config->ssdb.vcm_type && config->vcm_address) { |
| 851 | struct acpi_i2c i2c_vcm = i2c; |
| 852 | i2c_vcm.address = config->vcm_address; |
| 853 | acpi_device_write_i2c(&i2c_vcm); |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 854 | } |
| 855 | |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 856 | if (config->device_type == INTEL_ACPI_CAMERA_SENSOR && |
| 857 | config->ssdb.rom_type && config->rom_address) { |
| 858 | struct acpi_i2c i2c_rom = i2c; |
| 859 | i2c_rom.address = config->rom_address; |
| 860 | acpi_device_write_i2c(&i2c_rom); |
| 861 | } |
| 862 | |
| 863 | acpigen_write_resourcetemplate_footer(); |
| 864 | } |
| 865 | |
| 866 | static void write_camera_device_common(const struct device *dev) |
| 867 | { |
| 868 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
| 869 | |
| 870 | /* Mark it as Camera related device */ |
| 871 | if (config->device_type == INTEL_ACPI_CAMERA_CIO2 || |
| 872 | config->device_type == INTEL_ACPI_CAMERA_IMGU || |
| 873 | config->device_type == INTEL_ACPI_CAMERA_SENSOR || |
| 874 | config->device_type == INTEL_ACPI_CAMERA_VCM) { |
| 875 | acpigen_write_name_integer("CAMD", config->device_type); |
| 876 | } |
Matt Delco | c3a83bf | 2020-06-16 12:02:34 +0530 | [diff] [blame] | 877 | |
Sugnan Prabhu S | b087a94 | 2020-05-21 20:41:03 +0530 | [diff] [blame] | 878 | if (config->pr0 || config->has_power_resource) { |
| 879 | acpigen_write_name("_PR0"); |
| 880 | acpigen_write_package(1); |
| 881 | if (config->pr0) |
| 882 | acpigen_emit_namestring(config->pr0); /* External power resource */ |
| 883 | else |
| 884 | acpigen_emit_namestring(POWER_RESOURCE_NAME); |
| 885 | |
| 886 | acpigen_pop_len(); /* _PR0 */ |
| 887 | } |
| 888 | |
Matt Delco | c3a83bf | 2020-06-16 12:02:34 +0530 | [diff] [blame] | 889 | switch (config->device_type) { |
Matt Delco | 879b3c1 | 2020-06-17 13:10:22 +0530 | [diff] [blame] | 890 | case INTEL_ACPI_CAMERA_CIO2: |
| 891 | camera_fill_cio2(dev); |
| 892 | break; |
Matt Delco | 1245b1e | 2020-06-17 07:26:55 +0530 | [diff] [blame] | 893 | case INTEL_ACPI_CAMERA_SENSOR: |
| 894 | camera_fill_sensor(dev); |
| 895 | break; |
Matt Delco | c3a83bf | 2020-06-16 12:02:34 +0530 | [diff] [blame] | 896 | case INTEL_ACPI_CAMERA_VCM: |
| 897 | camera_fill_vcm(dev); |
| 898 | break; |
| 899 | case INTEL_ACPI_CAMERA_NVM: |
| 900 | camera_fill_nvm(dev); |
| 901 | break; |
| 902 | default: |
| 903 | break; |
| 904 | } |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | static void camera_fill_ssdt(const struct device *dev) |
| 908 | { |
| 909 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
Sugnan Prabhu S | 6d9f243 | 2020-07-02 13:02:23 +0530 | [diff] [blame] | 910 | const char *scope = NULL; |
| 911 | const struct device *pdev; |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 912 | |
Sugnan Prabhu S | 6d9f243 | 2020-07-02 13:02:23 +0530 | [diff] [blame] | 913 | if (config->has_power_resource) { |
| 914 | pdev = dev->bus->dev; |
| 915 | if (!pdev || !pdev->enabled) |
| 916 | return; |
| 917 | |
| 918 | scope = acpi_device_scope(pdev); |
| 919 | if (!scope) |
| 920 | return; |
| 921 | |
| 922 | acpigen_write_scope(scope); |
| 923 | add_guarded_operations(config, &config->on_seq); |
| 924 | add_guarded_operations(config, &config->off_seq); |
| 925 | acpigen_pop_len(); /* Guarded power resource operations scope */ |
| 926 | } |
| 927 | |
Sugnan Prabhu S | 3ea036f | 2020-07-29 23:18:46 +0530 | [diff] [blame] | 928 | switch (dev->path.type) { |
| 929 | case DEVICE_PATH_I2C: |
| 930 | scope = acpi_device_scope(dev); |
| 931 | if (!scope) |
| 932 | return; |
Sugnan Prabhu S | 6d9f243 | 2020-07-02 13:02:23 +0530 | [diff] [blame] | 933 | |
Sugnan Prabhu S | 3ea036f | 2020-07-29 23:18:46 +0530 | [diff] [blame] | 934 | acpigen_write_scope(scope); |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 935 | write_i2c_camera_device(dev, scope); |
Sugnan Prabhu S | 3ea036f | 2020-07-29 23:18:46 +0530 | [diff] [blame] | 936 | break; |
| 937 | case DEVICE_PATH_GENERIC: |
| 938 | pdev = dev->bus->dev; |
| 939 | scope = acpi_device_scope(pdev); |
| 940 | if (!scope) |
| 941 | return; |
| 942 | |
| 943 | acpigen_write_scope(scope); |
| 944 | write_pci_camera_device(pdev); |
| 945 | break; |
| 946 | default: |
| 947 | printk(BIOS_ERR, "Unsupported device type: %x\n" |
| 948 | "OS camera driver will likely not work\n", dev->path.type); |
| 949 | return; |
| 950 | } |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 951 | |
| 952 | write_camera_device_common(dev); |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 953 | |
| 954 | acpigen_pop_len(); /* Device */ |
| 955 | acpigen_pop_len(); /* Scope */ |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 956 | |
| 957 | if (dev->path.type == DEVICE_PATH_PCI) { |
| 958 | printk(BIOS_INFO, "%s: %s PCI address 0%x\n", acpi_device_path(dev), |
| 959 | dev->chip_ops->name, dev->path.pci.devfn); |
| 960 | } else { |
| 961 | printk(BIOS_INFO, "%s: %s I2C address 0%xh\n", acpi_device_path(dev), |
| 962 | dev->chip_ops->name, dev->path.i2c.device); |
| 963 | } |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 964 | } |
| 965 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 966 | static const char *camera_acpi_name(const struct device *dev) |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 967 | { |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 968 | const char *prefix = NULL; |
Sugnan Prabhu S | 6d9f243 | 2020-07-02 13:02:23 +0530 | [diff] [blame] | 969 | static char name[ACPI_NAME_BUFFER_SIZE]; |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 970 | struct drivers_intel_mipi_camera_config *config = dev->chip_info; |
Matt Delco | 7d00293 | 2020-06-16 11:39:52 +0530 | [diff] [blame] | 971 | |
| 972 | if (config->acpi_name) |
| 973 | return config->acpi_name; |
| 974 | |
| 975 | switch (config->device_type) { |
| 976 | case INTEL_ACPI_CAMERA_CIO2: |
| 977 | return "CIO2"; |
| 978 | case INTEL_ACPI_CAMERA_IMGU: |
| 979 | return "IMGU"; |
| 980 | case INTEL_ACPI_CAMERA_PMIC: |
| 981 | return "PMIC"; |
| 982 | case INTEL_ACPI_CAMERA_SENSOR: |
| 983 | prefix = "CAM"; |
| 984 | break; |
| 985 | case INTEL_ACPI_CAMERA_VCM: |
| 986 | prefix = "VCM"; |
| 987 | break; |
| 988 | case INTEL_ACPI_CAMERA_NVM: |
| 989 | prefix = "NVM"; |
| 990 | break; |
| 991 | default: |
| 992 | printk(BIOS_ERR, "Invalid device type: %x\n", config->device_type); |
| 993 | return NULL; |
| 994 | } |
| 995 | |
| 996 | /* |
| 997 | * The camera # knows which link # they use, so that's used as the basis for the |
| 998 | * instance #. The VCM and NVM don't have this information, so the best we can go on is |
| 999 | * the _UID. |
| 1000 | */ |
| 1001 | snprintf(name, sizeof(name), "%s%1u", prefix, |
| 1002 | config->device_type == INTEL_ACPI_CAMERA_SENSOR ? |
| 1003 | config->ssdb.link_used : config->acpi_uid); |
| 1004 | return name; |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | static struct device_operations camera_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 1008 | .read_resources = noop_read_resources, |
| 1009 | .set_resources = noop_set_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 1010 | .acpi_name = camera_acpi_name, |
| 1011 | .acpi_fill_ssdt = camera_fill_ssdt, |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 1012 | }; |
| 1013 | |
| 1014 | static void camera_enable(struct device *dev) |
| 1015 | { |
| 1016 | dev->ops = &camera_ops; |
| 1017 | } |
| 1018 | |
| 1019 | struct chip_operations drivers_intel_mipi_camera_ops = { |
| 1020 | CHIP_NAME("Intel MIPI Camera Device") |
Elyes HAOUAS | 2aa3b16 | 2018-11-27 17:02:10 +0100 | [diff] [blame] | 1021 | .enable_dev = camera_enable |
V Sowmya | 9f8023a | 2017-02-28 17:52:05 +0530 | [diff] [blame] | 1022 | }; |