From patchwork Wed May 4 20:15:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Rosin X-Patchwork-Id: 9018271 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 09E6A9F66C for ; Wed, 4 May 2016 20:16:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E3D12203EC for ; Wed, 4 May 2016 20:16:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 694B5203F4 for ; Wed, 4 May 2016 20:16:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754713AbcEDUQd (ORCPT ); Wed, 4 May 2016 16:16:33 -0400 Received: from mail-db5eur01on0097.outbound.protection.outlook.com ([104.47.2.97]:51128 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754532AbcEDUQ2 (ORCPT ); Wed, 4 May 2016 16:16:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axentiatech.onmicrosoft.com; s=selector1-axentia-se; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=QMEDsz6UBrurwox8RkDkuH9LN+hYP2PAIdDrjbHtuwc=; b=MVaLQNXe+sTnkSrMC8FgF4xOePY+Eir4MfPoLggXK/Nrb7/C7nS3wlSeLs3gExhsT8n9Ph4G5UtUGMEcgVMQwAtmYHpUagK3bMRNML2ioS4AqyHnKNRMO7+GS2O2OpovSI0FbrQOhhqjm8QUH1lf2+0Fkybhw0nMW9HZVij37vg= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=axentia.se; Received: from localhost.localdomain (217.210.101.82) by VI1PR02MB1312.eurprd02.prod.outlook.com (10.165.231.154) with Microsoft SMTP Server (TLS) id 15.1.485.9; Wed, 4 May 2016 20:16:19 +0000 From: Peter Rosin To: CC: Antti Palosaari , Peter Rosin , Wolfram Sang , Jonathan Corbet , Peter Korsgaard , Guenter Roeck , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald , Mauro Carvalho Chehab , Rob Herring , Frank Rowand , Grant Likely , Andrew Morton , "David S. Miller" , Greg Kroah-Hartman , Kalle Valo , Jiri Slaby , Daniel Baluta , Lucas De Marchi , Matt Ranostay , Krzysztof Kozlowski , Hans Verkuil , Terry Heo , Arnd Bergmann , Tommi Rantala , Crestez Dan Leonard , , , , , Subject: [PATCH v9 6/9] [media] si2168: change the i2c gate to be mux-locked Date: Wed, 4 May 2016 22:15:32 +0200 Message-ID: <1462392935-28011-7-git-send-email-peda@axentia.se> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1462392935-28011-1-git-send-email-peda@axentia.se> References: <1462392935-28011-1-git-send-email-peda@axentia.se> MIME-Version: 1.0 X-Originating-IP: [217.210.101.82] X-ClientProxiedBy: AM3PR04CA0090.eurprd04.prod.outlook.com (10.163.180.144) To VI1PR02MB1312.eurprd02.prod.outlook.com (10.165.231.154) X-MS-Office365-Filtering-Correlation-Id: cc2dc82b-f1e7-4685-8b22-08d37458f5f6 X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 2:KyHrLTaxD2bu5Z99FQSlmEBvBMpvJpUQWSg29NuHmyqPEXSi2rECA6cW/qgqBwQRp4Im0TnSePK5MvjWtz9zyVpY8GS2q3lJ0+hN+3InO6EphzuFqcwHkQhqpyYERDSVQCo4T/AtaFgB7cqDQEV5gzHivB9JRcvUH2S5wSt7tSfzhDPVg3a8Q2N2S/mhzXkm; 3:i11G5md2MksK66/TclgmVb/wu0C+LEejlMpK1koZHzcka5LE8R8CT5sSdf9vuRjNCJRakqPWV4Dm4d3zy1rKCXal4SLzbMGRhno4UmQFFRWvueQzeCoMUw1jQTAMQC32; 25:wAjBPTH/3doVkd9HC1TGCCNDutJ1glf+oCbfuM1yFqier8ZsdqCkU/wbYHJasSn0rAwtmzXegxn7VFiPPj2rrPynFViRv5Nw39+CW1Mz0VqYbeSL9BZKZ1ehw2HWextGCJqpjb76RQiUb7ihOKMWI4RHuXhII8m+pk1Cusa4YVg/7mXtTXujSX8QmJu/wBg2MsgXLCu9k33GoKo1MQCug2ZPHKBWuDC3BWbfJJxRwQniU7YmaClU4ycJX7GbLV0ArWLLqPOVN970fQ8ObqM+dagYvfaENmWZRE/yJNwpysdb71PoBe6dTlxhaZrktgoKxfU4uPyjnD/8DPNPAoH4jD4PLBJM4llFCg4Vmy4yUGQ4zQ39zeMjCgk+An1tv0xCgLr6B7ASN16xvy1eRzWeTFBtFzGOJkImKYxZQCx+LmgNOpiRfix+hHqnakhHHH+o X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR02MB1312; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(9101528026)(9101521098)(6040130)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6041072)(6043046); SRVR:VI1PR02MB1312; BCL:0; PCL:0; RULEID:; SRVR:VI1PR02MB1312; X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 4:n2MiZnzHv4nVAuTqTaKNg+viDoYfsV79lLj2TVlHP7wDHpcQyQRPdWQlYbA05hdz1RidPcvUDAwwpLPLT1hVMOEBOV775EhyeK1tS47v60A+9irggZZ+S42aq0TutHBe0caUEhOYvo0Jt4gVyr819a1f9jUg4AsZbYY2Y0uiWSfNli46rRB6jvkCqTo8JYEJmyu+IX830awP2ItpsiakWUoMqiVMta4pM7l2v9QscWpV+zEUG5aOnb9eNTpGz9PkGEJ2+o/XW0qzaWSfq/7EN4HSBtHg7QngmSAGJQ7RtagBnlQRGqiwXxjTfnevwMwv0ORZAdjHagmduqtdwZxsFtViau6ATV6TXc2YV7xzeHwV4vrJqVUgSXWR5lqWhwouKAj8kjgD8E7ZV4PBVWKA5AIiRscnPW1WG1Iv89pdqmVRG764RMMAVoRoy+H6nsKvc5KIEPifxkS55nDr+77gSmB51rCPuTQ+XTjEGWJVFc8= X-Forefront-PRVS: 093290AD39 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(4326007)(19580405001)(575784001)(86362001)(2351001)(229853001)(189998001)(586003)(6116002)(3846002)(19580395003)(110136002)(33646002)(47776003)(74482002)(81166005)(2906002)(50466002)(92566002)(48376002)(50986999)(77096005)(76176999)(5003940100001)(42186005)(50226002)(5004730100002)(2950100001)(36756003)(5008740100001)(7059030)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR02MB1312; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 23:oHdyeu4BTKJC/klwI2eOr7mSflAbIE8TV0UWBhkIeU83PIJzgcWSEvIU696papHJf+OYCFIadNJG99u+80NM4taveCuLZLvAX+b/nfTdYe3/6esxea0Q/7gWDQuwVG77bQUTthl9NjJIbQ2gpziXAMm1T93g5ocdnUEbwbGzYa0g+OFMH+Q/HVijGudOoVUafAxol9IkW9uwz0iQ8ccBMsAkPNPuudWn5jpPddDItyCnqRgMePDKN/l9UMQLtXdz4Go2nI9keinG7BDmo/Go1Ye4buNG59NRcJfh0XyqJXGrRSVRtm52Rj4aLPehMVWP6qbbJ04g5tHzxjFtKORrfkBeCJNrAMjbRlmjPdDTVzMsEwbedXAelKEQg/ZC+ZgDm05cGcqKG+anO6bY7ICJVEz53IQxMqQGLb0towsn7zBOVvys/oVnvy3+8cKWHCP9CsQjFO5qzUueljtiSc2PppwFejiJqeof/VNGxXTOsjxN0+J/SbORbvflxKLKnlf/oBgJHjwtFniZPGyBPLw4Gme64vBEHU/GLX63XQIFDnfFmHdUUQZ+ornHEUZL5IL/MHi/dVfWl9UNQYLU0dA/Q2ux6h4CA0+ac0e9iMx9HpERNEvj48MLV6A7TckEf3zuq0cOFscsTXs7oIkVNuft/ocfj5iwsrQY6OLGi/t3erMV4GFn//0PRs5CDxLHmzRuoSpAmYZJy0onXx/B/VB6YEjjLPk5moLOyiDTk9AbpB8zsJetJ/I9j7Qm4+VF5mpfXsqdZYIrqTz7E78ejlpHlwS57EMhTgrulxPA4OKtTAWXU0j2okU60ZZNDdHzP4rjUslFKZWeE/9klQgf7FgoPX5k6qVcVteY9c23wt3jSVTcuJnQ+rUAH09WnH2iolIAsQH49LThVj5V45TKC/A3wwHPl0sBCqpszGswEkAS2 ZQ= X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 5:KVxg1DYK28ooOvo2lUURekSCHQz4qIUWCdES/5Yq+0nNx/ks1KToIcdGCtoQ31d/DYghjQxL61fFG4HklKbHJBpWqP+t9tXAm/kIfE+c4qzcOFewYgmp88i8cqUeT31vld4r2TnDQC4xygcaWEW2kA==; 24:cdqEBktC8ucT+zhvB0RmuKNvuJ9HCjF6KRDuYft2Im6cGnC4DCwrRoGzmlNS1CkHGbMzmB8fyyCdIZ4UYaSqHNJZJaoIexM4O/iPMwD2SxY=; 7:sbUMiM7ntKXLm/CiZk07fegUkCt6lg3rtidch8Gbctmt1Are04Yn8HvUANu0wkUt+QK0CtEriSYXR5Ex+FpdyY8vpXlZXCUvAZ3g3Fg51M021TQSgyLklwPs50aY+JugukbovgfG1R5BzD0OSam+e4Pr3smhr58rUNDQpx4ttxO2gxR1x81A+m0gH5xVvyIp SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 May 2016 20:16:19.0796 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR02MB1312 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Antti Palosaari The root i2c adapter lock is then no longer held by the i2c mux during accesses behind the i2c gate, and such accesses need to take that lock just like any other ordinary i2c accesses do. So, declare the i2c gate mux-locked, and zap the code that makes the i2c accesses unlocked. But add a mutex so that firmware commands are still serialized. Signed-off-by: Antti Palosaari Signed-off-by: Peter Rosin --- Documentation/i2c/i2c-topology | 2 +- drivers/media/dvb-frontends/si2168.c | 83 ++++++++----------------------- drivers/media/dvb-frontends/si2168_priv.h | 1 + 3 files changed, 22 insertions(+), 64 deletions(-) diff --git a/Documentation/i2c/i2c-topology b/Documentation/i2c/i2c-topology index 69b008518454..5e40802f0be2 100644 --- a/Documentation/i2c/i2c-topology +++ b/Documentation/i2c/i2c-topology @@ -56,7 +56,7 @@ In drivers/media/ dvb-frontends/m88ds3103 Parent-locked dvb-frontends/rtl2830 Parent-locked dvb-frontends/rtl2832 Parent-locked -dvb-frontends/si2168 Parent-locked +dvb-frontends/si2168 Mux-locked usb/cx231xx/ Parent-locked diff --git a/drivers/media/dvb-frontends/si2168.c b/drivers/media/dvb-frontends/si2168.c index 5583827c386e..108a069fa1ae 100644 --- a/drivers/media/dvb-frontends/si2168.c +++ b/drivers/media/dvb-frontends/si2168.c @@ -18,53 +18,23 @@ static const struct dvb_frontend_ops si2168_ops; -/* Own I2C adapter locking is needed because of I2C gate logic. */ -static int si2168_i2c_master_send_unlocked(const struct i2c_client *client, - const char *buf, int count) -{ - int ret; - struct i2c_msg msg = { - .addr = client->addr, - .flags = 0, - .len = count, - .buf = (char *)buf, - }; - - ret = __i2c_transfer(client->adapter, &msg, 1); - return (ret == 1) ? count : ret; -} - -static int si2168_i2c_master_recv_unlocked(const struct i2c_client *client, - char *buf, int count) -{ - int ret; - struct i2c_msg msg = { - .addr = client->addr, - .flags = I2C_M_RD, - .len = count, - .buf = buf, - }; - - ret = __i2c_transfer(client->adapter, &msg, 1); - return (ret == 1) ? count : ret; -} - /* execute firmware command */ -static int si2168_cmd_execute_unlocked(struct i2c_client *client, - struct si2168_cmd *cmd) +static int si2168_cmd_execute(struct i2c_client *client, struct si2168_cmd *cmd) { + struct si2168_dev *dev = i2c_get_clientdata(client); int ret; unsigned long timeout; + mutex_lock(&dev->i2c_mutex); + if (cmd->wlen) { /* write cmd and args for firmware */ - ret = si2168_i2c_master_send_unlocked(client, cmd->args, - cmd->wlen); + ret = i2c_master_send(client, cmd->args, cmd->wlen); if (ret < 0) { - goto err; + goto err_mutex_unlock; } else if (ret != cmd->wlen) { ret = -EREMOTEIO; - goto err; + goto err_mutex_unlock; } } @@ -73,13 +43,12 @@ static int si2168_cmd_execute_unlocked(struct i2c_client *client, #define TIMEOUT 70 timeout = jiffies + msecs_to_jiffies(TIMEOUT); while (!time_after(jiffies, timeout)) { - ret = si2168_i2c_master_recv_unlocked(client, cmd->args, - cmd->rlen); + ret = i2c_master_recv(client, cmd->args, cmd->rlen); if (ret < 0) { - goto err; + goto err_mutex_unlock; } else if (ret != cmd->rlen) { ret = -EREMOTEIO; - goto err; + goto err_mutex_unlock; } /* firmware ready? */ @@ -94,32 +63,23 @@ static int si2168_cmd_execute_unlocked(struct i2c_client *client, /* error bit set? */ if ((cmd->args[0] >> 6) & 0x01) { ret = -EREMOTEIO; - goto err; + goto err_mutex_unlock; } if (!((cmd->args[0] >> 7) & 0x01)) { ret = -ETIMEDOUT; - goto err; + goto err_mutex_unlock; } } + mutex_unlock(&dev->i2c_mutex); return 0; -err: +err_mutex_unlock: + mutex_unlock(&dev->i2c_mutex); dev_dbg(&client->dev, "failed=%d\n", ret); return ret; } -static int si2168_cmd_execute(struct i2c_client *client, struct si2168_cmd *cmd) -{ - int ret; - - i2c_lock_adapter(client->adapter); - ret = si2168_cmd_execute_unlocked(client, cmd); - i2c_unlock_adapter(client->adapter); - - return ret; -} - static int si2168_read_status(struct dvb_frontend *fe, enum fe_status *status) { struct i2c_client *client = fe->demodulator_priv; @@ -610,11 +570,6 @@ static int si2168_get_tune_settings(struct dvb_frontend *fe, return 0; } -/* - * I2C gate logic - * We must use unlocked I2C I/O because I2C adapter lock is already taken - * by the caller (usually tuner driver). - */ static int si2168_select(struct i2c_mux_core *muxc, u32 chan) { struct i2c_client *client = i2c_mux_priv(muxc); @@ -625,7 +580,7 @@ static int si2168_select(struct i2c_mux_core *muxc, u32 chan) memcpy(cmd.args, "\xc0\x0d\x01", 3); cmd.wlen = 3; cmd.rlen = 0; - ret = si2168_cmd_execute_unlocked(client, &cmd); + ret = si2168_cmd_execute(client, &cmd); if (ret) goto err; @@ -645,7 +600,7 @@ static int si2168_deselect(struct i2c_mux_core *muxc, u32 chan) memcpy(cmd.args, "\xc0\x0d\x00", 3); cmd.wlen = 3; cmd.rlen = 0; - ret = si2168_cmd_execute_unlocked(client, &cmd); + ret = si2168_cmd_execute(client, &cmd); if (ret) goto err; @@ -708,9 +663,11 @@ static int si2168_probe(struct i2c_client *client, goto err; } + mutex_init(&dev->i2c_mutex); + /* create mux i2c adapter for tuner */ dev->muxc = i2c_mux_alloc(client->adapter, &client->dev, - 1, 0, 0, + 1, 0, I2C_MUX_LOCKED, si2168_select, si2168_deselect); if (!dev->muxc) { ret = -ENOMEM; diff --git a/drivers/media/dvb-frontends/si2168_priv.h b/drivers/media/dvb-frontends/si2168_priv.h index 165bf1412063..8a1f36d2014d 100644 --- a/drivers/media/dvb-frontends/si2168_priv.h +++ b/drivers/media/dvb-frontends/si2168_priv.h @@ -29,6 +29,7 @@ /* state struct */ struct si2168_dev { + struct mutex i2c_mutex; struct i2c_mux_core *muxc; struct dvb_frontend fe; enum fe_delivery_system delivery_system;