Commit a4207a1c authored by Olof Johansson's avatar Olof Johansson

Merge tag 'scmi-fixes-5.4' of...

Merge tag 'scmi-fixes-5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/sudeep.holla/linux into arm/fixes

ARM SCMI fixes for v5.4

Couple of fixes: one in scmi reset driver initialising missed scmi handle
and an other in scmi reset API implementation fixing the assignment of
reset state

* tag 'scmi-fixes-5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/sudeep.holla/linux:
  reset: reset-scmi: add missing handle initialisation
  firmware: arm_scmi: reset: fix reset_state assignment in scmi_domain_reset

Link: https://lore.kernel.org/r/20190918142139.GA4370@bogusSigned-off-by: default avatarOlof Johansson <olof@lixom.net>
parents b74d957f 61423712
...@@ -73,6 +73,16 @@ Required properties: ...@@ -73,6 +73,16 @@ Required properties:
as used by the firmware. Refer to platform details as used by the firmware. Refer to platform details
for your implementation for the IDs to use. for your implementation for the IDs to use.
Reset signal bindings for the reset domains based on SCMI Message Protocol
------------------------------------------------------------
This binding for the SCMI reset domain providers uses the generic reset
signal binding[5].
Required properties:
- #reset-cells : Should be 1. Contains the reset domain ID value used
by SCMI commands.
SRAM and Shared Memory for SCMI SRAM and Shared Memory for SCMI
------------------------------- -------------------------------
...@@ -93,6 +103,7 @@ Required sub-node properties: ...@@ -93,6 +103,7 @@ Required sub-node properties:
[2] Documentation/devicetree/bindings/power/power_domain.txt [2] Documentation/devicetree/bindings/power/power_domain.txt
[3] Documentation/devicetree/bindings/thermal/thermal.txt [3] Documentation/devicetree/bindings/thermal/thermal.txt
[4] Documentation/devicetree/bindings/sram/sram.txt [4] Documentation/devicetree/bindings/sram/sram.txt
[5] Documentation/devicetree/bindings/reset/reset.txt
Example: Example:
...@@ -152,6 +163,11 @@ firmware { ...@@ -152,6 +163,11 @@ firmware {
reg = <0x15>; reg = <0x15>;
#thermal-sensor-cells = <1>; #thermal-sensor-cells = <1>;
}; };
scmi_reset: protocol@16 {
reg = <0x16>;
#reset-cells = <1>;
};
}; };
}; };
...@@ -166,6 +182,7 @@ hdlcd@7ff60000 { ...@@ -166,6 +182,7 @@ hdlcd@7ff60000 {
reg = <0 0x7ff60000 0 0x1000>; reg = <0 0x7ff60000 0 0x1000>;
clocks = <&scmi_clk 4>; clocks = <&scmi_clk 4>;
power-domains = <&scmi_devpd 1>; power-domains = <&scmi_devpd 1>;
resets = <&scmi_reset 10>;
}; };
thermal-zones { thermal-zones {
......
...@@ -15575,6 +15575,7 @@ F: drivers/clk/clk-sc[mp]i.c ...@@ -15575,6 +15575,7 @@ F: drivers/clk/clk-sc[mp]i.c
F: drivers/cpufreq/sc[mp]i-cpufreq.c F: drivers/cpufreq/sc[mp]i-cpufreq.c
F: drivers/firmware/arm_scpi.c F: drivers/firmware/arm_scpi.c
F: drivers/firmware/arm_scmi/ F: drivers/firmware/arm_scmi/
F: drivers/reset/reset-scmi.c
F: include/linux/sc[mp]i_protocol.h F: include/linux/sc[mp]i_protocol.h
SYSTEM RESET/SHUTDOWN DRIVERS SYSTEM RESET/SHUTDOWN DRIVERS
......
...@@ -69,7 +69,7 @@ static int scmi_clk_set_rate(struct clk_hw *hw, unsigned long rate, ...@@ -69,7 +69,7 @@ static int scmi_clk_set_rate(struct clk_hw *hw, unsigned long rate,
{ {
struct scmi_clk *clk = to_scmi_clk(hw); struct scmi_clk *clk = to_scmi_clk(hw);
return clk->handle->clk_ops->rate_set(clk->handle, clk->id, 0, rate); return clk->handle->clk_ops->rate_set(clk->handle, clk->id, rate);
} }
static int scmi_clk_enable(struct clk_hw *hw) static int scmi_clk_enable(struct clk_hw *hw)
......
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
obj-y = scmi-bus.o scmi-driver.o scmi-protocols.o obj-y = scmi-bus.o scmi-driver.o scmi-protocols.o
scmi-bus-y = bus.o scmi-bus-y = bus.o
scmi-driver-y = driver.o scmi-driver-y = driver.o
scmi-protocols-y = base.o clock.o perf.o power.o sensors.o scmi-protocols-y = base.o clock.o perf.o power.o reset.o sensors.o
obj-$(CONFIG_ARM_SCMI_POWER_DOMAIN) += scmi_pm_domain.o obj-$(CONFIG_ARM_SCMI_POWER_DOMAIN) += scmi_pm_domain.o
...@@ -204,7 +204,7 @@ static int scmi_base_discover_agent_get(const struct scmi_handle *handle, ...@@ -204,7 +204,7 @@ static int scmi_base_discover_agent_get(const struct scmi_handle *handle,
if (ret) if (ret)
return ret; return ret;
*(__le32 *)t->tx.buf = cpu_to_le32(id); put_unaligned_le32(id, t->tx.buf);
ret = scmi_do_xfer(handle, t); ret = scmi_do_xfer(handle, t);
if (!ret) if (!ret)
......
...@@ -56,7 +56,7 @@ struct scmi_msg_resp_clock_describe_rates { ...@@ -56,7 +56,7 @@ struct scmi_msg_resp_clock_describe_rates {
struct scmi_clock_set_rate { struct scmi_clock_set_rate {
__le32 flags; __le32 flags;
#define CLOCK_SET_ASYNC BIT(0) #define CLOCK_SET_ASYNC BIT(0)
#define CLOCK_SET_DELAYED BIT(1) #define CLOCK_SET_IGNORE_RESP BIT(1)
#define CLOCK_SET_ROUND_UP BIT(2) #define CLOCK_SET_ROUND_UP BIT(2)
#define CLOCK_SET_ROUND_AUTO BIT(3) #define CLOCK_SET_ROUND_AUTO BIT(3)
__le32 id; __le32 id;
...@@ -67,6 +67,7 @@ struct scmi_clock_set_rate { ...@@ -67,6 +67,7 @@ struct scmi_clock_set_rate {
struct clock_info { struct clock_info {
int num_clocks; int num_clocks;
int max_async_req; int max_async_req;
atomic_t cur_async_req;
struct scmi_clock_info *clk; struct scmi_clock_info *clk;
}; };
...@@ -106,7 +107,7 @@ static int scmi_clock_attributes_get(const struct scmi_handle *handle, ...@@ -106,7 +107,7 @@ static int scmi_clock_attributes_get(const struct scmi_handle *handle,
if (ret) if (ret)
return ret; return ret;
*(__le32 *)t->tx.buf = cpu_to_le32(clk_id); put_unaligned_le32(clk_id, t->tx.buf);
attr = t->rx.buf; attr = t->rx.buf;
ret = scmi_do_xfer(handle, t); ret = scmi_do_xfer(handle, t);
...@@ -203,40 +204,48 @@ scmi_clock_rate_get(const struct scmi_handle *handle, u32 clk_id, u64 *value) ...@@ -203,40 +204,48 @@ scmi_clock_rate_get(const struct scmi_handle *handle, u32 clk_id, u64 *value)
if (ret) if (ret)
return ret; return ret;
*(__le32 *)t->tx.buf = cpu_to_le32(clk_id); put_unaligned_le32(clk_id, t->tx.buf);
ret = scmi_do_xfer(handle, t); ret = scmi_do_xfer(handle, t);
if (!ret) { if (!ret)
__le32 *pval = t->rx.buf; *value = get_unaligned_le64(t->rx.buf);
*value = le32_to_cpu(*pval);
*value |= (u64)le32_to_cpu(*(pval + 1)) << 32;
}
scmi_xfer_put(handle, t); scmi_xfer_put(handle, t);
return ret; return ret;
} }
static int scmi_clock_rate_set(const struct scmi_handle *handle, u32 clk_id, static int scmi_clock_rate_set(const struct scmi_handle *handle, u32 clk_id,
u32 config, u64 rate) u64 rate)
{ {
int ret; int ret;
u32 flags = 0;
struct scmi_xfer *t; struct scmi_xfer *t;
struct scmi_clock_set_rate *cfg; struct scmi_clock_set_rate *cfg;
struct clock_info *ci = handle->clk_priv;
ret = scmi_xfer_get_init(handle, CLOCK_RATE_SET, SCMI_PROTOCOL_CLOCK, ret = scmi_xfer_get_init(handle, CLOCK_RATE_SET, SCMI_PROTOCOL_CLOCK,
sizeof(*cfg), 0, &t); sizeof(*cfg), 0, &t);
if (ret) if (ret)
return ret; return ret;
if (ci->max_async_req &&
atomic_inc_return(&ci->cur_async_req) < ci->max_async_req)
flags |= CLOCK_SET_ASYNC;
cfg = t->tx.buf; cfg = t->tx.buf;
cfg->flags = cpu_to_le32(config); cfg->flags = cpu_to_le32(flags);
cfg->id = cpu_to_le32(clk_id); cfg->id = cpu_to_le32(clk_id);
cfg->value_low = cpu_to_le32(rate & 0xffffffff); cfg->value_low = cpu_to_le32(rate & 0xffffffff);
cfg->value_high = cpu_to_le32(rate >> 32); cfg->value_high = cpu_to_le32(rate >> 32);
if (flags & CLOCK_SET_ASYNC)
ret = scmi_do_xfer_with_response(handle, t);
else
ret = scmi_do_xfer(handle, t); ret = scmi_do_xfer(handle, t);
if (ci->max_async_req)
atomic_dec(&ci->cur_async_req);
scmi_xfer_put(handle, t); scmi_xfer_put(handle, t);
return ret; return ret;
} }
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include <linux/scmi_protocol.h> #include <linux/scmi_protocol.h>
#include <linux/types.h> #include <linux/types.h>
#include <asm/unaligned.h>
#define PROTOCOL_REV_MINOR_MASK GENMASK(15, 0) #define PROTOCOL_REV_MINOR_MASK GENMASK(15, 0)
#define PROTOCOL_REV_MAJOR_MASK GENMASK(31, 16) #define PROTOCOL_REV_MAJOR_MASK GENMASK(31, 16)
#define PROTOCOL_REV_MAJOR(x) (u16)(FIELD_GET(PROTOCOL_REV_MAJOR_MASK, (x))) #define PROTOCOL_REV_MAJOR(x) (u16)(FIELD_GET(PROTOCOL_REV_MAJOR_MASK, (x)))
...@@ -48,11 +50,11 @@ struct scmi_msg_resp_prot_version { ...@@ -48,11 +50,11 @@ struct scmi_msg_resp_prot_version {
/** /**
* struct scmi_msg_hdr - Message(Tx/Rx) header * struct scmi_msg_hdr - Message(Tx/Rx) header
* *
* @id: The identifier of the command being sent * @id: The identifier of the message being sent
* @protocol_id: The identifier of the protocol used to send @id command * @protocol_id: The identifier of the protocol used to send @id message
* @seq: The token to identify the message. when a message/command returns, * @seq: The token to identify the message. When a message returns, the
* the platform returns the whole message header unmodified including * platform returns the whole message header unmodified including the
* the token * token
* @status: Status of the transfer once it's complete * @status: Status of the transfer once it's complete
* @poll_completion: Indicate if the transfer needs to be polled for * @poll_completion: Indicate if the transfer needs to be polled for
* completion or interrupt mode is used * completion or interrupt mode is used
...@@ -84,17 +86,21 @@ struct scmi_msg { ...@@ -84,17 +86,21 @@ struct scmi_msg {
* @rx: Receive message, the buffer should be pre-allocated to store * @rx: Receive message, the buffer should be pre-allocated to store
* message. If request-ACK protocol is used, we can reuse the same * message. If request-ACK protocol is used, we can reuse the same
* buffer for the rx path as we use for the tx path. * buffer for the rx path as we use for the tx path.
* @done: completion event * @done: command message transmit completion event
* @async: pointer to delayed response message received event completion
*/ */
struct scmi_xfer { struct scmi_xfer {
struct scmi_msg_hdr hdr; struct scmi_msg_hdr hdr;
struct scmi_msg tx; struct scmi_msg tx;
struct scmi_msg rx; struct scmi_msg rx;
struct completion done; struct completion done;
struct completion *async_done;
}; };
void scmi_xfer_put(const struct scmi_handle *h, struct scmi_xfer *xfer); void scmi_xfer_put(const struct scmi_handle *h, struct scmi_xfer *xfer);
int scmi_do_xfer(const struct scmi_handle *h, struct scmi_xfer *xfer); int scmi_do_xfer(const struct scmi_handle *h, struct scmi_xfer *xfer);
int scmi_do_xfer_with_response(const struct scmi_handle *h,
struct scmi_xfer *xfer);
int scmi_xfer_get_init(const struct scmi_handle *h, u8 msg_id, u8 prot_id, int scmi_xfer_get_init(const struct scmi_handle *h, u8 msg_id, u8 prot_id,
size_t tx_size, size_t rx_size, struct scmi_xfer **p); size_t tx_size, size_t rx_size, struct scmi_xfer **p);
int scmi_handle_put(const struct scmi_handle *handle); int scmi_handle_put(const struct scmi_handle *handle);
......
This diff is collapsed.
This diff is collapsed.
...@@ -96,7 +96,7 @@ scmi_power_domain_attributes_get(const struct scmi_handle *handle, u32 domain, ...@@ -96,7 +96,7 @@ scmi_power_domain_attributes_get(const struct scmi_handle *handle, u32 domain,
if (ret) if (ret)
return ret; return ret;
*(__le32 *)t->tx.buf = cpu_to_le32(domain); put_unaligned_le32(domain, t->tx.buf);
attr = t->rx.buf; attr = t->rx.buf;
ret = scmi_do_xfer(handle, t); ret = scmi_do_xfer(handle, t);
...@@ -147,11 +147,11 @@ scmi_power_state_get(const struct scmi_handle *handle, u32 domain, u32 *state) ...@@ -147,11 +147,11 @@ scmi_power_state_get(const struct scmi_handle *handle, u32 domain, u32 *state)
if (ret) if (ret)
return ret; return ret;
*(__le32 *)t->tx.buf = cpu_to_le32(domain); put_unaligned_le32(domain, t->tx.buf);
ret = scmi_do_xfer(handle, t); ret = scmi_do_xfer(handle, t);
if (!ret) if (!ret)
*state = le32_to_cpu(*(__le32 *)t->rx.buf); *state = get_unaligned_le32(t->rx.buf);
scmi_xfer_put(handle, t); scmi_xfer_put(handle, t);
return ret; return ret;
......
// SPDX-License-Identifier: GPL-2.0
/*
* System Control and Management Interface (SCMI) Reset Protocol
*
* Copyright (C) 2019 ARM Ltd.
*/
#include "common.h"
enum scmi_reset_protocol_cmd {
RESET_DOMAIN_ATTRIBUTES = 0x3,
RESET = 0x4,
RESET_NOTIFY = 0x5,
};
enum scmi_reset_protocol_notify {
RESET_ISSUED = 0x0,
};
#define NUM_RESET_DOMAIN_MASK 0xffff
#define RESET_NOTIFY_ENABLE BIT(0)
struct scmi_msg_resp_reset_domain_attributes {
__le32 attributes;
#define SUPPORTS_ASYNC_RESET(x) ((x) & BIT(31))
#define SUPPORTS_NOTIFY_RESET(x) ((x) & BIT(30))
__le32 latency;
u8 name[SCMI_MAX_STR_SIZE];
};
struct scmi_msg_reset_domain_reset {
__le32 domain_id;
__le32 flags;
#define AUTONOMOUS_RESET BIT(0)
#define EXPLICIT_RESET_ASSERT BIT(1)
#define ASYNCHRONOUS_RESET BIT(2)
__le32 reset_state;
#define ARCH_RESET_TYPE BIT(31)
#define COLD_RESET_STATE BIT(0)
#define ARCH_COLD_RESET (ARCH_RESET_TYPE | COLD_RESET_STATE)
};
struct reset_dom_info {
bool async_reset;
bool reset_notify;
u32 latency_us;
char name[SCMI_MAX_STR_SIZE];
};
struct scmi_reset_info {
int num_domains;
struct reset_dom_info *dom_info;
};
static int scmi_reset_attributes_get(const struct scmi_handle *handle,
struct scmi_reset_info *pi)
{
int ret;
struct scmi_xfer *t;
u32 attr;
ret = scmi_xfer_get_init(handle, PROTOCOL_ATTRIBUTES,
SCMI_PROTOCOL_RESET, 0, sizeof(attr), &t);
if (ret)
return ret;
ret = scmi_do_xfer(handle, t);
if (!ret) {
attr = get_unaligned_le32(t->rx.buf);
pi->num_domains = attr & NUM_RESET_DOMAIN_MASK;
}
scmi_xfer_put(handle, t);
return ret;
}
static int
scmi_reset_domain_attributes_get(const struct scmi_handle *handle, u32 domain,
struct reset_dom_info *dom_info)
{
int ret;
struct scmi_xfer *t;
struct scmi_msg_resp_reset_domain_attributes *attr;
ret = scmi_xfer_get_init(handle, RESET_DOMAIN_ATTRIBUTES,
SCMI_PROTOCOL_RESET, sizeof(domain),
sizeof(*attr), &t);
if (ret)
return ret;
put_unaligned_le32(domain, t->tx.buf);
attr = t->rx.buf;
ret = scmi_do_xfer(handle, t);
if (!ret) {
u32 attributes = le32_to_cpu(attr->attributes);
dom_info->async_reset = SUPPORTS_ASYNC_RESET(attributes);
dom_info->reset_notify = SUPPORTS_NOTIFY_RESET(attributes);
dom_info->latency_us = le32_to_cpu(attr->latency);
if (dom_info->latency_us == U32_MAX)
dom_info->latency_us = 0;
strlcpy(dom_info->name, attr->name, SCMI_MAX_STR_SIZE);
}
scmi_xfer_put(handle, t);
return ret;
}
static int scmi_reset_num_domains_get(const struct scmi_handle *handle)
{
struct scmi_reset_info *pi = handle->reset_priv;
return pi->num_domains;
}
static char *scmi_reset_name_get(const struct scmi_handle *handle, u32 domain)
{
struct scmi_reset_info *pi = handle->reset_priv;
struct reset_dom_info *dom = pi->dom_info + domain;
return dom->name;
}
static int scmi_reset_latency_get(const struct scmi_handle *handle, u32 domain)
{
struct scmi_reset_info *pi = handle->reset_priv;
struct reset_dom_info *dom = pi->dom_info + domain;
return dom->latency_us;
}
static int scmi_domain_reset(const struct scmi_handle *handle, u32 domain,
u32 flags, u32 state)
{
int ret;
struct scmi_xfer *t;
struct scmi_msg_reset_domain_reset *dom;
struct scmi_reset_info *pi = handle->reset_priv;
struct reset_dom_info *rdom = pi->dom_info + domain;
if (rdom->async_reset)
flags |= ASYNCHRONOUS_RESET;
ret = scmi_xfer_get_init(handle, RESET, SCMI_PROTOCOL_RESET,
sizeof(*dom), 0, &t);
if (ret)
return ret;
dom = t->tx.buf;
dom->domain_id = cpu_to_le32(domain);
dom->flags = cpu_to_le32(flags);
dom->reset_state = cpu_to_le32(state);
if (rdom->async_reset)
ret = scmi_do_xfer_with_response(handle, t);
else
ret = scmi_do_xfer(handle, t);
scmi_xfer_put(handle, t);
return ret;
}
static int scmi_reset_domain_reset(const struct scmi_handle *handle, u32 domain)
{
return scmi_domain_reset(handle, domain, AUTONOMOUS_RESET,
ARCH_COLD_RESET);
}
static int
scmi_reset_domain_assert(const struct scmi_handle *handle, u32 domain)
{
return scmi_domain_reset(handle, domain, EXPLICIT_RESET_ASSERT,
ARCH_COLD_RESET);
}
static int
scmi_reset_domain_deassert(const struct scmi_handle *handle, u32 domain)
{
return scmi_domain_reset(handle, domain, 0, ARCH_COLD_RESET);
}
static struct scmi_reset_ops reset_ops = {
.num_domains_get = scmi_reset_num_domains_get,
.name_get = scmi_reset_name_get,
.latency_get = scmi_reset_latency_get,
.reset = scmi_reset_domain_reset,
.assert = scmi_reset_domain_assert,
.deassert = scmi_reset_domain_deassert,
};
static int scmi_reset_protocol_init(struct scmi_handle *handle)
{
int domain;
u32 version;
struct scmi_reset_info *pinfo;
scmi_version_get(handle, SCMI_PROTOCOL_RESET, &version);
dev_dbg(handle->dev, "Reset Version %d.%d\n",
PROTOCOL_REV_MAJOR(version), PROTOCOL_REV_MINOR(version));
pinfo = devm_kzalloc(handle->dev, sizeof(*pinfo), GFP_KERNEL);
if (!pinfo)
return -ENOMEM;
scmi_reset_attributes_get(handle, pinfo);
pinfo->dom_info = devm_kcalloc(handle->dev, pinfo->num_domains,
sizeof(*pinfo->dom_info), GFP_KERNEL);
if (!pinfo->dom_info)
return -ENOMEM;
for (domain = 0; domain < pinfo->num_domains; domain++) {
struct reset_dom_info *dom = pinfo->dom_info + domain;
scmi_reset_domain_attributes_get(handle, domain, dom);
}
handle->reset_ops = &reset_ops;
handle->reset_priv = pinfo;
return 0;
}
static int __init scmi_reset_init(void)
{
return scmi_protocol_register(SCMI_PROTOCOL_RESET,
&scmi_reset_protocol_init);
}
subsys_initcall(scmi_reset_init);
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
enum scmi_sensor_protocol_cmd { enum scmi_sensor_protocol_cmd {
SENSOR_DESCRIPTION_GET = 0x3, SENSOR_DESCRIPTION_GET = 0x3,
SENSOR_CONFIG_SET = 0x4, SENSOR_TRIP_POINT_NOTIFY = 0x4,
SENSOR_TRIP_POINT_SET = 0x5, SENSOR_TRIP_POINT_CONFIG = 0x5,
SENSOR_READING_GET = 0x6, SENSOR_READING_GET = 0x6,
}; };
...@@ -42,9 +42,10 @@ struct scmi_msg_resp_sensor_description { ...@@ -42,9 +42,10 @@ struct scmi_msg_resp_sensor_description {
} desc[0]; } desc[0];
}; };
struct scmi_msg_set_sensor_config { struct scmi_msg_sensor_trip_point_notify {
__le32 id; __le32 id;
__le32 event_control; __le32 event_control;
#define SENSOR_TP_NOTIFY_ALL BIT(0)
}; };
struct scmi_msg_set_sensor_trip_point { struct scmi_msg_set_sensor_trip_point {
...@@ -119,7 +120,7 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle, ...@@ -119,7 +120,7 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,
do { do {
/* Set the number of sensors to be skipped/already read */ /* Set the number of sensors to be skipped/already read */
*(__le32 *)t->tx.buf = cpu_to_le32(desc_index); put_unaligned_le32(desc_index, t->tx.buf);
ret = scmi_do_xfer(handle, t); ret = scmi_do_xfer(handle, t);
if (ret) if (ret)
...@@ -135,9 +136,10 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle, ...@@ -135,9 +136,10 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,
} }
for (cnt = 0; cnt < num_returned; cnt++) { for (cnt = 0; cnt < num_returned; cnt++) {
u32 attrh; u32 attrh, attrl;
struct scmi_sensor_info *s; struct scmi_sensor_info *s;
attrl = le32_to_cpu(buf->desc[cnt].attributes_low);
attrh = le32_to_cpu(buf->desc[cnt].attributes_high); attrh = le32_to_cpu(buf->desc[cnt].attributes_high);
s = &si->sensors[desc_index + cnt]; s = &si->sensors[desc_index + cnt];
s->id = le32_to_cpu(buf->desc[cnt].id); s->id = le32_to_cpu(buf->desc[cnt].id);
...@@ -146,6 +148,8 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle, ...@@ -146,6 +148,8 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,
/* Sign extend to a full s8 */ /* Sign extend to a full s8 */
if (s->scale & SENSOR_SCALE_SIGN) if (s->scale & SENSOR_SCALE_SIGN)
s->scale |= SENSOR_SCALE_EXTEND; s->scale |= SENSOR_SCALE_EXTEND;
s->async = SUPPORTS_ASYNC_READ(attrl);
s->num_trip_points = NUM_TRIP_POINTS(attrl);
strlcpy(s->name, buf->desc[cnt].name, SCMI_MAX_STR_SIZE); strlcpy(s->name, buf->desc[cnt].name, SCMI_MAX_STR_SIZE);
} }
...@@ -160,15 +164,15 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle, ...@@ -160,15 +164,15 @@ static int scmi_sensor_description_get(const struct scmi_handle *handle,
return ret; return ret;
} }
static int static int scmi_sensor_trip_point_notify(const struct scmi_handle *handle,
scmi_sensor_configuration_set(const struct scmi_handle *handle, u32 sensor_id) u32 sensor_id, bool enable)
{ {
int ret; int ret;
u32 evt_cntl = BIT(0); u32 evt_cntl = enable ? SENSOR_TP_NOTIFY_ALL : 0;
struct scmi_xfer *t; struct scmi_xfer *t;
struct scmi_msg_set_sensor_config *cfg; struct scmi_msg_sensor_trip_point_notify *cfg;
ret = scmi_xfer_get_init(handle, SENSOR_CONFIG_SET, ret = scmi_xfer_get_init(handle, SENSOR_TRIP_POINT_NOTIFY,
SCMI_PROTOCOL_SENSOR, sizeof(*cfg), 0, &t); SCMI_PROTOCOL_SENSOR, sizeof(*cfg), 0, &t);
if (ret) if (ret)
return ret; return ret;
...@@ -183,15 +187,16 @@ scmi_sensor_configuration_set(const struct scmi_handle *handle, u32 sensor_id) ...@@ -183,15 +187,16 @@ scmi_sensor_configuration_set(const struct scmi_handle *handle, u32 sensor_id)
return ret; return ret;
} }
static int scmi_sensor_trip_point_set(const struct scmi_handle *handle, static int
u32 sensor_id, u8 trip_id, u64 trip_value) scmi_sensor_trip_point_config(const struct scmi_handle *handle, u32 sensor_id,
u8 trip_id, u64 trip_value)
{ {
int ret; int ret;
u32 evt_cntl = SENSOR_TP_BOTH; u32 evt_cntl = SENSOR_TP_BOTH;
struct scmi_xfer *t; struct scmi_xfer *t;
struct scmi_msg_set_sensor_trip_point *trip; struct scmi_msg_set_sensor_trip_point *trip;
ret = scmi_xfer_get_init(handle, SENSOR_TRIP_POINT_SET, ret = scmi_xfer_get_init(handle, SENSOR_TRIP_POINT_CONFIG,
SCMI_PROTOCOL_SENSOR, sizeof(*trip), 0, &t); SCMI_PROTOCOL_SENSOR, sizeof(*trip), 0, &t);
if (ret) if (ret)
return ret; return ret;
...@@ -209,11 +214,13 @@ static int scmi_sensor_trip_point_set(const struct scmi_handle *handle, ...@@ -209,11 +214,13 @@ static int scmi_sensor_trip_point_set(const struct scmi_handle *handle,
} }
static int scmi_sensor_reading_get(const struct scmi_handle *handle, static int scmi_sensor_reading_get(const struct scmi_handle *handle,
u32 sensor_id, bool async, u64 *value) u32 sensor_id, u64 *value)
{ {
int ret; int ret;
struct scmi_xfer *t; struct scmi_xfer *t;
struct scmi_msg_sensor_reading_get *sensor; struct scmi_msg_sensor_reading_get *sensor;
struct sensors_info *si = handle->sensor_priv;
struct scmi_sensor_info *s = si->sensors + sensor_id;
ret = scmi_xfer_get_init(handle, SENSOR_READING_GET, ret = scmi_xfer_get_init(handle, SENSOR_READING_GET,
SCMI_PROTOCOL_SENSOR, sizeof(*sensor), SCMI_PROTOCOL_SENSOR, sizeof(*sensor),
...@@ -223,14 +230,18 @@ static int scmi_sensor_reading_get(const struct scmi_handle *handle, ...@@ -223,14 +230,18 @@ static int scmi_sensor_reading_get(const struct scmi_handle *handle,
sensor = t->tx.buf; sensor = t->tx.buf;
sensor->id = cpu_to_le32(sensor_id); sensor->id = cpu_to_le32(sensor_id);
sensor->flags = cpu_to_le32(async ? SENSOR_READ_ASYNC : 0);
if (s->async) {
sensor->flags = cpu_to_le32(SENSOR_READ_ASYNC);
ret = scmi_do_xfer_with_response(handle, t);
if (!ret)
*value = get_unaligned_le64((void *)
((__le32 *)t->rx.buf + 1));
} else {
sensor->flags = cpu_to_le32(0);
ret = scmi_do_xfer(handle, t); ret = scmi_do_xfer(handle, t);
if (!ret) { if (!ret)
__le32 *pval = t->rx.buf; *value = get_unaligned_le64(t->rx.buf);
*value = le32_to_cpu(*pval);
*value |= (u64)le32_to_cpu(*(pval + 1)) << 32;
} }
scmi_xfer_put(handle, t); scmi_xfer_put(handle, t);
...@@ -255,8 +266,8 @@ static int scmi_sensor_count_get(const struct scmi_handle *handle) ...@@ -255,8 +266,8 @@ static int scmi_sensor_count_get(const struct scmi_handle *handle)
static struct scmi_sensor_ops sensor_ops = { static struct scmi_sensor_ops sensor_ops = {
.count_get = scmi_sensor_count_get, .count_get = scmi_sensor_count_get,
.info_get = scmi_sensor_info_get, .info_get = scmi_sensor_info_get,
.configuration_set = scmi_sensor_configuration_set, .trip_point_notify = scmi_sensor_trip_point_notify,
.trip_point_set = scmi_sensor_trip_point_set, .trip_point_config = scmi_sensor_trip_point_config,
.reading_get = scmi_sensor_reading_get, .reading_get = scmi_sensor_reading_get,
}; };
......
...@@ -72,7 +72,7 @@ static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type, ...@@ -72,7 +72,7 @@ static int scmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
const struct scmi_handle *h = scmi_sensors->handle; const struct scmi_handle *h = scmi_sensors->handle;
sensor = *(scmi_sensors->info[type] + channel); sensor = *(scmi_sensors->info[type] + channel);
ret = h->sensor_ops->reading_get(h, sensor->id, false, &value); ret = h->sensor_ops->reading_get(h, sensor->id, &value);
if (ret) if (ret)
return ret; return ret;
......
...@@ -116,6 +116,17 @@ config RESET_QCOM_PDC ...@@ -116,6 +116,17 @@ config RESET_QCOM_PDC
to control reset signals provided by PDC for Modem, Compute, to control reset signals provided by PDC for Modem, Compute,
Display, GPU, Debug, AOP, Sensors, Audio, SP and APPS. Display, GPU, Debug, AOP, Sensors, Audio, SP and APPS.
config RESET_SCMI
tristate "Reset driver controlled via ARM SCMI interface"
depends on ARM_SCMI_PROTOCOL || COMPILE_TEST
default ARM_SCMI_PROTOCOL
help
This driver provides support for reset signal/domains that are
controlled by firmware that implements the SCMI interface.
This driver uses SCMI Message Protocol to interact with the
firmware controlling all the reset signals.
config RESET_SIMPLE config RESET_SIMPLE
bool "Simple Reset Controller Driver" if COMPILE_TEST bool "Simple Reset Controller Driver" if COMPILE_TEST
default ARCH_STM32 || ARCH_STRATIX10 || ARCH_SUNXI || ARCH_ZX || ARCH_ASPEED || ARCH_BITMAIN default ARCH_STM32 || ARCH_STRATIX10 || ARCH_SUNXI || ARCH_ZX || ARCH_ASPEED || ARCH_BITMAIN
......
...@@ -18,6 +18,7 @@ obj-$(CONFIG_RESET_OXNAS) += reset-oxnas.o ...@@ -18,6 +18,7 @@ obj-$(CONFIG_RESET_OXNAS) += reset-oxnas.o
obj-$(CONFIG_RESET_PISTACHIO) += reset-pistachio.o obj-$(CONFIG_RESET_PISTACHIO) += reset-pistachio.o
obj-$(CONFIG_RESET_QCOM_AOSS) += reset-qcom-aoss.o obj-$(CONFIG_RESET_QCOM_AOSS) += reset-qcom-aoss.o
obj-$(CONFIG_RESET_QCOM_PDC) += reset-qcom-pdc.o obj-$(CONFIG_RESET_QCOM_PDC) += reset-qcom-pdc.o
obj-$(CONFIG_RESET_SCMI) += reset-scmi.o
obj-$(CONFIG_RESET_SIMPLE) += reset-simple.o obj-$(CONFIG_RESET_SIMPLE) += reset-simple.o
obj-$(CONFIG_RESET_STM32MP157) += reset-stm32mp1.o obj-$(CONFIG_RESET_STM32MP157) += reset-stm32mp1.o
obj-$(CONFIG_RESET_SOCFPGA) += reset-socfpga.o obj-$(CONFIG_RESET_SOCFPGA) += reset-socfpga.o
......
// SPDX-License-Identifier: GPL-2.0
/*
* ARM System Control and Management Interface (ARM SCMI) reset driver
*
* Copyright (C) 2019 ARM Ltd.
*/
#include <linux/module.h>
#include <linux/of.h>
#include <linux/device.h>
#include <linux/reset-controller.h>
#include <linux/scmi_protocol.h>
/**
* struct scmi_reset_data - reset controller information structure
* @rcdev: reset controller entity
* @handle: ARM SCMI handle used for communication with system controller
*/
struct scmi_reset_data {
struct reset_controller_dev rcdev;
const struct scmi_handle *handle;
};
#define to_scmi_reset_data(p) container_of((p), struct scmi_reset_data, rcdev)
#define to_scmi_handle(p) (to_scmi_reset_data(p)->handle)
/**
* scmi_reset_assert() - assert device reset
* @rcdev: reset controller entity
* @id: ID of the reset to be asserted
*
* This function implements the reset driver op to assert a device's reset
* using the ARM SCMI protocol.
*
* Return: 0 for successful request, else a corresponding error value
*/
static int
scmi_reset_assert(struct reset_controller_dev *rcdev, unsigned long id)
{
const struct scmi_handle *handle = to_scmi_handle(rcdev);
return handle->reset_ops->assert(handle, id);
}
/**
* scmi_reset_deassert() - deassert device reset
* @rcdev: reset controller entity
* @id: ID of the reset to be deasserted
*
* This function implements the reset driver op to deassert a device's reset
* using the ARM SCMI protocol.
*
* Return: 0 for successful request, else a corresponding error value
*/
static int
scmi_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id)
{
const struct scmi_handle *handle = to_scmi_handle(rcdev);
return handle->reset_ops->deassert(handle, id);
}
/**
* scmi_reset_reset() - reset the device
* @rcdev: reset controller entity
* @id: ID of the reset signal to be reset(assert + deassert)
*
* This function implements the reset driver op to trigger a device's
* reset signal using the ARM SCMI protocol.
*
* Return: 0 for successful request, else a corresponding error value
*/
static int
scmi_reset_reset(struct reset_controller_dev *rcdev, unsigned long id)
{
const struct scmi_handle *handle = to_scmi_handle(rcdev);
return handle->reset_ops->reset(handle, id);
}
static const struct reset_control_ops scmi_reset_ops = {
.assert = scmi_reset_assert,
.deassert = scmi_reset_deassert,
.reset = scmi_reset_reset,
};
static int scmi_reset_probe(struct scmi_device *sdev)
{
struct scmi_reset_data *data;
struct device *dev = &sdev->dev;
struct device_node *np = dev->of_node;
const struct scmi_handle *handle = sdev->handle;
if (!handle || !handle->reset_ops)
return -ENODEV;
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;
data->rcdev.ops = &scmi_reset_ops;
data->rcdev.owner = THIS_MODULE;
data->rcdev.of_node = np;
data->rcdev.nr_resets = handle->reset_ops->num_domains_get(handle);
data->handle = handle;
return devm_reset_controller_register(dev, &data->rcdev);
}
static const struct scmi_device_id scmi_id_table[] = {
{ SCMI_PROTOCOL_RESET },
{ },
};
MODULE_DEVICE_TABLE(scmi, scmi_id_table);
static struct scmi_driver scmi_reset_driver = {
.name = "scmi-reset",
.probe = scmi_reset_probe,
.id_table = scmi_id_table,
};
module_scmi_driver(scmi_reset_driver);
MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>");
MODULE_DESCRIPTION("ARM SCMI reset controller driver");
MODULE_LICENSE("GPL v2");
// SPDX-License-Identifier: GPL-2.0 /* SPDX-License-Identifier: GPL-2.0-only */
/* /*
* SCMI Message Protocol driver header * SCMI Message Protocol driver header
* *
...@@ -71,7 +71,7 @@ struct scmi_clk_ops { ...@@ -71,7 +71,7 @@ struct scmi_clk_ops {
int (*rate_get)(const struct scmi_handle *handle, u32 clk_id, int (*rate_get)(const struct scmi_handle *handle, u32 clk_id,
u64 *rate); u64 *rate);
int (*rate_set)(const struct scmi_handle *handle, u32 clk_id, int (*rate_set)(const struct scmi_handle *handle, u32 clk_id,
u32 config, u64 rate); u64 rate);
int (*enable)(const struct scmi_handle *handle, u32 clk_id); int (*enable)(const struct scmi_handle *handle, u32 clk_id);
int (*disable)(const struct scmi_handle *handle, u32 clk_id); int (*disable)(const struct scmi_handle *handle, u32 clk_id);
}; };
...@@ -145,6 +145,8 @@ struct scmi_sensor_info { ...@@ -145,6 +145,8 @@ struct scmi_sensor_info {
u32 id; u32 id;
u8 type; u8 type;
s8 scale; s8 scale;
u8 num_trip_points;
bool async;
char name[SCMI_MAX_STR_SIZE]; char name[SCMI_MAX_STR_SIZE];
}; };
...@@ -167,9 +169,9 @@ enum scmi_sensor_class { ...@@ -167,9 +169,9 @@ enum scmi_sensor_class {
* *
* @count_get: get the count of sensors provided by SCMI * @count_get: get the count of sensors provided by SCMI
* @info_get: get the information of the specified sensor * @info_get: get the information of the specified sensor
* @configuration_set: control notifications on cross-over events for * @trip_point_notify: control notifications on cross-over events for
* the trip-points * the trip-points
* @trip_point_set: selects and configures a trip-point of interest * @trip_point_config: selects and configures a trip-point of interest
* @reading_get: gets the current value of the sensor * @reading_get: gets the current value of the sensor
*/ */
struct scmi_sensor_ops { struct scmi_sensor_ops {
...@@ -177,12 +179,32 @@ struct scmi_sensor_ops { ...@@ -177,12 +179,32 @@ struct scmi_sensor_ops {
const struct scmi_sensor_info *(*info_get) const struct scmi_sensor_info *(*info_get)
(const struct scmi_handle *handle, u32 sensor_id); (const struct scmi_handle *handle, u32 sensor_id);
int (*configuration_set)(const struct scmi_handle *handle, int (*trip_point_notify)(const struct scmi_handle *handle,
u32 sensor_id); u32 sensor_id, bool enable);
int (*trip_point_set)(const struct scmi_handle *handle, u32 sensor_id, int (*trip_point_config)(const struct scmi_handle *handle,
u8 trip_id, u64 trip_value); u32 sensor_id, u8 trip_id, u64 trip_value);
int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id, int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id,
bool async, u64 *value); u64 *value);
};
/**
* struct scmi_reset_ops - represents the various operations provided
* by SCMI Reset Protocol
*
* @num_domains_get: get the count of reset domains provided by SCMI
* @name_get: gets the name of a reset domain
* @latency_get: gets the reset latency for the specified reset domain
* @reset: resets the specified reset domain
* @assert: explicitly assert reset signal of the specified reset domain
* @deassert: explicitly deassert reset signal of the specified reset domain
*/
struct scmi_reset_ops {
int (*num_domains_get)(const struct scmi_handle *handle);
char *(*name_get)(const struct scmi_handle *handle, u32 domain);
int (*latency_get)(const struct scmi_handle *handle, u32 domain);
int (*reset)(const struct scmi_handle *handle, u32 domain);
int (*assert)(const struct scmi_handle *handle, u32 domain);
int (*deassert)(const struct scmi_handle *handle, u32 domain);
}; };
/** /**
...@@ -194,6 +216,7 @@ struct scmi_sensor_ops { ...@@ -194,6 +216,7 @@ struct scmi_sensor_ops {
* @perf_ops: pointer to set of performance protocol operations * @perf_ops: pointer to set of performance protocol operations
* @clk_ops: pointer to set of clock protocol operations * @clk_ops: pointer to set of clock protocol operations
* @sensor_ops: pointer to set of sensor protocol operations * @sensor_ops: pointer to set of sensor protocol operations
* @reset_ops: pointer to set of reset protocol operations
* @perf_priv: pointer to private data structure specific to performance * @perf_priv: pointer to private data structure specific to performance
* protocol(for internal use only) * protocol(for internal use only)
* @clk_priv: pointer to private data structure specific to clock * @clk_priv: pointer to private data structure specific to clock
...@@ -202,6 +225,8 @@ struct scmi_sensor_ops { ...@@ -202,6 +225,8 @@ struct scmi_sensor_ops {
* protocol(for internal use only) * protocol(for internal use only)
* @sensor_priv: pointer to private data structure specific to sensors * @sensor_priv: pointer to private data structure specific to sensors
* protocol(for internal use only) * protocol(for internal use only)
* @reset_priv: pointer to private data structure specific to reset
* protocol(for internal use only)
*/ */
struct scmi_handle { struct scmi_handle {
struct device *dev; struct device *dev;
...@@ -210,11 +235,13 @@ struct scmi_handle { ...@@ -210,11 +235,13 @@ struct scmi_handle {
struct scmi_clk_ops *clk_ops; struct scmi_clk_ops *clk_ops;
struct scmi_power_ops *power_ops; struct scmi_power_ops *power_ops;
struct scmi_sensor_ops *sensor_ops; struct scmi_sensor_ops *sensor_ops;
struct scmi_reset_ops *reset_ops;
/* for protocol internal use */ /* for protocol internal use */
void *perf_priv; void *perf_priv;
void *clk_priv; void *clk_priv;
void *power_priv; void *power_priv;
void *sensor_priv; void *sensor_priv;
void *reset_priv;
}; };
enum scmi_std_protocol { enum scmi_std_protocol {
...@@ -224,6 +251,7 @@ enum scmi_std_protocol { ...@@ -224,6 +251,7 @@ enum scmi_std_protocol {
SCMI_PROTOCOL_PERF = 0x13, SCMI_PROTOCOL_PERF = 0x13,
SCMI_PROTOCOL_CLOCK = 0x14, SCMI_PROTOCOL_CLOCK = 0x14,
SCMI_PROTOCOL_SENSOR = 0x15, SCMI_PROTOCOL_SENSOR = 0x15,
SCMI_PROTOCOL_RESET = 0x16,
}; };
struct scmi_device { struct scmi_device {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment