All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC 0/3] soc/fsl: various fixes for QE support
@ 2017-01-27 13:15 Valentin Longchamp
  2017-01-27 13:15 ` [RFC 1/3] soc/fsl/qe: round brg_freq to 1kHz granularity Valentin Longchamp
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Valentin Longchamp @ 2017-01-27 13:15 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: qiang.zhao, oss, Valentin Longchamp

Testing the QE's UCC for our HDLC bus I noticed a few odd things and I have
fixed these in these 3 patches.

Valentin Longchamp (3):
  soc/fsl/qe: round brg_freq to 1kHz granularity
  soc/fsl/qe: only apply QE_General4 workaround on affected SoCs
  soc/fsl/qe: add EXPORT_SYMBOL for the 2 qe_tdm functions

 drivers/soc/fsl/qe/qe.c     | 21 +++++++++++++++++++--
 drivers/soc/fsl/qe/qe_tdm.c |  2 ++
 2 files changed, 21 insertions(+), 2 deletions(-)

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [RFC 1/3] soc/fsl/qe: round brg_freq to 1kHz granularity
  2017-01-27 13:15 [RFC 0/3] soc/fsl: various fixes for QE support Valentin Longchamp
@ 2017-01-27 13:15 ` Valentin Longchamp
  2017-01-27 13:15 ` [RFC 2/3] soc/fsl/qe: only apply QE_General4 workaround on affected SoCs Valentin Longchamp
  2017-01-27 13:15 ` [RFC 3/3] soc/fsl/qe: add EXPORT_SYMBOL for the 2 qe_tdm functions Valentin Longchamp
  2 siblings, 0 replies; 4+ messages in thread
From: Valentin Longchamp @ 2017-01-27 13:15 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: qiang.zhao, oss, Valentin Longchamp

Because of integer computation rounding in u-boot (that sets the QE
brg-frequency DTS prop), the clk value is 99999999 Hz even though it is
100 MHz.

When setting brg clks that are exact divisors of 100 MHz, this small
differnce plays a role and can result in lower clks to be output (for
instance 20 MHz - divide by 5 - results in 16.666 MHz - divide by 6).

This patch fixes that by "forcing" the brg_clk to the nearest kHz when
the difference is below 2 integer rouding errors (i.e. 4).

Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
---
 drivers/soc/fsl/qe/qe.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c
index 2707a82..5482302 100644
--- a/drivers/soc/fsl/qe/qe.c
+++ b/drivers/soc/fsl/qe/qe.c
@@ -163,11 +163,15 @@ int qe_issue_cmd(u32 cmd, u32 device, u8 mcn_protocol, u32 cmd_input)
  */
 static unsigned int brg_clk = 0;
 
+#define CLK_GRAN	(1000)
+#define CLK_GRAN_LIMIT	(5)
+
 unsigned int qe_get_brg_clk(void)
 {
 	struct device_node *qe;
 	int size;
 	const u32 *prop;
+	unsigned int mod;
 
 	if (brg_clk)
 		return brg_clk;
@@ -185,6 +189,15 @@ unsigned int qe_get_brg_clk(void)
 
 	of_node_put(qe);
 
+	/* round this if near to a multiple of CLK_GRAN */
+	mod = brg_clk % CLK_GRAN;
+	if (mod) {
+		if (mod < CLK_GRAN_LIMIT)
+			brg_clk -= mod;
+		else if (mod > (CLK_GRAN - CLK_GRAN_LIMIT))
+			brg_clk += CLK_GRAN - mod;
+	}
+
 	return brg_clk;
 }
 EXPORT_SYMBOL(qe_get_brg_clk);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [RFC 2/3] soc/fsl/qe: only apply QE_General4 workaround on affected SoCs
  2017-01-27 13:15 [RFC 0/3] soc/fsl: various fixes for QE support Valentin Longchamp
  2017-01-27 13:15 ` [RFC 1/3] soc/fsl/qe: round brg_freq to 1kHz granularity Valentin Longchamp
@ 2017-01-27 13:15 ` Valentin Longchamp
  2017-01-27 13:15 ` [RFC 3/3] soc/fsl/qe: add EXPORT_SYMBOL for the 2 qe_tdm functions Valentin Longchamp
  2 siblings, 0 replies; 4+ messages in thread
From: Valentin Longchamp @ 2017-01-27 13:15 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: qiang.zhao, oss, Valentin Longchamp

The QE_General4 workaround is only valid for the MPC832x and MPC836x
SoCs. The other SoCs that embed a QUICC engine are not affected by this
hardware bug and thus can use the computed divisors (this was
successfully tested on the T1040).

Similalry to what was done in commit 8ce795cb0c6b ("i2c: mpc: assign the
correct prescaler from SVR") in order to avoid changes in
the device tree nodes of the QE (with maybe a variant of the compatible
property), the PVR reg is read out to find out if the workaround must be
applied or not.

Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
---
 drivers/soc/fsl/qe/qe.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/soc/fsl/qe/qe.c b/drivers/soc/fsl/qe/qe.c
index 5482302..8cf9493 100644
--- a/drivers/soc/fsl/qe/qe.c
+++ b/drivers/soc/fsl/qe/qe.c
@@ -202,6 +202,9 @@ unsigned int qe_get_brg_clk(void)
 }
 EXPORT_SYMBOL(qe_get_brg_clk);
 
+#define PVR_VER_836x	0x8083
+#define PVR_VER_832x	0x8084
+
 /* Program the BRG to the given sampling rate and multiplier
  *
  * @brg: the BRG, QE_BRG1 - QE_BRG16
@@ -228,8 +231,9 @@ int qe_setbrg(enum qe_clock brg, unsigned int rate, unsigned int multiplier)
 	/* Errata QE_General4, which affects some MPC832x and MPC836x SOCs, says
 	   that the BRG divisor must be even if you're not using divide-by-16
 	   mode. */
-	if (!div16 && (divisor & 1) && (divisor > 3))
-		divisor++;
+	if (pvr_version_is(PVR_VER_836x) || pvr_version_is(PVR_VER_832x))
+		if (!div16 && (divisor & 1) && (divisor > 3))
+			divisor++;
 
 	tempval = ((divisor - 1) << QE_BRGC_DIVISOR_SHIFT) |
 		QE_BRGC_ENABLE | div16;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [RFC 3/3] soc/fsl/qe: add EXPORT_SYMBOL for the 2 qe_tdm functions
  2017-01-27 13:15 [RFC 0/3] soc/fsl: various fixes for QE support Valentin Longchamp
  2017-01-27 13:15 ` [RFC 1/3] soc/fsl/qe: round brg_freq to 1kHz granularity Valentin Longchamp
  2017-01-27 13:15 ` [RFC 2/3] soc/fsl/qe: only apply QE_General4 workaround on affected SoCs Valentin Longchamp
@ 2017-01-27 13:15 ` Valentin Longchamp
  2 siblings, 0 replies; 4+ messages in thread
From: Valentin Longchamp @ 2017-01-27 13:15 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: qiang.zhao, oss, Valentin Longchamp

This allows to build the fsl_ucc_hdlc driver as a module.

Signed-off-by: Valentin Longchamp <valentin.longchamp@keymile.com>
---
 drivers/soc/fsl/qe/qe_tdm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/soc/fsl/qe/qe_tdm.c b/drivers/soc/fsl/qe/qe_tdm.c
index a1048b4..f744c21 100644
--- a/drivers/soc/fsl/qe/qe_tdm.c
+++ b/drivers/soc/fsl/qe/qe_tdm.c
@@ -177,6 +177,7 @@ int ucc_of_parse_tdm(struct device_node *np, struct ucc_tdm *utdm,
 	devm_iounmap(&pdev->dev, utdm->si_regs);
 	return ret;
 }
+EXPORT_SYMBOL(ucc_of_parse_tdm);
 
 void ucc_tdm_init(struct ucc_tdm *utdm, struct ucc_tdm_info *ut_info)
 {
@@ -274,3 +275,4 @@ void ucc_tdm_init(struct ucc_tdm *utdm, struct ucc_tdm_info *ut_info)
 		break;
 	}
 }
+EXPORT_SYMBOL(ucc_tdm_init);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-01-27 13:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-27 13:15 [RFC 0/3] soc/fsl: various fixes for QE support Valentin Longchamp
2017-01-27 13:15 ` [RFC 1/3] soc/fsl/qe: round brg_freq to 1kHz granularity Valentin Longchamp
2017-01-27 13:15 ` [RFC 2/3] soc/fsl/qe: only apply QE_General4 workaround on affected SoCs Valentin Longchamp
2017-01-27 13:15 ` [RFC 3/3] soc/fsl/qe: add EXPORT_SYMBOL for the 2 qe_tdm functions Valentin Longchamp

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.