| 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #ifndef __I2C_GENERIC_CHIP_H__ |
| 4 | #define __I2C_GENERIC_CHIP_H__ |
| 5 | |
| 6 | #include <acpi/acpi_device.h> |
| 7 | #include <device/i2c_simple.h> |
| 8 | |
| 9 | #define MAX_GENERIC_PROPERTY_LIST 10 |
| 10 | |
| 11 | struct drivers_i2c_generic_config { |
| 12 | const char *hid; /* ACPI _HID (required) */ |
| 13 | const char *cid; /* ACPI _CID */ |
| 14 | const char *sub; /* ACPI _SUB */ |
| 15 | const char *name; /* ACPI Device Name */ |
| 16 | const char *desc; /* Device Description */ |
| 17 | unsigned int uid; /* ACPI _UID */ |
| 18 | enum i2c_speed speed; /* Bus speed in Hz, default is I2C_SPEED_FAST */ |
| 19 | const char *compat_string; /* Compatible string for _HID=PRP0001 */ |
| 20 | unsigned int wake; /* Wake GPE */ |
| 21 | struct acpi_irq irq; /* Interrupt */ |
| 22 | |
| 23 | /* Use GPIO based interrupt instead of PIRQ */ |
| 24 | struct acpi_gpio irq_gpio; |
| 25 | |
| 26 | /* |
| 27 | * This flag will add a device property which will indicate |
| 28 | * to the OS that it should probe this device before adding it. |
| 29 | * |
| 30 | * This can be used to declare a device that may not exist on |
| 31 | * the board, for example to support multiple trackpad vendors. |
| 32 | */ |
| 33 | int probed; |
| 34 | |
| 35 | /* |
| 36 | * This flag will add a device property which will indicate |
| 37 | * that coreboot should attempt to detect the device on the i2c |
| 38 | * bus before generating a device entry in the SSDT. |
| 39 | * |
| 40 | * This can be used to declare a device that may not exist on |
| 41 | * the board, for example to support multiple touchpads and/or |
| 42 | * touchscreens. |
| 43 | */ |
| 44 | int detect; |
| 45 | |
| 46 | /* GPIO used to indicate if this device is present */ |
| 47 | unsigned int device_present_gpio; |
| 48 | unsigned int device_present_gpio_invert; |
| 49 | |
| 50 | /* Does the device have a power resource? */ |
| 51 | bool has_power_resource; |
| 52 | |
| 53 | /* GPIO used to take device out of reset or to put it into reset. */ |
| 54 | struct acpi_gpio reset_gpio; |
| 55 | /* Delay to be inserted after device is taken out of reset. */ |
| 56 | unsigned int reset_delay_ms; |
| 57 | /* Delay to be inserted after device is put into reset. */ |
| 58 | unsigned int reset_off_delay_ms; |
| 59 | /* GPIO used to enable device. */ |
| 60 | struct acpi_gpio enable_gpio; |
| 61 | /* Delay to be inserted after device is enabled. */ |
| 62 | unsigned int enable_delay_ms; |
| 63 | /* Delay to be inserted after device is disabled. */ |
| 64 | unsigned int enable_off_delay_ms; |
| 65 | /* GPIO used to stop operation of device. */ |
| 66 | struct acpi_gpio stop_gpio; |
| 67 | /* Delay to be inserted after disabling stop. */ |
| 68 | unsigned int stop_delay_ms; |
| 69 | /* Delay to be inserted after enabling stop. */ |
| 70 | unsigned int stop_off_delay_ms; |
| 71 | |
| 72 | /* |
| 73 | * The Rotation Matrix' allows specifying a 3x3 matrix representing |
| 74 | * the orientation of devices, such as accelerometers. Each value in |
| 75 | * the matrix can be one of -1, 0, or 1, indicating the transformation |
| 76 | * applied to the device's axes. |
| 77 | * |
| 78 | * It is expected by linux and required for the OS to correctly interpret |
| 79 | * the data from the device. |
| 80 | */ |
| 81 | bool has_rotation_matrix; |
| 82 | int rotation_matrix[9]; |
| 83 | |
| 84 | /* |
| 85 | * Chip Direct Mapping is exclusive to Windows, a allows specifying the |
| 86 | * position where a chip is mounted. There are 8 positions: |
| 87 | * 1: 90 Degrees |
| 88 | * 2: 270 Degrees |
| 89 | * 3: 180 Degrees |
| 90 | * 4: 0 Degrees |
| 91 | * 5: 90 Degrees (Inverted) |
| 92 | * 6: 270 Degrees (Inverted) |
| 93 | * 7: 180 Degrees (Inverted) |
| 94 | * 8: 0 Degrees (Inverted) |
| 95 | * |
| 96 | * The _CDM method should return 0xabcd0X, where X is the position. |
| 97 | */ |
| 98 | enum { |
| 99 | CDM_NOT_PRESENT = 0, |
| 100 | CDM_ROT_90, |
| 101 | CDM_ROT_180, |
| 102 | CDM_ROT_270, |
| 103 | CDM_ROT_0, |
| 104 | CDM_ROT_90_INVERT, |
| 105 | CDM_ROT_180_INVERT, |
| 106 | CDM_ROT_270_INVERT, |
| 107 | CDM_ROT_0_INVERT, |
| 108 | } cdm_index; |
| 109 | |
| 110 | /* Generic properties for exporting device-specific data to the OS */ |
| 111 | struct acpi_dp property_list[MAX_GENERIC_PROPERTY_LIST]; |
| 112 | int property_count; |
| 113 | |
| 114 | /* Write a _STA method that uses the state of the GPIOs to determine if |
| 115 | * the PowerResource is ON or OFF. If this is false, the _STA method |
| 116 | * will always return ON. |
| 117 | */ |
| 118 | bool use_gpio_for_status; |
| 119 | }; |
| 120 | |
| 121 | /* |
| 122 | * Fills in generic information about i2c device from device-tree |
| 123 | * properties. Callback can be provided to fill in any |
| 124 | * device-specific information in SSDT. |
| 125 | * |
| 126 | * Parameters: |
| 127 | * dev: Device requesting i2c generic information to be filled |
| 128 | * callback: Callback to fill in device-specific information |
| 129 | * config: Pointer to drivers_i2c_generic_config structure |
| 130 | */ |
| 131 | void i2c_generic_fill_ssdt(const struct device *dev, |
| 132 | void (*callback)(const struct device *dev), |
| 133 | struct drivers_i2c_generic_config *config); |
| 134 | |
| 135 | #endif /* __I2C_GENERIC_CHIP_H__ */ |