15 Jan, 2020

1 commit

  • commit 111bf02b8f544f98de53ea1f912ae01f598b161b upstream.

    When support for the R40 in the rtc-sun6i driver was split out for a
    separate compatible string, only the RTC half was covered, and not the
    clock half. Unfortunately this results in the whole driver not working,
    as the RTC half expects the clock half to have been initialized.

    Add support for the clock part as well. The clock part is like the H3,
    but does not need to export the internal oscillator, nor does it have
    a gateable LOSC external output.

    This fixes issues with WiFi and Bluetooth not working on the BPI M2U.

    Fixes: d6624cc75021 ("rtc: sun6i: Add R40 compatible")
    Cc: # 5.3.x
    Signed-off-by: Chen-Yu Tsai
    Acked-by: Maxime Ripard
    Link: https://lore.kernel.org/r/20191205085054.6049-1-wens@kernel.org
    Signed-off-by: Alexandre Belloni
    Signed-off-by: Greg Kroah-Hartman

    Chen-Yu Tsai
     

23 Sep, 2019

1 commit

  • Pull RTC updates from Alexandre Belloni:
    "Two new drivers and the new pcf2127 feature make the bulk of the
    additions. The rest are the usual fixes and new features.

    Subsystem:
    - add debug message when registration fails

    New drivers:
    - Amlogic Virtual Wake
    - Freescale FlexTimer Module alarm

    Drivers:
    - remove superfluous error messages
    - convert to i2c_new_dummy_device and devm_i2c_new_dummy_device
    - Remove dev_err() usage after platform_get_irq()
    - Set RTC range for: pcf2123, pcf8563, snvs.
    - pcf2127: tamper detection and watchdog support
    - pcf85363: fix regmap issue
    - sun6i: H6 support
    - remove w90x900/nuc900 driver"

    * tag 'rtc-5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (51 commits)
    rtc: meson: mark PM functions as __maybe_unused
    rtc: sc27xx: Remove clearing SPRD_RTC_POWEROFF_ALM_FLAG flag
    dt-bindings: rtc: ds1307: add rx8130 compatible
    rtc: sun6i: Allow using as wakeup source from suspend
    rtc: pcf8563: let the core handle range offsetting
    rtc: pcf8563: remove useless indirection
    rtc: pcf8563: convert to devm_rtc_allocate_device
    rtc: pcf8563: add Microcrystal RV8564 compatible
    rtc: pcf8563: add Epson RTC8564 compatible
    rtc: s35390a: convert to devm_i2c_new_dummy_device()
    rtc: max77686: convert to devm_i2c_new_dummy_device()
    rtc: pcf85363/pcf85263: fix regmap error in set_time
    rtc: snvs: switch to rtc_time64_to_tm/rtc_tm_to_time64
    rtc: snvs: set range
    rtc: snvs: fix possible race condition
    rtc: pcf2127: bugfix: watchdog build dependency
    rtc: pcf2127: add tamper detection support
    rtc: pcf2127: add watchdog feature support
    rtc: pcf2127: bugfix: read rtc disables watchdog
    rtc: pcf2127: cleanup register and bit defines
    ...

    Linus Torvalds
     

01 Sep, 2019

1 commit

  • This patch allows userspace to set up wakeup alarms on any RTC handled by the
    sun6i driver, and adds the necessary PM operations to allow resuming from
    suspend when the configured wakeup alarm fires a IRQ. Of course, that the
    device actually resumes depends on the suspend state and how a particular
    hardware reacts to it, but that is out of scope for this patch.

    I've tested these changes on a Pine H64 model B, which contains a
    Allwinner H6 SoC, with the help of CONFIG_PM_TEST_SUSPEND kernel option.
    These are the interesting outputs from the kernel and commands which
    show that it works. As every RTC handled by this driver is largely the
    same, I think that it shouldn't introduce any regression on other SoCs,
    but I may be wrong.

    [ 1.092705] PM: test RTC wakeup from 'freeze' suspend
    [ 1.098230] PM: suspend entry (s2idle)
    [ 1.212907] PM: suspend devices took 0.080 seconds
    (The SoC freezes for some seconds)
    [ 3.197604] PM: resume devices took 0.104 seconds
    [ 3.215937] PM: suspend exit

    [ 1.092812] PM: test RTC wakeup from 'mem' suspend
    [ 1.098089] PM: suspend entry (deep)
    [ 1.102033] PM: suspend exit
    [ 1.105205] PM: suspend test failed, error -22

    In any case, the RTC alarm interrupt gets fired as exptected:

    $ echo +5 > /sys/class/rtc/rtc0/wakealarm && sleep 5 && grep rtc /proc/interrupts
    29: 1 0 0 0 GICv2 133 Level 7000000.rtc

    Signed-off-by: Alejandro González
    Acked-by: Chen-Yu Tsai
    Link: https://lore.kernel.org/r/20190821210056.11995-1-alejandro.gonzalez.correo@gmail.com
    Signed-off-by: Alexandre Belloni

    Alejandro González
     

23 Aug, 2019

1 commit

  • RTC on H6 is mostly the same as on H5 and H3. It has slight differences
    mostly in features that are not yet supported by this driver.

    Some differences are already stated in the comments in existing code.
    One other difference is that H6 has extra bit in LOSC_CTRL_REG, called
    EXT_LOSC_EN to enable/disable external low speed crystal oscillator.

    It also has bit EXT_LOSC_STA in LOSC_AUTO_SWT_STA_REG, to check whether
    external low speed oscillator is working correctly.

    This patch adds support for enabling LOSC when necessary:

    - during reparenting
    - when probing the clock

    H6 also has capacbility to automatically reparent RTC clock from
    external crystal oscillator, to internal RC oscillator, if external
    oscillator fails. This is enabled by default. Disable it during
    probe.

    Signed-off-by: Ondrej Jirman
    Reviewed-by: Chen-Yu Tsai
    Link: https://lore.kernel.org/r/20190820151934.3860-3-megous@megous.com
    Signed-off-by: Alexandre Belloni

    Ondrej Jirman
     

17 Aug, 2019

1 commit

  • A future patch is going to change semantics of clk_register() so that
    clk_hw::init is guaranteed to be NULL after a clk is registered. Avoid
    referencing this member here so that we don't run into NULL pointer
    exceptions.

    Cc: Alessandro Zummo
    Cc: Alexandre Belloni
    Cc: Maxime Ripard
    Cc: Chen-Yu Tsai
    Reported-by: "kernelci.org bot"
    Signed-off-by: Stephen Boyd
    Link: https://lkml.kernel.org/r/20190815160020.183334-4-sboyd@kernel.org
    Acked-by: Chen-Yu Tsai
    Acked-by: Alexandre Belloni

    Stephen Boyd
     

13 Aug, 2019

1 commit

  • We don't need dev_err() messages when platform_get_irq() fails now that
    platform_get_irq() prints an error message itself when something goes
    wrong. Let's remove these prints with a simple semantic patch.

    //
    @@
    expression ret;
    struct platform_device *E;
    @@

    ret =
    (
    platform_get_irq(E, ...)
    |
    platform_get_irq_byname(E, ...)
    );

    if ( \( ret < 0 \| ret

    While we're here, remove braces on if statements that only have one
    statement (manually).

    Cc: Alessandro Zummo
    Cc: Alexandre Belloni
    Cc: linux-rtc@vger.kernel.org
    Cc: Greg Kroah-Hartman
    Signed-off-by: Stephen Boyd
    Link: https://lore.kernel.org/r/20190730181557.90391-40-swboyd@chromium.org
    Signed-off-by: Alexandre Belloni

    Stephen Boyd
     

18 Jul, 2019

1 commit

  • Pull RTC updates from Alexandre Belloni:
    "A quiet cycle this time.

    - ds1307: properly handle oscillator failure flags

    - imx-sc: alarm support

    - pcf2123: alarm support, correct offset handling

    - sun6i: add R40 support

    - simplify getting the adapter of an i2c client"

    * tag 'rtc-5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/abelloni/linux: (37 commits)
    rtc: wm831x: Add IRQF_ONESHOT flag
    rtc: stm32: remove one condition check in stm32_rtc_set_alarm()
    rtc: pcf2123: Fix build error
    rtc: interface: Change type of 'count' from int to u64
    rtc: pcf8563: Clear event flags and disable interrupts before requesting irq
    rtc: pcf8563: Fix interrupt trigger method
    rtc: pcf2123: fix negative offset rounding
    rtc: pcf2123: add alarm support
    rtc: pcf2123: use %ptR
    rtc: pcf2123: port to regmap
    rtc: pcf2123: remove sysfs register view
    rtc: rx8025: simplify getting the adapter of a client
    rtc: rx8010: simplify getting the adapter of a client
    rtc: rv8803: simplify getting the adapter of a client
    rtc: m41t80: simplify getting the adapter of a client
    rtc: fm3130: simplify getting the adapter of a client
    rtc: tegra: Drop MODULE_ALIAS
    rtc: sun6i: Add R40 compatible
    dt-bindings: rtc: sun6i: Add the R40 RTC compatible
    dt-bindings: rtc: Convert Allwinner A31 RTC to a schema
    ...

    Linus Torvalds
     

06 Jun, 2019

1 commit


31 May, 2019

1 commit

  • Based on 3 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version this program is distributed in the
    hope that it will be useful but without any warranty without even
    the implied warranty of merchantability or fitness for a particular
    purpose see the gnu general public license for more details

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version [author] [kishon] [vijay] [abraham]
    [i] [kishon]@[ti] [com] this program is distributed in the hope that
    it will be useful but without any warranty without even the implied
    warranty of merchantability or fitness for a particular purpose see
    the gnu general public license for more details

    this program is free software you can redistribute it and or modify
    it under the terms of the gnu general public license as published by
    the free software foundation either version 2 of the license or at
    your option any later version [author] [graeme] [gregory]
    [gg]@[slimlogic] [co] [uk] [author] [kishon] [vijay] [abraham] [i]
    [kishon]@[ti] [com] [based] [on] [twl6030]_[usb] [c] [author] [hema]
    [hk] [hemahk]@[ti] [com] this program is distributed in the hope
    that it will be useful but without any warranty without even the
    implied warranty of merchantability or fitness for a particular
    purpose see the gnu general public license for more details

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-or-later

    has been chosen to replace the boilerplate/reference in 1105 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Reviewed-by: Richard Fontana
    Reviewed-by: Kate Stewart
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190527070033.202006027@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

07 Dec, 2018

4 commits

  • 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.

    Tested-by: Corentin Labbe
    Signed-off-by: Chen-Yu Tsai
    Acked-by: Maxime Ripard
    Signed-off-by: Alexandre Belloni

    Chen-Yu Tsai
     
  • 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.

    Acked-by: Maxime Ripard
    Tested-by: Corentin Labbe
    Signed-off-by: Chen-Yu Tsai
    Signed-off-by: Alexandre Belloni

    Chen-Yu Tsai
     
  • 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.

    Acked-by: Maxime Ripard
    Tested-by: Corentin Labbe
    Signed-off-by: Chen-Yu Tsai
    Signed-off-by: Alexandre Belloni

    Chen-Yu Tsai
     
  • 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.

    Acked-by: Maxime Ripard
    Tested-by: Corentin Labbe
    Signed-off-by: Chen-Yu Tsai
    Signed-off-by: Alexandre Belloni

    Chen-Yu Tsai
     

28 Aug, 2018

1 commit

  • One of the more common cases of allocation size calculations is finding
    the size of a structure that has a zero-sized array at the end, along
    with memory for some number of elements for that array. For example:

    struct foo {
    int stuff;
    void *entry[];
    };

    instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);

    Instead of leaving these open-coded and prone to type mistakes, we can
    now use the new struct_size() helper:

    instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);

    Signed-off-by: Gustavo A. R. Silva
    Reviewed-by: Kees Cook
    Signed-off-by: Alexandre Belloni

    Gustavo A. R. Silva
     

01 Jun, 2018

1 commit

  • clk-gate core will take bit_idx through clk_register_gate
    and then do clk_gate_ops by using BIT(bit_idx), but rtc-sun6i
    is passing bit_idx as BIT(bit_idx) it becomes BIT(BIT(bit_idx)
    which is wrong and eventually external gate clock is not enabling.

    This patch fixed by passing bit index and the original change
    introduced from below commit.
    "rtc: sun6i: Add support for the external oscillator gate"
    (sha1: 17ecd246414b3a0fe0cb248c86977a8bda465b7b)

    Signed-off-by: Michael Trimarchi
    Fixes: 17ecd246414b ("rtc: sun6i: Add support for the external oscillator gate")
    Cc: stable@vger.kernel.org
    Signed-off-by: Jagan Teki
    Acked-by: Maxime Ripard
    Signed-off-by: Alexandre Belloni

    Michael Trimarchi
     

02 Mar, 2018

1 commit


19 Dec, 2017

1 commit

  • The error return path on clk_data allocation failure does not kfree
    the allocated rtc object. Fix this with a kfree of rtc on the error
    exit path.

    Detected by CoverityScan, CID#1452264 ("Resource Leak")

    Signed-off-by: Colin Ian King
    Signed-off-by: Alexandre Belloni

    Colin Ian King
     

01 Sep, 2017

1 commit

  • The RTC can output its 32kHz clock outside of the SoC, for example to clock
    a WiFi chip.

    Create a new clock that other devices will be able to retrieve, while
    maintaining the DT stability by providing a default name for that clock if
    clock-output-names doesn't list one.

    Signed-off-by: Maxime Ripard
    Signed-off-by: Alexandre Belloni

    Maxime Ripard
     

31 Jul, 2017

2 commits


12 Feb, 2017

1 commit

  • In case of error, the function of_io_request_and_map() returns ERR_PTR()
    and never returns NULL. The NULL test in the return value check should
    be replaced with IS_ERR().

    Fixes: 847b8bf62eb4 ("rtc: sun6i: Expose the 32kHz oscillator")
    Signed-off-by: Wei Yongjun
    Acked-by: Maxime Ripard
    Signed-off-by: Alexandre Belloni

    Wei Yongjun
     

01 Feb, 2017

5 commits

  • Commit 847b8bf62eb4 ("rtc: sun6i: Expose the 32kHz oscillator") adds
    a new clock for the rtc block with a 2 step probe mechanism. To share
    the register region between both the clock and rtc instance, a static
    pointer is used to keep the related data structure.

    To preserve compatibility with the old binding, the data structure
    should be saved as soon as the registers are mapped in, regardless
    of the presence of the clock bindings, so that the rtc device can
    retrieve it when it is probed.

    This fixes the rtc device not probing when we use the updated driver
    with an old device tree blob.

    Fixes: 847b8bf62eb4 ("rtc: sun6i: Expose the 32kHz oscillator")
    Signed-off-by: Chen-Yu Tsai
    Signed-off-by: Alexandre Belloni

    Chen-Yu Tsai
     
  • Now that we have a devm variant of rtc_device_register, switch to it.

    Signed-off-by: Maxime Ripard
    Signed-off-by: Alexandre Belloni

    Maxime Ripard
     
  • The RTC controls the input source of the main 32kHz oscillator in the
    system, feeding it to the clock unit too.

    By default, this is using an internal, very inaccurate (+/- 30%)
    oscillator with a divider to make it roughly around 32kHz. This is however
    quite impractical for the RTC, since our time will not be tracked properly.

    Since this oscillator is an input of the main clock unit, and since that
    clock unit will be probed using CLK_OF_DECLARE, we have to use it as well,
    leading to a two stage probe: one to enable the clock, the other one to
    enable the RTC.

    There is also a slight change in the binding that is required (and should
    have been from the beginning), since we'll need a phandle to the external
    oscillator used on that board. We support the old binding by not allowing
    to switch to the external oscillator and only using the internal one (which
    was the previous behaviour) in the case where we're missing that phandle.

    Signed-off-by: Maxime Ripard
    Acked-by: Rob Herring
    Signed-off-by: Alexandre Belloni

    Maxime Ripard
     
  • The RTC is clocked from either an internal, imprecise, oscillator or an
    external one, which is usually much more accurate.

    The difference perceived between the time elapsed and the time reported by
    the RTC is in a 10% scale, which prevents the RTC from being useful at all.

    Fortunately, the external oscillator is reported to be mandatory in the
    Allwinner datasheet, so we can just switch to it.

    Cc: stable@vger.kernel.org
    Fixes: 9765d2d94309 ("rtc: sun6i: Add sun6i RTC driver")
    Signed-off-by: Maxime Ripard
    Signed-off-by: Alexandre Belloni

    Maxime Ripard
     
  • Some registers have a read-modify-write access pattern that are not atomic.

    Add some locking to prevent from concurrent accesses.

    Cc: stable@vger.kernel.org
    Acked-by: Chen-Yu Tsai
    Signed-off-by: Maxime Ripard
    Signed-off-by: Alexandre Belloni

    Maxime Ripard
     

25 Jan, 2017

1 commit


19 Sep, 2014

1 commit

  • This patch introduces the driver for the RTC in the Allwinner A31 and
    A23 SoCs.

    Unlike the RTC found in A10/A20 SoCs, which was part of the timer, the
    RTC in A31/A23 are a separate hardware block, which also contain a few
    controls for the RTC block hardware (a regulator and RTC block GPIO pin
    latches), while also having separate interrupts for the alarms.

    The hardware is different enough to make a different driver for it.

    Signed-off-by: Chen-Yu Tsai
    Reviewed-by: Varka Bhadram
    Signed-off-by: Maxime Ripard

    Chen-Yu Tsai