Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3293181pxb; Fri, 12 Feb 2021 14:39:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJycLlQ0NO3E61VvmbB3siAWh+3F66vr8ebqXIU4JnLyqXHTLiN4t73nTsd9Qj/Dp5hxQSv0 X-Received: by 2002:a17:906:2b15:: with SMTP id a21mr5142059ejg.338.1613169549413; Fri, 12 Feb 2021 14:39:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613169549; cv=none; d=google.com; s=arc-20160816; b=kQMBvR7PsaIomgAiNARKxNWpeszN2bap8MYjLSjdzguzm1T9T0zVTWD2Ob0u8YUdLM E0/zfIJjpmqK4T8ittQSgRkutOdi2BpbPEKTpD9Zn0bnzRDLSz4ixwAcG/yTAoIrN+BR 6VKP5n+9cJlScvF5/PN3kphvhsbjOgevrN90BG/VSNF448pCTUMjql5IHHJkz/QuieGx 5fG4e2VivLXWFgf/dFiUFlLOwNaFewA7VgKt+5bbxoBbRxuIoXc/Th9BvzgH3PyXDqGK gXPdAbgRQKhaDMCyeRE8HNaSbTqEeUXlO0fkNXrAwGt5E2lAA4KFOqMP+znP6azFpEeF xGuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=PxSbKyv6wqiwG54HSqfDu0MU1VkUVqMjp4s08/jpjZs=; b=0mhZSSo2ciZJhI4DzBixElcXRi38gcgo5lfC5J3JjXWGGsz+DpZYZJdyo88RXVoAro VjJj91B8X7Jc7CJZ6lohSVo4kovyxx5BOVVI8hW7cj9dNzowl+8yP0TU2Sxmvxuch1dJ ou0sfvx69JduEcODm9k8tiO91mtxUCoeBYktFyBsC9FLo6Quuysr65HKpVTiNrCw1GcQ h7jctZuhmzmRohzat0eG34+4mdkI2l5McfMMw+heKTJBALJElvJanS5OQpNsdQQY5Inh +0V96biB/P444QM7LMV4b9Si1620eKwMmS/BV/fR5Ms4UdVtFxxvLLTdfIIKKbG4Ecde BN2A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pk24si7000663ejb.651.2021.02.12.14.38.46; Fri, 12 Feb 2021 14:39:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232338AbhBLWgB (ORCPT + 99 others); Fri, 12 Feb 2021 17:36:01 -0500 Received: from mga09.intel.com ([134.134.136.24]:34762 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232105AbhBLW1M (ORCPT ); Fri, 12 Feb 2021 17:27:12 -0500 IronPort-SDR: 0/FL+gIHPxA9bfGX5Cl94DaV8hAvFeUtL2SSwnq0NhZNf7TE7ySDG8RMJKkJoCKzAu8yHkWqV1 VzNzXaHGQixA== X-IronPort-AV: E=McAfee;i="6000,8403,9893"; a="182616446" X-IronPort-AV: E=Sophos;i="5.81,174,1610438400"; d="scan'208";a="182616446" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2021 14:23:09 -0800 IronPort-SDR: fkUHVDP8+at1vuIMuqMDbvnEwTe7YatITw7S5cJ8gHHcyj9fM11Eny2NN4F6Wjc+3w9OO84ZSi FS6Puk2IGayg== X-IronPort-AV: E=Sophos;i="5.81,174,1610438400"; d="scan'208";a="400012566" Received: from smtp.ostc.intel.com ([10.54.29.231]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2021 14:23:09 -0800 Received: from mtg-dev.jf.intel.com (mtg-dev.jf.intel.com [10.54.74.10]) by smtp.ostc.intel.com (Postfix) with ESMTP id 02E85636E; Fri, 12 Feb 2021 14:23:09 -0800 (PST) Received: by mtg-dev.jf.intel.com (Postfix, from userid 1000) id F04FB36370B; Fri, 12 Feb 2021 14:23:08 -0800 (PST) From: mgross@linux.intel.com To: markgross@kernel.org, mgross@linux.intel.com, arnd@arndb.de, bp@suse.de, damien.lemoal@wdc.com, dragan.cvetic@xilinx.com, gregkh@linuxfoundation.org, corbet@lwn.net, palmerdabbelt@google.com, paul.walmsley@sifive.com, peng.fan@nxp.com, robh+dt@kernel.org, shawnguo@kernel.org, jassisinghbrar@gmail.com Cc: linux-kernel@vger.kernel.org, "C, Udhayakumar" Subject: [PATCH v6 29/34] Intel tsens i2c slave driver. Date: Fri, 12 Feb 2021 14:22:59 -0800 Message-Id: <20210212222304.110194-30-mgross@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210212222304.110194-1-mgross@linux.intel.com> References: <20210212222304.110194-1-mgross@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "C, Udhayakumar" Add Intel tsens i2c slave driver for Intel Edge.AI Computer Vision platforms. The tsens i2c slave driver enables reading of on chip sensors present in the Intel Edge.AI Computer Vision platforms. In the tsens i2c module various junction and SoC temperatures are reported using i2c slave protocol. Signed-off-by: C Udhayakumar Signed-off-by: Mark Gross --- drivers/misc/intel_tsens/Kconfig | 14 +++ drivers/misc/intel_tsens/Makefile | 1 + drivers/misc/intel_tsens/intel_tsens_i2c.c | 119 +++++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 drivers/misc/intel_tsens/intel_tsens_i2c.c diff --git a/drivers/misc/intel_tsens/Kconfig b/drivers/misc/intel_tsens/Kconfig index 8b263fdd80c3..be8d27e81864 100644 --- a/drivers/misc/intel_tsens/Kconfig +++ b/drivers/misc/intel_tsens/Kconfig @@ -14,6 +14,20 @@ config INTEL_TSENS_LOCAL_HOST Say Y if using a processor that includes the Intel VPU such as Keem Bay. If unsure, say N. +config INTEL_TSENS_I2C_SLAVE + bool "I2C slave driver for intel tsens" + depends on INTEL_TSENS_LOCAL_HOST + depends on I2C=y && I2C_SLAVE + help + This option enables tsens I2C slave driver. + + This driver is used for reporting thermal data via I2C + SMBUS to remote host. + Enable this option if you want to have support for thermal + management controller. + Say Y if using a processor that includes the Intel VPU such as + Keem Bay. If unsure, say N. + config INTEL_TSENS_IA_HOST tristate "Temperature sensor driver for intel tsens remote host" depends on I2C && THERMAL diff --git a/drivers/misc/intel_tsens/Makefile b/drivers/misc/intel_tsens/Makefile index 250dc484fb49..f6f41bbca80c 100644 --- a/drivers/misc/intel_tsens/Makefile +++ b/drivers/misc/intel_tsens/Makefile @@ -5,4 +5,5 @@ # obj-$(CONFIG_INTEL_TSENS_LOCAL_HOST) += intel_tsens_thermal.o +obj-$(CONFIG_INTEL_TSENS_I2C_SLAVE) += intel_tsens_i2c.o obj-$(CONFIG_INTEL_TSENS_IA_HOST) += intel_tsens_host.o diff --git a/drivers/misc/intel_tsens/intel_tsens_i2c.c b/drivers/misc/intel_tsens/intel_tsens_i2c.c new file mode 100644 index 000000000000..520c3f4bf392 --- /dev/null +++ b/drivers/misc/intel_tsens/intel_tsens_i2c.c @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * + * Intel tsens I2C thermal Driver + * + * Copyright (C) 2020 Intel Corporation + * + */ + +#include +#include +#include +#include +#include "intel_tsens_thermal.h" + +#define TSENS_BYTE_INDEX_SHIFT 0x6 +#define TSENS_BYTE_INDEX_MASK 0x3 +#define TSENS_SENSOR_TYPE_MASK 0x3F + +struct intel_tsens_i2c { + int sensor_type; + u16 buffer_idx; + bool read_only; + u8 idx_write_cnt; + struct intel_tsens_i2c_plat_data *plat_data; +}; + +static int intel_i2c_tsens_slave_cb(struct i2c_client *client, + enum i2c_slave_event event, u8 *val) +{ + struct intel_tsens_i2c *tsens_i2c = i2c_get_clientdata(client); + struct intel_tsens_i2c_plat_data *plat_data = tsens_i2c->plat_data; + int ret = 0; + + switch (event) { + case I2C_SLAVE_WRITE_RECEIVED: + tsens_i2c->sensor_type = *val; + break; + + case I2C_SLAVE_READ_PROCESSED: + case I2C_SLAVE_READ_REQUESTED: + if (plat_data->get_temp) { + int temp; + int sensor_type = tsens_i2c->sensor_type & + TSENS_SENSOR_TYPE_MASK; + + if (!plat_data->get_temp(sensor_type, &temp, + plat_data->pdata)) { + u8 offset = (tsens_i2c->sensor_type >> + TSENS_BYTE_INDEX_SHIFT) & + TSENS_BYTE_INDEX_MASK; + u8 *ptr_temp = (u8 *)&temp; + + *val = ptr_temp[offset]; + tsens_i2c->buffer_idx++; + ret = 0; + } else { + ret = -EINVAL; + } + } else { + ret = -EINVAL; + } + break; + + case I2C_SLAVE_STOP: + case I2C_SLAVE_WRITE_REQUESTED: + tsens_i2c->idx_write_cnt = 0; + tsens_i2c->buffer_idx = 0; + break; + + default: + break; + } + return ret; +} + +static int intel_i2c_tsens_slave_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ struct intel_tsens_i2c *priv; + int ret; + + if (!id->driver_data) { + dev_err(&client->dev, "No platform data"); + return -EINVAL; + } + priv = devm_kzalloc(&client->dev, + sizeof(struct intel_tsens_i2c), + GFP_KERNEL); + if (!priv) + return -ENOMEM; + priv->plat_data = (struct intel_tsens_i2c_plat_data *)id->driver_data; + i2c_set_clientdata(client, priv); + ret = i2c_slave_register(client, intel_i2c_tsens_slave_cb); + if (ret) + dev_err(&client->dev, "i2c slave register failed\n"); + + return ret; +}; + +static struct i2c_device_id intel_i2c_tsens_slave_id[] = { + { "intel_tsens", (kernel_ulong_t)&i2c_plat_data}, + {} +}; +MODULE_DEVICE_TABLE(i2c, intel_i2c_tsens_slave_id); + +static struct i2c_driver intel_i2c_tsens_slave_driver = { + .driver = { + .name = "intel_tsens", + }, + .probe = intel_i2c_tsens_slave_probe, + .remove = i2c_slave_unregister, + .id_table = intel_i2c_tsens_slave_id, +}; + +module_i2c_driver(intel_i2c_tsens_slave_driver); + +MODULE_AUTHOR("Udhayakumar C "); +MODULE_DESCRIPTION("tsens i2c slave driver"); +MODULE_LICENSE("GPL"); -- 2.17.1