From patchwork Thu Nov 16 13:41:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugues FRUCHET X-Patchwork-Id: 10061179 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 170A8604D3 for ; Thu, 16 Nov 2017 13:42:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08DAE29A33 for ; Thu, 16 Nov 2017 13:42:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1E232AA49; Thu, 16 Nov 2017 13:42:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94A8529A33 for ; Thu, 16 Nov 2017 13:42:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934999AbdKPNmV (ORCPT ); Thu, 16 Nov 2017 08:42:21 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:52687 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934991AbdKPNmQ (ORCPT ); Thu, 16 Nov 2017 08:42:16 -0500 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAGDdLG5019651; Thu, 16 Nov 2017 14:42:13 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2e9bgf02y0-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 16 Nov 2017 14:42:13 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 704BA31; Thu, 16 Nov 2017 13:42:12 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas23.st.com [10.75.90.46]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 4E0CE298C; Thu, 16 Nov 2017 13:42:12 +0000 (GMT) Received: from SAFEX1HUBCAS22.st.com (10.75.90.93) by SAFEX1HUBCAS23.st.com (10.75.90.46) with Microsoft SMTP Server (TLS) id 14.3.352.0; Thu, 16 Nov 2017 14:42:12 +0100 Received: from localhost (10.201.23.73) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.352.0; Thu, 16 Nov 2017 14:42:11 +0100 From: Hugues Fruchet To: Steve Longerbeam , Hans Verkuil , Mauro Carvalho Chehab CC: , Hugues Fruchet , Benjamin Gaignard Subject: [PATCH v1 2/4] media: ov5640: check chip id Date: Thu, 16 Nov 2017 14:41:40 +0100 Message-ID: <1510839702-2454-3-git-send-email-hugues.fruchet@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1510839702-2454-1-git-send-email-hugues.fruchet@st.com> References: <1510839702-2454-1-git-send-email-hugues.fruchet@st.com> MIME-Version: 1.0 X-Originating-IP: [10.201.23.73] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-16_05:, , signatures=0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Verify that chip identifier is correct before starting streaming Signed-off-by: Hugues Fruchet --- drivers/media/i2c/ov5640.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c index 61071f5..a576d11 100644 --- a/drivers/media/i2c/ov5640.c +++ b/drivers/media/i2c/ov5640.c @@ -34,7 +34,8 @@ #define OV5640_DEFAULT_SLAVE_ID 0x3c -#define OV5640_REG_CHIP_ID 0x300a +#define OV5640_REG_CHIP_ID_HIGH 0x300a +#define OV5640_REG_CHIP_ID_LOW 0x300b #define OV5640_REG_PAD_OUTPUT00 0x3019 #define OV5640_REG_SC_PLL_CTRL0 0x3034 #define OV5640_REG_SC_PLL_CTRL1 0x3035 @@ -926,6 +927,29 @@ static int ov5640_load_regs(struct ov5640_dev *sensor, return ret; } +static int ov5640_check_chip_id(struct ov5640_dev *sensor) +{ + struct i2c_client *client = sensor->i2c_client; + int ret; + u8 chip_id_h, chip_id_l; + + ret = ov5640_read_reg(sensor, OV5640_REG_CHIP_ID_HIGH, &chip_id_h); + if (ret) + return ret; + + ret = ov5640_read_reg(sensor, OV5640_REG_CHIP_ID_LOW, &chip_id_l); + if (ret) + return ret; + + if (!(chip_id_h == 0x56 && chip_id_l == 0x40)) { + dev_err(&client->dev, "%s: wrong chip identifier, expected 0x5640, got 0x%x%x\n", + __func__, chip_id_h, chip_id_l); + return -EINVAL; + } + + return 0; +} + /* read exposure, in number of line periods */ static int ov5640_get_exposure(struct ov5640_dev *sensor) { @@ -1562,6 +1586,10 @@ static int ov5640_set_power(struct ov5640_dev *sensor, bool on) ov5640_reset(sensor); ov5640_power(sensor, true); + ret = ov5640_check_chip_id(sensor); + if (ret) + goto power_off; + ret = ov5640_init_slave_id(sensor); if (ret) goto power_off;