Commit de691855 authored by Ben Skeggs's avatar Ben Skeggs

drm/nouveau: improve dithering properties, and implement proper auto mode

Signed-off-by: default avatarBen Skeggs <bskeggs@redhat.com>
parent 488ff207
...@@ -517,12 +517,16 @@ nouveau_connector_set_property(struct drm_connector *connector, ...@@ -517,12 +517,16 @@ nouveau_connector_set_property(struct drm_connector *connector,
} }
/* Dithering */ /* Dithering */
if (property == dev->mode_config.dithering_mode_property) { if (property == disp->dithering_mode) {
if (value == DRM_MODE_DITHERING_ON) nv_connector->dithering_mode = value;
nv_connector->use_dithering = true; if (!nv_crtc || !nv_crtc->set_dither)
else return 0;
nv_connector->use_dithering = false;
return nv_crtc->set_dither(nv_crtc, true);
}
if (property == disp->dithering_depth) {
nv_connector->dithering_depth = value;
if (!nv_crtc || !nv_crtc->set_dither) if (!nv_crtc || !nv_crtc->set_dither)
return 0; return 0;
...@@ -918,7 +922,7 @@ nouveau_connector_create(struct drm_device *dev, int index) ...@@ -918,7 +922,7 @@ nouveau_connector_create(struct drm_device *dev, int index)
drm_connector_init(dev, connector, funcs, type); drm_connector_init(dev, connector, funcs, type);
drm_connector_helper_add(connector, &nouveau_connector_helper_funcs); drm_connector_helper_add(connector, &nouveau_connector_helper_funcs);
/* Check if we need dithering enabled */ /* parse lvds table now, we depend on bios->fp.* values later */
if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS) { if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS) {
bool dummy, is_24bit = false; bool dummy, is_24bit = false;
...@@ -928,8 +932,6 @@ nouveau_connector_create(struct drm_device *dev, int index) ...@@ -928,8 +932,6 @@ nouveau_connector_create(struct drm_device *dev, int index)
"LVDS\n"); "LVDS\n");
goto fail; goto fail;
} }
nv_connector->use_dithering = !is_24bit;
} }
/* Init DVI-I specific properties */ /* Init DVI-I specific properties */
...@@ -940,8 +942,7 @@ nouveau_connector_create(struct drm_device *dev, int index) ...@@ -940,8 +942,7 @@ nouveau_connector_create(struct drm_device *dev, int index)
} }
/* Add overscan compensation options to digital outputs */ /* Add overscan compensation options to digital outputs */
if ((dev_priv->card_type == NV_50 || if (disp->underscan_property &&
dev_priv->card_type == NV_C0) &&
(dcb->type == DCB_CONNECTOR_DVI_D || (dcb->type == DCB_CONNECTOR_DVI_D ||
dcb->type == DCB_CONNECTOR_DVI_I || dcb->type == DCB_CONNECTOR_DVI_I ||
dcb->type == DCB_CONNECTOR_HDMI_0 || dcb->type == DCB_CONNECTOR_HDMI_0 ||
...@@ -977,10 +978,18 @@ nouveau_connector_create(struct drm_device *dev, int index) ...@@ -977,10 +978,18 @@ nouveau_connector_create(struct drm_device *dev, int index)
drm_connector_attach_property(connector, drm_connector_attach_property(connector,
dev->mode_config.scaling_mode_property, dev->mode_config.scaling_mode_property,
nv_connector->scaling_mode); nv_connector->scaling_mode);
drm_connector_attach_property(connector, if (disp->dithering_mode) {
dev->mode_config.dithering_mode_property, nv_connector->dithering_mode = DITHERING_MODE_AUTO;
nv_connector->use_dithering ? drm_connector_attach_property(connector,
DRM_MODE_DITHERING_ON : DRM_MODE_DITHERING_OFF); disp->dithering_mode,
nv_connector->dithering_mode);
}
if (disp->dithering_depth) {
nv_connector->dithering_depth = DITHERING_DEPTH_AUTO;
drm_connector_attach_property(connector,
disp->dithering_depth,
nv_connector->dithering_depth);
}
break; break;
} }
......
...@@ -30,12 +30,37 @@ ...@@ -30,12 +30,37 @@
#include "drm_edid.h" #include "drm_edid.h"
#include "nouveau_i2c.h" #include "nouveau_i2c.h"
enum nouveau_underscan_type {
UNDERSCAN_OFF,
UNDERSCAN_ON,
UNDERSCAN_AUTO,
};
/* the enum values specifically defined here match nv50/nvd0 hw values, and
* the code relies on this
*/
enum nouveau_dithering_mode {
DITHERING_MODE_OFF = 0x00,
DITHERING_MODE_ON = 0x01,
DITHERING_MODE_DYNAMIC2X2 = 0x10 | DITHERING_MODE_ON,
DITHERING_MODE_STATIC2X2 = 0x18 | DITHERING_MODE_ON,
DITHERING_MODE_TEMPORAL = 0x20 | DITHERING_MODE_ON,
DITHERING_MODE_AUTO
};
enum nouveau_dithering_depth {
DITHERING_DEPTH_6BPC = 0x00,
DITHERING_DEPTH_8BPC = 0x02,
DITHERING_DEPTH_AUTO
};
struct nouveau_connector { struct nouveau_connector {
struct drm_connector base; struct drm_connector base;
struct dcb_connector_table_entry *dcb; struct dcb_connector_table_entry *dcb;
bool use_dithering; int dithering_mode;
int dithering_depth;
int scaling_mode; int scaling_mode;
enum nouveau_underscan_type underscan; enum nouveau_underscan_type underscan;
u32 underscan_hborder; u32 underscan_hborder;
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "nouveau_hw.h" #include "nouveau_hw.h"
#include "nouveau_crtc.h" #include "nouveau_crtc.h"
#include "nouveau_dma.h" #include "nouveau_dma.h"
#include "nouveau_connector.h"
#include "nv50_display.h" #include "nv50_display.h"
static void static void
...@@ -154,35 +155,78 @@ static const struct drm_mode_config_funcs nouveau_mode_config_funcs = { ...@@ -154,35 +155,78 @@ static const struct drm_mode_config_funcs nouveau_mode_config_funcs = {
struct drm_prop_enum_list { struct drm_prop_enum_list {
u8 gen_mask;
int type; int type;
char *name; char *name;
}; };
static struct drm_prop_enum_list nouveau_underscan_enum_list[] = { static struct drm_prop_enum_list underscan[] = {
{ UNDERSCAN_OFF, "off" }, { 2, UNDERSCAN_AUTO, "auto" },
{ UNDERSCAN_ON, "on" }, { 2, UNDERSCAN_OFF, "off" },
{ UNDERSCAN_AUTO, "auto" }, { 2, UNDERSCAN_ON, "on" },
{}
}; };
static struct drm_prop_enum_list dither_mode[] = {
{ 7, DITHERING_MODE_AUTO, "auto" },
{ 7, DITHERING_MODE_OFF, "off" },
{ 1, DITHERING_MODE_ON, "on" },
{ 6, DITHERING_MODE_STATIC2X2, "static 2x2" },
{ 6, DITHERING_MODE_DYNAMIC2X2, "dynamic 2x2" },
{ 4, DITHERING_MODE_TEMPORAL, "temporal" },
{}
};
static struct drm_prop_enum_list dither_depth[] = {
{ 6, DITHERING_DEPTH_AUTO, "auto" },
{ 6, DITHERING_DEPTH_6BPC, "6 bpc" },
{ 6, DITHERING_DEPTH_8BPC, "8 bpc" },
{}
};
#define PROP_ENUM(p,gen,n,list) do { \
struct drm_prop_enum_list *l = (list); \
int c = 0; \
while (l->gen_mask) { \
if (l->gen_mask & (1 << (gen))) \
c++; \
l++; \
} \
if (c) { \
p = drm_property_create(dev, DRM_MODE_PROP_ENUM, n, c); \
l = (list); \
c = 0; \
while (p && l->gen_mask) { \
if (l->gen_mask & (1 << (gen))) { \
drm_property_add_enum(p, c, l->type, l->name); \
c++; \
} \
l++; \
} \
} \
} while(0)
int int
nouveau_display_create(struct drm_device *dev) nouveau_display_create(struct drm_device *dev)
{ {
struct drm_nouveau_private *dev_priv = dev->dev_private; struct drm_nouveau_private *dev_priv = dev->dev_private;
struct nouveau_display_engine *disp = &dev_priv->engine.display; struct nouveau_display_engine *disp = &dev_priv->engine.display;
int ret, cnt, i; int ret, gen;
drm_mode_config_init(dev); drm_mode_config_init(dev);
drm_mode_create_scaling_mode_property(dev); drm_mode_create_scaling_mode_property(dev);
drm_mode_create_dithering_property(dev);
if (dev_priv->card_type < NV_50)
cnt = ARRAY_SIZE(nouveau_underscan_enum_list); gen = 0;
disp->underscan_property = drm_property_create(dev, DRM_MODE_PROP_ENUM, else
"underscan", cnt); if (dev_priv->card_type < NV_D0)
for (i = 0; i < cnt; i++) { gen = 1;
drm_property_add_enum(disp->underscan_property, i, else
nouveau_underscan_enum_list[i].type, gen = 2;
nouveau_underscan_enum_list[i].name);
} PROP_ENUM(disp->dithering_mode, gen, "dithering mode", dither_mode);
PROP_ENUM(disp->dithering_depth, gen, "dithering depth", dither_depth);
PROP_ENUM(disp->underscan_property, gen, "underscan", underscan);
disp->underscan_hborder_property = disp->underscan_hborder_property =
drm_property_create(dev, DRM_MODE_PROP_RANGE, drm_property_create(dev, DRM_MODE_PROP_RANGE,
......
...@@ -391,12 +391,6 @@ struct nouveau_fifo_engine { ...@@ -391,12 +391,6 @@ struct nouveau_fifo_engine {
void (*tlb_flush)(struct drm_device *dev); void (*tlb_flush)(struct drm_device *dev);
}; };
enum nouveau_underscan_type {
UNDERSCAN_OFF,
UNDERSCAN_ON,
UNDERSCAN_AUTO,
};
struct nouveau_display_engine { struct nouveau_display_engine {
void *priv; void *priv;
int (*early_init)(struct drm_device *); int (*early_init)(struct drm_device *);
...@@ -405,6 +399,8 @@ struct nouveau_display_engine { ...@@ -405,6 +399,8 @@ struct nouveau_display_engine {
int (*init)(struct drm_device *); int (*init)(struct drm_device *);
void (*destroy)(struct drm_device *); void (*destroy)(struct drm_device *);
struct drm_property *dithering_mode;
struct drm_property *dithering_depth;
struct drm_property *underscan_property; struct drm_property *underscan_property;
struct drm_property *underscan_hborder_property; struct drm_property *underscan_hborder_property;
struct drm_property *underscan_vborder_property; struct drm_property *underscan_vborder_property;
......
...@@ -289,6 +289,7 @@ static void nv04_dfp_mode_set(struct drm_encoder *encoder, ...@@ -289,6 +289,7 @@ static void nv04_dfp_mode_set(struct drm_encoder *encoder,
struct nouveau_connector *nv_connector = nouveau_crtc_connector_get(nv_crtc); struct nouveau_connector *nv_connector = nouveau_crtc_connector_get(nv_crtc);
struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
struct drm_display_mode *output_mode = &nv_encoder->mode; struct drm_display_mode *output_mode = &nv_encoder->mode;
struct drm_connector *connector = &nv_connector->base;
uint32_t mode_ratio, panel_ratio; uint32_t mode_ratio, panel_ratio;
NV_DEBUG_KMS(dev, "Output mode on CRTC %d:\n", nv_crtc->index); NV_DEBUG_KMS(dev, "Output mode on CRTC %d:\n", nv_crtc->index);
...@@ -407,7 +408,9 @@ static void nv04_dfp_mode_set(struct drm_encoder *encoder, ...@@ -407,7 +408,9 @@ static void nv04_dfp_mode_set(struct drm_encoder *encoder,
} }
/* Output property. */ /* Output property. */
if (nv_connector->use_dithering) { if ((nv_connector->dithering_mode == DITHERING_MODE_ON) ||
(nv_connector->dithering_mode == DITHERING_MODE_AUTO &&
encoder->crtc->fb->depth > connector->display_info.bpc * 3)) {
if (dev_priv->chipset == 0x11) if (dev_priv->chipset == 0x11)
regp->dither = savep->dither | 0x00010000; regp->dither = savep->dither | 0x00010000;
else { else {
......
...@@ -134,33 +134,40 @@ nv50_crtc_blank(struct nouveau_crtc *nv_crtc, bool blanked) ...@@ -134,33 +134,40 @@ nv50_crtc_blank(struct nouveau_crtc *nv_crtc, bool blanked)
static int static int
nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update) nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
{ {
struct drm_device *dev = nv_crtc->base.dev; struct nouveau_channel *evo = nv50_display(nv_crtc->base.dev)->master;
struct nouveau_channel *evo = nv50_display(dev)->master; struct nouveau_connector *nv_connector;
struct nouveau_connector *nv_connector = struct drm_connector *connector;
nouveau_crtc_connector_get(nv_crtc); int head = nv_crtc->index, ret;
int ret; u32 mode = 0x00;
NV_DEBUG_KMS(dev, "\n");
ret = RING_SPACE(evo, 2 + (update ? 2 : 0)); nv_connector = nouveau_crtc_connector_get(nv_crtc);
if (ret) { connector = &nv_connector->base;
NV_ERROR(dev, "no space while setting dither\n"); if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) {
return ret; if (nv_crtc->base.fb->depth > connector->display_info.bpc * 3)
mode = DITHERING_MODE_DYNAMIC2X2;
} else {
mode = nv_connector->dithering_mode;
} }
BEGIN_RING(evo, 0, NV50_EVO_CRTC(nv_crtc->index, DITHER_CTRL), 1); if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) {
if (nv_connector->use_dithering) if (connector->display_info.bpc >= 8)
OUT_RING(evo, NV50_EVO_CRTC_DITHER_CTRL_ON); mode |= DITHERING_DEPTH_8BPC;
else } else {
OUT_RING(evo, NV50_EVO_CRTC_DITHER_CTRL_OFF); mode |= nv_connector->dithering_depth;
}
if (update) { ret = RING_SPACE(evo, 2 + (update ? 2 : 0));
BEGIN_RING(evo, 0, NV50_EVO_UPDATE, 1); if (ret == 0) {
OUT_RING(evo, 0); BEGIN_RING(evo, 0, NV50_EVO_CRTC(head, DITHER_CTRL), 1);
FIRE_RING(evo); OUT_RING (evo, mode);
if (update) {
BEGIN_RING(evo, 0, NV50_EVO_UPDATE, 1);
OUT_RING (evo, 0);
FIRE_RING (evo);
}
} }
return 0; return ret;
} }
struct nouveau_connector * struct nouveau_connector *
......
...@@ -109,20 +109,25 @@ nvd0_display_crtc_get(struct drm_encoder *encoder) ...@@ -109,20 +109,25 @@ nvd0_display_crtc_get(struct drm_encoder *encoder)
static int static int
nvd0_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update) nvd0_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
{ {
struct nouveau_connector *nv_connector;
struct drm_device *dev = nv_crtc->base.dev; struct drm_device *dev = nv_crtc->base.dev;
u32 *push, mode = 0; struct nouveau_connector *nv_connector;
struct drm_connector *connector;
u32 *push, mode = 0x00;
nv_connector = nouveau_crtc_connector_get(nv_crtc); nv_connector = nouveau_crtc_connector_get(nv_crtc);
if (nv_connector->use_dithering) { connector = &nv_connector->base;
/* 0x11: 6bpc dynamic 2x2 if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) {
* 0x13: 8bpc dynamic 2x2 if (nv_crtc->base.fb->depth > connector->display_info.bpc * 3)
* 0x19: 6bpc static 2x2 mode = DITHERING_MODE_DYNAMIC2X2;
* 0x1b: 8bpc static 2x2 } else {
* 0x21: 6bpc temporal mode = nv_connector->dithering_mode;
* 0x23: 8bpc temporal }
*/
mode = 0x00000011; if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) {
if (connector->display_info.bpc >= 8)
mode |= DITHERING_DEPTH_8BPC;
} else {
mode |= nv_connector->dithering_depth;
} }
push = evo_wait(dev, 0, 4); push = evo_wait(dev, 0, 4);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment