Re: [RFC PATCH 5/8] firmware: arm_scmi: add initial support for clock protocol

2017-06-07 Thread Roy Franz
On Wed, Jun 7, 2017 at 9:10 AM, Sudeep Holla  wrote:
> The clock protocol is intended for management of clocks. It is used to
> enable or disable clocks, and to set and get the clock rates. This
> protocol provides commands to describe the protocol version, discover
> various implementation specific attributes, describe a clock, enable
> and disable a clock and get/set the rate of the clock synchronously or
> asynchronously.
>
> This patch adds initial support for the clock protocol.
>
> Signed-off-by: Sudeep Holla 
> ---
>  drivers/firmware/arm_scmi/Makefile |   2 +-
>  drivers/firmware/arm_scmi/clock.c  | 340 
> +
>  drivers/firmware/arm_scmi/common.h |   1 +
>  include/linux/scmi_protocol.h  |  18 ++
>  4 files changed, 360 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/firmware/arm_scmi/clock.c
>
> diff --git a/drivers/firmware/arm_scmi/Makefile 
> b/drivers/firmware/arm_scmi/Makefile
> index 159de726ee45..6836b1f38f7f 100644
> --- a/drivers/firmware/arm_scmi/Makefile
> +++ b/drivers/firmware/arm_scmi/Makefile
> @@ -1,2 +1,2 @@
>  obj-$(CONFIG_ARM_SCMI_PROTOCOL)= arm_scmi.o
> -arm_scmi-y = base.o driver.o perf.o
> +arm_scmi-y = base.o clock.o driver.o perf.o
> diff --git a/drivers/firmware/arm_scmi/clock.c 
> b/drivers/firmware/arm_scmi/clock.c
> new file mode 100644
> index ..e02827a48ab7
> --- /dev/null
> +++ b/drivers/firmware/arm_scmi/clock.c
> @@ -0,0 +1,340 @@
> +/*
> + * System Control and Management Interface (SCMI) Clock Protocol
> + *
> + * Copyright (C) 2017 ARM Ltd.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program. If not, see .
> + */
> +
> +#include "common.h"
> +
> +enum scmi_clock_protocol_cmd {
> +   CLOCK_ATTRIBUTES = 0x3,
> +   CLOCK_DESCRIBE_RATES = 0x4,
> +   CLOCK_RATE_SET = 0x5,
> +   CLOCK_RATE_GET = 0x6,
> +   CLOCK_CONFIG_SET = 0x7,
> +};
> +
> +struct scmi_msg_resp_clock_protocol_attributes {
> +   __le16 num_clocks;
> +   u8 max_async_req;
> +   u8 reserved;
> +} __packed;
> +
> +struct scmi_msg_resp_clock_attributes {
> +   __le32 attributes;
> +#defineCLOCK_ENABLEBIT(0)
> +   u8 name[SCMI_MAX_STR_SIZE];
> +} __packed;
> +
> +struct scmi_clock_set_config {
> +   __le32 id;
> +   __le32 attributes;
> +} __packed;
> +
> +struct scmi_msg_clock_describe_rates {
> +   __le32 id;
> +   __le32 rate_index;
> +} __packed;
> +
> +struct scmi_msg_resp_clock_describe_rates {
> +   __le16 num_returned;
> +#define NUM_RETURNED_MASK  (0xfff)
> +#define RATE_DISCRETE(x)   ((x) & BIT(12))
> +   __le16 num_remaining;
> +   struct {
> +   __le32 value_low;
> +   __le32 value_high;
> +   } rate[0];
> +#define RATE_TO_U64(X) \
> +({ \
> +   typeof(X) x = (X);  \
> +   le32_to_cpu((x).value_low) | (u64)le32_to_cpu((x).value_high) >> 32; \
> +})
> +} __packed;
> +
> +struct scmi_clock_set_rate {
> +   __le32 flags;
> +#define CLOCK_SET_ASYSCBIT(0)
> +#define CLOCK_SET_DELAYED  BIT(1)
> +#define CLOCK_ROUND_UP BIT(2)
> +#define CLOCK_ROUND_AUTO   BIT(3)
> +   __le32 id;
> +   __le32 value_low;
> +   __le32 value_high;
> +} __packed;
> +
> +struct clock_info {
> +   u32 attributes;
> +   char name[SCMI_MAX_STR_SIZE];
> +   union {
> +   int num_rates;
> +   u64 rates[MAX_NUM_RATES];
> +   struct {
> +   u64 min_rate;
> +   u64 max_rate;
> +   u64 step_size;
> +   } range;
> +   };
> +};
> +
> +struct scmi_clock_info {
> +   int num_clocks;
> +   int max_async_req;
> +   struct clock_info *clk;
> +};
> +
> +static struct scmi_clock_info clocks;
> +
> +static int scmi_clock_protocol_attributes_get(struct scmi_handle *handle,
> + struct scmi_clock_info *clocks)
> +{
> +   int ret;
> +   struct scmi_xfer *t;
> +   struct scmi_msg_resp_clock_protocol_attributes *attr;
> +
> +   ret = scmi_one_xfer_init(handle, PROTOCOL_ATTRIBUTES,
> +SCMI_PROTOCOL_CLOCK, 0, sizeof(*attr), );
> +   if (ret)
> +   return ret;
> +
> +   attr = (struct scmi_msg_resp_clock_protocol_attributes 

Re: [RFC PATCH 5/8] firmware: arm_scmi: add initial support for clock protocol

2017-06-07 Thread Roy Franz
On Wed, Jun 7, 2017 at 9:10 AM, Sudeep Holla  wrote:
> The clock protocol is intended for management of clocks. It is used to
> enable or disable clocks, and to set and get the clock rates. This
> protocol provides commands to describe the protocol version, discover
> various implementation specific attributes, describe a clock, enable
> and disable a clock and get/set the rate of the clock synchronously or
> asynchronously.
>
> This patch adds initial support for the clock protocol.
>
> Signed-off-by: Sudeep Holla 
> ---
>  drivers/firmware/arm_scmi/Makefile |   2 +-
>  drivers/firmware/arm_scmi/clock.c  | 340 
> +
>  drivers/firmware/arm_scmi/common.h |   1 +
>  include/linux/scmi_protocol.h  |  18 ++
>  4 files changed, 360 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/firmware/arm_scmi/clock.c
>
> diff --git a/drivers/firmware/arm_scmi/Makefile 
> b/drivers/firmware/arm_scmi/Makefile
> index 159de726ee45..6836b1f38f7f 100644
> --- a/drivers/firmware/arm_scmi/Makefile
> +++ b/drivers/firmware/arm_scmi/Makefile
> @@ -1,2 +1,2 @@
>  obj-$(CONFIG_ARM_SCMI_PROTOCOL)= arm_scmi.o
> -arm_scmi-y = base.o driver.o perf.o
> +arm_scmi-y = base.o clock.o driver.o perf.o
> diff --git a/drivers/firmware/arm_scmi/clock.c 
> b/drivers/firmware/arm_scmi/clock.c
> new file mode 100644
> index ..e02827a48ab7
> --- /dev/null
> +++ b/drivers/firmware/arm_scmi/clock.c
> @@ -0,0 +1,340 @@
> +/*
> + * System Control and Management Interface (SCMI) Clock Protocol
> + *
> + * Copyright (C) 2017 ARM Ltd.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program. If not, see .
> + */
> +
> +#include "common.h"
> +
> +enum scmi_clock_protocol_cmd {
> +   CLOCK_ATTRIBUTES = 0x3,
> +   CLOCK_DESCRIBE_RATES = 0x4,
> +   CLOCK_RATE_SET = 0x5,
> +   CLOCK_RATE_GET = 0x6,
> +   CLOCK_CONFIG_SET = 0x7,
> +};
> +
> +struct scmi_msg_resp_clock_protocol_attributes {
> +   __le16 num_clocks;
> +   u8 max_async_req;
> +   u8 reserved;
> +} __packed;
> +
> +struct scmi_msg_resp_clock_attributes {
> +   __le32 attributes;
> +#defineCLOCK_ENABLEBIT(0)
> +   u8 name[SCMI_MAX_STR_SIZE];
> +} __packed;
> +
> +struct scmi_clock_set_config {
> +   __le32 id;
> +   __le32 attributes;
> +} __packed;
> +
> +struct scmi_msg_clock_describe_rates {
> +   __le32 id;
> +   __le32 rate_index;
> +} __packed;
> +
> +struct scmi_msg_resp_clock_describe_rates {
> +   __le16 num_returned;
> +#define NUM_RETURNED_MASK  (0xfff)
> +#define RATE_DISCRETE(x)   ((x) & BIT(12))
> +   __le16 num_remaining;
> +   struct {
> +   __le32 value_low;
> +   __le32 value_high;
> +   } rate[0];
> +#define RATE_TO_U64(X) \
> +({ \
> +   typeof(X) x = (X);  \
> +   le32_to_cpu((x).value_low) | (u64)le32_to_cpu((x).value_high) >> 32; \
> +})
> +} __packed;
> +
> +struct scmi_clock_set_rate {
> +   __le32 flags;
> +#define CLOCK_SET_ASYSCBIT(0)
> +#define CLOCK_SET_DELAYED  BIT(1)
> +#define CLOCK_ROUND_UP BIT(2)
> +#define CLOCK_ROUND_AUTO   BIT(3)
> +   __le32 id;
> +   __le32 value_low;
> +   __le32 value_high;
> +} __packed;
> +
> +struct clock_info {
> +   u32 attributes;
> +   char name[SCMI_MAX_STR_SIZE];
> +   union {
> +   int num_rates;
> +   u64 rates[MAX_NUM_RATES];
> +   struct {
> +   u64 min_rate;
> +   u64 max_rate;
> +   u64 step_size;
> +   } range;
> +   };
> +};
> +
> +struct scmi_clock_info {
> +   int num_clocks;
> +   int max_async_req;
> +   struct clock_info *clk;
> +};
> +
> +static struct scmi_clock_info clocks;
> +
> +static int scmi_clock_protocol_attributes_get(struct scmi_handle *handle,
> + struct scmi_clock_info *clocks)
> +{
> +   int ret;
> +   struct scmi_xfer *t;
> +   struct scmi_msg_resp_clock_protocol_attributes *attr;
> +
> +   ret = scmi_one_xfer_init(handle, PROTOCOL_ATTRIBUTES,
> +SCMI_PROTOCOL_CLOCK, 0, sizeof(*attr), );
> +   if (ret)
> +   return ret;
> +
> +   attr = (struct scmi_msg_resp_clock_protocol_attributes *)t->rx.buf;
> +
> +   ret = 

[RFC PATCH 5/8] firmware: arm_scmi: add initial support for clock protocol

2017-06-07 Thread Sudeep Holla
The clock protocol is intended for management of clocks. It is used to
enable or disable clocks, and to set and get the clock rates. This
protocol provides commands to describe the protocol version, discover
various implementation specific attributes, describe a clock, enable
and disable a clock and get/set the rate of the clock synchronously or
asynchronously.

This patch adds initial support for the clock protocol.

Signed-off-by: Sudeep Holla 
---
 drivers/firmware/arm_scmi/Makefile |   2 +-
 drivers/firmware/arm_scmi/clock.c  | 340 +
 drivers/firmware/arm_scmi/common.h |   1 +
 include/linux/scmi_protocol.h  |  18 ++
 4 files changed, 360 insertions(+), 1 deletion(-)
 create mode 100644 drivers/firmware/arm_scmi/clock.c

diff --git a/drivers/firmware/arm_scmi/Makefile 
b/drivers/firmware/arm_scmi/Makefile
index 159de726ee45..6836b1f38f7f 100644
--- a/drivers/firmware/arm_scmi/Makefile
+++ b/drivers/firmware/arm_scmi/Makefile
@@ -1,2 +1,2 @@
 obj-$(CONFIG_ARM_SCMI_PROTOCOL)= arm_scmi.o
-arm_scmi-y = base.o driver.o perf.o
+arm_scmi-y = base.o clock.o driver.o perf.o
diff --git a/drivers/firmware/arm_scmi/clock.c 
b/drivers/firmware/arm_scmi/clock.c
new file mode 100644
index ..e02827a48ab7
--- /dev/null
+++ b/drivers/firmware/arm_scmi/clock.c
@@ -0,0 +1,340 @@
+/*
+ * System Control and Management Interface (SCMI) Clock Protocol
+ *
+ * Copyright (C) 2017 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see .
+ */
+
+#include "common.h"
+
+enum scmi_clock_protocol_cmd {
+   CLOCK_ATTRIBUTES = 0x3,
+   CLOCK_DESCRIBE_RATES = 0x4,
+   CLOCK_RATE_SET = 0x5,
+   CLOCK_RATE_GET = 0x6,
+   CLOCK_CONFIG_SET = 0x7,
+};
+
+struct scmi_msg_resp_clock_protocol_attributes {
+   __le16 num_clocks;
+   u8 max_async_req;
+   u8 reserved;
+} __packed;
+
+struct scmi_msg_resp_clock_attributes {
+   __le32 attributes;
+#defineCLOCK_ENABLEBIT(0)
+   u8 name[SCMI_MAX_STR_SIZE];
+} __packed;
+
+struct scmi_clock_set_config {
+   __le32 id;
+   __le32 attributes;
+} __packed;
+
+struct scmi_msg_clock_describe_rates {
+   __le32 id;
+   __le32 rate_index;
+} __packed;
+
+struct scmi_msg_resp_clock_describe_rates {
+   __le16 num_returned;
+#define NUM_RETURNED_MASK  (0xfff)
+#define RATE_DISCRETE(x)   ((x) & BIT(12))
+   __le16 num_remaining;
+   struct {
+   __le32 value_low;
+   __le32 value_high;
+   } rate[0];
+#define RATE_TO_U64(X) \
+({ \
+   typeof(X) x = (X);  \
+   le32_to_cpu((x).value_low) | (u64)le32_to_cpu((x).value_high) >> 32; \
+})
+} __packed;
+
+struct scmi_clock_set_rate {
+   __le32 flags;
+#define CLOCK_SET_ASYSCBIT(0)
+#define CLOCK_SET_DELAYED  BIT(1)
+#define CLOCK_ROUND_UP BIT(2)
+#define CLOCK_ROUND_AUTO   BIT(3)
+   __le32 id;
+   __le32 value_low;
+   __le32 value_high;
+} __packed;
+
+struct clock_info {
+   u32 attributes;
+   char name[SCMI_MAX_STR_SIZE];
+   union {
+   int num_rates;
+   u64 rates[MAX_NUM_RATES];
+   struct {
+   u64 min_rate;
+   u64 max_rate;
+   u64 step_size;
+   } range;
+   };
+};
+
+struct scmi_clock_info {
+   int num_clocks;
+   int max_async_req;
+   struct clock_info *clk;
+};
+
+static struct scmi_clock_info clocks;
+
+static int scmi_clock_protocol_attributes_get(struct scmi_handle *handle,
+ struct scmi_clock_info *clocks)
+{
+   int ret;
+   struct scmi_xfer *t;
+   struct scmi_msg_resp_clock_protocol_attributes *attr;
+
+   ret = scmi_one_xfer_init(handle, PROTOCOL_ATTRIBUTES,
+SCMI_PROTOCOL_CLOCK, 0, sizeof(*attr), );
+   if (ret)
+   return ret;
+
+   attr = (struct scmi_msg_resp_clock_protocol_attributes *)t->rx.buf;
+
+   ret = scmi_do_xfer(handle, t);
+   if (!ret) {
+   clocks->num_clocks = le16_to_cpu(attr->num_clocks);
+   clocks->max_async_req = attr->max_async_req;
+   }
+
+   scmi_put_one_xfer(handle, t);
+   return ret;
+}
+
+static int scmi_clock_attributes_get(struct scmi_handle *handle, u32 clk_id,
+  

[RFC PATCH 5/8] firmware: arm_scmi: add initial support for clock protocol

2017-06-07 Thread Sudeep Holla
The clock protocol is intended for management of clocks. It is used to
enable or disable clocks, and to set and get the clock rates. This
protocol provides commands to describe the protocol version, discover
various implementation specific attributes, describe a clock, enable
and disable a clock and get/set the rate of the clock synchronously or
asynchronously.

This patch adds initial support for the clock protocol.

Signed-off-by: Sudeep Holla 
---
 drivers/firmware/arm_scmi/Makefile |   2 +-
 drivers/firmware/arm_scmi/clock.c  | 340 +
 drivers/firmware/arm_scmi/common.h |   1 +
 include/linux/scmi_protocol.h  |  18 ++
 4 files changed, 360 insertions(+), 1 deletion(-)
 create mode 100644 drivers/firmware/arm_scmi/clock.c

diff --git a/drivers/firmware/arm_scmi/Makefile 
b/drivers/firmware/arm_scmi/Makefile
index 159de726ee45..6836b1f38f7f 100644
--- a/drivers/firmware/arm_scmi/Makefile
+++ b/drivers/firmware/arm_scmi/Makefile
@@ -1,2 +1,2 @@
 obj-$(CONFIG_ARM_SCMI_PROTOCOL)= arm_scmi.o
-arm_scmi-y = base.o driver.o perf.o
+arm_scmi-y = base.o clock.o driver.o perf.o
diff --git a/drivers/firmware/arm_scmi/clock.c 
b/drivers/firmware/arm_scmi/clock.c
new file mode 100644
index ..e02827a48ab7
--- /dev/null
+++ b/drivers/firmware/arm_scmi/clock.c
@@ -0,0 +1,340 @@
+/*
+ * System Control and Management Interface (SCMI) Clock Protocol
+ *
+ * Copyright (C) 2017 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see .
+ */
+
+#include "common.h"
+
+enum scmi_clock_protocol_cmd {
+   CLOCK_ATTRIBUTES = 0x3,
+   CLOCK_DESCRIBE_RATES = 0x4,
+   CLOCK_RATE_SET = 0x5,
+   CLOCK_RATE_GET = 0x6,
+   CLOCK_CONFIG_SET = 0x7,
+};
+
+struct scmi_msg_resp_clock_protocol_attributes {
+   __le16 num_clocks;
+   u8 max_async_req;
+   u8 reserved;
+} __packed;
+
+struct scmi_msg_resp_clock_attributes {
+   __le32 attributes;
+#defineCLOCK_ENABLEBIT(0)
+   u8 name[SCMI_MAX_STR_SIZE];
+} __packed;
+
+struct scmi_clock_set_config {
+   __le32 id;
+   __le32 attributes;
+} __packed;
+
+struct scmi_msg_clock_describe_rates {
+   __le32 id;
+   __le32 rate_index;
+} __packed;
+
+struct scmi_msg_resp_clock_describe_rates {
+   __le16 num_returned;
+#define NUM_RETURNED_MASK  (0xfff)
+#define RATE_DISCRETE(x)   ((x) & BIT(12))
+   __le16 num_remaining;
+   struct {
+   __le32 value_low;
+   __le32 value_high;
+   } rate[0];
+#define RATE_TO_U64(X) \
+({ \
+   typeof(X) x = (X);  \
+   le32_to_cpu((x).value_low) | (u64)le32_to_cpu((x).value_high) >> 32; \
+})
+} __packed;
+
+struct scmi_clock_set_rate {
+   __le32 flags;
+#define CLOCK_SET_ASYSCBIT(0)
+#define CLOCK_SET_DELAYED  BIT(1)
+#define CLOCK_ROUND_UP BIT(2)
+#define CLOCK_ROUND_AUTO   BIT(3)
+   __le32 id;
+   __le32 value_low;
+   __le32 value_high;
+} __packed;
+
+struct clock_info {
+   u32 attributes;
+   char name[SCMI_MAX_STR_SIZE];
+   union {
+   int num_rates;
+   u64 rates[MAX_NUM_RATES];
+   struct {
+   u64 min_rate;
+   u64 max_rate;
+   u64 step_size;
+   } range;
+   };
+};
+
+struct scmi_clock_info {
+   int num_clocks;
+   int max_async_req;
+   struct clock_info *clk;
+};
+
+static struct scmi_clock_info clocks;
+
+static int scmi_clock_protocol_attributes_get(struct scmi_handle *handle,
+ struct scmi_clock_info *clocks)
+{
+   int ret;
+   struct scmi_xfer *t;
+   struct scmi_msg_resp_clock_protocol_attributes *attr;
+
+   ret = scmi_one_xfer_init(handle, PROTOCOL_ATTRIBUTES,
+SCMI_PROTOCOL_CLOCK, 0, sizeof(*attr), );
+   if (ret)
+   return ret;
+
+   attr = (struct scmi_msg_resp_clock_protocol_attributes *)t->rx.buf;
+
+   ret = scmi_do_xfer(handle, t);
+   if (!ret) {
+   clocks->num_clocks = le16_to_cpu(attr->num_clocks);
+   clocks->max_async_req = attr->max_async_req;
+   }
+
+   scmi_put_one_xfer(handle, t);
+   return ret;
+}
+
+static int scmi_clock_attributes_get(struct scmi_handle *handle, u32 clk_id,
+