arm_scpi.c 30 KB

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