Skip to contentSkip to conversation

clk: x86: Do not gate clocks enabled by the firmware

PATCH Applied Carlo Caione 6 participants 10 messages Jul 14, 2017 – Sep 22, 2017

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 clk: x86: Do not gate clocks enabled by the firmware

From: Carlo Caione <[email protected]>

Read the enable register to determine if the clock is already in use by the firmware. In this case avoid gating the clock.

---
 drivers/clk/x86/clk-pmc-atom.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/clk/x86/clk-pmc-atom.c +7 -0
index 2b60577703ef..be8d821ce625 100644
@@ -185,6 +185,13 @@ static struct clk_plt *plt_clk_register(struct platform_device *pdev, int id,
 	pclk->reg = base + PMC_CLK_CTL_OFFSET + id * PMC_CLK_CTL_SIZE;
 	spin_lock_init(&pclk->lock);
 
+	/*
+	 * If the clock was already enabled by the firmware mark it as critical
+	 * to avoid it being gated by the clock framework if no driver owns it.
+	 */
+	if (plt_clk_is_enabled(&pclk->hw))
+		init.flags |= CLK_IS_CRITICAL;
+
 	ret = devm_clk_hw_register(&pdev->dev, &pclk->hw);
 	if (ret) {
 		pclk = ERR_PTR(ret);
Signature · 1 line
2.13.2
Applied
#1 lore raw
Quoted 10 lines · Carlo Caione

From: Carlo Caione <[email protected]>

Read the enable register to determine if the clock is already in use by the firmware. In this case avoid gating the clock.

---

Applied to clk-fixes and added a Fixes tag.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#2 lore raw
In reply to Carlo Caione
Quoted 21 lines · Carlo Caione

From: Carlo Caione <[email protected]>

Read the enable register to determine if the clock is already in use by the firmware. In this case avoid gating the clock.

---
 drivers/clk/x86/clk-pmc-atom.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/clk/x86/clk-pmc-atom.c +0 -0
index 2b60577703ef..be8d821ce625 100644
@@ -185,6 +185,13 @@ static struct clk_plt *plt_clk_register(struct platform_device *pdev, int id,
        pclk->reg = base + PMC_CLK_CTL_OFFSET + id * PMC_CLK_CTL_SIZE;
        spin_lock_init(&pclk->lock);
 

drivers/clk/x86/clk-pmc-atom.c static struct clk_plt *plt_clk_register(struct platform_device *pdev, int id, · line 197

Quoted 10 lines
drivers/clk/x86/clk-pmc-atom.c +7 -0
+       /*
+        * If the clock was already enabled by the firmware mark it as critical
+        * to avoid it being gated by the clock framework if no driver owns it.
+        */
+       if (plt_clk_is_enabled(&pclk->hw))
+               init.flags |= CLK_IS_CRITICAL;
+
        ret = devm_clk_hw_register(&pdev->dev, &pclk->hw);
        if (ret) {
                pclk = ERR_PTR(ret);

Hi,

I just discovered that this fix is not working anymore on my platform (with a baytrail processor).
This fix was needed on my setup because the clock pmc_plt_clk_4 used by the Ethernet and enabled by the firmware, was being gated by the clock framework since the r8169 driver was failing to claim it. You can read the whole discussion about this in [0]. This fix was also needed for some other audio machine drivers.

I bisected the problem down to commit 49d25364df ("staging/atomisp:
Add support for the Intel IPU v2"). The clock driver is basically shutting down all the clocks (see [1]) at probe time, so the clk-pmc-atom driver is seeing all the clocks already disabled when going to check.

Any idea how to proper fix this?

Cheers,

[0] https://www.spinics.net/lists/platform-driver-x86/msg12092.html
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/staging/media/atomisp/platform/clock/vlv2_plat_clock.c?h=v4.13#n200

Signature · 1 line
Carlo Caione
#3 lore raw
Quoted 43 lines · Carlo Caione
Quoted 21 lines · Carlo Caione

From: Carlo Caione <[email protected]>

Read the enable register to determine if the clock is already in use by the firmware. In this case avoid gating the clock.

---
  drivers/clk/x86/clk-pmc-atom.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/clk/x86/clk-pmc-atom.c +0 -0
index 2b60577703ef..be8d821ce625 100644
@@ -185,6 +185,13 @@ static struct clk_plt *plt_clk_register(struct platform_device *pdev, int id,
         pclk->reg = base + PMC_CLK_CTL_OFFSET + id * PMC_CLK_CTL_SIZE;
         spin_lock_init(&pclk->lock);
 

drivers/clk/x86/clk-pmc-atom.c static struct clk_plt *plt_clk_register(struct platform_device *pdev, int id, · line 197

Quoted 10 lines
drivers/clk/x86/clk-pmc-atom.c +7 -0
+       /*
+        * If the clock was already enabled by the firmware mark it as critical
+        * to avoid it being gated by the clock framework if no driver owns it.
+        */
+       if (plt_clk_is_enabled(&pclk->hw))
+               init.flags |= CLK_IS_CRITICAL;
+
         ret = devm_clk_hw_register(&pdev->dev, &pclk->hw);
         if (ret) {
                 pclk = ERR_PTR(ret);

Hi,

I just discovered that this fix is not working anymore on my platform (with a baytrail processor).
This fix was needed on my setup because the clock pmc_plt_clk_4 used by the Ethernet and enabled by the firmware, was being gated by the clock framework since the r8169 driver was failing to claim it. You can read the whole discussion about this in [0]. This fix was also needed for some other audio machine drivers.

Quoted 7 lines

I bisected the problem down to commit 49d25364df ("staging/atomisp:
Add support for the Intel IPU v2"). The clock driver is basically shutting down all the clocks (see [1]) at probe time, so the clk-pmc-atom driver is seeing all the clocks already disabled when going to check.

Any idea how to proper fix this?

Looks like the same code that was initially used as a reference for support of PMC clocks in the clock framework, so now we have 2 drivers programming the same PMC hardware, not so good. We'd probably have to move the atomisp driver to move to clk_get/prepare/enable instead of the old vlv2_clck_get?

Quoted 6 lines

Cheers,

[0] https://www.spinics.net/lists/platform-driver-x86/msg12092.html
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/staging/media/atomisp/platform/clock/vlv2_plat_clock.c?h=v4.13#n200

#4 lore raw
Quoted 53 lines · Pierre-Louis Bossart
Quoted 52 lines · Carlo Caione
Quoted 27 lines · Carlo Caione

From: Carlo Caione <[email protected]>

Read the enable register to determine if the clock is already in use by the firmware. In this case avoid gating the clock.

---
  drivers/clk/x86/clk-pmc-atom.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/clk/x86/clk-pmc-atom.c +2 -0
index 2b60577703ef..be8d821ce625 100644
@@ -185,6 +185,13 @@ static struct clk_plt *plt_clk_register(struct 
 platform_device *pdev, int id,
         pclk->reg = base + PMC_CLK_CTL_OFFSET + id * PMC_CLK_CTL_SIZE;
         spin_lock_init(&pclk->lock);
 
+       /*
+        * If the clock was already enabled by the firmware mark it 

as critical
+ * to avoid it being gated by the clock framework if no
driver owns it.

drivers/clk/x86/clk-pmc-atom.c

Quoted 7 lines
drivers/clk/x86/clk-pmc-atom.c +4 -0
+        */
+       if (plt_clk_is_enabled(&pclk->hw))
+               init.flags |= CLK_IS_CRITICAL;
+
         ret = devm_clk_hw_register(&pdev->dev, &pclk->hw);
         if (ret) {
                 pclk = ERR_PTR(ret);

Hi,

I just discovered that this fix is not working anymore on my platform (with a baytrail processor).
This fix was needed on my setup because the clock pmc_plt_clk_4 used by the Ethernet and enabled by the firmware, was being gated by the clock framework since the r8169 driver was failing to claim it. You can read the whole discussion about this in [0]. This fix was also needed for some other audio machine drivers.

I bisected the problem down to commit 49d25364df ("staging/atomisp:
Add support for the Intel IPU v2"). The clock driver is basically shutting down all the clocks (see [1]) at probe time, so the clk-pmc-atom driver is seeing all the clocks already disabled when going to check.

Quoted 3 lines
Quoted 1 line

Any idea how to proper fix this?

Looks like the same code that was initially used as a reference for support of PMC clocks in the clock framework, so now we have 2 drivers programming the same PMC hardware, not so good. We'd probably have to move the atomisp driver to move to clk_get/prepare/enable instead of the old vlv2_clck_get?

See attached an untested change to show the idea on moving to the clk API and get feedback (I am not a camera guy, just trying to help - compile-tested/checkpatch only). This code *should* enable the same functionality using existing hooks in the kernel (and handle the BYT/CHT clocking difference as a bonus). I am sure Andy will have plenty of comments :-)

Quoted 1 line

From 48bbe216d947eecc2fda97d6ca4b5d3225430e82 Mon Sep 17 00:00:00 2001

From: Pierre-Louis Bossart <[email protected]>
Date: Thu, 7 Sep 2017 16:15:46 -0500
Subject: [PATCH] [media] staging: atomisp: use clock framework for camera
clocks

The Atom ISP driver initializes and configures PMC clocks which are already handled by the clock framework.

Remove all legacy vlv2_platform_clock stuff and move to the clk API to avoid conflicts, e.g. with audio machine drivers enabling the MCLK for external codecs

[Compile-tested only - for comments-feedback]

---
 drivers/staging/media/atomisp/platform/Makefile    |   1 -
 .../staging/media/atomisp/platform/clock/Makefile  |   6 -
 .../platform/clock/platform_vlv2_plat_clk.c        |  40 ----
 .../platform/clock/platform_vlv2_plat_clk.h        |  27 ---
 .../media/atomisp/platform/clock/vlv2_plat_clock.c | 247 ---------------------
 .../platform/intel-mid/atomisp_gmin_platform.c     |  63 +++++-
 6 files changed, 51 insertions(+), 333 deletions(-)
 delete mode 100644 drivers/staging/media/atomisp/platform/clock/Makefile
 delete mode 100644 drivers/staging/media/atomisp/platform/clock/platform_vlv2_plat_clk.c
 delete mode 100644 drivers/staging/media/atomisp/platform/clock/platform_vlv2_plat_clk.h
 delete mode 100644 drivers/staging/media/atomisp/platform/clock/vlv2_plat_clock.c
drivers/staging/media/atomisp/platform/Makefile +0 -1
index df15763..0e3b7e1 100644
@@ -2,5 +2,4 @@
 # Makefile for camera drivers.
 #
 
-obj-$(CONFIG_INTEL_ATOMISP) += clock/
 obj-$(CONFIG_INTEL_ATOMISP) += intel-mid/
drivers/staging/media/atomisp/platform/clock/Makefile deleted +0 -0
deleted file mode 100644
index 82fbe8b..0000000
drivers/staging/media/atomisp/platform/clock/platform_vlv2_plat_clk.c deleted +0 -0
deleted file mode 100644
index 0aae9b0..0000000
drivers/staging/media/atomisp/platform/clock/platform_vlv2_plat_clk.h deleted +0 -0
deleted file mode 100644
index b730ab0..0000000
drivers/staging/media/atomisp/platform/clock/vlv2_plat_clock.c deleted +0 -0
deleted file mode 100644
index f96789a..0000000
drivers/staging/media/atomisp/platform/intel-mid/atomisp_gmin_platform.c +51 -12

103 lines not on this page · raw message

Signature · 1 line
2.9.3
#5 lore raw
Quoted 7 lines · Pierre-Louis Bossart

See attached an untested change to show the idea on moving to the clk API and get feedback (I am not a camera guy, just trying to help - compile-tested/checkpatch only).
This code *should* enable the same functionality using existing hooks in the kernel (and handle the BYT/CHT clocking difference as a bonus). I am sure Andy will have plenty of comments :-)

FWIW tested-by: Carlo Caione <[email protected]>

Thanks,

Signature · 1 line
Carlo Caione  |  +39.340.80.30.096  |  Endless
#6 lore raw
In reply to Pierre-Louis Bossart
Quoted 13 lines · Pierre-Louis Bossart
Quoted 4 lines
Quoted 8 lines

Looks like the same code that was initially used as a reference for support of PMC clocks in the clock framework, so now we have 2 drivers
programming the same PMC hardware, not so good. We'd probably have to
move the atomisp driver to move to clk_get/prepare/enable instead of
the old vlv2_clck_get?

Quoted 7 lines

See attached an untested change to show the idea on moving to the clk API and get feedback (I am not a camera guy, just trying to help - compile-tested/checkpatch only).
This code *should* enable the same functionality using existing hooks in
the kernel (and handle the BYT/CHT clocking difference as a bonus). I am sure Andy will have plenty of comments :-)

I have one comment: nice clean up!

AtomISP is a *horrible* mess.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#7 lore raw
Quoted 22 lines · Andy Shevchenko
Quoted 13 lines · Pierre-Louis Bossart
Quoted 4 lines
Quoted 8 lines

Looks like the same code that was initially used as a reference for support of PMC clocks in the clock framework, so now we have 2 drivers
programming the same PMC hardware, not so good. We'd probably have to
move the atomisp driver to move to clk_get/prepare/enable instead of
the old vlv2_clck_get?

Quoted 7 lines

See attached an untested change to show the idea on moving to the clk API and get feedback (I am not a camera guy, just trying to help - compile-tested/checkpatch only).
This code *should* enable the same functionality using existing hooks in
the kernel (and handle the BYT/CHT clocking difference as a bonus). I am sure Andy will have plenty of comments :-)

Quoted 4 lines

I have one comment: nice clean up!

AtomISP is a *horrible* mess.

Pierre, will you be submitting this patch officially now that you have a tested-by?

Signature · 2 lines
Darren Hart
VMware Open Source Technology Center
#8 lore raw
Quoted 23 lines · Darren Hart
Quoted 22 lines · Andy Shevchenko
Quoted 20 lines · Pierre-Louis Bossart
Quoted 4 lines
Quoted 8 lines

Looks like the same code that was initially used as a reference for support of PMC clocks in the clock framework, so now we have 2 drivers
programming the same PMC hardware, not so good. We'd probably have to
move the atomisp driver to move to clk_get/prepare/enable instead of
the old vlv2_clck_get?

See attached an untested change to show the idea on moving to the clk API and get feedback (I am not a camera guy, just trying to help - compile-tested/checkpatch only).
This code *should* enable the same functionality using existing hooks in
the kernel (and handle the BYT/CHT clocking difference as a bonus). I am sure Andy will have plenty of comments :-)

Quoted 7 lines
Quoted 4 lines

I have one comment: nice clean up!

AtomISP is a *horrible* mess.

Pierre, will you be submitting this patch officially now that you have a tested-by?

Just to clarify that my tested-by was to assert that the fix proposed by Pierre makes my system bootable again but I cannot say for sure if the atomisp driver keeps working fine after that.

Signature · 1 line
Carlo Caione  |  +39.340.80.30.096  |  Endless
#9 lore raw
In reply to Darren Hart
Quoted 18 lines · Darren Hart
Quoted 17 lines · Andy Shevchenko
Quoted 16 lines · Pierre-Louis Bossart
Quoted 9 lines

Looks like the same code that was initially used as a reference for support of PMC clocks in the clock framework, so now we have 2 drivers
programming the same PMC hardware, not so good. We'd probably have to
move the atomisp driver to move to clk_get/prepare/enable instead of
the old vlv2_clck_get?

See attached an untested change to show the idea on moving to the clk API and get feedback (I am not a camera guy, just trying to help - compile-tested/checkpatch only).
This code *should* enable the same functionality using existing hooks in
the kernel (and handle the BYT/CHT clocking difference as a bonus). I am sure Andy will have plenty of comments :-)

Quoted 6 lines
Quoted 4 lines

I have one comment: nice clean up!

AtomISP is a *horrible* mess.

Pierre, will you be submitting this patch officially now that you have a tested-by?

it was merged by Sakari this morning in the media tree

https://git.linuxtv.org/sailus/media_tree.git/log/?h=atomisp

Quoted 1 line