1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2013 IBM
8 #include <linux/delay.h>
9 #include <linux/of_platform.h>
11 #include <asm/machdep.h>
14 * This will return sensor information to driver based on the requested sensor
15 * handle. A handle is an opaque id for the powernv, read by the driver from the
18 int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data)
24 token = opal_async_get_token_interruptible();
28 ret = opal_sensor_read(sensor_hndl, token, &data);
30 case OPAL_ASYNC_COMPLETION:
31 ret = opal_async_wait_response(token, &msg);
33 pr_err("%s: Failed to wait for the async response, %d\n",
38 ret = opal_error_code(opal_get_async_rc(msg));
39 *sensor_data = be32_to_cpu(data);
44 *sensor_data = be32_to_cpu(data);
47 case OPAL_WRONG_STATE:
52 ret = opal_error_code(ret);
57 opal_async_release_token(token);
60 EXPORT_SYMBOL_GPL(opal_get_sensor_data);
62 int opal_get_sensor_data_u64(u32 sensor_hndl, u64 *sensor_data)
68 if (!opal_check_token(OPAL_SENSOR_READ_U64)) {
71 ret = opal_get_sensor_data(sensor_hndl, &sdata);
77 token = opal_async_get_token_interruptible();
81 ret = opal_sensor_read_u64(sensor_hndl, token, &data);
83 case OPAL_ASYNC_COMPLETION:
84 ret = opal_async_wait_response(token, &msg);
86 pr_err("%s: Failed to wait for the async response, %d\n",
91 ret = opal_error_code(opal_get_async_rc(msg));
92 *sensor_data = be64_to_cpu(data);
97 *sensor_data = be64_to_cpu(data);
100 case OPAL_WRONG_STATE:
105 ret = opal_error_code(ret);
110 opal_async_release_token(token);
113 EXPORT_SYMBOL_GPL(opal_get_sensor_data_u64);
115 int __init opal_sensor_init(void)
117 struct platform_device *pdev;
118 struct device_node *sensor;
120 sensor = of_find_node_by_path("/ibm,opal/sensors");
122 pr_err("Opal node 'sensors' not found\n");
126 pdev = of_platform_device_create(sensor, "opal-sensor", NULL);
129 return PTR_ERR_OR_ZERO(pdev);