Message ID | 20181128093013.24442-1-wens@csie.org |
---|---|
Headers | show |
Series | rtc: sun6i: clock rework and pre-H6 SoC support | expand |
On Wed, Nov 28, 2018 at 5:30 PM Chen-Yu Tsai <wens@csie.org> wrote: > > There are different variants to the RTC hardware first seen on sun6i > (A31). The differences we care about in this driver are the clock rate > for the internal oscillator, prescalers, and the presence of an external > clock output. > > This patch adds support for all the known base compatibles using the > variants data structure previously introduced. > > Signed-off-by: Chen-Yu Tsai <wens@csie.org> This one was from a prior WiP version. Please ignore it. ChenYu
On Wed, Nov 28, 2018 at 05:30:02PM +0800, Chen-Yu Tsai wrote: > The RTC's main clock, used internally and exported to the rest of the > SoC, is called "LOSC" (low speed oscillator) through the hardware > documentation. > > This patch adds a default name for this clock, in case the device tree > does not provide one. This shouldn't happen, but lets play it safe. > > Signed-off-by: Chen-Yu Tsai <wens@csie.org> Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> Maxime
On Wed, Nov 28, 2018 at 05:30:03PM +0800, Chen-Yu Tsai wrote: > Amongst the Allwinner SoCs that have seen some kind of coverage by the > linux-sunxi community, whether it be mainline Linux or U-boot support, > or just available datasheets, most newer chips use the RTC design first > seen in the A31 (sun6i). > > Overall there have been some minor differences. This patch covers the > following: > > - average clock rate of the internal RC oscillator > + presence of fixed and adjustable prescaler for this clock > - availability of an external (to the SoC) clock output > > One major difference regarding the H6 is the 24 MHz crystal is now > routed through the RTC, as a digitally compensated oscillator (DCXO). > This is not covered in this patch and will be supported later. > > Other differences are either unrelated to RTC or clock functionality, > such as boot or crypto related registers, or the driver simply doesn't > use the feature in question. One example of the latter is the > calibration function for the RC oscillator. We consider this clock to > be very bad and avoid using it. > > Signed-off-by: Chen-Yu Tsai <wens@csie.org> Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> Maxime
On Wed, Nov 28, 2018 at 05:30:04PM +0800, Chen-Yu Tsai wrote: > There are different variants to the RTC hardware first seen on sun6i > (A31). The differences we care about in this driver are the clock rate > for the internal oscillator, prescalers, and the presence of an external > clock output. > > This patch adds support for all the known pre-H6 base compatibles using > the variants data structure previously introduced. > > Signed-off-by: Chen-Yu Tsai <wens@csie.org> Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> Maxime
On Wed, Nov 28, 2018 at 05:30:07PM +0800, Chen-Yu Tsai wrote: > On the R40, in addition to a mux between the RTC's own RC oscillator and > an external 32768 Hz crystal, which are muxed inside the RTC module, the > CCU also has its own RC oscillator, which runs at around 2 MHz, and can > be muxed with the LOSC output from the RTC. This muxed output is called > "SYS 32K" in the module clock diagram, but otherwise referred to as the > LOSC throughout the CCU documentation. > > The RC oscillator is not very accurate, even though it has an undocumented > calibration function. We really want a precise clock at 32768 Hz, > instead of something at around 32 KHz. This patch forces the SYS 32K > clock to use the RTC output as its parent, and doesn't bother > registering the internal oscillator nor a clock mux. > > Signed-off-by: Chen-Yu Tsai <wens@csie.org> Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> Maxime
On Wed, Nov 28, 2018 at 05:30:08PM +0800, Chen-Yu Tsai wrote: > The RTC module on the A23 was claimed to be the same as on the A31, when > in fact it is not. The A31 does not have an RTC external clock output, > and its internal RC oscillator's average clock rate is not in the same > range. The A33's RTC is the same as the A23. > > This patch fixes the compatible string and clock properties to conform > to the updated bindings. The register range is also fixed. > > Signed-off-by: Chen-Yu Tsai <wens@csie.org> Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> Maxime
On Wed, Nov 28, 2018 at 05:30:09PM +0800, Chen-Yu Tsai wrote: > The H3 datasheet specifies a tolerance range for the external > oscillators used. Add them to the device tree as the clock accuracy. > The internal oscillator is left unchanged, as it will be removed later. > > Signed-off-by: Chen-Yu Tsai <wens@csie.org> Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> Maxime
On Wed, Nov 28, 2018 at 05:30:10PM +0800, Chen-Yu Tsai wrote: > The RTC module on the H3 was claimed to be the same as on the A31, when > in fact it is not. The A31 does not have an RTC external clock output, > and its internal RC oscillator's average clock rate is not in the same > range. The H5's RTC has some extra crypto-related registers compared to > the H3. Their exact functions are not clear. Also the RTC-VIO regulator > has different settings. > > This patch fixes the compatible string and clock properties to conform > to the updated bindings. The device node for the internal oscillator is > removed, as it is internalized into the RTC device. Clock references to > the IOSC and LOSC are also fixed. > > Signed-off-by: Chen-Yu Tsai <wens@csie.org> Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> > squash! ARM: dts: sunxi: h3/h5: Fix up RTC device node and clock references But you might want to remove that :) Maxime
On Wed, Nov 28, 2018 at 05:30:11PM +0800, Chen-Yu Tsai wrote: > The R40 datasheet specifies a tolerance range for the external > oscillators used. Add them to the device tree as the clock accuracy. > > Signed-off-by: Chen-Yu Tsai <wens@csie.org> Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> Maxime
On Wed, Nov 28, 2018 at 05:30:12PM +0800, Chen-Yu Tsai wrote: > The R40 has an RTC hardware block, which has additional registers > that are not related to RTC or clock functions, and is otherwise > compatible with the H3's RTC. > > Add a device node for it, and fix up any references to the LOSC. > > Signed-off-by: Chen-Yu Tsai <wens@csie.org> Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> Maxime
On Wed, Nov 28, 2018 at 05:30:13PM +0800, Chen-Yu Tsai wrote: > The RTC module on the A64 was claimed to be the same as on the A31, when > in fact it is not. It is actually compatible to the H3's RTC. The A64's > RTC has some extra crypto-related registers which the H3's does not, but > the exact function of these is not clear. > > This patch fixes the compatible string and clock properties to conform > to the updated bindings. The device node for the internal oscillator is > removed, as it is internalized into the RTC device. Clock references to > the IOSC and LOSC are also fixed. > > Signed-off-by: Chen-Yu Tsai <wens@csie.org> Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> Maxime
65;5402;1c On Wed, Nov 28, 2018 at 05:30:06PM +0800, Chen-Yu Tsai wrote: > The bindings have been updated to expose the RTC's internal oscillator, > for some SoCs that have it directly feeding the PRCM block. The changes > include the index 2 for the clock outputs, as well as the clock output > names. > > This patch adds the internal oscillator to the list of clocks exposed > through of_clk_add_hw_provider(), and also have the driver optionally > fetch the name of the clock from the device tree if it's available. > > Signed-off-by: Chen-Yu Tsai <wens@csie.org> > --- > drivers/rtc/rtc-sun6i.c | 10 +++++++--- > 1 file changed, 7 insertions(+), 3 deletions(-) > > diff --git a/drivers/rtc/rtc-sun6i.c b/drivers/rtc/rtc-sun6i.c > index 62ed9ce53d8c..273ab7fbbbe3 100644 > --- a/drivers/rtc/rtc-sun6i.c > +++ b/drivers/rtc/rtc-sun6i.c > @@ -220,6 +220,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, > .ops = &sun6i_rtc_osc_ops, > .name = "losc", > }; > + const char *iosc_name = "rtc-int-osc"; > const char *clkout_name = "osc32k-out"; > const char *parents[2]; > > @@ -228,7 +229,7 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, > return; > > rtc->data = data; > - clk_data = kzalloc(struct_size(clk_data, hws, 2), GFP_KERNEL); > + clk_data = kzalloc(struct_size(clk_data, hws, 3), GFP_KERNEL); > if (!clk_data) { > kfree(rtc); > return; > @@ -253,8 +254,10 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, > if (!of_get_property(node, "clocks", NULL)) > goto err; > > + of_property_read_string_index(node, "clock-output-names", 2, > + &iosc_name); > rtc->int_osc = clk_hw_register_fixed_rate_with_accuracy(NULL, > - "rtc-int-osc", > + iosc_name, > NULL, 0, > rtc->data->rc_osc_rate, > 300000000); > @@ -290,9 +293,10 @@ static void __init sun6i_rtc_clk_init(struct device_node *node, > return; > } > > - clk_data->num = 2; > + clk_data->num = 3; > clk_data->hws[0] = &rtc->hw; > clk_data->hws[1] = __clk_get_hw(rtc->ext_losc); > + clk_data->hws[2] = rtc->int_osc; Shouldn't we add a check on either the compatible on the number of clock-output-names? Maxime
On Wed, Nov 28, 2018 at 05:29:57PM +0800, Chen-Yu Tsai wrote: > Hi everyone, > > This series was started as part of enabling Bluetooth on various > Allwinner SBCs. The bluetooth controller requires a precise 32.768 kHz > clock fed to it to correctly detect the frequency of its main oscillator. > This clock signal is provided by the RTC, either directly from a special > pin on the SoC, or some clock output function from the clock controllers. > I found that the clock-related properties of the RTC on later SoCs were > incorrect or missing. > > This series reworks the compatible strings and clock parts of the device > tree bindings for sun6i-rtc. Currently we assume most Allwinner SoCs use > the same sun6i-rtc variant, when in fact they do not. The differences > that matter with regards to clocks are a) the A31 does not have an extra > external output for the RTC 32K clock, while most of the others do; > b) the clock frequency of the internal RC oscillator is different on > some SoCs; c) on the H6 the RTC also handles the 24 MHz DCXO, which > feeds the system HOSC. The last difference, and by extension the H6, are > not covered in this series. > > Patch 1 cleans up the clock-related section of the RTC device tree > binding. This would make it easier to read and easier to add additional > clocks. > > Patch 2 adds compatible strings for all identified variants introduced > prior to the H6. > > Patch 3 deprecates the external clock output for the A31. The A31 does > not have this output, so it's introduction and usage was an error. > > Patch 4 adds a clock output for the RTC's internal oscillator to the > device tree binding. This feeds the PRCM in some SoCs. > > Patch 5 adds a default clock name for the LOSC to the RTC driver. > > Patch 6 adds support for different hardware variants to the RTC driver. > > Patch 7 adds support for all known pre-H6 variants. > > Patch 8 exposes the RTC's internal oscillator through the device tree. > > Patch 9 makes the R40's CCU use the LOSC from the RTC module, instead of > its own internal oscillator. > > Patch 10 through 15 adds an RTC node or fixes up the RTC device node > address ranges, clock properties, names of existing clocks, and adds > accuracy properties for the external fixed oscillators. > > The clock names require fixing because the sunxi clock driver implicitly > depends on the HOSC and LOSC being named "osc24M" and "osc32k". The > "fixes" to the clock hierarchy introduced in this series means the names > must also be shuffled around or the in kernel representation would be > incorrect. This has been the case since the sunxi-ng drivers were > introduced. There are plans to address this, but the code is still in its > early stages. > > Please have a look. > > Thanks > ChenYu > > Chen-Yu Tsai (15): > dt-bindings: rtc: sun6i-rtc: Rewrite clock outputs as a list > dt-bindings: rtc: sun6i-rtc: Add compatible strings for pre-H6 > variants > dt-bindings: rtc: sun6i-rtc: Deprecate external clock output for A31 > dt-bindings: rtc: sun6i-rtc: Export internal RC oscillator > rtc: sun6i: Add default clock name for LOSC > rtc: sun6i: Add support for different variants > rtc: sun6i: Add support for all known pre-H6 variants > rtc: sun6i: Expose internal oscillator through device tree > clk: sunxi-ng: r40: Force LOSC parent to RTC LOSC output > ARM: dts: sun8i: a23/a33: Fix up RTC device node > ARM: dts: sunxi: h3/h5: Add clock accuracy for external oscillators > ARM: dts: sunxi: h3/h5: Fix up RTC device node and clock references > ARM: dts: sun8i: r40: Add clock accuracy for external oscillators > ARM: dts: sun8i: r40: Add RTC device node > arm64: dts: allwinner: a64: Fix up RTC device node and clock > references > > .../devicetree/bindings/rtc/sun6i-rtc.txt | 31 ++++- > arch/arm/boot/dts/sun8i-a23-a33.dtsi | 6 +- > arch/arm/boot/dts/sun8i-h3.dtsi | 4 + > arch/arm/boot/dts/sun8i-r40.dtsi | 18 ++- > arch/arm/boot/dts/sunxi-h3-h5.dtsi | 28 ++--- > arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi | 22 ++-- > arch/arm64/boot/dts/allwinner/sun50i-h5.dtsi | 4 + > drivers/clk/sunxi-ng/ccu-sun8i-r40.c | 11 ++ > drivers/rtc/rtc-sun6i.c | 117 ++++++++++++++++-- > 9 files changed, 188 insertions(+), 53 deletions(-) > > -- Hello Tested-by: Corentin Labbe <clabbe.montjoie@gmail.com> Tested-on: sun8i-r40-bananapi-m2-ultra Tested-on: sun50i-h5-nanopi-neo-plus2 Regards
Quoting Chen-Yu Tsai (2018-11-28 01:30:07) > On the R40, in addition to a mux between the RTC's own RC oscillator and > an external 32768 Hz crystal, which are muxed inside the RTC module, the > CCU also has its own RC oscillator, which runs at around 2 MHz, and can > be muxed with the LOSC output from the RTC. This muxed output is called > "SYS 32K" in the module clock diagram, but otherwise referred to as the > LOSC throughout the CCU documentation. > > The RC oscillator is not very accurate, even though it has an undocumented > calibration function. We really want a precise clock at 32768 Hz, > instead of something at around 32 KHz. This patch forces the SYS 32K > clock to use the RTC output as its parent, and doesn't bother > registering the internal oscillator nor a clock mux. > > Signed-off-by: Chen-Yu Tsai <wens@csie.org> > --- Acked-by: Stephen Boyd <sboyd@kernel.org>
On Thu, Nov 29, 2018 at 5:29 AM Stephen Boyd <sboyd@kernel.org> wrote: > > Quoting Chen-Yu Tsai (2018-11-28 01:30:07) > > On the R40, in addition to a mux between the RTC's own RC oscillator and > > an external 32768 Hz crystal, which are muxed inside the RTC module, the > > CCU also has its own RC oscillator, which runs at around 2 MHz, and can > > be muxed with the LOSC output from the RTC. This muxed output is called > > "SYS 32K" in the module clock diagram, but otherwise referred to as the > > LOSC throughout the CCU documentation. > > > > The RC oscillator is not very accurate, even though it has an undocumented > > calibration function. We really want a precise clock at 32768 Hz, > > instead of something at around 32 KHz. This patch forces the SYS 32K > > clock to use the RTC output as its parent, and doesn't bother > > registering the internal oscillator nor a clock mux. > > > > Signed-off-by: Chen-Yu Tsai <wens@csie.org> > > --- > > Acked-by: Stephen Boyd <sboyd@kernel.org> Merged with acks from Maxime and Stephen.