xref: /OK3568_Linux_fs/kernel/drivers/gpu/drm/nouveau/dispnv04/cursor.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: MIT
2*4882a593Smuzhiyun #include <drm/drm_mode.h>
3*4882a593Smuzhiyun #include "nouveau_drv.h"
4*4882a593Smuzhiyun #include "nouveau_reg.h"
5*4882a593Smuzhiyun #include "nouveau_crtc.h"
6*4882a593Smuzhiyun #include "hw.h"
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun static void
nv04_cursor_show(struct nouveau_crtc * nv_crtc,bool update)9*4882a593Smuzhiyun nv04_cursor_show(struct nouveau_crtc *nv_crtc, bool update)
10*4882a593Smuzhiyun {
11*4882a593Smuzhiyun 	nv_show_cursor(nv_crtc->base.dev, nv_crtc->index, true);
12*4882a593Smuzhiyun }
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun static void
nv04_cursor_hide(struct nouveau_crtc * nv_crtc,bool update)15*4882a593Smuzhiyun nv04_cursor_hide(struct nouveau_crtc *nv_crtc, bool update)
16*4882a593Smuzhiyun {
17*4882a593Smuzhiyun 	nv_show_cursor(nv_crtc->base.dev, nv_crtc->index, false);
18*4882a593Smuzhiyun }
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun static void
nv04_cursor_set_pos(struct nouveau_crtc * nv_crtc,int x,int y)21*4882a593Smuzhiyun nv04_cursor_set_pos(struct nouveau_crtc *nv_crtc, int x, int y)
22*4882a593Smuzhiyun {
23*4882a593Smuzhiyun 	nv_crtc->cursor_saved_x = x; nv_crtc->cursor_saved_y = y;
24*4882a593Smuzhiyun 	NVWriteRAMDAC(nv_crtc->base.dev, nv_crtc->index,
25*4882a593Smuzhiyun 		      NV_PRAMDAC_CU_START_POS,
26*4882a593Smuzhiyun 		      XLATE(y, 0, NV_PRAMDAC_CU_START_POS_Y) |
27*4882a593Smuzhiyun 		      XLATE(x, 0, NV_PRAMDAC_CU_START_POS_X));
28*4882a593Smuzhiyun }
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun static void
crtc_wr_cio_state(struct drm_crtc * crtc,struct nv04_crtc_reg * crtcstate,int index)31*4882a593Smuzhiyun crtc_wr_cio_state(struct drm_crtc *crtc, struct nv04_crtc_reg *crtcstate, int index)
32*4882a593Smuzhiyun {
33*4882a593Smuzhiyun 	NVWriteVgaCrtc(crtc->dev, nouveau_crtc(crtc)->index, index,
34*4882a593Smuzhiyun 		       crtcstate->CRTC[index]);
35*4882a593Smuzhiyun }
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun static void
nv04_cursor_set_offset(struct nouveau_crtc * nv_crtc,uint32_t offset)38*4882a593Smuzhiyun nv04_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun 	struct drm_device *dev = nv_crtc->base.dev;
41*4882a593Smuzhiyun 	struct nouveau_drm *drm = nouveau_drm(dev);
42*4882a593Smuzhiyun 	struct nv04_crtc_reg *regp = &nv04_display(dev)->mode_reg.crtc_reg[nv_crtc->index];
43*4882a593Smuzhiyun 	struct drm_crtc *crtc = &nv_crtc->base;
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun 	regp->CRTC[NV_CIO_CRE_HCUR_ADDR0_INDEX] =
46*4882a593Smuzhiyun 		MASK(NV_CIO_CRE_HCUR_ASI) |
47*4882a593Smuzhiyun 		XLATE(offset, 17, NV_CIO_CRE_HCUR_ADDR0_ADR);
48*4882a593Smuzhiyun 	regp->CRTC[NV_CIO_CRE_HCUR_ADDR1_INDEX] =
49*4882a593Smuzhiyun 		XLATE(offset, 11, NV_CIO_CRE_HCUR_ADDR1_ADR);
50*4882a593Smuzhiyun 	if (crtc->mode.flags & DRM_MODE_FLAG_DBLSCAN)
51*4882a593Smuzhiyun 		regp->CRTC[NV_CIO_CRE_HCUR_ADDR1_INDEX] |=
52*4882a593Smuzhiyun 			MASK(NV_CIO_CRE_HCUR_ADDR1_CUR_DBL);
53*4882a593Smuzhiyun 	regp->CRTC[NV_CIO_CRE_HCUR_ADDR2_INDEX] = offset >> 24;
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun 	crtc_wr_cio_state(crtc, regp, NV_CIO_CRE_HCUR_ADDR0_INDEX);
56*4882a593Smuzhiyun 	crtc_wr_cio_state(crtc, regp, NV_CIO_CRE_HCUR_ADDR1_INDEX);
57*4882a593Smuzhiyun 	crtc_wr_cio_state(crtc, regp, NV_CIO_CRE_HCUR_ADDR2_INDEX);
58*4882a593Smuzhiyun 	if (drm->client.device.info.family == NV_DEVICE_INFO_V0_CURIE)
59*4882a593Smuzhiyun 		nv_fix_nv40_hw_cursor(dev, nv_crtc->index);
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun int
nv04_cursor_init(struct nouveau_crtc * crtc)63*4882a593Smuzhiyun nv04_cursor_init(struct nouveau_crtc *crtc)
64*4882a593Smuzhiyun {
65*4882a593Smuzhiyun 	crtc->cursor.set_offset = nv04_cursor_set_offset;
66*4882a593Smuzhiyun 	crtc->cursor.set_pos = nv04_cursor_set_pos;
67*4882a593Smuzhiyun 	crtc->cursor.hide = nv04_cursor_hide;
68*4882a593Smuzhiyun 	crtc->cursor.show = nv04_cursor_show;
69*4882a593Smuzhiyun 	return 0;
70*4882a593Smuzhiyun }
71