From patchwork Mon Oct 2 13:28:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Todor Tomov X-Patchwork-Id: 114613 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp692209qgn; Mon, 2 Oct 2017 06:38:52 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAxtEA34k6T7mew7onVCDUcdSMEDpXY6nn8bpXeGcpCHNJ5VzZd4/f5wHe6hT2DqTurYEtB X-Received: by 10.98.246.24 with SMTP id x24mr4158755pfh.223.1506951532026; Mon, 02 Oct 2017 06:38:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506951532; cv=none; d=google.com; s=arc-20160816; b=ly+WLJl1bFBqRPMwYh8jDhezTOlD3hnLk+z9TS/BBNkhpLrHjHVIljHKxs1cBA2Ohi fSHCaGNxTTNa0Q+GJLXrQ6hIvdN3ZuAplbGS3eINLYjPsbTuUos1dcP1OO3UnnQXBGqi uVeQOVA9TIwHAryLFsGvgPlB19w9pB32WglYPQ4AUEH0lCKUsyX+3xVNUI3HRyAYDo5E eWs6FtzemiHQi9IDUrau9IJK4xQ8+KSyxxlSB3AyNgeS6f1DzAijQlruktHFugEKZ3O+ /fa2TZ6jxtHgHuEgz36bDv9W6EYUy5pWccts1BAVevLquNdiqzG8RzG4lp/WmsOi52s7 vM6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=G3lz/8sOvj6CozBmQ8NBX6wYhmYVVqoO43JwQ1wEXQU=; b=WiyIIFtO2vyGc4Dj/6LmmCznbmS61C2ySiH4tmhTUya1tHaMRnXcLcg+r9JXa1Kd2Z mLE+4BRS4Q2BCpVQKhquyAkY/Al5Qo/jzkgcu3/nrQeTmKcwnLvzEP8hrTDrzjqqX3D4 c1Xs97a01YjgW6OoGr4MS/u5XDmGPP/ulsEl07L40GfaQoKjmXrhrnZEa+qswndRYPvi tTzDAEmOCJ79YOVt5diktY7KzM8/WcKjyyCxCBDOa0AyG0W9BLmAHs2PubeApZgpFAN5 dmTgv2XWLQ0cRqgPHlgXgA8b/64HlFGB4N2CtBnTEpAFkBapPshKQ8GO+9dxs0i+Fd41 ifxg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si2993200pgr.464.2017.10.02.06.38.51; Mon, 02 Oct 2017 06:38:52 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751241AbdJBNit (ORCPT + 26 others); Mon, 2 Oct 2017 09:38:49 -0400 Received: from ns.mm-sol.com ([37.157.136.199]:57254 "EHLO extserv.mm-sol.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751036AbdJBNir (ORCPT ); Mon, 2 Oct 2017 09:38:47 -0400 X-Greylist: delayed 574 seconds by postgrey-1.27 at vger.kernel.org; Mon, 02 Oct 2017 09:38:47 EDT Received: from mms-0439.qualcomm.mm-sol.com (unknown [37.157.136.206]) by extserv.mm-sol.com (Postfix) with ESMTPSA id 49559CC24; Mon, 2 Oct 2017 16:29:12 +0300 (EEST) From: Todor Tomov To: mchehab@kernel.org, sakari.ailus@linux.intel.com, hansverk@cisco.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Todor Tomov Subject: [PATCH] [media] ov5645: I2C address change Date: Mon, 2 Oct 2017 16:28:45 +0300 Message-Id: <1506950925-13924-1-git-send-email-todor.tomov@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As soon as the sensor is powered on, change the I2C address to the one specified in DT. This allows to use multiple physical sensors connected to the same I2C bus. Signed-off-by: Todor Tomov --- drivers/media/i2c/ov5645.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) -- 2.7.4 diff --git a/drivers/media/i2c/ov5645.c b/drivers/media/i2c/ov5645.c index d28845f..8541109 100644 --- a/drivers/media/i2c/ov5645.c +++ b/drivers/media/i2c/ov5645.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,8 @@ #include #include +static DEFINE_MUTEX(ov5645_lock); + #define OV5645_VOLTAGE_ANALOG 2800000 #define OV5645_VOLTAGE_DIGITAL_CORE 1500000 #define OV5645_VOLTAGE_DIGITAL_IO 1800000 @@ -590,6 +593,31 @@ static void ov5645_regulators_disable(struct ov5645 *ov5645) dev_err(ov5645->dev, "io regulator disable failed\n"); } +static int ov5645_write_reg_to(struct ov5645 *ov5645, u16 reg, u8 val, + u16 i2c_addr) +{ + u8 regbuf[3] = { + reg >> 8, + reg & 0xff, + val + }; + struct i2c_msg msgs = { + .addr = i2c_addr, + .flags = 0, + .len = 3, + .buf = regbuf + }; + int ret; + + ret = i2c_transfer(ov5645->i2c_client->adapter, &msgs, 1); + if (ret < 0) + dev_err(ov5645->dev, + "%s: write reg error %d on addr 0x%x: reg=0x%x, val=0x%x\n", + __func__, ret, i2c_addr, reg, val); + + return ret; +} + static int ov5645_write_reg(struct ov5645 *ov5645, u16 reg, u8 val) { u8 regbuf[3]; @@ -729,10 +757,24 @@ static int ov5645_s_power(struct v4l2_subdev *sd, int on) */ if (ov5645->power_count == !on) { if (on) { + mutex_lock(&ov5645_lock); + ret = ov5645_set_power_on(ov5645); if (ret < 0) goto exit; + ret = ov5645_write_reg_to(ov5645, 0x3100, + ov5645->i2c_client->addr, 0x78); + if (ret < 0) { + dev_err(ov5645->dev, + "could not change i2c address\n"); + ov5645_set_power_off(ov5645); + mutex_unlock(&ov5645_lock); + goto exit; + } + + mutex_unlock(&ov5645_lock); + ret = ov5645_set_register_array(ov5645, ov5645_global_init_setting, ARRAY_SIZE(ov5645_global_init_setting));