Skip to content

Commit b51cd7a

Browse files
committed
drm/vc4: hvs: Fix frame count register readout
In order to get the field currently being output, the driver has been using the display FIFO frame count in the HVS, reading a 6-bit field at the offset 12 in the DISPSTATx register. While that field is indeed at that location for the FIFO 1 and 2, the one for the FIFO0 is actually in the DISPSTAT1 register, at the offset 18. Fixes: e538092 ("drm/vc4: Enable precise vblank timestamping for interlaced modes.") Signed-off-by: Maxime Ripard <maxime@cerno.tech> Acked-by: Thomas Zimmermann <tzimmermann@suse.de> Link: https://lore.kernel.org/r/20220331143744.777652-3-maxime@cerno.tech
1 parent 748acfc commit b51cd7a

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

drivers/gpu/drm/vc4/vc4_crtc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static bool vc4_crtc_get_scanout_position(struct drm_crtc *crtc,
123123
*vpos /= 2;
124124

125125
/* Use hpos to correct for field offset in interlaced mode. */
126-
if (VC4_GET_FIELD(val, SCALER_DISPSTATX_FRAME_COUNT) % 2)
126+
if (vc4_hvs_get_fifo_frame_count(dev, vc4_crtc_state->assigned_channel) % 2)
127127
*hpos += mode->crtc_htotal / 2;
128128
}
129129

drivers/gpu/drm/vc4/vc4_drv.h

+1
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ void vc4_irq_reset(struct drm_device *dev);
935935
extern struct platform_driver vc4_hvs_driver;
936936
void vc4_hvs_stop_channel(struct drm_device *dev, unsigned int output);
937937
int vc4_hvs_get_fifo_from_output(struct drm_device *dev, unsigned int output);
938+
u8 vc4_hvs_get_fifo_frame_count(struct drm_device *dev, unsigned int fifo);
938939
int vc4_hvs_atomic_check(struct drm_crtc *crtc, struct drm_atomic_state *state);
939940
void vc4_hvs_atomic_begin(struct drm_crtc *crtc, struct drm_atomic_state *state);
940941
void vc4_hvs_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state);

drivers/gpu/drm/vc4/vc4_hvs.c

+23
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,29 @@ static void vc4_hvs_update_gamma_lut(struct drm_crtc *crtc)
197197
vc4_hvs_lut_load(crtc);
198198
}
199199

200+
u8 vc4_hvs_get_fifo_frame_count(struct drm_device *dev, unsigned int fifo)
201+
{
202+
struct vc4_dev *vc4 = to_vc4_dev(dev);
203+
u8 field = 0;
204+
205+
switch (fifo) {
206+
case 0:
207+
field = VC4_GET_FIELD(HVS_READ(SCALER_DISPSTAT1),
208+
SCALER_DISPSTAT1_FRCNT0);
209+
break;
210+
case 1:
211+
field = VC4_GET_FIELD(HVS_READ(SCALER_DISPSTAT1),
212+
SCALER_DISPSTAT1_FRCNT1);
213+
break;
214+
case 2:
215+
field = VC4_GET_FIELD(HVS_READ(SCALER_DISPSTAT2),
216+
SCALER_DISPSTAT2_FRCNT2);
217+
break;
218+
}
219+
220+
return field;
221+
}
222+
200223
int vc4_hvs_get_fifo_from_output(struct drm_device *dev, unsigned int output)
201224
{
202225
struct vc4_dev *vc4 = to_vc4_dev(dev);

drivers/gpu/drm/vc4/vc4_regs.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,6 @@
379379
# define SCALER_DISPSTATX_MODE_EOF 3
380380
# define SCALER_DISPSTATX_FULL BIT(29)
381381
# define SCALER_DISPSTATX_EMPTY BIT(28)
382-
# define SCALER_DISPSTATX_FRAME_COUNT_MASK VC4_MASK(17, 12)
383-
# define SCALER_DISPSTATX_FRAME_COUNT_SHIFT 12
384382
# define SCALER_DISPSTATX_LINE_MASK VC4_MASK(11, 0)
385383
# define SCALER_DISPSTATX_LINE_SHIFT 0
386384

@@ -403,9 +401,15 @@
403401
(x) * (SCALER_DISPBKGND1 - \
404402
SCALER_DISPBKGND0))
405403
#define SCALER_DISPSTAT1 0x00000058
404+
# define SCALER_DISPSTAT1_FRCNT0_MASK VC4_MASK(23, 18)
405+
# define SCALER_DISPSTAT1_FRCNT0_SHIFT 18
406+
# define SCALER_DISPSTAT1_FRCNT1_MASK VC4_MASK(17, 12)
407+
# define SCALER_DISPSTAT1_FRCNT1_SHIFT 12
408+
406409
#define SCALER_DISPSTATX(x) (SCALER_DISPSTAT0 + \
407410
(x) * (SCALER_DISPSTAT1 - \
408411
SCALER_DISPSTAT0))
412+
409413
#define SCALER_DISPBASE1 0x0000005c
410414
#define SCALER_DISPBASEX(x) (SCALER_DISPBASE0 + \
411415
(x) * (SCALER_DISPBASE1 - \
@@ -415,7 +419,11 @@
415419
(x) * (SCALER_DISPCTRL1 - \
416420
SCALER_DISPCTRL0))
417421
#define SCALER_DISPBKGND2 0x00000064
422+
418423
#define SCALER_DISPSTAT2 0x00000068
424+
# define SCALER_DISPSTAT2_FRCNT2_MASK VC4_MASK(17, 12)
425+
# define SCALER_DISPSTAT2_FRCNT2_SHIFT 12
426+
419427
#define SCALER_DISPBASE2 0x0000006c
420428
#define SCALER_DISPALPHA2 0x00000070
421429
#define SCALER_GAMADDR 0x00000078

0 commit comments

Comments
 (0)