171d51719SMichael Gmelin /* 271d51719SMichael Gmelin * Copyright (c) 2014 The DragonFly Project. All rights reserved. 371d51719SMichael Gmelin * 471d51719SMichael Gmelin * This code is derived from software contributed to The DragonFly Project 571d51719SMichael Gmelin * by Matthew Dillon <dillon@backplane.com> and was subsequently ported 671d51719SMichael Gmelin * to FreeBSD by Michael Gmelin <freebsd@grem.de> 771d51719SMichael Gmelin * 871d51719SMichael Gmelin * Redistribution and use in source and binary forms, with or without 971d51719SMichael Gmelin * modification, are permitted provided that the following conditions 1071d51719SMichael Gmelin * are met: 1171d51719SMichael Gmelin * 1271d51719SMichael Gmelin * 1. Redistributions of source code must retain the above copyright 1371d51719SMichael Gmelin * notice, this list of conditions and the following disclaimer. 1471d51719SMichael Gmelin * 2. Redistributions in binary form must reproduce the above copyright 1571d51719SMichael Gmelin * notice, this list of conditions and the following disclaimer in 1671d51719SMichael Gmelin * the documentation and/or other materials provided with the 1771d51719SMichael Gmelin * distribution. 1871d51719SMichael Gmelin * 3. Neither the name of The DragonFly Project nor the names of its 1971d51719SMichael Gmelin * contributors may be used to endorse or promote products derived 2071d51719SMichael Gmelin * from this software without specific, prior written permission. 2171d51719SMichael Gmelin * 2271d51719SMichael Gmelin * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2371d51719SMichael Gmelin * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2471d51719SMichael Gmelin * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 2571d51719SMichael Gmelin * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 2671d51719SMichael Gmelin * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 2771d51719SMichael Gmelin * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 2871d51719SMichael Gmelin * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 2971d51719SMichael Gmelin * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 3071d51719SMichael Gmelin * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 3171d51719SMichael Gmelin * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 3271d51719SMichael Gmelin * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3371d51719SMichael Gmelin * SUCH DAMAGE. 3471d51719SMichael Gmelin */ 3571d51719SMichael Gmelin 36e3d25549SAndriy Gapon #ifndef _ICHIIC_IG4_VAR_H_ 37e3d25549SAndriy Gapon #define _ICHIIC_IG4_VAR_H_ 3871d51719SMichael Gmelin 3971d51719SMichael Gmelin #include "bus_if.h" 4071d51719SMichael Gmelin #include "device_if.h" 4171d51719SMichael Gmelin #include "pci_if.h" 42448897d3SAndriy Gapon #include "iicbus_if.h" 4371d51719SMichael Gmelin 446c6fd2b4SVladimir Kondratyev enum ig4_vers { 45*5972ffdeSAndrew Gallatin IG4_EMAG, 466c6fd2b4SVladimir Kondratyev IG4_HASWELL, 476c6fd2b4SVladimir Kondratyev IG4_ATOM, 486c6fd2b4SVladimir Kondratyev IG4_SKYLAKE, 496c6fd2b4SVladimir Kondratyev IG4_APL, 506c6fd2b4SVladimir Kondratyev IG4_CANNONLAKE, 51bbacb7ceSVladimir Kondratyev IG4_TIGERLAKE, 52bbacb7ceSVladimir Kondratyev IG4_GEMINILAKE 536c6fd2b4SVladimir Kondratyev }; 546c6fd2b4SVladimir Kondratyev 5581e81838SVladimir Kondratyev /* Controller has additional registers */ 566c6fd2b4SVladimir Kondratyev #define IG4_HAS_ADDREGS(vers) ((vers) >= IG4_SKYLAKE) 5771d51719SMichael Gmelin 5888512838SVladimir Kondratyev struct ig4_hw { 5988512838SVladimir Kondratyev uint32_t ic_clock_rate; /* MHz */ 6088512838SVladimir Kondratyev uint32_t sda_fall_time; /* nsec */ 6188512838SVladimir Kondratyev uint32_t scl_fall_time; /* nsec */ 6288512838SVladimir Kondratyev uint32_t sda_hold_time; /* nsec */ 6383a66b9bSVladimir Kondratyev int txfifo_depth; 6483a66b9bSVladimir Kondratyev int rxfifo_depth; 6588512838SVladimir Kondratyev }; 6688512838SVladimir Kondratyev 6788512838SVladimir Kondratyev struct ig4_cfg { 6888512838SVladimir Kondratyev uint32_t version; 6988512838SVladimir Kondratyev uint32_t bus_speed; 7088512838SVladimir Kondratyev uint16_t ss_scl_hcnt; 7188512838SVladimir Kondratyev uint16_t ss_scl_lcnt; 7288512838SVladimir Kondratyev uint16_t ss_sda_hold; 7388512838SVladimir Kondratyev uint16_t fs_scl_hcnt; 7488512838SVladimir Kondratyev uint16_t fs_scl_lcnt; 7588512838SVladimir Kondratyev uint16_t fs_sda_hold; 7683a66b9bSVladimir Kondratyev int txfifo_depth; 7783a66b9bSVladimir Kondratyev int rxfifo_depth; 7888512838SVladimir Kondratyev }; 7988512838SVladimir Kondratyev 8071d51719SMichael Gmelin struct ig4iic_softc { 8171d51719SMichael Gmelin device_t dev; 82448897d3SAndriy Gapon device_t iicbus; 8371d51719SMichael Gmelin struct resource *regs_res; 8471d51719SMichael Gmelin int regs_rid; 8571d51719SMichael Gmelin struct resource *intr_res; 8671d51719SMichael Gmelin int intr_rid; 8771d51719SMichael Gmelin void *intr_handle; 8871d51719SMichael Gmelin int intr_type; 89b3e8ee5dSOleksandr Tymoshenko enum ig4_vers version; 9088512838SVladimir Kondratyev struct ig4_cfg cfg; 9121e459c6SVladimir Kondratyev uint32_t intr_mask; 9271d51719SMichael Gmelin uint8_t last_slave; 9387f55ab0SDimitry Andric bool platform_attached : 1; 9487f55ab0SDimitry Andric bool use_10bit : 1; 9587f55ab0SDimitry Andric bool slave_valid : 1; 964cd6abddSMichael Gmelin 974cd6abddSMichael Gmelin /* 984cd6abddSMichael Gmelin * Locking semantics: 994cd6abddSMichael Gmelin * 100e3d25549SAndriy Gapon * Functions implementing the icbus interface that interact 1014cd6abddSMichael Gmelin * with the controller acquire an exclusive lock on call_lock 102733d657aSVladimir Kondratyev * to prevent interleaving of calls to the interface. 103733d657aSVladimir Kondratyev * 104733d657aSVladimir Kondratyev * io_lock is used as condition variable to synchronize active process 105733d657aSVladimir Kondratyev * with the interrupt handler. It should not be used for tasks other 106733d657aSVladimir Kondratyev * than waiting for interrupt and passing parameters to and from 107733d657aSVladimir Kondratyev * it's handler. 1084cd6abddSMichael Gmelin */ 1094cd6abddSMichael Gmelin struct sx call_lock; 1104cd6abddSMichael Gmelin struct mtx io_lock; 11171d51719SMichael Gmelin }; 11271d51719SMichael Gmelin 11371d51719SMichael Gmelin typedef struct ig4iic_softc ig4iic_softc_t; 11471d51719SMichael Gmelin 11571d51719SMichael Gmelin /* Attach/Detach called from ig4iic_pci_*() */ 11671d51719SMichael Gmelin int ig4iic_attach(ig4iic_softc_t *sc); 11771d51719SMichael Gmelin int ig4iic_detach(ig4iic_softc_t *sc); 118db7caa2eSVladimir Kondratyev int ig4iic_suspend(ig4iic_softc_t *sc); 119db7caa2eSVladimir Kondratyev int ig4iic_resume(ig4iic_softc_t *sc); 12071d51719SMichael Gmelin 121e3d25549SAndriy Gapon /* iicbus methods */ 122448897d3SAndriy Gapon extern iicbus_transfer_t ig4iic_transfer; 123448897d3SAndriy Gapon extern iicbus_reset_t ig4iic_reset; 12441b24e09SVladimir Kondratyev extern iicbus_callback_t ig4iic_callback; 12571d51719SMichael Gmelin 126e3d25549SAndriy Gapon #endif /* _ICHIIC_IG4_VAR_H_ */ 127