linux-stable/arch/powerpc/platforms/powernv/opal-sensor.c
Thomas Gleixner 1a59d1b8e0 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156
Based on 1 normalized pattern(s):

  this program is free software you can redistribute it and or modify
  it under the terms of the gnu general public license as published by
  the free software foundation either version 2 of the license or at
  your option any later version this program is distributed in the
  hope that it will be useful but without any warranty without even
  the implied warranty of merchantability or fitness for a particular
  purpose see the gnu general public license for more details you
  should have received a copy of the gnu general public license along
  with this program if not write to the free software foundation inc
  59 temple place suite 330 boston ma 02111 1307 usa

extracted by the scancode license scanner the SPDX license identifier

  GPL-2.0-or-later

has been chosen to replace the boilerplate/reference in 1334 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Allison Randal <allison@lohutok.net>
Reviewed-by: Richard Fontana <rfontana@redhat.com>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190527070033.113240726@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-05-30 11:26:35 -07:00

130 lines
2.5 KiB
C

// SPDX-License-Identifier: GPL-2.0-or-later
/*
* PowerNV sensor code
*
* Copyright (C) 2013 IBM
*/
#include <linux/delay.h>
#include <linux/of_platform.h>
#include <asm/opal.h>
#include <asm/machdep.h>
/*
* This will return sensor information to driver based on the requested sensor
* handle. A handle is an opaque id for the powernv, read by the driver from the
* device tree..
*/
int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data)
{
int ret, token;
struct opal_msg msg;
__be32 data;
token = opal_async_get_token_interruptible();
if (token < 0)
return token;
ret = opal_sensor_read(sensor_hndl, token, &data);
switch (ret) {
case OPAL_ASYNC_COMPLETION:
ret = opal_async_wait_response(token, &msg);
if (ret) {
pr_err("%s: Failed to wait for the async response, %d\n",
__func__, ret);
goto out;
}
ret = opal_error_code(opal_get_async_rc(msg));
*sensor_data = be32_to_cpu(data);
break;
case OPAL_SUCCESS:
ret = 0;
*sensor_data = be32_to_cpu(data);
break;
case OPAL_WRONG_STATE:
ret = -EIO;
break;
default:
ret = opal_error_code(ret);
break;
}
out:
opal_async_release_token(token);
return ret;
}
EXPORT_SYMBOL_GPL(opal_get_sensor_data);
int opal_get_sensor_data_u64(u32 sensor_hndl, u64 *sensor_data)
{
int ret, token;
struct opal_msg msg;
__be64 data;
if (!opal_check_token(OPAL_SENSOR_READ_U64)) {
u32 sdata;
ret = opal_get_sensor_data(sensor_hndl, &sdata);
if (!ret)
*sensor_data = sdata;
return ret;
}
token = opal_async_get_token_interruptible();
if (token < 0)
return token;
ret = opal_sensor_read_u64(sensor_hndl, token, &data);
switch (ret) {
case OPAL_ASYNC_COMPLETION:
ret = opal_async_wait_response(token, &msg);
if (ret) {
pr_err("%s: Failed to wait for the async response, %d\n",
__func__, ret);
goto out_token;
}
ret = opal_error_code(opal_get_async_rc(msg));
*sensor_data = be64_to_cpu(data);
break;
case OPAL_SUCCESS:
ret = 0;
*sensor_data = be64_to_cpu(data);
break;
case OPAL_WRONG_STATE:
ret = -EIO;
break;
default:
ret = opal_error_code(ret);
break;
}
out_token:
opal_async_release_token(token);
return ret;
}
EXPORT_SYMBOL_GPL(opal_get_sensor_data_u64);
int __init opal_sensor_init(void)
{
struct platform_device *pdev;
struct device_node *sensor;
sensor = of_find_node_by_path("/ibm,opal/sensors");
if (!sensor) {
pr_err("Opal node 'sensors' not found\n");
return -ENODEV;
}
pdev = of_platform_device_create(sensor, "opal-sensor", NULL);
of_node_put(sensor);
return PTR_ERR_OR_ZERO(pdev);
}