xref: /netbsd-src/sys/dev/ic/dw_hdmi.h (revision dd47db3e83a68b8e7f55e1a33bd6e94970c2de7e)
1 /* $NetBSD: dw_hdmi.h,v 1.8 2021/12/19 11:01:11 riastradh Exp $ */
2 
3 /*-
4  * Copyright (c) 2019 Jared D. McNeill <jmcneill@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/drm_bridge.h>
38 #include <drm/drm_connector.h>
39 #include <drm/drm_drv.h>
40 #include <drm/drm_modes.h>
41 
42 struct dwhdmi_softc;
43 
44 struct dwhdmi_connector {
45 	struct drm_connector	base;
46 	struct dwhdmi_softc	*sc;
47 
48 	bool			hdmi_monitor;
49 	bool			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 	device_t		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	__BIT(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 	struct audio_dai_device	sc_dai;
83 	uint8_t			sc_swvol;
84 
85 	struct dwhdmi_connector	sc_connector;
86 	struct drm_bridge	sc_bridge;
87 
88 	struct drm_display_mode	sc_curmode;
89 
90 	const struct dwhdmi_mpll_config *sc_mpll_config;
91 	const struct dwhdmi_phy_config *sc_phy_config;
92 
93 	enum drm_connector_status (*sc_detect)(struct dwhdmi_softc *, bool);
94 	void			(*sc_enable)(struct dwhdmi_softc *);
95 	void			(*sc_disable)(struct dwhdmi_softc *);
96 	void			(*sc_mode_set)(struct dwhdmi_softc *,
97 					       const struct drm_display_mode *,
98 					       const struct drm_display_mode *);
99 };
100 
101 #define	to_dwhdmi_connector(x)	container_of(x, struct dwhdmi_connector, base)
102 
103 int		dwhdmi_attach(struct dwhdmi_softc *);
104 int		dwhdmi_bind(struct dwhdmi_softc *, struct drm_encoder *);
105 
106 uint8_t		dwhdmi_read(struct dwhdmi_softc *, bus_size_t);
107 void		dwhdmi_write(struct dwhdmi_softc *, bus_size_t, uint8_t);
108 
109 enum drm_connector_status dwhdmi_phy_detect(struct dwhdmi_softc *, bool);
110 void		dwhdmi_phy_enable(struct dwhdmi_softc *);
111 void		dwhdmi_phy_disable(struct dwhdmi_softc *);
112 void		dwhdmi_phy_mode_set(struct dwhdmi_softc *,
113 				    const struct drm_display_mode *,
114 				    const struct drm_display_mode *);
115 
116 #endif /* !_DEV_IC_DWHDMI_H */
117