From patchwork Sun Feb 25 12:31:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scheller X-Patchwork-Id: 10240857 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 4C145603B4 for ; Sun, 25 Feb 2018 12:32:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F57E29CBE for ; Sun, 25 Feb 2018 12:32:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 341D429CE4; Sun, 25 Feb 2018 12:32:04 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, 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 C578B29CBE for ; Sun, 25 Feb 2018 12:32:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751800AbeBYMcB (ORCPT ); Sun, 25 Feb 2018 07:32:01 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:50491 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751784AbeBYMbx (ORCPT ); Sun, 25 Feb 2018 07:31:53 -0500 Received: by mail-wm0-f67.google.com with SMTP id w128so6525479wmw.0 for ; Sun, 25 Feb 2018 04:31:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=mwSt0UuXMqW/muw5W4kkwEmf+aYExwnlG8bFS0VLyIo=; b=u92TxGgCZbrlmflpwjWrN/prCmb5IcBdcLW40R9tBinp16ZH++p6mvfse0ICchlAoE 3a5Ph1Qqj8R2Wyq0TuN7s5LxiNgJd2JO5WVz3WDN22F44und+qRDPwK+6TNpezu8IP5B emn3ZV3kqqSfOvfvS7EMXOW4cSXthLsabl0smnBk+idhDDdjl5Ixqdv+8K9kB1ShUawa lYmmJftwUBSGw3T4rDzOlKaI/FMjQLDwoIXmfhk1fwteCjTdUXKajkdFFOOrcyaQzOA2 VpBGiq5z2k809wtiukrfspKiQaANZ4I30kYj5mzVUFSQhpvFQ47G3e6zAh6YLAh15urM bigg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=mwSt0UuXMqW/muw5W4kkwEmf+aYExwnlG8bFS0VLyIo=; b=ac3EpjgCFgZ/ovOOF7cs3KW0+EggkFA10RZ5tx2Y/fW/6jfFfX4qNwpGkEWUZDExyC VVVs/yRc3B2BmZujUAOp0L9Rc1Ddk9EKpRT88ogRlz5jLE4dRLecWtjaq4tBn63hT/5Q mh6erdP2HNo983qu20vAxcYvstxSSEdollFSQffInjekBiHAaeDUwwkOpE3myHsHCZJs ocppCHVhMZZWADJ1hz1lkTl3HzyDsyq2rKNV0T5YJAfWRrKN4oUyy9ywYUnxmQI9V1kx tSpwNrB1DsS9iTYbO3D/jSE95oGsUranIue5HEOBBxvMNBAxbCvnFrOctj/Vp5AZvtyN rMaA== X-Gm-Message-State: APf1xPBBx0DTFOqosySA715s3UoUFfWndz6DVFO8+xU+wiCnMXRlxiVn QMPsVz1Jj3iZ1Pd8HNSTVJKdKw== X-Google-Smtp-Source: AH8x224bpZ60SJS2g0dq1caKPDm40hGic4lO1c7WRGmfaX5y7MSbkCYSqZffm3S6kkHZb+f5gmH+KQ== X-Received: by 10.28.208.70 with SMTP id h67mr6518572wmg.95.1519561912069; Sun, 25 Feb 2018 04:31:52 -0800 (PST) Received: from dvbdev.wuest.de (ip-84-118-193-200.unity-media.net. [84.118.193.200]) by smtp.gmail.com with ESMTPSA id y34sm15304779wry.19.2018.02.25.04.31.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Feb 2018 04:31:51 -0800 (PST) From: Daniel Scheller To: linux-media@vger.kernel.org, mchehab@kernel.org, mchehab@s-opensource.com Subject: [PATCH v2 09/12] [media] ngene: check for CXD2099AR presence before attaching Date: Sun, 25 Feb 2018 13:31:37 +0100 Message-Id: <20180225123140.19486-10-d.scheller.oss@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180225123140.19486-1-d.scheller.oss@gmail.com> References: <20180225123140.19486-1-d.scheller.oss@gmail.com> 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 From: Daniel Scheller Currently, if there's no CXD2099AR attached to any expansion connector of the ngene hardware, it will complain with this on every module load: cxd2099 1-0040: No CXD2099AR detected at 0x40 cxd2099: probe of 1-0040 failed with error -5 ngene 0000:02:00.0: CXD2099AR attach failed This happens due to the logic assuming such hardware is always there and blindly tries to attach the cxd2099 I2C driver. Rather add a probe function (in ngene-cards.c with a prototype in ngene.h) to check for the existence of such hardware before probing, and don't try further if no CXD2099 was found. Signed-off-by: Daniel Scheller --- drivers/media/pci/ngene/ngene-cards.c | 19 +++++++++++++++++++ drivers/media/pci/ngene/ngene-core.c | 14 ++++++++++++++ drivers/media/pci/ngene/ngene.h | 3 +++ 3 files changed, 36 insertions(+) diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c index dff55c7c9f86..d603d0af703e 100644 --- a/drivers/media/pci/ngene/ngene-cards.c +++ b/drivers/media/pci/ngene/ngene-cards.c @@ -505,6 +505,25 @@ static int port_has_stv0367(struct i2c_adapter *i2c) return 1; } +int ngene_port_has_cxd2099(struct i2c_adapter *i2c, u8 *type) +{ + u8 val; + u8 probe[4] = { 0xe0, 0x00, 0x00, 0x00 }, data[4]; + struct i2c_msg msgs[2] = {{ .addr = 0x40, .flags = 0, + .buf = probe, .len = 4 }, + { .addr = 0x40, .flags = I2C_M_RD, + .buf = data, .len = 4 } }; + val = i2c_transfer(i2c, msgs, 2); + if (val != 2) + return 0; + + if (data[0] == 0x02 && data[1] == 0x2b && data[3] == 0x43) + *type = 2; + else + *type = 1; + return 1; +} + static int demod_attach_drxk(struct ngene_channel *chan, struct i2c_adapter *i2c) { diff --git a/drivers/media/pci/ngene/ngene-core.c b/drivers/media/pci/ngene/ngene-core.c index 526d0adfa427..f69a8fc1ec2a 100644 --- a/drivers/media/pci/ngene/ngene-core.c +++ b/drivers/media/pci/ngene/ngene-core.c @@ -1589,6 +1589,20 @@ static void cxd_attach(struct ngene *dev) .addr = 0x40, .platform_data = &cxd_cfg, }; + int ret; + u8 type; + + /* check for CXD2099AR presence before attaching */ + ret = ngene_port_has_cxd2099(&dev->channel[0].i2c_adapter, &type); + if (!ret) { + dev_dbg(pdev, "No CXD2099AR found\n"); + return; + } + + if (type != 1) { + dev_warn(pdev, "CXD2099AR is uninitialized!\n"); + return; + } cxd_cfg.en = &ci->en; diff --git a/drivers/media/pci/ngene/ngene.h b/drivers/media/pci/ngene/ngene.h index 72195f6552b3..66d8eaa28549 100644 --- a/drivers/media/pci/ngene/ngene.h +++ b/drivers/media/pci/ngene/ngene.h @@ -909,6 +909,9 @@ int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level); void set_transfer(struct ngene_channel *chan, int state); void FillTSBuffer(void *Buffer, int Length, u32 Flags); +/* Provided by ngene-cards.c */ +int ngene_port_has_cxd2099(struct i2c_adapter *i2c, u8 *type); + /* Provided by ngene-i2c.c */ int ngene_i2c_init(struct ngene *dev, int dev_nr);