dw_hdmi.h revision 1.2 1 /* $NetBSD: dw_hdmi.h,v 1.2 2019/11/09 23:27:50 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 <drm/drmP.h>
36
37 struct dwhdmi_softc;
38
39 struct dwhdmi_connector {
40 struct drm_connector base;
41 struct dwhdmi_softc *sc;
42
43 bool hdmi_monitor;
44 bool monitor_audio;
45 };
46
47 struct dwhdmi_phy_config {
48 u_int pixel_clock;
49 uint32_t sym;
50 uint32_t term;
51 uint32_t vlev;
52 };
53
54 struct dwhdmi_mpll_config {
55 u_int pixel_clock;
56 uint32_t cpce;
57 uint32_t gmp;
58 uint32_t curr;
59 };
60
61 struct dwhdmi_softc {
62 device_t sc_dev;
63 bus_space_tag_t sc_bst;
64 bus_space_handle_t sc_bsh;
65 u_int sc_reg_width;
66 u_int sc_flags;
67 #define DWHDMI_USE_INTERNAL_PHY __BIT(0)
68
69 u_int sc_phytype;
70 u_int sc_version;
71
72 i2c_tag_t sc_ic;
73 kmutex_t sc_ic_lock;
74 struct i2c_controller sc_ic_builtin;
75
76 struct dwhdmi_connector sc_connector;
77 struct drm_bridge sc_bridge;
78
79 struct drm_display_mode sc_curmode;
80
81 const struct dwhdmi_mpll_config *sc_mpll_config;
82 const struct dwhdmi_phy_config *sc_phy_config;
83
84 enum drm_connector_status (*sc_detect)(struct dwhdmi_softc *, bool);
85 void (*sc_enable)(struct dwhdmi_softc *);
86 void (*sc_disable)(struct dwhdmi_softc *);
87 void (*sc_mode_set)(struct dwhdmi_softc *,
88 struct drm_display_mode *,
89 struct drm_display_mode *);
90 };
91
92 #define to_dwhdmi_connector(x) container_of(x, struct dwhdmi_connector, base)
93
94 int dwhdmi_attach(struct dwhdmi_softc *);
95 int dwhdmi_bind(struct dwhdmi_softc *, struct drm_encoder *);
96
97 uint8_t dwhdmi_read(struct dwhdmi_softc *, bus_size_t);
98 void dwhdmi_write(struct dwhdmi_softc *, bus_size_t, uint8_t);
99
100 enum drm_connector_status dwhdmi_phy_detect(struct dwhdmi_softc *, bool);
101 void dwhdmi_phy_enable(struct dwhdmi_softc *);
102 void dwhdmi_phy_disable(struct dwhdmi_softc *);
103 void dwhdmi_phy_mode_set(struct dwhdmi_softc *,
104 struct drm_display_mode *,
105 struct drm_display_mode *);
106
107 #endif /* !_DEV_IC_DWHDMI_H */
108