dt-bindings: Document JZ47xx VPU auxiliary processor
Paul Cercueil
maintainerPATCH v3 1/4 dt-bindings: Document JZ47xx VPU auxiliary processor
Inside the Video Processing Unit (VPU) of the recent JZ47xx SoCs from Ingenic is a second Xburst MIPS CPU very similar to the main core. This document describes the devicetree bindings for this auxiliary processor.
---
Notes:
v2: Update TCSM0 address in example
v3: Change node name to 'video-decoder'
.../bindings/remoteproc/ingenic,vpu.txt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Documentation/devicetree/bindings/remoteproc/ingenic,vpu.txt
Documentation/devicetree/bindings/remoteproc/ingenic,vpu.txt new file +36 -0
@@ -0,0 +1,36 @@ +* Ingenic JZ47xx auxiliary processor + +Inside the Video Processing Unit (VPU) of the recent JZ47xx SoCs from Ingenic +is a second Xburst MIPS CPU very similar to the main core. +This document describes the devicetree bindings for this auxiliary processor. + +Required properties: +- compatible: Should be "ingenic,jz4770-vpu-rproc" +- reg: Must contain the registers location and length for: + * the auxiliary processor, + * the Tightly Coupled Shared Memory 0 (TCSM0), + * the Tightly Coupled Shared Memory 1 (TCSM1), + * the shared SRAM. +- reg-names: Must contain "aux", "tcsm0", "tcsm1", "sram". +- clocks: Clock specifier for the AUX and VPU clocks. +- clock-names: Must contain "aux", "vpu". +- interrupts: Interrupt specifier for the VPU hardware block. + +Example: + +vpu: video-decoder@132a0000 { + compatible = "ingenic,jz4770-vpu-rproc"; + + reg = <0x132a0000 0x20 /* AUX */ + 0x132b0000 0x4000 /* TCSM0 */ + 0x132c0000 0xc000 /* TCSM1 */ + 0x132f0000 0x7000 /* SRAM */ + >; + reg-names = "aux", "tcsm0", "tcsm1", "sram"; + + clocks = <&cgu JZ4770_CLK_AUX>, <&cgu JZ4770_CLK_VPU>; + clock-names = "aux", "vpu"; + + interrupt-parent = <&cpuintc>; + interrupts = <3>; +};
Signature · 1 line
2.24.0
Paul Cercueil
maintainerPATCH v3 2/4 remoteproc: Add device-managed variants of rproc_alloc/rproc_add
Add API functions devm_rproc_alloc() and devm_rproc_add(), which behave like rproc_alloc() and rproc_add() respectively, but register their respective cleanup function to be called on driver detach.
---
Notes:
v3: New patch
drivers/remoteproc/remoteproc_core.c | 67 ++++++++++++++++++++++++++++ include/linux/remoteproc.h | 5 +++ 2 files changed, 72 insertions(+)
drivers/remoteproc/remoteproc_core.c +67 -0
@@ -1933,6 +1933,33 @@ int rproc_add(struct rproc *rproc) }EXPORT_SYMBOL (rproc_add); +static void devm_rproc_remove (void *rproc) +{ +rproc_del (rproc); +} + +/** +* devm_rproc_add() - resource managed rproc_add() +* @dev: the underlying device +* @rproc: the remote processor handle to register +* +* This function performs like rproc_add() but the registered rproc device will +* automatically be removed on driver detach. +* +* Returns 0 on success and an appropriate error code otherwise. +*/ +int devm_rproc_add (struct device *dev,struct rproc *rproc) +{ +int err; + + err =rproc_add (rproc); +if (err) +return err; + +return devm_add_action_or_reset (dev, devm_rproc_remove, rproc); +} +EXPORT_SYMBOL (devm_rproc_add); +/** * rproc_type_release() - release a remote processor instance * @dev: the rproc's device
@@ -2150,6 +2177,46 @@ int rproc_del(struct rproc *rproc) }EXPORT_SYMBOL (rproc_del); +static void devm_rproc_free (struct device *dev,void *res) +{ +rproc_free (*(struct rproc **)res); +} + +/** +* devm_rproc_alloc() - resource managed rproc_alloc() +* @dev: the underlying device +* @name: name of this remote processor +* @ops: platform-specific handlers (mainly start/stop) +* @firmware: name of firmware file to load, can be NULL +* @len: length of private data needed by the rproc driver (in bytes) +* +* This function performs like rproc_alloc() but the acuired rproc device will +* automatically be released on driver detach. +* +* On success the new rproc is returned, and on failure, NULL. +*/ +struct rproc *devm_rproc_alloc (struct device *dev,const char *name, +const struct rproc_ops *ops, +const char *firmware,int len) +{ +struct rproc **ptr, *rproc; + + ptr =devres_alloc (devm_rproc_free,sizeof (*ptr),GFP_KERNEL ); +if (!ptr) +return ERR_PTR (-ENOMEM ); + + rproc =rproc_alloc (dev, name, ops, firmware, len); +if (rproc) { + *ptr = rproc; +devres_add (dev, ptr); + }else { +devres_free (ptr); + } + +return rproc; +} +EXPORT_SYMBOL (devm_rproc_alloc); +/** * rproc_add_subdev() - add a subdevice to a remoteproc * @rproc: rproc handle to add the subdevice to
include/linux/remoteproc.h +5 -0
@@ -595,6 +595,11 @@ int rproc_add(struct rproc *rproc);int rproc_del (struct rproc *rproc);void rproc_free (struct rproc *rproc); +struct rproc *devm_rproc_alloc (struct device *dev,const char *name, +const struct rproc_ops *ops, +const char *firmware,int len); +int devm_rproc_add (struct device *dev,struct rproc *rproc); +void rproc_add_carveout (struct rproc *rproc,struct rproc_mem_entry *mem); struct rproc_mem_entry *
Signature · 1 line
2.24.0
Paul Cercueil
maintainerPATCH v3 3/4 remoteproc: Add prepare/unprepare callbacks
In reply to Paul CercueilThe .prepare() callback is called before the firmware is loaded to memory. This is useful for instance in the case where some setup is required for the memory to be accessible.
---
Notes:
v2: No change
v3: No change
drivers/remoteproc/remoteproc_core.c | 16 +++++++++++++++- include/linux/remoteproc.h | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-)
drivers/remoteproc/remoteproc_core.c +15 -1
@@ -1300,11 +1300,19 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw)struct device *dev = &rproc->dev;int ret; +if (rproc->ops->prepare) { + ret = rproc->ops->prepare (rproc); +if (ret) { +dev_err (dev,"Failed to prepare rproc: %d\n" , ret); +return ret; + } + } +/* load the ELF segments to memory */ ret =rproc_load_segments (rproc, fw);if (ret) {dev_err (dev,"Failed to load program segments: %d\n" , ret); -return ret; + goto unprepare_rproc; }/*
@@ -1355,6 +1363,9 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw)rproc_unprepare_subdevices (rproc); reset_table_ptr: rproc->table_ptr = rproc->cached_table; +unprepare_rproc: +if (rproc->ops->unprepare) + rproc->ops->unprepare (rproc);return ret; }
@@ -1484,6 +1495,9 @@ static int rproc_stop(struct rproc *rproc, bool crashed) rproc->state =RPROC_OFFLINE ; +if (rproc->ops->unprepare) + rproc->ops->unprepare (rproc); +dev_info (dev,"stopped remote processor %s\n" , rproc->name);return 0 ;
include/linux/remoteproc.h +4 -0
@@ -355,6 +355,8 @@ enum rsc_handling_status {/** * struct rproc_ops - platform-specific device handlers +* @prepare: prepare the device for power up (before the firmware is loaded) +* @unprepare: unprepare the device after it is stopped * @start: power on the device and boot it * @stop: power off the device * @kick: kick a virtqueue (virtqueue id given as a parameter)
@@ -371,6 +373,8 @@ enum rsc_handling_status {* @get_boot_addr: get boot address to entry point specified in firmware */ struct rproc_ops { +int (*prepare)(struct rproc *rproc); +void (*unprepare)(struct rproc *rproc);int (*start)(struct rproc *rproc);int (*stop)(struct rproc *rproc);void (*kick)(struct rproc *rproc,int vqid);
Signature · 1 line
2.24.0
Paul Cercueil
maintainerPATCH v3 4/4 remoteproc: ingenic: Added remoteproc driver
In reply to Paul CercueilThis driver is used to boot, communicate with and load firmwares to the MIPS co-processor found in the VPU hardware of the JZ47xx SoCs from Ingenic.
---
Notes:
v2: Remove exception for always-mapped memories
v3: - Use clk_bulk API
- Move device-managed code to its own patch [3/4]
- Move devicetree table right above ingenic_rproc_driver
- Removed #ifdef CONFIG_OF around devicetree table
- Removed .owner = THIS_MODULE in ingenic_rproc_driver
- Removed useless platform_set_drvdata()
drivers/remoteproc/Kconfig | 8 + drivers/remoteproc/Makefile | 1 + drivers/remoteproc/ingenic_rproc.c | 242 +++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 drivers/remoteproc/ingenic_rproc.c
drivers/remoteproc/Kconfig +8 -0
@@ -214,6 +214,14 @@ config STM32_RPROC This can be either built-in or a loadable module. +config INGENIC_RPROC + tristate "Ingenic JZ47xx VPU remoteproc support" + depends on MIPS || COMPILE_TEST + help + Say y or m here to support the VPU in the JZ47xx SoCs from Ingenic. + This can be either built-in or a loadable module. + If unsure say N. + endif # REMOTEPROC endmenu
drivers/remoteproc/Makefile +1 -0
@@ -10,6 +10,7 @@ remoteproc-y += remoteproc_sysfs.o remoteproc-y += remoteproc_virtio.o remoteproc-y += remoteproc_elf_loader.o obj-$(CONFIG_IMX_REMOTEPROC) += imx_rproc.o +obj-$(CONFIG_INGENIC_RPROC) += ingenic_rproc.o obj-$(CONFIG_OMAP_REMOTEPROC) += omap_remoteproc.o obj-$(CONFIG_WKUP_M3_RPROC) += wkup_m3_rproc.o obj-$(CONFIG_DA8XX_REMOTEPROC) += da8xx_remoteproc.o
drivers/remoteproc/ingenic_rproc.c new file +242 -0
242 lines not on this page · raw message
Signature · 1 line
2.24.0
Re: [PATCH v3 4/4] remoteproc: ingenic: Added remoteproc driver
Hi Paul,
Quoted 27 lines · Paul Cercueil
This driver is used to boot, communicate with and load firmwares to the MIPS co-processor found in the VPU hardware of the JZ47xx SoCs from Ingenic.
Signed-off-by Paul Cercueil <[email protected]>---
Notes:
v2: Remove exception for always-mapped memories
v3: - Useclk_bulkAPI
- Move device-managed code to its own patch [3/4]
- Move devicetree table right aboveingenic_rproc_driver
- Removed #ifdefCONFIG_OFaround devicetree table
- Removed .owner =THIS_MODULEiningenic_rproc_driver
- Removed uselessplatform_set_drvdata()drivers/remoteproc/Kconfig | 8 + drivers/remoteproc/Makefile | 1 + drivers/remoteproc/ingenic_rproc.c | 242 +++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 drivers/remoteproc/ingenic_rproc.cdrivers/remoteproc/Kconfig +0
-0
drivers/remoteproc/Kconfig config STM32_RPROC · line 217
Quoted 4 lines
drivers/remoteproc/Kconfig +1
-0@@ -214,6 +214,14 @@ config STM32_RPROC This can be either built-in or a loadable module. +config INGENIC_RPROC
Are you sure you don't want to make this something like INGENIC_RPROC_JZ47XX_VPU so that future remote proc system from Ingenic can be added easily?
Quoted 15 lines
drivers/remoteproc/Kconfig +7
-0+ tristate "Ingenic JZ47xx VPU remoteproc support" + depends on MIPS || COMPILE_TEST + help + Say y or m here to support the VPU in the JZ47xx SoCs from Ingenic. + This can be either built-in or a loadable module. + If unsure say N. + endif # REMOTEPROC endmenudrivers/remoteproc/Makefile +0
-0
drivers/remoteproc/Makefile remoteproc-y += remoteproc_sysfs.o · line 13
Quoted 4 lines
drivers/remoteproc/Makefile +1
-0@@ -10,6 +10,7 @@ remoteproc-y += remoteproc_sysfs.o remoteproc-y += remoteproc_virtio.o remoteproc-y += remoteproc_elf_loader.o obj-$(CONFIG_IMX_REMOTEPROC) += imx_rproc.o +obj-$(CONFIG_INGENIC_RPROC) += ingenic_rproc.a
This comes out as one tab to many on my side.
Quoted 53 lines
drivers/remoteproc/Makefile +0
-0obj-$(CONFIG_OMAP_REMOTEPROC) += omap_remoteproc.o obj-$(CONFIG_WKUP_M3_RPROC) += wkup_m3_rproc.o obj-$(CONFIG_DA8XX_REMOTEPROC) += da8xx_remoteproc.odrivers/remoteproc/ingenic_rproc.c new file +44
-0@@ -0,0 +1,242 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Ingenic JZ47xx remoteproc driver +* Copyright 2019, Paul Cercueil <[email protected]> +*/ + +#include <linux/bitops.h> +#include <linux/clk.h> +#include <linux/err.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/remoteproc.h> + +#include "remoteproc_internal.h" + +#define REG_AUX_CTRL 0x0 +#define REG_AUX_MSG_ACK 0x10 +#define REG_AUX_MSG 0x14 +#define REG_CORE_MSG_ACK 0x18 +#define REG_CORE_MSG 0x1C + +#define AUX_CTRL_SLEEP BIT(31) +#define AUX_CTRL_MSG_IRQ_EN BIT(3) +#define AUX_CTRL_NMI_RESETS BIT(2) +#define AUX_CTRL_NMI BIT(1) +#define AUX_CTRL_SW_RESET BIT(0) + +struct vpu_mem_map { +const char *name; +unsigned int da; +}; + +struct vpu_mem_info { +const struct vpu_mem_map *map; +unsigned long len; +void __iomem *base; +}; + +static const struct vpu_mem_map vpu_mem_map[] = { + {"tcsm0" ,0x132b0000 }, + {"tcsm1" ,0xf4000000 }, + {"sram" ,0x132f0000 },
drivers/remoteproc/ingenic_rproc.c line 54
Quoted 10 lines
drivers/remoteproc/ingenic_rproc.c new file +10
-0+}; + +/* Device data */ +struct vpu { +int irq; +struct clk_bulk_data clks[2 ]; +void __iomem *aux_base; +struct vpu_mem_info mem_info[ARRAY_SIZE (vpu_mem_map)]; +struct device *dev; +};
Documentation of structure fields is always appreciated but it is up to Bjorn to decide on this one.
Quoted 21 lines
drivers/remoteproc/ingenic_rproc.c new file +21
-0+ +static int ingenic_rproc_prepare (struct rproc *rproc) +{ +struct vpu *vpu = rproc->priv; +int ret; + +/* The clocks must be enabled for the firmware to be loaded in TCSM */ + ret =clk_bulk_prepare_enable (ARRAY_SIZE (vpu->clks), vpu->clks); +if (ret) +dev_err (vpu->dev,"Unable to start clocks: %d" , ret); + +return ret; +} + +static void ingenic_rproc_unprepare (struct rproc *rproc) +{ +struct vpu *vpu = rproc->priv; + +clk_bulk_disable_unprepare (ARRAY_SIZE (vpu->clks), vpu->clks); +} +
drivers/remoteproc/ingenic_rproc.c line 85
Quoted 10 lines
drivers/remoteproc/ingenic_rproc.c new file +10
-0+static int ingenic_rproc_start (struct rproc *rproc) +{ +struct vpu *vpu = rproc->priv; +u32 ctrl; + +enable_irq (vpu->irq); + +/* Reset the AUX and enable message IRQ */ + ctrl =AUX_CTRL_NMI_RESETS |AUX_CTRL_NMI |AUX_CTRL_MSG_IRQ_EN ; +writel (ctrl, vpu->aux_base +REG_AUX_CTRL );
Out of curiosity, there is no power domain associated with this co-processor? Clocks are all you need?
drivers/remoteproc/ingenic_rproc.c line 97
Quoted 12 lines
drivers/remoteproc/ingenic_rproc.c new file +12
-0+ +return 0 ; +} + +static int ingenic_rproc_stop (struct rproc *rproc) +{ +struct vpu *vpu = rproc->priv; + +/* Keep AUX in reset mode */ +writel (AUX_CTRL_SW_RESET , vpu->aux_base +REG_AUX_CTRL ); + +disable_irq_nosync (vpu->irq);
Also out of curiosity, why the need for _nosync()?
Quoted 135 lines
drivers/remoteproc/ingenic_rproc.c new file +135
-0+ +return 0 ; +} + +static void ingenic_rproc_kick (struct rproc *rproc,int vqid) +{ +struct vpu *vpu = rproc->priv; + +writel (vqid, vpu->aux_base +REG_CORE_MSG ); +} + +static void *ingenic_rproc_da_to_va (struct rproc *rproc,u64 da,int len) +{ +struct vpu *vpu = rproc->priv; +void __iomem *va =NULL ; +unsigned int i; + +if (len <=0 ) +return NULL ; + +for (i =0 ; i <ARRAY_SIZE (vpu_mem_map); i++) { +const struct vpu_mem_info *info = &vpu->mem_info[i]; +const struct vpu_mem_map *map = info->map; + +if (da >= map->da && (da + len) < (map->da + info->len)) { + va = info->base + (da - map->da); +break ; + } + } + +return (__force void *)va; +} + +static struct rproc_ops ingenic_rproc_ops = { + .prepare = ingenic_rproc_prepare, + .unprepare = ingenic_rproc_unprepare, + .start = ingenic_rproc_start, + .stop = ingenic_rproc_stop, + .kick = ingenic_rproc_kick, + .da_to_va = ingenic_rproc_da_to_va, +}; + +static irqreturn_t vpu_interrupt (int irq,void *data) +{ +struct rproc *rproc = data; +struct vpu *vpu = rproc->priv; +u32 vring; + + vring =readl (vpu->aux_base +REG_AUX_MSG ); + +/* Ack the interrupt */ +writel (0 , vpu->aux_base +REG_AUX_MSG_ACK ); + +return rproc_vq_interrupt (rproc, vring); +} + +static int ingenic_rproc_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct resource *mem; +struct rproc *rproc; +struct vpu *vpu; +unsigned int i; +int ret; + + rproc =devm_rproc_alloc (dev,"ingenic-vpu" , + &ingenic_rproc_ops,NULL ,sizeof (*vpu)); +if (!rproc) +return -ENOMEM ; + + vpu = rproc->priv; + vpu->dev = &pdev->dev; + + mem =platform_get_resource_byname (pdev,IORESOURCE_MEM ,"aux" ); + vpu->aux_base =devm_ioremap_resource (dev, mem); +if (IS_ERR (vpu->aux_base)) { +dev_err (dev,"Failed to ioremap" ); +return PTR_ERR (vpu->aux_base); + } + +for (i =0 ; i <ARRAY_SIZE (vpu_mem_map); i++) { + mem =platform_get_resource_byname (pdev,IORESOURCE_MEM , + vpu_mem_map[i].name); + + vpu->mem_info[i].base =devm_ioremap_resource (dev, mem); +if (IS_ERR (vpu->mem_info[i].base)) { + ret =PTR_ERR (vpu->mem_info[i].base); +dev_err (dev,"Failed to ioremap" ); +return ret; + } + + vpu->mem_info[i].len =resource_size (mem); + vpu->mem_info[i].map = &vpu_mem_map[i]; + } + + vpu->clks[0 ].id ="vpu" ; + vpu->clks[1 ].id ="aux" ; + + ret =devm_clk_bulk_get (dev,ARRAY_SIZE (vpu->clks), vpu->clks); +if (ret) { +dev_err (dev,"Failed to get clocks" ); +return ret; + } + + vpu->irq =platform_get_irq (pdev,0 ); +if (vpu->irq <0 ) { +dev_err (dev,"Failed to get platform IRQ" ); +return vpu->irq; + } + + ret =devm_request_irq (dev, vpu->irq, vpu_interrupt,0 ,"VPU" , rproc); +if (ret <0 ) { +dev_err (dev,"Failed to request IRQ" ); +return ret; + } + +disable_irq_nosync (vpu->irq); + + ret =devm_rproc_add (dev, rproc); +if (ret) { +dev_err (dev,"Failed to register remote processor" ); +return ret; + } + +return 0 ; +} + +static const struct of_device_id ingenic_rproc_of_matches[] = { + { .compatible ="ingenic,jz4770-vpu-rproc" , }, + {} +}; +MODULE_DEVICE_TABLE (of, ingenic_rproc_of_matches); + +static struct platform_driver ingenic_rproc_driver = { + .probe = ingenic_rproc_probe,
drivers/remoteproc/ingenic_rproc.c line 242
Quoted 10 lines
drivers/remoteproc/ingenic_rproc.c new file +10
-0+ .driver = { + .name = "ingenic-vpu", + .of_match_table = of_match_ptr(ingenic_rproc_of_matches), + }, +}; +module_platform_driver (ingenic_rproc_driver); + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Paul Cercueil <[email protected]>" ); +MODULE_DESCRIPTION ("Ingenic JZ47xx Remote Processor control driver" );
Nice, clean and simple driver. With the above and after rolling in Julia's patch:
Quoted 3 lines
Signature · 1 line
2.24.0
Paul Cercueil
maintainerRe: [PATCH v3 4/4] remoteproc: ingenic: Added remoteproc driver
Hi Mathieu,
Quoted 33 lines · Mathieu Poirier
Hi Paul,
Quoted 30 lines · Paul Cercueil
This driver is used to boot, communicate with and load firmwares to
the
MIPS co-processor found in the VPU hardware of the JZ47xx SoCs from Ingenic.Signed-off-by Paul Cercueil <[email protected]>---
Notes:
v2: Remove exception for always-mapped memories
v3: - Useclk_bulkAPI
- Move device-managed code to its own patch [3/4]
- Move devicetree table right aboveingenic_rproc_driver
- Removed #ifdefCONFIG_OFaround devicetree table
- Removed .owner =THIS_MODULEiningenic_rproc_driver
- Removed uselessplatform_set_drvdata()drivers/remoteproc/Kconfig | 8 + drivers/remoteproc/Makefile | 1 + drivers/remoteproc/ingenic_rproc.c | 242 +++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+)create mode 100644
drivers/remoteproc/ingenic_rproc.cdiff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig index
94afdde4bc9f..f7d4b183d152100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -214,6 +214,14 @@ configSTM32_RPROC
Quoted 7 lines
Quoted 3 lines
This can be either built-in or a loadable module.
+config
INGENIC_RPROCAre you sure you don't want to make this something like
INGENIC_RPROC_JZ47XX_VPUso that future remote proc system from Ingenic can be added easily?
Ingenic SoCs aren't named JZ47xx anymore; I'll name the symbol INGENIC_VPU_RPROC then.
Quoted 89 lines
Quoted 10 lines
+ tristate "Ingenic JZ47xx VPU remoteproc support"
+ depends on MIPS ||COMPILE_TEST
+ help
+ Say y or m here to support the VPU in the JZ47xx SoCs from
Ingenic.
+ This can be either built-in or a loadable module.
+ If unsure say N.
+
endif # REMOTEPROCQuoted 11 lines
endmenu
diff --git a/drivers/remoteproc/Makefile
b/drivers/remoteproc/Makefile
index00f09e658cb3..6eb0137abbc7100644
--- a/drivers/remoteproc/Makefile
+++ b/drivers/remoteproc/Makefile
@@ -10,6 +10,7 @@ remoteproc-y += remoteproc_sysfs.o
remoteproc-y += remoteproc_virtio.o
remoteproc-y += remoteproc_elf_loader.o
obj-$(CONFIG_IMX_REMOTEPROC) += imx_rproc.o
+obj-$(CONFIG_INGENIC_RPROC) += ingenic_rproc.aThis comes out as one tab to many on my side.
Quoted 56 lines
obj-$(CONFIG_OMAP_REMOTEPROC) += omap_remoteproc.o
obj-$(CONFIG_WKUP_M3_RPROC) += wkup_m3_rproc.o
obj-$(CONFIG_DA8XX_REMOTEPROC) += da8xx_remoteproc.o
diff --gita/drivers/remoteproc/ingenic_rproc.cb/drivers/remoteproc/ingenic_rproc.c
new file mode 100644
index 000000000000..5a7c7d8d9a90
---/dev/null
+++b/drivers/remoteproc/ingenic_rproc.c
@@ -0,0 +1,242 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Ingenic JZ47xx remoteproc driver
+ * Copyright 2019, Paul Cercueil <[email protected]>
+ */
+
+#include <linux/bitops.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/remoteproc.h>
+
+#include "remoteproc_internal.h"
+
+#defineREG_AUX_CTRL0x0
+#defineREG_AUX_MSG_ACK0x10
+#defineREG_AUX_MSG0x14
+#defineREG_CORE_MSG_ACK0x18
+#defineREG_CORE_MSG0x1C
+
+#defineAUX_CTRL_SLEEPBIT(31)
+#defineAUX_CTRL_MSG_IRQ_ENBIT(3)
+#defineAUX_CTRL_NMI_RESETSBIT(2)
+#defineAUX_CTRL_NMIBIT(1)
+#defineAUX_CTRL_SW_RESETBIT(0)
+
+structvpu_mem_map{
+ const char *name;
+ unsigned int da;
+};
+
+structvpu_mem_info{
+ const structvpu_mem_map*map;
+ unsigned long len;
+ void__iomem*base;
+};
+
+static const structvpu_mem_mapvpu_mem_map[] = {
+ { "tcsm0",0x132b0000},
+ { "tcsm1",0xf4000000},
+ { "sram",0x132f0000},
+};
+Quoted 8 lines
+/* Device data */
+struct vpu {
+ int irq;
+ structclk_bulk_dataclks[2];
+ void__iomem*aux_base;
+ structvpu_mem_infomem_info[ARRAY_SIZE(vpu_mem_map)];
+ struct device *dev;
+};
Quoted 2 lines
Documentation of structure fields is always appreciated but it is up to Bjorn to decide on this one.
It's a private structure within a driver, does it matter that much? Besides, it's pretty much self-explanatory.
Quoted 33 lines
Quoted 24 lines
+
+static intingenic_rproc_prepare(struct rproc *rproc)+{
+ struct vpu *vpu =rproc->priv;
+ int ret;
+
+ /* The clocks must be enabled for the firmware to be loaded in
TCSM */
+ ret =clk_bulk_prepare_enable(ARRAY_SIZE(vpu->clks), vpu->clks);
+ if (ret)
+dev_err(vpu->dev, "Unable to start clocks: %d", ret);
+
+ return ret;
+}
+
+static voidingenic_rproc_unprepare(struct rproc *rproc)+{
+ struct vpu *vpu =rproc->priv;
+
+clk_bulk_disable_unprepare(ARRAY_SIZE(vpu->clks), vpu->clks);
+}
+
+static intingenic_rproc_start(struct rproc *rproc)+{Quoted 8 lines
+ struct vpu *vpu =
rproc->priv;
+ u32 ctrl;
+
+enable_irq(vpu->irq);
+
+ /* Reset the AUX and enable message IRQ */
+ ctrl =AUX_CTRL_NMI_RESETS|AUX_CTRL_NMI|AUX_CTRL_MSG_IRQ_EN;
+writel(ctrl, vpu->aux_base + REG_AUX_CTRL);
Quoted 2 lines
Out of curiosity, there is no power domain associated with this co-processor? Clocks are all you need?
That's correct.
Quoted 13 lines
Quoted 4 lines
+
+ return 0;
+}
+Quoted 8 lines
+static int
ingenic_rproc_stop(struct rproc *rproc)+{
+ struct vpu *vpu =rproc->priv;
+
+ /* Keep AUX in reset mode */
+writel(AUX_CTRL_SW_RESET, vpu->aux_base + REG_AUX_CTRL);
+
+disable_irq_nosync(vpu->irq);
Quoted 1 line
Also out of curiosity, why the need for
_nosync()?
It probably doesn't need it. I'll remove it.
Quoted 149 lines
Quoted 140 lines
+
+ return 0;
+}
+
+static voidingenic_rproc_kick(struct rproc *rproc, int vqid)+{
+ struct vpu *vpu =rproc->priv;
+
+writel(vqid, vpu->aux_base + REG_CORE_MSG);
+}
+
+static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da,
int len)
+{
+ struct vpu *vpu =rproc->priv;
+ void__iomem*va = NULL;
+ unsigned int i;
+
+ if (len <= 0)
+ return NULL;
+
+ for (i = 0; i <ARRAY_SIZE(vpu_mem_map); i++) {
+ const structvpu_mem_info*info = &vpu->mem_info[i];
+ const structvpu_mem_map*map =info->map;
+
+ if (da >=map->da&& (da + len) < (map->da+info->len)) {
+ va =info->base+ (da -map->da);
+ break;
+ }
+ }
+
+ return (__forcevoid *)va;
+}
+
+static structrproc_opsingenic_rproc_ops= {
+ .prepare =ingenic_rproc_prepare,
+ .unprepare =ingenic_rproc_unprepare,
+ .start =ingenic_rproc_start,
+ .stop =ingenic_rproc_stop,
+ .kick =ingenic_rproc_kick,
+ .da_to_va =ingenic_rproc_da_to_va,
+};
+
+staticirqreturn_tvpu_interrupt(int irq, void *data)+{
+ struct rproc *rproc = data;
+ struct vpu *vpu =rproc->priv;
+ u32 vring;
+
+ vring =readl(vpu->aux_base + REG_AUX_MSG);
+
+ /* Ack the interrupt */
+writel(0, vpu->aux_base + REG_AUX_MSG_ACK);
+
+ returnrproc_vq_interrupt(rproc, vring);
+}
+
+static intingenic_rproc_probe(struct platform_device *pdev)+{
+ struct device *dev =&pdev->dev;
+ struct resource *mem;
+ struct rproc *rproc;
+ struct vpu *vpu;
+ unsigned int i;
+ int ret;
+
+ rproc = devm_rproc_alloc(dev, "ingenic-vpu",
+&ingenic_rproc_ops, NULL,sizeof(*vpu));
+ if (!rproc)
+ return-ENOMEM;
+
+ vpu =rproc->priv;
+vpu->dev=&pdev->dev;
+
+ mem =platform_get_resource_byname(pdev, IORESOURCE_MEM, "aux");
+vpu->aux_base=devm_ioremap_resource(dev, mem);
+ if (IS_ERR(vpu->aux_base)) {
+dev_err(dev, "Failed to ioremap");
+ returnPTR_ERR(vpu->aux_base);
+ }
+
+ for (i = 0; i <ARRAY_SIZE(vpu_mem_map); i++) {
+ mem = platform_get_resource_byname(pdev,IORESOURCE_MEM,
+ vpu_mem_map[i].name);
+
+ vpu->mem_info[i].base =devm_ioremap_resource(dev, mem);
+ if (IS_ERR(vpu->mem_info[i].base)) {
+ ret =PTR_ERR(vpu->mem_info[i].base);
+dev_err(dev, "Failed to ioremap");
+ return ret;
+ }
+
+ vpu->mem_info[i].len =resource_size(mem);
+ vpu->mem_info[i].map = &vpu_mem_map[i];
+ }
+
+ vpu->clks[0].id = "vpu";
+ vpu->clks[1].id = "aux";
+
+ ret =devm_clk_bulk_get(dev, ARRAY_SIZE(vpu->clks), vpu->clks);
+ if (ret) {
+dev_err(dev, "Failed to get clocks");
+ return ret;
+ }
+
+vpu->irq=platform_get_irq(pdev, 0);
+ if (vpu->irq< 0) {
+dev_err(dev, "Failed to get platform IRQ");
+ returnvpu->irq;
+ }
+
+ ret = devm_request_irq(dev,vpu->irq,vpu_interrupt, 0, "VPU",
rproc);
+ if (ret < 0) {
+dev_err(dev, "Failed to request IRQ");
+ return ret;
+ }
+
+disable_irq_nosync(vpu->irq);
+
+ ret =devm_rproc_add(dev, rproc);
+ if (ret) {
+dev_err(dev, "Failed to register remote processor");
+ return ret;
+ }
+
+ return 0;
+}
+
+static const structof_device_idingenic_rproc_of_matches[] = {
+ { .compatible = "ingenic,jz4770-vpu-rproc", },
+ {}
+};
+MODULE_DEVICE_TABLE(of,ingenic_rproc_of_matches);
+
+static structplatform_driveringenic_rproc_driver= {
+ .probe =ingenic_rproc_probe,
+ .driver = {
+ .name = "ingenic-vpu",
+ .of_match_table =of_match_ptr(ingenic_rproc_of_matches),Quoted 8 lines
+ },
+};
+module_platform_driver(ingenic_rproc_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Paul Cercueil <[email protected]>"); +MODULE_DESCRIPTION("Ingenic JZ47xx Remote Processor control
driver");
Quoted 4 lines
Nice, clean and simple driver. With the above and after rolling in Julia's patch:
Acked-by Mathieu Poirier <[email protected]>
Thanks!
Cheers,
-Paul
Mathieu Poirier
maintainerRe: [PATCH v3 4/4] remoteproc: ingenic: Added remoteproc driver
Quoted 140 lines · Paul Cercueil
Hi Mathieu,
Quoted 33 lines · Mathieu Poirier
Hi Paul,
Quoted 30 lines · Paul Cercueil
This driver is used to boot, communicate with and load firmwares to
the
MIPS co-processor found in the VPU hardware of the JZ47xx SoCs from Ingenic.Signed-off-by Paul Cercueil <[email protected]>---
Notes:
v2: Remove exception for always-mapped memories
v3: - Useclk_bulkAPI
- Move device-managed code to its own patch [3/4]
- Move devicetree table right aboveingenic_rproc_driver
- Removed #ifdefCONFIG_OFaround devicetree table
- Removed .owner =THIS_MODULEiningenic_rproc_driver
- Removed uselessplatform_set_drvdata()drivers/remoteproc/Kconfig | 8 + drivers/remoteproc/Makefile | 1 + drivers/remoteproc/ingenic_rproc.c | 242 +++++++++++++++++++++++++++++ 3 files changed, 251 insertions(+)create mode 100644
drivers/remoteproc/ingenic_rproc.cdiff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig index
94afdde4bc9f..f7d4b183d152100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -214,6 +214,14 @@ configSTM32_RPROCQuoted 8 lines
Quoted 3 lines
This can be either built-in or a loadable module.
+config
INGENIC_RPROCAre you sure you don't want to make this something like
INGENIC_RPROC_JZ47XX_VPUso that future remote proc system from Ingenic can be
added easily?Ingenic SoCs aren't named JZ47xx anymore; I'll name the symbol
INGENIC_VPU_RPROCthen.Quoted 89 lines
Quoted 17 lines
+ tristate "Ingenic JZ47xx VPU remoteproc support" + depends on MIPS || COMPILE_TEST + help+ Say y or m here to support the VPU in the JZ47xx SoCs from
Ingenic.
+ This can be either built-in or a loadable module.
+ If unsure say N.
+
endif # REMOTEPROCendmenu
diff --git a/drivers/remoteproc/Makefile
b/drivers/remoteproc/Makefile
index00f09e658cb3..6eb0137abbc7100644
--- a/drivers/remoteproc/Makefile
+++ b/drivers/remoteproc/Makefile
@@ -10,6 +10,7 @@ remoteproc-y += remoteproc_sysfs.oQuoted 4 lines
remoteproc-y += remoteproc_virtio.o remoteproc-y += remoteproc_elf_loader.o obj-$(CONFIG_IMX_REMOTEPROC) += imx_rproc.o+obj-$(CONFIG_INGENIC_RPROC) += ingenic_rproc.a
This comes out as one tab to many on my side.
Quoted 64 lines
obj-$(CONFIG_OMAP_REMOTEPROC) += omap_remoteproc.o obj-$(CONFIG_WKUP_M3_RPROC) += wkup_m3_rproc.o obj-$(CONFIG_DA8XX_REMOTEPROC) += da8xx_remoteproc.odiff --git
a/drivers/remoteproc/ingenic_rproc.cb/drivers/remoteproc/ingenic_rproc.c
new file mode 100644
index 000000000000..5a7c7d8d9a90
---/dev/null
+++b/drivers/remoteproc/ingenic_rproc.c
@@ -0,0 +1,242 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Ingenic JZ47xx remoteproc driver
+ * Copyright 2019, Paul Cercueil <[email protected]>
+ */
+
+#include <linux/bitops.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/remoteproc.h>
+
+#include "remoteproc_internal.h"
++#define REG_AUX_CTRL 0x0 +#define REG_AUX_MSG_ACK 0x10 +#define REG_AUX_MSG 0x14 +#define REG_CORE_MSG_ACK 0x18 +#define REG_CORE_MSG 0x1C + +#define AUX_CTRL_SLEEP BIT(31) +#define AUX_CTRL_MSG_IRQ_EN BIT(3) +#define AUX_CTRL_NMI_RESETS BIT(2) +#define AUX_CTRL_NMI BIT(1) +#define AUX_CTRL_SW_RESET BIT(0) + +struct vpu_mem_map { + const char *name; + unsigned int da; +}; + +struct vpu_mem_info { + const struct vpu_mem_map *map; + unsigned long len; + void __iomem *base; +}; + +static const struct vpu_mem_map vpu_mem_map[] = { + { "tcsm0", 0x132b0000 }, + { "tcsm1", 0xf4000000 }, + { "sram", 0x132f0000 }, +}; + +/* Device data */ +struct vpu { + int irq; + struct clk_bulk_data clks[2]; + void __iomem *aux_base; + struct vpu_mem_info mem_info[ARRAY_SIZE(vpu_mem_map)]; + struct device *dev;+};
Quoted 6 lines
Quoted 3 lines
Documentation of structure fields is always appreciated but it is up to Bjorn to
decide on this one.It's a private structure within a driver, does it matter that much? Besides, it's pretty much self-explanatory.
It is a matter of time before people add complexity to the drivers and more field in the structures. If documentation is already present then new fields get documented and things are easier to understand.
Quoted 217 lines
Quoted 34 lines
Quoted 30 lines
+
+static intingenic_rproc_prepare(struct rproc *rproc)+{
+ struct vpu *vpu =rproc->priv;
+ int ret;
+
+ /* The clocks must be enabled for the firmware to be loaded in
TCSM */
+ ret =clk_bulk_prepare_enable(ARRAY_SIZE(vpu->clks), vpu->clks);
+ if (ret)
+dev_err(vpu->dev, "Unable to start clocks: %d", ret);
+
+ return ret;
+}
+
+static voidingenic_rproc_unprepare(struct rproc *rproc)+{
+ struct vpu *vpu =rproc->priv;
+
+clk_bulk_disable_unprepare(ARRAY_SIZE(vpu->clks), vpu->clks);
+}
+
+static intingenic_rproc_start(struct rproc *rproc)+{
+ struct vpu *vpu =rproc->priv;
+ u32 ctrl;
+
+enable_irq(vpu->irq);
+Quoted 3 lines
+ /* Reset the AUX and enable message IRQ */ + ctrl = AUX_CTRL_NMI_RESETS | AUX_CTRL_NMI | AUX_CTRL_MSG_IRQ_EN; + writel(ctrl, vpu->aux_base + REG_AUX_CTRL);Quoted 2 lines
Out of curiosity, there is no power domain associated with this co-processor? Clocks are all you need?
That's correct.
Quoted 13 lines
Quoted 4 lines
+
+ return 0;
+}
+Quoted 8 lines
+static int
ingenic_rproc_stop(struct rproc *rproc)+{
+ struct vpu *vpu =rproc->priv;
+
+ /* Keep AUX in reset mode */
+writel(AUX_CTRL_SW_RESET, vpu->aux_base + REG_AUX_CTRL);
+
+disable_irq_nosync(vpu->irq);Quoted 1 line
Also out of curiosity, why the need for
_nosync()?It probably doesn't need it. I'll remove it.
Quoted 149 lines
Quoted 140 lines
+
+ return 0;
+}
+
+static voidingenic_rproc_kick(struct rproc *rproc, int vqid)+{
+ struct vpu *vpu =rproc->priv;
+
+writel(vqid, vpu->aux_base + REG_CORE_MSG);
+}
+
+static void *ingenic_rproc_da_to_va(struct rproc *rproc, u64 da,
int len)
+{+ struct vpu *vpu = rproc->priv; + void __iomem *va = NULL; + unsigned int i; + + if (len <= 0) + return NULL; + + for (i = 0; i < ARRAY_SIZE(vpu_mem_map); i++) { + const struct vpu_mem_info *info = &vpu->mem_info[i]; + const struct vpu_mem_map *map = info->map; + + if (da >= map->da && (da + len) < (map->da + info->len)) { + va = info->base + (da - map->da); + break; + } + } + + return (__force void *)va; +} + +static struct rproc_ops ingenic_rproc_ops = { + .prepare = ingenic_rproc_prepare, + .unprepare = ingenic_rproc_unprepare, + .start = ingenic_rproc_start, + .stop = ingenic_rproc_stop, + .kick = ingenic_rproc_kick, + .da_to_va = ingenic_rproc_da_to_va, +}; + +static irqreturn_t vpu_interrupt(int irq, void *data) +{ + struct rproc *rproc = data; + struct vpu *vpu = rproc->priv; + u32 vring; + + vring = readl(vpu->aux_base + REG_AUX_MSG); + + /* Ack the interrupt */ + writel(0, vpu->aux_base + REG_AUX_MSG_ACK); + + return rproc_vq_interrupt(rproc, vring); +} + +static int ingenic_rproc_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct resource *mem; + struct rproc *rproc; + struct vpu *vpu; + unsigned int i; + int ret; + + rproc = devm_rproc_alloc(dev, "ingenic-vpu", + &ingenic_rproc_ops, NULL, sizeof(*vpu)); + if (!rproc) + return -ENOMEM; + + vpu = rproc->priv; + vpu->dev = &pdev->dev; + + mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "aux"); + vpu->aux_base = devm_ioremap_resource(dev, mem); + if (IS_ERR(vpu->aux_base)) { + dev_err(dev, "Failed to ioremap"); + return PTR_ERR(vpu->aux_base); + } + + for (i = 0; i < ARRAY_SIZE(vpu_mem_map); i++) { + mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, + vpu_mem_map[i].name); + + vpu->mem_info[i].base = devm_ioremap_resource(dev, mem); + if (IS_ERR(vpu->mem_info[i].base)) { + ret = PTR_ERR(vpu->mem_info[i].base); + dev_err(dev, "Failed to ioremap"); + return ret;+ }
+
+ vpu->mem_info[i].len =resource_size(mem);
+ vpu->mem_info[i].map = &vpu_mem_map[i];
+ }
+
+ vpu->clks[0].id = "vpu";
+ vpu->clks[1].id = "aux";
+
+ ret =devm_clk_bulk_get(dev, ARRAY_SIZE(vpu->clks), vpu->clks);
+ if (ret) {
+dev_err(dev, "Failed to get clocks");
+ return ret;
+ }
+
+vpu->irq=platform_get_irq(pdev, 0);
+ if (vpu->irq< 0) {
+dev_err(dev, "Failed to get platform IRQ");
+ returnvpu->irq;
+ }
+
+ ret = devm_request_irq(dev,vpu->irq,vpu_interrupt, 0, "VPU",
rproc);
+ if (ret < 0) {
+dev_err(dev, "Failed to request IRQ");
+ return ret;
+ }
+
+disable_irq_nosync(vpu->irq);
+
+ ret =devm_rproc_add(dev, rproc);
+ if (ret) {
+dev_err(dev, "Failed to register remote processor");
+ return ret;
+ }
+
+ return 0;
+}
+
+static const structof_device_idingenic_rproc_of_matches[] = {
+ { .compatible = "ingenic,jz4770-vpu-rproc", },
+ {}
+};
+MODULE_DEVICE_TABLE(of,ingenic_rproc_of_matches);
+
+static structplatform_driveringenic_rproc_driver= {
+ .probe =ingenic_rproc_probe,
+ .driver = {
+ .name = "ingenic-vpu",
+ .of_match_table =of_match_ptr(ingenic_rproc_of_matches),Quoted 8 lines
+ },
+};
+module_platform_driver(ingenic_rproc_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Paul Cercueil <[email protected]>"); +MODULE_DESCRIPTION("Ingenic JZ47xx Remote Processor control
driver");Quoted 5 lines
Nice, clean and simple driver. With the above and after rolling in Julia's
patch:Acked-by Mathieu Poirier <[email protected]>Thanks!
Cheers,
-Paul
Quoted 8 lines · Paul Cercueil
Inside the Video Processing Unit (VPU) of the recent JZ47xx SoCs from Ingenic is a second Xburst MIPS CPU very similar to the main core. This document describes the devicetree bindings for this auxiliary processor.
Signed-off-by Paul Cercueil <[email protected]>---
Quoted 8 lines
Notes:
v2: Update TCSM0 address in example
v3: Change node name to 'video-decoder'.../bindings/remoteproc/ingenic,vpu.txt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Documentation/devicetree/bindings/remoteproc/ingenic,vpu.txt