scpi: Add support for legacy SCPI protocol
Subsystems (3)
v2 cover scpi: Add support for legacy SCPI protocol
This patchset aims to support the legacy SCPI firmware implementation that was delivered as early technology preview for the JUNO platform.
Finally a stable, maintained and public implementation for the SCPI protocol has been upstreamed part of the JUNO support and it is the recommended way of implementing SCP communication on ARMv8 platforms.
The Amlogic GXBB platform is using this legacy protocol, as the RK3368 & RK3399 platforms. This patchset will only add support for Amlogic GXBB SoC.
This patchset add support for the legacy protocol in the arm_scpi.c file, avoiding code duplication.
Last RFC discution tread can be found at : https://lkml.org/lkml/2016/8/9/210
The last patch depends on the "Platform MHU" dtsi patch.
Changes since v1 at : http://lkml.kernel.org/r/1471515066-3626-1-git-send-email-narmstrong at baylibre.com
- Dropped vendor_send_message and rockchip vendor mechanism patches
- Merged alternate functions into main functions using is_legacy boolean
- Added DT match table to set is_legacy to true
- Kept alternate scpi_ops structure for legacy
Neil Armstrong (7):
scpi: Add alternative legacy structures, functions and macros
scpi: Use legacy variants command index calling scpi_send_message
scpi: Add support for Legacy match table for Amlogic GXBB SoC
scpi: grow MAX_DVFS_OPPS to 16 entries
dt-bindings: Add support for Amlogic GXBB SCPI Interface
ARM64: dts: meson-gxbb: Add SRAM node
ARM64: dts: meson-gxbb: Add SCPI with cpufreq & sensors Nodes
Documentation/devicetree/bindings/arm/arm,scpi.txt | 8 +- arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 45 ++++ drivers/firmware/arm_scpi.c | 279 +++++++++++++++++++-- 3 files changed, 302 insertions(+), 30 deletions(-)
Signature · 1 line
1.9.1
PATCH v2 1/7 scpi: Add alternative legacy structures, functions and macros
In order to support the legacy SCPI protocol variant, add back the structures and macros that varies against the final specification.
Add support for legacy in scpi_send_message.
--- drivers/firmware/arm_scpi.c | 142 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 135 insertions(+), 7 deletions(-)
drivers/firmware/arm_scpi.c +135 -7
@@ -50,11 +50,16 @@#define CMD_TOKEN_ID_MASK 0xff#define CMD_DATA_SIZE_SHIFT 16#define CMD_DATA_SIZE_MASK 0x1ff +#define CMD_LEGACY_DATA_SIZE_SHIFT 20 +#define CMD_LEGACY_DATA_SIZE_MASK 0x1ff#define PACK_SCPI_CMD (cmd_id, tx_sz) \ ((((cmd_id) & CMD_ID_MASK) << CMD_ID_SHIFT) | \ (((tx_sz) & CMD_DATA_SIZE_MASK) << CMD_DATA_SIZE_SHIFT))#define ADD_SCPI_TOKEN (cmd, token) \ ((cmd) |= (((token) & CMD_TOKEN_ID_MASK) << CMD_TOKEN_ID_SHIFT)) +#define PACK_LEGACY_SCPI_CMD (cmd_id, tx_sz) \ + ((((cmd_id) & CMD_ID_MASK) << CMD_ID_SHIFT) | \ + (((tx_sz) & CMD_LEGACY_DATA_SIZE_MASK) << CMD_LEGACY_DATA_SIZE_SHIFT))#define CMD_SIZE (cmd) (((cmd) >> CMD_DATA_SIZE_SHIFT) & CMD_DATA_SIZE_MASK)#define CMD_UNIQ_MASK (CMD_TOKEN_ID_MASK << CMD_TOKEN_ID_SHIFT | CMD_ID_MASK)
@@ -132,6 +137,42 @@ enum scpi_std_cmd {SCPI_CMD_COUNT }; +enum legacy_scpi_std_cmd { +LEGACY_SCPI_CMD_INVALID =0x00 , +LEGACY_SCPI_CMD_SCPI_READY =0x01 , +LEGACY_SCPI_CMD_SCPI_CAPABILITIES =0x02 , +LEGACY_SCPI_CMD_EVENT =0x03 , +LEGACY_SCPI_CMD_SET_CSS_PWR_STATE =0x04 , +LEGACY_SCPI_CMD_GET_CSS_PWR_STATE =0x05 , +LEGACY_SCPI_CMD_CFG_PWR_STATE_STAT =0x06 , +LEGACY_SCPI_CMD_GET_PWR_STATE_STAT =0x07 , +LEGACY_SCPI_CMD_SYS_PWR_STATE =0x08 , +LEGACY_SCPI_CMD_L2_READY =0x09 , +LEGACY_SCPI_CMD_SET_AP_TIMER =0x0a , +LEGACY_SCPI_CMD_CANCEL_AP_TIME =0x0b , +LEGACY_SCPI_CMD_DVFS_CAPABILITIES =0x0c , +LEGACY_SCPI_CMD_GET_DVFS_INFO =0x0d , +LEGACY_SCPI_CMD_SET_DVFS =0x0e , +LEGACY_SCPI_CMD_GET_DVFS =0x0f , +LEGACY_SCPI_CMD_GET_DVFS_STAT =0x10 , +LEGACY_SCPI_CMD_SET_RTC =0x11 , +LEGACY_SCPI_CMD_GET_RTC =0x12 , +LEGACY_SCPI_CMD_CLOCK_CAPABILITIES =0x13 , +LEGACY_SCPI_CMD_SET_CLOCK_INDEX =0x14 , +LEGACY_SCPI_CMD_SET_CLOCK_VALUE =0x15 , +LEGACY_SCPI_CMD_GET_CLOCK_VALUE =0x16 , +LEGACY_SCPI_CMD_PSU_CAPABILITIES =0x17 , +LEGACY_SCPI_CMD_SET_PSU =0x18 , +LEGACY_SCPI_CMD_GET_PSU =0x19 , +LEGACY_SCPI_CMD_SENSOR_CAPABILITIES =0x1a , +LEGACY_SCPI_CMD_SENSOR_INFO =0x1b , +LEGACY_SCPI_CMD_SENSOR_VALUE =0x1c , +LEGACY_SCPI_CMD_SENSOR_CFG_PERIODIC =0x1d , +LEGACY_SCPI_CMD_SENSOR_CFG_BOUNDS =0x1e , +LEGACY_SCPI_CMD_SENSOR_ASYNC_VALUE =0x1f , +LEGACY_SCPI_CMD_COUNT +}; +struct scpi_xfer {u32 slot;/* has to be first element */ u32 cmd;
@@ -155,11 +196,13 @@ struct scpi_chan {spinlock_t rx_lock;/* locking for the rx pending list */ struct mutex xfers_lock;u8 token; +struct scpi_xfer *t; };struct scpi_drvinfo {u32 protocol_version;u32 firmware_version; +bool is_legacy;int num_chans;atomic_t next_chan;struct scpi_ops *scpi_ops;
@@ -177,6 +220,11 @@ struct scpi_shared_mem {u8 payload[0 ]; } __packed; +struct legacy_scpi_shared_mem { +__le32 status; +u8 payload[0 ]; +} __packed; +struct scp_capabilities {__le32 protocol_version;__le32 event_version;
@@ -202,6 +250,12 @@ struct clk_set_value {__le32 rate; } __packed; +struct legacy_clk_set_value { +__le32 rate; +__le16 id; +__le16 reserved; +} __packed; +struct dvfs_info {__le32 header;struct {
@@ -302,6 +356,23 @@ static void scpi_handle_remote_msg(struct mbox_client *c, void *msg)scpi_process_cmd (ch, cmd); } +static void legacy_scpi_handle_remote_msg (struct mbox_client *c,void *__msg) +{ +struct scpi_chan *ch = + container_of(c, struct scpi_chan, cl); +struct legacy_scpi_shared_mem *mem = ch->rx_payload; +unsigned int len; + + len = ch->t->rx_len; + + ch->t->status =le32_to_cpu (mem->status); + +if (len) +memcpy_fromio (ch->t->rx_buf, mem->payload, len); + +complete (&ch->t->done); +} +static void scpi_tx_prepare (struct mbox_client *c,void *msg) {unsigned long flags;
@@ -322,6 +393,43 @@ static void scpi_tx_prepare(struct mbox_client *c, void *msg) mem->command =cpu_to_le32 (t->cmd); } +static void legacy_scpi_tx_prepare (struct mbox_client *c,void *__msg) +{ +struct scpi_chan *ch = + container_of(c, struct scpi_chan, cl); + +if (ch->t->tx_buf && ch->t->tx_len) +memcpy_toio (ch->tx_payload, ch->t->tx_buf, ch->t->tx_len); +} + +static int legacy_high_priority_cmds[] = { +LEGACY_SCPI_CMD_GET_CSS_PWR_STATE , +LEGACY_SCPI_CMD_CFG_PWR_STATE_STAT , +LEGACY_SCPI_CMD_GET_PWR_STATE_STAT , +LEGACY_SCPI_CMD_SET_DVFS , +LEGACY_SCPI_CMD_GET_DVFS , +LEGACY_SCPI_CMD_SET_RTC , +LEGACY_SCPI_CMD_GET_RTC , +LEGACY_SCPI_CMD_SET_CLOCK_INDEX , +LEGACY_SCPI_CMD_SET_CLOCK_VALUE , +LEGACY_SCPI_CMD_GET_CLOCK_VALUE , +LEGACY_SCPI_CMD_SET_PSU , +LEGACY_SCPI_CMD_GET_PSU , +LEGACY_SCPI_CMD_SENSOR_CFG_PERIODIC , +LEGACY_SCPI_CMD_SENSOR_CFG_BOUNDS , +}; + +static int legacy_scpi_get_chan (u8 cmd) +{ +int idx; + +for (idx =0 ; idx <ARRAY_SIZE (legacy_high_priority_cmds); idx++) +if (cmd == legacy_high_priority_cmds[idx]) +return 1 ; + +return 0 ; +} +static struct scpi_xfer *get_scpi_xfer (struct scpi_chan *ch) {struct scpi_xfer *t;
@@ -352,15 +460,27 @@ static int scpi_send_message(u8 cmd, void *tx_buf, unsigned int tx_len,struct scpi_xfer *msg;struct scpi_chan *scpi_chan; - chan =atomic_inc_return (&scpi_info->next_chan) % scpi_info->num_chans; +if (scpi_info->is_legacy) + chan =legacy_scpi_get_chan (cmd); +else + chan =atomic_inc_return (&scpi_info->next_chan) % + scpi_info->num_chans; scpi_chan = scpi_info->channels + chan; msg =get_scpi_xfer (scpi_chan);if (!msg)return -ENOMEM ; - msg->slot =BIT (SCPI_SLOT ); - msg->cmd =PACK_SCPI_CMD (cmd, tx_len); +if (scpi_info->is_legacy) { +mutex_lock (&scpi_chan->xfers_lock); + + scpi_chan->t = msg; + msg->cmd =PACK_LEGACY_SCPI_CMD (cmd, tx_len); + msg->slot = msg->cmd; + }else { + msg->slot =BIT (SCPI_SLOT ); + msg->cmd =PACK_SCPI_CMD (cmd, tx_len); + } msg->tx_buf = tx_buf; msg->tx_len = tx_len; msg->rx_buf = rx_buf;
@@ -368,7 +488,7 @@ static int scpi_send_message(u8 cmd, void *tx_buf, unsigned int tx_len,init_completion (&msg->done); ret =mbox_send_message (scpi_chan->chan, msg); -if (ret <0 || !rx_buf) +if (ret <0 || (!scpi_info->is_legacy && !rx_buf)) goto out;if (!wait_for_completion_timeout (&msg->done,MAX_RX_TIMEOUT ))
@@ -377,7 +497,10 @@ static int scpi_send_message(u8 cmd, void *tx_buf, unsigned int tx_len,/* first status word */ ret = msg->status; out: -if (ret <0 && rx_buf)/* remove entry from the list if timed-out */ +if (scpi_info->is_legacy) +mutex_unlock (&scpi_chan->xfers_lock); +else if (ret <0 && rx_buf) +/* remove entry from the list if timed-out */ scpi_process_cmd (scpi_chan, msg->cmd);put_scpi_xfer (msg, scpi_chan);
@@ -725,8 +848,13 @@ static int scpi_probe(struct platform_device *pdev) pchan->tx_payload = pchan->rx_payload + (size >>1 ); cl->dev = dev; - cl->rx_callback = scpi_handle_remote_msg; - cl->tx_prepare = scpi_tx_prepare; +if (scpi_info->is_legacy) { + cl->rx_callback = legacy_scpi_handle_remote_msg; + cl->tx_prepare = legacy_scpi_tx_prepare; + }else { + cl->rx_callback = scpi_handle_remote_msg; + cl->tx_prepare = scpi_tx_prepare; + } cl->tx_block = true; cl->tx_tout =20 ; cl->knows_txdone = false;/* controller can't ack */
Signature · 1 line
1.9.1
PATCH v2 2/7 scpi: Use legacy variants command index calling scpi_send_message
In reply to Neil ArmstrongIn order to support legacy SCP functions from kernel-wide driver, use legacy command indexes calling scpi_send_message.
--- drivers/firmware/arm_scpi.c | 126 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 107 insertions(+), 19 deletions(-)
drivers/firmware/arm_scpi.c +107 -19
@@ -520,6 +520,9 @@ scpi_clk_get_range(u16 clk_id, unsigned long *min, unsigned long *max)struct clk_get_info clk;__le16 le_clk_id =cpu_to_le16 (clk_id); +if (scpi_info->is_legacy) +return -EOPNOTSUPP ; + ret =scpi_send_message (SCPI_CMD_GET_CLOCK_INFO , &le_clk_id,sizeof (le_clk_id), &clk,sizeof (clk));if (!ret) {
@@ -535,8 +538,14 @@ static unsigned long scpi_clk_get_val(u16 clk_id)struct clk_get_value clk;__le16 le_clk_id =cpu_to_le16 (clk_id); - ret =scpi_send_message (SCPI_CMD_GET_CLOCK_VALUE , &le_clk_id, -sizeof (le_clk_id), &clk,sizeof (clk)); +if (scpi_info->is_legacy) + ret =scpi_send_message (LEGACY_SCPI_CMD_GET_CLOCK_VALUE , + &le_clk_id,sizeof (le_clk_id), + &clk,sizeof (clk)); +else + ret =scpi_send_message (SCPI_CMD_GET_CLOCK_VALUE , &le_clk_id, +sizeof (le_clk_id), &clk,sizeof (clk)); +return ret ? ret :le32_to_cpu (clk.rate); }
@@ -552,13 +561,33 @@ static int scpi_clk_set_val(u16 clk_id, unsigned long rate) &stat, sizeof(stat)); } +static int legacy_scpi_clk_set_val (u16 clk_id,unsigned long rate) +{ +int stat; +struct legacy_clk_set_value clk = { + .id =cpu_to_le16 (clk_id), + .rate =cpu_to_le32 (rate) + }; + +return scpi_send_message (LEGACY_SCPI_CMD_SET_CLOCK_VALUE , + &clk,sizeof (clk), + &stat,sizeof (stat)); +} +static int scpi_dvfs_get_idx (u8 domain) {int ret;u8 dvfs_idx; - ret =scpi_send_message (SCPI_CMD_GET_DVFS , &domain,sizeof (domain), - &dvfs_idx,sizeof (dvfs_idx)); +if (scpi_info->is_legacy) + ret =scpi_send_message (LEGACY_SCPI_CMD_GET_DVFS , + &domain,sizeof (domain), + &dvfs_idx,sizeof (dvfs_idx)); +else + ret =scpi_send_message (SCPI_CMD_GET_DVFS , + &domain,sizeof (domain), + &dvfs_idx,sizeof (dvfs_idx)); +return ret ? ret : dvfs_idx; }
@@ -567,6 +596,11 @@ static int scpi_dvfs_set_idx(u8 domain, u8 index)int stat;struct dvfs_set dvfs = {domain, index}; +if (scpi_info->is_legacy) +return scpi_send_message (LEGACY_SCPI_CMD_SET_DVFS , + &dvfs,sizeof (dvfs), + &stat,sizeof (stat)); +return scpi_send_message (SCPI_CMD_SET_DVFS , &dvfs,sizeof (dvfs), &stat,sizeof (stat)); }
@@ -591,9 +625,14 @@ static struct scpi_dvfs_info *scpi_dvfs_get_info(u8 domain)if (scpi_info->dvfs[domain])/* data already populated */ return scpi_info->dvfs[domain]; - ret =scpi_send_message (SCPI_CMD_GET_DVFS_INFO , &domain,sizeof (domain), - &buf,sizeof (buf)); - +if (scpi_info->is_legacy) + ret =scpi_send_message (LEGACY_SCPI_CMD_GET_DVFS_INFO , + &domain,sizeof (domain), + &buf,sizeof (buf)); +else + ret =scpi_send_message (SCPI_CMD_GET_DVFS_INFO , + &domain,sizeof (domain), + &buf,sizeof (buf));if (ret)return ERR_PTR (ret);
@@ -626,8 +665,12 @@ static int scpi_sensor_get_capability(u16 *sensors)struct sensor_capabilities cap_buf;int ret; - ret =scpi_send_message (SCPI_CMD_SENSOR_CAPABILITIES ,NULL ,0 , &cap_buf, -sizeof (cap_buf)); +if (scpi_info->is_legacy) + ret =scpi_send_message (LEGACY_SCPI_CMD_SENSOR_CAPABILITIES , +NULL ,0 , &cap_buf,sizeof (cap_buf)); +else + ret =scpi_send_message (SCPI_CMD_SENSOR_CAPABILITIES , +NULL ,0 , &cap_buf,sizeof (cap_buf));if (!ret) *sensors =le16_to_cpu (cap_buf.sensors);
@@ -640,8 +683,13 @@ static int scpi_sensor_get_info(u16 sensor_id, struct scpi_sensor_info *info)struct _scpi_sensor_info _info;int ret; - ret =scpi_send_message (SCPI_CMD_SENSOR_INFO , &id,sizeof (id), - &_info,sizeof (_info)); +if (scpi_info->is_legacy) + ret =scpi_send_message (LEGACY_SCPI_CMD_SENSOR_INFO , + &id,sizeof (id), + &_info,sizeof (_info)); +else + ret =scpi_send_message (SCPI_CMD_SENSOR_INFO , &id,sizeof (id), + &_info,sizeof (_info));if (!ret) {memcpy (info, &_info,sizeof (*info)); info->sensor_id =le16_to_cpu (_info.sensor_id);
@@ -656,11 +704,18 @@ static int scpi_sensor_get_value(u16 sensor, u64 *val)struct sensor_value buf;int ret; - ret =scpi_send_message (SCPI_CMD_SENSOR_VALUE , &id,sizeof (id), - &buf,sizeof (buf)); -if (!ret) - *val = (u64 )le32_to_cpu (buf.hi_val) <<32 | -le32_to_cpu (buf.lo_val); +if (scpi_info->is_legacy) { + ret =scpi_send_message (LEGACY_SCPI_CMD_SENSOR_VALUE , + &id,sizeof (id), &buf,sizeof (buf)); +if (!ret) + *val = (u64 )le32_to_cpu (buf.lo_val); + }else { + ret =scpi_send_message (SCPI_CMD_SENSOR_VALUE , &id,sizeof (id), + &buf,sizeof (buf)); +if (!ret) + *val = (u64 )le32_to_cpu (buf.hi_val) <<32 | +le32_to_cpu (buf.lo_val); + }return ret; }
@@ -671,6 +726,9 @@ static int scpi_device_get_power_state(u16 dev_id)u8 pstate;__le16 id =cpu_to_le16 (dev_id); +if (scpi_info->is_legacy) +return -EOPNOTSUPP ; + ret =scpi_send_message (SCPI_CMD_GET_DEVICE_PWR_STATE , &id,sizeof (id), &pstate,sizeof (pstate));return ret ? ret : pstate;
@@ -684,6 +742,9 @@ static int scpi_device_set_power_state(u16 dev_id, u8 pstate) .pstate = pstate, }; +if (scpi_info->is_legacy) +return -EOPNOTSUPP ; +return scpi_send_message (SCPI_CMD_SET_DEVICE_PWR_STATE , &dev_set,sizeof (dev_set), &stat,sizeof (stat)); }
@@ -703,6 +764,21 @@ static struct scpi_ops scpi_ops = { .device_set_power_state = scpi_device_set_power_state, }; +static struct scpi_ops legacy_scpi_ops = { + .get_version = scpi_get_version, + .clk_get_range =NULL , + .clk_get_val = scpi_clk_get_val, + .clk_set_val = legacy_scpi_clk_set_val, + .dvfs_get_idx = scpi_dvfs_get_idx, + .dvfs_set_idx = scpi_dvfs_set_idx, + .dvfs_get_info = scpi_dvfs_get_info, + .sensor_get_capability = scpi_sensor_get_capability, + .sensor_get_info = scpi_sensor_get_info, + .sensor_get_value = scpi_sensor_get_value, + .device_get_power_state =NULL , + .device_set_power_state =NULL , +}; +struct scpi_ops *get_scpi_ops (void ) {return scpi_info ? scpi_info->scpi_ops :NULL ;
@@ -714,12 +790,20 @@ static int scpi_init_versions(struct scpi_drvinfo *info)int ret;struct scp_capabilities caps; - ret =scpi_send_message (SCPI_CMD_SCPI_CAPABILITIES ,NULL ,0 , - &caps,sizeof (caps)); +if (scpi_info->is_legacy) + ret =scpi_send_message (LEGACY_SCPI_CMD_SCPI_CAPABILITIES , +NULL ,0 , &caps,sizeof (caps)); +else + ret =scpi_send_message (SCPI_CMD_SCPI_CAPABILITIES ,NULL ,0 , + &caps,sizeof (caps));if (!ret) { info->protocol_version =le32_to_cpu (caps.protocol_version); info->firmware_version =le32_to_cpu (caps.platform_version); } +/* Ignore error if not implemented */ +if (scpi_info->is_legacy && ret == -EOPNOTSUPP ) +return 0 ; +return ret; }
@@ -897,7 +981,11 @@ err:FW_REV_MAJOR (scpi_info->firmware_version),FW_REV_MINOR (scpi_info->firmware_version), FW_REV_PATCH(scpi_info->firmware_version)); - scpi_info->scpi_ops = &scpi_ops; + +if (scpi_info->is_legacy) + scpi_info->scpi_ops = &legacy_scpi_ops; +else + scpi_info->scpi_ops = &scpi_ops; ret =sysfs_create_groups (&dev->kobj, versions_groups);if (ret)
Signature · 1 line
1.9.1
PATCH v2 3/7 scpi: Add support for Legacy match table for Amlogic GXBB SoC
In reply to Neil ArmstrongAdd new DT match table to setup the is_legacy boolean value across the scpi functions.
Add the Amlogic GXBB SoC compatible for platform and as legacy match entry.
--- drivers/firmware/arm_scpi.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/firmware/arm_scpi.c +9 -0
@@ -888,6 +888,11 @@ static int scpi_alloc_xfer_list(struct device *dev, struct scpi_chan *ch)return 0 ; } +static const struct of_device_id legacy_scpi_of_match[] = { + {.compatible ="amlogic,meson-gxbb-scpi" }, + {}, +}; +static int scpi_probe (struct platform_device *pdev) {int count, idx, ret;
@@ -900,6 +905,9 @@ static int scpi_probe(struct platform_device *pdev)if (!scpi_info)return -ENOMEM ; +if (of_match_device (legacy_scpi_of_match, &pdev->dev)) + scpi_info->is_legacy = true; + count =of_count_phandle_with_args (np,"mboxes" ,"#mbox-cells" );if (count <0 ) {dev_err (dev,"no mboxes property in '%s'\n" , np->full_name);
@@ -996,6 +1004,7 @@ err:static const struct of_device_id scpi_of_match[] = { {.compatible ="arm,scpi" }, + {.compatible ="amlogic,meson-gxbb-scpi" }, {}, };
Signature · 1 line
1.9.1
PATCH v2 4/7 scpi: grow MAX_DVFS_OPPS to 16 entries
In reply to Neil ArmstrongSince Amlogic SoCs reports more than 8 OPPs per domains, grow the structure size to 16.
--- drivers/firmware/arm_scpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/arm_scpi.c +1 -1
@@ -68,7 +68,7 @@#define SCPI_SLOT 0#define MAX_DVFS_DOMAINS 8 -#define MAX_DVFS_OPPS 8 +#define MAX_DVFS_OPPS 16#define DVFS_LATENCY (hdr) (le32_to_cpu(hdr) >> 16)#define DVFS_OPP_COUNT (hdr) ((le32_to_cpu(hdr) >> 8) & 0xff)
Signature · 1 line
1.9.1
PATCH v2 5/7 dt-bindings: Add support for Amlogic GXBB SCPI Interface
In reply to Neil Armstrong--- Documentation/devicetree/bindings/arm/arm,scpi.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/arm/arm,scpi.txt +5 -3
@@ -7,7 +7,7 @@ by Linux to initiate various system control and power operations. Required properties: -- compatible : should be "arm,scpi" +- compatible : should be "arm,scpi" or "amlogic,meson-gxbb-scpi" - mboxes: List of phandle and mailbox channel specifiers All the channels reserved by remote SCP firmware for use by SCPI message protocol should be specified in any order
@@ -60,7 +60,8 @@ A small area of SRAM is reserved for SCPI communication between application processors and SCP. Required properties: -- compatible : should be "arm,juno-sram-ns" for Non-secure SRAM on Juno +- compatible : should be "arm,juno-sram-ns" for Non-secure SRAM on Juno, + or "amlogic,meson-gxbb-sram" for Amlogic GXBB SoC. The rest of the properties should follow the generic mmio-sram description found in ../../sram/sram.txt
@@ -70,7 +71,8 @@ Each sub-node represents the reserved area for SCPI. Required sub-node properties: - reg : The base offset and size of the reserved area with the SRAM - compatible : should be "arm,juno-scp-shmem" for Non-secure SRAM based - shared memory on Juno platforms + shared memory on Juno platforms or + "amlogic,meson-gxbb-scp-shmem" for Amlogic GXBB SoC. Sensor bindings for the sensors based on SCPI Message Protocol --------------------------------------------------------------
Signature · 1 line
1.9.1
PATCH v2 6/7 ARM64: dts: meson-gxbb: Add SRAM node
In reply to Neil Armstrong--- arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +9 -0
@@ -124,6 +124,15 @@ #size-cells = <2>; ranges; + sram: sram at c8000000 { + compatible = "amlogic,meson-gxbb-sram", "mmio-sram"; + reg = <0x0 0xc8000000 0x0 0x14000>; + + #address-cells = <1>; + #size-cells = <1>; + ranges = <0 0x0 0xc8000000 0x14000>; + }; + cbus: cbus at c1100000 { compatible = "simple-bus"; reg = <0x0 0xc1100000 0x0 0x100000>;
Signature · 1 line
1.9.1
PATCH v2 7/7 ARM64: dts: meson-gxbb: Add SCPI with cpufreq & sensors Nodes
In reply to Neil Armstrong--- arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi +36 -0
@@ -61,6 +61,7 @@ compatible = "arm,cortex-a53", "arm,armv8"; reg = <0x0 0x0>; enable-method = "psci"; + clocks = <&scpi_dvfs 0>; }; cpu1: cpu at 1 {
@@ -68,6 +69,7 @@ compatible = "arm,cortex-a53", "arm,armv8"; reg = <0x0 0x1>; enable-method = "psci"; + clocks = <&scpi_dvfs 0>; }; cpu2: cpu at 2 {
@@ -75,6 +77,7 @@ compatible = "arm,cortex-a53", "arm,armv8"; reg = <0x0 0x2>; enable-method = "psci"; + clocks = <&scpi_dvfs 0>; }; cpu3: cpu at 3 {
@@ -82,6 +85,7 @@ compatible = "arm,cortex-a53", "arm,armv8"; reg = <0x0 0x3>; enable-method = "psci"; + clocks = <&scpi_dvfs 0>; }; };
@@ -99,6 +103,28 @@ method = "smc"; }; + scpi { + compatible = "amlogic,meson-gxbb-scpi"; + mboxes = <&mailbox 1 &mailbox 2>; + shmem = <&cpu_scp_lpri &cpu_scp_hpri>; + + clocks { + compatible = "arm,scpi-clocks"; + + scpi_dvfs: scpi_clocks at 0 { + compatible = "arm,scpi-dvfs-clocks"; + #clock-cells = <1>; + clock-indices = <0>; + clock-output-names = "vcpu"; + }; + }; + + scpi_sensors: sensors { + compatible = "arm,scpi-sensors"; + #thermal-sensor-cells = <1>; + }; + }; + timer { compatible = "arm,armv8-timer"; interrupts = <GIC_PPI 13
@@ -131,6 +157,16 @@ #address-cells = <1>; #size-cells = <1>; ranges = <0 0x0 0xc8000000 0x14000>; + + cpu_scp_lpri: scp-shmem at 0 { + compatible = "amlogic,meson-gxbb-scp-shmem"; + reg = <0x13000 0x400>; + }; + + cpu_scp_hpri: scp-shmem at 200 { + compatible = "amlogic,meson-gxbb-scp-shmem"; + reg = <0x13400 0x400>; + }; }; cbus: cbus at c1100000 {
Signature · 1 line
1.9.1
Quoted 32 lines · Neil Armstrong
This patchset aims to support the legacy SCPI firmware implementation that was delivered as early technology preview for the JUNO platform.
Finally a stable, maintained and public implementation for the SCPI protocol has been upstreamed part of the JUNO support and it is the recommended way of implementing SCP communication on ARMv8 platforms.
The Amlogic GXBB platform is using this legacy protocol, as the RK3368 & RK3399 platforms. This patchset will only add support for Amlogic GXBB SoC.
This patchset add support for the legacy protocol in the
arm_scpi.cfile, avoiding code duplication.Last RFC discution tread can be found at : https://lkml.org/lkml/2016/8/9/210
The last patch depends on the "Platform MHU" dtsi patch.
Changes since v1 at : http://lkml.kernel.org/r/1471515066-3626-1-git-send-email-narmstrong at baylibre.com
- Droppedvendor_send_messageand rockchip vendor mechanism patches
- Merged alternate functions into main functions usingis_legacyboolean
- Added DT match table to setis_legacyto true
- Kept alternatescpi_opsstructure for legacyNeil Armstrong (7):
scpi: Add alternative legacy structures, functions and macros
scpi: Use legacy variants command index callingscpi_send_message
scpi: Add support for Legacy match table for Amlogic GXBB SoC
scpi: growMAX_DVFS_OPPSto 16 entries
dt-bindings: Add support for Amlogic GXBB SCPI Interface
ARM64: dts: meson-gxbb: Add SRAM node
ARM64: dts: meson-gxbb: Add SCPI with cpufreq & sensors Nodes
Quoted 5 lines
Documentation/devicetree/bindings/arm/arm,scpi.txt | 8 +- arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 45 ++++ drivers/firmware/arm_scpi.c | 279 +++++++++++++++++++-- 3 files changed, 302 insertions(+), 30 deletions(-)
Hi Sudeep,
Sorry but I posted this V2 before you had time to look at my previous v1 replies...
In this serie, I merged the scpi_send_message, but I must still evaluate how it's possible to use the list to queue commands.
Here I used if(is_legacy) to stop duplicating functions, is this ok for you ?
Thanks,
Neil
Quoted 39 lines · Neil Armstrong
Quoted 32 lines · Neil Armstrong
This patchset aims to support the legacy SCPI firmware implementation that was delivered as early technology preview for the JUNO platform.
Finally a stable, maintained and public implementation for the SCPI protocol has been upstreamed part of the JUNO support and it is the recommended way of implementing SCP communication on ARMv8 platforms.
The Amlogic GXBB platform is using this legacy protocol, as the RK3368 & RK3399 platforms. This patchset will only add support for Amlogic GXBB SoC.
This patchset add support for the legacy protocol in the
arm_scpi.cfile, avoiding code duplication.Last RFC discution tread can be found at : https://lkml.org/lkml/2016/8/9/210
The last patch depends on the "Platform MHU" dtsi patch.
Changes since v1 at : http://lkml.kernel.org/r/1471515066-3626-1-git-send-email-narmstrong at baylibre.com
- Droppedvendor_send_messageand rockchip vendor mechanism patches
- Merged alternate functions into main functions usingis_legacyboolean
- Added DT match table to setis_legacyto true
- Kept alternatescpi_opsstructure for legacyNeil Armstrong (7):
scpi: Add alternative legacy structures, functions and macros
scpi: Use legacy variants command index callingscpi_send_message
scpi: Add support for Legacy match table for Amlogic GXBB SoC
scpi: growMAX_DVFS_OPPSto 16 entries
dt-bindings: Add support for Amlogic GXBB SCPI Interface
ARM64: dts: meson-gxbb: Add SRAM node
ARM64: dts: meson-gxbb: Add SCPI with cpufreq & sensors NodesQuoted 5 lines
Documentation/devicetree/bindings/arm/arm,scpi.txt | 8 +- arch/arm64/boot/dts/amlogic/meson-gxbb.dtsi | 45 ++++ drivers/firmware/arm_scpi.c | 279 +++++++++++++++++++-- 3 files changed, 302 insertions(+), 30 deletions(-)
Quoted 5 lines
Hi Sudeep,
Sorry but I posted this V2 before you had time to look at my previous v1 replies...
That's fine.
Quoted 3 lines
In this series, I merged the
scpi_send_message, but I must still evaluate how it's possible to use the list to queue commands.
Ah OK.
Quoted 3 lines
Here I used
if(is_legacy)to stop duplicating functions, is this ok for you ?
I am still thinking if it can be abstracted well, some kind of mapping but haven't thought too much about that yet. Also I was thinking about bitmap for high priority commands. I remember doing something before but seem to have lost that copy. I will try to dig it out..
Signature · 2 lines
Regards, Sudeep
Quoted 3 lines · Sudeep Holla
On 25/08/16 14:18, Neil Armstrong wrote:
[...]
Quoted 9 lines
Quoted 3 lines
Here I used
if(is_legacy)to stop duplicating functions, is this ok for you ?I am still thinking if it can be abstracted well, some kind of mapping but haven't thought too much about that yet. Also I was thinking about bitmap for high priority commands. I remember doing something before but seem to have lost that copy. I will try to dig it out..
OK how about something like:
1. in struct scpi_drvinfo
DECLARE_BITMAP(cmd_priority, SCPI_CMD_COUNT);
2. scpi_send_message
scpi_chan = test_bit(cmd, scpi_info->cmd_priority) ? scpi_info->channels + 1 : scpi_info->channels;
3. probe
for (idx = 0; idx < ARRAY_SIZE(hpriority_cmds); idx++) set_bit(hpriority_cmds[idx], scpi_info->cmd_priority);
For commands, I am thinking some kind of indirection like the below patch. See if that helps, I will add the description later, but you can build your patches on top of it if you think that works and keeps code simple.
Regards,
Sudeep
-->8
From afde0d2f1d3381d443445301ab5ec111276934e5 Mon Sep 17 00:00:00 2001
From: Sudeep Holla <[email protected]>
Date: Thu, 25 Aug 2016 17:21:49 +0100
Subject: [PATCH] firmware: arm_scpi: create command indirection to support
legacy commands
--- drivers/firmware/arm_scpi.c | 68 +++++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 17 deletions(-)
drivers/firmware/arm_scpi.c +34 -1
@@ -129,7 +129,39 @@ enum scpi_std_cmd {SCPI_CMD_SENSOR_ASYNC_VALUE =0x1a ,SCPI_CMD_SET_DEVICE_PWR_STATE =0x1b , SCPI_CMD_GET_DEVICE_PWR_STATE = 0x1c, -SCPI_CMD_COUNT +}; + +enum scpi_drv_cmd { +SCPI_CAPABILITIES =0 , +GET_DVFS_INFO =1 , +SET_DVFS =2 , +GET_DVFS =3 , +GET_CLOCK_INFO =4 , +SET_CLOCK_VALUE =5 , +GET_CLOCK_VALUE =6 , +PSU_CAPABILITIES =7 , +SENSOR_CAPABILITIES =8 , +SENSOR_INFO =9 , +SENSOR_VALUE =10 , +SET_DEV_PWR_STATE =11 , +GET_DEV_PWR_STATE =12 , +CMD_MAX_COUNT +}; + +static int scpi_std_commands[CMD_MAX_COUNT ] = { +SCPI_CMD_SCPI_CAPABILITIES , +SCPI_CMD_GET_DVFS_INFO , +SCPI_CMD_SET_DVFS , +SCPI_CMD_GET_DVFS , +SCPI_CMD_GET_CLOCK_INFO , +SCPI_CMD_SET_CLOCK_VALUE , +SCPI_CMD_GET_CLOCK_VALUE , +SCPI_CMD_PSU_CAPABILITIES , +SCPI_CMD_SENSOR_CAPABILITIES , +SCPI_CMD_SENSOR_INFO , +SCPI_CMD_SENSOR_VALUE , +SCPI_CMD_SET_DEVICE_PWR_STATE , +SCPI_CMD_GET_DEVICE_PWR_STATE , }; struct scpi_xfer {
@@ -161,6 +193,7 @@ struct scpi_drvinfo {u32 protocol_version;u32 firmware_version;int num_chans; +int *cmds;atomic_t next_chan;struct scpi_ops *scpi_ops;struct scpi_chan *channels;
@@ -397,7 +430,7 @@ scpi_clk_get_range(u16 clk_id, unsigned long *min,
unsigned long *max)
struct clk_get_info clk;
__le16 le_clk_id = cpu_to_le16(clk_id);
- ret = scpi_send_message(SCPI_CMD_GET_CLOCK_INFO, &le_clk_id,
+ ret = scpi_send_message(scpi_info->cmds[GET_CLOCK_INFO], &le_clk_id,
sizeof(le_clk_id), &clk, sizeof(clk));
if (!ret) {
*min = le32_to_cpu(clk.min_rate);
@@ -412,7 +445,7 @@ static unsigned long scpi_clk_get_val(u16 clk_id)
struct clk_get_value clk;
__le16 le_clk_id = cpu_to_le16(clk_id);
- ret = scpi_send_message(SCPI_CMD_GET_CLOCK_VALUE, &le_clk_id,
+ ret = scpi_send_message(scpi_info->cmds[GET_CLOCK_VALUE], &le_clk_id,
sizeof(le_clk_id), &clk, sizeof(clk));
return ret ? ret : le32_to_cpu(clk.rate);
}
@@ -425,8 +458,8 @@ static int scpi_clk_set_val(u16 clk_id, unsigned long rate)
.rate = cpu_to_le32(rate)
};
- return scpi_send_message(SCPI_CMD_SET_CLOCK_VALUE, &clk, sizeof(clk),
- &stat, sizeof(stat));
+ return scpi_send_message(scpi_info->cmds[SET_CLOCK_VALUE], &clk,
+ sizeof(clk), &stat, sizeof(stat));
}
static int scpi_dvfs_get_idx(u8 domain)
@@ -434,8 +467,8 @@ static int scpi_dvfs_get_idx(u8 domain)
int ret;
u8 dvfs_idx;
- ret = scpi_send_message(SCPI_CMD_GET_DVFS, &domain, sizeof(domain),
- &dvfs_idx, sizeof(dvfs_idx));
+ ret = scpi_send_message(scpi_info->cmds[GET_DVFS], &domain,
+ sizeof(domain), &dvfs_idx, sizeof(dvfs_idx));
return ret ? ret : dvfs_idx;
}
@@ -444,7 +477,7 @@ static int scpi_dvfs_set_idx(u8 domain, u8 index)
int stat;
struct dvfs_set dvfs = {domain, index};
- return scpi_send_message(SCPI_CMD_SET_DVFS, &dvfs, sizeof(dvfs),
+ return scpi_send_message(scpi_info->cmds[SET_DVFS], &dvfs, sizeof(dvfs),
&stat, sizeof(stat));
}
@@ -468,8 +501,8 @@ static struct scpi_dvfs_info
*scpi_dvfs_get_info(u8 domain)
if (scpi_info->dvfs[domain]) /* data already populated */
return scpi_info->dvfs[domain];
- ret = scpi_send_message(SCPI_CMD_GET_DVFS_INFO, &domain, sizeof(domain),
- &buf, sizeof(buf));
+ ret = scpi_send_message(scpi_info->cmds[GET_DVFS_INFO], &domain,
+ sizeof(domain), &buf, sizeof(buf));
if (ret)
return ERR_PTR(ret);
@@ -503,8 +536,8 @@ static int scpi_sensor_get_capability(u16 *sensors)
struct sensor_capabilities cap_buf;
int ret;
- ret = scpi_send_message(SCPI_CMD_SENSOR_CAPABILITIES, NULL, 0, &cap_buf,
- sizeof(cap_buf));
+ ret = scpi_send_message(scpi_info->cmds[SENSOR_CAPABILITIES], NULL, 0,
+ &cap_buf, sizeof(cap_buf));
if (!ret)
*sensors = le16_to_cpu(cap_buf.sensors);
@@ -517,7 +550,7 @@ static int scpi_sensor_get_info(u16 sensor_id,
struct scpi_sensor_info *info)
struct _scpi_sensor_info _info;
int ret;
- ret = scpi_send_message(SCPI_CMD_SENSOR_INFO, &id, sizeof(id),
+ ret = scpi_send_message(scpi_info->cmds[SENSOR_INFO], &id, sizeof(id),
&_info, sizeof(_info));
if (!ret) {
memcpy(info, &_info, sizeof(*info));
@@ -533,7 +566,7 @@ static int scpi_sensor_get_value(u16 sensor, u64 *val)
struct sensor_value buf;
int ret;
- ret = scpi_send_message(SCPI_CMD_SENSOR_VALUE, &id, sizeof(id),
+ ret = scpi_send_message(scpi_info->cmds[SENSOR_VALUE], &id, sizeof(id),
&buf, sizeof(buf));
if (!ret)
*val = (u64)le32_to_cpu(buf.hi_val) << 32 |
@@ -548,7 +581,7 @@ static int scpi_device_get_power_state(u16 dev_id)
u8 pstate;
__le16 id = cpu_to_le16(dev_id);
- ret = scpi_send_message(SCPI_CMD_GET_DEVICE_PWR_STATE, &id,
+ ret = scpi_send_message(scpi_info->cmds[GET_DEV_PWR_STATE], &id,
sizeof(id), &pstate, sizeof(pstate));
return ret ? ret : pstate;
}
@@ -561,7 +594,7 @@ static int scpi_device_set_power_state(u16 dev_id, u8 pstate)
.pstate = pstate,
};
- return scpi_send_message(SCPI_CMD_SET_DEVICE_PWR_STATE, &dev_set,
+ return scpi_send_message(scpi_info->cmds[SET_DEV_PWR_STATE], &dev_set,
sizeof(dev_set), &stat, sizeof(stat));
}
@@ -591,7 +624,7 @@ static int scpi_init_versions(struct scpi_drvinfo
*info)
int ret;
struct scp_capabilities caps;
- ret = scpi_send_message(SCPI_CMD_SCPI_CAPABILITIES, NULL, 0,
+ ret = scpi_send_message(info->cmds[SCPI_CAPABILITIES], NULL, 0,
&caps, sizeof(caps));
if (!ret) {
info->protocol_version = le32_to_cpu(caps.protocol_version);
@@ -754,6 +787,7 @@ static int scpi_probe(struct platform_device *pdev)
scpi_info->channels = scpi_chan;
scpi_info->num_chans = count;
+ scpi_info->cmds = scpi_std_commands;
platform_set_drvdata(pdev, scpi_info);
ret = scpi_init_versions(scpi_info);
Signature · 1 line
2.7.4