Received: by 10.223.185.116 with SMTP id b49csp2687896wrg; Mon, 12 Feb 2018 14:10:21 -0800 (PST) X-Google-Smtp-Source: AH8x225tcgGE/9A7QJReBxjks/IZ6+1U+I54Z9dBXQBToGUaCJHHvt8BI7q3/3A5zqogdF69ij+S X-Received: by 10.98.79.65 with SMTP id d62mr13102389pfb.138.1518473421530; Mon, 12 Feb 2018 14:10:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518473421; cv=none; d=google.com; s=arc-20160816; b=C+b7IsuKt5Gs/7ZrImUQesLyBwwZt0Pf1vboqsm8Px4+uvZpVVwg+em63t7X722vA5 WcRi9WBA5PAG5qyDAKy/ujuOfk4iQVlUhpUsDyIiUgl7aelFKEJuwZtsyt9/TKyfmBbG y7Qz+xswFlelY9xcPbnineEuXmiT0Opcux8XgVNrBiXJypWX88INfk1CDbFcMuJMra7c Psv18LyHXBzDb6D8cQZtIAO+SNlq7DqPJY9lDFtb1JCB53EuUyCwRY0bo49Yqrc/BUJ5 oA/X1lMtqtBwOQAoJ+mfWYx8X7rMpE+kZrmMHUuT+1PfsY1yoV+n5VgXoXUaQLSJhwJ2 6HPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dmarc-filter:arc-authentication-results; bh=F1pkyauWBmAyAoA6/u+npUe/IOzCbsfBDHxMjF0DP7o=; b=m12aiQX85QSLQKaETOQjvdmn3qMVXS/VuNBXQazrHCOpSMlZaDWcpA348xKwq6zAXp fIj20cUGhHHITB5C/FnnipkUXaqcUeuK4k713WWw6Ppqdneo5XOZTCANjCLKvmY3zkAe OIgLU+P6mMscA3NQlWnxNmibgEqySk5/Wgb/aRe2CofvJj3QenQXf894c/QbQZElT7S7 i9arMAmS+PYB4Q7bNms51CntJUV9ZE3BqUS5swZtb3484+mEtwzuqJunH+T5ybK0NK9c FPQEY+ddjlHfJ1eSvawe/hfo6GB82PEOlTTfzM05XKl3NP6oPNriPrAP+JQ6nPGarHrC R7mg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m25si473402pge.363.2018.02.12.14.10.06; Mon, 12 Feb 2018 14:10:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932805AbeBLWI5 (ORCPT + 99 others); Mon, 12 Feb 2018 17:08:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:59072 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932562AbeBLWIT (ORCPT ); Mon, 12 Feb 2018 17:08:19 -0500 Received: from localhost.localdomain (cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 06428217AE; Mon, 12 Feb 2018 22:08:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06428217AE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=kbingham@kernel.org From: Kieran Bingham To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org Cc: Kieran Bingham , Jean-Michel Hautbois , Sergei Shtylyov , Lars-Peter Clausen , Kieran Bingham , Hans Verkuil , Mauro Carvalho Chehab Subject: [PATCH v3 4/5] media: adv7604: Add support for i2c_new_secondary_device Date: Mon, 12 Feb 2018 22:07:52 +0000 Message-Id: <1518473273-6333-5-git-send-email-kbingham@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518473273-6333-1-git-send-email-kbingham@kernel.org> References: <1518473273-6333-1-git-send-email-kbingham@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jean-Michel Hautbois The ADV7604 has thirteen 256-byte maps that can be accessed via the main I²C ports. Each map has it own I²C address and acts as a standard slave device on the I²C 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. Signed-off-by: Jean-Michel Hautbois [Kieran: Re-adapted for mainline] Signed-off-by: Kieran Bingham --- Based upon the original posting : https://lkml.org/lkml/2014/10/22/469 v2: - Split out DT bindings from driver updates - Return -EINVAL on error paths from adv76xx_dummy_client() drivers/media/i2c/adv7604.c | 62 +++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c index 1544920ec52d..872e124793f8 100644 --- a/drivers/media/i2c/adv7604.c +++ b/drivers/media/i2c/adv7604.c @@ -2734,6 +2734,27 @@ static const struct v4l2_ctrl_config adv76xx_ctrl_free_run_color = { /* ----------------------------------------------------------------------- */ +struct adv76xx_register { + const char *name; + u8 default_addr; +}; + +static const struct adv76xx_register adv76xx_secondary_names[] = { + [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); @@ -2834,13 +2855,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 i) { 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 + i; + struct i2c_client *new_client; + + if (pdata && pdata->i2c_addresses[i]) + new_client = i2c_new_dummy(client->adapter, + pdata->i2c_addresses[i]); + else + new_client = i2c_new_secondary_device(client, + adv76xx_secondary_names[i].name, + adv76xx_secondary_names[i].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[] = { @@ -3115,20 +3149,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; @@ -3478,11 +3498,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; } -- 2.7.4