From patchwork Mon Sep 29 07:44:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olli Salonen X-Patchwork-Id: 26184 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1XYVe5-0007cm-Do; Mon, 29 Sep 2014 09:45:21 +0200 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.72/mailfrontend-8) with esmtp id 1XYVe3-0000mS-kJ; Mon, 29 Sep 2014 09:45:21 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751815AbaI2HpQ (ORCPT + 1 other); Mon, 29 Sep 2014 03:45:16 -0400 Received: from mail-lb0-f171.google.com ([209.85.217.171]:53870 "EHLO mail-lb0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751714AbaI2HpP (ORCPT ); Mon, 29 Sep 2014 03:45:15 -0400 Received: by mail-lb0-f171.google.com with SMTP id l4so17352475lbv.16 for ; Mon, 29 Sep 2014 00:45:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=PqaKJqovEEITEBOW0wpGYtXUWzRKddAP07rfr4ikjoQ=; b=kIKDRLG4qyWvlT0aFNB4PWPBD6Djrs1drCrS7Zx4Po9Gniul/gjMCFNvio/LxmHf4n gXq/PL6j2XNJnkKZH+fFTeHm7JliI0NCu1zntDufC3om98hlLxOcgPWEnW8wmuAH+K1R TvIM/HQxX5xrfKveEE+yA/E0Wty+gqpBUYNW2L/pxT2Y69vO10jbrczcrBs8x6WQxAk2 dp9YuVO6QfugIzpnWxsOqtliiAIFEus66ECn8rAGkcMMgacLDxbWizaVOlOzCbV93oPD 0/mZHYDXwD/fv8Shm08vbmLpPTxaqisYrqEbWCEc1FJCDZ6dGgvdTvfeDUgvmBSJtbnC hJjA== X-Gm-Message-State: ALoCoQkSXbL/fZ4HzZTUUGaRLRYKbKBIT+cIMXPtiXAdSDw/jwj4BpFORZsu5JmLg0TE0+dp8MPO X-Received: by 10.112.125.132 with SMTP id mq4mr1103073lbb.103.1411976713819; Mon, 29 Sep 2014 00:45:13 -0700 (PDT) Received: from devlin.trsqr.net (dsl-espbrasgw1-54f9ca-144.dhcp.inet.fi. [84.249.202.144]) by mx.google.com with ESMTPSA id o4sm4556112lao.32.2014.09.29.00.45.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Sep 2014 00:45:13 -0700 (PDT) From: Olli Salonen To: linux-media@vger.kernel.org Cc: Olli Salonen Subject: [PATCH 5/5] cx23855: add CI support for DVBSky T980C Date: Mon, 29 Sep 2014 10:44:20 +0300 Message-Id: <1411976660-19329-5-git-send-email-olli.salonen@iki.fi> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1411976660-19329-1-git-send-email-olli.salonen@iki.fi> References: <1411976660-19329-1-git-send-email-olli.salonen@iki.fi> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2014.9.29.73319 X-PMX-Spam: Gauge=X, Probability=10%, Report=' HASHBUSTER_BLOCK_V2 0.5, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_4000_4999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __DATE_TZ_RU 0, __HASHBUSTER_BLOCK_V2_1 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS , __YOUTUBE_RCVD 0' Add CI support for DVBSky T980C. I used the new host device independent CIMaX SP2 I2C driver to implement it. cx23885_sp2_ci_ctrl function is borrowed entirely from cimax2.c. Signed-off-by: Olli Salonen --- drivers/media/pci/cx23885/cx23885-dvb.c | 105 +++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 2 deletions(-) diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c index cc88997..70dbcd6 100644 --- a/drivers/media/pci/cx23885/cx23885-dvb.c +++ b/drivers/media/pci/cx23885/cx23885-dvb.c @@ -71,6 +71,7 @@ #include "si2165.h" #include "si2168.h" #include "si2157.h" +#include "sp2.h" #include "m88ds3103.h" #include "m88ts2022.h" @@ -616,6 +617,76 @@ static int dvbsky_t9580_set_voltage(struct dvb_frontend *fe, return 0; } +static int cx23885_sp2_ci_ctrl(void *priv, u8 read, int addr, + u8 data, int *mem) +{ + + /* MC417 */ + #define SP2_DATA 0x000000ff + #define SP2_WR 0x00008000 + #define SP2_RD 0x00004000 + #define SP2_ACK 0x00001000 + #define SP2_ADHI 0x00000800 + #define SP2_ADLO 0x00000400 + #define SP2_CS1 0x00000200 + #define SP2_CS0 0x00000100 + #define SP2_EN_ALL 0x00001000 + #define SP2_CTRL_OFF (SP2_CS1 | SP2_CS0 | SP2_WR | SP2_RD) + + struct cx23885_tsport *port = priv; + struct cx23885_dev *dev = port->dev; + int ret; + int tmp; + unsigned long timeout; + + mutex_lock(&dev->gpio_lock); + + /* write addr */ + cx_write(MC417_OEN, SP2_EN_ALL); + cx_write(MC417_RWD, SP2_CTRL_OFF | + SP2_ADLO | (0xff & addr)); + cx_clear(MC417_RWD, SP2_ADLO); + cx_write(MC417_RWD, SP2_CTRL_OFF | + SP2_ADHI | (0xff & (addr >> 8))); + cx_clear(MC417_RWD, SP2_ADHI); + + if (read) { /* data in */ + cx_write(MC417_OEN, SP2_EN_ALL | SP2_DATA); + } else /* data out */ + cx_write(MC417_RWD, SP2_CTRL_OFF | data); + + /* chip select 0 */ + cx_clear(MC417_RWD, SP2_CS0); + + /* read/write */ + cx_clear(MC417_RWD, (read) ? SP2_RD : SP2_WR); + + timeout = jiffies + msecs_to_jiffies(1); + for (;;) { + tmp = cx_read(MC417_RWD); + if ((tmp & SP2_ACK) == 0) + break; + if (time_after(jiffies, timeout)) + break; + udelay(1); + } + + cx_set(MC417_RWD, SP2_CTRL_OFF); + *mem = tmp & 0xff; + + mutex_unlock(&dev->gpio_lock); + + if (!read) + if (*mem < 0) { + ret = -EREMOTEIO; + goto err; + } + + return 0; +err: + return ret; +} + static int cx23885_dvb_set_frontend(struct dvb_frontend *fe) { struct dtv_frontend_properties *p = &fe->dtv_property_cache; @@ -944,11 +1015,11 @@ static int dvb_register(struct cx23885_tsport *port) struct vb2_dvb_frontend *fe0, *fe1 = NULL; struct si2168_config si2168_config; struct si2157_config si2157_config; + struct sp2_config sp2_config; struct m88ts2022_config m88ts2022_config; struct i2c_board_info info; struct i2c_adapter *adapter; - struct i2c_client *client_demod; - struct i2c_client *client_tuner; + struct i2c_client *client_demod, *client_tuner, *client_ci; int mfe_shared = 0; /* bus not shared by default */ int ret; @@ -1683,6 +1754,7 @@ static int dvb_register(struct cx23885_tsport *port) break; case CX23885_BOARD_DVBSKY_T980C: i2c_bus = &dev->i2c_bus[1]; + i2c_bus2 = &dev->i2c_bus[0]; /* attach frontend */ memset(&si2168_config, 0, sizeof(si2168_config)); @@ -1820,6 +1892,35 @@ static int dvb_register(struct cx23885_tsport *port) case CX23885_BOARD_DVBSKY_T980C: { u8 eeprom[256]; /* 24C02 i2c eeprom */ + /* attach CI */ + memset(&sp2_config, 0, sizeof(sp2_config)); + sp2_config.dvb_adap = &port->frontends.adapter; + sp2_config.priv = port; + sp2_config.ci_control = cx23885_sp2_ci_ctrl; + memset(&info, 0, sizeof(struct i2c_board_info)); + strlcpy(info.type, "sp2", I2C_NAME_SIZE); + info.addr = 0x40; + info.platform_data = &sp2_config; + request_module(info.type); + client_ci = i2c_new_device(&i2c_bus2->i2c_adap, &info); + if (client_ci == NULL || + client_ci->dev.driver == NULL) { + module_put(client_tuner->dev.driver->owner); + i2c_unregister_device(client_tuner); + module_put(client_demod->dev.driver->owner); + i2c_unregister_device(client_demod); + goto frontend_detach; + } + if (!try_module_get(client_ci->dev.driver->owner)) { + i2c_unregister_device(client_ci); + module_put(client_tuner->dev.driver->owner); + i2c_unregister_device(client_tuner); + module_put(client_demod->dev.driver->owner); + i2c_unregister_device(client_demod); + goto frontend_detach; + } + port->i2c_client_ci = client_ci; + if (port->nr != 1) break;