soc: add microchip polarfire soc system controller
Subsystems (3)
[email protected]
maintainerv4 cover soc: add microchip polarfire soc system controller
From: Conor Dooley <[email protected]>
Since I submitted version 1 of this driver, I attempted to upstream bindings for devices dependant on the system controller [0]. In that process, Rob said that since they were devices with no resources, other than a reference to the system controller, the devices should not be in the device tree & instead they should be created by the system controller (which it now does).
Since the sub devices using mpfs_sys_controller_get will now have the system controller as their parent, this function now just checks if the parent device is compatible. If the parent is compatible, the sub- device then attempts to register as a consumer of the system controller
@Arnd Hopefully this clears up the issues you had with reference counting & the lack of checks as to whether the device found by mpfs_sys_controller_get was in fact a system controller.
Depends on [0] to change the compatible string in the dt-binding. Thanks,
Conor.
Changes since v3:
- switch to devm_kzalloc in probe
- unify exports to use the non GPL version
Changes since v2:
- system controller is no longer an mfd, system controller now creates sub devices for itself.
- specify that a mpfs_mss_msg is used in mpfs_blocking_transaction rather than using a void pointer.
- as the subdevices are now all created by the system controller, the get() function now checks that the requesting device's parent is compatible.
- mpfs_sys_controller_get now passes a pointer to the device that is trying to register as a consumer rather than a device node.
Changes since v1:
- system controller is now an mfd
- parentage is now used to get the device node on the system controller
- mpfs_sys_controller_get() now updates the reference count
- "polarfire-soc" in compat string changed to "mpfs"
[0] https://lore.kernel.org/linux-riscv/[email protected]/
Conor Dooley (1):
soc: add microchip polarfire soc system controller
drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/microchip/Kconfig | 10 + drivers/soc/microchip/Makefile | 1 + drivers/soc/microchip/mpfs-sys-controller.c | 194 ++++++++++++++++++++ include/soc/microchip/mpfs.h | 4 +- 6 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 drivers/soc/microchip/Kconfig create mode 100644 drivers/soc/microchip/Makefile create mode 100644 drivers/soc/microchip/mpfs-sys-controller.c
Signature · 1 line
2.35.1
[email protected]
maintainerPATCH v4 1/1 soc: add microchip polarfire soc system controller
From: Conor Dooley <[email protected]>
This driver provides an interface for other drivers to access the functions of the system controller on the Microchip PolarFire SoC.
--- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/microchip/Kconfig | 10 + drivers/soc/microchip/Makefile | 1 + drivers/soc/microchip/mpfs-sys-controller.c | 194 ++++++++++++++++++++ include/soc/microchip/mpfs.h | 4 +- 6 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 drivers/soc/microchip/Kconfig create mode 100644 drivers/soc/microchip/Makefile create mode 100644 drivers/soc/microchip/mpfs-sys-controller.c
drivers/soc/Kconfig +1 -0
@@ -13,6 +13,7 @@ source "drivers/soc/imx/Kconfig" source "drivers/soc/ixp4xx/Kconfig" source "drivers/soc/litex/Kconfig" source "drivers/soc/mediatek/Kconfig" +source "drivers/soc/microchip/Kconfig" source "drivers/soc/qcom/Kconfig" source "drivers/soc/renesas/Kconfig" source "drivers/soc/rockchip/Kconfig"
drivers/soc/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-y += ixp4xx/ obj-$(CONFIG_SOC_XWAY) += lantiq/ obj-$(CONFIG_LITEX_SOC_CONTROLLER) += litex/ obj-y += mediatek/ +obj-y += microchip/ obj-y += amlogic/ obj-y += qcom/ obj-y += renesas/
drivers/soc/microchip/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +config POLARFIRE_SOC_SYS_CTRL + tristate "POLARFIRE_SOC_SYS_CTRL" + depends on POLARFIRE_SOC_MAILBOX + help + This driver adds support for the PolarFire SoC (MPFS) system controller. + + To compile this driver as a module, choose M here. the + module will be called mpfs_system_controller. + + If unsure, say N.
drivers/soc/microchip/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_POLARFIRE_SOC_SYS_CTRL) += mpfs-sys-controller.o
drivers/soc/microchip/mpfs-sys-controller.c new file +194 -0
194 lines not on this page · raw message
include/soc/microchip/mpfs.h +2 -2
@@ -34,9 +34,9 @@ struct mpfs_mss_response {#if IS_ENABLED (CONFIG_POLARFIRE_SOC_SYS_CTRL ) -int mpfs_blocking_transaction (struct mpfs_sys_controller *mpfs_client,void *msg); +int mpfs_blocking_transaction (struct mpfs_sys_controller *mpfs_client,struct mpfs_mss_msg *msg); -struct mpfs_sys_controller *mpfs_sys_controller_get (struct device_node *mailbox_node); +struct mpfs_sys_controller *mpfs_sys_controller_get (struct device *dev);#endif /* if IS_ENABLED(CONFIG_POLARFIRE_SOC_SYS_CTRL) */
Signature · 1 line
2.35.1
Quoted 6 lines · On 17/02/2022 at 11:13, [email protected] wrote:
From: Conor Dooley <[email protected]>
This driver provides an interface for other drivers to access the functions of the system controller on the Microchip PolarFire SoC.
Signed-off-by Conor Dooley <[email protected]>
It looks okay to me:
As agreed with Conor, I queue it in my at91-soc branch for 5.18 which will be reached via arm-soc.
Best regards,
Nicolas
Quoted 275 lines
--- drivers/soc/Kconfig | 1 + drivers/soc/Makefile | 1 + drivers/soc/microchip/Kconfig | 10 + drivers/soc/microchip/Makefile | 1 + drivers/soc/microchip/mpfs-sys-controller.c | 194 ++++++++++++++++++++ include/soc/microchip/mpfs.h | 4 +- 6 files changed, 209 insertions(+), 2 deletions(-)create mode 100644
drivers/soc/microchip/Kconfigcreate mode 100644drivers/soc/microchip/Makefilecreate mode 100644drivers/soc/microchip/mpfs-sys-controller.cdrivers/soc/Kconfig +1
-0@@ -13,6 +13,7 @@ source "drivers/soc/imx/Kconfig" source "drivers/soc/ixp4xx/Kconfig" source "drivers/soc/litex/Kconfig" source "drivers/soc/mediatek/Kconfig" +source "drivers/soc/microchip/Kconfig" source "drivers/soc/qcom/Kconfig" source "drivers/soc/renesas/Kconfig" source "drivers/soc/rockchip/Kconfig"drivers/soc/Makefile +1
-0@@ -18,6 +18,7 @@ obj-y += ixp4xx/ obj-$(CONFIG_SOC_XWAY) += lantiq/ obj-$(CONFIG_LITEX_SOC_CONTROLLER) += litex/ obj-y += mediatek/ +obj-y += microchip/ obj-y += amlogic/ obj-y += qcom/ obj-y += renesas/drivers/soc/microchip/Kconfig new file +10
-0@@ -0,0 +1,10 @@ +config POLARFIRE_SOC_SYS_CTRL + tristate "POLARFIRE_SOC_SYS_CTRL" + depends on POLARFIRE_SOC_MAILBOX + help + This driver adds support for the PolarFire SoC (MPFS) system controller. + + To compile this driver as a module, choose M here. the + module will be called mpfs_system_controller. + + If unsure, say N.drivers/soc/microchip/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-$(CONFIG_POLARFIRE_SOC_SYS_CTRL) += mpfs-sys-controller.odrivers/soc/microchip/mpfs-sys-controller.c new file +194
-0@@ -0,0 +1,194 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Microchip PolarFire SoC (MPFS) system controller driver +* +* Copyright (c) 2020-2021 Microchip Corporation. All rights reserved. +* +* Author: Conor Dooley <[email protected]> +* +*/ + +#include <linux/slab.h> +#include <linux/kref.h> +#include <linux/module.h> +#include <linux/interrupt.h> +#include <linux/of_platform.h> +#include <linux/mailbox_client.h> +#include <linux/platform_device.h> +#include <soc/microchip/mpfs.h> + +static DEFINE_MUTEX (transaction_lock); + +struct mpfs_sys_controller { +struct mbox_client client; +struct mbox_chan *chan; +struct completion c; +struct kref consumers; +}; + +int mpfs_blocking_transaction (struct mpfs_sys_controller *sys_controller,struct mpfs_mss_msg *msg) +{ +int ret, err; + + err =mutex_lock_interruptible (&transaction_lock); +if (err) +return err; + +reinit_completion (&sys_controller->c); + + ret =mbox_send_message (sys_controller->chan, msg); +if (ret >=0 ) { +if (wait_for_completion_timeout (&sys_controller->c,HZ )) { + ret =0 ; + }else { + ret = -ETIMEDOUT ; +dev_warn (sys_controller->client.dev, +"MPFS sys controller transaction timeout\n" ); + } + }else { +dev_err (sys_controller->client.dev, +"mpfs sys controller transaction returned %d\n" , ret); + } + +mutex_unlock (&transaction_lock); + +return ret; +} +EXPORT_SYMBOL (mpfs_blocking_transaction); + +static void rx_callback (struct mbox_client *client,void *msg) +{ +struct mpfs_sys_controller *sys_controller = + container_of(client, struct mpfs_sys_controller, client); + +complete (&sys_controller->c); +} + +static void mpfs_sys_controller_delete (struct kref *kref) +{ + struct mpfs_sys_controller *sys_controller = container_of(kref, struct mpfs_sys_controller, + consumers); + +mbox_free_channel (sys_controller->chan); +kfree (sys_controller); +} + +void mpfs_sys_controller_put (void *data) +{ +struct mpfs_sys_controller *sys_controller = data; + +kref_put (&sys_controller->consumers, mpfs_sys_controller_delete); +} +EXPORT_SYMBOL (mpfs_sys_controller_put); + +static struct platform_device subdevs[] = { + { + .name ="mpfs-rng" , + .id =-1 , + }, + { + .name ="mpfs-generic-service" , + .id =-1 , + } +}; + +static int mpfs_sys_controller_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct mpfs_sys_controller *sys_controller; +int i; + + sys_controller =devm_kzalloc (dev,sizeof (*sys_controller),GFP_KERNEL ); +if (!sys_controller) +return -ENOMEM ; + + sys_controller->client.dev = dev; + sys_controller->client.rx_callback = rx_callback; + sys_controller->client.tx_block =1U ; + + sys_controller->chan =mbox_request_channel (&sys_controller->client,0 ); +if (IS_ERR (sys_controller->chan)) +return dev_err_probe (dev,PTR_ERR (sys_controller->chan), +"Failed to get mbox channel\n" ); + +init_completion (&sys_controller->c); +kref_init (&sys_controller->consumers); + +platform_set_drvdata (pdev, sys_controller); + +dev_info (&pdev->dev,"Registered MPFS system controller\n" ); + +for (i =0 ; i <ARRAY_SIZE (subdevs); i++) { + subdevs[i].dev.parent = dev; +if (platform_device_register (&subdevs[i])) +dev_warn (dev,"Error registering sub device %s\n" , subdevs[i].name); + } + +return 0 ; +} + +static int mpfs_sys_controller_remove (struct platform_device *pdev) +{ +struct mpfs_sys_controller *sys_controller =platform_get_drvdata (pdev); + +mpfs_sys_controller_put (sys_controller); + +return 0 ; +} + +static const struct of_device_id mpfs_sys_controller_of_match[] = { + {.compatible ="microchip,mpfs-sys-controller" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, mpfs_sys_controller_of_match); + +struct mpfs_sys_controller *mpfs_sys_controller_get (struct device *dev) +{ +const struct of_device_id *match; +struct mpfs_sys_controller *sys_controller; +int ret; + +if (!dev->parent) + goto err_no_device; + + match =of_match_node (mpfs_sys_controller_of_match, dev->parent->of_node); +of_node_put (dev->parent->of_node); +if (!match) + goto err_no_device; + + sys_controller =dev_get_drvdata (dev->parent); +if (!sys_controller) + goto err_bad_device; + +if (!kref_get_unless_zero (&sys_controller->consumers)) + goto err_bad_device; + + ret =devm_add_action_or_reset (dev, mpfs_sys_controller_put, sys_controller); +if (ret) +return ERR_PTR (ret); + +return sys_controller; + +err_no_device: +dev_dbg (dev,"Parent device was not an MPFS system controller\n" ); +return ERR_PTR (-ENODEV ); + +err_bad_device: +dev_dbg (dev,"MPFS system controller found but could not register as a sub device\n" ); +return ERR_PTR (-EPROBE_DEFER ); +} +EXPORT_SYMBOL (mpfs_sys_controller_get); + +static struct platform_driver mpfs_sys_controller_driver = { + .driver = { + .name ="mpfs-sys-controller" , + .of_match_table = mpfs_sys_controller_of_match, + }, + .probe = mpfs_sys_controller_probe, + .remove = mpfs_sys_controller_remove, +}; +module_platform_driver (mpfs_sys_controller_driver); + +MODULE_LICENSE ("GPL v2" ); +MODULE_AUTHOR ("Conor Dooley <[email protected]>" ); +MODULE_DESCRIPTION ("MPFS system controller driver" );include/soc/microchip/mpfs.h +2
-2@@ -34,9 +34,9 @@ struct mpfs_mss_response {#if IS_ENABLED (CONFIG_POLARFIRE_SOC_SYS_CTRL ) -int mpfs_blocking_transaction (struct mpfs_sys_controller *mpfs_client,void *msg); +int mpfs_blocking_transaction (struct mpfs_sys_controller *mpfs_client,struct mpfs_mss_msg *msg); -struct mpfs_sys_controller *mpfs_sys_controller_get (struct device_node *mailbox_node); +struct mpfs_sys_controller *mpfs_sys_controller_get (struct device *dev);#endif /* if IS_ENABLED(CONFIG_POLARFIRE_SOC_SYS_CTRL) */
Signature · 1 line
Nicolas Ferre