From patchwork Sun Sep 23 16:34:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10611817 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1502D13A4 for ; Sun, 23 Sep 2018 16:35:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 000A52925E for ; Sun, 23 Sep 2018 16:35:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8889292ED; Sun, 23 Sep 2018 16:35:18 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,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 51C412925E for ; Sun, 23 Sep 2018 16:35:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726437AbeIWWdT (ORCPT ); Sun, 23 Sep 2018 18:33:19 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:46939 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726230AbeIWWdT (ORCPT ); Sun, 23 Sep 2018 18:33:19 -0400 Received: by mail-pl1-f193.google.com with SMTP id v19-v6so388883ply.13 for ; Sun, 23 Sep 2018 09:35:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QW6YC/O6XJd39htXy14C0r1cJPhxfBFB2G+R8wc+oz8=; b=UGY6PBibrFrP+mWLxTpFBCz5TT07Pr8saEUkeVEAUn5AA65CeJPrVtXlNOGhpeI0m7 b2QW8e0pfhN9tUNANKwgACcZWX8f+fJgj/occHuz0oU2n4p+UpxMlxjuqicTLlHfn+ed wppLlAiji049+eqEe3Pw/wGAI512bhy4Z/d0gaGX/P/MVwV+o9vjHDAJgWu3msPnXKs2 WmtrF8mqLcVz/x4K0wB4BlzQXr+eFfbEQ9mPiPmp0TsbMnheA9ZCek1oQmvXKxE1YncS dyX3Qt4IiDRhEOJ+lmnw4Gf4iQqstoKe2rCKs1IheD5G8228v6Bpm5n2L/5UKr2BhJcm Xo6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QW6YC/O6XJd39htXy14C0r1cJPhxfBFB2G+R8wc+oz8=; b=fuXX5FOz0sqjCHw/94NgCYKL8XqsTjKUzyoxQmyIJXtlSwotfNCHa8ycfsuMYkxXiJ UJ2YO9ccsCmf2DswJpFEGKQbhZ9gGLy/2cmix5vNfIeCRf+2z6dZwcl/Yt6c7Jj2YSun nIVnU9tBEXsu8UBslK2EOe78p5rdsGt/cRSYlPuzGuYeklqOsThM0ukSh0s3NEMmIjtj i3QW1nLg70tT7Ik7xPtlewlBg1dmIsQj5WnT8Ah/oROwq+pqL8rpCsvn4jGh2enviUg4 gCG6rwpvfWaRLDT9ei3ILRRJIwasFl/7KIP/XRwFVvAmV5NVD/8IADa2k+Rk8+EiPQKV rP1w== X-Gm-Message-State: ABuFfojSajO1PARpl5TZvnrEhHFBsS/E0bPiwx9LSjlVWSiOseeToMAe t9r66rPt4+gU4Qs9WsoLBX5LE3Yb X-Google-Smtp-Source: ACcGV62u7X9hEo+UIe4gnLl1kmoO0HEnpSWiAWffoUtaUOnaJAjRCUqzoEcK/bbfjHb8MPsRedKKxA== X-Received: by 2002:a17:902:44:: with SMTP id 62-v6mr7121346pla.181.1537720515328; Sun, 23 Sep 2018 09:35:15 -0700 (PDT) Received: from mita-MS-7A45.lan ([240f:34:212d:1:9f:aa8:eeac:60f7]) by smtp.gmail.com with ESMTPSA id d129-v6sm18286250pga.69.2018.09.23.09.35.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Sep 2018 09:35:14 -0700 (PDT) From: Akinobu Mita To: linux-media@vger.kernel.org Cc: Akinobu Mita , Matt Ranostay , Sakari Ailus , Hans Verkuil , Mauro Carvalho Chehab Subject: [PATCH v2 2/6] media: video-i2c: use i2c regmap Date: Mon, 24 Sep 2018 01:34:48 +0900 Message-Id: <1537720492-31201-3-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1537720492-31201-1-git-send-email-akinobu.mita@gmail.com> References: <1537720492-31201-1-git-send-email-akinobu.mita@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 Use regmap for i2c register access. This simplifies register accesses and chooses suitable access commands based on the functionality that the adapter supports. Cc: Matt Ranostay Cc: Sakari Ailus Cc: Hans Verkuil Cc: Mauro Carvalho Chehab Signed-off-by: Akinobu Mita Acked-by: Matt Ranostay --- * v2 - Add thermistor and termperature register address definisions drivers/media/i2c/video-i2c.c | 60 ++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c index b7a2af9..fb8509e 100644 --- a/drivers/media/i2c/video-i2c.c +++ b/drivers/media/i2c/video-i2c.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -38,7 +39,7 @@ struct video_i2c_buffer { }; struct video_i2c_data { - struct i2c_client *client; + struct regmap *regmap; const struct video_i2c_chip *chip; struct mutex lock; spinlock_t slock; @@ -62,6 +63,12 @@ static const struct v4l2_frmsize_discrete amg88xx_size = { .height = 8, }; +static const struct regmap_config amg88xx_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = 0xff +}; + struct video_i2c_chip { /* video dimensions */ const struct v4l2_fmtdesc *format; @@ -76,6 +83,8 @@ struct video_i2c_chip { /* pixel size in bits */ unsigned int bpp; + const struct regmap_config *regmap_config; + /* xfer function */ int (*xfer)(struct video_i2c_data *data, char *buf); @@ -83,26 +92,16 @@ struct video_i2c_chip { int (*hwmon_init)(struct video_i2c_data *data); }; -static int amg88xx_xfer(struct video_i2c_data *data, char *buf) -{ - struct i2c_client *client = data->client; - struct i2c_msg msg[2]; - u8 reg = 0x80; - int ret; - - msg[0].addr = client->addr; - msg[0].flags = 0; - msg[0].len = 1; - msg[0].buf = (char *)® - - msg[1].addr = client->addr; - msg[1].flags = I2C_M_RD; - msg[1].len = data->chip->buffer_size; - msg[1].buf = (char *)buf; +/* Thermistor register */ +#define AMG88XX_REG_TTHL 0x0e - ret = i2c_transfer(client->adapter, msg, 2); +/* Temperature register */ +#define AMG88XX_REG_T01L 0x80 - return (ret == 2) ? 0 : -EIO; +static int amg88xx_xfer(struct video_i2c_data *data, char *buf) +{ + return regmap_bulk_read(data->regmap, AMG88XX_REG_T01L, buf, + data->chip->buffer_size); } #if IS_ENABLED(CONFIG_HWMON) @@ -133,12 +132,15 @@ static int amg88xx_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, int channel, long *val) { struct video_i2c_data *data = dev_get_drvdata(dev); - struct i2c_client *client = data->client; - int tmp = i2c_smbus_read_word_data(client, 0x0e); + __le16 buf; + int tmp; - if (tmp < 0) + tmp = regmap_bulk_read(data->regmap, AMG88XX_REG_TTHL, &buf, 2); + if (tmp) return tmp; + tmp = le16_to_cpu(buf); + /* * Check for sign bit, this isn't a two's complement value but an * absolute temperature that needs to be inverted in the case of being @@ -164,8 +166,9 @@ static const struct hwmon_chip_info amg88xx_chip_info = { static int amg88xx_hwmon_init(struct video_i2c_data *data) { - void *hwmon = devm_hwmon_device_register_with_info(&data->client->dev, - "amg88xx", data, &amg88xx_chip_info, NULL); + struct device *dev = regmap_get_device(data->regmap); + void *hwmon = devm_hwmon_device_register_with_info(dev, "amg88xx", data, + &amg88xx_chip_info, NULL); return PTR_ERR_OR_ZERO(hwmon); } @@ -182,6 +185,7 @@ static const struct video_i2c_chip video_i2c_chip[] = { .max_fps = 10, .buffer_size = 128, .bpp = 16, + .regmap_config = &amg88xx_regmap_config, .xfer = &amg88xx_xfer, .hwmon_init = amg88xx_hwmon_init, }, @@ -350,7 +354,8 @@ static int video_i2c_querycap(struct file *file, void *priv, struct v4l2_capability *vcap) { struct video_i2c_data *data = video_drvdata(file); - struct i2c_client *client = data->client; + struct device *dev = regmap_get_device(data->regmap); + struct i2c_client *client = to_i2c_client(dev); strlcpy(vcap->driver, data->v4l2_dev.name, sizeof(vcap->driver)); strlcpy(vcap->card, data->vdev.name, sizeof(vcap->card)); @@ -527,7 +532,10 @@ static int video_i2c_probe(struct i2c_client *client, else return -ENODEV; - data->client = client; + data->regmap = devm_regmap_init_i2c(client, data->chip->regmap_config); + if (IS_ERR(data->regmap)) + return PTR_ERR(data->regmap); + v4l2_dev = &data->v4l2_dev; strlcpy(v4l2_dev->name, VIDEO_I2C_DRIVER, sizeof(v4l2_dev->name));