From patchwork Tue Sep 15 16:50:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Punit Agrawal X-Patchwork-Id: 53690 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by patches.linaro.org (Postfix) with ESMTPS id B693A22A0D for ; Tue, 15 Sep 2015 16:52:49 +0000 (UTC) Received: by lagj9 with SMTP id j9sf66519254lag.0 for ; Tue, 15 Sep 2015 09:52:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=u5MuzbLWL8RlJivT2vee00JBEs4Wdjh3NwA/wDZMtnE=; b=FP3gp4Gvdnghx6vCN6p1vKpxdzj42nML1pN9q0qPMC2EjDH9eAJScAZV65g6WwQKrK xG3l8P0VQwTv/WyfWeGs+R0pNcpYf/vnlww6cjnNnWFNGSvoQi/AHMy3bEqaTjX+/ZbM psj9A95QwMQsoRVbULpnewIymKG3gi2hixYXbIVV6qPcd7C5khEvBjXdKN4v3AI/LVSL AHWvCDWsakc9HeM3yom0/S4YhPz39c2KfF0v2/KIQdVodpJJm9da5ohbdkjNVh7pSM6r nvRswN7x4m7ebPWUL+20KRkGYn6Yo/1wnHXKwdy8vZpPYN12Z50SGOzHudlifH2MO+PS 7P4g== X-Gm-Message-State: ALoCoQlOt0bsa/ugMEHltiGiANeMsEE12Y6wfcR0G//lkDk5Z+yYnywyBX317edIt2fGf227um6x X-Received: by 10.152.29.10 with SMTP id f10mr2240415lah.1.1442335968730; Tue, 15 Sep 2015 09:52:48 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.100 with SMTP id s4ls813211lag.83.gmail; Tue, 15 Sep 2015 09:52:48 -0700 (PDT) X-Received: by 10.112.85.204 with SMTP id j12mr22343643lbz.47.1442335968424; Tue, 15 Sep 2015 09:52:48 -0700 (PDT) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id mu6si14828300lbc.88.2015.09.15.09.52.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Sep 2015 09:52:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbbmp1 with SMTP id mp1so88847964lbb.1 for ; Tue, 15 Sep 2015 09:52:48 -0700 (PDT) X-Received: by 10.112.166.106 with SMTP id zf10mr22828084lbb.36.1442335968299; Tue, 15 Sep 2015 09:52:48 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp1919417lbq; Tue, 15 Sep 2015 09:52:47 -0700 (PDT) X-Received: by 10.68.235.99 with SMTP id ul3mr49746197pbc.138.1442335967171; Tue, 15 Sep 2015 09:52:47 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id nv1si33204916pbc.145.2015.09.15.09.52.43; Tue, 15 Sep 2015 09:52:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753552AbbIOQwi (ORCPT + 29 others); Tue, 15 Sep 2015 12:52:38 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.140]:56653 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752108AbbIOQwf (ORCPT ); Tue, 15 Sep 2015 12:52:35 -0400 Received: from e105922-lin.cambridge.arm.com (e105922-lin.cambridge.arm.com [10.2.135.144]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with SMTP id t8FGq1Sn002983; Tue, 15 Sep 2015 17:52:01 +0100 Received: by e105922-lin.cambridge.arm.com (sSMTP sendmail emulation); Tue, 15 Sep 2015 17:52:01 +0100 From: Punit Agrawal To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: linux-kernel@vger.kernel.org, mark.rutland@arm.com, robh+dt@kernel.org, edubezval@gmail.com, sudeep.holla@arm.com, liviu.dudau@arm.com, linux@roeck-us.net, Punit Agrawal Subject: [PATCH v4 2/5] firmware: arm_scpi: Extend to support sensors Date: Tue, 15 Sep 2015 17:50:58 +0100 Message-Id: <1442335861-7282-3-git-send-email-punit.agrawal@arm.com> X-Mailer: git-send-email 2.5.1 In-Reply-To: <1442335861-7282-1-git-send-email-punit.agrawal@arm.com> References: <1442335861-7282-1-git-send-email-punit.agrawal@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: punit.agrawal@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , ARM System Control Processor (SCP) provides an API to query and use the sensors available in the system. Extend the SCPI driver to support sensor messages. Signed-off-by: Punit Agrawal Cc: Sudeep Holla Acked-by: Sudeep Holla --- drivers/firmware/arm_scpi.c | 60 +++++++++++++++++++++++++++++++++++++++++++ include/linux/scpi_protocol.h | 17 ++++++++++++ 2 files changed, 77 insertions(+) diff --git a/drivers/firmware/arm_scpi.c b/drivers/firmware/arm_scpi.c index cb75c75..321680e 100644 --- a/drivers/firmware/arm_scpi.c +++ b/drivers/firmware/arm_scpi.c @@ -219,6 +219,21 @@ struct dvfs_set { u8 index; } __packed; +struct sensor_capabilities { + __le16 sensors; +} __packed; + +struct _scpi_sensor_info { + __le16 sensor_id; + u8 class; + u8 trigger_type; + char name[20]; +}; + +struct sensor_value { + __le32 val; +} __packed; + static struct scpi_drvinfo *scpi_info; static int scpi_linux_errmap[SCPI_ERR_MAX] = { @@ -481,6 +496,48 @@ static struct scpi_dvfs_info *scpi_dvfs_get_info(u8 domain) return info; } +static int scpi_sensor_get_capability(u16 *sensors) +{ + struct sensor_capabilities cap_buf; + int ret; + + ret = scpi_send_message(SCPI_CMD_SENSOR_CAPABILITIES, NULL, 0, &cap_buf, + sizeof(cap_buf)); + if (!ret) + *sensors = le16_to_cpu(cap_buf.sensors); + + return ret; +} + +static int scpi_sensor_get_info(u16 sensor_id, struct scpi_sensor_info *info) +{ + __le16 id = cpu_to_le16(sensor_id); + struct _scpi_sensor_info _info; + int ret; + + ret = scpi_send_message(SCPI_CMD_SENSOR_INFO, &id, + sizeof(id), &_info, sizeof(_info)); + if (!ret) { + memcpy(info, &_info, sizeof(*info)); + info->sensor_id = le16_to_cpu(_info.sensor_id); + } + + return ret; +} + +int scpi_sensor_get_value(u16 sensor, u32 *val) +{ + struct sensor_value buf; + int ret; + + ret = scpi_send_message(SCPI_CMD_SENSOR_VALUE, &sensor, sizeof(sensor), + &buf, sizeof(buf)); + if (!ret) + *val = le32_to_cpu(buf.val); + + return ret; +} + static struct scpi_ops scpi_ops = { .get_version = scpi_get_version, .clk_get_range = scpi_clk_get_range, @@ -489,6 +546,9 @@ static struct scpi_ops scpi_ops = { .dvfs_get_idx = scpi_dvfs_get_idx, .dvfs_set_idx = scpi_dvfs_set_idx, .dvfs_get_info = scpi_dvfs_get_info, + .sensor_get_capability = scpi_sensor_get_capability, + .sensor_get_info = scpi_sensor_get_info, + .sensor_get_value = scpi_sensor_get_value, }; struct scpi_ops *get_scpi_ops(void) diff --git a/include/linux/scpi_protocol.h b/include/linux/scpi_protocol.h index e7169cd..80af3cd 100644 --- a/include/linux/scpi_protocol.h +++ b/include/linux/scpi_protocol.h @@ -28,6 +28,20 @@ struct scpi_dvfs_info { struct scpi_opp *opps; }; +enum scpi_sensor_class { + TEMPERATURE, + VOLTAGE, + CURRENT, + POWER, +}; + +struct scpi_sensor_info { + u16 sensor_id; + u8 class; + u8 trigger_type; + char name[20]; +} __packed; + /** * struct scpi_ops - represents the various operations provided * by SCP through SCPI message protocol @@ -52,6 +66,9 @@ struct scpi_ops { int (*dvfs_get_idx)(u8); int (*dvfs_set_idx)(u8, u8); struct scpi_dvfs_info *(*dvfs_get_info)(u8); + int (*sensor_get_capability)(u16 *sensors); + int (*sensor_get_info)(u16 sensor_id, struct scpi_sensor_info *); + int (*sensor_get_value)(u16, u32 *); }; #if IS_ENABLED(CONFIG_ARM_SCPI_PROTOCOL)