sun4i CCU CCF vs CSI0 question (Re: [PATCH] doc sunxi: update CCU wiki page link in clocks.rst)

43 views
Skip to first unread message

Oleg Verych

unread,
Feb 5, 2023, 2:50:25 PM2/5/23
to open list:ARM/Allwinner sunXi SoC support, Priit Laes, Gregory CLEMENT, Emilio López, Maxime Ripard, Chen-Yu Tsai, linux-sunxi, Oleg Verych
Hello!

On 1/17/23, Oleg Verych <ole...@gmail.com> wrote:
> Update wiki page link to the Allwinner sunXi SoC Clock Control Module.
>
> Signed-off-by: Oleg Verych <ole...@gmail.com>
> ---
> Hi!
>
> Can I ask additional question to those in the file?

Q:
> How is it possible to setup PLL7 to particular frequency and select
> it as a source to CSI0 via CCM_CSI0_CLK[1]?

A:
by setting clock source and frequency via CCF[2] in a camera device as:

```
ov5640: camera@3c {
compatible = "ovti,ov5640";
reg = <0x3c>;
pinctrl-names = "default";
pinctrl-0 = <&csi0_clk_pin>;
clocks = <&ccu CLK_CSI0>;
clock-names = "xclk";

assigned-clocks = <&ccu CLK_CSI0>, <&ccu 17>; /* 17 = CLK_PLL_VIDEO1 * /
assigned-clock-rates = <32000000>;
assigned-clock-parents = <&ccu 17>;
...
port {
ov5640_to_csi0: endpoint {
...

```
[2] https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/clock/clock.yaml

Set of other related questions:

Q: When trying to setup main CSI0 clock to 32MHz from example above,
it is not possible to get integer mode value:

sun4i_csi_probe mclk: 31578948 Hz

Why it is so, while PLL7 can be configured to (3*(9 + 23)) = 96 MHz
which then can be divided by (2 + 1) using CCM_CSI0_CLK [1] /
CSI0_CLK_REG [A20_User_Manual_v1.4_20150510.pdf p.84]?

Q: Initial value for CSI0 ISP clock is not as hardcoded in
`sun4i_csi_runtime_resume()`. Is it correct to hardcode the value for
resume? E.g.[3]:
```
clk_prepare_enable(csi->ram_clk);
>> clk_set_rate(csi->isp_clk, 80000000);
clk_prepare_enable(csi->isp_clk);
```
[3] https://elixir.bootlin.com/linux/v6.1/source/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c#L303


Q: Is there a good guide / how-to somewhere on how to suspend/resume
A20-processor based devices, e.g. for `sun4i_csi_runtime_resume()`
testing?

Thanks!

> Is it possible to put such device tree example in documentation?
>
> Thanks!

[1] https://linux-sunxi.org/Clock_Control_Module#CCM_CSI0_CLK

> Documentation/arm/sunxi/clocks.rst | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/Documentation/arm/sunxi/clocks.rst
> b/Documentation/arm/sunxi/clocks.rst
> index 23bd03f3e..f435bdd70 100644
> --- a/Documentation/arm/sunxi/clocks.rst
> +++ b/Documentation/arm/sunxi/clocks.rst
> @@ -49,7 +49,7 @@ Q: Were can I learn more about the sunxi clocks?
> A: The linux-sunxi wiki contains a page documenting the clock registers,
> you can find it at
>
> - http://linux-sunxi.org/A10/CCM
> + https://linux-sunxi.org/Clock_Control_Module
>
> The authoritative source for information at this time is the ccmu
> driver
> released by Allwinner, you can find it at
> --
> 2.20.1
>
>
--
sed 'sh && sed && node.js + olecom = happiness and mirth' << ''
-o--=O`C
#oo'L O
<___=E M

Maxime Ripard

unread,
Feb 7, 2023, 4:06:55 AM2/7/23
to Oleg Verych, open list:ARM/Allwinner sunXi SoC support, Priit Laes, Gregory CLEMENT, Emilio López, Chen-Yu Tsai, linux-sunxi
On Sun, Feb 05, 2023 at 09:50:22PM +0200, Oleg Verych wrote:
> Hello!
>
> On 1/17/23, Oleg Verych <ole...@gmail.com> wrote:
> > Update wiki page link to the Allwinner sunXi SoC Clock Control Module.
> >
> > Signed-off-by: Oleg Verych <ole...@gmail.com>
> > ---
> > Hi!
> >
> > Can I ask additional question to those in the file?
>
> Q:
> > How is it possible to setup PLL7 to particular frequency and select
> > it as a source to CSI0 via CCM_CSI0_CLK[1]?
>
> A:
> by setting clock source and frequency via CCF[2] in a camera device as:
>
> ```
> ov5640: camera@3c {
> compatible = "ovti,ov5640";
> reg = <0x3c>;
> pinctrl-names = "default";
> pinctrl-0 = <&csi0_clk_pin>;
> clocks = <&ccu CLK_CSI0>;
> clock-names = "xclk";
>
> assigned-clocks = <&ccu CLK_CSI0>, <&ccu 17>; /* 17 = CLK_PLL_VIDEO1 * /

You don't need the second clock.

> assigned-clock-rates = <32000000>;
> assigned-clock-parents = <&ccu 17>;
> ...
> port {
> ov5640_to_csi0: endpoint {
> ...
>
> ```
> [2] https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/clock/clock.yaml

I'm not sure why you're trying to do that in the first place, but please
note that this isn't a guarantee in any way. It could change at any
point in time after probe has been called.

> Set of other related questions:
>
> Q: When trying to setup main CSI0 clock to 32MHz from example above,
> it is not possible to get integer mode value:
>
> sun4i_csi_probe mclk: 31578948 Hz
>
> Why it is so, while PLL7 can be configured to (3*(9 + 23)) = 96 MHz
> which then can be divided by (2 + 1) using CCM_CSI0_CLK [1] /
> CSI0_CLK_REG [A20_User_Manual_v1.4_20150510.pdf p.84]?

I think what happens with your DT bits is that CLK_CSI0 and PLL_VIDEO1
will be set to 32MHz, in that order.

> Q: Initial value for CSI0 ISP clock is not as hardcoded in
> `sun4i_csi_runtime_resume()`. Is it correct to hardcode the value for
> resume? E.g.[3]:
> ```
> clk_prepare_enable(csi->ram_clk);
> >> clk_set_rate(csi->isp_clk, 80000000);
> clk_prepare_enable(csi->isp_clk);
> ```
> [3] https://elixir.bootlin.com/linux/v6.1/source/drivers/media/platform/sunxi/sun4i-csi/sun4i_csi.c#L303

I guess? What's wrong with it?

> Q: Is there a good guide / how-to somewhere on how to suspend/resume
> A20-processor based devices, e.g. for `sun4i_csi_runtime_resume()`
> testing?

runtime PM is not related to suspend/resume. It will start and stop the
device whenever it's actually used instead of keeping it on all the
time.

If you start a capture and it works, then you've tested runtime PM

Maxime

Oleg Verych

unread,
Feb 7, 2023, 10:55:28 AM2/7/23
to Maxime Ripard, open list:ARM/Allwinner sunXi SoC support, Priit Laes, Gregory CLEMENT, Emilio López, Chen-Yu Tsai, linux-sunxi
Hello!
I see, thanks.

>> Set of other related questions:
>>
>> Q: When trying to setup main CSI0 clock to 32MHz from example above,
>> it is not possible to get integer mode value:
>>
>> sun4i_csi_probe mclk: 31578948 Hz
>>
>> Why it is so, while PLL7 can be configured to (3*(9 + 23)) = 96 MHz
>> which then can be divided by (2 + 1) using CCM_CSI0_CLK [1] /
>> CSI0_CLK_REG [A20_User_Manual_v1.4_20150510.pdf p.84]?
>
> I think what happens with your DT bits is that CLK_CSI0 and PLL_VIDEO1
> will be set to 32MHz, in that order.
>

Reading all clk-related replies along with the calculations they led
me to this solution, which works:
```
[ 340.017355] ?dvp-csi-dev ?sun4i_csi_probe mclk: 32000000 Hz
assigned-clocks = <&ccu CLK_CSI0>, <&ccu 17>;
assigned-clock-parents = <&ccu 17>;
assigned-clock-rates = <32000000>, <96000000>;
```

Thanks, very appreciated!
__________

JuanEsf

unread,
Oct 4, 2023, 1:08:24 PM10/4/23
to linux-sunxi
Hi Oleg...
I have an ov5640 camera from a pinecube and a bananapi m2 ultra board (Allwinner R40) with a sun4i-csi controller. I am trying to activate the camera in armbian with kernel 6.4 among others.
I am following Chen-Yu Tsai's demo patch[1].
The sun4i-csi and ov5640 module among others is loaded but I cannot capture images or videos. Do you have a camera running on the sun4i-csi controller?
And what program and/or parameters are you using? could you guide me?


(Camera tested on BSP Ubuntu with kernel 3.10)

IMG_20230921_233748.jpg
Reply all
Reply to author
Forward
0 new messages