From patchwork Tue Jun 26 06:30:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Ranostay X-Patchwork-Id: 10488037 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3B8E560386 for ; Tue, 26 Jun 2018 06:30:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 272DF2893B for ; Tue, 26 Jun 2018 06:30:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 137CF28A89; Tue, 26 Jun 2018 06:30:59 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 9308F2881E for ; Tue, 26 Jun 2018 06:30:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751884AbeFZGa3 (ORCPT ); Tue, 26 Jun 2018 02:30:29 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:33516 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751639AbeFZGa2 (ORCPT ); Tue, 26 Jun 2018 02:30:28 -0400 Received: by mail-pg0-f67.google.com with SMTP id e11-v6so7192942pgq.0 for ; Mon, 25 Jun 2018 23:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=from:to:cc:subject:date:message-id; bh=qse4i1dikEHKAZZL3C01X+JBy2RHadE7mb8sU7iQRNQ=; b=pB4Pg72JGV74grqTPLlOSKoEqzT0mT8j9kbE2vZOC0Y8kY7VqHCkF7evY8rAkZ8OfH wU3+qykcqsfK31h7E8BP6JV9RjjHbNtfQ3il6/siA1Gkj6o0Rzd5heva2k74vO1unPGH ElLYoOjv0Xvd+X0nWdZrldBequYTLpUbUqa5I= 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; bh=qse4i1dikEHKAZZL3C01X+JBy2RHadE7mb8sU7iQRNQ=; b=C14CHo/MWXXRLAXTeW1G6wjKIHn0B5OYVUN9/nth62smne/hdTHHS0D0+BjawON7V/ xQN6ISClM8UuJhkqBQPRsnB0oojekkROB3MrBRHcqCHOd1XArmRk9ZnczLEVqfmmYlTK Pa40T1FBEj5lXUyjF6TZdiyotcPlLCYnf9y8XyAj9PP6Ij0kYcfq+ekQ7NTYJyvBlTSR ZI9EZ1uitUGO/imsyqR889aV53vp4xx7Fcn6KmTgm6ep2ryjDKrs2tZcWUKo1eGXd7Rs SvemSIV7g5YmQTaZm9wGm6LBIGlj6h4mhiE1kzVr5ldbD/l1sEaChnX4bcPb7+fJEN1+ kwCA== X-Gm-Message-State: APt69E2V3RCRkcnmYXCHt18zLUdkUj3Ztr3QdVqdHIknYe8lYepcZyfo 708RzkLkVvImabeKnY/AERU2YeoJdtI= X-Google-Smtp-Source: ADUXVKJRUSSxNSgpD2OVg9X4VW/PrmUSqrAPavrjSheoOVmjkQp7m8gUS6ksaWNUiefgt8Pk85SVDg== X-Received: by 2002:a65:494b:: with SMTP id q11-v6mr201545pgs.105.1529994628022; Mon, 25 Jun 2018 23:30:28 -0700 (PDT) Received: from niteshade.hsd1.or.comcast.net ([2601:1c2:5000:8d45::3f0e]) by smtp.gmail.com with ESMTPSA id b4-v6sm977656pgq.51.2018.06.25.23.30.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jun 2018 23:30:27 -0700 (PDT) From: Matt Ranostay To: linux-media@vger.kernel.org Cc: Matt Ranostay , linux-hwmon@vger.kernel.org Subject: [PATCH] media: video-i2c: add hwmon support for amg88xx Date: Mon, 25 Jun 2018 23:30:25 -0700 Message-Id: <20180626063025.7778-1-matt.ranostay@konsulko.com> X-Mailer: git-send-email 2.17.1 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP AMG88xx has an on-board thermistor which is used for more accurate processing of its temperature readings from the 8x8 thermopile array Cc: linux-hwmon@vger.kernel.org Signed-off-by: Matt Ranostay --- drivers/media/i2c/video-i2c.c | 73 +++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/drivers/media/i2c/video-i2c.c b/drivers/media/i2c/video-i2c.c index 0b347cc19aa5..16c3e03af219 100644 --- a/drivers/media/i2c/video-i2c.c +++ b/drivers/media/i2c/video-i2c.c @@ -10,6 +10,8 @@ #include #include +#include +#include #include #include #include @@ -77,6 +79,9 @@ struct video_i2c_chip { /* xfer function */ int (*xfer)(struct video_i2c_data *data, char *buf); + + /* hwmon init function */ + int (*hwmon_init)(struct video_i2c_data *data); }; static int amg88xx_xfer(struct video_i2c_data *data, char *buf) @@ -101,6 +106,70 @@ static int amg88xx_xfer(struct video_i2c_data *data, char *buf) return (ret == 2) ? 0 : -EIO; } +#if defined(CONFIG_HWMON) || (defined(MODULE) && defined(CONFIG_HWMON_MODULE)) + +static const u32 amg88xx_temp_config[] = { + HWMON_T_INPUT, + 0 +}; + +static const struct hwmon_channel_info amg88xx_temp = { + .type = hwmon_temp, + .config = amg88xx_temp_config, +}; + +static const struct hwmon_channel_info *amg88xx_info[] = { + &amg88xx_temp, + NULL +}; + +static umode_t amg88xx_is_visible(const void *drvdata, + enum hwmon_sensor_types type, + u32 attr, int channel) +{ + return 0444; +} + +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); + + if (tmp < 0) + return -EINVAL; + + /* check for sign bit, and invert temp reading to a negative value */ + if (0x800 & tmp) + tmp = -(tmp & 0x7ff); + + *val = (tmp * 625) / 10; + + return 0; +} + +static const struct hwmon_ops amg88xx_hwmon_ops = { + .is_visible = amg88xx_is_visible, + .read = amg88xx_read, +}; + +static const struct hwmon_chip_info amg88xx_chip_info = { + .ops = &amg88xx_hwmon_ops, + .info = amg88xx_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); + + return IS_ERR(hwmon); +} +#else +#define amg88xx_hwmon_init NULL +#endif + #define AMG88XX 0 static const struct video_i2c_chip video_i2c_chip[] = { @@ -111,6 +180,7 @@ static const struct video_i2c_chip video_i2c_chip[] = { .buffer_size = 128, .bpp = 16, .xfer = &amg88xx_xfer, + .hwmon_init = &amg88xx_hwmon_init, }, }; @@ -505,6 +575,9 @@ static int video_i2c_probe(struct i2c_client *client, video_set_drvdata(&data->vdev, data); i2c_set_clientdata(client, data); + if (data->chip->hwmon_init) + data->chip->hwmon_init(data); + ret = video_register_device(&data->vdev, VFL_TYPE_GRABBER, -1); if (ret < 0) goto error_unregister_device;