1 /* $OpenBSD: dwiicvar.h,v 1.6 2023/08/29 12:09:40 kettenis Exp $ */ 2 /* 3 * Synopsys DesignWare I2C controller 4 * 5 * Copyright (c) 2015, 2016 joshua stein <jcs@openbsd.org> 6 * 7 * Permission to use, copy, modify, and/or distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #include <sys/param.h> 21 #include <sys/systm.h> 22 #include <sys/kernel.h> 23 24 #ifdef __HAVE_ACPI 25 #include "acpi.h" 26 #include <dev/acpi/acpireg.h> 27 #include <dev/acpi/acpivar.h> 28 #include <dev/acpi/acpidev.h> 29 #include <dev/acpi/amltypes.h> 30 #include <dev/acpi/dsdt.h> 31 #endif 32 33 #include <dev/pci/pcivar.h> 34 35 #include <dev/i2c/i2cvar.h> 36 37 #include <dev/ic/dwiicreg.h> 38 39 /* #define DWIIC_DEBUG */ 40 41 #ifdef DWIIC_DEBUG 42 #define DPRINTF(x) printf x 43 #else 44 #define DPRINTF(x) 45 #endif 46 47 struct dwiic_softc { 48 struct device sc_dev; 49 50 bus_space_tag_t sc_iot; 51 bus_space_handle_t sc_ioh; 52 53 struct acpi_softc *sc_acpi; 54 struct aml_node *sc_devnode; 55 char sc_hid[16]; 56 void *sc_ih; 57 58 struct pci_attach_args sc_paa; 59 60 struct i2cbus_attach_args sc_iba; 61 struct device *sc_iic; 62 63 u_int32_t sc_caps; 64 int sc_poll; 65 int sc_poll_ihidev; 66 int sc_busy; 67 int sc_readwait; 68 int sc_writewait; 69 70 uint32_t master_cfg; 71 uint16_t ss_hcnt, ss_lcnt, fs_hcnt, fs_lcnt; 72 uint32_t sda_hold_time; 73 int tx_fifo_depth; 74 int rx_fifo_depth; 75 76 struct i2c_controller sc_i2c_tag; 77 struct rwlock sc_i2c_lock; 78 struct { 79 i2c_op_t op; 80 void *buf; 81 size_t len; 82 int flags; 83 volatile int error; 84 } sc_i2c_xfer; 85 }; 86 87 int dwiic_activate(struct device *, int); 88 int dwiic_init(struct dwiic_softc *); 89 void dwiic_enable(struct dwiic_softc *, int); 90 int dwiic_intr(void *); 91 92 void * dwiic_i2c_intr_establish(void *, void *, int, 93 int (*)(void *), void *, const char *); 94 void dwiic_i2c_intr_disestablish(void *, void *); 95 const char * dwiic_i2c_intr_string(void *, void *); 96 int dwiic_i2c_print(void *, const char *); 97 98 int dwiic_i2c_acquire_bus(void *, int); 99 void dwiic_i2c_release_bus(void *, int); 100 uint32_t dwiic_read(struct dwiic_softc *, int); 101 void dwiic_write(struct dwiic_softc *, int, uint32_t); 102 int dwiic_i2c_exec(void *, i2c_op_t, i2c_addr_t, const void *, 103 size_t, void *, size_t, int); 104 105 #if NACPI > 0 106 int dwiic_acpi_found_hid(struct aml_node *, void *); 107 void dwiic_acpi_get_params(struct dwiic_softc *, char *, uint16_t *, 108 uint16_t *, uint32_t *); 109 #endif 110