2009-12-11 16:24:15 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Maarten Maathuis.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial
|
|
|
|
* portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-10-03 00:01:07 +07:00
|
|
|
#include <drm/drmP.h>
|
|
|
|
#include <drm/drm_crtc_helper.h>
|
2009-12-11 16:24:15 +07:00
|
|
|
|
|
|
|
#define NOUVEAU_DMA_DEBUG (nouveau_reg_debug & NOUVEAU_REG_DEBUG_EVO)
|
|
|
|
#include "nouveau_reg.h"
|
2012-07-31 13:16:21 +07:00
|
|
|
#include "nouveau_drm.h"
|
2009-12-11 16:24:15 +07:00
|
|
|
#include "nouveau_dma.h"
|
|
|
|
#include "nouveau_encoder.h"
|
|
|
|
#include "nouveau_connector.h"
|
|
|
|
#include "nouveau_crtc.h"
|
|
|
|
#include "nv50_display.h"
|
|
|
|
|
2012-07-31 13:16:21 +07:00
|
|
|
#include <subdev/timer.h>
|
|
|
|
|
2012-03-09 13:22:56 +07:00
|
|
|
static u32
|
2012-07-11 07:44:20 +07:00
|
|
|
nv50_sor_dp_lane_map(struct drm_device *dev, struct dcb_output *dcb, u8 lane)
|
2012-03-09 13:22:56 +07:00
|
|
|
{
|
2012-07-31 13:16:21 +07:00
|
|
|
struct nouveau_drm *drm = nouveau_drm(dev);
|
2012-03-09 13:22:56 +07:00
|
|
|
static const u8 nvaf[] = { 24, 16, 8, 0 }; /* thanks, apple.. */
|
|
|
|
static const u8 nv50[] = { 16, 8, 0, 24 };
|
2012-07-31 13:16:21 +07:00
|
|
|
if (nv_device(drm->device)->chipset == 0xaf)
|
2012-03-09 13:22:56 +07:00
|
|
|
return nvaf[lane];
|
|
|
|
return nv50[lane];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-07-11 07:44:20 +07:00
|
|
|
nv50_sor_dp_train_set(struct drm_device *dev, struct dcb_output *dcb, u8 pattern)
|
2012-03-09 13:22:56 +07:00
|
|
|
{
|
2012-07-31 13:16:21 +07:00
|
|
|
struct nouveau_device *device = nouveau_dev(dev);
|
2012-03-09 13:22:56 +07:00
|
|
|
u32 or = ffs(dcb->or) - 1, link = !(dcb->sorconf.link & 1);
|
2012-07-31 13:16:21 +07:00
|
|
|
nv_mask(device, NV50_SOR_DP_CTRL(or, link), 0x0f000000, pattern << 24);
|
2012-03-09 13:22:56 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-07-11 07:44:20 +07:00
|
|
|
nv50_sor_dp_train_adj(struct drm_device *dev, struct dcb_output *dcb,
|
2012-03-09 13:22:56 +07:00
|
|
|
u8 lane, u8 swing, u8 preem)
|
|
|
|
{
|
2012-07-31 13:16:21 +07:00
|
|
|
struct nouveau_device *device = nouveau_dev(dev);
|
|
|
|
struct nouveau_drm *drm = nouveau_drm(dev);
|
2012-03-09 13:22:56 +07:00
|
|
|
u32 or = ffs(dcb->or) - 1, link = !(dcb->sorconf.link & 1);
|
|
|
|
u32 shift = nv50_sor_dp_lane_map(dev, dcb, lane);
|
|
|
|
u32 mask = 0x000000ff << shift;
|
|
|
|
u8 *table, *entry, *config;
|
|
|
|
|
|
|
|
table = nouveau_dp_bios_data(dev, dcb, &entry);
|
|
|
|
if (!table || (table[0] != 0x20 && table[0] != 0x21)) {
|
2012-07-31 13:16:21 +07:00
|
|
|
NV_ERROR(drm, "PDISP: unsupported DP table for chipset\n");
|
2012-03-09 13:22:56 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
config = entry + table[4];
|
|
|
|
while (config[0] != swing || config[1] != preem) {
|
|
|
|
config += table[5];
|
|
|
|
if (config >= entry + table[4] + entry[4] * table[5])
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-31 13:16:21 +07:00
|
|
|
nv_mask(device, NV50_SOR_DP_UNK118(or, link), mask, config[2] << shift);
|
|
|
|
nv_mask(device, NV50_SOR_DP_UNK120(or, link), mask, config[3] << shift);
|
|
|
|
nv_mask(device, NV50_SOR_DP_UNK130(or, link), 0x0000ff00, config[4] << 8);
|
2012-03-09 13:22:56 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-07-11 07:44:20 +07:00
|
|
|
nv50_sor_dp_link_set(struct drm_device *dev, struct dcb_output *dcb, int crtc,
|
2012-03-09 13:22:56 +07:00
|
|
|
int link_nr, u32 link_bw, bool enhframe)
|
|
|
|
{
|
2012-07-31 13:16:21 +07:00
|
|
|
struct nouveau_device *device = nouveau_dev(dev);
|
|
|
|
struct nouveau_drm *drm = nouveau_drm(dev);
|
2012-03-09 13:22:56 +07:00
|
|
|
u32 or = ffs(dcb->or) - 1, link = !(dcb->sorconf.link & 1);
|
2012-07-31 13:16:21 +07:00
|
|
|
u32 dpctrl = nv_rd32(device, NV50_SOR_DP_CTRL(or, link)) & ~0x001f4000;
|
|
|
|
u32 clksor = nv_rd32(device, 0x614300 + (or * 0x800)) & ~0x000c0000;
|
2012-03-09 13:22:56 +07:00
|
|
|
u8 *table, *entry, mask;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
table = nouveau_dp_bios_data(dev, dcb, &entry);
|
|
|
|
if (!table || (table[0] != 0x20 && table[0] != 0x21)) {
|
2012-07-31 13:16:21 +07:00
|
|
|
NV_ERROR(drm, "PDISP: unsupported DP table for chipset\n");
|
2012-03-09 13:22:56 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = ROMPTR(dev, entry[10]);
|
|
|
|
if (entry) {
|
|
|
|
while (link_bw < ROM16(entry[0]) * 10)
|
|
|
|
entry += 4;
|
|
|
|
|
|
|
|
nouveau_bios_run_init_table(dev, ROM16(entry[2]), dcb, crtc);
|
|
|
|
}
|
|
|
|
|
|
|
|
dpctrl |= ((1 << link_nr) - 1) << 16;
|
|
|
|
if (enhframe)
|
|
|
|
dpctrl |= 0x00004000;
|
|
|
|
|
|
|
|
if (link_bw > 162000)
|
|
|
|
clksor |= 0x00040000;
|
|
|
|
|
2012-07-31 13:16:21 +07:00
|
|
|
nv_wr32(device, 0x614300 + (or * 0x800), clksor);
|
|
|
|
nv_wr32(device, NV50_SOR_DP_CTRL(or, link), dpctrl);
|
2012-03-09 13:22:56 +07:00
|
|
|
|
|
|
|
mask = 0;
|
|
|
|
for (i = 0; i < link_nr; i++)
|
|
|
|
mask |= 1 << (nv50_sor_dp_lane_map(dev, dcb, i) >> 3);
|
2012-07-31 13:16:21 +07:00
|
|
|
nv_mask(device, NV50_SOR_DP_UNK130(or, link), 0x0000000f, mask);
|
2012-03-09 13:22:56 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nv50_sor_dp_link_get(struct drm_device *dev, u32 or, u32 link, u32 *nr, u32 *bw)
|
|
|
|
{
|
2012-07-31 13:16:21 +07:00
|
|
|
struct nouveau_device *device = nouveau_dev(dev);
|
|
|
|
u32 dpctrl = nv_rd32(device, NV50_SOR_DP_CTRL(or, link)) & 0x000f0000;
|
|
|
|
u32 clksor = nv_rd32(device, 0x614300 + (or * 0x800));
|
2012-03-09 13:22:56 +07:00
|
|
|
if (clksor & 0x000c0000)
|
|
|
|
*bw = 270000;
|
|
|
|
else
|
|
|
|
*bw = 162000;
|
|
|
|
|
|
|
|
if (dpctrl > 0x00030000) *nr = 4;
|
|
|
|
else if (dpctrl > 0x00010000) *nr = 2;
|
|
|
|
else *nr = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nv50_sor_dp_calc_tu(struct drm_device *dev, int or, int link, u32 clk, u32 bpp)
|
|
|
|
{
|
2012-07-31 13:16:21 +07:00
|
|
|
struct nouveau_device *device = nouveau_dev(dev);
|
|
|
|
struct nouveau_drm *drm = nouveau_drm(dev);
|
2012-03-09 13:22:56 +07:00
|
|
|
const u32 symbol = 100000;
|
|
|
|
int bestTU = 0, bestVTUi = 0, bestVTUf = 0, bestVTUa = 0;
|
|
|
|
int TU, VTUi, VTUf, VTUa;
|
|
|
|
u64 link_data_rate, link_ratio, unk;
|
|
|
|
u32 best_diff = 64 * symbol;
|
|
|
|
u32 link_nr, link_bw, r;
|
|
|
|
|
|
|
|
/* calculate packed data rate for each lane */
|
|
|
|
nv50_sor_dp_link_get(dev, or, link, &link_nr, &link_bw);
|
|
|
|
link_data_rate = (clk * bpp / 8) / link_nr;
|
|
|
|
|
|
|
|
/* calculate ratio of packed data rate to link symbol rate */
|
|
|
|
link_ratio = link_data_rate * symbol;
|
|
|
|
r = do_div(link_ratio, link_bw);
|
|
|
|
|
|
|
|
for (TU = 64; TU >= 32; TU--) {
|
|
|
|
/* calculate average number of valid symbols in each TU */
|
|
|
|
u32 tu_valid = link_ratio * TU;
|
|
|
|
u32 calc, diff;
|
|
|
|
|
|
|
|
/* find a hw representation for the fraction.. */
|
|
|
|
VTUi = tu_valid / symbol;
|
|
|
|
calc = VTUi * symbol;
|
|
|
|
diff = tu_valid - calc;
|
|
|
|
if (diff) {
|
|
|
|
if (diff >= (symbol / 2)) {
|
|
|
|
VTUf = symbol / (symbol - diff);
|
|
|
|
if (symbol - (VTUf * diff))
|
|
|
|
VTUf++;
|
|
|
|
|
|
|
|
if (VTUf <= 15) {
|
|
|
|
VTUa = 1;
|
|
|
|
calc += symbol - (symbol / VTUf);
|
|
|
|
} else {
|
|
|
|
VTUa = 0;
|
|
|
|
VTUf = 1;
|
|
|
|
calc += symbol;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
VTUa = 0;
|
|
|
|
VTUf = min((int)(symbol / diff), 15);
|
|
|
|
calc += symbol / VTUf;
|
|
|
|
}
|
|
|
|
|
|
|
|
diff = calc - tu_valid;
|
|
|
|
} else {
|
|
|
|
/* no remainder, but the hw doesn't like the fractional
|
|
|
|
* part to be zero. decrement the integer part and
|
|
|
|
* have the fraction add a whole symbol back
|
|
|
|
*/
|
|
|
|
VTUa = 0;
|
|
|
|
VTUf = 1;
|
|
|
|
VTUi--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (diff < best_diff) {
|
|
|
|
best_diff = diff;
|
|
|
|
bestTU = TU;
|
|
|
|
bestVTUa = VTUa;
|
|
|
|
bestVTUf = VTUf;
|
|
|
|
bestVTUi = VTUi;
|
|
|
|
if (diff == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bestTU) {
|
2012-07-31 13:16:21 +07:00
|
|
|
NV_ERROR(drm, "DP: unable to find suitable config\n");
|
2012-03-09 13:22:56 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX close to vbios numbers, but not right */
|
|
|
|
unk = (symbol - link_ratio) * bestTU;
|
|
|
|
unk *= link_ratio;
|
|
|
|
r = do_div(unk, symbol);
|
|
|
|
r = do_div(unk, symbol);
|
|
|
|
unk += 6;
|
|
|
|
|
2012-07-31 13:16:21 +07:00
|
|
|
nv_mask(device, NV50_SOR_DP_CTRL(or, link), 0x000001fc, bestTU << 2);
|
|
|
|
nv_mask(device, NV50_SOR_DP_SCFG(or, link), 0x010f7f3f, bestVTUa << 24 |
|
2012-03-09 13:22:56 +07:00
|
|
|
bestVTUf << 16 |
|
|
|
|
bestVTUi << 8 |
|
|
|
|
unk);
|
|
|
|
}
|
2009-12-11 16:24:15 +07:00
|
|
|
static void
|
2010-07-01 12:33:45 +07:00
|
|
|
nv50_sor_disconnect(struct drm_encoder *encoder)
|
2009-12-11 16:24:15 +07:00
|
|
|
{
|
2010-07-01 12:33:45 +07:00
|
|
|
struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
|
2012-07-31 13:16:21 +07:00
|
|
|
struct nouveau_drm *drm = nouveau_drm(encoder->dev);
|
2010-07-01 12:33:45 +07:00
|
|
|
struct drm_device *dev = encoder->dev;
|
2011-02-01 07:24:41 +07:00
|
|
|
struct nouveau_channel *evo = nv50_display(dev)->master;
|
2009-12-11 16:24:15 +07:00
|
|
|
int ret;
|
|
|
|
|
2010-07-01 12:33:45 +07:00
|
|
|
if (!nv_encoder->crtc)
|
|
|
|
return;
|
2010-07-05 12:19:16 +07:00
|
|
|
nv50_crtc_blank(nouveau_crtc(nv_encoder->crtc), true);
|
2010-07-01 12:33:45 +07:00
|
|
|
|
2012-07-31 13:16:21 +07:00
|
|
|
NV_DEBUG(drm, "Disconnecting SOR %d\n", nv_encoder->or);
|
2009-12-11 16:24:15 +07:00
|
|
|
|
2010-07-05 12:19:16 +07:00
|
|
|
ret = RING_SPACE(evo, 4);
|
2009-12-11 16:24:15 +07:00
|
|
|
if (ret) {
|
2012-07-31 13:16:21 +07:00
|
|
|
NV_ERROR(drm, "no space while disconnecting SOR\n");
|
2009-12-11 16:24:15 +07:00
|
|
|
return;
|
|
|
|
}
|
2012-04-01 18:09:13 +07:00
|
|
|
BEGIN_NV04(evo, 0, NV50_EVO_SOR(nv_encoder->or, MODE_CTRL), 1);
|
2010-07-05 12:19:16 +07:00
|
|
|
OUT_RING (evo, 0);
|
2012-04-01 18:09:13 +07:00
|
|
|
BEGIN_NV04(evo, 0, NV50_EVO_UPDATE, 1);
|
2010-07-05 12:19:16 +07:00
|
|
|
OUT_RING (evo, 0);
|
2010-07-01 12:33:45 +07:00
|
|
|
|
2011-10-05 08:05:07 +07:00
|
|
|
nouveau_hdmi_mode_set(encoder, NULL);
|
|
|
|
|
2010-07-01 12:33:45 +07:00
|
|
|
nv_encoder->crtc = NULL;
|
|
|
|
nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
|
2009-12-11 16:24:15 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nv50_sor_dpms(struct drm_encoder *encoder, int mode)
|
|
|
|
{
|
2012-07-31 13:16:21 +07:00
|
|
|
struct nouveau_device *device = nouveau_dev(encoder->dev);
|
|
|
|
struct nouveau_drm *drm = nouveau_drm(encoder->dev);
|
2009-12-11 16:24:15 +07:00
|
|
|
struct drm_device *dev = encoder->dev;
|
|
|
|
struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
|
2010-01-22 07:57:01 +07:00
|
|
|
struct drm_encoder *enc;
|
2009-12-11 16:24:15 +07:00
|
|
|
uint32_t val;
|
|
|
|
int or = nv_encoder->or;
|
|
|
|
|
2012-07-31 13:16:21 +07:00
|
|
|
NV_DEBUG(drm, "or %d type %d mode %d\n", or, nv_encoder->dcb->type, mode);
|
2009-12-11 16:24:15 +07:00
|
|
|
|
2010-01-22 07:57:01 +07:00
|
|
|
nv_encoder->last_dpms = mode;
|
|
|
|
list_for_each_entry(enc, &dev->mode_config.encoder_list, head) {
|
|
|
|
struct nouveau_encoder *nvenc = nouveau_encoder(enc);
|
|
|
|
|
|
|
|
if (nvenc == nv_encoder ||
|
2012-07-11 07:44:20 +07:00
|
|
|
(nvenc->dcb->type != DCB_OUTPUT_TMDS &&
|
|
|
|
nvenc->dcb->type != DCB_OUTPUT_LVDS &&
|
|
|
|
nvenc->dcb->type != DCB_OUTPUT_DP) ||
|
2010-01-22 07:57:01 +07:00
|
|
|
nvenc->dcb->or != nv_encoder->dcb->or)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (nvenc->last_dpms == DRM_MODE_DPMS_ON)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-11 16:24:15 +07:00
|
|
|
/* wait for it to be done */
|
2012-07-31 13:16:21 +07:00
|
|
|
if (!nv_wait(device, NV50_PDISPLAY_SOR_DPMS_CTRL(or),
|
2009-12-11 16:24:15 +07:00
|
|
|
NV50_PDISPLAY_SOR_DPMS_CTRL_PENDING, 0)) {
|
2012-07-31 13:16:21 +07:00
|
|
|
NV_ERROR(drm, "timeout: SOR_DPMS_CTRL_PENDING(%d) == 0\n", or);
|
|
|
|
NV_ERROR(drm, "SOR_DPMS_CTRL(%d) = 0x%08x\n", or,
|
|
|
|
nv_rd32(device, NV50_PDISPLAY_SOR_DPMS_CTRL(or)));
|
2009-12-11 16:24:15 +07:00
|
|
|
}
|
|
|
|
|
2012-07-31 13:16:21 +07:00
|
|
|
val = nv_rd32(device, NV50_PDISPLAY_SOR_DPMS_CTRL(or));
|
2009-12-11 16:24:15 +07:00
|
|
|
|
|
|
|
if (mode == DRM_MODE_DPMS_ON)
|
|
|
|
val |= NV50_PDISPLAY_SOR_DPMS_CTRL_ON;
|
|
|
|
else
|
|
|
|
val &= ~NV50_PDISPLAY_SOR_DPMS_CTRL_ON;
|
|
|
|
|
2012-07-31 13:16:21 +07:00
|
|
|
nv_wr32(device, NV50_PDISPLAY_SOR_DPMS_CTRL(or), val |
|
2009-12-11 16:24:15 +07:00
|
|
|
NV50_PDISPLAY_SOR_DPMS_CTRL_PENDING);
|
2012-07-31 13:16:21 +07:00
|
|
|
if (!nv_wait(device, NV50_PDISPLAY_SOR_DPMS_STATE(or),
|
2009-12-11 16:24:15 +07:00
|
|
|
NV50_PDISPLAY_SOR_DPMS_STATE_WAIT, 0)) {
|
2012-07-31 13:16:21 +07:00
|
|
|
NV_ERROR(drm, "timeout: SOR_DPMS_STATE_WAIT(%d) == 0\n", or);
|
|
|
|
NV_ERROR(drm, "SOR_DPMS_STATE(%d) = 0x%08x\n", or,
|
|
|
|
nv_rd32(device, NV50_PDISPLAY_SOR_DPMS_STATE(or)));
|
2009-12-11 16:24:15 +07:00
|
|
|
}
|
|
|
|
|
2012-07-11 07:44:20 +07:00
|
|
|
if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
|
2012-03-10 22:20:54 +07:00
|
|
|
struct dp_train_func func = {
|
|
|
|
.link_set = nv50_sor_dp_link_set,
|
|
|
|
.train_set = nv50_sor_dp_train_set,
|
|
|
|
.train_adj = nv50_sor_dp_train_adj
|
|
|
|
};
|
2010-07-06 08:20:17 +07:00
|
|
|
|
2012-03-10 22:20:54 +07:00
|
|
|
nouveau_dp_dpms(encoder, mode, nv_encoder->dp.datarate, &func);
|
2010-07-06 08:20:17 +07:00
|
|
|
}
|
2009-12-11 16:24:15 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nv50_sor_save(struct drm_encoder *encoder)
|
|
|
|
{
|
2012-07-31 13:16:21 +07:00
|
|
|
struct nouveau_drm *drm = nouveau_drm(encoder->dev);
|
|
|
|
NV_ERROR(drm, "!!\n");
|
2009-12-11 16:24:15 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nv50_sor_restore(struct drm_encoder *encoder)
|
|
|
|
{
|
2012-07-31 13:16:21 +07:00
|
|
|
struct nouveau_drm *drm = nouveau_drm(encoder->dev);
|
|
|
|
NV_ERROR(drm, "!!\n");
|
2009-12-11 16:24:15 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2012-07-17 22:56:50 +07:00
|
|
|
nv50_sor_mode_fixup(struct drm_encoder *encoder,
|
|
|
|
const struct drm_display_mode *mode,
|
2009-12-11 16:24:15 +07:00
|
|
|
struct drm_display_mode *adjusted_mode)
|
|
|
|
{
|
2012-07-31 13:16:21 +07:00
|
|
|
struct nouveau_drm *drm = nouveau_drm(encoder->dev);
|
2009-12-11 16:24:15 +07:00
|
|
|
struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
|
|
|
|
struct nouveau_connector *connector;
|
|
|
|
|
2012-07-31 13:16:21 +07:00
|
|
|
NV_DEBUG(drm, "or %d\n", nv_encoder->or);
|
2009-12-11 16:24:15 +07:00
|
|
|
|
|
|
|
connector = nouveau_encoder_connector_get(nv_encoder);
|
|
|
|
if (!connector) {
|
2012-07-31 13:16:21 +07:00
|
|
|
NV_ERROR(drm, "Encoder has no connector\n");
|
2009-12-11 16:24:15 +07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (connector->scaling_mode != DRM_MODE_SCALE_NONE &&
|
2012-03-13 17:35:51 +07:00
|
|
|
connector->native_mode)
|
|
|
|
drm_mode_copy(adjusted_mode, connector->native_mode);
|
2009-12-11 16:24:15 +07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nv50_sor_prepare(struct drm_encoder *encoder)
|
|
|
|
{
|
2011-10-17 05:56:09 +07:00
|
|
|
struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
|
2011-10-14 11:43:20 +07:00
|
|
|
nv50_sor_disconnect(encoder);
|
2012-07-11 07:44:20 +07:00
|
|
|
if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
|
2011-10-17 05:56:09 +07:00
|
|
|
/* avoid race between link training and supervisor intr */
|
|
|
|
nv50_display_sync(encoder->dev);
|
|
|
|
}
|
2009-12-11 16:24:15 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nv50_sor_commit(struct drm_encoder *encoder)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-10-20 11:25:53 +07:00
|
|
|
nv50_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
|
|
|
|
struct drm_display_mode *mode)
|
2009-12-11 16:24:15 +07:00
|
|
|
{
|
2011-02-01 07:24:41 +07:00
|
|
|
struct nouveau_channel *evo = nv50_display(encoder->dev)->master;
|
2009-12-11 16:24:15 +07:00
|
|
|
struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
|
2012-07-31 13:16:21 +07:00
|
|
|
struct nouveau_drm *drm = nouveau_drm(encoder->dev);
|
2009-12-11 16:24:15 +07:00
|
|
|
struct nouveau_crtc *crtc = nouveau_crtc(encoder->crtc);
|
2011-07-01 12:51:49 +07:00
|
|
|
struct nouveau_connector *nv_connector;
|
2009-12-11 16:24:15 +07:00
|
|
|
uint32_t mode_ctl = 0;
|
|
|
|
int ret;
|
|
|
|
|
2012-07-31 13:16:21 +07:00
|
|
|
NV_DEBUG(drm, "or %d type %d -> crtc %d\n",
|
2010-07-02 10:47:38 +07:00
|
|
|
nv_encoder->or, nv_encoder->dcb->type, crtc->index);
|
2011-10-05 11:52:02 +07:00
|
|
|
nv_encoder->crtc = encoder->crtc;
|
2009-12-11 16:24:15 +07:00
|
|
|
|
|
|
|
switch (nv_encoder->dcb->type) {
|
2012-07-11 07:44:20 +07:00
|
|
|
case DCB_OUTPUT_TMDS:
|
2009-12-11 16:24:15 +07:00
|
|
|
if (nv_encoder->dcb->sorconf.link & 1) {
|
2011-10-20 11:25:53 +07:00
|
|
|
if (mode->clock < 165000)
|
2009-12-11 16:24:15 +07:00
|
|
|
mode_ctl = 0x0100;
|
|
|
|
else
|
|
|
|
mode_ctl = 0x0500;
|
|
|
|
} else
|
|
|
|
mode_ctl = 0x0200;
|
2011-10-05 08:05:07 +07:00
|
|
|
|
2011-10-20 11:25:53 +07:00
|
|
|
nouveau_hdmi_mode_set(encoder, mode);
|
2009-12-11 16:24:15 +07:00
|
|
|
break;
|
2012-07-11 07:44:20 +07:00
|
|
|
case DCB_OUTPUT_DP:
|
2011-07-01 12:51:49 +07:00
|
|
|
nv_connector = nouveau_encoder_connector_get(nv_encoder);
|
2011-08-04 08:04:47 +07:00
|
|
|
if (nv_connector && nv_connector->base.display_info.bpc == 6) {
|
2011-10-20 11:25:53 +07:00
|
|
|
nv_encoder->dp.datarate = mode->clock * 18 / 8;
|
2011-07-01 12:51:49 +07:00
|
|
|
mode_ctl |= 0x00020000;
|
2011-08-04 08:04:47 +07:00
|
|
|
} else {
|
2011-10-20 11:25:53 +07:00
|
|
|
nv_encoder->dp.datarate = mode->clock * 24 / 8;
|
2011-07-01 12:51:49 +07:00
|
|
|
mode_ctl |= 0x00050000;
|
2011-08-04 08:04:47 +07:00
|
|
|
}
|
2011-07-01 12:51:49 +07:00
|
|
|
|
2009-12-11 16:24:15 +07:00
|
|
|
if (nv_encoder->dcb->sorconf.link & 1)
|
|
|
|
mode_ctl |= 0x00000800;
|
|
|
|
else
|
|
|
|
mode_ctl |= 0x00000900;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (crtc->index == 1)
|
|
|
|
mode_ctl |= NV50_EVO_SOR_MODE_CTRL_CRTC1;
|
|
|
|
else
|
|
|
|
mode_ctl |= NV50_EVO_SOR_MODE_CTRL_CRTC0;
|
|
|
|
|
2011-10-20 11:25:53 +07:00
|
|
|
if (mode->flags & DRM_MODE_FLAG_NHSYNC)
|
2009-12-11 16:24:15 +07:00
|
|
|
mode_ctl |= NV50_EVO_SOR_MODE_CTRL_NHSYNC;
|
|
|
|
|
2011-10-20 11:25:53 +07:00
|
|
|
if (mode->flags & DRM_MODE_FLAG_NVSYNC)
|
2009-12-11 16:24:15 +07:00
|
|
|
mode_ctl |= NV50_EVO_SOR_MODE_CTRL_NVSYNC;
|
|
|
|
|
2011-08-04 08:04:47 +07:00
|
|
|
nv50_sor_dpms(encoder, DRM_MODE_DPMS_ON);
|
|
|
|
|
2009-12-11 16:24:15 +07:00
|
|
|
ret = RING_SPACE(evo, 2);
|
|
|
|
if (ret) {
|
2012-07-31 13:16:21 +07:00
|
|
|
NV_ERROR(drm, "no space while connecting SOR\n");
|
2011-10-05 11:52:02 +07:00
|
|
|
nv_encoder->crtc = NULL;
|
2009-12-11 16:24:15 +07:00
|
|
|
return;
|
|
|
|
}
|
2012-04-01 18:09:13 +07:00
|
|
|
BEGIN_NV04(evo, 0, NV50_EVO_SOR(nv_encoder->or, MODE_CTRL), 1);
|
2009-12-11 16:24:15 +07:00
|
|
|
OUT_RING(evo, mode_ctl);
|
2010-07-01 12:33:45 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct drm_crtc *
|
|
|
|
nv50_sor_crtc_get(struct drm_encoder *encoder)
|
|
|
|
{
|
|
|
|
return nouveau_encoder(encoder)->crtc;
|
2009-12-11 16:24:15 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_encoder_helper_funcs nv50_sor_helper_funcs = {
|
|
|
|
.dpms = nv50_sor_dpms,
|
|
|
|
.save = nv50_sor_save,
|
|
|
|
.restore = nv50_sor_restore,
|
|
|
|
.mode_fixup = nv50_sor_mode_fixup,
|
|
|
|
.prepare = nv50_sor_prepare,
|
|
|
|
.commit = nv50_sor_commit,
|
|
|
|
.mode_set = nv50_sor_mode_set,
|
2010-07-01 12:33:45 +07:00
|
|
|
.get_crtc = nv50_sor_crtc_get,
|
|
|
|
.detect = NULL,
|
|
|
|
.disable = nv50_sor_disconnect
|
2009-12-11 16:24:15 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
nv50_sor_destroy(struct drm_encoder *encoder)
|
|
|
|
{
|
|
|
|
struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
|
2012-07-31 13:16:21 +07:00
|
|
|
struct nouveau_drm *drm = nouveau_drm(encoder->dev);
|
2009-12-11 16:24:15 +07:00
|
|
|
|
2012-07-31 13:16:21 +07:00
|
|
|
NV_DEBUG(drm, "\n");
|
2009-12-11 16:24:15 +07:00
|
|
|
|
|
|
|
drm_encoder_cleanup(encoder);
|
|
|
|
|
|
|
|
kfree(nv_encoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_encoder_funcs nv50_sor_encoder_funcs = {
|
|
|
|
.destroy = nv50_sor_destroy,
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
2012-07-11 07:44:20 +07:00
|
|
|
nv50_sor_create(struct drm_connector *connector, struct dcb_output *entry)
|
2009-12-11 16:24:15 +07:00
|
|
|
{
|
|
|
|
struct nouveau_encoder *nv_encoder = NULL;
|
2010-06-28 11:35:50 +07:00
|
|
|
struct drm_device *dev = connector->dev;
|
2012-07-31 13:16:21 +07:00
|
|
|
struct nouveau_drm *drm = nouveau_drm(dev);
|
2009-12-11 16:24:15 +07:00
|
|
|
struct drm_encoder *encoder;
|
|
|
|
int type;
|
|
|
|
|
2012-07-31 13:16:21 +07:00
|
|
|
NV_DEBUG(drm, "\n");
|
2009-12-11 16:24:15 +07:00
|
|
|
|
|
|
|
switch (entry->type) {
|
2012-07-11 07:44:20 +07:00
|
|
|
case DCB_OUTPUT_TMDS:
|
|
|
|
case DCB_OUTPUT_DP:
|
2009-12-11 16:24:15 +07:00
|
|
|
type = DRM_MODE_ENCODER_TMDS;
|
|
|
|
break;
|
2012-07-11 07:44:20 +07:00
|
|
|
case DCB_OUTPUT_LVDS:
|
2009-12-11 16:24:15 +07:00
|
|
|
type = DRM_MODE_ENCODER_LVDS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
|
|
|
|
if (!nv_encoder)
|
|
|
|
return -ENOMEM;
|
|
|
|
encoder = to_drm_encoder(nv_encoder);
|
|
|
|
|
|
|
|
nv_encoder->dcb = entry;
|
|
|
|
nv_encoder->or = ffs(entry->or) - 1;
|
2010-07-01 12:33:45 +07:00
|
|
|
nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
|
2009-12-11 16:24:15 +07:00
|
|
|
|
|
|
|
drm_encoder_init(dev, encoder, &nv50_sor_encoder_funcs, type);
|
|
|
|
drm_encoder_helper_add(encoder, &nv50_sor_helper_funcs);
|
|
|
|
|
|
|
|
encoder->possible_crtcs = entry->heads;
|
|
|
|
encoder->possible_clones = 0;
|
|
|
|
|
2010-06-28 11:35:50 +07:00
|
|
|
drm_mode_connector_attach_encoder(connector, encoder);
|
2009-12-11 16:24:15 +07:00
|
|
|
return 0;
|
|
|
|
}
|