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