1 /* $OpenBSD: dwhdmi.h,v 1.4 2020/06/30 02:19:12 deraadt Exp $ */ 2 /* $NetBSD: dw_hdmi.h,v 1.6 2019/12/22 23:23:32 thorpej Exp $ */ 3 4 /*- 5 * Copyright (c) 2019 Jared D. McNeill <jmcneill@invisible.ca> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 22 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #ifndef _DEV_IC_DWHDMI_H 31 #define _DEV_IC_DWHDMI_H 32 33 #include <dev/i2c/i2cvar.h> 34 35 #ifdef notyet 36 #include <dev/audio/audio_dai.h> 37 #endif 38 39 #include <drm/drm_connector.h> 40 #include <drm/drm_bridge.h> 41 42 struct dwhdmi_softc; 43 44 struct dwhdmi_connector { 45 struct drm_connector base; 46 struct dwhdmi_softc *sc; 47 48 int hdmi_monitor; 49 int monitor_audio; 50 }; 51 52 struct dwhdmi_phy_config { 53 u_int pixel_clock; 54 uint32_t sym; 55 uint32_t term; 56 uint32_t vlev; 57 }; 58 59 struct dwhdmi_mpll_config { 60 u_int pixel_clock; 61 uint32_t cpce; 62 uint32_t gmp; 63 uint32_t curr; 64 }; 65 66 struct dwhdmi_softc { 67 struct device sc_dev; 68 bus_space_tag_t sc_bst; 69 bus_space_handle_t sc_bsh; 70 u_int sc_reg_width; 71 u_int sc_flags; 72 #define DWHDMI_USE_INTERNAL_PHY (1 << 0) 73 u_int sc_scl_hcnt; 74 u_int sc_scl_lcnt; 75 76 u_int sc_phytype; 77 u_int sc_version; 78 79 i2c_tag_t sc_ic; 80 struct i2c_controller sc_ic_builtin; 81 82 #ifdef notyet 83 struct audio_dai_device sc_dai; 84 uint8_t sc_swvol; 85 #endif 86 87 struct dwhdmi_connector sc_connector; 88 struct drm_bridge sc_bridge; 89 90 struct drm_display_mode sc_curmode; 91 92 const struct dwhdmi_mpll_config *sc_mpll_config; 93 const struct dwhdmi_phy_config *sc_phy_config; 94 95 enum drm_connector_status (*sc_detect)(struct dwhdmi_softc *, int); 96 void (*sc_enable)(struct dwhdmi_softc *); 97 void (*sc_disable)(struct dwhdmi_softc *); 98 void (*sc_mode_set)(struct dwhdmi_softc *, 99 const struct drm_display_mode *, 100 const struct drm_display_mode *); 101 enum drm_mode_status (*sc_mode_valid)(struct dwhdmi_softc *, 102 const struct drm_display_mode *); 103 }; 104 105 #define to_dwhdmi_connector(x) container_of(x, struct dwhdmi_connector, base) 106 107 int dwhdmi_attach(struct dwhdmi_softc *); 108 int dwhdmi_bind(struct dwhdmi_softc *, struct drm_encoder *); 109 110 uint8_t dwhdmi_read(struct dwhdmi_softc *, bus_size_t); 111 void dwhdmi_write(struct dwhdmi_softc *, bus_size_t, uint8_t); 112 113 enum drm_connector_status dwhdmi_phy_detect(struct dwhdmi_softc *, int); 114 void dwhdmi_phy_enable(struct dwhdmi_softc *); 115 void dwhdmi_phy_disable(struct dwhdmi_softc *); 116 void dwhdmi_phy_mode_set(struct dwhdmi_softc *, 117 const struct drm_display_mode *, 118 const struct drm_display_mode *); 119 120 #endif /* !_DEV_IC_DWHDMI_H */ 121