xref: /openbsd-src/sys/dev/ic/dwhdmi.h (revision 7137d9bb155774a6d8722e4853eceeb2045bcd3d)
1*7137d9bbSderaadt /* $OpenBSD: dwhdmi.h,v 1.4 2020/06/30 02:19:12 deraadt Exp $ */
26a2cdf39Skettenis /* $NetBSD: dw_hdmi.h,v 1.6 2019/12/22 23:23:32 thorpej Exp $ */
36a2cdf39Skettenis 
46a2cdf39Skettenis /*-
56a2cdf39Skettenis  * Copyright (c) 2019 Jared D. McNeill <jmcneill@invisible.ca>
66a2cdf39Skettenis  * All rights reserved.
76a2cdf39Skettenis  *
86a2cdf39Skettenis  * Redistribution and use in source and binary forms, with or without
96a2cdf39Skettenis  * modification, are permitted provided that the following conditions
106a2cdf39Skettenis  * are met:
116a2cdf39Skettenis  * 1. Redistributions of source code must retain the above copyright
126a2cdf39Skettenis  *    notice, this list of conditions and the following disclaimer.
136a2cdf39Skettenis  * 2. Redistributions in binary form must reproduce the above copyright
146a2cdf39Skettenis  *    notice, this list of conditions and the following disclaimer in the
156a2cdf39Skettenis  *    documentation and/or other materials provided with the distribution.
166a2cdf39Skettenis  *
176a2cdf39Skettenis  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
186a2cdf39Skettenis  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
196a2cdf39Skettenis  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
206a2cdf39Skettenis  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
216a2cdf39Skettenis  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
226a2cdf39Skettenis  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
236a2cdf39Skettenis  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
246a2cdf39Skettenis  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
256a2cdf39Skettenis  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
266a2cdf39Skettenis  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
276a2cdf39Skettenis  * SUCH DAMAGE.
286a2cdf39Skettenis  */
296a2cdf39Skettenis 
306a2cdf39Skettenis #ifndef _DEV_IC_DWHDMI_H
316a2cdf39Skettenis #define _DEV_IC_DWHDMI_H
326a2cdf39Skettenis 
336a2cdf39Skettenis #include <dev/i2c/i2cvar.h>
346a2cdf39Skettenis 
356a2cdf39Skettenis #ifdef notyet
366a2cdf39Skettenis #include <dev/audio/audio_dai.h>
376a2cdf39Skettenis #endif
386a2cdf39Skettenis 
39c349dbc7Sjsg #include <drm/drm_connector.h>
40c349dbc7Sjsg #include <drm/drm_bridge.h>
416a2cdf39Skettenis 
426a2cdf39Skettenis struct dwhdmi_softc;
436a2cdf39Skettenis 
446a2cdf39Skettenis struct dwhdmi_connector {
456a2cdf39Skettenis 	struct drm_connector	base;
466a2cdf39Skettenis 	struct dwhdmi_softc	*sc;
476a2cdf39Skettenis 
486a2cdf39Skettenis 	int			hdmi_monitor;
496a2cdf39Skettenis 	int			monitor_audio;
506a2cdf39Skettenis };
516a2cdf39Skettenis 
526a2cdf39Skettenis struct dwhdmi_phy_config {
536a2cdf39Skettenis 	u_int			pixel_clock;
546a2cdf39Skettenis 	uint32_t		sym;
556a2cdf39Skettenis 	uint32_t		term;
566a2cdf39Skettenis 	uint32_t		vlev;
576a2cdf39Skettenis };
586a2cdf39Skettenis 
596a2cdf39Skettenis struct dwhdmi_mpll_config {
606a2cdf39Skettenis 	u_int			pixel_clock;
616a2cdf39Skettenis 	uint32_t		cpce;
626a2cdf39Skettenis 	uint32_t		gmp;
636a2cdf39Skettenis 	uint32_t		curr;
646a2cdf39Skettenis };
656a2cdf39Skettenis 
666a2cdf39Skettenis struct dwhdmi_softc {
676a2cdf39Skettenis 	struct device		sc_dev;
686a2cdf39Skettenis 	bus_space_tag_t		sc_bst;
696a2cdf39Skettenis 	bus_space_handle_t	sc_bsh;
706a2cdf39Skettenis 	u_int			sc_reg_width;
716a2cdf39Skettenis 	u_int			sc_flags;
726a2cdf39Skettenis #define	DWHDMI_USE_INTERNAL_PHY	(1 << 0)
736a2cdf39Skettenis 	u_int			sc_scl_hcnt;
746a2cdf39Skettenis 	u_int			sc_scl_lcnt;
756a2cdf39Skettenis 
766a2cdf39Skettenis 	u_int			sc_phytype;
776a2cdf39Skettenis 	u_int			sc_version;
786a2cdf39Skettenis 
796a2cdf39Skettenis 	i2c_tag_t		sc_ic;
806a2cdf39Skettenis 	struct i2c_controller	sc_ic_builtin;
816a2cdf39Skettenis 
826a2cdf39Skettenis #ifdef notyet
836a2cdf39Skettenis 	struct audio_dai_device	sc_dai;
846a2cdf39Skettenis 	uint8_t			sc_swvol;
856a2cdf39Skettenis #endif
866a2cdf39Skettenis 
876a2cdf39Skettenis 	struct dwhdmi_connector	sc_connector;
886a2cdf39Skettenis 	struct drm_bridge	sc_bridge;
896a2cdf39Skettenis 
906a2cdf39Skettenis 	struct drm_display_mode	sc_curmode;
916a2cdf39Skettenis 
926a2cdf39Skettenis 	const struct dwhdmi_mpll_config *sc_mpll_config;
936a2cdf39Skettenis 	const struct dwhdmi_phy_config *sc_phy_config;
946a2cdf39Skettenis 
956a2cdf39Skettenis 	enum drm_connector_status (*sc_detect)(struct dwhdmi_softc *, int);
966a2cdf39Skettenis 	void			(*sc_enable)(struct dwhdmi_softc *);
976a2cdf39Skettenis 	void			(*sc_disable)(struct dwhdmi_softc *);
986a2cdf39Skettenis 	void			(*sc_mode_set)(struct dwhdmi_softc *,
99*7137d9bbSderaadt 					       const struct drm_display_mode *,
100*7137d9bbSderaadt 					       const struct drm_display_mode *);
10113a9a14fSkettenis 	enum drm_mode_status	(*sc_mode_valid)(struct dwhdmi_softc *,
102*7137d9bbSderaadt 						 const struct drm_display_mode *);
1036a2cdf39Skettenis };
1046a2cdf39Skettenis 
1056a2cdf39Skettenis #define	to_dwhdmi_connector(x)	container_of(x, struct dwhdmi_connector, base)
1066a2cdf39Skettenis 
1076a2cdf39Skettenis int		dwhdmi_attach(struct dwhdmi_softc *);
1086a2cdf39Skettenis int		dwhdmi_bind(struct dwhdmi_softc *, struct drm_encoder *);
1096a2cdf39Skettenis 
1106a2cdf39Skettenis uint8_t		dwhdmi_read(struct dwhdmi_softc *, bus_size_t);
1116a2cdf39Skettenis void		dwhdmi_write(struct dwhdmi_softc *, bus_size_t, uint8_t);
1126a2cdf39Skettenis 
1136a2cdf39Skettenis enum drm_connector_status dwhdmi_phy_detect(struct dwhdmi_softc *, int);
1146a2cdf39Skettenis void		dwhdmi_phy_enable(struct dwhdmi_softc *);
1156a2cdf39Skettenis void		dwhdmi_phy_disable(struct dwhdmi_softc *);
1166a2cdf39Skettenis void		dwhdmi_phy_mode_set(struct dwhdmi_softc *,
117*7137d9bbSderaadt 				    const struct drm_display_mode *,
118*7137d9bbSderaadt 				    const struct drm_display_mode *);
1196a2cdf39Skettenis 
1206a2cdf39Skettenis #endif /* !_DEV_IC_DWHDMI_H */
121