From patchwork Mon Sep 17 16:03:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 10602985 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 19F3C13AD for ; Mon, 17 Sep 2018 16:03:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0728528E16 for ; Mon, 17 Sep 2018 16:03:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF38A290BD; Mon, 17 Sep 2018 16:03:31 +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 772A328E16 for ; Mon, 17 Sep 2018 16:03:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728269AbeIQVba (ORCPT ); Mon, 17 Sep 2018 17:31:30 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:43594 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726979AbeIQVb3 (ORCPT ); Mon, 17 Sep 2018 17:31:29 -0400 Received: by mail-pf1-f195.google.com with SMTP id j26-v6so7759592pfi.10 for ; Mon, 17 Sep 2018 09:03:30 -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=q//dDXv1IbyrirsfzSDl4hRjoUfCgVMnB6dkWr+GH6Y=; b=A/vMACV0JsGCTD4yvgm8N4LluGNMKaj17oqsJTKHLaqO0oAMKC52RGURz9e3e8kRl/ Pm+Su120vDQ/dGiHqCfrL40ocbyyq036r71X0ce+jDO51LNSe9oYJNSOwt6cjt44g9y+ EaO7RMyIlnc3/G2pO8CHpxUD+ipwHKYAGvVO21GjLx7bB51wkNkFavU26IxyMzalfTJw ZCIlj65Fo7n3LRBwNdkfZ9I4DWY8dflQnUci04Ti8AiCAiyimspeTZ/EIWuw4yUrTmW/ ISPOhmiyRjo7Go76R6kpp9lXFm8HLNgdHmka6VZoD7VfBPjESz5QsTS/vquHgwe+GYkF 5MNg== 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=q//dDXv1IbyrirsfzSDl4hRjoUfCgVMnB6dkWr+GH6Y=; b=oQA8l1Tg03KI9Chdvmx0CxYL6vq/KjpU2r3MoTQKC1WH8khfaUW2G13/R1B0CcXOoq q1uLdU7xGMwi+afVb7kHtS6QPph7OX/wIyTdIiBVw+JZzZNXbOnn7mNnvJZJ3l4T1T9v BsU4saMWu9tNQPJ+AwDG+tX2zWFxq2lfovYhmIbaHyR8H6eCdZsKx6VNepesfOFQvDnR qqEnDYBiffps39z9ZnI8RdaSN8pNd9vG7h1uESYm80Z+2UzcDMzwhMWVOoU7PV5WggJd nNSvv7UpMefgTIQvGXHJWod0koWEjjBq3a8kUUpRW0Q240UKrIjoika0kFMp5NmEEEyW GYYw== X-Gm-Message-State: APzg51B/bG9aD4Sjx15+mHTe4khD1LdJbyJ6VUmMFLYhRGT7zMVmlYGp aaMF3/+A9HJYiWdtxwk0cQRSHlEf X-Google-Smtp-Source: ANB0VdbIHlsFG1lYkdNEyYiu8E1SCSLMVn2b4bLo5rbhSxA6RGPsFIV/h+VCmkMgcbI+O/iJ09VH3w== X-Received: by 2002:a63:2906:: with SMTP id p6-v6mr23910524pgp.204.1537200209744; Mon, 17 Sep 2018 09:03:29 -0700 (PDT) Received: from mita-MS-7A45.lan ([240f:34:212d:1:f447:4113:b862:c2f5]) by smtp.gmail.com with ESMTPSA id p3-v6sm20088607pfo.130.2018.09.17.09.03.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Sep 2018 09:03:29 -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 2/5] media: video-i2c: use i2c regmap Date: Tue, 18 Sep 2018 01:03:08 +0900 Message-Id: <1537200191-17956-3-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1537200191-17956-1-git-send-email-akinobu.mita@gmail.com> References: <1537200191-17956-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 --- drivers/media/i2c/video-i2c.c | 54 ++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c index b7a2af9..90d389b 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); @@ -85,24 +94,8 @@ struct video_i2c_chip { 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; - - ret = i2c_transfer(client->adapter, msg, 2); - - return (ret == 2) ? 0 : -EIO; + return regmap_bulk_read(data->regmap, 0x80, buf, + data->chip->buffer_size); } #if IS_ENABLED(CONFIG_HWMON) @@ -133,12 +126,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, 0x0e, &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 +160,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 +179,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 +348,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 +526,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));