Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 1 | /* |
| 2 | * System Control and Power Interface (SCPI) Message Protocol driver |
| 3 | * |
| 4 | * SCPI Message Protocol is used between the System Control Processor(SCP) |
| 5 | * and the Application Processors(AP). The Message Handling Unit(MHU) |
| 6 | * provides a mechanism for inter-processor communication between SCP's |
| 7 | * Cortex M3 and AP. |
| 8 | * |
| 9 | * SCP offers control and management of the core/cluster power states, |
| 10 | * various power domain DVFS including the core/cluster, certain system |
| 11 | * clocks configuration, thermal sensors and many others. |
| 12 | * |
| 13 | * Copyright (C) 2015 ARM Ltd. |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify it |
| 16 | * under the terms and conditions of the GNU General Public License, |
| 17 | * version 2, as published by the Free Software Foundation. |
| 18 | * |
| 19 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 20 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 22 | * more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License along |
| 25 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 26 | */ |
| 27 | |
| 28 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 29 | |
| 30 | #include <linux/bitmap.h> |
Heiner Kallweit | 7cd49a2 | 2017-12-05 23:16:55 +0100 | [diff] [blame] | 31 | #include <linux/bitfield.h> |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 32 | #include <linux/device.h> |
| 33 | #include <linux/err.h> |
| 34 | #include <linux/export.h> |
| 35 | #include <linux/io.h> |
| 36 | #include <linux/kernel.h> |
| 37 | #include <linux/list.h> |
| 38 | #include <linux/mailbox_client.h> |
| 39 | #include <linux/module.h> |
| 40 | #include <linux/of_address.h> |
| 41 | #include <linux/of_platform.h> |
| 42 | #include <linux/printk.h> |
Sudeep Holla | 45ca7df | 2017-04-27 15:08:51 +0100 | [diff] [blame] | 43 | #include <linux/pm_opp.h> |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 44 | #include <linux/scpi_protocol.h> |
| 45 | #include <linux/slab.h> |
| 46 | #include <linux/sort.h> |
| 47 | #include <linux/spinlock.h> |
| 48 | |
Heiner Kallweit | 96fe77b | 2017-12-05 23:17:15 +0100 | [diff] [blame] | 49 | #define CMD_ID_MASK GENMASK(6, 0) |
| 50 | #define CMD_TOKEN_ID_MASK GENMASK(15, 8) |
| 51 | #define CMD_DATA_SIZE_MASK GENMASK(24, 16) |
| 52 | #define CMD_LEGACY_DATA_SIZE_MASK GENMASK(28, 20) |
| 53 | #define PACK_SCPI_CMD(cmd_id, tx_sz) \ |
| 54 | (FIELD_PREP(CMD_ID_MASK, cmd_id) | \ |
| 55 | FIELD_PREP(CMD_DATA_SIZE_MASK, tx_sz)) |
| 56 | #define PACK_LEGACY_SCPI_CMD(cmd_id, tx_sz) \ |
| 57 | (FIELD_PREP(CMD_ID_MASK, cmd_id) | \ |
| 58 | FIELD_PREP(CMD_LEGACY_DATA_SIZE_MASK, tx_sz)) |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 59 | |
Heiner Kallweit | 96fe77b | 2017-12-05 23:17:15 +0100 | [diff] [blame] | 60 | #define CMD_SIZE(cmd) FIELD_GET(CMD_DATA_SIZE_MASK, cmd) |
| 61 | #define CMD_UNIQ_MASK (CMD_TOKEN_ID_MASK | CMD_ID_MASK) |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 62 | #define CMD_XTRACT_UNIQ(cmd) ((cmd) & CMD_UNIQ_MASK) |
| 63 | |
| 64 | #define SCPI_SLOT 0 |
| 65 | |
| 66 | #define MAX_DVFS_DOMAINS 8 |
Neil Armstrong | bb789cd | 2016-10-05 09:33:31 +0200 | [diff] [blame] | 67 | #define MAX_DVFS_OPPS 16 |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 68 | |
Heiner Kallweit | 7cd49a2 | 2017-12-05 23:16:55 +0100 | [diff] [blame] | 69 | #define PROTO_REV_MAJOR_MASK GENMASK(31, 16) |
| 70 | #define PROTO_REV_MINOR_MASK GENMASK(15, 0) |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 71 | |
Heiner Kallweit | 7cd49a2 | 2017-12-05 23:16:55 +0100 | [diff] [blame] | 72 | #define FW_REV_MAJOR_MASK GENMASK(31, 24) |
| 73 | #define FW_REV_MINOR_MASK GENMASK(23, 16) |
| 74 | #define FW_REV_PATCH_MASK GENMASK(15, 0) |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 75 | |
Sudeep Holla | 3bdd884 | 2016-01-15 11:57:38 +0000 | [diff] [blame] | 76 | #define MAX_RX_TIMEOUT (msecs_to_jiffies(30)) |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 77 | |
| 78 | enum scpi_error_codes { |
| 79 | SCPI_SUCCESS = 0, /* Success */ |
| 80 | SCPI_ERR_PARAM = 1, /* Invalid parameter(s) */ |
| 81 | SCPI_ERR_ALIGN = 2, /* Invalid alignment */ |
| 82 | SCPI_ERR_SIZE = 3, /* Invalid size */ |
| 83 | SCPI_ERR_HANDLER = 4, /* Invalid handler/callback */ |
| 84 | SCPI_ERR_ACCESS = 5, /* Invalid access/permission denied */ |
| 85 | SCPI_ERR_RANGE = 6, /* Value out of range */ |
| 86 | SCPI_ERR_TIMEOUT = 7, /* Timeout has occurred */ |
| 87 | SCPI_ERR_NOMEM = 8, /* Invalid memory area or pointer */ |
| 88 | SCPI_ERR_PWRSTATE = 9, /* Invalid power state */ |
| 89 | SCPI_ERR_SUPPORT = 10, /* Not supported or disabled */ |
| 90 | SCPI_ERR_DEVICE = 11, /* Device error */ |
| 91 | SCPI_ERR_BUSY = 12, /* Device busy */ |
| 92 | SCPI_ERR_MAX |
| 93 | }; |
| 94 | |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 95 | /* SCPI Standard commands */ |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 96 | enum scpi_std_cmd { |
| 97 | SCPI_CMD_INVALID = 0x00, |
| 98 | SCPI_CMD_SCPI_READY = 0x01, |
| 99 | SCPI_CMD_SCPI_CAPABILITIES = 0x02, |
| 100 | SCPI_CMD_SET_CSS_PWR_STATE = 0x03, |
| 101 | SCPI_CMD_GET_CSS_PWR_STATE = 0x04, |
| 102 | SCPI_CMD_SET_SYS_PWR_STATE = 0x05, |
| 103 | SCPI_CMD_SET_CPU_TIMER = 0x06, |
| 104 | SCPI_CMD_CANCEL_CPU_TIMER = 0x07, |
| 105 | SCPI_CMD_DVFS_CAPABILITIES = 0x08, |
| 106 | SCPI_CMD_GET_DVFS_INFO = 0x09, |
| 107 | SCPI_CMD_SET_DVFS = 0x0a, |
| 108 | SCPI_CMD_GET_DVFS = 0x0b, |
| 109 | SCPI_CMD_GET_DVFS_STAT = 0x0c, |
| 110 | SCPI_CMD_CLOCK_CAPABILITIES = 0x0d, |
| 111 | SCPI_CMD_GET_CLOCK_INFO = 0x0e, |
| 112 | SCPI_CMD_SET_CLOCK_VALUE = 0x0f, |
| 113 | SCPI_CMD_GET_CLOCK_VALUE = 0x10, |
| 114 | SCPI_CMD_PSU_CAPABILITIES = 0x11, |
| 115 | SCPI_CMD_GET_PSU_INFO = 0x12, |
| 116 | SCPI_CMD_SET_PSU = 0x13, |
| 117 | SCPI_CMD_GET_PSU = 0x14, |
| 118 | SCPI_CMD_SENSOR_CAPABILITIES = 0x15, |
| 119 | SCPI_CMD_SENSOR_INFO = 0x16, |
| 120 | SCPI_CMD_SENSOR_VALUE = 0x17, |
| 121 | SCPI_CMD_SENSOR_CFG_PERIODIC = 0x18, |
| 122 | SCPI_CMD_SENSOR_CFG_BOUNDS = 0x19, |
| 123 | SCPI_CMD_SENSOR_ASYNC_VALUE = 0x1a, |
| 124 | SCPI_CMD_SET_DEVICE_PWR_STATE = 0x1b, |
| 125 | SCPI_CMD_GET_DEVICE_PWR_STATE = 0x1c, |
| 126 | SCPI_CMD_COUNT |
| 127 | }; |
| 128 | |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 129 | /* SCPI Legacy Commands */ |
| 130 | enum legacy_scpi_std_cmd { |
| 131 | LEGACY_SCPI_CMD_INVALID = 0x00, |
| 132 | LEGACY_SCPI_CMD_SCPI_READY = 0x01, |
| 133 | LEGACY_SCPI_CMD_SCPI_CAPABILITIES = 0x02, |
| 134 | LEGACY_SCPI_CMD_EVENT = 0x03, |
| 135 | LEGACY_SCPI_CMD_SET_CSS_PWR_STATE = 0x04, |
| 136 | LEGACY_SCPI_CMD_GET_CSS_PWR_STATE = 0x05, |
| 137 | LEGACY_SCPI_CMD_CFG_PWR_STATE_STAT = 0x06, |
| 138 | LEGACY_SCPI_CMD_GET_PWR_STATE_STAT = 0x07, |
| 139 | LEGACY_SCPI_CMD_SYS_PWR_STATE = 0x08, |
| 140 | LEGACY_SCPI_CMD_L2_READY = 0x09, |
| 141 | LEGACY_SCPI_CMD_SET_AP_TIMER = 0x0a, |
| 142 | LEGACY_SCPI_CMD_CANCEL_AP_TIME = 0x0b, |
| 143 | LEGACY_SCPI_CMD_DVFS_CAPABILITIES = 0x0c, |
| 144 | LEGACY_SCPI_CMD_GET_DVFS_INFO = 0x0d, |
| 145 | LEGACY_SCPI_CMD_SET_DVFS = 0x0e, |
| 146 | LEGACY_SCPI_CMD_GET_DVFS = 0x0f, |
| 147 | LEGACY_SCPI_CMD_GET_DVFS_STAT = 0x10, |
| 148 | LEGACY_SCPI_CMD_SET_RTC = 0x11, |
| 149 | LEGACY_SCPI_CMD_GET_RTC = 0x12, |
| 150 | LEGACY_SCPI_CMD_CLOCK_CAPABILITIES = 0x13, |
| 151 | LEGACY_SCPI_CMD_SET_CLOCK_INDEX = 0x14, |
| 152 | LEGACY_SCPI_CMD_SET_CLOCK_VALUE = 0x15, |
| 153 | LEGACY_SCPI_CMD_GET_CLOCK_VALUE = 0x16, |
| 154 | LEGACY_SCPI_CMD_PSU_CAPABILITIES = 0x17, |
| 155 | LEGACY_SCPI_CMD_SET_PSU = 0x18, |
| 156 | LEGACY_SCPI_CMD_GET_PSU = 0x19, |
| 157 | LEGACY_SCPI_CMD_SENSOR_CAPABILITIES = 0x1a, |
| 158 | LEGACY_SCPI_CMD_SENSOR_INFO = 0x1b, |
| 159 | LEGACY_SCPI_CMD_SENSOR_VALUE = 0x1c, |
| 160 | LEGACY_SCPI_CMD_SENSOR_CFG_PERIODIC = 0x1d, |
| 161 | LEGACY_SCPI_CMD_SENSOR_CFG_BOUNDS = 0x1e, |
| 162 | LEGACY_SCPI_CMD_SENSOR_ASYNC_VALUE = 0x1f, |
| 163 | LEGACY_SCPI_CMD_COUNT |
| 164 | }; |
| 165 | |
| 166 | /* List all commands that are required to go through the high priority link */ |
| 167 | static int legacy_hpriority_cmds[] = { |
| 168 | LEGACY_SCPI_CMD_GET_CSS_PWR_STATE, |
| 169 | LEGACY_SCPI_CMD_CFG_PWR_STATE_STAT, |
| 170 | LEGACY_SCPI_CMD_GET_PWR_STATE_STAT, |
| 171 | LEGACY_SCPI_CMD_SET_DVFS, |
| 172 | LEGACY_SCPI_CMD_GET_DVFS, |
| 173 | LEGACY_SCPI_CMD_SET_RTC, |
| 174 | LEGACY_SCPI_CMD_GET_RTC, |
| 175 | LEGACY_SCPI_CMD_SET_CLOCK_INDEX, |
| 176 | LEGACY_SCPI_CMD_SET_CLOCK_VALUE, |
| 177 | LEGACY_SCPI_CMD_GET_CLOCK_VALUE, |
| 178 | LEGACY_SCPI_CMD_SET_PSU, |
| 179 | LEGACY_SCPI_CMD_GET_PSU, |
| 180 | LEGACY_SCPI_CMD_SENSOR_CFG_PERIODIC, |
| 181 | LEGACY_SCPI_CMD_SENSOR_CFG_BOUNDS, |
| 182 | }; |
| 183 | |
| 184 | /* List all commands used by this driver, used as indexes */ |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 185 | enum scpi_drv_cmds { |
| 186 | CMD_SCPI_CAPABILITIES = 0, |
| 187 | CMD_GET_CLOCK_INFO, |
| 188 | CMD_GET_CLOCK_VALUE, |
| 189 | CMD_SET_CLOCK_VALUE, |
| 190 | CMD_GET_DVFS, |
| 191 | CMD_SET_DVFS, |
| 192 | CMD_GET_DVFS_INFO, |
| 193 | CMD_SENSOR_CAPABILITIES, |
| 194 | CMD_SENSOR_INFO, |
| 195 | CMD_SENSOR_VALUE, |
| 196 | CMD_SET_DEVICE_PWR_STATE, |
| 197 | CMD_GET_DEVICE_PWR_STATE, |
| 198 | CMD_MAX_COUNT, |
| 199 | }; |
| 200 | |
| 201 | static int scpi_std_commands[CMD_MAX_COUNT] = { |
| 202 | SCPI_CMD_SCPI_CAPABILITIES, |
| 203 | SCPI_CMD_GET_CLOCK_INFO, |
| 204 | SCPI_CMD_GET_CLOCK_VALUE, |
| 205 | SCPI_CMD_SET_CLOCK_VALUE, |
| 206 | SCPI_CMD_GET_DVFS, |
| 207 | SCPI_CMD_SET_DVFS, |
| 208 | SCPI_CMD_GET_DVFS_INFO, |
| 209 | SCPI_CMD_SENSOR_CAPABILITIES, |
| 210 | SCPI_CMD_SENSOR_INFO, |
| 211 | SCPI_CMD_SENSOR_VALUE, |
| 212 | SCPI_CMD_SET_DEVICE_PWR_STATE, |
| 213 | SCPI_CMD_GET_DEVICE_PWR_STATE, |
| 214 | }; |
| 215 | |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 216 | static int scpi_legacy_commands[CMD_MAX_COUNT] = { |
| 217 | LEGACY_SCPI_CMD_SCPI_CAPABILITIES, |
| 218 | -1, /* GET_CLOCK_INFO */ |
| 219 | LEGACY_SCPI_CMD_GET_CLOCK_VALUE, |
| 220 | LEGACY_SCPI_CMD_SET_CLOCK_VALUE, |
| 221 | LEGACY_SCPI_CMD_GET_DVFS, |
| 222 | LEGACY_SCPI_CMD_SET_DVFS, |
| 223 | LEGACY_SCPI_CMD_GET_DVFS_INFO, |
| 224 | LEGACY_SCPI_CMD_SENSOR_CAPABILITIES, |
| 225 | LEGACY_SCPI_CMD_SENSOR_INFO, |
| 226 | LEGACY_SCPI_CMD_SENSOR_VALUE, |
| 227 | -1, /* SET_DEVICE_PWR_STATE */ |
| 228 | -1, /* GET_DEVICE_PWR_STATE */ |
| 229 | }; |
| 230 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 231 | struct scpi_xfer { |
| 232 | u32 slot; /* has to be first element */ |
| 233 | u32 cmd; |
| 234 | u32 status; |
| 235 | const void *tx_buf; |
| 236 | void *rx_buf; |
| 237 | unsigned int tx_len; |
| 238 | unsigned int rx_len; |
| 239 | struct list_head node; |
| 240 | struct completion done; |
| 241 | }; |
| 242 | |
| 243 | struct scpi_chan { |
| 244 | struct mbox_client cl; |
| 245 | struct mbox_chan *chan; |
| 246 | void __iomem *tx_payload; |
| 247 | void __iomem *rx_payload; |
| 248 | struct list_head rx_pending; |
| 249 | struct list_head xfers_list; |
| 250 | struct scpi_xfer *xfers; |
| 251 | spinlock_t rx_lock; /* locking for the rx pending list */ |
| 252 | struct mutex xfers_lock; |
| 253 | u8 token; |
| 254 | }; |
| 255 | |
| 256 | struct scpi_drvinfo { |
| 257 | u32 protocol_version; |
| 258 | u32 firmware_version; |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 259 | bool is_legacy; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 260 | int num_chans; |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 261 | int *commands; |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 262 | DECLARE_BITMAP(cmd_priority, LEGACY_SCPI_CMD_COUNT); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 263 | atomic_t next_chan; |
| 264 | struct scpi_ops *scpi_ops; |
| 265 | struct scpi_chan *channels; |
| 266 | struct scpi_dvfs_info *dvfs[MAX_DVFS_DOMAINS]; |
| 267 | }; |
| 268 | |
| 269 | /* |
| 270 | * The SCP firmware only executes in little-endian mode, so any buffers |
| 271 | * shared through SCPI should have their contents converted to little-endian |
| 272 | */ |
| 273 | struct scpi_shared_mem { |
| 274 | __le32 command; |
| 275 | __le32 status; |
| 276 | u8 payload[0]; |
| 277 | } __packed; |
| 278 | |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 279 | struct legacy_scpi_shared_mem { |
| 280 | __le32 status; |
| 281 | u8 payload[0]; |
| 282 | } __packed; |
| 283 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 284 | struct scp_capabilities { |
| 285 | __le32 protocol_version; |
| 286 | __le32 event_version; |
| 287 | __le32 platform_version; |
| 288 | __le32 commands[4]; |
| 289 | } __packed; |
| 290 | |
| 291 | struct clk_get_info { |
| 292 | __le16 id; |
| 293 | __le16 flags; |
| 294 | __le32 min_rate; |
| 295 | __le32 max_rate; |
| 296 | u8 name[20]; |
| 297 | } __packed; |
| 298 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 299 | struct clk_set_value { |
| 300 | __le16 id; |
| 301 | __le16 reserved; |
| 302 | __le32 rate; |
| 303 | } __packed; |
| 304 | |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 305 | struct legacy_clk_set_value { |
| 306 | __le32 rate; |
| 307 | __le16 id; |
| 308 | __le16 reserved; |
| 309 | } __packed; |
| 310 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 311 | struct dvfs_info { |
Heiner Kallweit | a963d7c | 2017-12-05 23:16:52 +0100 | [diff] [blame] | 312 | u8 domain; |
| 313 | u8 opp_count; |
| 314 | __le16 latency; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 315 | struct { |
| 316 | __le32 freq; |
| 317 | __le32 m_volt; |
| 318 | } opps[MAX_DVFS_OPPS]; |
| 319 | } __packed; |
| 320 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 321 | struct dvfs_set { |
| 322 | u8 domain; |
| 323 | u8 index; |
| 324 | } __packed; |
| 325 | |
Punit Agrawal | 38a1bdc | 2015-06-19 15:31:46 +0100 | [diff] [blame] | 326 | struct _scpi_sensor_info { |
| 327 | __le16 sensor_id; |
| 328 | u8 class; |
| 329 | u8 trigger_type; |
| 330 | char name[20]; |
| 331 | }; |
| 332 | |
Sudeep Holla | 37a441d | 2016-04-20 14:05:14 +0100 | [diff] [blame] | 333 | struct dev_pstate_set { |
Sudeep Holla | 0d30176 | 2017-08-18 15:39:28 +0100 | [diff] [blame] | 334 | __le16 dev_id; |
Sudeep Holla | 37a441d | 2016-04-20 14:05:14 +0100 | [diff] [blame] | 335 | u8 pstate; |
| 336 | } __packed; |
| 337 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 338 | static struct scpi_drvinfo *scpi_info; |
| 339 | |
| 340 | static int scpi_linux_errmap[SCPI_ERR_MAX] = { |
| 341 | /* better than switch case as long as return value is continuous */ |
| 342 | 0, /* SCPI_SUCCESS */ |
| 343 | -EINVAL, /* SCPI_ERR_PARAM */ |
| 344 | -ENOEXEC, /* SCPI_ERR_ALIGN */ |
| 345 | -EMSGSIZE, /* SCPI_ERR_SIZE */ |
| 346 | -EINVAL, /* SCPI_ERR_HANDLER */ |
| 347 | -EACCES, /* SCPI_ERR_ACCESS */ |
| 348 | -ERANGE, /* SCPI_ERR_RANGE */ |
| 349 | -ETIMEDOUT, /* SCPI_ERR_TIMEOUT */ |
| 350 | -ENOMEM, /* SCPI_ERR_NOMEM */ |
| 351 | -EINVAL, /* SCPI_ERR_PWRSTATE */ |
| 352 | -EOPNOTSUPP, /* SCPI_ERR_SUPPORT */ |
| 353 | -EIO, /* SCPI_ERR_DEVICE */ |
| 354 | -EBUSY, /* SCPI_ERR_BUSY */ |
| 355 | }; |
| 356 | |
| 357 | static inline int scpi_to_linux_errno(int errno) |
| 358 | { |
| 359 | if (errno >= SCPI_SUCCESS && errno < SCPI_ERR_MAX) |
| 360 | return scpi_linux_errmap[errno]; |
| 361 | return -EIO; |
| 362 | } |
| 363 | |
| 364 | static void scpi_process_cmd(struct scpi_chan *ch, u32 cmd) |
| 365 | { |
| 366 | unsigned long flags; |
| 367 | struct scpi_xfer *t, *match = NULL; |
| 368 | |
| 369 | spin_lock_irqsave(&ch->rx_lock, flags); |
| 370 | if (list_empty(&ch->rx_pending)) { |
| 371 | spin_unlock_irqrestore(&ch->rx_lock, flags); |
| 372 | return; |
| 373 | } |
| 374 | |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 375 | /* Command type is not replied by the SCP Firmware in legacy Mode |
| 376 | * We should consider that command is the head of pending RX commands |
| 377 | * if the list is not empty. In TX only mode, the list would be empty. |
| 378 | */ |
| 379 | if (scpi_info->is_legacy) { |
| 380 | match = list_first_entry(&ch->rx_pending, struct scpi_xfer, |
| 381 | node); |
| 382 | list_del(&match->node); |
| 383 | } else { |
| 384 | list_for_each_entry(t, &ch->rx_pending, node) |
| 385 | if (CMD_XTRACT_UNIQ(t->cmd) == CMD_XTRACT_UNIQ(cmd)) { |
| 386 | list_del(&t->node); |
| 387 | match = t; |
| 388 | break; |
| 389 | } |
| 390 | } |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 391 | /* check if wait_for_completion is in progress or timed-out */ |
| 392 | if (match && !completion_done(&match->done)) { |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 393 | unsigned int len; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 394 | |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 395 | if (scpi_info->is_legacy) { |
Heiner Kallweit | 5204abd | 2017-12-05 23:17:11 +0100 | [diff] [blame] | 396 | struct legacy_scpi_shared_mem __iomem *mem = |
| 397 | ch->rx_payload; |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 398 | |
| 399 | /* RX Length is not replied by the legacy Firmware */ |
| 400 | len = match->rx_len; |
| 401 | |
Heiner Kallweit | 5204abd | 2017-12-05 23:17:11 +0100 | [diff] [blame] | 402 | match->status = ioread32(&mem->status); |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 403 | memcpy_fromio(match->rx_buf, mem->payload, len); |
| 404 | } else { |
Heiner Kallweit | 5204abd | 2017-12-05 23:17:11 +0100 | [diff] [blame] | 405 | struct scpi_shared_mem __iomem *mem = ch->rx_payload; |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 406 | |
Heiner Kallweit | 96fe77b | 2017-12-05 23:17:15 +0100 | [diff] [blame] | 407 | len = min_t(unsigned int, match->rx_len, CMD_SIZE(cmd)); |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 408 | |
Heiner Kallweit | 5204abd | 2017-12-05 23:17:11 +0100 | [diff] [blame] | 409 | match->status = ioread32(&mem->status); |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 410 | memcpy_fromio(match->rx_buf, mem->payload, len); |
| 411 | } |
| 412 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 413 | if (match->rx_len > len) |
| 414 | memset(match->rx_buf + len, 0, match->rx_len - len); |
| 415 | complete(&match->done); |
| 416 | } |
| 417 | spin_unlock_irqrestore(&ch->rx_lock, flags); |
| 418 | } |
| 419 | |
| 420 | static void scpi_handle_remote_msg(struct mbox_client *c, void *msg) |
| 421 | { |
| 422 | struct scpi_chan *ch = container_of(c, struct scpi_chan, cl); |
Heiner Kallweit | 5204abd | 2017-12-05 23:17:11 +0100 | [diff] [blame] | 423 | struct scpi_shared_mem __iomem *mem = ch->rx_payload; |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 424 | u32 cmd = 0; |
| 425 | |
| 426 | if (!scpi_info->is_legacy) |
Heiner Kallweit | 5204abd | 2017-12-05 23:17:11 +0100 | [diff] [blame] | 427 | cmd = ioread32(&mem->command); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 428 | |
| 429 | scpi_process_cmd(ch, cmd); |
| 430 | } |
| 431 | |
| 432 | static void scpi_tx_prepare(struct mbox_client *c, void *msg) |
| 433 | { |
| 434 | unsigned long flags; |
| 435 | struct scpi_xfer *t = msg; |
| 436 | struct scpi_chan *ch = container_of(c, struct scpi_chan, cl); |
Heiner Kallweit | 5204abd | 2017-12-05 23:17:11 +0100 | [diff] [blame] | 437 | struct scpi_shared_mem __iomem *mem = ch->tx_payload; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 438 | |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 439 | if (t->tx_buf) { |
| 440 | if (scpi_info->is_legacy) |
| 441 | memcpy_toio(ch->tx_payload, t->tx_buf, t->tx_len); |
| 442 | else |
| 443 | memcpy_toio(mem->payload, t->tx_buf, t->tx_len); |
| 444 | } |
| 445 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 446 | if (t->rx_buf) { |
| 447 | if (!(++ch->token)) |
| 448 | ++ch->token; |
Heiner Kallweit | 96fe77b | 2017-12-05 23:17:15 +0100 | [diff] [blame] | 449 | t->cmd |= FIELD_PREP(CMD_TOKEN_ID_MASK, ch->token); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 450 | spin_lock_irqsave(&ch->rx_lock, flags); |
| 451 | list_add_tail(&t->node, &ch->rx_pending); |
| 452 | spin_unlock_irqrestore(&ch->rx_lock, flags); |
| 453 | } |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 454 | |
| 455 | if (!scpi_info->is_legacy) |
Heiner Kallweit | 5204abd | 2017-12-05 23:17:11 +0100 | [diff] [blame] | 456 | iowrite32(t->cmd, &mem->command); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | static struct scpi_xfer *get_scpi_xfer(struct scpi_chan *ch) |
| 460 | { |
| 461 | struct scpi_xfer *t; |
| 462 | |
| 463 | mutex_lock(&ch->xfers_lock); |
| 464 | if (list_empty(&ch->xfers_list)) { |
| 465 | mutex_unlock(&ch->xfers_lock); |
| 466 | return NULL; |
| 467 | } |
| 468 | t = list_first_entry(&ch->xfers_list, struct scpi_xfer, node); |
| 469 | list_del(&t->node); |
| 470 | mutex_unlock(&ch->xfers_lock); |
| 471 | return t; |
| 472 | } |
| 473 | |
| 474 | static void put_scpi_xfer(struct scpi_xfer *t, struct scpi_chan *ch) |
| 475 | { |
| 476 | mutex_lock(&ch->xfers_lock); |
| 477 | list_add_tail(&t->node, &ch->xfers_list); |
| 478 | mutex_unlock(&ch->xfers_lock); |
| 479 | } |
| 480 | |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 481 | static int scpi_send_message(u8 idx, void *tx_buf, unsigned int tx_len, |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 482 | void *rx_buf, unsigned int rx_len) |
| 483 | { |
| 484 | int ret; |
| 485 | u8 chan; |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 486 | u8 cmd; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 487 | struct scpi_xfer *msg; |
| 488 | struct scpi_chan *scpi_chan; |
| 489 | |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 490 | if (scpi_info->commands[idx] < 0) |
| 491 | return -EOPNOTSUPP; |
| 492 | |
| 493 | cmd = scpi_info->commands[idx]; |
| 494 | |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 495 | if (scpi_info->is_legacy) |
| 496 | chan = test_bit(cmd, scpi_info->cmd_priority) ? 1 : 0; |
| 497 | else |
| 498 | chan = atomic_inc_return(&scpi_info->next_chan) % |
| 499 | scpi_info->num_chans; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 500 | scpi_chan = scpi_info->channels + chan; |
| 501 | |
| 502 | msg = get_scpi_xfer(scpi_chan); |
| 503 | if (!msg) |
| 504 | return -ENOMEM; |
| 505 | |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 506 | if (scpi_info->is_legacy) { |
| 507 | msg->cmd = PACK_LEGACY_SCPI_CMD(cmd, tx_len); |
| 508 | msg->slot = msg->cmd; |
| 509 | } else { |
| 510 | msg->slot = BIT(SCPI_SLOT); |
| 511 | msg->cmd = PACK_SCPI_CMD(cmd, tx_len); |
| 512 | } |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 513 | msg->tx_buf = tx_buf; |
| 514 | msg->tx_len = tx_len; |
| 515 | msg->rx_buf = rx_buf; |
| 516 | msg->rx_len = rx_len; |
Alexey Klimov | c511fa3f | 2017-03-29 19:16:27 +0100 | [diff] [blame] | 517 | reinit_completion(&msg->done); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 518 | |
| 519 | ret = mbox_send_message(scpi_chan->chan, msg); |
| 520 | if (ret < 0 || !rx_buf) |
| 521 | goto out; |
| 522 | |
| 523 | if (!wait_for_completion_timeout(&msg->done, MAX_RX_TIMEOUT)) |
| 524 | ret = -ETIMEDOUT; |
| 525 | else |
| 526 | /* first status word */ |
Sudeep Holla | dd9a1d6 | 2016-01-29 13:35:44 +0000 | [diff] [blame] | 527 | ret = msg->status; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 528 | out: |
| 529 | if (ret < 0 && rx_buf) /* remove entry from the list if timed-out */ |
| 530 | scpi_process_cmd(scpi_chan, msg->cmd); |
| 531 | |
| 532 | put_scpi_xfer(msg, scpi_chan); |
| 533 | /* SCPI error codes > 0, translate them to Linux scale*/ |
| 534 | return ret > 0 ? scpi_to_linux_errno(ret) : ret; |
| 535 | } |
| 536 | |
| 537 | static u32 scpi_get_version(void) |
| 538 | { |
| 539 | return scpi_info->protocol_version; |
| 540 | } |
| 541 | |
| 542 | static int |
| 543 | scpi_clk_get_range(u16 clk_id, unsigned long *min, unsigned long *max) |
| 544 | { |
| 545 | int ret; |
| 546 | struct clk_get_info clk; |
| 547 | __le16 le_clk_id = cpu_to_le16(clk_id); |
| 548 | |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 549 | ret = scpi_send_message(CMD_GET_CLOCK_INFO, &le_clk_id, |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 550 | sizeof(le_clk_id), &clk, sizeof(clk)); |
| 551 | if (!ret) { |
| 552 | *min = le32_to_cpu(clk.min_rate); |
| 553 | *max = le32_to_cpu(clk.max_rate); |
| 554 | } |
| 555 | return ret; |
| 556 | } |
| 557 | |
| 558 | static unsigned long scpi_clk_get_val(u16 clk_id) |
| 559 | { |
| 560 | int ret; |
Sudeep Holla | c10bd41 | 2017-12-05 23:17:09 +0100 | [diff] [blame] | 561 | __le32 rate; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 562 | __le16 le_clk_id = cpu_to_le16(clk_id); |
| 563 | |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 564 | ret = scpi_send_message(CMD_GET_CLOCK_VALUE, &le_clk_id, |
Sudeep Holla | c10bd41 | 2017-12-05 23:17:09 +0100 | [diff] [blame] | 565 | sizeof(le_clk_id), &rate, sizeof(rate)); |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 566 | |
Sudeep Holla | c10bd41 | 2017-12-05 23:17:09 +0100 | [diff] [blame] | 567 | return ret ? ret : le32_to_cpu(rate); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | static int scpi_clk_set_val(u16 clk_id, unsigned long rate) |
| 571 | { |
| 572 | int stat; |
| 573 | struct clk_set_value clk = { |
| 574 | .id = cpu_to_le16(clk_id), |
| 575 | .rate = cpu_to_le32(rate) |
| 576 | }; |
| 577 | |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 578 | return scpi_send_message(CMD_SET_CLOCK_VALUE, &clk, sizeof(clk), |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 579 | &stat, sizeof(stat)); |
| 580 | } |
| 581 | |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 582 | static int legacy_scpi_clk_set_val(u16 clk_id, unsigned long rate) |
| 583 | { |
| 584 | int stat; |
| 585 | struct legacy_clk_set_value clk = { |
| 586 | .id = cpu_to_le16(clk_id), |
| 587 | .rate = cpu_to_le32(rate) |
| 588 | }; |
| 589 | |
| 590 | return scpi_send_message(CMD_SET_CLOCK_VALUE, &clk, sizeof(clk), |
| 591 | &stat, sizeof(stat)); |
| 592 | } |
| 593 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 594 | static int scpi_dvfs_get_idx(u8 domain) |
| 595 | { |
| 596 | int ret; |
Sudeep Holla | f9d91de | 2016-04-20 13:25:01 +0100 | [diff] [blame] | 597 | u8 dvfs_idx; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 598 | |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 599 | ret = scpi_send_message(CMD_GET_DVFS, &domain, sizeof(domain), |
Sudeep Holla | f9d91de | 2016-04-20 13:25:01 +0100 | [diff] [blame] | 600 | &dvfs_idx, sizeof(dvfs_idx)); |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 601 | |
Sudeep Holla | f9d91de | 2016-04-20 13:25:01 +0100 | [diff] [blame] | 602 | return ret ? ret : dvfs_idx; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | static int scpi_dvfs_set_idx(u8 domain, u8 index) |
| 606 | { |
| 607 | int stat; |
| 608 | struct dvfs_set dvfs = {domain, index}; |
| 609 | |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 610 | return scpi_send_message(CMD_SET_DVFS, &dvfs, sizeof(dvfs), |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 611 | &stat, sizeof(stat)); |
| 612 | } |
| 613 | |
| 614 | static int opp_cmp_func(const void *opp1, const void *opp2) |
| 615 | { |
| 616 | const struct scpi_opp *t1 = opp1, *t2 = opp2; |
| 617 | |
| 618 | return t1->freq - t2->freq; |
| 619 | } |
| 620 | |
| 621 | static struct scpi_dvfs_info *scpi_dvfs_get_info(u8 domain) |
| 622 | { |
| 623 | struct scpi_dvfs_info *info; |
| 624 | struct scpi_opp *opp; |
| 625 | struct dvfs_info buf; |
| 626 | int ret, i; |
| 627 | |
Olof Johansson | 81faa55 | 2017-12-03 19:28:33 -0800 | [diff] [blame] | 628 | if (domain >= MAX_DVFS_DOMAINS) |
| 629 | return ERR_PTR(-EINVAL); |
| 630 | |
| 631 | if (scpi_info->dvfs[domain]) /* data already populated */ |
| 632 | return scpi_info->dvfs[domain]; |
| 633 | |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 634 | ret = scpi_send_message(CMD_GET_DVFS_INFO, &domain, sizeof(domain), |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 635 | &buf, sizeof(buf)); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 636 | if (ret) |
Olof Johansson | 81faa55 | 2017-12-03 19:28:33 -0800 | [diff] [blame] | 637 | return ERR_PTR(ret); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 638 | |
Olof Johansson | 81faa55 | 2017-12-03 19:28:33 -0800 | [diff] [blame] | 639 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 640 | if (!info) |
Olof Johansson | 81faa55 | 2017-12-03 19:28:33 -0800 | [diff] [blame] | 641 | return ERR_PTR(-ENOMEM); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 642 | |
Heiner Kallweit | a963d7c | 2017-12-05 23:16:52 +0100 | [diff] [blame] | 643 | info->count = buf.opp_count; |
| 644 | info->latency = le16_to_cpu(buf.latency) * 1000; /* uS to nS */ |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 645 | |
Olof Johansson | 81faa55 | 2017-12-03 19:28:33 -0800 | [diff] [blame] | 646 | info->opps = kcalloc(info->count, sizeof(*opp), GFP_KERNEL); |
| 647 | if (!info->opps) { |
| 648 | kfree(info); |
| 649 | return ERR_PTR(-ENOMEM); |
| 650 | } |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 651 | |
| 652 | for (i = 0, opp = info->opps; i < info->count; i++, opp++) { |
| 653 | opp->freq = le32_to_cpu(buf.opps[i].freq); |
| 654 | opp->m_volt = le32_to_cpu(buf.opps[i].m_volt); |
| 655 | } |
| 656 | |
| 657 | sort(info->opps, info->count, sizeof(*opp), opp_cmp_func, NULL); |
| 658 | |
| 659 | scpi_info->dvfs[domain] = info; |
Olof Johansson | 81faa55 | 2017-12-03 19:28:33 -0800 | [diff] [blame] | 660 | return info; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 661 | } |
| 662 | |
Sudeep Holla | 45ca7df | 2017-04-27 15:08:51 +0100 | [diff] [blame] | 663 | static int scpi_dev_domain_id(struct device *dev) |
| 664 | { |
| 665 | struct of_phandle_args clkspec; |
| 666 | |
| 667 | if (of_parse_phandle_with_args(dev->of_node, "clocks", "#clock-cells", |
| 668 | 0, &clkspec)) |
| 669 | return -EINVAL; |
| 670 | |
| 671 | return clkspec.args[0]; |
| 672 | } |
| 673 | |
| 674 | static struct scpi_dvfs_info *scpi_dvfs_info(struct device *dev) |
| 675 | { |
| 676 | int domain = scpi_dev_domain_id(dev); |
| 677 | |
| 678 | if (domain < 0) |
| 679 | return ERR_PTR(domain); |
| 680 | |
| 681 | return scpi_dvfs_get_info(domain); |
| 682 | } |
| 683 | |
| 684 | static int scpi_dvfs_get_transition_latency(struct device *dev) |
| 685 | { |
| 686 | struct scpi_dvfs_info *info = scpi_dvfs_info(dev); |
| 687 | |
| 688 | if (IS_ERR(info)) |
| 689 | return PTR_ERR(info); |
| 690 | |
Sudeep Holla | 45ca7df | 2017-04-27 15:08:51 +0100 | [diff] [blame] | 691 | return info->latency; |
| 692 | } |
| 693 | |
| 694 | static int scpi_dvfs_add_opps_to_device(struct device *dev) |
| 695 | { |
| 696 | int idx, ret; |
| 697 | struct scpi_opp *opp; |
| 698 | struct scpi_dvfs_info *info = scpi_dvfs_info(dev); |
| 699 | |
| 700 | if (IS_ERR(info)) |
| 701 | return PTR_ERR(info); |
| 702 | |
| 703 | if (!info->opps) |
| 704 | return -EIO; |
| 705 | |
| 706 | for (opp = info->opps, idx = 0; idx < info->count; idx++, opp++) { |
| 707 | ret = dev_pm_opp_add(dev, opp->freq, opp->m_volt * 1000); |
| 708 | if (ret) { |
| 709 | dev_warn(dev, "failed to add opp %uHz %umV\n", |
| 710 | opp->freq, opp->m_volt); |
| 711 | while (idx-- > 0) |
| 712 | dev_pm_opp_remove(dev, (--opp)->freq); |
| 713 | return ret; |
| 714 | } |
| 715 | } |
| 716 | return 0; |
| 717 | } |
| 718 | |
Punit Agrawal | 38a1bdc | 2015-06-19 15:31:46 +0100 | [diff] [blame] | 719 | static int scpi_sensor_get_capability(u16 *sensors) |
| 720 | { |
Heiner Kallweit | 17431b7 | 2017-12-05 23:17:13 +0100 | [diff] [blame] | 721 | __le16 cap; |
Punit Agrawal | 38a1bdc | 2015-06-19 15:31:46 +0100 | [diff] [blame] | 722 | int ret; |
| 723 | |
Heiner Kallweit | 17431b7 | 2017-12-05 23:17:13 +0100 | [diff] [blame] | 724 | ret = scpi_send_message(CMD_SENSOR_CAPABILITIES, NULL, 0, &cap, |
| 725 | sizeof(cap)); |
Punit Agrawal | 38a1bdc | 2015-06-19 15:31:46 +0100 | [diff] [blame] | 726 | if (!ret) |
Heiner Kallweit | 17431b7 | 2017-12-05 23:17:13 +0100 | [diff] [blame] | 727 | *sensors = le16_to_cpu(cap); |
Punit Agrawal | 38a1bdc | 2015-06-19 15:31:46 +0100 | [diff] [blame] | 728 | |
| 729 | return ret; |
| 730 | } |
| 731 | |
| 732 | static int scpi_sensor_get_info(u16 sensor_id, struct scpi_sensor_info *info) |
| 733 | { |
| 734 | __le16 id = cpu_to_le16(sensor_id); |
| 735 | struct _scpi_sensor_info _info; |
| 736 | int ret; |
| 737 | |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 738 | ret = scpi_send_message(CMD_SENSOR_INFO, &id, sizeof(id), |
Punit Agrawal | 38a1bdc | 2015-06-19 15:31:46 +0100 | [diff] [blame] | 739 | &_info, sizeof(_info)); |
| 740 | if (!ret) { |
| 741 | memcpy(info, &_info, sizeof(*info)); |
| 742 | info->sensor_id = le16_to_cpu(_info.sensor_id); |
| 743 | } |
| 744 | |
| 745 | return ret; |
| 746 | } |
| 747 | |
Sudeep Holla | 3678b98 | 2016-02-23 16:21:16 +0000 | [diff] [blame] | 748 | static int scpi_sensor_get_value(u16 sensor, u64 *val) |
Punit Agrawal | 38a1bdc | 2015-06-19 15:31:46 +0100 | [diff] [blame] | 749 | { |
Sudeep Holla | dd9a1d6 | 2016-01-29 13:35:44 +0000 | [diff] [blame] | 750 | __le16 id = cpu_to_le16(sensor); |
Sudeep Holla | c10bd41 | 2017-12-05 23:17:09 +0100 | [diff] [blame] | 751 | __le64 value; |
Punit Agrawal | 38a1bdc | 2015-06-19 15:31:46 +0100 | [diff] [blame] | 752 | int ret; |
| 753 | |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 754 | ret = scpi_send_message(CMD_SENSOR_VALUE, &id, sizeof(id), |
Sudeep Holla | c10bd41 | 2017-12-05 23:17:09 +0100 | [diff] [blame] | 755 | &value, sizeof(value)); |
Martin Blumenstingl | a766347 | 2016-12-11 22:14:32 +0100 | [diff] [blame] | 756 | if (ret) |
| 757 | return ret; |
| 758 | |
| 759 | if (scpi_info->is_legacy) |
Heiner Kallweit | 83a6060 | 2017-12-05 23:16:58 +0100 | [diff] [blame] | 760 | /* only 32-bits supported, upper 32 bits can be junk */ |
Sudeep Holla | c10bd41 | 2017-12-05 23:17:09 +0100 | [diff] [blame] | 761 | *val = le32_to_cpup((__le32 *)&value); |
Martin Blumenstingl | a766347 | 2016-12-11 22:14:32 +0100 | [diff] [blame] | 762 | else |
Sudeep Holla | c10bd41 | 2017-12-05 23:17:09 +0100 | [diff] [blame] | 763 | *val = le64_to_cpu(value); |
Punit Agrawal | 38a1bdc | 2015-06-19 15:31:46 +0100 | [diff] [blame] | 764 | |
Martin Blumenstingl | a766347 | 2016-12-11 22:14:32 +0100 | [diff] [blame] | 765 | return 0; |
Punit Agrawal | 38a1bdc | 2015-06-19 15:31:46 +0100 | [diff] [blame] | 766 | } |
| 767 | |
Sudeep Holla | 37a441d | 2016-04-20 14:05:14 +0100 | [diff] [blame] | 768 | static int scpi_device_get_power_state(u16 dev_id) |
| 769 | { |
| 770 | int ret; |
| 771 | u8 pstate; |
| 772 | __le16 id = cpu_to_le16(dev_id); |
| 773 | |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 774 | ret = scpi_send_message(CMD_GET_DEVICE_PWR_STATE, &id, |
Sudeep Holla | 37a441d | 2016-04-20 14:05:14 +0100 | [diff] [blame] | 775 | sizeof(id), &pstate, sizeof(pstate)); |
| 776 | return ret ? ret : pstate; |
| 777 | } |
| 778 | |
| 779 | static int scpi_device_set_power_state(u16 dev_id, u8 pstate) |
| 780 | { |
| 781 | int stat; |
| 782 | struct dev_pstate_set dev_set = { |
| 783 | .dev_id = cpu_to_le16(dev_id), |
| 784 | .pstate = pstate, |
| 785 | }; |
| 786 | |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 787 | return scpi_send_message(CMD_SET_DEVICE_PWR_STATE, &dev_set, |
Sudeep Holla | 37a441d | 2016-04-20 14:05:14 +0100 | [diff] [blame] | 788 | sizeof(dev_set), &stat, sizeof(stat)); |
| 789 | } |
| 790 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 791 | static struct scpi_ops scpi_ops = { |
| 792 | .get_version = scpi_get_version, |
| 793 | .clk_get_range = scpi_clk_get_range, |
| 794 | .clk_get_val = scpi_clk_get_val, |
| 795 | .clk_set_val = scpi_clk_set_val, |
| 796 | .dvfs_get_idx = scpi_dvfs_get_idx, |
| 797 | .dvfs_set_idx = scpi_dvfs_set_idx, |
| 798 | .dvfs_get_info = scpi_dvfs_get_info, |
Sudeep Holla | 45ca7df | 2017-04-27 15:08:51 +0100 | [diff] [blame] | 799 | .device_domain_id = scpi_dev_domain_id, |
| 800 | .get_transition_latency = scpi_dvfs_get_transition_latency, |
| 801 | .add_opps_to_device = scpi_dvfs_add_opps_to_device, |
Punit Agrawal | 38a1bdc | 2015-06-19 15:31:46 +0100 | [diff] [blame] | 802 | .sensor_get_capability = scpi_sensor_get_capability, |
| 803 | .sensor_get_info = scpi_sensor_get_info, |
| 804 | .sensor_get_value = scpi_sensor_get_value, |
Sudeep Holla | 37a441d | 2016-04-20 14:05:14 +0100 | [diff] [blame] | 805 | .device_get_power_state = scpi_device_get_power_state, |
| 806 | .device_set_power_state = scpi_device_set_power_state, |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 807 | }; |
| 808 | |
| 809 | struct scpi_ops *get_scpi_ops(void) |
| 810 | { |
| 811 | return scpi_info ? scpi_info->scpi_ops : NULL; |
| 812 | } |
| 813 | EXPORT_SYMBOL_GPL(get_scpi_ops); |
| 814 | |
| 815 | static int scpi_init_versions(struct scpi_drvinfo *info) |
| 816 | { |
| 817 | int ret; |
| 818 | struct scp_capabilities caps; |
| 819 | |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 820 | ret = scpi_send_message(CMD_SCPI_CAPABILITIES, NULL, 0, |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 821 | &caps, sizeof(caps)); |
| 822 | if (!ret) { |
| 823 | info->protocol_version = le32_to_cpu(caps.protocol_version); |
| 824 | info->firmware_version = le32_to_cpu(caps.platform_version); |
| 825 | } |
Neil Armstrong | abd3e80 | 2016-10-19 14:51:09 +0200 | [diff] [blame] | 826 | /* Ignore error if not implemented */ |
| 827 | if (scpi_info->is_legacy && ret == -EOPNOTSUPP) |
| 828 | return 0; |
| 829 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 830 | return ret; |
| 831 | } |
| 832 | |
| 833 | static ssize_t protocol_version_show(struct device *dev, |
| 834 | struct device_attribute *attr, char *buf) |
| 835 | { |
Olof Johansson | 81faa55 | 2017-12-03 19:28:33 -0800 | [diff] [blame] | 836 | struct scpi_drvinfo *scpi_info = dev_get_drvdata(dev); |
| 837 | |
Heiner Kallweit | 7cd49a2 | 2017-12-05 23:16:55 +0100 | [diff] [blame] | 838 | return sprintf(buf, "%lu.%lu\n", |
| 839 | FIELD_GET(PROTO_REV_MAJOR_MASK, scpi_info->protocol_version), |
| 840 | FIELD_GET(PROTO_REV_MINOR_MASK, scpi_info->protocol_version)); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 841 | } |
| 842 | static DEVICE_ATTR_RO(protocol_version); |
| 843 | |
| 844 | static ssize_t firmware_version_show(struct device *dev, |
| 845 | struct device_attribute *attr, char *buf) |
| 846 | { |
Olof Johansson | 81faa55 | 2017-12-03 19:28:33 -0800 | [diff] [blame] | 847 | struct scpi_drvinfo *scpi_info = dev_get_drvdata(dev); |
| 848 | |
Heiner Kallweit | 7cd49a2 | 2017-12-05 23:16:55 +0100 | [diff] [blame] | 849 | return sprintf(buf, "%lu.%lu.%lu\n", |
| 850 | FIELD_GET(FW_REV_MAJOR_MASK, scpi_info->firmware_version), |
| 851 | FIELD_GET(FW_REV_MINOR_MASK, scpi_info->firmware_version), |
| 852 | FIELD_GET(FW_REV_PATCH_MASK, scpi_info->firmware_version)); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 853 | } |
| 854 | static DEVICE_ATTR_RO(firmware_version); |
| 855 | |
| 856 | static struct attribute *versions_attrs[] = { |
| 857 | &dev_attr_firmware_version.attr, |
| 858 | &dev_attr_protocol_version.attr, |
| 859 | NULL, |
| 860 | }; |
| 861 | ATTRIBUTE_GROUPS(versions); |
| 862 | |
Heiner Kallweit | c14f1db | 2017-12-05 23:16:42 +0100 | [diff] [blame] | 863 | static void scpi_free_channels(void *data) |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 864 | { |
Heiner Kallweit | c14f1db | 2017-12-05 23:16:42 +0100 | [diff] [blame] | 865 | struct scpi_drvinfo *info = data; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 866 | int i; |
| 867 | |
Heiner Kallweit | c14f1db | 2017-12-05 23:16:42 +0100 | [diff] [blame] | 868 | for (i = 0; i < info->num_chans; i++) |
| 869 | mbox_free_channel(info->channels[i].chan); |
Olof Johansson | 81faa55 | 2017-12-03 19:28:33 -0800 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | static int scpi_remove(struct platform_device *pdev) |
| 873 | { |
| 874 | int i; |
Olof Johansson | 81faa55 | 2017-12-03 19:28:33 -0800 | [diff] [blame] | 875 | struct scpi_drvinfo *info = platform_get_drvdata(pdev); |
| 876 | |
| 877 | scpi_info = NULL; /* stop exporting SCPI ops through get_scpi_ops */ |
| 878 | |
Olof Johansson | 81faa55 | 2017-12-03 19:28:33 -0800 | [diff] [blame] | 879 | for (i = 0; i < MAX_DVFS_DOMAINS && info->dvfs[i]; i++) { |
| 880 | kfree(info->dvfs[i]->opps); |
| 881 | kfree(info->dvfs[i]); |
| 882 | } |
Olof Johansson | 81faa55 | 2017-12-03 19:28:33 -0800 | [diff] [blame] | 883 | |
| 884 | return 0; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 885 | } |
| 886 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 887 | #define MAX_SCPI_XFERS 10 |
| 888 | static int scpi_alloc_xfer_list(struct device *dev, struct scpi_chan *ch) |
| 889 | { |
| 890 | int i; |
| 891 | struct scpi_xfer *xfers; |
| 892 | |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 893 | xfers = devm_kcalloc(dev, MAX_SCPI_XFERS, sizeof(*xfers), GFP_KERNEL); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 894 | if (!xfers) |
| 895 | return -ENOMEM; |
| 896 | |
| 897 | ch->xfers = xfers; |
Alexey Klimov | c511fa3f | 2017-03-29 19:16:27 +0100 | [diff] [blame] | 898 | for (i = 0; i < MAX_SCPI_XFERS; i++, xfers++) { |
| 899 | init_completion(&xfers->done); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 900 | list_add_tail(&xfers->node, &ch->xfers_list); |
Alexey Klimov | c511fa3f | 2017-03-29 19:16:27 +0100 | [diff] [blame] | 901 | } |
| 902 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 903 | return 0; |
| 904 | } |
| 905 | |
Sudeep Holla | 8358c6b | 2016-10-19 14:51:10 +0200 | [diff] [blame] | 906 | static const struct of_device_id legacy_scpi_of_match[] = { |
| 907 | {.compatible = "arm,scpi-pre-1.0"}, |
| 908 | {}, |
| 909 | }; |
| 910 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 911 | static int scpi_probe(struct platform_device *pdev) |
| 912 | { |
| 913 | int count, idx, ret; |
| 914 | struct resource res; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 915 | struct device *dev = &pdev->dev; |
| 916 | struct device_node *np = dev->of_node; |
| 917 | |
| 918 | scpi_info = devm_kzalloc(dev, sizeof(*scpi_info), GFP_KERNEL); |
| 919 | if (!scpi_info) |
| 920 | return -ENOMEM; |
| 921 | |
Sudeep Holla | 8358c6b | 2016-10-19 14:51:10 +0200 | [diff] [blame] | 922 | if (of_match_device(legacy_scpi_of_match, &pdev->dev)) |
| 923 | scpi_info->is_legacy = true; |
| 924 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 925 | count = of_count_phandle_with_args(np, "mboxes", "#mbox-cells"); |
| 926 | if (count < 0) { |
Rob Herring | 9deee31 | 2017-07-18 16:43:01 -0500 | [diff] [blame] | 927 | dev_err(dev, "no mboxes property in '%pOF'\n", np); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 928 | return -ENODEV; |
| 929 | } |
| 930 | |
Heiner Kallweit | c14f1db | 2017-12-05 23:16:42 +0100 | [diff] [blame] | 931 | scpi_info->channels = devm_kcalloc(dev, count, sizeof(struct scpi_chan), |
| 932 | GFP_KERNEL); |
| 933 | if (!scpi_info->channels) |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 934 | return -ENOMEM; |
| 935 | |
Heiner Kallweit | c14f1db | 2017-12-05 23:16:42 +0100 | [diff] [blame] | 936 | ret = devm_add_action(dev, scpi_free_channels, scpi_info); |
| 937 | if (ret) |
| 938 | return ret; |
| 939 | |
| 940 | for (; scpi_info->num_chans < count; scpi_info->num_chans++) { |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 941 | resource_size_t size; |
Heiner Kallweit | c14f1db | 2017-12-05 23:16:42 +0100 | [diff] [blame] | 942 | int idx = scpi_info->num_chans; |
| 943 | struct scpi_chan *pchan = scpi_info->channels + idx; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 944 | struct mbox_client *cl = &pchan->cl; |
| 945 | struct device_node *shmem = of_parse_phandle(np, "shmem", idx); |
| 946 | |
Peter Chen | b079bd5 | 2016-07-04 14:55:57 +0800 | [diff] [blame] | 947 | ret = of_address_to_resource(shmem, 0, &res); |
| 948 | of_node_put(shmem); |
| 949 | if (ret) { |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 950 | dev_err(dev, "failed to get SCPI payload mem resource\n"); |
Heiner Kallweit | c14f1db | 2017-12-05 23:16:42 +0100 | [diff] [blame] | 951 | return ret; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | size = resource_size(&res); |
| 955 | pchan->rx_payload = devm_ioremap(dev, res.start, size); |
| 956 | if (!pchan->rx_payload) { |
| 957 | dev_err(dev, "failed to ioremap SCPI payload\n"); |
Heiner Kallweit | c14f1db | 2017-12-05 23:16:42 +0100 | [diff] [blame] | 958 | return -EADDRNOTAVAIL; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 959 | } |
| 960 | pchan->tx_payload = pchan->rx_payload + (size >> 1); |
| 961 | |
| 962 | cl->dev = dev; |
| 963 | cl->rx_callback = scpi_handle_remote_msg; |
| 964 | cl->tx_prepare = scpi_tx_prepare; |
| 965 | cl->tx_block = true; |
Sudeep Holla | 3bdd884 | 2016-01-15 11:57:38 +0000 | [diff] [blame] | 966 | cl->tx_tout = 20; |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 967 | cl->knows_txdone = false; /* controller can't ack */ |
| 968 | |
| 969 | INIT_LIST_HEAD(&pchan->rx_pending); |
| 970 | INIT_LIST_HEAD(&pchan->xfers_list); |
| 971 | spin_lock_init(&pchan->rx_lock); |
| 972 | mutex_init(&pchan->xfers_lock); |
| 973 | |
| 974 | ret = scpi_alloc_xfer_list(dev, pchan); |
| 975 | if (!ret) { |
| 976 | pchan->chan = mbox_request_channel(cl, idx); |
| 977 | if (!IS_ERR(pchan->chan)) |
| 978 | continue; |
| 979 | ret = PTR_ERR(pchan->chan); |
| 980 | if (ret != -EPROBE_DEFER) |
| 981 | dev_err(dev, "failed to get channel%d err %d\n", |
| 982 | idx, ret); |
| 983 | } |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 984 | return ret; |
| 985 | } |
| 986 | |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 987 | scpi_info->commands = scpi_std_commands; |
Olof Johansson | 81faa55 | 2017-12-03 19:28:33 -0800 | [diff] [blame] | 988 | |
| 989 | platform_set_drvdata(pdev, scpi_info); |
Sudeep Holla | 761d0ef | 2016-10-05 09:33:27 +0200 | [diff] [blame] | 990 | |
Neil Armstrong | 4dfe32d | 2016-10-19 14:51:08 +0200 | [diff] [blame] | 991 | if (scpi_info->is_legacy) { |
| 992 | /* Replace with legacy variants */ |
| 993 | scpi_ops.clk_set_val = legacy_scpi_clk_set_val; |
| 994 | scpi_info->commands = scpi_legacy_commands; |
| 995 | |
| 996 | /* Fill priority bitmap */ |
| 997 | for (idx = 0; idx < ARRAY_SIZE(legacy_hpriority_cmds); idx++) |
| 998 | set_bit(legacy_hpriority_cmds[idx], |
| 999 | scpi_info->cmd_priority); |
| 1000 | } |
| 1001 | |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 1002 | ret = scpi_init_versions(scpi_info); |
| 1003 | if (ret) { |
| 1004 | dev_err(dev, "incorrect or no SCP firmware found\n"); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 1005 | return ret; |
| 1006 | } |
| 1007 | |
Heiner Kallweit | 62c60ef | 2017-12-05 23:17:19 +0100 | [diff] [blame] | 1008 | if (scpi_info->is_legacy && !scpi_info->protocol_version && |
| 1009 | !scpi_info->firmware_version) |
| 1010 | dev_info(dev, "SCP Protocol legacy pre-1.0 firmware\n"); |
| 1011 | else |
| 1012 | dev_info(dev, "SCP Protocol %lu.%lu Firmware %lu.%lu.%lu version\n", |
| 1013 | FIELD_GET(PROTO_REV_MAJOR_MASK, |
| 1014 | scpi_info->protocol_version), |
| 1015 | FIELD_GET(PROTO_REV_MINOR_MASK, |
| 1016 | scpi_info->protocol_version), |
| 1017 | FIELD_GET(FW_REV_MAJOR_MASK, |
| 1018 | scpi_info->firmware_version), |
| 1019 | FIELD_GET(FW_REV_MINOR_MASK, |
| 1020 | scpi_info->firmware_version), |
| 1021 | FIELD_GET(FW_REV_PATCH_MASK, |
| 1022 | scpi_info->firmware_version)); |
Olof Johansson | 81faa55 | 2017-12-03 19:28:33 -0800 | [diff] [blame] | 1023 | scpi_info->scpi_ops = &scpi_ops; |
Heiner Kallweit | 931cf0c | 2017-09-29 23:44:05 +0200 | [diff] [blame] | 1024 | |
Heiner Kallweit | 5abc793 | 2017-12-05 23:16:48 +0100 | [diff] [blame] | 1025 | ret = devm_device_add_groups(dev, versions_groups); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 1026 | if (ret) |
| 1027 | dev_err(dev, "unable to create sysfs version group\n"); |
| 1028 | |
Heiner Kallweit | 5abc793 | 2017-12-05 23:16:48 +0100 | [diff] [blame] | 1029 | return devm_of_platform_populate(dev); |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | static const struct of_device_id scpi_of_match[] = { |
| 1033 | {.compatible = "arm,scpi"}, |
Sudeep Holla | 8358c6b | 2016-10-19 14:51:10 +0200 | [diff] [blame] | 1034 | {.compatible = "arm,scpi-pre-1.0"}, |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 1035 | {}, |
| 1036 | }; |
| 1037 | |
| 1038 | MODULE_DEVICE_TABLE(of, scpi_of_match); |
| 1039 | |
| 1040 | static struct platform_driver scpi_driver = { |
| 1041 | .driver = { |
| 1042 | .name = "scpi_protocol", |
| 1043 | .of_match_table = scpi_of_match, |
| 1044 | }, |
| 1045 | .probe = scpi_probe, |
Olof Johansson | 81faa55 | 2017-12-03 19:28:33 -0800 | [diff] [blame] | 1046 | .remove = scpi_remove, |
Sudeep Holla | 8cb7cf5 | 2015-03-30 10:59:52 +0100 | [diff] [blame] | 1047 | }; |
| 1048 | module_platform_driver(scpi_driver); |
| 1049 | |
| 1050 | MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>"); |
| 1051 | MODULE_DESCRIPTION("ARM SCPI mailbox protocol driver"); |
| 1052 | MODULE_LICENSE("GPL v2"); |