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

Commit be2068bf authored by Jean-Michel Hautbois's avatar Jean-Michel Hautbois Committed by Mauro Carvalho Chehab
Browse files

media: adv7604: Add support for i2c_new_secondary_device



The ADV7604 has thirteen 256-byte maps that can be accessed via the main
I2C ports. Each map has it own I2C address and acts as a standard slave
device on the I2C bus.

Allow a device tree node to override the default addresses so that
address conflicts with other devices on the same bus may be resolved at
the board description level.

[Kieran: Re-adapted for mainline]

Signed-off-by: default avatarJean-Michel Hautbois <jean-michel.hautbois@vodalys.com>
Signed-off-by: default avatarKieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Reviewed-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 9feb7868
Loading
Loading
Loading
Loading
+40 −22
Original line number Diff line number Diff line
@@ -2722,6 +2722,27 @@ static const struct v4l2_ctrl_config adv76xx_ctrl_free_run_color = {

/* ----------------------------------------------------------------------- */

struct adv76xx_register_map {
	const char *name;
	u8 default_addr;
};

static const struct adv76xx_register_map adv76xx_default_addresses[] = {
	[ADV76XX_PAGE_IO] = { "main", 0x4c },
	[ADV7604_PAGE_AVLINK] = { "avlink", 0x42 },
	[ADV76XX_PAGE_CEC] = { "cec", 0x40 },
	[ADV76XX_PAGE_INFOFRAME] = { "infoframe", 0x3e },
	[ADV7604_PAGE_ESDP] = { "esdp", 0x38 },
	[ADV7604_PAGE_DPP] = { "dpp", 0x3c },
	[ADV76XX_PAGE_AFE] = { "afe", 0x26 },
	[ADV76XX_PAGE_REP] = { "rep", 0x32 },
	[ADV76XX_PAGE_EDID] = { "edid", 0x36 },
	[ADV76XX_PAGE_HDMI] = { "hdmi", 0x34 },
	[ADV76XX_PAGE_TEST] = { "test", 0x30 },
	[ADV76XX_PAGE_CP] = { "cp", 0x22 },
	[ADV7604_PAGE_VDP] = { "vdp", 0x24 },
};

static int adv76xx_core_init(struct v4l2_subdev *sd)
{
	struct adv76xx_state *state = to_state(sd);
@@ -2822,13 +2843,26 @@ static void adv76xx_unregister_clients(struct adv76xx_state *state)
}

static struct i2c_client *adv76xx_dummy_client(struct v4l2_subdev *sd,
							u8 addr, u8 io_reg)
					       unsigned int page)
{
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	struct adv76xx_state *state = to_state(sd);
	struct adv76xx_platform_data *pdata = &state->pdata;
	unsigned int io_reg = 0xf2 + page;
	struct i2c_client *new_client;

	if (pdata && pdata->i2c_addresses[page])
		new_client = i2c_new_dummy(client->adapter,
					   pdata->i2c_addresses[page]);
	else
		new_client = i2c_new_secondary_device(client,
				adv76xx_default_addresses[page].name,
				adv76xx_default_addresses[page].default_addr);

	if (addr)
		io_write(sd, io_reg, addr << 1);
	return i2c_new_dummy(client->adapter, io_read(sd, io_reg) >> 1);
	if (new_client)
		io_write(sd, io_reg, new_client->addr << 1);

	return new_client;
}

static const struct adv76xx_reg_seq adv7604_recommended_settings_afe[] = {
@@ -3103,20 +3137,6 @@ static int adv76xx_parse_dt(struct adv76xx_state *state)
	/* Disable the interrupt for now as no DT-based board uses it. */
	state->pdata.int1_config = ADV76XX_INT1_CONFIG_DISABLED;

	/* Use the default I2C addresses. */
	state->pdata.i2c_addresses[ADV7604_PAGE_AVLINK] = 0x42;
	state->pdata.i2c_addresses[ADV76XX_PAGE_CEC] = 0x40;
	state->pdata.i2c_addresses[ADV76XX_PAGE_INFOFRAME] = 0x3e;
	state->pdata.i2c_addresses[ADV7604_PAGE_ESDP] = 0x38;
	state->pdata.i2c_addresses[ADV7604_PAGE_DPP] = 0x3c;
	state->pdata.i2c_addresses[ADV76XX_PAGE_AFE] = 0x26;
	state->pdata.i2c_addresses[ADV76XX_PAGE_REP] = 0x32;
	state->pdata.i2c_addresses[ADV76XX_PAGE_EDID] = 0x36;
	state->pdata.i2c_addresses[ADV76XX_PAGE_HDMI] = 0x34;
	state->pdata.i2c_addresses[ADV76XX_PAGE_TEST] = 0x30;
	state->pdata.i2c_addresses[ADV76XX_PAGE_CP] = 0x22;
	state->pdata.i2c_addresses[ADV7604_PAGE_VDP] = 0x24;

	/* Hardcode the remaining platform data fields. */
	state->pdata.disable_pwrdnb = 0;
	state->pdata.disable_cable_det_rst = 0;
@@ -3466,11 +3486,9 @@ static int adv76xx_probe(struct i2c_client *client,
		if (!(BIT(i) & state->info->page_mask))
			continue;

		state->i2c_clients[i] =
			adv76xx_dummy_client(sd, state->pdata.i2c_addresses[i],
					     0xf2 + i);
		state->i2c_clients[i] = adv76xx_dummy_client(sd, i);
		if (!state->i2c_clients[i]) {
			err = -ENOMEM;
			err = -EINVAL;
			v4l2_err(sd, "failed to create i2c client %u\n", i);
			goto err_i2c;
		}