Received: by 10.223.185.116 with SMTP id b49csp3925872wrg; Tue, 13 Feb 2018 09:51:39 -0800 (PST) X-Google-Smtp-Source: AH8x226XL6PwMrQmz3NP5OM801Lo4GRknsXrHlxtLuwunkMG/DEy+h/0LKejg3mgix8KNCMRRjYf X-Received: by 10.101.99.133 with SMTP id h5mr1546472pgv.381.1518544299433; Tue, 13 Feb 2018 09:51:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518544299; cv=none; d=google.com; s=arc-20160816; b=AmaFuGKusBUbbBK4jzhRSvqCOamj9Mxz4gT22+x0SFVaWCyVNW7z/zSMIQ6miWvu94 7o8Nl3Zr6TjBg4iB62T/F9wWUbW7HYI0/fASt0nvYBZ+9j1kV9qYh8rMcA9aAdGdF0xH 35+yqgLjLbidz5yAQwOUJoP1cZg3nJgwsEkfq7UPIrBDeMrF1XCWlntm6eDCJhtv1EtQ TueVEvvCokKXqhuVF3G0HkvJbmVbDmtkkjwLDcYMgdlh+f9IK6s3C3Ok9prSufIAi+Lj HMox1Wl0+B1AzIcsNAJhyusLl3yMt5CrQ9ZQ5Q+2JEtDkHDK+bxkrkRb1pGbs9F0UoTj spUQ== 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=Kh7AK4w2aixFclkPB/nTO27w9DryHdb2rNF1gJH76i0=; b=F9FMVrhFKlkQ1hlToEZGBpBdPFgAD9AYVi7CQNFVztSOsn+bQOlbeXJSJiaMha2QJ7 yatekJRsBawdoQNIXjF/L78ZZCgVyqc6qV++gDYtv2fcdM75ax4jKRf3D0aPEp3fbEFh B2q24hW14cEwhqRlAdupW3LixMrlJO8Lw+yzWqqoK2mhK0BLjfWHzgn2m3mBfHh9Saey QC/VXHZBl3zdpg3jjLW/lL+kKJOGDFjieHcm1q3pevuDDDcTXb3DNs1+d46YAJ3JGs5h K7IK8d/hcQKOJD42T+P/+VzUuatw46onEGJwnIj3PIsIrauD1WALRkp8ZcC2KfmO6ON3 Q33Q== 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 x88si1485751pfj.307.2018.02.13.09.51.24; Tue, 13 Feb 2018 09:51:39 -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 S965508AbeBMRuS (ORCPT + 99 others); Tue, 13 Feb 2018 12:50:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:42350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965333AbeBMRtL (ORCPT ); Tue, 13 Feb 2018 12:49:11 -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 C6389217C7; Tue, 13 Feb 2018 17:49:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C6389217C7 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-kernel@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-renesas-soc@vger.kernel.org Cc: Kieran Bingham , Jean-Michel Hautbois , Sergei Shtylyov , Lars-Peter Clausen , Kieran Bingham Subject: [PATCH v4 4/5] media: adv7604: Add support for i2c_new_secondary_device Date: Tue, 13 Feb 2018 17:48:56 +0000 Message-Id: <1518544137-2742-5-git-send-email-kbingham@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518544137-2742-1-git-send-email-kbingham@kernel.org> References: <1518544137-2742-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 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. Signed-off-by: Jean-Michel Hautbois [Kieran: Re-adapted for mainline] Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- 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() v3: - No change v4: - s/struct adv76xx_register/struct adv76xx_register_map/ - s/adv76xx_secondary_names/adv76xx_default_addresses/ - Normalise I2C usage (s/I²C/I2C/) 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..d52c624a2970 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_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); @@ -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 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[] = { @@ -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