From patchwork Mon Sep 14 13:00:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Punit Agrawal X-Patchwork-Id: 53548 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by patches.linaro.org (Postfix) with ESMTPS id A411322B17 for ; Mon, 14 Sep 2015 13:05:41 +0000 (UTC) Received: by lamf6 with SMTP id f6sf11215034lam.1 for ; Mon, 14 Sep 2015 06:05:40 -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=GyoXpn60UfjMYWCUHx/ZsVaR39pBLfoS8Ki4ikSrq2Y=; b=W5gIztzdq0bm1Odx0CgAZi3oy1lLEpf51JpGBwV9xBO/c+5xUfjT50JGOny0nK0Daf +1hl80pybn7f60jjtpiBhkqGJF6+jHsCnvCvqWpr3n/kNoOGIGiCtYF7M+opOD3WzThI msM0T7DGA5Ew88XNB/7IpHY5bT1ftDs1vl574v1iQZR5FVHJCZimwpooqz+jMmF3yBZk uuE1xUNb4nRIdl21HTaRQNHQaI2p1Lya/jD7rCUpID4iIo+Q/WnkelHbuVa9RK4Yf7HV clfA5wavpA5OKUo1R935OkSkhTyP6k94+kk0t41ZSk4S9olS9XW5jHoAUO9X9N83os4B BomA== X-Gm-Message-State: ALoCoQlciVBvxfuFz2+cR5ebkr5jJeDh4cbk/lrCtGUZkB3+veVhzLxRZopyLRPgIjdCdbooOt/w X-Received: by 10.152.21.233 with SMTP id y9mr3039711lae.5.1442235940331; Mon, 14 Sep 2015 06:05:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.22.202 with SMTP id g10ls417610laf.29.gmail; Mon, 14 Sep 2015 06:05:40 -0700 (PDT) X-Received: by 10.112.158.1 with SMTP id wq1mr13442233lbb.67.1442235940150; Mon, 14 Sep 2015 06:05:40 -0700 (PDT) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id qd10si9651473lbb.77.2015.09.14.06.05.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2015 06:05:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by lagj9 with SMTP id j9so87356111lag.2 for ; Mon, 14 Sep 2015 06:05:40 -0700 (PDT) X-Received: by 10.152.37.135 with SMTP id y7mr11795733laj.106.1442235939971; Mon, 14 Sep 2015 06:05:39 -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 w3csp1189429lbq; Mon, 14 Sep 2015 06:05:37 -0700 (PDT) X-Received: by 10.69.12.162 with SMTP id er2mr34244240pbd.24.1442235937657; Mon, 14 Sep 2015 06:05:37 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w13si23290506pas.205.2015.09.14.06.05.35; Mon, 14 Sep 2015 06:05:37 -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 S1754965AbbINNFW (ORCPT + 29 others); Mon, 14 Sep 2015 09:05:22 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.140]:59024 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754546AbbINNFR (ORCPT ); Mon, 14 Sep 2015 09:05:17 -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 t8ED39t2022524; Mon, 14 Sep 2015 14:03:09 +0100 Received: by e105922-lin.cambridge.arm.com (sSMTP sendmail emulation); Mon, 14 Sep 2015 14:04:37 +0100 From: Punit Agrawal To: linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Cc: sudeep.holla@arm.com, linux-pm@vger.kernel.org, lm-sensors@lm-sensors.org, liviu.dudau@arm.com, edubezval@gmail.com, mark.rutland@arm.com, linux@roeck-us.net, linux-kernel@vger.kernel.org, robh+dt@kernel.org, Punit Agrawal Subject: [PATCH v3 2/5] firmware: arm_scpi: Extend to support sensors Date: Mon, 14 Sep 2015 14:00:15 +0100 Message-Id: <1442235619-4029-3-git-send-email-punit.agrawal@arm.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1442235619-4029-1-git-send-email-punit.agrawal@arm.com> References: <1442235619-4029-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.215.52 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 --- 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)