summaryrefslogtreecommitdiff
path: root/libdrm/xf86drmHash.c
AgeCommit message (Collapse)Author
2007-07-18drm: remove drm_u64_t, replace with uint64_t everwhereDave Airlie
This might break something, stdint.h inclusion in drm.h maybe required but I'm not sure yet what platforms have it what ones don't.
2007-04-26libdrm: remove HAVE_XORG_CONFIG_H and XFree86LOADER ifdef's.George Sapountzis
We no longer import libdrm in the xserver.
2006-03-15Avoid walking off the end of the hash table. (Coverity report #465)Adam Jackson
2006-02-20Formatting cleanup, dead code removal. Remove N() namespacing macro,Adam Jackson
useless. Remove SIGIO handling functions as they're server-only and properly belong in libdri.
2005-11-30Resync from Xorg head: conditional include of xorg-config.hAdam Jackson
2005-11-28fix mem leak in HashHash() (bug 5171)Brian Paul
2005-01-30Final pass of libdrm.so work:Adam Jackson
- Add $(DESTDIR) for distributors doing package creation - Remove OS-specific include path from build - Add /usr/include/drm for driver-kernel API - Install all of shared-core/*.h in /usr/include/drm - Rename xf86drm.h to libdrm.h since we're not X biased anymore - Include backwards compat for xf86drm.h name, with a warning - Fix libdrm source to account for drm.h living in /usr/include/drm
2001-04-09First pass of XFree86 4.0.99.2 merge.David Dawes
2001-03-13Rest of MGA dualhead patch.Gareth Hughes
2000-07-11Merge XFree86 4.0.1Alan Hourihane
2000-06-13Update email addresses and copyright notices to reflect VA Linux SystemsRik Faith
2000-03-15Import of XFree86 4.0Jeff Hartmann
1999-12-05Initial revisionDaryll Strauss
id='n181' href='#n181'>181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
/*
 * 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.
 *
 */

#include "nv50_connector.h"

static struct nv50_output *nv50_connector_to_output(struct nv50_connector *connector, bool digital)
{
	struct nv50_display *display = nv50_get_display(connector->dev);
	struct nv50_output *output = NULL;
	bool digital_possible = false;
	bool analog_possible = false;

	switch (connector->type) {
		case CONNECTOR_VGA:
		case CONNECTOR_TV:
			analog_possible = true;
			break;
		case CONNECTOR_DVI_I:
			analog_possible = true;
			digital_possible = true;
			break;
		case CONNECTOR_DVI_D:
		case CONNECTOR_LVDS:
			digital_possible = true;
			break;
		default:
			break;
	}

	/* Return early on bad situations. */
	if (!analog_possible && !digital_possible)
		return NULL;

	if (!analog_possible && !digital)
		return NULL;

	if (!digital_possible && digital)
		return NULL;

	list_for_each_entry(output, &display->outputs, item) {
		if (connector->bus != output->bus)
			continue;
		if (digital && output->type == OUTPUT_TMDS)
			return output;
		if (digital && output->type == OUTPUT_LVDS)
			return output;
		if (!digital && output->type == OUTPUT_DAC)
			return output;
		if (!digital && output->type == OUTPUT_TV)
			return output;
	}

	return NULL;
}

static int nv50_connector_hpd_detect(struct nv50_connector *connector)
{
	struct drm_nouveau_private *dev_priv = connector->dev->dev_private;
	bool present = 0;
	uint32_t reg = 0;

	/* Assume connected for the moment. */
	if (connector->type == CONNECTOR_LVDS) {
		NV50_DEBUG("LVDS is defaulting to connected for the moment.\n");
		return 1;
	}

	/* No i2c port, no idea what to do for hotplug. */
	if (connector->i2c_chan->index == 15) {
		DRM_ERROR("You have a non-LVDS SOR with no i2c port, please report\n");
		return -EINVAL;
	}

	if (connector->i2c_chan->index > 3) {
		DRM_ERROR("You have an unusual configuration, index is %d\n", connector->i2c_chan->index);
		DRM_ERROR("Please report.\n");
		return -EINVAL;
	}

	/* Check hotplug pins. */
	reg = NV_READ(NV50_PCONNECTOR_HOTPLUG_STATE);
	if (reg & (NV50_PCONNECTOR_HOTPLUG_STATE_PIN_CONNECTED_I2C0 << (4 * connector->i2c_chan->index)))
		present = 1;

	if (present)
		NV50_DEBUG("Hotplug detect returned positive for bus %d\n", connector->bus);
	else
		NV50_DEBUG("Hotplug detect returned negative for bus %d\n", connector->bus);

	return present;
}

static int nv50_connector_i2c_detect(struct nv50_connector *connector)
{
	/* kindly borrrowed from the intel driver, hope it works. */
	uint8_t out_buf[] = { 0x0, 0x0};
	uint8_t buf[2];
	int ret;
	struct i2c_msg msgs[] = {
		{
			.addr = 0x50,
			.flags = 0,
			.len = 1,
			.buf = out_buf,
		},
		{
			.addr = 0x50,
			.flags = I2C_M_RD,
			.len = 1,
			.buf = buf,
		}
	};

	if (!connector->i2c_chan)
		return -EINVAL;

	ret = i2c_transfer(&connector->i2c_chan->adapter, msgs, 2);
	NV50_DEBUG("I2C detect returned %d\n", ret);

	if (ret == 2)
		return true;

	return false;
}

static int nv50_connector_destroy(struct nv50_connector *connector)
{
	struct drm_device *dev = connector->dev;
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct nv50_display *display = nv50_get_display(dev);

	NV50_DEBUG("\n");

	if (!display || !connector)
		return -EINVAL;

	list_del(&connector->item);

	if (connector->i2c_chan)
		nv50_i2c_channel_destroy(connector->i2c_chan);

	if (dev_priv->free_connector)
		dev_priv->free_connector(connector);

	return 0;
}

int nv50_connector_create(struct drm_device *dev, int bus, int i2c_index, int type)
{
	struct nv50_connector *connector = NULL;
	struct drm_nouveau_private *dev_priv = dev->dev_private;
	struct nv50_display *display = NULL;

	NV50_DEBUG("\n");

	/* This allows the public layer to do it's thing. */
	if (dev_priv->alloc_connector)
		connector = dev_priv->alloc_connector(dev);

	if (!connector)
		return -ENOMEM;

	connector->dev = dev;

	display = nv50_get_display(dev);
	if (!display)
		goto out;

	if (type == CONNECTOR_UNKNOWN)
		goto out;

	list_add_tail(&connector->item, &display->connectors);

	connector->bus = bus;
	connector->type = type;

	switch (type) {
		case CONNECTOR_VGA:
			DRM_INFO("Detected a VGA connector\n");
			break;
		case CONNECTOR_DVI_D:
			DRM_INFO("Detected a DVI-D connector\n");
			break;
		case CONNECTOR_DVI_I:
			DRM_INFO("Detected a DVI-I connector\n");
			break;
		case CONNECTOR_LVDS:
			DRM_INFO("Detected a LVDS connector\n");
			break;
		case CONNECTOR_TV:
			DRM_INFO("Detected a TV connector\n");
			break;
		default:
			DRM_ERROR("Unknown connector, this is not good.\n");
			break;
	}

	/* some reasonable defaults */
	if (type == CONNECTOR_DVI_D || type == CONNECTOR_DVI_I || type == CONNECTOR_LVDS)
		connector->requested_scaling_mode = SCALE_FULLSCREEN;
	else
		connector->requested_scaling_mode = SCALE_NON_GPU;

	connector->use_dithering = false;

	if (i2c_index < 0xf)
		connector->i2c_chan = nv50_i2c_channel_create(dev, i2c_index);

	/* set function pointers */
	connector->hpd_detect = nv50_connector_hpd_detect;
	connector->i2c_detect = nv50_connector_i2c_detect;
	connector->destroy = nv50_connector_destroy;
	connector->to_output = nv50_connector_to_output;

	return 0;

out:
	if (dev_priv->free_connector)
		dev_priv->free_connector(connector);

	return -EINVAL;
}