2018-03-21 12:09:51

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH 0/8] ARM: davinci: complete the conversion to using the reset framework

From: Bartosz Golaszewski <[email protected]>

This series converts the only user of the handcoded, mach-specific reset
routines in the davinci platform to using the reset framework.

Patch 1 modifies the way lookup entries are registered with the reset
framework.

Patches 2-4 add necessary lookups/DT-properties.

Patches 5-7 convert the davinci-rproc driver to the reset framework.

Patch 8 removes now dead code.

Philipp: it turned out that it's indeed better to use the reset
controller's device name for the entry lookup.

Tested both in DT and legacy modes by booting the examples from
ti-ipc-rtos recipe in meta-ti.

This series applies on top of David Lechner's common-clk-v9 branch[1]
with Philipp Zabel's reset/next branch[2] pulled in.

It can be found in my github tree as well[3].

[1] git://github.com/dlech/ev3dev-kernel.git common-clk-v9
[2] git://git.pengutronix.de/git/pza/linux reset/next
[3] [email protected]:brgl/linux.git topic/davinci-reset

Bartosz Golaszewski (8):
reset: modify the way reset lookup works for board files
ARM: davinci: dts: make psc0 a reset provider
ARM: davinci: dts: add a reset control to the dsp node
clk: davinci: add a reset lookup table for psc0
remoteproc: da8xx: add the missing checke for clk_enable()
remoteproc: da8xx: prepare and unprepare the clock where needed
remoteproc: da8xx: use the reset framework
clk: davinci: kill davinci_clk_reset_assert/deassert()

arch/arm/boot/dts/da850.dtsi | 2 ++
arch/arm/mach-davinci/include/mach/clock.h | 21 ----------------
drivers/clk/davinci/psc-da850.c | 8 ++++++
drivers/clk/davinci/psc.c | 19 +-------------
drivers/remoteproc/da8xx_remoteproc.c | 40 ++++++++++++++++++++++++------
drivers/reset/core.c | 33 +++++++++++++++++++++---
include/linux/reset-controller.h | 8 +++---
7 files changed, 78 insertions(+), 53 deletions(-)
delete mode 100644 arch/arm/mach-davinci/include/mach/clock.h

--
2.16.1



2018-03-21 12:10:11

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH 4/8] clk: davinci: add a reset lookup table for psc0

From: Bartosz Golaszewski <[email protected]>

In order to be able to use the reset framework in legacy boot mode as
well, add the reset lookup table to the psc driver for da850 variant.

Signed-off-by: Bartosz Golaszewski <[email protected]>
---
drivers/clk/davinci/psc-da850.c | 8 ++++++++
drivers/clk/davinci/psc.c | 1 +
2 files changed, 9 insertions(+)

diff --git a/drivers/clk/davinci/psc-da850.c b/drivers/clk/davinci/psc-da850.c
index ccc7eb17bf3a..395db4b2c0ee 100644
--- a/drivers/clk/davinci/psc-da850.c
+++ b/drivers/clk/davinci/psc-da850.c
@@ -6,6 +6,7 @@
*/

#include <linux/clk-provider.h>
+#include <linux/reset-controller.h>
#include <linux/clk.h>
#include <linux/clkdev.h>
#include <linux/init.h>
@@ -66,8 +67,15 @@ LPSC_CLKDEV3(ecap_clkdev, "fck", "ecap.0",
"fck", "ecap.1",
"fck", "ecap.2");

+static struct reset_control_lookup da850_psc0_reset_lookup_table[] = {
+ RESET_LOOKUP("davinci-rproc.0", NULL, 15),
+};
+
static int da850_psc0_init(struct device *dev, void __iomem *base)
{
+ reset_controller_add_lookup("da850-psc0",
+ da850_psc0_reset_lookup_table,
+ ARRAY_SIZE(da850_psc0_reset_lookup_table));
return davinci_psc_register_clocks(dev, da850_psc0_info, 16, base);
}

diff --git a/drivers/clk/davinci/psc.c b/drivers/clk/davinci/psc.c
index 3b0e59dfbdd7..063df62381ea 100644
--- a/drivers/clk/davinci/psc.c
+++ b/drivers/clk/davinci/psc.c
@@ -425,6 +425,7 @@ __davinci_psc_register_clocks(struct device *dev,

psc->rcdev.ops = &davinci_psc_reset_ops;
psc->rcdev.owner = THIS_MODULE;
+ psc->rcdev.dev = dev;
psc->rcdev.of_node = dev->of_node;
psc->rcdev.of_reset_n_cells = 1;
psc->rcdev.of_xlate = davinci_psc_reset_of_xlate;
--
2.16.1


2018-03-21 12:10:31

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH 3/8] ARM: davinci: dts: add a reset control to the dsp node

From: Bartosz Golaszewski <[email protected]>

The davinci-rproc driver will soon use the reset framework. Add the
resets property to the dsp node in da850.dtsi.

Signed-off-by: Bartosz Golaszewski <[email protected]>
---
arch/arm/boot/dts/da850.dtsi | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/arm/boot/dts/da850.dtsi b/arch/arm/boot/dts/da850.dtsi
index 89af749c5b6f..5b485e44b83e 100644
--- a/arch/arm/boot/dts/da850.dtsi
+++ b/arch/arm/boot/dts/da850.dtsi
@@ -124,6 +124,7 @@
compatible = "ti,da850-psc0";
reg = <0x10000 0x1000>;
#clock-cells = <1>;
+ #reset-cells = <1>;
#power-domain-cells = <1>;
clocks = <&pll0_sysclk 1>, <&pll0_sysclk 2>,
<&pll0_sysclk 4>, <&pll0_sysclk 6>,
--
2.16.1


2018-03-21 12:11:05

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH 6/8] remoteproc: da8xx: prepare and unprepare the clock where needed

From: Bartosz Golaszewski <[email protected]>

We're currently switching the platform to using the common clock
framework. We need to explicitly prepare and unprepare the rproc
clock.

Signed-off-by: Bartosz Golaszewski <[email protected]>
---
drivers/remoteproc/da8xx_remoteproc.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/da8xx_remoteproc.c b/drivers/remoteproc/da8xx_remoteproc.c
index 592bf0fc52e8..83f2d66ad3a9 100644
--- a/drivers/remoteproc/da8xx_remoteproc.c
+++ b/drivers/remoteproc/da8xx_remoteproc.c
@@ -149,9 +149,9 @@ static int da8xx_rproc_start(struct rproc *rproc)

writel(rproc->bootaddr, drproc->bootreg);

- rv = clk_enable(dsp_clk);
+ rv = clk_prepare_enable(dsp_clk);
if (rv) {
- dev_err(dev, "clk_enable() failed: %d\n", rv);
+ dev_err(dev, "clk_prepare_enable() failed: %d\n", rv);
return rv;
}

@@ -165,7 +165,7 @@ static int da8xx_rproc_stop(struct rproc *rproc)
struct da8xx_rproc *drproc = rproc->priv;

davinci_clk_reset_assert(drproc->dsp_clk);
- clk_disable(drproc->dsp_clk);
+ clk_disable_unprepare(drproc->dsp_clk);

return 0;
}
--
2.16.1


2018-03-21 12:11:13

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH 7/8] remoteproc: da8xx: use the reset framework

From: Bartosz Golaszewski <[email protected]>

Switch to using the reset framework instead of handcoded reset routines
we used so far.

Signed-off-by: Bartosz Golaszewski <[email protected]>
---
drivers/remoteproc/da8xx_remoteproc.c | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/drivers/remoteproc/da8xx_remoteproc.c b/drivers/remoteproc/da8xx_remoteproc.c
index 83f2d66ad3a9..fc29b78d0f77 100644
--- a/drivers/remoteproc/da8xx_remoteproc.c
+++ b/drivers/remoteproc/da8xx_remoteproc.c
@@ -10,6 +10,7 @@

#include <linux/bitops.h>
#include <linux/clk.h>
+#include <linux/reset.h>
#include <linux/err.h>
#include <linux/interrupt.h>
#include <linux/io.h>
@@ -20,8 +21,6 @@
#include <linux/platform_device.h>
#include <linux/remoteproc.h>

-#include <mach/clock.h> /* for davinci_clk_reset_assert/deassert() */
-
#include "remoteproc_internal.h"

static char *da8xx_fw_name;
@@ -72,6 +71,7 @@ struct da8xx_rproc {
struct da8xx_rproc_mem *mem;
int num_mems;
struct clk *dsp_clk;
+ struct reset_control *dsp_reset;
void (*ack_fxn)(struct irq_data *data);
struct irq_data *irq_data;
void __iomem *chipsig;
@@ -138,6 +138,7 @@ static int da8xx_rproc_start(struct rproc *rproc)
struct device *dev = rproc->dev.parent;
struct da8xx_rproc *drproc = (struct da8xx_rproc *)rproc->priv;
struct clk *dsp_clk = drproc->dsp_clk;
+ struct reset_control *dsp_reset = drproc->dsp_reset;
int rv;

/* hw requires the start (boot) address be on 1KB boundary */
@@ -155,7 +156,11 @@ static int da8xx_rproc_start(struct rproc *rproc)
return rv;
}

- davinci_clk_reset_deassert(dsp_clk);
+ rv = reset_control_deassert(dsp_reset);
+ if (rv) {
+ dev_err(dev, "reset_control_deassert() failed: %d\n", rv);
+ return rv;
+ }

return 0;
}
@@ -163,8 +168,15 @@ static int da8xx_rproc_start(struct rproc *rproc)
static int da8xx_rproc_stop(struct rproc *rproc)
{
struct da8xx_rproc *drproc = rproc->priv;
+ int rv;
+
+ rv = reset_control_assert(drproc->dsp_reset);
+ if (rv) {
+ dev_err(rproc->dev.parent,
+ "reset_control_assert() failed: %d\n", rv);
+ return rv;
+ }

- davinci_clk_reset_assert(drproc->dsp_clk);
clk_disable_unprepare(drproc->dsp_clk);

return 0;
@@ -232,6 +244,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev)
struct resource *bootreg_res;
struct resource *chipsig_res;
struct clk *dsp_clk;
+ struct reset_control *dsp_reset;
void __iomem *chipsig;
void __iomem *bootreg;
int irq;
@@ -268,6 +281,13 @@ static int da8xx_rproc_probe(struct platform_device *pdev)
return PTR_ERR(dsp_clk);
}

+ dsp_reset = devm_reset_control_get_exclusive(dev, NULL);
+ if (IS_ERR(dsp_reset)) {
+ dev_err(dev, "unable to get reset control: %ld\n",
+ PTR_ERR(dsp_reset));
+ return PTR_ERR(dsp_reset);
+ }
+
if (dev->of_node) {
ret = of_reserved_mem_device_init(dev);
if (ret) {
@@ -309,7 +329,7 @@ static int da8xx_rproc_probe(struct platform_device *pdev)
* *not* in reset, but da8xx_rproc_start() needs the DSP to be
* held in reset at the time it is called.
*/
- ret = davinci_clk_reset_assert(drproc->dsp_clk);
+ ret = reset_control_assert(dsp_reset);
if (ret)
goto free_rproc;

--
2.16.1


2018-03-21 12:11:31

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH 8/8] clk: davinci: kill davinci_clk_reset_assert/deassert()

From: Bartosz Golaszewski <[email protected]>

This code is no longer used. Remove it.

Signed-off-by: Bartosz Golaszewski <[email protected]>
---
arch/arm/mach-davinci/include/mach/clock.h | 21 ---------------------
drivers/clk/davinci/psc.c | 18 ------------------
2 files changed, 39 deletions(-)
delete mode 100644 arch/arm/mach-davinci/include/mach/clock.h

diff --git a/arch/arm/mach-davinci/include/mach/clock.h b/arch/arm/mach-davinci/include/mach/clock.h
deleted file mode 100644
index 42ed4f2f5ce4..000000000000
--- a/arch/arm/mach-davinci/include/mach/clock.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * arch/arm/mach-davinci/include/mach/clock.h
- *
- * Clock control driver for DaVinci - header file
- *
- * Authors: Vladimir Barinov <[email protected]>
- *
- * 2007 (c) MontaVista Software, Inc. This file is licensed under
- * the terms of the GNU General Public License version 2. This program
- * is licensed "as is" without any warranty of any kind, whether express
- * or implied.
- */
-#ifndef __ASM_ARCH_DAVINCI_CLOCK_H
-#define __ASM_ARCH_DAVINCI_CLOCK_H
-
-struct clk;
-
-int davinci_clk_reset_assert(struct clk *c);
-int davinci_clk_reset_deassert(struct clk *c);
-
-#endif
diff --git a/drivers/clk/davinci/psc.c b/drivers/clk/davinci/psc.c
index 063df62381ea..75c4bc6f23e3 100644
--- a/drivers/clk/davinci/psc.c
+++ b/drivers/clk/davinci/psc.c
@@ -295,24 +295,6 @@ static int davinci_lpsc_clk_reset(struct clk *clk, bool reset)
return 0;
}

-/*
- * REVISIT: These exported functions can be removed after a non-DT lookup is
- * added to the reset controller framework and the davinci-rproc driver is
- * updated to use the generic reset controller framework.
- */
-
-int davinci_clk_reset_assert(struct clk *clk)
-{
- return davinci_lpsc_clk_reset(clk, true);
-}
-EXPORT_SYMBOL(davinci_clk_reset_assert);
-
-int davinci_clk_reset_deassert(struct clk *clk)
-{
- return davinci_lpsc_clk_reset(clk, false);
-}
-EXPORT_SYMBOL(davinci_clk_reset_deassert);
-
static int davinci_psc_reset_assert(struct reset_controller_dev *rcdev,
unsigned long id)
{
--
2.16.1


2018-03-21 12:12:05

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH 5/8] remoteproc: da8xx: add the missing checke for clk_enable()

From: Bartosz Golaszewski <[email protected]>

The davinci platform is being switched to using the common clock
framework, where clk_enable() can fail. Add the return value check.

Signed-off-by: Bartosz Golaszewski <[email protected]>
---
drivers/remoteproc/da8xx_remoteproc.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/da8xx_remoteproc.c b/drivers/remoteproc/da8xx_remoteproc.c
index bf3b9034c319..592bf0fc52e8 100644
--- a/drivers/remoteproc/da8xx_remoteproc.c
+++ b/drivers/remoteproc/da8xx_remoteproc.c
@@ -138,6 +138,7 @@ static int da8xx_rproc_start(struct rproc *rproc)
struct device *dev = rproc->dev.parent;
struct da8xx_rproc *drproc = (struct da8xx_rproc *)rproc->priv;
struct clk *dsp_clk = drproc->dsp_clk;
+ int rv;

/* hw requires the start (boot) address be on 1KB boundary */
if (rproc->bootaddr & 0x3ff) {
@@ -148,7 +149,12 @@ static int da8xx_rproc_start(struct rproc *rproc)

writel(rproc->bootaddr, drproc->bootreg);

- clk_enable(dsp_clk);
+ rv = clk_enable(dsp_clk);
+ if (rv) {
+ dev_err(dev, "clk_enable() failed: %d\n", rv);
+ return rv;
+ }
+
davinci_clk_reset_deassert(dsp_clk);

return 0;
--
2.16.1


2018-03-21 12:12:05

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH 2/8] ARM: davinci: dts: make psc0 a reset provider

From: Bartosz Golaszewski <[email protected]>

The psc driver registers with the reset framework as a provider. Add
the #reset-cells property to the psc0 node.

Signed-off-by: Bartosz Golaszewski <[email protected]>
---
arch/arm/boot/dts/da850.dtsi | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/arm/boot/dts/da850.dtsi b/arch/arm/boot/dts/da850.dtsi
index a3b9a99b43ca..89af749c5b6f 100644
--- a/arch/arm/boot/dts/da850.dtsi
+++ b/arch/arm/boot/dts/da850.dtsi
@@ -109,6 +109,7 @@
interrupt-parent = <&intc>;
interrupts = <28>;
clocks = <&psc0 15>;
+ resets = <&psc0 15>;
status = "disabled";
};
soc@1c00000 {
--
2.16.1


2018-03-21 12:12:05

by Bartosz Golaszewski

[permalink] [raw]
Subject: [PATCH 1/8] reset: modify the way reset lookup works for board files

From: Bartosz Golaszewski <[email protected]>

Commit 7af1bb19f1d7 ("reset: add support for non-DT systems")
introduced reset control lookup mechanism for boards that still use
board files.

The routine used to register lookup entries takes the corresponding
reset_controlled_dev structure as argument.

It's been determined however that for the first user of this new
interface - davinci psc driver - it will be easier to register the
lookup entries using the reset controller device name.

This patch changes the way lookup entries are added.

Signed-off-by: Bartosz Golaszewski <[email protected]>
---
drivers/reset/core.c | 33 +++++++++++++++++++++++++++++----
include/linux/reset-controller.h | 8 +++++---
2 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 06fa4907afc4..f37048e55336 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -153,11 +153,11 @@ EXPORT_SYMBOL_GPL(devm_reset_controller_register);

/**
* reset_controller_add_lookup - register a set of lookup entries
- * @rcdev: initialized reset controller device owning the reset line
+ * @provider: name of the reset controller provider
* @lookup: array of reset lookup entries
* @num_entries: number of entries in the lookup array
*/
-void reset_controller_add_lookup(struct reset_controller_dev *rcdev,
+void reset_controller_add_lookup(const char *provider,
struct reset_control_lookup *lookup,
unsigned int num_entries)
{
@@ -174,7 +174,7 @@ void reset_controller_add_lookup(struct reset_controller_dev *rcdev,
continue;
}

- entry->rcdev = rcdev;
+ entry->provider = provider;
list_add_tail(&entry->list, &reset_lookup_list);
}
mutex_unlock(&reset_lookup_mutex);
@@ -526,11 +526,30 @@ struct reset_control *__of_reset_control_get(struct device_node *node,
}
EXPORT_SYMBOL_GPL(__of_reset_control_get);

+static struct reset_controller_dev *
+__reset_controller_by_name(const char *name)
+{
+ struct reset_controller_dev *rcdev;
+
+ lockdep_assert_held(&reset_list_mutex);
+
+ list_for_each_entry(rcdev, &reset_controller_list, list) {
+ if (!rcdev->dev)
+ continue;
+
+ if (!strcmp(name, dev_name(rcdev->dev)))
+ return rcdev;
+ }
+
+ return NULL;
+}
+
static struct reset_control *
__reset_control_get_from_lookup(struct device *dev, const char *con_id,
bool shared, bool optional)
{
const struct reset_control_lookup *lookup;
+ struct reset_controller_dev *rcdev;
const char *dev_id = dev_name(dev);
struct reset_control *rstc = NULL;

@@ -547,7 +566,13 @@ __reset_control_get_from_lookup(struct device *dev, const char *con_id,
((con_id && lookup->con_id) &&
!strcmp(con_id, lookup->con_id))) {
mutex_lock(&reset_list_mutex);
- rstc = __reset_control_get_internal(lookup->rcdev,
+ rcdev = __reset_controller_by_name(lookup->provider);
+ if (!rcdev) {
+ mutex_unlock(&reset_list_mutex);
+ continue;
+ }
+
+ rstc = __reset_control_get_internal(rcdev,
lookup->index,
shared);
mutex_unlock(&reset_list_mutex);
diff --git a/include/linux/reset-controller.h b/include/linux/reset-controller.h
index 25698f6c1fae..1a6c25d825d3 100644
--- a/include/linux/reset-controller.h
+++ b/include/linux/reset-controller.h
@@ -30,14 +30,14 @@ struct of_phandle_args;
* struct reset_control_lookup - represents a single lookup entry
*
* @list: internal list of all reset lookup entries
- * @rcdev: reset controller device controlling this reset line
+ * @provider: name of the reset controller device controlling this reset line
* @index: ID of the reset controller in the reset controller device
* @dev_id: name of the device associated with this reset line
* @con_id name of the reset line (can be NULL)
*/
struct reset_control_lookup {
struct list_head list;
- struct reset_controller_dev *rcdev;
+ const char *provider;
unsigned int index;
const char *dev_id;
const char *con_id;
@@ -57,6 +57,7 @@ struct reset_control_lookup {
* @owner: kernel module of the reset controller driver
* @list: internal list of reset controller devices
* @reset_control_head: head of internal list of requested reset controls
+ * @dev: corresponding driver model device struct
* @of_node: corresponding device tree node as phandle target
* @of_reset_n_cells: number of cells in reset line specifiers
* @of_xlate: translation function to translate from specifier as found in the
@@ -68,6 +69,7 @@ struct reset_controller_dev {
struct module *owner;
struct list_head list;
struct list_head reset_control_head;
+ struct device *dev;
struct device_node *of_node;
int of_reset_n_cells;
int (*of_xlate)(struct reset_controller_dev *rcdev,
@@ -82,7 +84,7 @@ struct device;
int devm_reset_controller_register(struct device *dev,
struct reset_controller_dev *rcdev);

-void reset_controller_add_lookup(struct reset_controller_dev *rcdev,
+void reset_controller_add_lookup(const char *provider,
struct reset_control_lookup *lookup,
unsigned int num_entries);

--
2.16.1


2018-03-21 14:06:55

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH 3/8] ARM: davinci: dts: add a reset control to the dsp node

2018-03-21 13:08 GMT+01:00 Bartosz Golaszewski <[email protected]>:
> From: Bartosz Golaszewski <[email protected]>
>
> The davinci-rproc driver will soon use the reset framework. Add the
> resets property to the dsp node in da850.dtsi.
>
> Signed-off-by: Bartosz Golaszewski <[email protected]>
> ---
> arch/arm/boot/dts/da850.dtsi | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/arm/boot/dts/da850.dtsi b/arch/arm/boot/dts/da850.dtsi
> index 89af749c5b6f..5b485e44b83e 100644
> --- a/arch/arm/boot/dts/da850.dtsi
> +++ b/arch/arm/boot/dts/da850.dtsi
> @@ -124,6 +124,7 @@
> compatible = "ti,da850-psc0";
> reg = <0x10000 0x1000>;
> #clock-cells = <1>;
> + #reset-cells = <1>;
> #power-domain-cells = <1>;
> clocks = <&pll0_sysclk 1>, <&pll0_sysclk 2>,
> <&pll0_sysclk 4>, <&pll0_sysclk 6>,
> --
> 2.16.1
>

I noticed I mixed up the descriptions in patches 2/8 and 3/8. It'll
need a v2, but I'll wait for some reviews first.

Bart

2018-03-21 16:04:42

by David Lechner

[permalink] [raw]
Subject: Re: [PATCH 4/8] clk: davinci: add a reset lookup table for psc0

On 03/21/2018 07:08 AM, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <[email protected]>
>
> In order to be able to use the reset framework in legacy boot mode as
> well, add the reset lookup table to the psc driver for da850 variant.
>
> Signed-off-by: Bartosz Golaszewski <[email protected]>
> ---
> drivers/clk/davinci/psc-da850.c | 8 ++++++++
> drivers/clk/davinci/psc.c | 1 +
> 2 files changed, 9 insertions(+)
>
> diff --git a/drivers/clk/davinci/psc-da850.c b/drivers/clk/davinci/psc-da850.c
> index ccc7eb17bf3a..395db4b2c0ee 100644
> --- a/drivers/clk/davinci/psc-da850.c
> +++ b/drivers/clk/davinci/psc-da850.c
> @@ -6,6 +6,7 @@
> */
>
> #include <linux/clk-provider.h>
> +#include <linux/reset-controller.h>
> #include <linux/clk.h>
> #include <linux/clkdev.h>
> #include <linux/init.h>
> @@ -66,8 +67,15 @@ LPSC_CLKDEV3(ecap_clkdev, "fck", "ecap.0",
> "fck", "ecap.1",
> "fck", "ecap.2");
>
> +static struct reset_control_lookup da850_psc0_reset_lookup_table[] = {
> + RESET_LOOKUP("davinci-rproc.0", NULL, 15),
> +};
> +
> static int da850_psc0_init(struct device *dev, void __iomem *base)
> {
> + reset_controller_add_lookup("da850-psc0",
> + da850_psc0_reset_lookup_table,
> + ARRAY_SIZE(da850_psc0_reset_lookup_table));

Could there be a race condition here since you are adding the lookup *before*
you are adding the actual provider? It seems like reset_controller_add_lookup()
should be after davinci_psc_register_clocks().

> return davinci_psc_register_clocks(dev, da850_psc0_info, 16, base);
> }
>
> diff --git a/drivers/clk/davinci/psc.c b/drivers/clk/davinci/psc.c
> index 3b0e59dfbdd7..063df62381ea 100644
> --- a/drivers/clk/davinci/psc.c
> +++ b/drivers/clk/davinci/psc.c
> @@ -425,6 +425,7 @@ __davinci_psc_register_clocks(struct device *dev,
>
> psc->rcdev.ops = &davinci_psc_reset_ops;
> psc->rcdev.owner = THIS_MODULE;
> + psc->rcdev.dev = dev;
> psc->rcdev.of_node = dev->of_node;
> psc->rcdev.of_reset_n_cells = 1;
> psc->rcdev.of_xlate = davinci_psc_reset_of_xlate;
>


2018-03-21 16:09:28

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH 4/8] clk: davinci: add a reset lookup table for psc0

2018-03-21 17:01 GMT+01:00 David Lechner <[email protected]>:
> On 03/21/2018 07:08 AM, Bartosz Golaszewski wrote:
>>
>> From: Bartosz Golaszewski <[email protected]>
>>
>> In order to be able to use the reset framework in legacy boot mode as
>> well, add the reset lookup table to the psc driver for da850 variant.
>>
>> Signed-off-by: Bartosz Golaszewski <[email protected]>
>> ---
>> drivers/clk/davinci/psc-da850.c | 8 ++++++++
>> drivers/clk/davinci/psc.c | 1 +
>> 2 files changed, 9 insertions(+)
>>
>> diff --git a/drivers/clk/davinci/psc-da850.c
>> b/drivers/clk/davinci/psc-da850.c
>> index ccc7eb17bf3a..395db4b2c0ee 100644
>> --- a/drivers/clk/davinci/psc-da850.c
>> +++ b/drivers/clk/davinci/psc-da850.c
>> @@ -6,6 +6,7 @@
>> */
>> #include <linux/clk-provider.h>
>> +#include <linux/reset-controller.h>
>> #include <linux/clk.h>
>> #include <linux/clkdev.h>
>> #include <linux/init.h>
>> @@ -66,8 +67,15 @@ LPSC_CLKDEV3(ecap_clkdev, "fck", "ecap.0",
>> "fck", "ecap.1",
>> "fck", "ecap.2");
>> +static struct reset_control_lookup da850_psc0_reset_lookup_table[] = {
>> + RESET_LOOKUP("davinci-rproc.0", NULL, 15),
>> +};
>> +
>> static int da850_psc0_init(struct device *dev, void __iomem *base)
>> {
>> + reset_controller_add_lookup("da850-psc0",
>> + da850_psc0_reset_lookup_table,
>> +
>> ARRAY_SIZE(da850_psc0_reset_lookup_table));
>
>
> Could there be a race condition here since you are adding the lookup
> *before*
> you are adding the actual provider? It seems like
> reset_controller_add_lookup()
> should be after davinci_psc_register_clocks().
>

I don't think so, because reset_controller_add_lookup() only adds the
lookup structure to the list in reset/core.c. The actual reset
controller struct is only located and used when reset_control_get_*()
is called, so after probing the user. And it's all protected with
mutexes.

This made me think though - maybe if we can't locate the controller,
we should return -EPROBE_DEFER from probe in davinci-rproc?

Bart

2018-03-21 16:09:45

by David Lechner

[permalink] [raw]
Subject: Re: [PATCH 3/8] ARM: davinci: dts: add a reset control to the dsp node

On 03/21/2018 09:04 AM, Bartosz Golaszewski wrote:
> 2018-03-21 13:08 GMT+01:00 Bartosz Golaszewski <[email protected]>:
>> From: Bartosz Golaszewski <[email protected]>
>>
>> The davinci-rproc driver will soon use the reset framework. Add the
>> resets property to the dsp node in da850.dtsi.
>>
>> Signed-off-by: Bartosz Golaszewski <[email protected]>
>> ---
>> arch/arm/boot/dts/da850.dtsi | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/arch/arm/boot/dts/da850.dtsi b/arch/arm/boot/dts/da850.dtsi
>> index 89af749c5b6f..5b485e44b83e 100644
>> --- a/arch/arm/boot/dts/da850.dtsi
>> +++ b/arch/arm/boot/dts/da850.dtsi
>> @@ -124,6 +124,7 @@
>> compatible = "ti,da850-psc0";
>> reg = <0x10000 0x1000>;
>> #clock-cells = <1>;
>> + #reset-cells = <1>;
>> #power-domain-cells = <1>;
>> clocks = <&pll0_sysclk 1>, <&pll0_sysclk 2>,
>> <&pll0_sysclk 4>, <&pll0_sysclk 6>,
>> --
>> 2.16.1
>>
>
> I noticed I mixed up the descriptions in patches 2/8 and 3/8. It'll
> need a v2, but I'll wait for some reviews first.
>
> Bart
>

Yes, and this patch should be first to avoid a possible compiler warning.

2018-03-21 16:18:58

by David Lechner

[permalink] [raw]
Subject: Re: [PATCH 4/8] clk: davinci: add a reset lookup table for psc0

On 03/21/2018 11:08 AM, Bartosz Golaszewski wrote:
> 2018-03-21 17:01 GMT+01:00 David Lechner <[email protected]>:
>> On 03/21/2018 07:08 AM, Bartosz Golaszewski wrote:
>>>
>>> From: Bartosz Golaszewski <[email protected]>
>>>
>>> In order to be able to use the reset framework in legacy boot mode as
>>> well, add the reset lookup table to the psc driver for da850 variant.
>>>
>>> Signed-off-by: Bartosz Golaszewski <[email protected]>
>>> ---
>>> drivers/clk/davinci/psc-da850.c | 8 ++++++++
>>> drivers/clk/davinci/psc.c | 1 +
>>> 2 files changed, 9 insertions(+)
>>>
>>> diff --git a/drivers/clk/davinci/psc-da850.c
>>> b/drivers/clk/davinci/psc-da850.c
>>> index ccc7eb17bf3a..395db4b2c0ee 100644
>>> --- a/drivers/clk/davinci/psc-da850.c
>>> +++ b/drivers/clk/davinci/psc-da850.c
>>> @@ -6,6 +6,7 @@
>>> */
>>> #include <linux/clk-provider.h>
>>> +#include <linux/reset-controller.h>
>>> #include <linux/clk.h>
>>> #include <linux/clkdev.h>
>>> #include <linux/init.h>
>>> @@ -66,8 +67,15 @@ LPSC_CLKDEV3(ecap_clkdev, "fck", "ecap.0",
>>> "fck", "ecap.1",
>>> "fck", "ecap.2");
>>> +static struct reset_control_lookup da850_psc0_reset_lookup_table[] = {
>>> + RESET_LOOKUP("davinci-rproc.0", NULL, 15),
>>> +};
>>> +
>>> static int da850_psc0_init(struct device *dev, void __iomem *base)
>>> {
>>> + reset_controller_add_lookup("da850-psc0",
>>> + da850_psc0_reset_lookup_table,
>>> +
>>> ARRAY_SIZE(da850_psc0_reset_lookup_table));
>>
>>
>> Could there be a race condition here since you are adding the lookup
>> *before*
>> you are adding the actual provider? It seems like
>> reset_controller_add_lookup()
>> should be after davinci_psc_register_clocks().
>>
>
> I don't think so, because reset_controller_add_lookup() only adds the
> lookup structure to the list in reset/core.c. The actual reset
> controller struct is only located and used when reset_control_get_*()
> is called, so after probing the user. And it's all protected with
> mutexes.
>
> This made me think though - maybe if we can't locate the controller,
> we should return -EPROBE_DEFER from probe in davinci-rproc?
>
> Bart
>

Yes, especially since we know that the PSC driver itself does get
deferred already.

2018-03-21 16:22:14

by David Lechner

[permalink] [raw]
Subject: Re: [PATCH 5/8] remoteproc: da8xx: add the missing checke for clk_enable()

On 03/21/2018 07:08 AM, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <[email protected]>
>
> The davinci platform is being switched to using the common clock
> framework, where clk_enable() can fail. Add the return value check.
>
> Signed-off-by: Bartosz Golaszewski <[email protected]>
> ---
> drivers/remoteproc/da8xx_remoteproc.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/remoteproc/da8xx_remoteproc.c b/drivers/remoteproc/da8xx_remoteproc.c
> index bf3b9034c319..592bf0fc52e8 100644
> --- a/drivers/remoteproc/da8xx_remoteproc.c
> +++ b/drivers/remoteproc/da8xx_remoteproc.c
> @@ -138,6 +138,7 @@ static int da8xx_rproc_start(struct rproc *rproc)
> struct device *dev = rproc->dev.parent;
> struct da8xx_rproc *drproc = (struct da8xx_rproc *)rproc->priv;
> struct clk *dsp_clk = drproc->dsp_clk;
> + int rv;

For style points, you could use ret instead of rv to be consistent with
the rest of this driver.

>
> /* hw requires the start (boot) address be on 1KB boundary */
> if (rproc->bootaddr & 0x3ff) {
> @@ -148,7 +149,12 @@ static int da8xx_rproc_start(struct rproc *rproc)
>
> writel(rproc->bootaddr, drproc->bootreg);
>
> - clk_enable(dsp_clk);
> + rv = clk_enable(dsp_clk);
> + if (rv) {
> + dev_err(dev, "clk_enable() failed: %d\n", rv);
> + return rv;
> + }
> +
> davinci_clk_reset_deassert(dsp_clk);
>
> return 0;
>


2018-03-21 16:26:02

by David Lechner

[permalink] [raw]
Subject: Re: [PATCH 8/8] clk: davinci: kill davinci_clk_reset_assert/deassert()

On 03/21/2018 07:08 AM, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <[email protected]>
>
> This code is no longer used. Remove it.
>
> Signed-off-by: Bartosz Golaszewski <[email protected]>
> ---

Reviewed-by: David Lechner <[email protected]>


2018-03-23 09:08:47

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH 4/8] clk: davinci: add a reset lookup table for psc0

2018-03-21 17:17 GMT+01:00 David Lechner <[email protected]>:
> On 03/21/2018 11:08 AM, Bartosz Golaszewski wrote:
>>
>> 2018-03-21 17:01 GMT+01:00 David Lechner <[email protected]>:
>>>
>>> On 03/21/2018 07:08 AM, Bartosz Golaszewski wrote:
>>>>
>>>>
>>>> From: Bartosz Golaszewski <[email protected]>
>>>>
>>>> In order to be able to use the reset framework in legacy boot mode as
>>>> well, add the reset lookup table to the psc driver for da850 variant.
>>>>
>>>> Signed-off-by: Bartosz Golaszewski <[email protected]>
>>>> ---
>>>> drivers/clk/davinci/psc-da850.c | 8 ++++++++
>>>> drivers/clk/davinci/psc.c | 1 +
>>>> 2 files changed, 9 insertions(+)
>>>>
>>>> diff --git a/drivers/clk/davinci/psc-da850.c
>>>> b/drivers/clk/davinci/psc-da850.c
>>>> index ccc7eb17bf3a..395db4b2c0ee 100644
>>>> --- a/drivers/clk/davinci/psc-da850.c
>>>> +++ b/drivers/clk/davinci/psc-da850.c
>>>> @@ -6,6 +6,7 @@
>>>> */
>>>> #include <linux/clk-provider.h>
>>>> +#include <linux/reset-controller.h>
>>>> #include <linux/clk.h>
>>>> #include <linux/clkdev.h>
>>>> #include <linux/init.h>
>>>> @@ -66,8 +67,15 @@ LPSC_CLKDEV3(ecap_clkdev, "fck", "ecap.0",
>>>> "fck", "ecap.1",
>>>> "fck", "ecap.2");
>>>> +static struct reset_control_lookup da850_psc0_reset_lookup_table[] =
>>>> {
>>>> + RESET_LOOKUP("davinci-rproc.0", NULL, 15),
>>>> +};
>>>> +
>>>> static int da850_psc0_init(struct device *dev, void __iomem *base)
>>>> {
>>>> + reset_controller_add_lookup("da850-psc0",
>>>> + da850_psc0_reset_lookup_table,
>>>> +
>>>> ARRAY_SIZE(da850_psc0_reset_lookup_table));
>>>
>>>
>>>
>>> Could there be a race condition here since you are adding the lookup
>>> *before*
>>> you are adding the actual provider? It seems like
>>> reset_controller_add_lookup()
>>> should be after davinci_psc_register_clocks().
>>>
>>
>> I don't think so, because reset_controller_add_lookup() only adds the
>> lookup structure to the list in reset/core.c. The actual reset
>> controller struct is only located and used when reset_control_get_*()
>> is called, so after probing the user. And it's all protected with
>> mutexes.
>>
>> This made me think though - maybe if we can't locate the controller,
>> we should return -EPROBE_DEFER from probe in davinci-rproc?
>>
>> Bart
>>
>
> Yes, especially since we know that the PSC driver itself does get
> deferred already.

On the other hand if clk_get() succeeded, than the psc driver is
already initialized and the subsequent call to reset_control_get()
must succeed. But this is probably too machine-specific for a driver.

Bart