From patchwork Wed Apr 20 15:18:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Rosin X-Patchwork-Id: 8892621 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0086DBF29F for ; Wed, 20 Apr 2016 15:51:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 369EB2024D for ; Wed, 20 Apr 2016 15:51:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5522020145 for ; Wed, 20 Apr 2016 15:51:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751584AbcDTPvS (ORCPT ); Wed, 20 Apr 2016 11:51:18 -0400 Received: from mail-db5eur01on0118.outbound.protection.outlook.com ([104.47.2.118]:9024 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750929AbcDTPvP (ORCPT ); Wed, 20 Apr 2016 11:51:15 -0400 X-Greylist: delayed 906 seconds by postgrey-1.27 at vger.kernel.org; Wed, 20 Apr 2016 11:51:14 EDT 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=2f2UWqK9BD4QgNeVUUOtFAmDVqr3Ti58h9OCAuEjruU=; b=RitAnGy8RvtY8DaVQiyVkbmmDoQsUKPIqNTCsDXssacu4wNo44e1UB1PnRJkq0jTdNzKLIGlHKmdBl08Ecj0ekTaYX5Vj/DBfjQhppg3n8mkgBNR5U+EGLTsaCCX7+fytbwl3B6mzM8XqT8PisI2gt4Mx981ehpJoSE8LhfqKho= 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.466.19; Wed, 20 Apr 2016 15:20:50 +0000 From: Peter Rosin To: CC: Peter Rosin , Wolfram Sang , "Jonathan Corbet" , Peter Korsgaard , "Guenter Roeck" , Jonathan Cameron , "Hartmut Knaack" , Lars-Peter Clausen , "Peter Meerwald" , Antti Palosaari , "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 , Adriana Reus , Matt Ranostay , Krzysztof Kozlowski , Hans Verkuil , Terry Heo , "Arnd Bergmann" , Tommi Rantala , "Crestez Dan Leonard" , , , , , , Peter Rosin Subject: [PATCH v7 22/24] [media] rtl2832: change the i2c gate to be mux-locked Date: Wed, 20 Apr 2016 17:18:02 +0200 Message-ID: <1461165484-2314-23-git-send-email-peda@axentia.se> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1461165484-2314-1-git-send-email-peda@axentia.se> References: <1461165484-2314-1-git-send-email-peda@axentia.se> MIME-Version: 1.0 X-Originating-IP: [217.210.101.82] X-ClientProxiedBy: DB3PR01CA0069.eurprd01.prod.exchangelabs.com (10.242.133.172) To VI1PR02MB1312.eurprd02.prod.outlook.com (10.165.231.154) X-MS-Office365-Filtering-Correlation-Id: 87494014-d0ae-4eb4-761f-08d3692f5e38 X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 2:TyBYLbNV1yN5buuO21zGXiHWasOLQfSSK0CEGLFQLi33uvi/MR0lNq+LUDWBXSlOWG487i5biFKjo0ysYhOaIgxjqs7vVmbUuZUsPuRMxnHC2L/cmfDR9IzkxpwCDqOTLLBhS19R3Ym7aXOLLCuqk9DVvK7AP+GrhnO6GgjWAsOK4ONJ+/KOYuZtkDghEasb; 3:xQfWIhptptzUQXXhSDGQ1v1jibYP6c45zW+cl4nu6JtauLd5YbRUuQ2scaJPhNTGbBcFIAs/3+0BL3SljG/a3xlvEG/cEoXCLbzXI3u9noA1w+UNYrhSRvUuGS6DG9Pg; 25:vaVQkaScGBY4Q+HSwezTZ25iWmOEfTsX3xUb8OMfnDFmpQMc+q/aJ+jNMSbUw2IaF5IzXZ4U23yEy59NE7t7Y/tymFmD3282/nSZdy0DvhyA/Ta6qNU8K4Ld/h6PkovDLGbXPOULpY/SkaGXJnVX2l7P/VqdqieA6hBzoHYCsDITFLm3IGlF98hecfA+SjtBmwsQgyXw7KvSZ1C4/IzRfHOKlTqqykhdSwFB49vYXqt3B+dehgDgFyLM4sLjyK1U9Yg7FcYF5VoYLTs0HXMoU31nbbE8a3mQNgP/WY8RQ538B2ExeQKx5vEusOXLFdS3f+GbOfiITICcO4/fxLbjdA== 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:(9101521026)(6040130)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(6041046)(6043046); SRVR:VI1PR02MB1312; BCL:0; PCL:0; RULEID:; SRVR:VI1PR02MB1312; X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 4:jv5NFKnlUELrt3JqfuH87rLe2WRvjqBmvHMMsdUkkzWoWMIegMDDf3B2amXlBKJUyPibhlD0ZkxLSnxgIRe61zLJUChQNW6HaX2gccO6VcfSK1F/6nAyb7kYrhL2WGZhhU7bfDGaAuLu+oq4JLRRKw5t6F+JSaj2/cw6hNNEWCSIdbkpEGaQQqaJlhBUqy1Lebw7rQSpFRryhFVkzGn8FJ6Ibue3zzehEIKHBC6i33Xa1s00LMYdjSr0ALJK/ORTdIgTDaa0bD9qT+NY5u6QkkdTVmPAdRzISRfrjP0opDO9arKNxMQE+64jPSs+vXuzmyTlnr7T0Gjuuq2CXWGkBq1dj2GOUSSJqv8KQ8IOcFinUrt7SQLYUrrkGHQlnB7u6q71JwZxQoIhfxr14RJF1FyRsn1/AFjKxn8bn1ngm3lRhGC7ypElCVI7foZBtKEFLNk5vOQ6ZvkCX27nO1yElA== X-Forefront-PRVS: 0918748D70 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6069001)(66066001)(2906002)(19580395003)(19580405001)(110136002)(92566002)(189998001)(5008740100001)(5890100001)(47776003)(42186005)(33646002)(6116002)(3846002)(5003940100001)(586003)(81166005)(48376002)(2950100001)(4326007)(50466002)(76176999)(1096002)(50226001)(77096005)(50986999)(36756003)(575784001)(86362001)(2351001)(229853001)(74482002)(5004730100002)(7059030)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR02MB1312; H:localhost.localdomain; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR02MB1312; 23:CRIqwFywKyJ/55Pb6CGY6x+9Vd7ZlunB7tDLVsBYy?= =?us-ascii?Q?IzMdPZa8H7Gey4NkGjyVXliQ4JiZbJacJiktZhVNYkU4pVgzMkXkg1ESCR4U?= =?us-ascii?Q?BX5eo5wlmGrv2T/AGpOiVG+704wZdJnKfuBlVB/sosBfIHFKw9n89DajTzSK?= =?us-ascii?Q?MersEjUcXjJ4LBM8g40cQljROi9dqldJ9QxkG7siDswAdJFOq1H/+phkWjvQ?= =?us-ascii?Q?hv80yGgDiQ/ddNNaPL5iPH3YLUxJUb72ZB3OrtlfZhFygvCpJbIJvb7enhgX?= =?us-ascii?Q?Q3zW4ZqM5hqPkB2Gaz2IwIUA9JN/RvbgLhfUFPeONoTrsaGG1wnUSqPIHdws?= =?us-ascii?Q?i52fDqa51zq7ZlBHykO0Jwx/LxQkNq81jq7i5RFqf89ElsjeXvtLdulWv/Kn?= =?us-ascii?Q?LiUqUwoGNc532sPcXlUmhivdpXsyRhubxpMnp0omdXI9O5X1o68NStFIV1AS?= =?us-ascii?Q?L7C0v3GP/MRJseiAn7AU7YSgDLTVpPnpYskIDwmlUhNg+R5ghlLGPidLib7R?= =?us-ascii?Q?GiAVSd1khyeQk564V/wPZE7tizcuyRMa0SM1qesMU4Sajtxdo6OMq/sAmdWY?= =?us-ascii?Q?hbuMNUfG6fuvC+q/x2gQRSLL/2a9ymgqpd47RUNdgh+4GzxEZrCTK3lTa72d?= =?us-ascii?Q?4+zglibIl4h92sxnrt40v/U7Z0GsVYjA/PzluA2l3T+rC4mAG0jCyMDPNdei?= =?us-ascii?Q?nT2q9bwkl5ZmgWE9qPFwhXs+JvJXOjteZ4YjXLK+hjFtjDqesYD1zOrc29wb?= =?us-ascii?Q?ZGyFM4LgRbjbvdcsSJFoHNlizOLth9J3Ume176+wPJlaQ4xEQcMqvcvmt95G?= =?us-ascii?Q?RS6IfoSVcsFtua2FBQEOFMRHG6hhuPnfunJzL7YgSB+c4bna7piRmrFzRevw?= =?us-ascii?Q?bfEsZyQgnaZkVNcx0tNZAZ4YosIyH2FEf+oGfBIGRz9/Oiu1ZiBjw/aYZAtz?= =?us-ascii?Q?X1OyXklHiRoaEZJ+tdpn4Au0e31B07sXOZAwNbP1gJmPiCApA9COCQzmOECZ?= =?us-ascii?Q?2l2mkBQ9Uh2PKFJ2zV4FgNk?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR02MB1312; 5:1XH6BxlY6hvZi4Sze6cHvkNC1GOCU/CEEA8lWFPygkaaLc+RYlBT747IPGu1fVXmU3MFHYNoNowzGYdCpP3XIzjaOyLOY+XaII1g8Uw9zfQKbmcVFw8C+xHBfHrXeJlAhtq/VL5EIazfRlavNNVON4205w6qesrLFyvqzCQd3ei+CXLymSw4YLURhveADaAl; 24:/Kp5qutsZWdBo8C/1rAyoDZ4Kj3IfQFwUMcfb6cm/jqq6ndmJrzusZOk3zXxepwDLj5DQvTQuNrguqqabZdXEcFqBG1IRz3r+lizBknN6+c=; 7:U3aau9t6hd6+TpqMd2SeRh/ETyqCWZ2Ei90+5Zm4XlZ+zNgCNurxXEpnSp+XzCNqk5kfynN7qWwCi0V6o1PiAtPQcAOLxNaIcGvbQX/SzzCtJHTuKhTKtN1KfMuV228NU3uQwtGWXaXN4gshGoLeZHVE8vYf64jJQndE3X0k5EHo8cNN/hyXAB5yc6Ux2K4wjcyn4PcAWbpoOINv6HgWK0957IMJawanbNUyIStxewY= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: axentia.se X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2016 15:20:50.4820 (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=-7.8 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 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 regmap overrides that makes the i2c accesses unlocked and use plain old regmap accesses. This also removes the need for the regmap wrappers used by rtl2832_sdr, so deconvolute the code further and provide the regmap handle directly instead of the wrapper functions. Signed-off-by: Peter Rosin --- Documentation/i2c/i2c-topology | 2 +- drivers/media/dvb-frontends/rtl2832.c | 190 ++++-------------------------- drivers/media/dvb-frontends/rtl2832.h | 4 +- drivers/media/dvb-frontends/rtl2832_sdr.c | 13 +- drivers/media/dvb-frontends/rtl2832_sdr.h | 5 +- drivers/media/usb/dvb-usb-v2/rtl28xxu.c | 5 +- 6 files changed, 37 insertions(+), 182 deletions(-) diff --git a/Documentation/i2c/i2c-topology b/Documentation/i2c/i2c-topology index 5e40802f0be2..e0aefeece551 100644 --- a/Documentation/i2c/i2c-topology +++ b/Documentation/i2c/i2c-topology @@ -55,7 +55,7 @@ imu/inv_mpu6050/ Mux-locked In drivers/media/ dvb-frontends/m88ds3103 Parent-locked dvb-frontends/rtl2830 Parent-locked -dvb-frontends/rtl2832 Parent-locked +dvb-frontends/rtl2832 Mux-locked dvb-frontends/si2168 Mux-locked usb/cx231xx/ Parent-locked diff --git a/drivers/media/dvb-frontends/rtl2832.c b/drivers/media/dvb-frontends/rtl2832.c index 1b23788797b5..957523f07f61 100644 --- a/drivers/media/dvb-frontends/rtl2832.c +++ b/drivers/media/dvb-frontends/rtl2832.c @@ -153,43 +153,6 @@ static const struct rtl2832_reg_entry registers[] = { [DVBT_REG_4MSEL] = {0x013, 0, 0}, }; -/* Our regmap is bypassing I2C adapter lock, thus we do it! */ -static int rtl2832_bulk_write(struct i2c_client *client, unsigned int reg, - const void *val, size_t val_count) -{ - struct rtl2832_dev *dev = i2c_get_clientdata(client); - int ret; - - i2c_lock_adapter(client->adapter); - ret = regmap_bulk_write(dev->regmap, reg, val, val_count); - i2c_unlock_adapter(client->adapter); - return ret; -} - -static int rtl2832_update_bits(struct i2c_client *client, unsigned int reg, - unsigned int mask, unsigned int val) -{ - struct rtl2832_dev *dev = i2c_get_clientdata(client); - int ret; - - i2c_lock_adapter(client->adapter); - ret = regmap_update_bits(dev->regmap, reg, mask, val); - i2c_unlock_adapter(client->adapter); - return ret; -} - -static int rtl2832_bulk_read(struct i2c_client *client, unsigned int reg, - void *val, size_t val_count) -{ - struct rtl2832_dev *dev = i2c_get_clientdata(client); - int ret; - - i2c_lock_adapter(client->adapter); - ret = regmap_bulk_read(dev->regmap, reg, val, val_count); - i2c_unlock_adapter(client->adapter); - return ret; -} - static int rtl2832_rd_demod_reg(struct rtl2832_dev *dev, int reg, u32 *val) { struct i2c_client *client = dev->client; @@ -204,7 +167,7 @@ static int rtl2832_rd_demod_reg(struct rtl2832_dev *dev, int reg, u32 *val) len = (msb >> 3) + 1; mask = REG_MASK(msb - lsb); - ret = rtl2832_bulk_read(client, reg_start_addr, reading, len); + ret = regmap_bulk_read(dev->regmap, reg_start_addr, reading, len); if (ret) goto err; @@ -234,7 +197,7 @@ static int rtl2832_wr_demod_reg(struct rtl2832_dev *dev, int reg, u32 val) len = (msb >> 3) + 1; mask = REG_MASK(msb - lsb); - ret = rtl2832_bulk_read(client, reg_start_addr, reading, len); + ret = regmap_bulk_read(dev->regmap, reg_start_addr, reading, len); if (ret) goto err; @@ -248,7 +211,7 @@ static int rtl2832_wr_demod_reg(struct rtl2832_dev *dev, int reg, u32 val) for (i = 0; i < len; i++) writing[i] = (writing_tmp >> ((len - 1 - i) * 8)) & 0xff; - ret = rtl2832_bulk_write(client, reg_start_addr, writing, len); + ret = regmap_bulk_write(dev->regmap, reg_start_addr, writing, len); if (ret) goto err; @@ -525,7 +488,8 @@ static int rtl2832_set_frontend(struct dvb_frontend *fe) } for (j = 0; j < sizeof(bw_params[0]); j++) { - ret = rtl2832_bulk_write(client, 0x11c + j, &bw_params[i][j], 1); + ret = regmap_bulk_write(dev->regmap, + 0x11c + j, &bw_params[i][j], 1); if (ret) goto err; } @@ -581,11 +545,11 @@ static int rtl2832_get_frontend(struct dvb_frontend *fe, if (dev->sleeping) return 0; - ret = rtl2832_bulk_read(client, 0x33c, buf, 2); + ret = regmap_bulk_read(dev->regmap, 0x33c, buf, 2); if (ret) goto err; - ret = rtl2832_bulk_read(client, 0x351, &buf[2], 1); + ret = regmap_bulk_read(dev->regmap, 0x351, &buf[2], 1); if (ret) goto err; @@ -716,7 +680,7 @@ static int rtl2832_read_status(struct dvb_frontend *fe, enum fe_status *status) /* signal strength */ if (dev->fe_status & FE_HAS_SIGNAL) { /* read digital AGC */ - ret = rtl2832_bulk_read(client, 0x305, &u8tmp, 1); + ret = regmap_bulk_read(dev->regmap, 0x305, &u8tmp, 1); if (ret) goto err; @@ -742,7 +706,7 @@ static int rtl2832_read_status(struct dvb_frontend *fe, enum fe_status *status) {87659938, 87659938, 87885178, 88241743}, }; - ret = rtl2832_bulk_read(client, 0x33c, &u8tmp, 1); + ret = regmap_bulk_read(dev->regmap, 0x33c, &u8tmp, 1); if (ret) goto err; @@ -754,7 +718,7 @@ static int rtl2832_read_status(struct dvb_frontend *fe, enum fe_status *status) if (hierarchy > HIERARCHY_NUM - 1) goto err; - ret = rtl2832_bulk_read(client, 0x40c, buf, 2); + ret = regmap_bulk_read(dev->regmap, 0x40c, buf, 2); if (ret) goto err; @@ -775,7 +739,7 @@ static int rtl2832_read_status(struct dvb_frontend *fe, enum fe_status *status) /* BER */ if (dev->fe_status & FE_HAS_LOCK) { - ret = rtl2832_bulk_read(client, 0x34e, buf, 2); + ret = regmap_bulk_read(dev->regmap, 0x34e, buf, 2); if (ret) goto err; @@ -825,8 +789,6 @@ static int rtl2832_read_ber(struct dvb_frontend *fe, u32 *ber) /* * I2C gate/mux/repeater logic - * We must use unlocked __i2c_transfer() here (through regmap) because of I2C - * adapter lock is already taken by tuner driver. * There is delay mechanism to avoid unneeded I2C gate open / close. Gate close * is delayed here a little bit in order to see if there is sequence of I2C * messages sent to same I2C bus. @@ -838,7 +800,7 @@ static void rtl2832_i2c_gate_work(struct work_struct *work) int ret; /* close gate */ - ret = rtl2832_update_bits(dev->client, 0x101, 0x08, 0x00); + ret = regmap_update_bits(dev->regmap, 0x101, 0x08, 0x00); if (ret) goto err; @@ -856,10 +818,7 @@ static int rtl2832_select(struct i2c_mux_core *muxc, u32 chan_id) /* terminate possible gate closing */ cancel_delayed_work(&dev->i2c_gate_work); - /* - * I2C adapter lock is already taken and due to that we will use - * regmap_update_bits() which does not lock again I2C adapter. - */ + /* open gate */ ret = regmap_update_bits(dev->regmap, 0x101, 0x08, 0x08); if (ret) goto err; @@ -932,94 +891,6 @@ static bool rtl2832_volatile_reg(struct device *dev, unsigned int reg) } /* - * We implement own I2C access routines for regmap in order to get manual access - * to I2C adapter lock, which is needed for I2C mux adapter. - */ -static int rtl2832_regmap_read(void *context, const void *reg_buf, - size_t reg_size, void *val_buf, size_t val_size) -{ - struct i2c_client *client = context; - int ret; - struct i2c_msg msg[2] = { - { - .addr = client->addr, - .flags = 0, - .len = reg_size, - .buf = (u8 *)reg_buf, - }, { - .addr = client->addr, - .flags = I2C_M_RD, - .len = val_size, - .buf = val_buf, - } - }; - - ret = __i2c_transfer(client->adapter, msg, 2); - if (ret != 2) { - dev_warn(&client->dev, "i2c reg read failed %d reg %02x\n", - ret, *(u8 *)reg_buf); - if (ret >= 0) - ret = -EREMOTEIO; - return ret; - } - return 0; -} - -static int rtl2832_regmap_write(void *context, const void *data, size_t count) -{ - struct i2c_client *client = context; - int ret; - struct i2c_msg msg[1] = { - { - .addr = client->addr, - .flags = 0, - .len = count, - .buf = (u8 *)data, - } - }; - - ret = __i2c_transfer(client->adapter, msg, 1); - if (ret != 1) { - dev_warn(&client->dev, "i2c reg write failed %d reg %02x\n", - ret, *(u8 *)data); - if (ret >= 0) - ret = -EREMOTEIO; - return ret; - } - return 0; -} - -static int rtl2832_regmap_gather_write(void *context, const void *reg, - size_t reg_len, const void *val, - size_t val_len) -{ - struct i2c_client *client = context; - int ret; - u8 buf[256]; - struct i2c_msg msg[1] = { - { - .addr = client->addr, - .flags = 0, - .len = 1 + val_len, - .buf = buf, - } - }; - - buf[0] = *(u8 const *)reg; - memcpy(&buf[1], val, val_len); - - ret = __i2c_transfer(client->adapter, msg, 1); - if (ret != 1) { - dev_warn(&client->dev, "i2c reg write failed %d reg %02x\n", - ret, *(u8 const *)reg); - if (ret >= 0) - ret = -EREMOTEIO; - return ret; - } - return 0; -} - -/* * FIXME: Hack. Implement own regmap locking in order to silence lockdep * recursive lock warning. That happens when regmap I2C client calls I2C mux * adapter, which leads demod I2C repeater enable via demod regmap. Operation @@ -1072,29 +943,29 @@ static int rtl2832_slave_ts_ctrl(struct i2c_client *client, bool enable) ret = rtl2832_wr_demod_reg(dev, DVBT_SOFT_RST, 0x0); if (ret) goto err; - ret = rtl2832_bulk_write(client, 0x10c, "\x5f\xff", 2); + ret = regmap_bulk_write(dev->regmap, 0x10c, "\x5f\xff", 2); if (ret) goto err; ret = rtl2832_wr_demod_reg(dev, DVBT_PIP_ON, 0x1); if (ret) goto err; - ret = rtl2832_bulk_write(client, 0x0bc, "\x18", 1); + ret = regmap_bulk_write(dev->regmap, 0x0bc, "\x18", 1); if (ret) goto err; - ret = rtl2832_bulk_write(client, 0x192, "\x7f\xf7\xff", 3); + ret = regmap_bulk_write(dev->regmap, 0x192, "\x7f\xf7\xff", 3); if (ret) goto err; } else { - ret = rtl2832_bulk_write(client, 0x192, "\x00\x0f\xff", 3); + ret = regmap_bulk_write(dev->regmap, 0x192, "\x00\x0f\xff", 3); if (ret) goto err; - ret = rtl2832_bulk_write(client, 0x0bc, "\x08", 1); + ret = regmap_bulk_write(dev->regmap, 0x0bc, "\x08", 1); if (ret) goto err; ret = rtl2832_wr_demod_reg(dev, DVBT_PIP_ON, 0x0); if (ret) goto err; - ret = rtl2832_bulk_write(client, 0x10c, "\x00\x00", 2); + ret = regmap_bulk_write(dev->regmap, 0x10c, "\x00\x00", 2); if (ret) goto err; ret = rtl2832_wr_demod_reg(dev, DVBT_SOFT_RST, 0x1); @@ -1123,7 +994,7 @@ static int rtl2832_pid_filter_ctrl(struct dvb_frontend *fe, int onoff) else u8tmp = 0x00; - ret = rtl2832_update_bits(client, 0x061, 0xc0, u8tmp); + ret = regmap_update_bits(dev->regmap, 0x061, 0xc0, u8tmp); if (ret) goto err; @@ -1158,14 +1029,14 @@ static int rtl2832_pid_filter(struct dvb_frontend *fe, u8 index, u16 pid, buf[1] = (dev->filters >> 8) & 0xff; buf[2] = (dev->filters >> 16) & 0xff; buf[3] = (dev->filters >> 24) & 0xff; - ret = rtl2832_bulk_write(client, 0x062, buf, 4); + ret = regmap_bulk_write(dev->regmap, 0x062, buf, 4); if (ret) goto err; /* add PID */ buf[0] = (pid >> 8) & 0xff; buf[1] = (pid >> 0) & 0xff; - ret = rtl2832_bulk_write(client, 0x066 + 2 * index, buf, 2); + ret = regmap_bulk_write(dev->regmap, 0x066 + 2 * index, buf, 2); if (ret) goto err; @@ -1183,12 +1054,6 @@ static int rtl2832_probe(struct i2c_client *client, struct rtl2832_dev *dev; int ret; u8 tmp; - static const struct regmap_bus regmap_bus = { - .read = rtl2832_regmap_read, - .write = rtl2832_regmap_write, - .gather_write = rtl2832_regmap_gather_write, - .val_format_endian_default = REGMAP_ENDIAN_NATIVE, - }; static const struct regmap_range_cfg regmap_range_cfg[] = { { .selector_reg = 0x00, @@ -1228,20 +1093,19 @@ static int rtl2832_probe(struct i2c_client *client, dev->regmap_config.ranges = regmap_range_cfg, dev->regmap_config.num_ranges = ARRAY_SIZE(regmap_range_cfg), dev->regmap_config.cache_type = REGCACHE_NONE, - dev->regmap = regmap_init(&client->dev, ®map_bus, client, - &dev->regmap_config); + dev->regmap = regmap_init_i2c(client, &dev->regmap_config); if (IS_ERR(dev->regmap)) { ret = PTR_ERR(dev->regmap); goto err_kfree; } /* check if the demod is there */ - ret = rtl2832_bulk_read(client, 0x000, &tmp, 1); + ret = regmap_bulk_read(dev->regmap, 0x000, &tmp, 1); if (ret) goto err_regmap_exit; /* create muxed i2c adapter for demod tuner bus */ - dev->muxc = i2c_mux_alloc(i2c, &i2c->dev, 1, 0, 0, + dev->muxc = i2c_mux_alloc(i2c, &i2c->dev, 1, 0, I2C_MUX_LOCKED, rtl2832_select, rtl2832_deselect); if (!dev->muxc) { ret = -ENOMEM; @@ -1262,9 +1126,7 @@ static int rtl2832_probe(struct i2c_client *client, pdata->slave_ts_ctrl = rtl2832_slave_ts_ctrl; pdata->pid_filter = rtl2832_pid_filter; pdata->pid_filter_ctrl = rtl2832_pid_filter_ctrl; - pdata->bulk_read = rtl2832_bulk_read; - pdata->bulk_write = rtl2832_bulk_write; - pdata->update_bits = rtl2832_update_bits; + pdata->regmap = dev->regmap; dev_info(&client->dev, "Realtek RTL2832 successfully attached\n"); return 0; diff --git a/drivers/media/dvb-frontends/rtl2832.h b/drivers/media/dvb-frontends/rtl2832.h index 6390af64cf45..03c0de039fa9 100644 --- a/drivers/media/dvb-frontends/rtl2832.h +++ b/drivers/media/dvb-frontends/rtl2832.h @@ -57,9 +57,7 @@ struct rtl2832_platform_data { int (*pid_filter)(struct dvb_frontend *, u8, u16, int); int (*pid_filter_ctrl)(struct dvb_frontend *, int); /* private: Register access for SDR module use only */ - int (*bulk_read)(struct i2c_client *, unsigned int, void *, size_t); - int (*bulk_write)(struct i2c_client *, unsigned int, const void *, size_t); - int (*update_bits)(struct i2c_client *, unsigned int, unsigned int, unsigned int); + struct regmap *regmap; }; #endif /* RTL2832_H */ diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.c b/drivers/media/dvb-frontends/rtl2832_sdr.c index b860f02a4e55..6a6b1debe277 100644 --- a/drivers/media/dvb-frontends/rtl2832_sdr.c +++ b/drivers/media/dvb-frontends/rtl2832_sdr.c @@ -35,6 +35,7 @@ #include #include #include +#include static bool rtl2832_sdr_emulated_fmt; module_param_named(emulated_formats, rtl2832_sdr_emulated_fmt, bool, 0644); @@ -169,9 +170,9 @@ static int rtl2832_sdr_wr_regs(struct rtl2832_sdr_dev *dev, u16 reg, { struct platform_device *pdev = dev->pdev; struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data; - struct i2c_client *client = pdata->i2c_client; + struct regmap *regmap = pdata->regmap; - return pdata->bulk_write(client, reg, val, len); + return regmap_bulk_write(regmap, reg, val, len); } #if 0 @@ -181,9 +182,9 @@ static int rtl2832_sdr_rd_regs(struct rtl2832_sdr_dev *dev, u16 reg, u8 *val, { struct platform_device *pdev = dev->pdev; struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data; - struct i2c_client *client = pdata->i2c_client; + struct regmap *regmap = pdata->regmap; - return pdata->bulk_read(client, reg, val, len); + return regmap_bulk_read(regmap, reg, val, len); } #endif @@ -199,9 +200,9 @@ static int rtl2832_sdr_wr_reg_mask(struct rtl2832_sdr_dev *dev, u16 reg, { struct platform_device *pdev = dev->pdev; struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data; - struct i2c_client *client = pdata->i2c_client; + struct regmap *regmap = pdata->regmap; - return pdata->update_bits(client, reg, mask, val); + return regmap_update_bits(regmap, reg, mask, val); } /* Private functions */ diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.h b/drivers/media/dvb-frontends/rtl2832_sdr.h index 342ea84860df..d8fc7e7212e3 100644 --- a/drivers/media/dvb-frontends/rtl2832_sdr.h +++ b/drivers/media/dvb-frontends/rtl2832_sdr.h @@ -56,10 +56,7 @@ struct rtl2832_sdr_platform_data { #define RTL2832_SDR_TUNER_R828D 0x2b u8 tuner; - struct i2c_client *i2c_client; - int (*bulk_read)(struct i2c_client *, unsigned int, void *, size_t); - int (*bulk_write)(struct i2c_client *, unsigned int, const void *, size_t); - int (*update_bits)(struct i2c_client *, unsigned int, unsigned int, unsigned int); + struct regmap *regmap; struct dvb_frontend *dvb_frontend; struct v4l2_subdev *v4l2_subdev; struct dvb_usb_device *dvb_usb_device; diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c index fa72642d41f3..eb7af8cb8aca 100644 --- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c +++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c @@ -1333,10 +1333,7 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap) case TUNER_RTL2832_R828D: pdata.clk = dev->rtl2832_platform_data.clk; pdata.tuner = dev->tuner; - pdata.i2c_client = dev->i2c_client_demod; - pdata.bulk_read = dev->rtl2832_platform_data.bulk_read; - pdata.bulk_write = dev->rtl2832_platform_data.bulk_write; - pdata.update_bits = dev->rtl2832_platform_data.update_bits; + pdata.regmap = dev->rtl2832_platform_data.regmap; pdata.dvb_frontend = adap->fe[0]; pdata.dvb_usb_device = d; pdata.v4l2_subdev = subdev;