Skip to content

Commit 0fa6075

Browse files
committed
Pinebook Pro framebuffer edp support WIP
Mostly taken from netbsd. Breaks rk_vop for hdmi.
1 parent d3eb69d commit 0fa6075

File tree

15 files changed

+1720
-44
lines changed

15 files changed

+1720
-44
lines changed

bridges/anxdp/anx_dp.c

Lines changed: 809 additions & 0 deletions
Large diffs are not rendered by default.

bridges/anxdp/anx_dp.h

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
/*-
2+
* SPDX-License-Identifier: BSD-2-Clause
3+
*
4+
* Copyright (c) 2021 Jesper Schmitz Mouridsen <[email protected]>
5+
* Copyright (c) 2019 Jonathan A. Kollasch <[email protected]>
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 AND CONTRIBUTORS ``AS IS'' AND
17+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24+
* LIABILITY, 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+
* $FreeBSD$
29+
*/
30+
31+
32+
#ifndef __ANXEDP_H__
33+
#define __ANXEDP_H__
34+
#include <drm/drmP.h>
35+
#include <drm/drm_crtc.h>
36+
#undef CONFIG_DRM_DP_CEC
37+
#include <drm/drm_crtc_helper.h>
38+
#include <drm/drm_dp_helper.h>
39+
#include <drm/drm_edid.h>
40+
#include <drm/drm_dp_helper.h>
41+
#include <drm/drm_probe_helper.h>
42+
#include <drm/drm_bridge.h>
43+
#include <drm/drm_panel.h>
44+
#include <drm/drm_connector.h>
45+
#include <drm/drm_edid.h>
46+
#include <linux/bitops.h>
47+
#include "dev/drm/rockchip/rk_edp.h"
48+
#define __BITS(hi,lo) ((~((~0)<<((hi)+1)))&((~0)<<(lo)))
49+
#define __BIT BIT
50+
#define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask))
51+
#define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask))
52+
#define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask))
53+
#define ANXDP_AUDIO 0
54+
#define ANXDP_DP_TX_VERSION 0x010
55+
#define ANXDP_TX_SW_RESET 0x014
56+
#define RESET_DP_TX __BIT(0)
57+
#define ANXDP_FUNC_EN_1 0x018
58+
#define MASTER_VID_FUNC_EN_N __BIT(7)
59+
#define RK_VID_CAP_FUNC_EN_N __BIT(6)
60+
#define SLAVE_VID_FUNC_EN_N __BIT(5)
61+
#define RK_VID_FIFO_FUNC_EN_N __BIT(5)
62+
#define AUD_FIFO_FUNC_EN_N __BIT(4)
63+
#define AUD_FUNC_EN_N __BIT(3)
64+
#define HDCP_FUNC_EN_N __BIT(2)
65+
#define CRC_FUNC_EN_N __BIT(1)
66+
#define SW_FUNC_EN_N __BIT(0)
67+
#define ANXDP_FUNC_EN_2 0x01c
68+
#define SSC_FUNC_EN_N __BIT(7)
69+
#define AUX_FUNC_EN_N __BIT(2)
70+
#define SERDES_FIFO_FUNC_EN_N __BIT(1)
71+
#define LS_CLK_DOMAIN_FUNC_EN_N __BIT(0)
72+
#define ANXDP_VIDEO_CTL_1 0x020
73+
#define VIDEO_EN __BIT(7)
74+
#define VIDEO_MUTE __BIT(6)
75+
#define ANXDP_VIDEO_CTL_2 0x024
76+
#define ANXDP_VIDEO_CTL_3 0x028
77+
#define ANXDP_VIDEO_CTL_4 0x02c
78+
#define ANXDP_VIDEO_CTL_8 0x03c
79+
#define ANXDP_VIDEO_CTL_10 0x044
80+
#define F_SEL __BIT(4)
81+
#define SLAVE_I_SCAN_CFG __BIT(2)
82+
#define SLAVE_VSYNC_P_CFG __BIT(1)
83+
#define SLAVE_HSYNC_P_CFG __BIT(0)
84+
#define ANXDP_PLL_REG_1 0x0fc
85+
#define REF_CLK_24M __BIT(0)
86+
#define RKANXDP_PD 0x12c
87+
#define DP_INC_BG __BIT(7)
88+
#define DP_EXP_PD __BIT(6)
89+
#define DP_PHY_PD __BIT(5)
90+
#define RK_AUX_PD __BIT(5)
91+
#define AUX_PD __BIT(4)
92+
#define RK_PLL_PD __BIT(4)
93+
#define CHx_PD(x) __BIT(x) /* 0<=x<=3 */
94+
#define DP_ALL_PD __BITS(7,0)
95+
#define ANXDP_LANE_MAP 0x35c
96+
#define ANXDP_ANALOG_CTL_1 0x370
97+
#define TX_TERMINAL_CTRL_50_OHM __BIT(4)
98+
#define ANXDP_ANALOG_CTL_2 0x374
99+
#define SEL_24M __BIT(3)
100+
#define TX_DVDD_BIT_1_0625V 0x4
101+
#define ANXDP_ANALOG_CTL_3 0x378
102+
#define DRIVE_DVDD_BIT_1_0625V (0x4 << 5)
103+
#define VCO_BIT_600_MICRO (0x5 << 0)
104+
#define ANXDP_PLL_FILTER_CTL_1 0x37c
105+
#define PD_RING_OSC __BIT(6)
106+
#define AUX_TERMINAL_CTRL_50_OHM (2 << 4)
107+
#define TX_CUR1_2X __BIT(2)
108+
#define TX_CUR_16_MA 3
109+
#define ANXDP_TX_AMP_TUNING_CTL 0x380
110+
#define ANXDP_AUX_HW_RETRY_CTL 0x390
111+
#define AUX_BIT_PERIOD_EXPECTED_DELAY(x) __SHIFTIN((x), __BITS(10,8))
112+
#define AUX_HW_RETRY_INTERVAL_600_US __SHIFTIN(0, __BITS(4,3))
113+
#define AUX_HW_RETRY_INTERVAL_800_US __SHIFTIN(1, __BITS(4,3))
114+
#define AUX_HW_RETRY_INTERVAL_1000_US __SHIFTIN(2, __BITS(4,3))
115+
#define AUX_HW_RETRY_INTERVAL_1800_US __SHIFTIN(3, __BITS(4,3))
116+
#define AUX_HW_RETRY_COUNT_SEL(x) __SHIFTIN((x), __BITS(2,0))
117+
#define ANXDP_COMMON_INT_STA_1 0x3c4
118+
#define PLL_LOCK_CHG __BIT(6)
119+
#define ANXDP_COMMON_INT_STA_2 0x3c8
120+
#define ANXDP_COMMON_INT_STA_3 0x3cc
121+
#define ANXDP_COMMON_INT_STA_4 0x3d0
122+
#define ANXDP_DP_INT_STA 0x3dc
123+
#define INT_HPD __BIT(6)
124+
#define HW_TRAINING_FINISH __BIT(5)
125+
#define RPLY_RECEIV __BIT(1)
126+
#define AUX_ERR __BIT(0)
127+
#define ANXDP_SYS_CTL_1 0x600
128+
#define DET_STA __BIT(2)
129+
#define FORCE_DET __BIT(1)
130+
#define DET_CTRL __BIT(0)
131+
#define ANXDP_SYS_CTL_2 0x604
132+
#define ANXDP_SYS_CTL_3 0x608
133+
#define HPD_STATUS __BIT(6)
134+
#define F_HPD __BIT(5)
135+
#define HPD_CTRL __BIT(4)
136+
#define HDCP_RDY __BIT(3)
137+
#define STRM_VALID __BIT(2)
138+
#define F_VALID __BIT(1)
139+
#define VALID_CTRL __BIT(0)
140+
#define ANXDP_SYS_CTL_4 0x60c
141+
#define ANXDP_PKT_SEND_CTL 0x640
142+
#define ANXDP_HDCP_CTL 0x648
143+
#define ANXDP_LINK_BW_SET 0x680
144+
#define ANXDP_LANE_COUNT_SET 0x684
145+
#define ANXDP_TRAINING_PTN_SET 0x688
146+
#define SCRAMBLING_DISABLE __BIT(5)
147+
#define SW_TRAINING_PATTERN_SET_PTN2 __SHIFTIN(2, __BITS(1,0))
148+
#define SW_TRAINING_PATTERN_SET_PTN1 __SHIFTIN(1, __BITS(1,0))
149+
#define ANXDP_LNx_LINK_TRAINING_CTL(x) (0x68c + 4 * (x)) /* 0 <= x <= 3 */
150+
#define MAX_PRE_REACH __BIT(5)
151+
#define PRE_EMPHASIS_SET(x) __SHIFTIN((x), __BITS(4,3))
152+
#define MAX_DRIVE_REACH __BIT(2)
153+
#define DRIVE_CURRENT_SET(x) __SHIFTIN((x), __BITS(1,0))
154+
#define ANXDP_DEBUG_CTL 0x6c0
155+
#define PLL_LOCK __BIT(4)
156+
#define F_PLL_LOCK __BIT(3)
157+
#define PLL_LOCK_CTRL __BIT(2)
158+
#define PN_INV __BIT(0)
159+
#define ANXDP_LINK_DEBUG_CTL 0x6e0
160+
#define ANXDP_PLL_CTL 0x71c
161+
#define ANXDP_PHY_PD 0x720
162+
#define ANXDP_PHY_TEST 0x724
163+
#define MACRO_RST __BIT(5)
164+
#define ANXDP_M_AUD_GEN_FILTER_TH 0x778
165+
#define ANXDP_AUX_CH_STA 0x780
166+
#define AUX_BUSY __BIT(4)
167+
#define AUX_STATUS(x) __SHIFTOUT((x), __BITS(3,0))
168+
#define ANXDP_AUX_ERR_NUM 0x784
169+
#define ANXDP_AUX_CH_DEFER_CTL 0x788
170+
#define DEFER_CTRL_EN __BIT(7)
171+
#define DEFER_COUNT(x) __SHIFTIN((x), __BITS(6,0))
172+
#define ANXDP_AUX_RX_COMM 0x78c
173+
#define AUX_RX_COMM_I2C_DEFER __BIT(3)
174+
#define AUX_RX_COMM_AUX_DEFER __BIT(1)
175+
#define ANXDP_BUFFER_DATA_CTL 0x790
176+
#define BUF_CLR __BIT(7)
177+
#define BUF_DATA_COUNT(x) __SHIFTIN((x), __BITS(4,0))
178+
#define ANXDP_AUX_CH_CTL_1 0x794
179+
#define AUX_LENGTH(x) __SHIFTIN((x) - 1, __BITS(7,4))
180+
#define AUX_TX_COMM_I2C_TRANSACTION (0x0 << 3)
181+
182+
#define AUX_TX_COMM(x) __SHIFTOUT(x, __BITS(3,0))
183+
#define AUX_TX_COMM_DP __BIT(3)
184+
#define AUX_TX_COMM_MOT __BIT(2)
185+
#define AUX_TX_COMM_READ __BIT(0)
186+
#define ANXDP_AUX_ADDR_7_0 0x798
187+
#define AUX_ADDR_7_0(x) (((x) >> 0) & 0xff)
188+
#define ANXDP_AUX_ADDR_15_8 0x79c
189+
#define AUX_ADDR_15_8(x) (((x) >> 8) & 0xff)
190+
#define ANXDP_AUX_ADDR_19_16 0x7a0
191+
#define AUX_ADDR_19_16(x) (((x) >> 16) & 0xf)
192+
#define ANXDP_AUX_CH_CTL_2 0x7a4
193+
#define ADDR_ONLY __BIT(1)
194+
#define AUX_EN __BIT(0)
195+
#define ANXDP_BUF_DATA(x) (0x7c0 + 4 * (x))
196+
#define ANXDP_SOC_GENERAL_CTL 0x800
197+
#define AUDIO_MODE_SPDIF_MODE __BIT(8)
198+
#define VIDEO_MODE_SLAVE_MODE __BIT(1)
199+
#define ANXDP_CRC_CON 0x890
200+
#define ANXDP_PLL_REG_2 0x9e4
201+
#define ANXDP_PLL_REG_3 0x9e8
202+
#define ANXDP_PLL_REG_4 0x9ec
203+
#define ANXDP_PLL_REG_5 0xa00
204+
205+
206+
207+
struct rk_edp_softc;
208+
209+
struct anxdp_softc {
210+
device_t iicbus;
211+
struct device* sc_dev;
212+
bus_space_tag_t sc_bst;
213+
bus_space_handle_t sc_bsh;
214+
u_int sc_flags;
215+
#define ANXDP_FLAG_ROCKCHIP __BIT(0)
216+
struct drm_connector sc_connector;
217+
struct drm_encoder sc_encoder;
218+
struct drm_dp_aux sc_dpaux;
219+
struct drm_panel * sc_panel;
220+
uint8_t sc_dpcd[DP_RECEIVER_CAP_SIZE];
221+
struct drm_bridge sc_bridge;
222+
struct drm_display_mode sc_curmode;
223+
};
224+
struct rk_edp_softc {
225+
struct anxdp_softc sc_base;
226+
device_t dev;
227+
struct resource *res[2];
228+
struct syscon *grf;
229+
clk_t pclk;
230+
clk_t dpclk;
231+
clk_t grfclk;
232+
bus_space_tag_t sc_bst;
233+
bus_space_handle_t sc_bsh;
234+
235+
};
236+
#define to_edp_connector(x) container_of(x, struct anxdp_connector, base)
237+
int anxdp_attach(struct anxdp_softc *sc);
238+
int anxdp_bind(struct anxdp_softc *sc,struct drm_encoder *encoder);
239+
void anxdp_init_aux(struct anxdp_softc * sc);
240+
void anxdp_add_bridge(struct anxdp_softc *sc,struct drm_encoder *encoder);
241+
242+
DECLARE_CLASS(anxdp_driver);
243+
#endif /* ANXEDP_H */
244+

bridges/anxdp/anx_edp_if.m

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#-
2+
# Copyright (c) 2019 Emmanuel Vadot <[email protected]>
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions
6+
# are met:
7+
# 1. Redistributions of source code must retain the above copyright
8+
# notice, this list of conditions and the following disclaimer.
9+
# 2. Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
#
13+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16+
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19+
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21+
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22+
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23+
# SUCH DAMAGE.
24+
#
25+
# $FreeBSD$
26+
#
27+
28+
INTERFACE anx_edp;
29+
30+
HEADER {
31+
struct drm_crtc;
32+
struct drm_device;
33+
};
34+
35+
#
36+
# Add the encoder to the drm pipeline
37+
#
38+
METHOD int add_encoder {
39+
device_t dev;
40+
struct drm_crtc *crtc;
41+
struct drm_device *drm;
42+
};

core/drm_dp_helper.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -678,11 +678,11 @@ static int drm_dp_i2c_do_msg(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
678678
* communicate with a non-existant DisplayPort device).
679679
* Avoid spamming the kernel log with timeout errors.
680680
*/
681-
if (ret == -ETIMEDOUT)
681+
if (ret == -ETIMEDOUT) {
682682
DRM_DEBUG_KMS_RATELIMITED("transaction timed out\n");
683-
else
683+
} else {
684684
DRM_DEBUG_KMS("transaction failed: %d\n", ret);
685-
685+
}
686686
return ret;
687687
}
688688

@@ -899,13 +899,13 @@ static void unlock_bus(struct i2c_adapter *i2c, unsigned int flags)
899899
{
900900
mutex_unlock(&i2c_to_aux(i2c)->hw_mutex);
901901
}
902-
902+
#ifndef __FreeBSD__
903903
static const struct i2c_lock_operations drm_dp_i2c_lock_ops = {
904904
.lock_bus = lock_bus,
905905
.trylock_bus = trylock_bus,
906906
.unlock_bus = unlock_bus,
907907
};
908-
908+
#endif
909909
static int drm_dp_aux_get_crc(struct drm_dp_aux *aux, u8 *crc)
910910
{
911911
u8 buf, count;
@@ -1009,8 +1009,9 @@ void drm_dp_aux_init(struct drm_dp_aux *aux)
10091009
aux->ddc.algo = &drm_dp_i2c_algo;
10101010
aux->ddc.algo_data = aux;
10111011
aux->ddc.retries = 3;
1012-
1012+
#ifndef __FreeBSD__
10131013
aux->ddc.lock_ops = &drm_dp_i2c_lock_ops;
1014+
#endif
10141015
}
10151016
EXPORT_SYMBOL(drm_dp_aux_init);
10161017

core/drm_dp_mst_topology.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <linux/kernel.h>
2828
#include <linux/sched.h>
2929
#include <linux/seq_file.h>
30-
30+
#define CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS 0
3131
#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
3232
#include <linux/stacktrace.h>
3333
#include <linux/sort.h>
@@ -2130,9 +2130,10 @@ static void build_mst_prop_path(const struct drm_dp_mst_branch *mstb,
21302130
int drm_dp_mst_connector_late_register(struct drm_connector *connector,
21312131
struct drm_dp_mst_port *port)
21322132
{
2133+
#ifndef __FreeBSD__
21332134
DRM_DEBUG_KMS("registering %s remote bus for %s\n",
21342135
port->aux.name, connector->kdev->kobj.name);
2135-
2136+
#endif
21362137
port->aux.dev = connector->kdev;
21372138
return drm_dp_aux_register_devnode(&port->aux);
21382139
}
@@ -2150,8 +2151,10 @@ EXPORT_SYMBOL(drm_dp_mst_connector_late_register);
21502151
void drm_dp_mst_connector_early_unregister(struct drm_connector *connector,
21512152
struct drm_dp_mst_port *port)
21522153
{
2154+
#ifndef __FreeBSD__
21532155
DRM_DEBUG_KMS("unregistering %s remote bus for %s\n",
21542156
port->aux.name, connector->kdev->kobj.name);
2157+
#endif
21552158
drm_dp_aux_unregister_devnode(&port->aux);
21562159
}
21572160
EXPORT_SYMBOL(drm_dp_mst_connector_early_unregister);
@@ -5377,8 +5380,9 @@ static int drm_dp_mst_register_i2c_bus(struct drm_dp_aux *aux)
53775380
aux->ddc.class = I2C_CLASS_DDC;
53785381
aux->ddc.owner = THIS_MODULE;
53795382
aux->ddc.dev.parent = aux->dev;
5383+
#ifndef __FreeBSD__
53805384
aux->ddc.dev.of_node = aux->dev->of_node;
5381-
5385+
#endif
53825386
strlcpy(aux->ddc.name, aux->name ? aux->name : dev_name(aux->dev),
53835387
sizeof(aux->ddc.name));
53845388

core/include/drm/drm_dp_helper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222

2323
#ifndef _DRM_DP_HELPER_H_
2424
#define _DRM_DP_HELPER_H_
25-
25+
#include <linux/mutex.h>
26+
#include <linux/workqueue.h>
2627
#include <linux/delay.h>
2728
#include <linux/i2c.h>
2829
#include <linux/types.h>

core/include/drm/drm_dp_mst_helper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
#ifndef _DRM_DP_MST_HELPER_H_
2323
#define _DRM_DP_MST_HELPER_H_
2424

25-
#include <linux/types.h>
25+
#include <sys/types.h>
2626
#include <drm/drm_dp_helper.h>
2727
#include <drm/drm_atomic.h>
28-
28+
#define CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS 0
2929
#if IS_ENABLED(CONFIG_DRM_DEBUG_DP_MST_TOPOLOGY_REFS)
3030
#include <linux/stackdepot.h>
3131
#include <linux/timekeeping.h>

0 commit comments

Comments
 (0)