Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 79d6d942 authored by Dave Airlie's avatar Dave Airlie
Browse files

Merge branch 'drm-tda998x-devel' of git://ftp.arm.linux.org.uk/~rmk/linux-arm into drm-next

A number of TDA998x updates for the next merge window.  Patches
included in this set are:
* adding support for finding the attached CRTCs from DT
* a fix function name mis-spelling in a dev_err()
* simplify the EDID reading by using the drm_do_get_edid() function
  instead of coding this ourselves.

* 'drm-tda998x-devel' of git://ftp.arm.linux.org.uk/~rmk/linux-arm:
  drm/i2c: tda998x: use drm_do_get_edid()
  drm/i2c: tda998x: fix misspelling of current function in string
  drm/i2c: tda998x: add OF support for finding attached CRTCs
parents 329414c4 07259f8b
Loading
Loading
Loading
Loading
+31 −70
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@
#include <drm/drm_crtc_helper.h>
#include <drm/drm_crtc_helper.h>
#include <drm/drm_encoder_slave.h>
#include <drm/drm_encoder_slave.h>
#include <drm/drm_edid.h>
#include <drm/drm_edid.h>
#include <drm/drm_of.h>
#include <drm/i2c/tda998x.h>
#include <drm/i2c/tda998x.h>


#define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
#define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
@@ -387,7 +388,7 @@ set_page(struct tda998x_priv *priv, uint16_t reg)
		};
		};
		int ret = i2c_master_send(client, buf, sizeof(buf));
		int ret = i2c_master_send(client, buf, sizeof(buf));
		if (ret < 0) {
		if (ret < 0) {
			dev_err(&client->dev, "setpage %04x err %d\n",
			dev_err(&client->dev, "%s %04x err %d\n", __func__,
					reg, ret);
					reg, ret);
			return ret;
			return ret;
		}
		}
@@ -1035,8 +1036,9 @@ tda998x_encoder_detect(struct tda998x_priv *priv)
			connector_status_disconnected;
			connector_status_disconnected;
}
}


static int read_edid_block(struct tda998x_priv *priv, uint8_t *buf, int blk)
static int read_edid_block(void *data, u8 *buf, unsigned int blk, size_t length)
{
{
	struct tda998x_priv *priv = data;
	uint8_t offset, segptr;
	uint8_t offset, segptr;
	int ret, i;
	int ret, i;


@@ -1080,8 +1082,8 @@ static int read_edid_block(struct tda998x_priv *priv, uint8_t *buf, int blk)
		return -ETIMEDOUT;
		return -ETIMEDOUT;
	}
	}


	ret = reg_read_range(priv, REG_EDID_DATA_0, buf, EDID_LENGTH);
	ret = reg_read_range(priv, REG_EDID_DATA_0, buf, length);
	if (ret != EDID_LENGTH) {
	if (ret != length) {
		dev_err(&priv->hdmi->dev, "failed to read edid block %d: %d\n",
		dev_err(&priv->hdmi->dev, "failed to read edid block %d: %d\n",
			blk, ret);
			blk, ret);
		return ret;
		return ret;
@@ -1090,81 +1092,30 @@ static int read_edid_block(struct tda998x_priv *priv, uint8_t *buf, int blk)
	return 0;
	return 0;
}
}


static uint8_t *do_get_edid(struct tda998x_priv *priv)
static int
tda998x_encoder_get_modes(struct tda998x_priv *priv,
			  struct drm_connector *connector)
{
{
	int j, valid_extensions = 0;
	struct edid *edid;
	uint8_t *block, *new;
	int n;
	bool print_bad_edid = drm_debug & DRM_UT_KMS;

	if ((block = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
		return NULL;


	if (priv->rev == TDA19988)
	if (priv->rev == TDA19988)
		reg_clear(priv, REG_TX4, TX4_PD_RAM);
		reg_clear(priv, REG_TX4, TX4_PD_RAM);


	/* base block fetch */
	edid = drm_do_get_edid(connector, read_edid_block, priv);
	if (read_edid_block(priv, block, 0))
		goto fail;

	if (!drm_edid_block_valid(block, 0, print_bad_edid))
		goto fail;

	/* if there's no extensions, we're done */
	if (block[0x7e] == 0)
		goto done;

	new = krealloc(block, (block[0x7e] + 1) * EDID_LENGTH, GFP_KERNEL);
	if (!new)
		goto fail;
	block = new;

	for (j = 1; j <= block[0x7e]; j++) {
		uint8_t *ext_block = block + (valid_extensions + 1) * EDID_LENGTH;
		if (read_edid_block(priv, ext_block, j))
			goto fail;

		if (!drm_edid_block_valid(ext_block, j, print_bad_edid))
			goto fail;

		valid_extensions++;
	}

	if (valid_extensions != block[0x7e]) {
		block[EDID_LENGTH-1] += block[0x7e] - valid_extensions;
		block[0x7e] = valid_extensions;
		new = krealloc(block, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
		if (!new)
			goto fail;
		block = new;
	}


done:
	if (priv->rev == TDA19988)
	if (priv->rev == TDA19988)
		reg_set(priv, REG_TX4, TX4_PD_RAM);
		reg_set(priv, REG_TX4, TX4_PD_RAM);


	return block;
	if (!edid) {

fail:
	if (priv->rev == TDA19988)
		reg_set(priv, REG_TX4, TX4_PD_RAM);
		dev_warn(&priv->hdmi->dev, "failed to read EDID\n");
		dev_warn(&priv->hdmi->dev, "failed to read EDID\n");
	kfree(block);
		return 0;
	return NULL;
	}
	}


static int
tda998x_encoder_get_modes(struct tda998x_priv *priv,
			  struct drm_connector *connector)
{
	struct edid *edid = (struct edid *)do_get_edid(priv);
	int n = 0;

	if (edid) {
	drm_mode_connector_update_edid_property(connector, edid);
	drm_mode_connector_update_edid_property(connector, edid);
	n = drm_add_edid_modes(connector, edid);
	n = drm_add_edid_modes(connector, edid);
	priv->is_hdmi_sink = drm_detect_hdmi_monitor(edid);
	priv->is_hdmi_sink = drm_detect_hdmi_monitor(edid);
	kfree(edid);
	kfree(edid);
	}


	return n;
	return n;
}
}
@@ -1547,6 +1498,7 @@ static int tda998x_bind(struct device *dev, struct device *master, void *data)
	struct i2c_client *client = to_i2c_client(dev);
	struct i2c_client *client = to_i2c_client(dev);
	struct drm_device *drm = data;
	struct drm_device *drm = data;
	struct tda998x_priv2 *priv;
	struct tda998x_priv2 *priv;
	uint32_t crtcs = 0;
	int ret;
	int ret;


	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -1555,9 +1507,18 @@ static int tda998x_bind(struct device *dev, struct device *master, void *data)


	dev_set_drvdata(dev, priv);
	dev_set_drvdata(dev, priv);


	if (dev->of_node)
		crtcs = drm_of_find_possible_crtcs(drm, dev->of_node);

	/* If no CRTCs were found, fall back to our old behaviour */
	if (crtcs == 0) {
		dev_warn(dev, "Falling back to first CRTC\n");
		crtcs = 1 << 0;
	}

	priv->base.encoder = &priv->encoder;
	priv->base.encoder = &priv->encoder;
	priv->connector.interlace_allowed = 1;
	priv->connector.interlace_allowed = 1;
	priv->encoder.possible_crtcs = 1 << 0;
	priv->encoder.possible_crtcs = crtcs;


	ret = tda998x_create(client, &priv->base);
	ret = tda998x_create(client, &priv->base);
	if (ret)
	if (ret)