firmware: Add support for TI System Control Interface (TI-SCI) protocol driver
Subsystems (2)
Nishanth Menon
maintainerv3 cover firmware: Add support for TI System Control Interface (TI-SCI) protocol driver
Hi,
Version 3 of the series with change in the way we describe the children nodes (no change to drivers required - only the dts description changes).
Texas Instruments' Keystone generation System on Chips (SoC) starting with 66AK2G02[1], now include a dedicated SoC System Control entity called PMMC(Power Management Micro Controller) in line with ARM architecture recommendations. The function of this module is to integrate all system operations in a centralized location. Communication with the SoC System Control entity from various processing units like ARM/DSP occurs over Message Manager hardware block.
This series adds the base support for TI System Control Interface (TI-SCI) protocol[2]. The protocol is built on top of Texas Instrument's Message Manager communication mechanism[3].
Overall architecture is very similar to SCPI[4] as follows:
+-------------+ +---------+ +------^-----+
| TI SCI GENPD| |TISCI Clk| |TISCI reset |
+------+------+ +----+----+ +------+-----+
| | |
| +----v--------------+ |
+----------> TISCI Protocol(*) <--+
+----+--------------+
|
+---v-----------+
| MAILBOX FWK |
+---+-----------+
|
+---v-----------+
| TI MSGMGR |-> TISCI hardware block
+---------------+(*) This series.
V3 of the series is based off v4.8-rc1 and is also available here:
https://github.com/nmenon/linux-2.6-playground/commits/upstream/v4.9/tisci-base-v3
integration of v3 along with https://lkml.org/lkml/2016/8/19/790 and
https://lkml.org/lkml/2016/8/19/811 is available here:
https://github.com/nmenon/linux-2.6-playground/commits/upstream/v4.9/tisci-integ-v3
Test of complete integrated solution: http://pastebin.ubuntu.com/23142652/
Changes since v2:
- Child nodes are now children of the TISCI node
- related driver updates
V2: https://lkml.org/lkml/2016/8/30/273
V1: https://lkml.org/lkml/2016/8/19/768
Nishanth Menon (5):
Documentation: Add support for TI System Control Interface (TI-SCI)
protocol
firmware: Add basic support for TI System Control Interface (TI-SCI)
protocol
firmware: ti_sci: Add support for Device control
firmware: ti_sci: Add support for Clock control
firmware: ti_sci: Add support for reboot core service
.../devicetree/bindings/arm/keystone/ti,sci.txt | 81 + MAINTAINERS | 10 + drivers/firmware/Kconfig | 15 + drivers/firmware/Makefile | 1 + drivers/firmware/ti_sci.c | 1993 ++++++++++++++++++++ drivers/firmware/ti_sci.h | 492 +++++ include/linux/soc/ti/ti_sci_protocol.h | 249 +++ 7 files changed, 2841 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/keystone/ti,sci.txt create mode 100644 drivers/firmware/ti_sci.c create mode 100644 drivers/firmware/ti_sci.h create mode 100644 include/linux/soc/ti/ti_sci_protocol.h
Signature · 1 line
2.10.0
Nishanth Menon
maintainerPATCH v3 1/5 Documentation: Add support for TI System Control Interface (TI-SCI) protocol
Texas Instrument's System Control Interface (TI-SCI) Message Protocol is used in Texas Instrument's System on Chip (SoC) such as those in newer SoCs in the keystone processor family starting with K2G.
This message protocol is used to communicate between various compute or processing entities (such as ARM, DSP etc.) with a central system controller entity.
TI-SCI message protocol provides support for management of various hardware entities within the SoC.
The message protocol can be found here:
http://processors.wiki.ti.com/index.php/TISCI
---
Changes in V3:
- All dependent nodes like PD/Clk are children of TISCI node
- minor formatting updates
V2: https://patchwork.kernel.org/patch/9305413/
V1: https://patchwork.kernel.org/patch/9291343/
.../devicetree/bindings/arm/keystone/ti,sci.txt | 81 ++++++++++++++++++++++ MAINTAINERS | 8 +++ 2 files changed, 89 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/keystone/ti,sci.txt
Documentation/devicetree/bindings/arm/keystone/ti,sci.txt new file +81 -0
@@ -0,0 +1,81 @@ +Texas Instruments System Control Interface (TI-SCI) Message Protocol +-------------------------------------------------------------------- + +Texas Instrument's processors including those belonging to Keystone generation +of processors have separate hardware entity which is now responsible for the +management of the System on Chip (SoC) system. These include various system +level functions as well. + +An example of such an SoC is K2G, which contains the system control hardware +block called Power Management Micro Controller (PMMC). This hardware block is +initialized early into boot process and provides services to Operating Systems +on multiple processors including ones running Linux. + +See http://processors.wiki.ti.com/index.php/TISCI for protocol definition. + +TI-SCI controller Device Node: +============================= + +The TI-SCI node describes the Texas Instrument's System Controller entity node. +This parent node may optionally have additional children nodes which describe +specific functionality such as clocks, power domain, reset or additional +functionality as may be required for the SoC. This hierarchy also describes the +relationship between the TI-SCI parent node to the child node. + +Required properties: +------------------- +- compatible: should be "ti,k2g-sci" +- mbox-names: + "rx" - Mailbox corresponding to receive path + "tx" - Mailbox corresponding to transmit path + +- mboxes: Mailboxes corresponding to the mbox-names. Each value of the mboxes + property should contain a phandle to the mailbox controller device + node and an args specifier that will be the phandle to the intended + sub-mailbox child node to be used for communication. + +See Documentation/devicetree/bindings/mailbox/mailbox.txt for more details +about the generic mailbox controller and client driver bindings. Also see +Documentation/devicetree/bindings/mailbox/ti,message-manager.txt for typical +controller that is used to communicate with this System controllers. + +Optional Properties: +------------------- +- reg-names: + debug_messages - Map the Debug message region +- reg: register space corresponding to the debug_messages +- ti,system-reboot-controller: If system reboot can be triggered by SoC reboot + +Example (K2G): +------------- + pmmc: pmmc { + compatible = "ti,k2g-sci"; + mbox-names = "rx", "tx"; + mboxes= <&msgmgr &msgmgr_proxy_pmmc_rx>, + <&msgmgr &msgmgr_proxy_pmmc_tx>; + reg-names = "debug_messages"; + reg = <0x02921800 0x800>; + }; + + +TI-SCI Client Device Node: +========================= + +Client nodes are maintained as children of the relevant TI-SCI device node. + +Example (K2G): +------------- + pmmc: pmmc { + compatible = "ti,k2g-sci"; + ... + + my_clk_node: clk_node { + ... + ... + }; + + my_pd_node: pd_node { + ... + ... + }; + };
MAINTAINERS +8 -0
@@ -11564,6 +11564,14 @@ S: Maintained F: arch/xtensa/ F: drivers/irqchip/irq-xtensa-* +Texas Instruments' System Control Interface (TISCI) Protocol Driver +M: Nishanth Menon <[email protected]> +M: Tero Kristo <[email protected]> +M: Santosh Shilimkar <[email protected]> +L: linux-arm-kernel at lists.infradead.org +S: Maintained +F: Documentation/devicetree/bindings/arm/keystone/ti,sci.txt + THANKO'S RAREMONO AM/FM/SW RADIO RECEIVER USB DRIVER M: Hans Verkuil <[email protected]> L: linux-media at vger.kernel.org
Signature · 1 line
2.10.0
Re: [PATCH V3 1/5] Documentation: Add support for TI System Control Interface (TI-SCI) protocol
Quoted 20 lines · Nishanth Menon
Texas Instrument's System Control Interface (TI-SCI) Message Protocol is used in Texas Instrument's System on Chip (SoC) such as those in newer SoCs in the keystone processor family starting with K2G.
This message protocol is used to communicate between various compute or processing entities (such as ARM, DSP etc.) with a central system controller entity.
TI-SCI message protocol provides support for management of various hardware entities within the SoC.
The message protocol can be found here:
http://processors.wiki.ti.com/index.php/TISCISigned-off-by Nishanth Menon <[email protected]>---
Changes in V3:
- All dependent nodes like PD/Clk are children of TISCI node
- minor formatting updates
Quoted 7 lines
V2: https://patchwork.kernel.org/patch/9305413/
V1: https://patchwork.kernel.org/patch/9291343/.../devicetree/bindings/arm/keystone/ti,sci.txt | 81 ++++++++++++++++++++++ MAINTAINERS | 8 +++ 2 files changed, 89 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/keystone/ti,sci.txt
Nishanth Menon
maintainerPATCH v3 2/5 firmware: Add basic support for TI System Control Interface (TI-SCI) protocol
In reply to Nishanth MenonTexas Instrument's System Control Interface (TI-SCI) Message Protocol is used in Texas Instrument's System on Chip (SoC) such as those in keystone family K2G SoC to communicate between various compute processors with a central system controller entity.
TI-SCI message protocol provides support for management of various hardware entities within the SoC. Add support driver to allow communication with system controller entity within the SoC using the mailbox client.
We introduce the basic registration and query capability for the driver protocol as part of this change. Subsequent patches add in functionality specific to the TI-SCI features.
---
Changes in v3:
- Handle the change in bindings - populate and de-populate children
- Get handle without needing phandle linkage by using the parent device
V2: https://patchwork.kernel.org/patch/9305419/
V1: https://patchwork.kernel.org/patch/9291349/
MAINTAINERS | 2 + drivers/firmware/Kconfig | 15 + drivers/firmware/Makefile | 1 + drivers/firmware/ti_sci.c | 790 +++++++++++++++++++++++++++++++++ drivers/firmware/ti_sci.h | 93 ++++ include/linux/soc/ti/ti_sci_protocol.h | 69 +++ 6 files changed, 970 insertions(+) create mode 100644 drivers/firmware/ti_sci.c create mode 100644 drivers/firmware/ti_sci.h create mode 100644 include/linux/soc/ti/ti_sci_protocol.h
MAINTAINERS +2 -0
@@ -11571,6 +11571,8 @@ M: Santosh Shilimkar <[email protected]> L: linux-arm-kernel at lists.infradead.org S: Maintained F: Documentation/devicetree/bindings/arm/keystone/ti,sci.txt +F: drivers/firmware/ti_sci* +F: include/linux/soc/ti/ti_sci_protocol.h THANKO'S RAREMONO AM/FM/SW RADIO RECEIVER USB DRIVER M: Hans Verkuil <[email protected]>
drivers/firmware/Kconfig +15 -0
@@ -203,6 +203,21 @@ config QCOM_SCM_64 def_bool y depends on QCOM_SCM && ARM64 +config TI_SCI_PROTOCOL + tristate "TI System Control Interface (TISCI) Message Protocol" + depends on TI_MESSAGE_MANAGER + help + TI System Control Interface (TISCI) Message Protocol is used to manage + compute systems such as ARM, DSP etc with the system controller in + complex System on Chip(SoC) such as those found on certain keystone + generation SoC from TI. + + System controller provides various facilities including power + management function support. + + This protocol library is used by client drivers to use the features + provided by the system controller. + config HAVE_ARM_SMCCC bool
drivers/firmware/Makefile +1 -0
@@ -20,6 +20,7 @@ obj-$(CONFIG_QCOM_SCM) += qcom_scm.o obj-$(CONFIG_QCOM_SCM_64) += qcom_scm-64.o obj-$(CONFIG_QCOM_SCM_32) += qcom_scm-32.o CFLAGS_qcom_scm-32.o :=$(call as-instr,.arch armv7-a\n.arch_extension sec,-DREQUIRES_SEC=1) -march=armv7-a +obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.o obj-y += broadcom/ obj-$(CONFIG_GOOGLE_FIRMWARE) += google/
drivers/firmware/ti_sci.c new file +790 -0
790 lines not on this page · raw message
drivers/firmware/ti_sci.h new file +93 -0
93 lines not on this page · raw message
include/linux/soc/ti/ti_sci_protocol.h new file +69 -0
69 lines not on this page · raw message
Signature · 1 line
2.10.0
Nishanth Menon
maintainerPATCH v3 3/5 firmware: ti_sci: Add support for Device control
In reply to Nishanth MenonTexas Instrument's System Control Interface (TI-SCI) Message Protocol is used in Texas Instrument's System on Chip (SoC) such as those in keystone family K2G SoC to communicate between various compute processors with a central system controller entity.
TI-SCI message protocol provides support for management of various hardware entitites within the SoC. Add support driver to allow communication with system controller entity within the SoC using the mailbox client.
We introduce the fundamental device management capability support to the driver protocol as part of this change.
---
Changes in V3: Just rebase
V2: https://patchwork.kernel.org/patch/9305427/
V1: https://patchwork.kernel.org/patch/9291345/
drivers/firmware/ti_sci.c | 433 +++++++++++++++++++++++++++++++++ drivers/firmware/ti_sci.h | 98 ++++++++ include/linux/soc/ti/ti_sci_protocol.h | 91 +++++++ 3 files changed, 622 insertions(+)
drivers/firmware/ti_sci.c +433 -0
@@ -495,6 +495,437 @@ fail: }/** +* ti_sci_is_response_ack() - Generic ACK/NACK message checkup +* @r: pointer to response buffer +* +* Return: true if the response was an ACK, else returns false. +*/ +static inline bool ti_sci_is_response_ack (void *r) +{ +struct ti_sci_msg_hdr *hdr = r; + +return hdr->flags &TI_SCI_FLAG_RESP_GENERIC_ACK ? true : false; +} + +/** +* ti_sci_set_device_state() - Set device state helper +* @handle: pointer to TI SCI handle +* @id: Device identifier +* @flags: flags to setup for the device +* @state: State to move the device to +* +* Return: 0 if all went well, else returns appropriate error value. +*/ +static int ti_sci_set_device_state (const struct ti_sci_handle *handle, +u32 id,u32 flags,u8 state) +{ +struct ti_sci_info *info; +struct ti_sci_msg_req_set_device_state *req; +struct ti_sci_msg_hdr *resp; +struct ti_sci_xfer *xfer; +struct device *dev; +int ret =0 ; + +if (IS_ERR (handle)) +return PTR_ERR (handle); +if (!handle) +return -EINVAL ; + + info =handle_to_ti_sci_info (handle); + dev = info->dev; + + xfer =ti_sci_get_one_xfer (info,TI_SCI_MSG_SET_DEVICE_STATE , + flags |TI_SCI_FLAG_REQ_ACK_ON_PROCESSED , +sizeof (*req),sizeof (*resp)); +if (IS_ERR (xfer)) { + ret =PTR_ERR (xfer); +dev_err (dev,"Message alloc failed(%d)\n" , ret); +return ret; + } + req = (struct ti_sci_msg_req_set_device_state *)xfer->xfer_buf; + req->id = id; + req->state = state; + + ret =ti_sci_do_xfer (info, xfer); +if (ret) { +dev_err (dev,"Mbox send fail %d\n" , ret); + goto fail; + } + + resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; + + ret =ti_sci_is_response_ack (resp) ?0 : -ENODEV ; + +fail: +ti_sci_put_one_xfer (&info->minfo, xfer); + +return ret; +} + +/** +* ti_sci_get_device_state() - Get device state helper +* @handle: Handle to the device +* @id: Device Identifier +* @clcnt: Pointer to Context Loss Count +* @resets: pointer to resets +* @p_state: pointer to p_state +* @c_state: pointer to c_state +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_get_device_state (const struct ti_sci_handle *handle, +u32 id,u32 *clcnt,u32 *resets, +u8 *p_state,u8 *c_state) +{ +struct ti_sci_info *info; +struct ti_sci_msg_req_get_device_state *req; +struct ti_sci_msg_resp_get_device_state *resp; +struct ti_sci_xfer *xfer; +struct device *dev; +int ret =0 ; + +if (IS_ERR (handle)) +return PTR_ERR (handle); +if (!handle) +return -EINVAL ; + +if (!clcnt && !resets && !p_state && !c_state) +return -EINVAL ; + + info =handle_to_ti_sci_info (handle); + dev = info->dev; + +/* Response is expected, so need of any flags */ + xfer =ti_sci_get_one_xfer (info,TI_SCI_MSG_GET_DEVICE_STATE , +0 ,sizeof (*req),sizeof (*resp)); +if (IS_ERR (xfer)) { + ret =PTR_ERR (xfer); +dev_err (dev,"Message alloc failed(%d)\n" , ret); +return ret; + } + req = (struct ti_sci_msg_req_get_device_state *)xfer->xfer_buf; + req->id = id; + + ret =ti_sci_do_xfer (info, xfer); +if (ret) { +dev_err (dev,"Mbox send fail %d\n" , ret); + goto fail; + } + + resp = (struct ti_sci_msg_resp_get_device_state *)xfer->xfer_buf; +if (!ti_sci_is_response_ack (resp)) { + ret = -ENODEV ; + goto fail; + } + +if (clcnt) + *clcnt = resp->context_loss_count; +if (resets) + *resets = resp->resets; +if (p_state) + *p_state = resp->programmed_state; +if (c_state) + *c_state = resp->current_state; +fail: +ti_sci_put_one_xfer (&info->minfo, xfer); + +return ret; +} + +/** +* ti_sci_cmd_get_device() - command to request for device managed by TISCI +* @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle +* @id: Device Identifier +* +* Request for the device - NOTE: the client MUST maintain integrity of +* usage count by balancing get_device with put_device. No refcounting is +* managed by driver for that purpose. +* +* NOTE: The request is for exclusive access for the processor. +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_get_device (const struct ti_sci_handle *handle,u32 id) +{ +return ti_sci_set_device_state (handle, id, +MSG_FLAG_DEVICE_EXCLUSIVE , +MSG_DEVICE_SW_STATE_ON ); +} + +/** +* ti_sci_cmd_idle_device() - Command to idle a device managed by TISCI +* @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle +* @id: Device Identifier +* +* Request for the device - NOTE: the client MUST maintain integrity of +* usage count by balancing get_device with put_device. No refcounting is +* managed by driver for that purpose. +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_idle_device (const struct ti_sci_handle *handle,u32 id) +{ +return ti_sci_set_device_state (handle, id, +MSG_FLAG_DEVICE_EXCLUSIVE , +MSG_DEVICE_SW_STATE_RETENTION ); +} + +/** +* ti_sci_cmd_put_device() - command to release a device managed by TISCI +* @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle +* @id: Device Identifier +* +* Request for the device - NOTE: the client MUST maintain integrity of +* usage count by balancing get_device with put_device. No refcounting is +* managed by driver for that purpose. +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_put_device (const struct ti_sci_handle *handle,u32 id) +{ +return ti_sci_set_device_state (handle, id, +0 ,MSG_DEVICE_SW_STATE_AUTO_OFF ); +} + +/** +* ti_sci_cmd_dev_is_valid() - Is the device valid +* @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle +* @id: Device Identifier +* +* Return: 0 if all went fine and the device ID is valid, else return +* appropriate error. +*/ +static int ti_sci_cmd_dev_is_valid (const struct ti_sci_handle *handle,u32 id) +{ +u8 unused; + +/* check the device state which will also tell us if the ID is valid */ +return ti_sci_get_device_state (handle, id,NULL ,NULL ,NULL , &unused); +} + +/** +* ti_sci_cmd_dev_get_clcnt() - Get context loss counter +* @handle: Pointer to TISCI handle +* @id: Device Identifier +* @count: Pointer to Context Loss counter to populate +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_dev_get_clcnt (const struct ti_sci_handle *handle,u32 id, +u32 *count) +{ +return ti_sci_get_device_state (handle, id, count,NULL ,NULL ,NULL ); +} + +/** +* ti_sci_cmd_dev_is_idle() - Check if the device is requested to be idle +* @handle: Pointer to TISCI handle +* @id: Device Identifier +* @r_state: true if requested to be idle +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_dev_is_idle (const struct ti_sci_handle *handle,u32 id, +bool *r_state) +{ +int ret; +u8 state; + +if (!r_state) +return -EINVAL ; + + ret =ti_sci_get_device_state (handle, id,NULL ,NULL , &state,NULL ); +if (ret) +return ret; + + *r_state = (state ==MSG_DEVICE_SW_STATE_RETENTION ); + +return 0 ; +} + +/** +* ti_sci_cmd_dev_is_stop() - Check if the device is requested to be stopped +* @handle: Pointer to TISCI handle +* @id: Device Identifier +* @r_state: true if requested to be stopped +* @curr_state: true if currently stopped. +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_dev_is_stop (const struct ti_sci_handle *handle,u32 id, +bool *r_state,bool *curr_state) +{ +int ret; +u8 p_state, c_state; + +if (!r_state && !curr_state) +return -EINVAL ; + + ret = +ti_sci_get_device_state (handle, id,NULL ,NULL , &p_state, &c_state); +if (ret) +return ret; + +if (r_state) + *r_state = (p_state ==MSG_DEVICE_SW_STATE_AUTO_OFF ); +if (curr_state) + *curr_state = (c_state ==MSG_DEVICE_HW_STATE_OFF ); + +return 0 ; +} + +/** +* ti_sci_cmd_dev_is_on() - Check if the device is requested to be ON +* @handle: Pointer to TISCI handle +* @id: Device Identifier +* @r_state: true if requested to be ON +* @curr_state: true if currently ON and active +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_dev_is_on (const struct ti_sci_handle *handle,u32 id, +bool *r_state,bool *curr_state) +{ +int ret; +u8 p_state, c_state; + +if (!r_state && !curr_state) +return -EINVAL ; + + ret = +ti_sci_get_device_state (handle, id,NULL ,NULL , &p_state, &c_state); +if (ret) +return ret; + +if (r_state) + *r_state = (p_state ==MSG_DEVICE_SW_STATE_ON ); +if (curr_state) + *curr_state = (c_state ==MSG_DEVICE_HW_STATE_ON ); + +return 0 ; +} + +/** +* ti_sci_cmd_dev_is_trans() - Check if the device is currently transitioning +* @handle: Pointer to TISCI handle +* @id: Device Identifier +* @curr_state: true if currently transitioning. +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_dev_is_trans (const struct ti_sci_handle *handle,u32 id, +bool *curr_state) +{ +int ret; +u8 state; + +if (!curr_state) +return -EINVAL ; + + ret =ti_sci_get_device_state (handle, id,NULL ,NULL ,NULL , &state); +if (ret) +return ret; + + *curr_state = (state ==MSG_DEVICE_HW_STATE_TRANS ); + +return 0 ; +} + +/** +* ti_sci_cmd_set_device_resets() - command to set resets for device managed +* by TISCI +* @handle: Pointer to TISCI handle as retrieved by *ti_sci_get_handle +* @id: Device Identifier +* @reset_state: Device specific reset bit field +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_set_device_resets (const struct ti_sci_handle *handle, +u32 id,u32 reset_state) +{ +struct ti_sci_info *info; +struct ti_sci_msg_req_set_device_resets *req; +struct ti_sci_msg_hdr *resp; +struct ti_sci_xfer *xfer; +struct device *dev; +int ret =0 ; + +if (IS_ERR (handle)) +return PTR_ERR (handle); +if (!handle) +return -EINVAL ; + + info =handle_to_ti_sci_info (handle); + dev = info->dev; + + xfer =ti_sci_get_one_xfer (info,TI_SCI_MSG_SET_DEVICE_RESETS , +TI_SCI_FLAG_REQ_ACK_ON_PROCESSED , +sizeof (*req),sizeof (*resp)); +if (IS_ERR (xfer)) { + ret =PTR_ERR (xfer); +dev_err (dev,"Message alloc failed(%d)\n" , ret); +return ret; + } + req = (struct ti_sci_msg_req_set_device_resets *)xfer->xfer_buf; + req->id = id; + req->resets = reset_state; + + ret =ti_sci_do_xfer (info, xfer); +if (ret) { +dev_err (dev,"Mbox send fail %d\n" , ret); + goto fail; + } + + resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; + + ret =ti_sci_is_response_ack (resp) ?0 : -ENODEV ; + +fail: +ti_sci_put_one_xfer (&info->minfo, xfer); + +return ret; +} + +/** +* ti_sci_cmd_get_device_resets() - Get reset state for device managed +* by TISCI +* @handle: Pointer to TISCI handle +* @id: Device Identifier +* @reset_state: Pointer to reset state to populate +* +* Return: 0 if all went fine, else return appropriate error. +*/ +static int ti_sci_cmd_get_device_resets (const struct ti_sci_handle *handle, +u32 id,u32 *reset_state) +{ +return ti_sci_get_device_state (handle, id,NULL , reset_state,NULL , +NULL ); +} + +/* +* ti_sci_setup_ops() - Setup the operations structures +* @info: pointer to TISCI pointer +*/ +static void ti_sci_setup_ops (struct ti_sci_info *info) +{ +struct ti_sci_ops *ops = &info->handle.ops; +struct ti_sci_dev_ops *dops = &ops->dev_ops; + + dops->get_device = ti_sci_cmd_get_device; + dops->idle_device = ti_sci_cmd_idle_device; + dops->put_device = ti_sci_cmd_put_device; + + dops->is_valid = ti_sci_cmd_dev_is_valid; + dops->get_context_loss_count = ti_sci_cmd_dev_get_clcnt; + dops->is_idle = ti_sci_cmd_dev_is_idle; + dops->is_stop = ti_sci_cmd_dev_is_stop; + dops->is_on = ti_sci_cmd_dev_is_on; + dops->is_transitioning = ti_sci_cmd_dev_is_trans; + dops->set_device_resets = ti_sci_cmd_set_device_resets; + dops->get_device_resets = ti_sci_cmd_get_device_resets; +} + +/** * ti_sci_get_handle() - Get the TI SCI handle for a device * @dev: Pointer to device for which we want SCI handle *
@@ -727,6 +1158,8 @@ static int ti_sci_probe(struct platform_device *pdev) goto out; } +ti_sci_setup_ops (info); + dev_info(dev, "ABI: %d.%d (firmware rev 0x%04x '%s')\n", info->handle.version.abi_major, info->handle.version.abi_minor, info->handle.version.firmware_revision,
drivers/firmware/ti_sci.h +98 -0
108 lines not on this page · raw message
include/linux/soc/ti/ti_sci_protocol.h +91 -0
103 lines not on this page · raw message
Signature · 1 line
2.10.0
Nishanth Menon
maintainerPATCH v3 4/5 firmware: ti_sci: Add support for Clock control
In reply to Nishanth MenonTexas Instrument's System Control Interface (TI-SCI) Message Protocol is used in Texas Instrument's System on Chip (SoC) such as those in keystone family K2G SoC to communicate between various compute processors with a central system controller entity.
TI-SCI message protocol provides support for management of various hardware entities within the SoC. Add support driver to allow communication with system controller entity within the SoC using the mailbox client.
In general, we expect to function at a device level of abstraction, however, for proper operation of hardware blocks, many clocks directly supplying the hardware block needs to be queried or configured.
Introduce support for the set of SCI message protocol support that provide us with this capability.
---
Changes in V3: just rebase
V2: https://patchwork.kernel.org/patch/9305421/
V1: https://patchwork.kernel.org/patch/9291347/
drivers/firmware/ti_sci.c | 685 +++++++++++++++++++++++++++++++++ drivers/firmware/ti_sci.h | 289 ++++++++++++++ include/linux/soc/ti/ti_sci_protocol.h | 78 ++++ 3 files changed, 1052 insertions(+)
drivers/firmware/ti_sci.c +685 -0
@@ -902,6 +902,675 @@ static int ti_sci_cmd_get_device_resets(const struct ti_sci_handle *handle, NULL); } +/** +* ti_sci_set_clock_state() - Set clock state helper +* @handle: pointer to TI SCI handle +* @dev_id: Device identifier this request is for +* @clk_id: Clock identifier for the device for this request. +* Each device has it's own set of clock inputs. This indexes +* which clock input to modify. +* @flags: Header flags as needed +* @state: State to request for the clock. +* +* Return: 0 if all went well, else returns appropriate error value. +*/ +static int ti_sci_set_clock_state (const struct ti_sci_handle *handle, +u32 dev_id,u8 clk_id, +u32 flags,u8 state) +{ +struct ti_sci_info *info; +struct ti_sci_msg_req_set_clock_state *req; +struct ti_sci_msg_hdr *resp; +struct ti_sci_xfer *xfer; +struct device *dev; +int ret =0 ; + +if (IS_ERR (handle)) +return PTR_ERR (handle); +if (!handle) +return -EINVAL ; + + info =handle_to_ti_sci_info (handle); + dev = info->dev; + + xfer =ti_sci_get_one_xfer (info,TI_SCI_MSG_SET_CLOCK_STATE , + flags |TI_SCI_FLAG_REQ_ACK_ON_PROCESSED , +sizeof (*req),sizeof (*resp)); +if (IS_ERR (xfer)) { + ret =PTR_ERR (xfer); +dev_err (dev,"Message alloc failed(%d)\n" , ret); +return ret; + } + req = (struct ti_sci_msg_req_set_clock_state *)xfer->xfer_buf; + req->dev_id = dev_id; + req->clk_id = clk_id; + req->request_state = state; + + ret =ti_sci_do_xfer (info, xfer); +if (ret) { +dev_err (dev,"Mbox send fail %d\n" , ret); + goto fail; + } + + resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; + + ret =ti_sci_is_response_ack (resp) ?0 : -ENODEV ; + +fail: +ti_sci_put_one_xfer (&info->minfo, xfer); + +return ret; +} + +/** +* ti_sci_cmd_get_clock_state() - Get clock state helper +* @handle: pointer to TI SCI handle +* @dev_id: Device identifier this request is for +* @clk_id: Clock identifier for the device for this request. +* Each device has it's own set of clock inputs. This indexes +* which clock input to modify. +* @programmed_state: State requested for clock to move to +* @current_state: State that the clock is currently in +* +* Return: 0 if all went well, else returns appropriate error value. +*/ +static int ti_sci_cmd_get_clock_state (const struct ti_sci_handle *handle, +u32 dev_id,u8 clk_id, +u8 *programmed_state,u8 *current_state) +{ +struct ti_sci_info *info; +struct ti_sci_msg_req_get_clock_state *req; +struct ti_sci_msg_resp_get_clock_state *resp; +struct ti_sci_xfer *xfer; +struct device *dev; +int ret =0 ; + +if (IS_ERR (handle)) +return PTR_ERR (handle); +if (!handle) +return -EINVAL ; + +if (!programmed_state && !current_state) +return -EINVAL ; + + info =handle_to_ti_sci_info (handle); + dev = info->dev; + + xfer =ti_sci_get_one_xfer (info,TI_SCI_MSG_GET_CLOCK_STATE , +TI_SCI_FLAG_REQ_ACK_ON_PROCESSED , +sizeof (*req),sizeof (*resp)); +if (IS_ERR (xfer)) { + ret =PTR_ERR (xfer); +dev_err (dev,"Message alloc failed(%d)\n" , ret); +return ret; + } + req = (struct ti_sci_msg_req_get_clock_state *)xfer->xfer_buf; + req->dev_id = dev_id; + req->clk_id = clk_id; + + ret =ti_sci_do_xfer (info, xfer); +if (ret) { +dev_err (dev,"Mbox send fail %d\n" , ret); + goto fail; + } + + resp = (struct ti_sci_msg_resp_get_clock_state *)xfer->xfer_buf; + +if (!ti_sci_is_response_ack (resp)) { + ret = -ENODEV ; + goto fail; + } + +if (programmed_state) + *programmed_state = resp->programmed_state; +if (current_state) + *current_state = resp->current_state; + +fail: +ti_sci_put_one_xfer (&info->minfo, xfer); + +return ret; +} + +/** +* ti_sci_cmd_get_clock() - Get control of a clock from TI SCI +* @handle: pointer to TI SCI handle +* @dev_id: Device identifier this request is for +* @clk_id: Clock identifier for the device for this request. +* Each device has it's own set of clock inputs. This indexes +* which clock input to modify. +* @needs_ssc: 'true' if Spread Spectrum clock is desired, else 'false' +* @can_change_freq: 'true' if frequency change is desired, else 'false' +* @enable_input_term: 'true' if input termination is desired, else 'false' +* +* Return: 0 if all went well, else returns appropriate error value. +*/ +static int ti_sci_cmd_get_clock (const struct ti_sci_handle *handle,u32 dev_id, +u8 clk_id,bool needs_ssc,bool can_change_freq, +bool enable_input_term) +{ +u32 flags =0 ; + + flags |= needs_ssc ?MSG_FLAG_CLOCK_ALLOW_SSC :0 ; + flags |= can_change_freq ?MSG_FLAG_CLOCK_ALLOW_FREQ_CHANGE :0 ; + flags |= enable_input_term ?MSG_FLAG_CLOCK_INPUT_TERM :0 ; + +return ti_sci_set_clock_state (handle, dev_id, clk_id, flags, +MSG_CLOCK_SW_STATE_REQ ); +} + +/** +* ti_sci_cmd_idle_clock() - Idle a clock which is in our control +* @handle: pointer to TI SCI handle +* @dev_id: Device identifier this request is for +* @clk_id: Clock identifier for the device for this request. +* Each device has it's own set of clock inputs. This indexes +* which clock input to modify. +* +* NOTE: This clock must have been requested by get_clock previously. +* +* Return: 0 if all went well, else returns appropriate error value. +*/ +static int ti_sci_cmd_idle_clock (const struct ti_sci_handle *handle, +u32 dev_id,u8 clk_id) +{ +return ti_sci_set_clock_state (handle, dev_id, clk_id,0 , +MSG_CLOCK_SW_STATE_UNREQ ); +} + +/** +* ti_sci_cmd_put_clock() - Release a clock from our control back to TISCI +* @handle: pointer to TI SCI handle +* @dev_id: Device identifier this request is for +* @clk_id: Clock identifier for the device for this request. +* Each device has it's own set of clock inputs. This indexes +* which clock input to modify. +* +* NOTE: This clock must have been requested by get_clock previously. +* +* Return: 0 if all went well, else returns appropriate error value. +*/ +static int ti_sci_cmd_put_clock (const struct ti_sci_handle *handle, +u32 dev_id,u8 clk_id) +{ +return ti_sci_set_clock_state (handle, dev_id, clk_id,0 , +MSG_CLOCK_SW_STATE_AUTO ); +} + +/** +* ti_sci_cmd_clk_is_auto() - Is the clock being auto managed +* @handle: pointer to TI SCI handle +* @dev_id: Device identifier this request is for +* @clk_id: Clock identifier for the device for this request. +* Each device has it's own set of clock inputs. This indexes +* which clock input to modify. +* @req_state: state indicating if the clock is auto managed +* +* Return: 0 if all went well, else returns appropriate error value. +*/ +static int ti_sci_cmd_clk_is_auto (const struct ti_sci_handle *handle, +u32 dev_id,u8 clk_id,bool *req_state) +{ +u8 state =0 ; +int ret; + +if (!req_state) +return -EINVAL ; + + ret =ti_sci_cmd_get_clock_state (handle, dev_id, clk_id, &state,NULL ); +if (ret) +return ret; + + *req_state = (state ==MSG_CLOCK_SW_STATE_AUTO ); +return 0 ; +} + +/** +* ti_sci_cmd_clk_is_on() - Is the clock ON +* @handle: pointer to TI SCI handle +* @dev_id: Device identifier this request is for +* @clk_id: Clock identifier for the device for this request. +* Each device has it's own set of clock inputs. This indexes +* which clock input to modify. +* @req_state: state indicating if the clock is managed by us and enabled +* @curr_state: state indicating if the clock is ready for operation +* +* Return: 0 if all went well, else returns appropriate error value. +*/ +static int ti_sci_cmd_clk_is_on (const struct ti_sci_handle *handle,u32 dev_id, +u8 clk_id,bool *req_state,bool *curr_state) +{ +u8 c_state =0 , r_state =0 ; +int ret; + +if (!req_state && !curr_state) +return -EINVAL ; + + ret =ti_sci_cmd_get_clock_state (handle, dev_id, clk_id, + &r_state, &c_state); +if (ret) +return ret; + +if (req_state) + *req_state = (r_state ==MSG_CLOCK_SW_STATE_REQ ); +if (curr_state) + *curr_state = (c_state ==MSG_CLOCK_HW_STATE_READY ); +return 0 ; +} + +/** +* ti_sci_cmd_clk_is_off() - Is the clock OFF +* @handle: pointer to TI SCI handle +* @dev_id: Device identifier this request is for +* @clk_id: Clock identifier for the device for this request. +* Each device has it's own set of clock inputs. This indexes +* which clock input to modify. +* @req_state: state indicating if the clock is managed by us and disabled +* @curr_state: state indicating if the clock is NOT ready for operation +* +* Return: 0 if all went well, else returns appropriate error value. +*/ +static int ti_sci_cmd_clk_is_off (const struct ti_sci_handle *handle,u32 dev_id, +u8 clk_id,bool *req_state,bool *curr_state) +{ +u8 c_state =0 , r_state =0 ; +int ret; + +if (!req_state && !curr_state) +return -EINVAL ; + + ret =ti_sci_cmd_get_clock_state (handle, dev_id, clk_id, + &r_state, &c_state); +if (ret) +return ret; + +if (req_state) + *req_state = (r_state ==MSG_CLOCK_SW_STATE_UNREQ ); +if (curr_state) + *curr_state = (c_state ==MSG_CLOCK_HW_STATE_NOT_READY ); +return 0 ; +} + +/** +* ti_sci_cmd_clk_set_parent() - Set the clock source of a specific device clock +* @handle: pointer to TI SCI handle +* @dev_id: Device identifier this request is for +* @clk_id: Clock identifier for the device for this request. +* Each device has it's own set of clock inputs. This indexes +* which clock input to modify. +* @parent_id: Parent clock identifier to set +* +* Return: 0 if all went well, else returns appropriate error value. +*/ +static int ti_sci_cmd_clk_set_parent (const struct ti_sci_handle *handle, +u32 dev_id,u8 clk_id,u8 parent_id) +{ +struct ti_sci_info *info; +struct ti_sci_msg_req_set_clock_parent *req; +struct ti_sci_msg_hdr *resp; +struct ti_sci_xfer *xfer; +struct device *dev; +int ret =0 ; + +if (IS_ERR (handle)) +return PTR_ERR (handle); +if (!handle) +return -EINVAL ; + + info =handle_to_ti_sci_info (handle); + dev = info->dev; + + xfer =ti_sci_get_one_xfer (info,TI_SCI_MSG_SET_CLOCK_PARENT , +TI_SCI_FLAG_REQ_ACK_ON_PROCESSED , +sizeof (*req),sizeof (*resp)); +if (IS_ERR (xfer)) { + ret =PTR_ERR (xfer); +dev_err (dev,"Message alloc failed(%d)\n" , ret); +return ret; + } + req = (struct ti_sci_msg_req_set_clock_parent *)xfer->xfer_buf; + req->dev_id = dev_id; + req->clk_id = clk_id; + req->parent_id = parent_id; + + ret =ti_sci_do_xfer (info, xfer); +if (ret) { +dev_err (dev,"Mbox send fail %d\n" , ret); + goto fail; + } + + resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; + + ret =ti_sci_is_response_ack (resp) ?0 : -ENODEV ; + +fail: +ti_sci_put_one_xfer (&info->minfo, xfer); + +return ret; +} + +/** +* ti_sci_cmd_clk_get_parent() - Get current parent clock source +* @handle: pointer to TI SCI handle +* @dev_id: Device identifier this request is for +* @clk_id: Clock identifier for the device for this request. +* Each device has it's own set of clock inputs. This indexes +* which clock input to modify. +* @parent_id: Current clock parent +* +* Return: 0 if all went well, else returns appropriate error value. +*/ +static int ti_sci_cmd_clk_get_parent (const struct ti_sci_handle *handle, +u32 dev_id,u8 clk_id,u8 *parent_id) +{ +struct ti_sci_info *info; +struct ti_sci_msg_req_get_clock_parent *req; +struct ti_sci_msg_resp_get_clock_parent *resp; +struct ti_sci_xfer *xfer; +struct device *dev; +int ret =0 ; + +if (IS_ERR (handle)) +return PTR_ERR (handle); +if (!handle || !parent_id) +return -EINVAL ; + + info =handle_to_ti_sci_info (handle); + dev = info->dev; + + xfer =ti_sci_get_one_xfer (info,TI_SCI_MSG_GET_CLOCK_PARENT , +TI_SCI_FLAG_REQ_ACK_ON_PROCESSED , +sizeof (*req),sizeof (*resp)); +if (IS_ERR (xfer)) { + ret =PTR_ERR (xfer); +dev_err (dev,"Message alloc failed(%d)\n" , ret); +return ret; + } + req = (struct ti_sci_msg_req_get_clock_parent *)xfer->xfer_buf; + req->dev_id = dev_id; + req->clk_id = clk_id; + + ret =ti_sci_do_xfer (info, xfer); +if (ret) { +dev_err (dev,"Mbox send fail %d\n" , ret); + goto fail; + } + + resp = (struct ti_sci_msg_resp_get_clock_parent *)xfer->xfer_buf; + +if (!ti_sci_is_response_ack (resp)) + ret = -ENODEV ; +else + *parent_id = resp->parent_id; + +fail: +ti_sci_put_one_xfer (&info->minfo, xfer); + +return ret; +} + +/** +* ti_sci_cmd_clk_get_num_parents() - Get num parents of the current clk source +* @handle: pointer to TI SCI handle +* @dev_id: Device identifier this request is for +* @clk_id: Clock identifier for the device for this request. +* Each device has it's own set of clock inputs. This indexes +* which clock input to modify. +* @num_parents: Returns he number of parents to the current clock. +* +* Return: 0 if all went well, else returns appropriate error value. +*/ +static int ti_sci_cmd_clk_get_num_parents (const struct ti_sci_handle *handle, +u32 dev_id,u8 clk_id, +u8 *num_parents) +{ +struct ti_sci_info *info; +struct ti_sci_msg_req_get_clock_num_parents *req; +struct ti_sci_msg_resp_get_clock_num_parents *resp; +struct ti_sci_xfer *xfer; +struct device *dev; +int ret =0 ; + +if (IS_ERR (handle)) +return PTR_ERR (handle); +if (!handle || !num_parents) +return -EINVAL ; + + info =handle_to_ti_sci_info (handle); + dev = info->dev; + + xfer =ti_sci_get_one_xfer (info,TI_SCI_MSG_GET_NUM_CLOCK_PARENTS , +TI_SCI_FLAG_REQ_ACK_ON_PROCESSED , +sizeof (*req),sizeof (*resp)); +if (IS_ERR (xfer)) { + ret =PTR_ERR (xfer); +dev_err (dev,"Message alloc failed(%d)\n" , ret); +return ret; + } + req = (struct ti_sci_msg_req_get_clock_num_parents *)xfer->xfer_buf; + req->dev_id = dev_id; + req->clk_id = clk_id; + + ret =ti_sci_do_xfer (info, xfer); +if (ret) { +dev_err (dev,"Mbox send fail %d\n" , ret); + goto fail; + } + + resp = (struct ti_sci_msg_resp_get_clock_num_parents *)xfer->xfer_buf; + +if (!ti_sci_is_response_ack (resp)) + ret = -ENODEV ; +else + *num_parents = resp->num_parents; + +fail: +ti_sci_put_one_xfer (&info->minfo, xfer); + +return ret; +} + +/** +* ti_sci_cmd_clk_get_match_freq() - Find a good match for frequency +* @handle: pointer to TI SCI handle +* @dev_id: Device identifier this request is for +* @clk_id: Clock identifier for the device for this request. +* Each device has it's own set of clock inputs. This indexes +* which clock input to modify. +* @min_freq: The minimum allowable frequency in Hz. This is the minimum +* allowable programmed frequency and does not account for clock +* tolerances and jitter. +* @target_freq: The target clock frequency in Hz. A frequency will be +* processed as close to this target frequency as possible. +* @max_freq: The maximum allowable frequency in Hz. This is the maximum +* allowable programmed frequency and does not account for clock +* tolerances and jitter. +* @match_freq: Frequency match in Hz response. +* +* Return: 0 if all went well, else returns appropriate error value. +*/ +static int ti_sci_cmd_clk_get_match_freq (const struct ti_sci_handle *handle, +u32 dev_id,u8 clk_id,u64 min_freq, +u64 target_freq,u64 max_freq, +u64 *match_freq) +{ +struct ti_sci_info *info; +struct ti_sci_msg_req_query_clock_freq *req; +struct ti_sci_msg_resp_query_clock_freq *resp; +struct ti_sci_xfer *xfer; +struct device *dev; +int ret =0 ; + +if (IS_ERR (handle)) +return PTR_ERR (handle); +if (!handle || !match_freq) +return -EINVAL ; + + info =handle_to_ti_sci_info (handle); + dev = info->dev; + + xfer =ti_sci_get_one_xfer (info,TI_SCI_MSG_QUERY_CLOCK_FREQ , +TI_SCI_FLAG_REQ_ACK_ON_PROCESSED , +sizeof (*req),sizeof (*resp)); +if (IS_ERR (xfer)) { + ret =PTR_ERR (xfer); +dev_err (dev,"Message alloc failed(%d)\n" , ret); +return ret; + } + req = (struct ti_sci_msg_req_query_clock_freq *)xfer->xfer_buf; + req->dev_id = dev_id; + req->clk_id = clk_id; + req->min_freq_hz = min_freq; + req->target_freq_hz = target_freq; + req->max_freq_hz = max_freq; + + ret =ti_sci_do_xfer (info, xfer); +if (ret) { +dev_err (dev,"Mbox send fail %d\n" , ret); + goto fail; + } + + resp = (struct ti_sci_msg_resp_query_clock_freq *)xfer->xfer_buf; + +if (!ti_sci_is_response_ack (resp)) + ret = -ENODEV ; +else + *match_freq = resp->freq_hz; + +fail: +ti_sci_put_one_xfer (&info->minfo, xfer); + +return ret; +} + +/** +* ti_sci_cmd_clk_set_freq() - Set a frequency for clock +* @handle: pointer to TI SCI handle +* @dev_id: Device identifier this request is for +* @clk_id: Clock identifier for the device for this request. +* Each device has it's own set of clock inputs. This indexes +* which clock input to modify. +* @min_freq: The minimum allowable frequency in Hz. This is the minimum +* allowable programmed frequency and does not account for clock +* tolerances and jitter. +* @target_freq: The target clock frequency in Hz. A frequency will be +* processed as close to this target frequency as possible. +* @max_freq: The maximum allowable frequency in Hz. This is the maximum +* allowable programmed frequency and does not account for clock +* tolerances and jitter. +* +* Return: 0 if all went well, else returns appropriate error value. +*/ +static int ti_sci_cmd_clk_set_freq (const struct ti_sci_handle *handle, +u32 dev_id,u8 clk_id,u64 min_freq, +u64 target_freq,u64 max_freq) +{ +struct ti_sci_info *info; +struct ti_sci_msg_req_set_clock_freq *req; +struct ti_sci_msg_hdr *resp; +struct ti_sci_xfer *xfer; +struct device *dev; +int ret =0 ; + +if (IS_ERR (handle)) +return PTR_ERR (handle); +if (!handle) +return -EINVAL ; + + info =handle_to_ti_sci_info (handle); + dev = info->dev; + + xfer =ti_sci_get_one_xfer (info,TI_SCI_MSG_SET_CLOCK_FREQ , +TI_SCI_FLAG_REQ_ACK_ON_PROCESSED , +sizeof (*req),sizeof (*resp)); +if (IS_ERR (xfer)) { + ret =PTR_ERR (xfer); +dev_err (dev,"Message alloc failed(%d)\n" , ret); +return ret; + } + req = (struct ti_sci_msg_req_set_clock_freq *)xfer->xfer_buf; + req->dev_id = dev_id; + req->clk_id = clk_id; + req->min_freq_hz = min_freq; + req->target_freq_hz = target_freq; + req->max_freq_hz = max_freq; + + ret =ti_sci_do_xfer (info, xfer); +if (ret) { +dev_err (dev,"Mbox send fail %d\n" , ret); + goto fail; + } + + resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; + + ret =ti_sci_is_response_ack (resp) ?0 : -ENODEV ; + +fail: +ti_sci_put_one_xfer (&info->minfo, xfer); + +return ret; +} + +/** +* ti_sci_cmd_clk_get_freq() - Get current frequency +* @handle: pointer to TI SCI handle +* @dev_id: Device identifier this request is for +* @clk_id: Clock identifier for the device for this request. +* Each device has it's own set of clock inputs. This indexes +* which clock input to modify. +* @freq: Currently frequency in Hz +* +* Return: 0 if all went well, else returns appropriate error value. +*/ +static int ti_sci_cmd_clk_get_freq (const struct ti_sci_handle *handle, +u32 dev_id,u8 clk_id,u64 *freq) +{ +struct ti_sci_info *info; +struct ti_sci_msg_req_get_clock_freq *req; +struct ti_sci_msg_resp_get_clock_freq *resp; +struct ti_sci_xfer *xfer; +struct device *dev; +int ret =0 ; + +if (IS_ERR (handle)) +return PTR_ERR (handle); +if (!handle || !freq) +return -EINVAL ; + + info =handle_to_ti_sci_info (handle); + dev = info->dev; + + xfer =ti_sci_get_one_xfer (info,TI_SCI_MSG_GET_CLOCK_FREQ , +TI_SCI_FLAG_REQ_ACK_ON_PROCESSED , +sizeof (*req),sizeof (*resp)); +if (IS_ERR (xfer)) { + ret =PTR_ERR (xfer); +dev_err (dev,"Message alloc failed(%d)\n" , ret); +return ret; + } + req = (struct ti_sci_msg_req_get_clock_freq *)xfer->xfer_buf; + req->dev_id = dev_id; + req->clk_id = clk_id; + + ret =ti_sci_do_xfer (info, xfer); +if (ret) { +dev_err (dev,"Mbox send fail %d\n" , ret); + goto fail; + } + + resp = (struct ti_sci_msg_resp_get_clock_freq *)xfer->xfer_buf; + +if (!ti_sci_is_response_ack (resp)) + ret = -ENODEV ; +else + *freq = resp->freq_hz; + +fail: +ti_sci_put_one_xfer (&info->minfo, xfer); + +return ret; +} +/* * ti_sci_setup_ops() - Setup the operations structures * @info: pointer to TISCI pointer
@@ -910,6 +1579,7 @@ static void ti_sci_setup_ops(struct ti_sci_info *info) {struct ti_sci_ops *ops = &info->handle.ops;struct ti_sci_dev_ops *dops = &ops->dev_ops; +struct ti_sci_clk_ops *cops = &ops->clk_ops; dops->get_device = ti_sci_cmd_get_device; dops->idle_device = ti_sci_cmd_idle_device;
@@ -923,6 +1593,21 @@ static void ti_sci_setup_ops(struct ti_sci_info *info) dops->is_transitioning = ti_sci_cmd_dev_is_trans; dops->set_device_resets = ti_sci_cmd_set_device_resets; dops->get_device_resets = ti_sci_cmd_get_device_resets; + + cops->get_clock = ti_sci_cmd_get_clock; + cops->idle_clock = ti_sci_cmd_idle_clock; + cops->put_clock = ti_sci_cmd_put_clock; + cops->is_auto = ti_sci_cmd_clk_is_auto; + cops->is_on = ti_sci_cmd_clk_is_on; + cops->is_off = ti_sci_cmd_clk_is_off; + + cops->set_parent = ti_sci_cmd_clk_set_parent; + cops->get_parent = ti_sci_cmd_clk_get_parent; + cops->get_num_parents = ti_sci_cmd_clk_get_num_parents; + + cops->get_best_match_freq = ti_sci_cmd_clk_get_match_freq; + cops->set_freq = ti_sci_cmd_clk_set_freq; + cops->get_freq = ti_sci_cmd_clk_get_freq; }/**
drivers/firmware/ti_sci.h +289 -0
299 lines not on this page · raw message
include/linux/soc/ti/ti_sci_protocol.h +78 -0
89 lines not on this page · raw message
Signature · 1 line
2.10.0
Nishanth Menon
maintainerPATCH v3 5/5 firmware: ti_sci: Add support for reboot core service
In reply to Nishanth MenonSince system controller now has control over SoC power management, it needs to be explicitly requested to reboot the SoC. Add support for it.
In some systems however, SoC needs to toggle a GPIO or send event to an external entity (like a PMIC) for a system reboot to take place. To facilitate that, we allow for a DT property to determine if the reboot handler will be registered and further, the service is also made available to other drivers (such as PMIC driver) to sequence the additional operation and trigger the SoC reboot as the last step.
---
Changes in V3: just rebase
V2: https://patchwork.kernel.org/patch/9305423/
V1: https://patchwork.kernel.org/patch/9291351/
drivers/firmware/ti_sci.c | 85 ++++++++++++++++++++++++++++++++++ drivers/firmware/ti_sci.h | 12 +++++ include/linux/soc/ti/ti_sci_protocol.h | 11 +++++ 3 files changed, 108 insertions(+)
drivers/firmware/ti_sci.c +85 -0
@@ -28,6 +28,7 @@#include <linux/slab.h> #include <linux/soc/ti/ti-msgmgr.h> #include <linux/soc/ti/ti_sci_protocol.h> +#include <linux/reboot.h> #include "ti_sci.h"
@@ -90,6 +91,7 @@ struct ti_sci_desc {* struct ti_sci_info - Structure representing a TI SCI instance * @dev: Device pointer * @desc: SoC description for this instance +* @nb: Reboot Notifier block * @d: Debugfs file entry * @debug_region: Memory region where the debug message are available * @debug_region_size: Debug region size
@@ -104,6 +106,7 @@ struct ti_sci_desc {*/ struct ti_sci_info {struct device *dev; +struct notifier_block nb;const struct ti_sci_desc *desc;struct dentry *d;void __iomem *debug_region;
@@ -117,11 +120,15 @@ struct ti_sci_info {struct list_head node;/* protected by ti_sci_list_mutex */ int users; + };#define cl_to_ti_sci_info (cl) container_of(cl, struct ti_sci_info, cl)#define handle_to_ti_sci_info (handle) container_of(handle, struct ti_sci_info,\ handle) +#define reboot_to_ti_sci_info (nb) container_of(nb,\ + struct ti_sci_info,\ + nb)#ifdef CONFIG_DEBUG_FS /**
@@ -1571,6 +1578,52 @@ fail:return ret; } +static int ti_sci_cmd_core_reboot (const struct ti_sci_handle *handle) +{ +struct ti_sci_info *info; +struct ti_sci_msg_req_reboot *req; +struct ti_sci_msg_hdr *resp; +struct ti_sci_xfer *xfer; +struct device *dev; +int ret =0 ; + +if (IS_ERR (handle)) +return PTR_ERR (handle); +if (!handle) +return -EINVAL ; + + info =handle_to_ti_sci_info (handle); + dev = info->dev; + + xfer =ti_sci_get_one_xfer (info,TI_SCI_MSG_SYS_RESET , +TI_SCI_FLAG_REQ_ACK_ON_PROCESSED , +sizeof (*req),sizeof (*resp)); +if (IS_ERR (xfer)) { + ret =PTR_ERR (xfer); +dev_err (dev,"Message alloc failed(%d)\n" , ret); +return ret; + } + req = (struct ti_sci_msg_req_reboot *)xfer->xfer_buf; + + ret =ti_sci_do_xfer (info, xfer); +if (ret) { +dev_err (dev,"Mbox send fail %d\n" , ret); + goto fail; + } + + resp = (struct ti_sci_msg_hdr *)xfer->xfer_buf; + +if (!ti_sci_is_response_ack (resp)) + ret = -ENODEV ; +else + ret =0 ; + +fail: +ti_sci_put_one_xfer (&info->minfo, xfer); + +return ret; +} +/* * ti_sci_setup_ops() - Setup the operations structures * @info: pointer to TISCI pointer
@@ -1578,9 +1631,12 @@ fail:static void ti_sci_setup_ops (struct ti_sci_info *info) {struct ti_sci_ops *ops = &info->handle.ops; +struct ti_sci_core_ops *core_ops = &ops->core_ops;struct ti_sci_dev_ops *dops = &ops->dev_ops;struct ti_sci_clk_ops *cops = &ops->clk_ops; + core_ops->reboot_device = ti_sci_cmd_core_reboot; + dops->get_device = ti_sci_cmd_get_device; dops->idle_device = ti_sci_cmd_idle_device; dops->put_device = ti_sci_cmd_put_device;
@@ -1732,6 +1788,18 @@ const struct ti_sci_handle *devm_ti_sci_get_handle(struct device *dev) }EXPORT_SYMBOL_GPL (devm_ti_sci_get_handle); +static int tisci_reboot_handler (struct notifier_block *nb,unsigned long mode, +void *cmd) +{ +struct ti_sci_info *info =reboot_to_ti_sci_info (nb); +const struct ti_sci_handle *handle = &info->handle; + +ti_sci_cmd_core_reboot (handle); + +/* call fail OR pass, we should not be here in the first place */ +return NOTIFY_BAD ; +} +/* Description for K2G */ static const struct ti_sci_desc ti_sci_pmmc_k2g_desc = { .host_id =2 ,
@@ -1759,6 +1827,7 @@ static int ti_sci_probe(struct platform_device *pdev)struct mbox_client *cl;int ret = -EINVAL ;int i; +int reboot =0 ; of_id =of_match_device (ti_sci_of_match, dev);if (!of_id) {
@@ -1773,6 +1842,8 @@ static int ti_sci_probe(struct platform_device *pdev) info->dev = dev; info->desc = desc; + reboot =of_property_read_bool (dev->of_node, +"ti,system-reboot-controller" );INIT_LIST_HEAD (&info->node); minfo = &info->minfo;
@@ -1845,6 +1916,17 @@ static int ti_sci_probe(struct platform_device *pdev)ti_sci_setup_ops (info); +if (reboot) { + info->nb.notifier_call = tisci_reboot_handler; + info->nb.priority =128 ; + + ret =register_restart_handler (&info->nb); +if (ret) { +dev_err (dev,"reboot registration fail(%d)\n" , ret); +return ret; + } + } + dev_info(dev, "ABI: %d.%d (firmware rev 0x%04x '%s')\n", info->handle.version.abi_major, info->handle.version.abi_minor, info->handle.version.firmware_revision,
@@ -1874,6 +1956,9 @@ static int ti_sci_remove(struct platform_device *pdev) info =platform_get_drvdata (pdev); +if (info->nb.notifier_call) +unregister_restart_handler (&info->nb); +mutex_lock (&ti_sci_list_mutex);if (info->users) ret = -EBUSY ;
drivers/firmware/ti_sci.h +12 -0
@@ -46,6 +46,7 @@#define TI_SCI_MSG_VERSION 0x0002#define TI_SCI_MSG_WAKE_REASON 0x0003#define TI_SCI_MSG_GOODBYE 0x0004 +#define TI_SCI_MSG_SYS_RESET 0x0005/* Device requests */ #define TI_SCI_MSG_SET_DEVICE_STATE 0x0200
@@ -106,6 +107,17 @@ struct ti_sci_msg_resp_version { } __packed;/** +* struct ti_sci_msg_req_reboot - Reboot the SoC +* @hdr: Generic Header +* +* Request type is TI_SCI_MSG_SYS_RESET, responded with a generic +* ACK/NACK message. +*/ +struct ti_sci_msg_req_reboot { +struct ti_sci_msg_hdr hdr; +} __packed; + +/** * struct ti_sci_msg_req_set_device_state - Set the desired state of the device * @hdr: Generic header * @id: Indicates which device to modify
include/linux/soc/ti/ti_sci_protocol.h +11 -0
@@ -36,6 +36,16 @@ struct ti_sci_version_info {struct ti_sci_handle ;/** +* struct ti_sci_core_ops - SoC Core Operations +* @reboot_device: Reboot the SoC +* Returns 0 for successful request(ideally should never return), +* else returns corresponding error value. +*/ +struct ti_sci_core_ops { +int (*reboot_device)(const struct ti_sci_handle *handle); +}; + +/** * struct ti_sci_dev_ops - Device control operations * @get_device: Command to request for device managed by TISCI * Returns 0 for successful exclusive request, else returns
@@ -196,6 +206,7 @@ struct ti_sci_clk_ops {* @clk_ops: Clock specific operations */ struct ti_sci_ops { +struct ti_sci_core_ops core_ops;struct ti_sci_dev_ops dev_ops;struct ti_sci_clk_ops clk_ops; };
Signature · 1 line
2.10.0
Quoted 14 lines · Nishanth Menon
Hi,
Version 3 of the series with change in the way we describe the children nodes (no change to drivers required - only the dts description changes).
Texas Instruments' Keystone generation System on Chips (SoC) starting with 66AK2G02[1], now include a dedicated SoC System Control entity called PMMC(Power Management Micro Controller) in line with ARM architecture recommendations. The function of this module is to integrate all system operations in a centralized location. Communication with the SoC System Control entity from various processing units like ARM/DSP occurs over Message Manager hardware block.
Quoted 5 lines
This series adds the base support for TI System Control Interface (TI-SCI) protocol[2]. The protocol is built on top of Texas Instrument's Message Manager communication mechanism[3].
Overall architecture is very similar to SCPI[4] as follows:
Dumb Q: I'm curious about the limitations in SCPI that were found that made TI decided to implement its own version.
Thanks,
Kevin
Nishanth Menon
maintainerQuoted 1 line · Kevin Hilman
Nishanth Menon <[email protected]> writes:
[...] full mail thread in https://lkml.org/lkml/2016/9/6/747
Quoted 4 lines
Quoted 1 line
Overall architecture is very similar to SCPI[4] as follows:
Dumb Q: I'm curious about the limitations in SCPI that were found that made TI decided to implement its own version.
Not really a dumb question.. (and praying I dont trigger a flame war :D) I will skip the approximately year something worth of discussions and TI's Linaro connect requests for consolidation of standards aside, lets not forget to add ARM's new protocol proposal to the list that I cant seem to find public reference to (ccying folks in case I have'nt looked the right place in http://infocenter.arm.com), but which also developed in parallel to TI-SCI. Anyways..
Just as a background for new folks: ARM Power Control System Architecture Specification Version (ARM DEN 0050) (which you'd need to contact ARM to get access to) strongly recommends System Control Processor - but ofcourse, SCPI evolved as ARMs way of solving the Juno problem set (and Sudeep can probably add lots of backgrounds on that). And SCPI is not, at least to my knowledge, mandatory for ARM vendors to follow. It probably suffices to say that ARM had SCPI and TI developed TI-SCI.
Now, to answer your question, why did we not just use SCPI instead of re-inventing the wheel? To be honest, and folks who have the year something background know this: We really did not want to spin our own.
SCPI and TISCI or other similar protocols tend to have few constraints to work with:
a) messaging infrastructure and capabilities ARM MHU Vs what we have for TI message Manager (one word vs upto 128 queued 64byte messages in message manager from multiple simultaneous requesters)- examples being virtualized pipes and sizes we have for communication allows our protocol to optimize messaging appropriate to the SoC.
b) SoC architecture and constraints required of that - examples: here being the processing entities, multitude variations of integrations and SoC spins, required higher level of abstraction to even have a resemblance of sanity at HLOS level.
c) To a minor extent, not really relevant for this thread: timelines of parallel development and influence from corresponding SoC and other stakeholders within each corporates.
Long story short, investigation was done into what SCPI was providing (TI internal ofcourse) and SCPI did not fit our SoC generation needs -
-
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0922g/index.html
vs http://processors.wiki.ti.com/index.php/TISCI is available to compare and contrast but the key highlights are probably as follows:
- SCPI seems to be constrained around capabilities of MHU and does not allow better leverage of h/w K2G (and future SoCs) have capabilities of.
- SCPI abstraction levels did not fit our SoC architecture models we are moving to where ARM cores running Linux are optional and no longer the system master of the SoC - we do have non-ARM SoCs as well in our SoC portfolio and obviously non-Linux solutions as well. some little details:
- From being able to mandate response messages which can be tuned
from "dont bother to tell me once you are done" to fine grained as "tell me when you get around to this operation but let me know before you actually process" as optional states for any type of messages
- Levels of abstraction of "I dont care what you in system
controller do as long as my Display Subsystem func clk runs as xyz Hz"
- we need to care about hardware block level operation, not how the
SoC intricacies of operating the hardware block is.. example we need capability to hold a hardware block active from two processing entities for blocks that are capable of doing so (example: GPIO and blocks with virtualized view capability)
and obviously more..
Obviously, each protocol could claim superiority of level of control/abstraction provided based on SoC arch targeted etc.. but I will try and avoid getting into that debate.
Signature · 2 lines
Regards, Nishanth Menon
Quoted 9 lines · Nishanth Menon
Quoted 1 line · Kevin Hilman
Nishanth Menon <[email protected]> writes:
[...] full mail thread in https://lkml.org/lkml/2016/9/6/747
Quoted 4 lines
Quoted 1 line
Overall architecture is very similar to SCPI[4] as follows:
Dumb Q: I'm curious about the limitations in SCPI that were found that made TI decided to implement its own version.
[...]
Quoted 2 lines
Long story short, investigation was done into what SCPI was providing (TI internal ofcourse) and SCPI did not fit our SoC generation needs -
Thanks for the detailed explanation. Very helpful.
To be clear, I'm not a proponent of always using ARM "standards" (especially when it's not exactly clear if it's a standard or a Juno thing) but I'm seeing several SoCs come out with SCPI derivatives, or old ARM versions etc., so was just curious about the decision making process.
Thanks for sharing,
Kevin
Quoted 25 lines · Kevin Hilman
Quoted 9 lines · Nishanth Menon
Quoted 1 line · Kevin Hilman
Nishanth Menon <[email protected]> writes:
[...] full mail thread in https://lkml.org/lkml/2016/9/6/747
Quoted 4 lines
Quoted 1 line
Overall architecture is very similar to SCPI[4] as follows:
Dumb Q: I'm curious about the limitations in SCPI that were found that made TI decided to implement its own version.
[...]
Quoted 2 lines
Long story short, investigation was done into what SCPI was providing (TI internal ofcourse) and SCPI did not fit our SoC generation needs -
Thanks for the detailed explanation. Very helpful.
To be clear, I'm not a proponent of always using ARM "standards" (especially when it's not exactly clear if it's a standard or a Juno thing) but I'm seeing several SoCs come out with SCPI derivatives, or old ARM versions etc., so was just curious about the decision making process.
Quoted 3 lines
Thanks for sharing,
Kevin
So, any other comments for this series or shall we still try to get it merged for 4.9? We are -rc5 so it might be too late already and probably better to push this for 4.10.
-Tero