~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/platforms/powernv/opal-sensor.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * PowerNV sensor code
  4  *
  5  * Copyright (C) 2013 IBM
  6  */
  7 
  8 #include <linux/delay.h>
  9 #include <linux/of.h>
 10 #include <linux/of_platform.h>
 11 #include <linux/platform_device.h>
 12 #include <asm/opal.h>
 13 #include <asm/machdep.h>
 14 
 15 /*
 16  * This will return sensor information to driver based on the requested sensor
 17  * handle. A handle is an opaque id for the powernv, read by the driver from the
 18  * device tree..
 19  */
 20 int opal_get_sensor_data(u32 sensor_hndl, u32 *sensor_data)
 21 {
 22         int ret, token;
 23         struct opal_msg msg;
 24         __be32 data;
 25 
 26         token = opal_async_get_token_interruptible();
 27         if (token < 0)
 28                 return token;
 29 
 30         ret = opal_sensor_read(sensor_hndl, token, &data);
 31         switch (ret) {
 32         case OPAL_ASYNC_COMPLETION:
 33                 ret = opal_async_wait_response(token, &msg);
 34                 if (ret) {
 35                         pr_err("%s: Failed to wait for the async response, %d\n",
 36                                __func__, ret);
 37                         goto out;
 38                 }
 39 
 40                 ret = opal_error_code(opal_get_async_rc(msg));
 41                 *sensor_data = be32_to_cpu(data);
 42                 break;
 43 
 44         case OPAL_SUCCESS:
 45                 ret = 0;
 46                 *sensor_data = be32_to_cpu(data);
 47                 break;
 48 
 49         case OPAL_WRONG_STATE:
 50                 ret = -EIO;
 51                 break;
 52 
 53         default:
 54                 ret = opal_error_code(ret);
 55                 break;
 56         }
 57 
 58 out:
 59         opal_async_release_token(token);
 60         return ret;
 61 }
 62 EXPORT_SYMBOL_GPL(opal_get_sensor_data);
 63 
 64 int opal_get_sensor_data_u64(u32 sensor_hndl, u64 *sensor_data)
 65 {
 66         int ret, token;
 67         struct opal_msg msg;
 68         __be64 data;
 69 
 70         if (!opal_check_token(OPAL_SENSOR_READ_U64)) {
 71                 u32 sdata;
 72 
 73                 ret = opal_get_sensor_data(sensor_hndl, &sdata);
 74                 if (!ret)
 75                         *sensor_data = sdata;
 76                 return ret;
 77         }
 78 
 79         token = opal_async_get_token_interruptible();
 80         if (token < 0)
 81                 return token;
 82 
 83         ret = opal_sensor_read_u64(sensor_hndl, token, &data);
 84         switch (ret) {
 85         case OPAL_ASYNC_COMPLETION:
 86                 ret = opal_async_wait_response(token, &msg);
 87                 if (ret) {
 88                         pr_err("%s: Failed to wait for the async response, %d\n",
 89                                __func__, ret);
 90                         goto out_token;
 91                 }
 92 
 93                 ret = opal_error_code(opal_get_async_rc(msg));
 94                 *sensor_data = be64_to_cpu(data);
 95                 break;
 96 
 97         case OPAL_SUCCESS:
 98                 ret = 0;
 99                 *sensor_data = be64_to_cpu(data);
100                 break;
101 
102         case OPAL_WRONG_STATE:
103                 ret = -EIO;
104                 break;
105 
106         default:
107                 ret = opal_error_code(ret);
108                 break;
109         }
110 
111 out_token:
112         opal_async_release_token(token);
113         return ret;
114 }
115 EXPORT_SYMBOL_GPL(opal_get_sensor_data_u64);
116 
117 int __init opal_sensor_init(void)
118 {
119         struct platform_device *pdev;
120         struct device_node *sensor;
121 
122         sensor = of_find_node_by_path("/ibm,opal/sensors");
123         if (!sensor) {
124                 pr_err("Opal node 'sensors' not found\n");
125                 return -ENODEV;
126         }
127 
128         pdev = of_platform_device_create(sensor, "opal-sensor", NULL);
129         of_node_put(sensor);
130 
131         return PTR_ERR_OR_ZERO(pdev);
132 }
133 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php