From patchwork Mon Jul 27 11:22:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antti Palosaari X-Patchwork-Id: 6872341 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 BCA709F380 for ; Mon, 27 Jul 2015 11:22:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C697E202DD for ; Mon, 27 Jul 2015 11:22:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C59AF2043C for ; Mon, 27 Jul 2015 11:22:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752063AbbG0LWv (ORCPT ); Mon, 27 Jul 2015 07:22:51 -0400 Received: from mail.kapsi.fi ([217.30.184.167]:39853 "EHLO mail.kapsi.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752233AbbG0LWq (ORCPT ); Mon, 27 Jul 2015 07:22:46 -0400 Received: from 85-23-164-218.bb.dnainternet.fi ([85.23.164.218] helo=localhost.localdomain.localdomain) by mail.kapsi.fi with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1ZJgUV-0005gW-Vy; Mon, 27 Jul 2015 14:22:44 +0300 From: Antti Palosaari To: linux-media@vger.kernel.org Cc: Antti Palosaari Subject: [PATCH 1/6] mt2060: add i2c bindings Date: Mon, 27 Jul 2015 14:22:05 +0300 Message-Id: <1437996130-23735-2-git-send-email-crope@iki.fi> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1437996130-23735-1-git-send-email-crope@iki.fi> References: <1437996130-23735-1-git-send-email-crope@iki.fi> X-SA-Exim-Connect-IP: 85.23.164.218 X-SA-Exim-Mail-From: crope@iki.fi X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false 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.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 Add proper i2c driver model bindings. Signed-off-by: Antti Palosaari --- drivers/media/tuners/mt2060.c | 83 ++++++++++++++++++++++++++++++++++++++ drivers/media/tuners/mt2060.h | 20 +++++++++ drivers/media/tuners/mt2060_priv.h | 2 + 3 files changed, 105 insertions(+) diff --git a/drivers/media/tuners/mt2060.c b/drivers/media/tuners/mt2060.c index b87b254..aa8280a 100644 --- a/drivers/media/tuners/mt2060.c +++ b/drivers/media/tuners/mt2060.c @@ -397,6 +397,89 @@ struct dvb_frontend * mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter } EXPORT_SYMBOL(mt2060_attach); +static int mt2060_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct mt2060_platform_data *pdata = client->dev.platform_data; + struct dvb_frontend *fe; + struct mt2060_priv *dev; + int ret; + u8 chip_id; + + dev_dbg(&client->dev, "\n"); + + if (!pdata) { + dev_err(&client->dev, "Cannot proceed without platform data\n"); + ret = -EINVAL; + goto err; + } + + dev = devm_kzalloc(&client->dev, sizeof(*dev), GFP_KERNEL); + if (!dev) { + ret = -ENOMEM; + goto err; + } + + fe = pdata->dvb_frontend; + dev->config.i2c_address = client->addr; + dev->config.clock_out = pdata->clock_out; + dev->cfg = &dev->config; + dev->i2c = client->adapter; + dev->if1_freq = pdata->if1 ? pdata->if1 : 1220; + dev->client = client; + + ret = mt2060_readreg(dev, REG_PART_REV, &chip_id); + if (ret) { + ret = -ENODEV; + goto err; + } + + dev_dbg(&client->dev, "chip id=%02x\n", chip_id); + + if (chip_id != PART_REV) { + ret = -ENODEV; + goto err; + } + + dev_info(&client->dev, "Microtune MT2060 successfully identified\n"); + memcpy(&fe->ops.tuner_ops, &mt2060_tuner_ops, sizeof(fe->ops.tuner_ops)); + fe->ops.tuner_ops.release = NULL; + fe->tuner_priv = dev; + i2c_set_clientdata(client, dev); + + mt2060_calibrate(dev); + + return 0; +err: + dev_dbg(&client->dev, "failed=%d\n", ret); + return ret; +} + +static int mt2060_remove(struct i2c_client *client) +{ + dev_dbg(&client->dev, "\n"); + + return 0; +} + +static const struct i2c_device_id mt2060_id_table[] = { + {"mt2060", 0}, + {} +}; +MODULE_DEVICE_TABLE(i2c, mt2060_id_table); + +static struct i2c_driver mt2060_driver = { + .driver = { + .name = "mt2060", + .suppress_bind_attrs = true, + }, + .probe = mt2060_probe, + .remove = mt2060_remove, + .id_table = mt2060_id_table, +}; + +module_i2c_driver(mt2060_driver); + MODULE_AUTHOR("Olivier DANET"); MODULE_DESCRIPTION("Microtune MT2060 silicon tuner driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/media/tuners/mt2060.h b/drivers/media/tuners/mt2060.h index 6efed35..05c0d55 100644 --- a/drivers/media/tuners/mt2060.h +++ b/drivers/media/tuners/mt2060.h @@ -25,6 +25,26 @@ struct dvb_frontend; struct i2c_adapter; +/* + * I2C address + * 0x60, ... + */ + +/** + * struct mt2060_platform_data - Platform data for the mt2060 driver + * @clock_out: Clock output setting. 0 = off, 1 = CLK/4, 2 = CLK/2, 3 = CLK/1. + * @if1: First IF used [MHz]. 0 defaults to 1220. + * @dvb_frontend: DVB frontend. + */ + +struct mt2060_platform_data { + u8 clock_out; + u16 if1; + struct dvb_frontend *dvb_frontend; +}; + + +/* configuration struct for mt2060_attach() */ struct mt2060_config { u8 i2c_address; u8 clock_out; /* 0 = off, 1 = CLK/4, 2 = CLK/2, 3 = CLK/1 */ diff --git a/drivers/media/tuners/mt2060_priv.h b/drivers/media/tuners/mt2060_priv.h index 2b60de6..dfc4a06 100644 --- a/drivers/media/tuners/mt2060_priv.h +++ b/drivers/media/tuners/mt2060_priv.h @@ -95,6 +95,8 @@ struct mt2060_priv { struct mt2060_config *cfg; struct i2c_adapter *i2c; + struct i2c_client *client; + struct mt2060_config config; u32 frequency; u16 if1_freq;