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