Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Generation of tables for particular device types |
| 4 | * |
| 5 | * Copyright 2019 Google LLC |
| 6 | * Mostly taken from coreboot file of the same name |
| 7 | */ |
| 8 | |
| 9 | #ifndef __ACPI_DEVICE_H |
| 10 | #define __ACPI_DEVICE_H |
| 11 | |
Simon Glass | 39ab867 | 2020-07-07 13:11:48 -0600 | [diff] [blame] | 12 | #include <i2c.h> |
Simon Glass | 31cc5b4 | 2020-09-22 12:45:01 -0600 | [diff] [blame] | 13 | #include <irq.h> |
Simon Glass | 711fd98 | 2020-07-07 13:11:49 -0600 | [diff] [blame] | 14 | #include <spi.h> |
Simon Glass | 31cc5b4 | 2020-09-22 12:45:01 -0600 | [diff] [blame] | 15 | #include <asm-generic/gpio.h> |
Simon Glass | 8965cc9 | 2020-07-07 13:11:40 -0600 | [diff] [blame] | 16 | #include <linux/bitops.h> |
| 17 | |
Simon Glass | 3d39c13 | 2020-07-07 13:11:43 -0600 | [diff] [blame] | 18 | struct acpi_ctx; |
Simon Glass | 4fa6331 | 2020-07-07 13:11:46 -0600 | [diff] [blame] | 19 | struct gpio_desc; |
Simon Glass | 3d39c13 | 2020-07-07 13:11:43 -0600 | [diff] [blame] | 20 | struct irq; |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 21 | struct udevice; |
| 22 | |
Simon Glass | b24cbf4 | 2020-07-07 13:11:41 -0600 | [diff] [blame] | 23 | /* ACPI descriptor values for common descriptors: SERIAL_BUS means I2C */ |
| 24 | #define ACPI_DESCRIPTOR_LARGE BIT(7) |
Simon Glass | 837127f | 2020-07-07 21:32:11 -0600 | [diff] [blame] | 25 | #define ACPI_DESCRIPTOR_REGISTER (ACPI_DESCRIPTOR_LARGE | 2) |
Simon Glass | b24cbf4 | 2020-07-07 13:11:41 -0600 | [diff] [blame] | 26 | #define ACPI_DESCRIPTOR_INTERRUPT (ACPI_DESCRIPTOR_LARGE | 9) |
| 27 | #define ACPI_DESCRIPTOR_GPIO (ACPI_DESCRIPTOR_LARGE | 12) |
| 28 | #define ACPI_DESCRIPTOR_SERIAL_BUS (ACPI_DESCRIPTOR_LARGE | 14) |
| 29 | |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 30 | /* Length of a full path to an ACPI device */ |
| 31 | #define ACPI_PATH_MAX 30 |
| 32 | |
Simon Glass | 4c8cbbd | 2020-09-22 12:44:58 -0600 | [diff] [blame] | 33 | /* UUID for an I2C _DSM method */ |
| 34 | #define ACPI_DSM_I2C_HID_UUID "3cdff6f7-4267-4555-ad05-b30a3d8938de" |
| 35 | |
Simon Glass | 8965cc9 | 2020-07-07 13:11:40 -0600 | [diff] [blame] | 36 | /* Values that can be returned for ACPI device _STA method */ |
| 37 | enum acpi_dev_status { |
| 38 | ACPI_DSTATUS_PRESENT = BIT(0), |
| 39 | ACPI_DSTATUS_ENABLED = BIT(1), |
| 40 | ACPI_DSTATUS_SHOW_IN_UI = BIT(2), |
| 41 | ACPI_DSTATUS_OK = BIT(3), |
| 42 | ACPI_DSTATUS_HAS_BATTERY = BIT(4), |
| 43 | |
| 44 | ACPI_DSTATUS_ALL_OFF = 0, |
| 45 | ACPI_DSTATUS_HIDDEN_ON = ACPI_DSTATUS_PRESENT | ACPI_DSTATUS_ENABLED | |
| 46 | ACPI_DSTATUS_OK, |
| 47 | ACPI_DSTATUS_ALL_ON = ACPI_DSTATUS_HIDDEN_ON | |
| 48 | ACPI_DSTATUS_SHOW_IN_UI, |
| 49 | }; |
| 50 | |
Simon Glass | b24cbf4 | 2020-07-07 13:11:41 -0600 | [diff] [blame] | 51 | /** enum acpi_irq_mode - edge/level trigger mode */ |
| 52 | enum acpi_irq_mode { |
| 53 | ACPI_IRQ_EDGE_TRIGGERED, |
| 54 | ACPI_IRQ_LEVEL_TRIGGERED, |
| 55 | }; |
| 56 | |
| 57 | /** |
| 58 | * enum acpi_irq_polarity - polarity of interrupt |
| 59 | * |
| 60 | * @ACPI_IRQ_ACTIVE_LOW - for ACPI_IRQ_EDGE_TRIGGERED this means falling edge |
| 61 | * @ACPI_IRQ_ACTIVE_HIGH - for ACPI_IRQ_EDGE_TRIGGERED this means rising edge |
| 62 | * @ACPI_IRQ_ACTIVE_BOTH - not meaningful for ACPI_IRQ_EDGE_TRIGGERED |
| 63 | */ |
| 64 | enum acpi_irq_polarity { |
| 65 | ACPI_IRQ_ACTIVE_LOW, |
| 66 | ACPI_IRQ_ACTIVE_HIGH, |
| 67 | ACPI_IRQ_ACTIVE_BOTH, |
| 68 | }; |
| 69 | |
| 70 | /** |
| 71 | * enum acpi_irq_shared - whether interrupt is shared or not |
| 72 | * |
| 73 | * @ACPI_IRQ_EXCLUSIVE: only this device uses the interrupt |
| 74 | * @ACPI_IRQ_SHARED: other devices may use this interrupt |
| 75 | */ |
| 76 | enum acpi_irq_shared { |
| 77 | ACPI_IRQ_EXCLUSIVE, |
| 78 | ACPI_IRQ_SHARED, |
| 79 | }; |
| 80 | |
| 81 | /** enum acpi_irq_wake - indicates whether this interrupt can wake the device */ |
| 82 | enum acpi_irq_wake { |
| 83 | ACPI_IRQ_NO_WAKE, |
| 84 | ACPI_IRQ_WAKE, |
| 85 | }; |
| 86 | |
| 87 | /** |
| 88 | * struct acpi_irq - representation of an ACPI interrupt |
| 89 | * |
| 90 | * @pin: ACPI pin that is monitored for the interrupt |
| 91 | * @mode: Edge/level triggering |
| 92 | * @polarity: Interrupt polarity |
| 93 | * @shared: Whether interrupt is shared or not |
| 94 | * @wake: Whether interrupt can wake the device from sleep |
| 95 | */ |
| 96 | struct acpi_irq { |
| 97 | unsigned int pin; |
| 98 | enum acpi_irq_mode mode; |
| 99 | enum acpi_irq_polarity polarity; |
| 100 | enum acpi_irq_shared shared; |
| 101 | enum acpi_irq_wake wake; |
| 102 | }; |
| 103 | |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 104 | /** |
Simon Glass | 3176b6c | 2020-07-07 13:11:44 -0600 | [diff] [blame] | 105 | * enum acpi_gpio_type - type of the descriptor |
| 106 | * |
| 107 | * @ACPI_GPIO_TYPE_INTERRUPT: GpioInterrupt |
| 108 | * @ACPI_GPIO_TYPE_IO: GpioIo |
| 109 | */ |
| 110 | enum acpi_gpio_type { |
| 111 | ACPI_GPIO_TYPE_INTERRUPT, |
| 112 | ACPI_GPIO_TYPE_IO, |
| 113 | }; |
| 114 | |
| 115 | /** |
| 116 | * enum acpi_gpio_pull - pull direction |
| 117 | * |
| 118 | * @ACPI_GPIO_PULL_DEFAULT: Use default value for pin |
| 119 | * @ACPI_GPIO_PULL_UP: Pull up |
| 120 | * @ACPI_GPIO_PULL_DOWN: Pull down |
| 121 | * @ACPI_GPIO_PULL_NONE: No pullup/pulldown |
| 122 | */ |
| 123 | enum acpi_gpio_pull { |
| 124 | ACPI_GPIO_PULL_DEFAULT, |
| 125 | ACPI_GPIO_PULL_UP, |
| 126 | ACPI_GPIO_PULL_DOWN, |
| 127 | ACPI_GPIO_PULL_NONE, |
| 128 | }; |
| 129 | |
| 130 | /** |
| 131 | * enum acpi_gpio_io_restrict - controls input/output of pin |
| 132 | * |
| 133 | * @ACPI_GPIO_IO_RESTRICT_NONE: no restrictions |
| 134 | * @ACPI_GPIO_IO_RESTRICT_INPUT: input only (no output) |
| 135 | * @ACPI_GPIO_IO_RESTRICT_OUTPUT: output only (no input) |
| 136 | * @ACPI_GPIO_IO_RESTRICT_PRESERVE: preserve settings when driver not active |
| 137 | */ |
| 138 | enum acpi_gpio_io_restrict { |
| 139 | ACPI_GPIO_IO_RESTRICT_NONE, |
| 140 | ACPI_GPIO_IO_RESTRICT_INPUT, |
| 141 | ACPI_GPIO_IO_RESTRICT_OUTPUT, |
| 142 | ACPI_GPIO_IO_RESTRICT_PRESERVE, |
| 143 | }; |
| 144 | |
| 145 | /** enum acpi_gpio_polarity - controls the GPIO polarity */ |
| 146 | enum acpi_gpio_polarity { |
| 147 | ACPI_GPIO_ACTIVE_HIGH = 0, |
| 148 | ACPI_GPIO_ACTIVE_LOW = 1, |
| 149 | }; |
| 150 | |
| 151 | #define ACPI_GPIO_REVISION_ID 1 |
| 152 | #define ACPI_GPIO_MAX_PINS 2 |
| 153 | |
| 154 | /** |
| 155 | * struct acpi_gpio - representation of an ACPI GPIO |
| 156 | * |
| 157 | * @pin_count: Number of pins represented |
| 158 | * @pins: List of pins |
| 159 | * @pin0_addr: Address in memory of the control registers for pin 0. This is |
| 160 | * used when generating ACPI tables |
| 161 | * @type: GPIO type |
| 162 | * @pull: Pullup/pulldown setting |
| 163 | * @resource: Resource name for this GPIO controller |
| 164 | * For GpioInt: |
| 165 | * @interrupt_debounce_timeout: Debounce timeout in units of 10us |
| 166 | * @irq: Interrupt |
| 167 | * |
| 168 | * For GpioIo: |
| 169 | * @output_drive_strength: Drive strength in units of 10uA |
| 170 | * @io_shared; true if GPIO is shared |
| 171 | * @io_restrict: I/O restriction setting |
| 172 | * @polarity: GPIO polarity |
Simon Glass | d010cc1 | 2020-09-22 12:45:43 -0600 | [diff] [blame] | 173 | * |
| 174 | * Note that GpioIo doesn't have any means of Active Low / High setting, so a |
| 175 | * _DSD must be provided to mitigate this. |
| 176 | * |
| 177 | * GpioIo doesn't properly communicate the initial state of the output pin, |
| 178 | * thus Linux assumes the simple rule: |
| 179 | * |
| 180 | * Pull Bias Polarity Requested... |
| 181 | * |
| 182 | * Implicit x AS IS (assumed firmware configured for us) |
| 183 | * Explicit x (no _DSD) as Pull Bias (Up == High, Down == Low), |
| 184 | * assuming non-active (Polarity = !Pull Bias) |
| 185 | * |
| 186 | * Down Low as low, assuming active |
| 187 | * Down High as high, assuming non-active |
| 188 | * Up Low as high, assuming non-active |
| 189 | * Up High as high, assuming active |
| 190 | * |
| 191 | * GpioIo() can be used as interrupt and in this case the IoRestriction mustn't |
| 192 | * be OutputOnly. It also requires active_low flag from _DSD in cases where it's |
| 193 | * needed (better to always provide than rely on above assumption made on OS |
| 194 | * level). |
Simon Glass | 3176b6c | 2020-07-07 13:11:44 -0600 | [diff] [blame] | 195 | */ |
| 196 | struct acpi_gpio { |
| 197 | int pin_count; |
| 198 | u16 pins[ACPI_GPIO_MAX_PINS]; |
| 199 | ulong pin0_addr; |
| 200 | |
| 201 | enum acpi_gpio_type type; |
| 202 | enum acpi_gpio_pull pull; |
| 203 | char resource[ACPI_PATH_MAX]; |
| 204 | |
| 205 | /* GpioInt */ |
| 206 | u16 interrupt_debounce_timeout; |
| 207 | struct acpi_irq irq; |
| 208 | |
| 209 | /* GpioIo */ |
| 210 | u16 output_drive_strength; |
| 211 | bool io_shared; |
| 212 | enum acpi_gpio_io_restrict io_restrict; |
| 213 | enum acpi_gpio_polarity polarity; |
| 214 | }; |
| 215 | |
Simon Glass | 39ab867 | 2020-07-07 13:11:48 -0600 | [diff] [blame] | 216 | /* ACPI Descriptors for Serial Bus interfaces */ |
| 217 | #define ACPI_SERIAL_BUS_TYPE_I2C 1 |
Simon Glass | 711fd98 | 2020-07-07 13:11:49 -0600 | [diff] [blame] | 218 | #define ACPI_SERIAL_BUS_TYPE_SPI 2 |
Simon Glass | 39ab867 | 2020-07-07 13:11:48 -0600 | [diff] [blame] | 219 | #define ACPI_I2C_SERIAL_BUS_REVISION_ID 1 /* TODO: upgrade to 2 */ |
| 220 | #define ACPI_I2C_TYPE_SPECIFIC_REVISION_ID 1 |
Simon Glass | 711fd98 | 2020-07-07 13:11:49 -0600 | [diff] [blame] | 221 | #define ACPI_SPI_SERIAL_BUS_REVISION_ID 1 |
| 222 | #define ACPI_SPI_TYPE_SPECIFIC_REVISION_ID 1 |
Simon Glass | 39ab867 | 2020-07-07 13:11:48 -0600 | [diff] [blame] | 223 | |
| 224 | /** |
| 225 | * struct acpi_i2c - representation of an ACPI I2C device |
| 226 | * |
| 227 | * @address: 7-bit or 10-bit I2C address |
| 228 | * @mode_10bit: Which address size is used |
| 229 | * @speed: Bus speed in Hz |
| 230 | * @resource: Resource name for the I2C controller |
| 231 | */ |
| 232 | struct acpi_i2c { |
| 233 | u16 address; |
| 234 | enum i2c_address_mode mode_10bit; |
| 235 | enum i2c_speed_rate speed; |
| 236 | const char *resource; |
| 237 | }; |
| 238 | |
Simon Glass | 3176b6c | 2020-07-07 13:11:44 -0600 | [diff] [blame] | 239 | /** |
Simon Glass | 711fd98 | 2020-07-07 13:11:49 -0600 | [diff] [blame] | 240 | * struct acpi_spi - representation of an ACPI SPI device |
| 241 | * |
| 242 | * @device_select: Chip select used by this device (typically 0) |
| 243 | * @device_select_polarity: Polarity for the device |
| 244 | * @wire_mode: Number of wires used for SPI |
| 245 | * @speed: Bus speed in Hz |
| 246 | * @data_bit_length: Word length for SPI (typically 8) |
| 247 | * @clock_phase: Clock phase to capture data |
| 248 | * @clock_polarity: Bus polarity |
| 249 | * @resource: Resource name for the SPI controller |
| 250 | */ |
| 251 | struct acpi_spi { |
| 252 | u16 device_select; |
| 253 | enum spi_polarity device_select_polarity; |
| 254 | enum spi_wire_mode wire_mode; |
| 255 | unsigned int speed; |
| 256 | u8 data_bit_length; |
| 257 | enum spi_clock_phase clock_phase; |
| 258 | enum spi_polarity clock_polarity; |
| 259 | const char *resource; |
| 260 | }; |
| 261 | |
| 262 | /** |
Simon Glass | 31cc5b4 | 2020-09-22 12:45:01 -0600 | [diff] [blame] | 263 | * struct acpi_i2c_priv - Information read from device tree |
| 264 | * |
| 265 | * This is used by devices which want to specify various pieces of ACPI |
| 266 | * information, including power control. It allows a generic function to |
| 267 | * generate the information for ACPI, based on device-tree properties. |
| 268 | * |
| 269 | * @disable_gpio_export_in_crs: Don't export GPIOs in the CRS |
| 270 | * @reset_gpio: GPIO used to assert reset to the device |
| 271 | * @enable_gpio: GPIO used to enable the device |
| 272 | * @stop_gpio: GPIO used to stop the device |
| 273 | * @irq_gpio: GPIO used for interrupt (if @irq is not used) |
| 274 | * @irq: IRQ used for interrupt (if @irq_gpio is not used) |
| 275 | * @hid: _HID value for device (required) |
| 276 | * @uid: _UID value for device |
| 277 | * @desc: _DDN value for device |
| 278 | * @wake: Wake event, e.g. GPE0_DW1_15; 0 if none |
| 279 | * @property_count: Number of other DSD properties (currently always 0) |
| 280 | * @probed: true set set 'linux,probed' property |
| 281 | * @compat_string: Device tree compatible string to report through ACPI |
| 282 | * @has_power_resource: true if this device has a power resource |
| 283 | * @reset_delay_ms: Delay after de-asserting reset, in ms |
| 284 | * @reset_off_delay_ms: Delay after asserting reset (during power off) |
| 285 | * @enable_delay_ms: Delay after asserting enable |
| 286 | * @enable_off_delay_ms: Delay after de-asserting enable (during power off) |
| 287 | * @stop_delay_ms: Delay after de-aserting stop |
| 288 | * @stop_off_delay_ms: Delay after asserting stop (during power off) |
| 289 | * @hid_desc_reg_offset: HID register offset (for Human Interface Devices) |
| 290 | */ |
| 291 | struct acpi_i2c_priv { |
| 292 | bool disable_gpio_export_in_crs; |
| 293 | struct gpio_desc reset_gpio; |
| 294 | struct gpio_desc enable_gpio; |
| 295 | struct gpio_desc irq_gpio; |
| 296 | struct gpio_desc stop_gpio; |
| 297 | struct irq irq; |
| 298 | const char *hid; |
| 299 | u32 uid; |
| 300 | const char *desc; |
| 301 | u32 wake; |
| 302 | u32 property_count; |
| 303 | bool probed; |
| 304 | const char *compat_string; |
| 305 | bool has_power_resource; |
| 306 | u32 reset_delay_ms; |
| 307 | u32 reset_off_delay_ms; |
| 308 | u32 enable_delay_ms; |
| 309 | u32 enable_off_delay_ms; |
| 310 | u32 stop_delay_ms; |
| 311 | u32 stop_off_delay_ms; |
| 312 | u32 hid_desc_reg_offset; |
| 313 | }; |
| 314 | |
| 315 | /** |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 316 | * acpi_device_path() - Get the full path to an ACPI device |
| 317 | * |
| 318 | * This gets the full path in the form XXXX.YYYY.ZZZZ where XXXX is the root |
| 319 | * and ZZZZ is the device. All parent devices are added to the path. |
| 320 | * |
| 321 | * @dev: Device to check |
| 322 | * @buf: Buffer to place the path in (should be ACPI_PATH_MAX long) |
| 323 | * @maxlen: Size of buffer (typically ACPI_PATH_MAX) |
| 324 | * @return 0 if OK, -ve on error |
| 325 | */ |
| 326 | int acpi_device_path(const struct udevice *dev, char *buf, int maxlen); |
| 327 | |
| 328 | /** |
| 329 | * acpi_device_scope() - Get the scope of an ACPI device |
| 330 | * |
| 331 | * This gets the scope which is the full path of the parent device, as per |
| 332 | * acpi_device_path(). |
| 333 | * |
| 334 | * @dev: Device to check |
| 335 | * @buf: Buffer to place the path in (should be ACPI_PATH_MAX long) |
| 336 | * @maxlen: Size of buffer (typically ACPI_PATH_MAX) |
| 337 | * @return 0 if OK, -EINVAL if the device has no parent, other -ve on other |
| 338 | * error |
| 339 | */ |
| 340 | int acpi_device_scope(const struct udevice *dev, char *scope, int maxlen); |
| 341 | |
Simon Glass | 8965cc9 | 2020-07-07 13:11:40 -0600 | [diff] [blame] | 342 | /** |
| 343 | * acpi_device_status() - Get the status of a device |
| 344 | * |
| 345 | * This currently just returns ACPI_DSTATUS_ALL_ON. It does not support |
| 346 | * inactive or hidden devices. |
| 347 | * |
| 348 | * @dev: Device to check |
| 349 | * @return device status, as ACPI_DSTATUS_... |
| 350 | */ |
| 351 | enum acpi_dev_status acpi_device_status(const struct udevice *dev); |
| 352 | |
Simon Glass | 3d39c13 | 2020-07-07 13:11:43 -0600 | [diff] [blame] | 353 | /** |
| 354 | * acpi_device_write_interrupt_irq() - Write an interrupt descriptor |
| 355 | * |
| 356 | * This writes an ACPI interrupt descriptor for the given interrupt, converting |
| 357 | * fields as needed. |
| 358 | * |
| 359 | * @ctx: ACPI context pointer |
| 360 | * @req_irq: Interrupt to output |
| 361 | * @return IRQ pin number if OK, -ve on error |
| 362 | */ |
| 363 | int acpi_device_write_interrupt_irq(struct acpi_ctx *ctx, |
| 364 | const struct irq *req_irq); |
| 365 | |
Simon Glass | 4fa6331 | 2020-07-07 13:11:46 -0600 | [diff] [blame] | 366 | /** |
| 367 | * acpi_device_write_gpio() - Write GpioIo() or GpioInt() descriptor |
| 368 | * |
| 369 | * @gpio: GPIO information to write |
| 370 | * @return GPIO pin number of first GPIO if OK, -ve on error |
| 371 | */ |
| 372 | int acpi_device_write_gpio(struct acpi_ctx *ctx, const struct acpi_gpio *gpio); |
| 373 | |
| 374 | /** |
| 375 | * acpi_device_write_gpio_desc() - Write a GPIO to ACPI |
| 376 | * |
| 377 | * This creates a GPIO descriptor for a GPIO, including information ACPI needs |
| 378 | * to use it. |
| 379 | * |
| 380 | * @ctx: ACPI context pointer |
| 381 | * @desc: GPIO to write |
| 382 | * @return 0 if OK, -ve on error |
| 383 | */ |
| 384 | int acpi_device_write_gpio_desc(struct acpi_ctx *ctx, |
| 385 | const struct gpio_desc *desc); |
| 386 | |
Simon Glass | e2bbb13 | 2020-07-07 13:11:47 -0600 | [diff] [blame] | 387 | /** |
| 388 | * acpi_device_write_interrupt_or_gpio() - Write interrupt or GPIO to ACPI |
| 389 | * |
| 390 | * This reads an interrupt from the device tree "interrupts-extended" property, |
| 391 | * if available. If not it reads the first GPIO with the name @prop. |
| 392 | * |
| 393 | * If an interrupt is found, an ACPI interrupt descriptor is written to the ACPI |
| 394 | * output. If not, but if a GPIO is found, a GPIO descriptor is written. |
| 395 | * |
| 396 | * @return irq or GPIO pin number if OK, -ve if neither an interrupt nor a GPIO |
| 397 | * could be found, or some other error occurred |
| 398 | */ |
| 399 | int acpi_device_write_interrupt_or_gpio(struct acpi_ctx *ctx, |
| 400 | struct udevice *dev, const char *prop); |
| 401 | |
Simon Glass | 39ab867 | 2020-07-07 13:11:48 -0600 | [diff] [blame] | 402 | /** |
Simon Glass | 4c8cbbd | 2020-09-22 12:44:58 -0600 | [diff] [blame] | 403 | * acpi_device_write_dsm_i2c_hid() - Write a device-specific method for HID |
| 404 | * |
| 405 | * This writes a DSM for an I2C Human-Interface Device based on the config |
| 406 | * provided |
| 407 | * |
| 408 | * @hid_desc_reg_offset: HID register offset |
| 409 | */ |
| 410 | int acpi_device_write_dsm_i2c_hid(struct acpi_ctx *ctx, |
| 411 | int hid_desc_reg_offset); |
| 412 | |
| 413 | /** |
Simon Glass | 39ab867 | 2020-07-07 13:11:48 -0600 | [diff] [blame] | 414 | * acpi_device_write_i2c_dev() - Write an I2C device to ACPI |
| 415 | * |
Simon Glass | 6e4116a | 2020-09-22 12:45:44 -0600 | [diff] [blame] | 416 | * This creates a I2cSerialBusV2 descriptor for an I2C device, including |
Simon Glass | 39ab867 | 2020-07-07 13:11:48 -0600 | [diff] [blame] | 417 | * information ACPI needs to use it. |
| 418 | * |
| 419 | * @ctx: ACPI context pointer |
| 420 | * @dev: I2C device to write |
| 421 | * @return I2C address of device if OK, -ve on error |
| 422 | */ |
| 423 | int acpi_device_write_i2c_dev(struct acpi_ctx *ctx, const struct udevice *dev); |
| 424 | |
Simon Glass | 711fd98 | 2020-07-07 13:11:49 -0600 | [diff] [blame] | 425 | /** |
| 426 | * acpi_device_write_spi_dev() - Write a SPI device to ACPI |
| 427 | * |
| 428 | * This writes a serial bus descriptor for the SPI device so that ACPI can use |
| 429 | * it |
| 430 | * |
| 431 | * @ctx: ACPI context pointer |
| 432 | * @dev: SPI device to write |
| 433 | * @return 0 if OK, -ve on error |
| 434 | */ |
| 435 | int acpi_device_write_spi_dev(struct acpi_ctx *ctx, const struct udevice *dev); |
| 436 | |
Simon Glass | cec3af0 | 2020-07-07 13:12:02 -0600 | [diff] [blame] | 437 | /** |
| 438 | * acpi_device_add_power_res() - Add a basic PowerResource block for a device |
| 439 | * |
| 440 | * This includes GPIOs to control enable, reset and stop operation of the |
| 441 | * device. Each GPIO is optional, but at least one must be provided. |
| 442 | * This can be applied to any device that has power control, so is fairly |
| 443 | * generic. |
| 444 | * |
| 445 | * Reset - Put the device into / take the device out of reset. |
| 446 | * Enable - Enable / disable power to device. |
| 447 | * Stop - Stop / start operation of device. |
| 448 | * |
| 449 | * @ctx: ACPI context pointer |
| 450 | * @tx_state_val: Mask to use to toggle the TX state on the GPIO pin, e,g. |
| 451 | * PAD_CFG0_TX_STATE |
| 452 | * @dw0_read: Name to use to read dw0, e.g. "\\_SB.GPC0" |
| 453 | * @dw0_write: Name to use to read dw0, e.g. "\\_SB.SPC0" |
| 454 | * @reset_gpio: GPIO used to take device out of reset or to put it into reset |
| 455 | * @reset_delay_ms: Delay to be inserted after device is taken out of reset |
| 456 | * (_ON method delay) |
| 457 | * @reset_off_delay_ms: Delay to be inserted after device is put into reset |
| 458 | * (_OFF method delay) |
| 459 | * @enable_gpio: GPIO used to enable device |
| 460 | * @enable_delay_ms: Delay to be inserted after device is enabled |
| 461 | * @enable_off_delay_ms: Delay to be inserted after device is disabled |
| 462 | * (_OFF method delay) |
| 463 | * @stop_gpio: GPIO used to stop operation of device |
| 464 | * @stop_delay_ms: Delay to be inserted after disabling stop (_ON method delay) |
| 465 | * @stop_off_delay_ms: Delay to be inserted after enabling stop. |
| 466 | * (_OFF method delay) |
| 467 | * |
| 468 | * @return 0 if OK, -ve if at least one GPIO is not provided |
| 469 | */ |
| 470 | int acpi_device_add_power_res(struct acpi_ctx *ctx, u32 tx_state_val, |
| 471 | const char *dw0_read, const char *dw0_write, |
| 472 | const struct gpio_desc *reset_gpio, |
| 473 | uint reset_delay_ms, uint reset_off_delay_ms, |
| 474 | const struct gpio_desc *enable_gpio, |
| 475 | uint enable_delay_ms, uint enable_off_delay_ms, |
| 476 | const struct gpio_desc *stop_gpio, |
| 477 | uint stop_delay_ms, uint stop_off_delay_ms); |
| 478 | |
Simon Glass | 0964239 | 2020-07-07 13:12:11 -0600 | [diff] [blame] | 479 | /** |
| 480 | * acpi_device_infer_name() - Infer the name from its uclass or parent |
| 481 | * |
| 482 | * Many ACPI devices have a standard name that can be inferred from the uclass |
| 483 | * they are in, or the uclass of their parent. These rules are implemented in |
| 484 | * this function. It attempts to produce a name for a device based on these |
| 485 | * rules. |
| 486 | * |
| 487 | * NOTE: This currently supports only x86 devices. Feel free to enhance it for |
| 488 | * other architectures as needed. |
| 489 | * |
| 490 | * @dev: Device to check |
| 491 | * @out_name: Place to put the name (must hold ACPI_NAME_MAX bytes) |
| 492 | * @return 0 if a name was found, -ENOENT if not found, -ENXIO if the device |
| 493 | * sequence number could not be determined |
| 494 | */ |
| 495 | int acpi_device_infer_name(const struct udevice *dev, char *out_name); |
| 496 | |
Simon Glass | ebb2e83 | 2020-07-07 13:11:39 -0600 | [diff] [blame] | 497 | #endif |