2018-08-22 01:02:14 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-10-16 12:41:19 +03:00
|
|
|
/*
|
|
|
|
* Renesas Clock Pulse Generator / Module Standby and Software Reset
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Glider bvba
|
|
|
|
*
|
|
|
|
* Based on clk-mstp.c, clk-rcar-gen2.c, and clk-rcar-gen3.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Ideas On Board SPRL
|
|
|
|
* Copyright (C) 2015 Renesas Electronics Corp.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/clk-provider.h>
|
2016-03-04 19:03:46 +03:00
|
|
|
#include <linux/clk/renesas.h>
|
2017-01-20 13:03:03 +03:00
|
|
|
#include <linux/delay.h>
|
2015-10-16 12:41:19 +03:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/init.h>
|
2019-04-19 01:20:22 +03:00
|
|
|
#include <linux/io.h>
|
2015-10-16 12:41:19 +03:00
|
|
|
#include <linux/mod_devicetable.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/of_device.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/pm_clock.h>
|
|
|
|
#include <linux/pm_domain.h>
|
clk: renesas: cpg-mssr: Restore module clocks during resume
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
clock register state is lost. Note that as the boot loader skips most
initialization after system resume, clock register state differs from
the state encountered during normal system boot, too.
Hence after s2ram, some operations may fail because module clocks are
disabled, while drivers expect them to be still enabled. E.g. EtherAVB
fails when Wake-on-LAN has been enabled using "ethtool -s eth0 wol g":
ravb e6800000.ethernet eth0: failed to switch device to config mode
ravb e6800000.ethernet eth0: device will be stopped after h/w processes are done.
ravb e6800000.ethernet eth0: failed to switch device to config
PM: Device e6800000.ethernet failed to resume: error -110
In addition, some module clocks that were disabled by
clk_disable_unused() may have been re-enabled, wasting power.
To fix this, restore all bits of the SMSTPCR registers that represent
clocks under control of Linux.
Notes:
- While this fixes EtherAVB operation after resume from s2ram,
EtherAVB cannot be used as an actual wake-up source from s2ram, only
from s2idle, due to PSCI limitations,
- To avoid overhead on platforms not needing it, the suspend/resume
code has a build time dependency on sleep and PSCI support, and a
runtime dependency on PSCI.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
2017-06-07 14:20:06 +03:00
|
|
|
#include <linux/psci.h>
|
2017-01-20 13:03:03 +03:00
|
|
|
#include <linux/reset-controller.h>
|
2015-10-16 12:41:19 +03:00
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
#include <dt-bindings/clock/renesas-cpg-mssr.h>
|
|
|
|
|
|
|
|
#include "renesas-cpg-mssr.h"
|
|
|
|
#include "clk-div6.h"
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define WARN_DEBUG(x) WARN_ON(x)
|
2016-10-03 14:03:38 +03:00
|
|
|
#else
|
|
|
|
#define WARN_DEBUG(x) do { } while (0)
|
2015-10-16 12:41:19 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Module Standby and Software Reset register offets.
|
|
|
|
*
|
|
|
|
* If the registers exist, these are valid for SH-Mobile, R-Mobile,
|
2017-01-20 12:53:11 +03:00
|
|
|
* R-Car Gen2, R-Car Gen3, and RZ/G1.
|
2015-10-16 12:41:19 +03:00
|
|
|
* These are NOT valid for R-Car Gen1 and RZ/A1!
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Module Stop Status Register offsets
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const u16 mstpsr[] = {
|
|
|
|
0x030, 0x038, 0x040, 0x048, 0x04C, 0x03C, 0x1C0, 0x1C4,
|
|
|
|
0x9A0, 0x9A4, 0x9A8, 0x9AC,
|
|
|
|
};
|
|
|
|
|
2021-12-01 10:33:02 +03:00
|
|
|
static const u16 mstpsr_for_gen4[] = {
|
2020-09-11 10:43:51 +03:00
|
|
|
0x2E00, 0x2E04, 0x2E08, 0x2E0C, 0x2E10, 0x2E14, 0x2E18, 0x2E1C,
|
2021-12-01 10:33:02 +03:00
|
|
|
0x2E20, 0x2E24, 0x2E28, 0x2E2C, 0x2E30, 0x2E34, 0x2E38, 0x2E3C,
|
|
|
|
0x2E40, 0x2E44, 0x2E48, 0x2E4C, 0x2E50, 0x2E54, 0x2E58, 0x2E5C,
|
|
|
|
0x2E60, 0x2E64, 0x2E68, 0x2E6C,
|
2020-09-11 10:43:51 +03:00
|
|
|
};
|
|
|
|
|
2015-10-16 12:41:19 +03:00
|
|
|
/*
|
|
|
|
* System Module Stop Control Register offsets
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const u16 smstpcr[] = {
|
|
|
|
0x130, 0x134, 0x138, 0x13C, 0x140, 0x144, 0x148, 0x14C,
|
|
|
|
0x990, 0x994, 0x998, 0x99C,
|
|
|
|
};
|
|
|
|
|
2021-12-01 10:33:02 +03:00
|
|
|
static const u16 mstpcr_for_gen4[] = {
|
2020-09-11 10:43:51 +03:00
|
|
|
0x2D00, 0x2D04, 0x2D08, 0x2D0C, 0x2D10, 0x2D14, 0x2D18, 0x2D1C,
|
2021-12-01 10:33:02 +03:00
|
|
|
0x2D20, 0x2D24, 0x2D28, 0x2D2C, 0x2D30, 0x2D34, 0x2D38, 0x2D3C,
|
|
|
|
0x2D40, 0x2D44, 0x2D48, 0x2D4C, 0x2D50, 0x2D54, 0x2D58, 0x2D5C,
|
|
|
|
0x2D60, 0x2D64, 0x2D68, 0x2D6C,
|
2020-09-11 10:43:51 +03:00
|
|
|
};
|
|
|
|
|
2018-09-07 19:58:49 +03:00
|
|
|
/*
|
|
|
|
* Standby Control Register offsets (RZ/A)
|
|
|
|
* Base address is FRQCR register
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const u16 stbcr[] = {
|
|
|
|
0xFFFF/*dummy*/, 0x010, 0x014, 0x410, 0x414, 0x418, 0x41C, 0x420,
|
|
|
|
0x424, 0x428, 0x42C,
|
|
|
|
};
|
|
|
|
|
2015-10-16 12:41:19 +03:00
|
|
|
/*
|
|
|
|
* Software Reset Register offsets
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const u16 srcr[] = {
|
|
|
|
0x0A0, 0x0A8, 0x0B0, 0x0B8, 0x0BC, 0x0C4, 0x1C8, 0x1CC,
|
|
|
|
0x920, 0x924, 0x928, 0x92C,
|
|
|
|
};
|
|
|
|
|
2021-12-01 10:33:02 +03:00
|
|
|
static const u16 srcr_for_gen4[] = {
|
2020-09-11 10:43:51 +03:00
|
|
|
0x2C00, 0x2C04, 0x2C08, 0x2C0C, 0x2C10, 0x2C14, 0x2C18, 0x2C1C,
|
2021-12-01 10:33:02 +03:00
|
|
|
0x2C20, 0x2C24, 0x2C28, 0x2C2C, 0x2C30, 0x2C34, 0x2C38, 0x2C3C,
|
|
|
|
0x2C40, 0x2C44, 0x2C48, 0x2C4C, 0x2C50, 0x2C54, 0x2C58, 0x2C5C,
|
|
|
|
0x2C60, 0x2C64, 0x2C68, 0x2C6C,
|
2020-09-11 10:43:51 +03:00
|
|
|
};
|
|
|
|
|
2021-05-04 12:17:22 +03:00
|
|
|
/*
|
|
|
|
* Software Reset Clearing Register offsets
|
|
|
|
*/
|
2015-10-16 12:41:19 +03:00
|
|
|
|
2020-09-11 10:43:50 +03:00
|
|
|
static const u16 srstclr[] = {
|
|
|
|
0x940, 0x944, 0x948, 0x94C, 0x950, 0x954, 0x958, 0x95C,
|
|
|
|
0x960, 0x964, 0x968, 0x96C,
|
|
|
|
};
|
2015-10-16 12:41:19 +03:00
|
|
|
|
2021-12-01 10:33:02 +03:00
|
|
|
static const u16 srstclr_for_gen4[] = {
|
2020-09-11 10:43:51 +03:00
|
|
|
0x2C80, 0x2C84, 0x2C88, 0x2C8C, 0x2C90, 0x2C94, 0x2C98, 0x2C9C,
|
2021-12-01 10:33:02 +03:00
|
|
|
0x2CA0, 0x2CA4, 0x2CA8, 0x2CAC, 0x2CB0, 0x2CB4, 0x2CB8, 0x2CBC,
|
|
|
|
0x2CC0, 0x2CC4, 0x2CC8, 0x2CCC, 0x2CD0, 0x2CD4, 0x2CD8, 0x2CDC,
|
|
|
|
0x2CE0, 0x2CE4, 0x2CE8, 0x2CEC,
|
2020-09-11 10:43:51 +03:00
|
|
|
};
|
|
|
|
|
2015-10-16 12:41:19 +03:00
|
|
|
/**
|
2020-11-03 19:24:34 +03:00
|
|
|
* struct cpg_mssr_priv - Clock Pulse Generator / Module Standby
|
|
|
|
* and Software Reset Private Data
|
2015-10-16 12:41:19 +03:00
|
|
|
*
|
2017-01-20 13:03:03 +03:00
|
|
|
* @rcdev: Optional reset controller entity
|
2015-10-16 12:41:19 +03:00
|
|
|
* @dev: CPG/MSSR device
|
|
|
|
* @base: CPG/MSSR register block base address
|
2020-09-11 10:43:49 +03:00
|
|
|
* @reg_layout: CPG/MSSR register layout
|
2017-01-20 12:58:11 +03:00
|
|
|
* @rmw_lock: protects RMW register accesses
|
2019-06-12 18:19:12 +03:00
|
|
|
* @np: Device node in DT for this CPG/MSSR module
|
2015-10-16 12:41:19 +03:00
|
|
|
* @num_core_clks: Number of Core Clocks in clks[]
|
|
|
|
* @num_mod_clks: Number of Module Clocks in clks[]
|
|
|
|
* @last_dt_core_clk: ID of the last Core Clock exported to DT
|
2017-06-21 23:24:15 +03:00
|
|
|
* @notifiers: Notifier chain to save/restore clock state for system resume
|
2020-09-11 10:43:50 +03:00
|
|
|
* @status_regs: Pointer to status registers array
|
|
|
|
* @control_regs: Pointer to control registers array
|
|
|
|
* @reset_regs: Pointer to reset registers array
|
|
|
|
* @reset_clear_regs: Pointer to reset clearing registers array
|
2021-01-26 15:45:30 +03:00
|
|
|
* @smstpcr_saved: [].mask: Mask of SMSTPCR[] bits under our control
|
|
|
|
* [].val: Saved values of SMSTPCR[]
|
2019-06-12 18:27:56 +03:00
|
|
|
* @clks: Array containing all Core and Module Clocks
|
2015-10-16 12:41:19 +03:00
|
|
|
*/
|
|
|
|
struct cpg_mssr_priv {
|
2017-01-20 13:03:03 +03:00
|
|
|
#ifdef CONFIG_RESET_CONTROLLER
|
|
|
|
struct reset_controller_dev rcdev;
|
|
|
|
#endif
|
2015-10-16 12:41:19 +03:00
|
|
|
struct device *dev;
|
|
|
|
void __iomem *base;
|
2020-09-11 10:43:49 +03:00
|
|
|
enum clk_reg_layout reg_layout;
|
2017-01-20 12:58:11 +03:00
|
|
|
spinlock_t rmw_lock;
|
2018-09-24 19:49:35 +03:00
|
|
|
struct device_node *np;
|
2015-10-16 12:41:19 +03:00
|
|
|
|
|
|
|
unsigned int num_core_clks;
|
|
|
|
unsigned int num_mod_clks;
|
|
|
|
unsigned int last_dt_core_clk;
|
clk: renesas: cpg-mssr: Restore module clocks during resume
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
clock register state is lost. Note that as the boot loader skips most
initialization after system resume, clock register state differs from
the state encountered during normal system boot, too.
Hence after s2ram, some operations may fail because module clocks are
disabled, while drivers expect them to be still enabled. E.g. EtherAVB
fails when Wake-on-LAN has been enabled using "ethtool -s eth0 wol g":
ravb e6800000.ethernet eth0: failed to switch device to config mode
ravb e6800000.ethernet eth0: device will be stopped after h/w processes are done.
ravb e6800000.ethernet eth0: failed to switch device to config
PM: Device e6800000.ethernet failed to resume: error -110
In addition, some module clocks that were disabled by
clk_disable_unused() may have been re-enabled, wasting power.
To fix this, restore all bits of the SMSTPCR registers that represent
clocks under control of Linux.
Notes:
- While this fixes EtherAVB operation after resume from s2ram,
EtherAVB cannot be used as an actual wake-up source from s2ram, only
from s2idle, due to PSCI limitations,
- To avoid overhead on platforms not needing it, the suspend/resume
code has a build time dependency on sleep and PSCI support, and a
runtime dependency on PSCI.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
2017-06-07 14:20:06 +03:00
|
|
|
|
2017-06-21 23:24:15 +03:00
|
|
|
struct raw_notifier_head notifiers;
|
2020-09-11 10:43:50 +03:00
|
|
|
const u16 *status_regs;
|
|
|
|
const u16 *control_regs;
|
|
|
|
const u16 *reset_regs;
|
|
|
|
const u16 *reset_clear_regs;
|
clk: renesas: cpg-mssr: Restore module clocks during resume
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
clock register state is lost. Note that as the boot loader skips most
initialization after system resume, clock register state differs from
the state encountered during normal system boot, too.
Hence after s2ram, some operations may fail because module clocks are
disabled, while drivers expect them to be still enabled. E.g. EtherAVB
fails when Wake-on-LAN has been enabled using "ethtool -s eth0 wol g":
ravb e6800000.ethernet eth0: failed to switch device to config mode
ravb e6800000.ethernet eth0: device will be stopped after h/w processes are done.
ravb e6800000.ethernet eth0: failed to switch device to config
PM: Device e6800000.ethernet failed to resume: error -110
In addition, some module clocks that were disabled by
clk_disable_unused() may have been re-enabled, wasting power.
To fix this, restore all bits of the SMSTPCR registers that represent
clocks under control of Linux.
Notes:
- While this fixes EtherAVB operation after resume from s2ram,
EtherAVB cannot be used as an actual wake-up source from s2ram, only
from s2idle, due to PSCI limitations,
- To avoid overhead on platforms not needing it, the suspend/resume
code has a build time dependency on sleep and PSCI support, and a
runtime dependency on PSCI.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
2017-06-07 14:20:06 +03:00
|
|
|
struct {
|
|
|
|
u32 mask;
|
|
|
|
u32 val;
|
2021-12-01 10:33:02 +03:00
|
|
|
} smstpcr_saved[ARRAY_SIZE(mstpsr_for_gen4)];
|
2019-06-12 18:27:56 +03:00
|
|
|
|
|
|
|
struct clk *clks[];
|
2015-10-16 12:41:19 +03:00
|
|
|
};
|
|
|
|
|
2018-09-24 19:49:35 +03:00
|
|
|
static struct cpg_mssr_priv *cpg_mssr_priv;
|
2015-10-16 12:41:19 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct mstp_clock - MSTP gating clock
|
|
|
|
* @hw: handle between common and hardware-specific interfaces
|
|
|
|
* @index: MSTP clock number
|
|
|
|
* @priv: CPG/MSSR private data
|
|
|
|
*/
|
|
|
|
struct mstp_clock {
|
|
|
|
struct clk_hw hw;
|
|
|
|
u32 index;
|
|
|
|
struct cpg_mssr_priv *priv;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_mstp_clock(_hw) container_of(_hw, struct mstp_clock, hw)
|
|
|
|
|
|
|
|
static int cpg_mstp_clock_endisable(struct clk_hw *hw, bool enable)
|
|
|
|
{
|
|
|
|
struct mstp_clock *clock = to_mstp_clock(hw);
|
|
|
|
struct cpg_mssr_priv *priv = clock->priv;
|
|
|
|
unsigned int reg = clock->index / 32;
|
|
|
|
unsigned int bit = clock->index % 32;
|
|
|
|
struct device *dev = priv->dev;
|
|
|
|
u32 bitmask = BIT(bit);
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int i;
|
|
|
|
u32 value;
|
|
|
|
|
|
|
|
dev_dbg(dev, "MSTP %u%02u/%pC %s\n", reg, bit, hw->clk,
|
|
|
|
enable ? "ON" : "OFF");
|
2017-01-20 12:58:11 +03:00
|
|
|
spin_lock_irqsave(&priv->rmw_lock, flags);
|
2015-10-16 12:41:19 +03:00
|
|
|
|
2020-09-11 10:43:49 +03:00
|
|
|
if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) {
|
2020-09-11 10:43:50 +03:00
|
|
|
value = readb(priv->base + priv->control_regs[reg]);
|
2018-09-07 19:58:49 +03:00
|
|
|
if (enable)
|
|
|
|
value &= ~bitmask;
|
|
|
|
else
|
|
|
|
value |= bitmask;
|
2020-09-11 10:43:50 +03:00
|
|
|
writeb(value, priv->base + priv->control_regs[reg]);
|
2018-09-07 19:58:49 +03:00
|
|
|
|
|
|
|
/* dummy read to ensure write has completed */
|
2020-09-11 10:43:50 +03:00
|
|
|
readb(priv->base + priv->control_regs[reg]);
|
|
|
|
barrier_data(priv->base + priv->control_regs[reg]);
|
2018-09-07 19:58:49 +03:00
|
|
|
} else {
|
2020-09-11 10:43:50 +03:00
|
|
|
value = readl(priv->base + priv->control_regs[reg]);
|
2018-09-07 19:58:49 +03:00
|
|
|
if (enable)
|
|
|
|
value &= ~bitmask;
|
|
|
|
else
|
|
|
|
value |= bitmask;
|
2020-09-11 10:43:50 +03:00
|
|
|
writel(value, priv->base + priv->control_regs[reg]);
|
2018-09-07 19:58:49 +03:00
|
|
|
}
|
2015-10-16 12:41:19 +03:00
|
|
|
|
2017-01-20 12:58:11 +03:00
|
|
|
spin_unlock_irqrestore(&priv->rmw_lock, flags);
|
2015-10-16 12:41:19 +03:00
|
|
|
|
2020-09-11 10:43:49 +03:00
|
|
|
if (!enable || priv->reg_layout == CLK_REG_LAYOUT_RZ_A)
|
2015-10-16 12:41:19 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 1000; i > 0; --i) {
|
2020-09-11 10:43:50 +03:00
|
|
|
if (!(readl(priv->base + priv->status_regs[reg]) & bitmask))
|
2015-10-16 12:41:19 +03:00
|
|
|
break;
|
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!i) {
|
|
|
|
dev_err(dev, "Failed to enable SMSTP %p[%d]\n",
|
2020-09-11 10:43:50 +03:00
|
|
|
priv->base + priv->control_regs[reg], bit);
|
2015-10-16 12:41:19 +03:00
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpg_mstp_clock_enable(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
return cpg_mstp_clock_endisable(hw, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cpg_mstp_clock_disable(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
cpg_mstp_clock_endisable(hw, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpg_mstp_clock_is_enabled(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
struct mstp_clock *clock = to_mstp_clock(hw);
|
|
|
|
struct cpg_mssr_priv *priv = clock->priv;
|
|
|
|
u32 value;
|
|
|
|
|
2020-09-11 10:43:49 +03:00
|
|
|
if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A)
|
2020-09-11 10:43:50 +03:00
|
|
|
value = readb(priv->base + priv->control_regs[clock->index / 32]);
|
2018-09-07 19:58:49 +03:00
|
|
|
else
|
2020-09-11 10:43:50 +03:00
|
|
|
value = readl(priv->base + priv->status_regs[clock->index / 32]);
|
2015-10-16 12:41:19 +03:00
|
|
|
|
|
|
|
return !(value & BIT(clock->index % 32));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct clk_ops cpg_mstp_clock_ops = {
|
|
|
|
.enable = cpg_mstp_clock_enable,
|
|
|
|
.disable = cpg_mstp_clock_disable,
|
|
|
|
.is_enabled = cpg_mstp_clock_is_enabled,
|
|
|
|
};
|
|
|
|
|
|
|
|
static
|
|
|
|
struct clk *cpg_mssr_clk_src_twocell_get(struct of_phandle_args *clkspec,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
unsigned int clkidx = clkspec->args[1];
|
|
|
|
struct cpg_mssr_priv *priv = data;
|
|
|
|
struct device *dev = priv->dev;
|
|
|
|
unsigned int idx;
|
|
|
|
const char *type;
|
|
|
|
struct clk *clk;
|
2018-09-07 19:58:49 +03:00
|
|
|
int range_check;
|
2015-10-16 12:41:19 +03:00
|
|
|
|
|
|
|
switch (clkspec->args[0]) {
|
|
|
|
case CPG_CORE:
|
|
|
|
type = "core";
|
|
|
|
if (clkidx > priv->last_dt_core_clk) {
|
|
|
|
dev_err(dev, "Invalid %s clock index %u\n", type,
|
|
|
|
clkidx);
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
clk = priv->clks[clkidx];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CPG_MOD:
|
|
|
|
type = "module";
|
2020-09-11 10:43:49 +03:00
|
|
|
if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) {
|
2018-09-07 19:58:49 +03:00
|
|
|
idx = MOD_CLK_PACK_10(clkidx);
|
|
|
|
range_check = 7 - (clkidx % 10);
|
|
|
|
} else {
|
|
|
|
idx = MOD_CLK_PACK(clkidx);
|
|
|
|
range_check = 31 - (clkidx % 100);
|
|
|
|
}
|
|
|
|
if (range_check < 0 || idx >= priv->num_mod_clks) {
|
2015-10-16 12:41:19 +03:00
|
|
|
dev_err(dev, "Invalid %s clock index %u\n", type,
|
|
|
|
clkidx);
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
clk = priv->clks[priv->num_core_clks + idx];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dev_err(dev, "Invalid CPG clock type %u\n", clkspec->args[0]);
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ERR(clk))
|
|
|
|
dev_err(dev, "Cannot get %s clock %u: %ld", type, clkidx,
|
|
|
|
PTR_ERR(clk));
|
|
|
|
else
|
2018-06-01 12:28:19 +03:00
|
|
|
dev_dbg(dev, "clock (%u, %u) is %pC at %lu Hz\n",
|
|
|
|
clkspec->args[0], clkspec->args[1], clk,
|
|
|
|
clk_get_rate(clk));
|
2015-10-16 12:41:19 +03:00
|
|
|
return clk;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init cpg_mssr_register_core_clk(const struct cpg_core_clk *core,
|
|
|
|
const struct cpg_mssr_info *info,
|
|
|
|
struct cpg_mssr_priv *priv)
|
|
|
|
{
|
2017-05-17 16:43:56 +03:00
|
|
|
struct clk *clk = ERR_PTR(-ENOTSUPP), *parent;
|
2015-10-16 12:41:19 +03:00
|
|
|
struct device *dev = priv->dev;
|
2016-03-30 17:58:18 +03:00
|
|
|
unsigned int id = core->id, div = core->div;
|
2015-10-16 12:41:19 +03:00
|
|
|
const char *parent_name;
|
|
|
|
|
|
|
|
WARN_DEBUG(id >= priv->num_core_clks);
|
|
|
|
WARN_DEBUG(PTR_ERR(priv->clks[id]) != -ENOENT);
|
|
|
|
|
2016-09-29 15:47:58 +03:00
|
|
|
if (!core->name) {
|
|
|
|
/* Skip NULLified clock */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-16 12:41:19 +03:00
|
|
|
switch (core->type) {
|
|
|
|
case CLK_TYPE_IN:
|
2018-09-24 19:49:35 +03:00
|
|
|
clk = of_clk_get_by_name(priv->np, core->name);
|
2015-10-16 12:41:19 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CLK_TYPE_FF:
|
|
|
|
case CLK_TYPE_DIV6P1:
|
2016-03-30 17:58:18 +03:00
|
|
|
case CLK_TYPE_DIV6_RO:
|
2015-10-16 12:41:19 +03:00
|
|
|
WARN_DEBUG(core->parent >= priv->num_core_clks);
|
|
|
|
parent = priv->clks[core->parent];
|
|
|
|
if (IS_ERR(parent)) {
|
|
|
|
clk = parent;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent_name = __clk_get_name(parent);
|
2016-03-30 17:58:18 +03:00
|
|
|
|
|
|
|
if (core->type == CLK_TYPE_DIV6_RO)
|
|
|
|
/* Multiply with the DIV6 register value */
|
|
|
|
div *= (readl(priv->base + core->offset) & 0x3f) + 1;
|
|
|
|
|
|
|
|
if (core->type == CLK_TYPE_DIV6P1) {
|
2015-10-16 12:41:19 +03:00
|
|
|
clk = cpg_div6_register(core->name, 1, &parent_name,
|
2017-06-21 23:34:33 +03:00
|
|
|
priv->base + core->offset,
|
|
|
|
&priv->notifiers);
|
2016-03-30 17:58:18 +03:00
|
|
|
} else {
|
|
|
|
clk = clk_register_fixed_factor(NULL, core->name,
|
|
|
|
parent_name, 0,
|
|
|
|
core->mult, div);
|
2015-10-16 12:41:19 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-07-11 14:47:28 +03:00
|
|
|
case CLK_TYPE_FR:
|
|
|
|
clk = clk_register_fixed_rate(NULL, core->name, NULL, 0,
|
|
|
|
core->mult);
|
|
|
|
break;
|
|
|
|
|
2015-10-16 12:41:19 +03:00
|
|
|
default:
|
|
|
|
if (info->cpg_clk_register)
|
|
|
|
clk = info->cpg_clk_register(dev, core, info,
|
2017-06-21 23:24:15 +03:00
|
|
|
priv->clks, priv->base,
|
|
|
|
&priv->notifiers);
|
2015-10-16 12:41:19 +03:00
|
|
|
else
|
|
|
|
dev_err(dev, "%s has unsupported core clock type %u\n",
|
|
|
|
core->name, core->type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IS_ERR_OR_NULL(clk))
|
|
|
|
goto fail;
|
|
|
|
|
2018-06-01 12:28:19 +03:00
|
|
|
dev_dbg(dev, "Core clock %pC at %lu Hz\n", clk, clk_get_rate(clk));
|
2015-10-16 12:41:19 +03:00
|
|
|
priv->clks[id] = clk;
|
|
|
|
return;
|
|
|
|
|
|
|
|
fail:
|
2016-10-18 16:59:13 +03:00
|
|
|
dev_err(dev, "Failed to register %s clock %s: %ld\n", "core",
|
2015-10-16 12:41:19 +03:00
|
|
|
core->name, PTR_ERR(clk));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __init cpg_mssr_register_mod_clk(const struct mssr_mod_clk *mod,
|
|
|
|
const struct cpg_mssr_info *info,
|
|
|
|
struct cpg_mssr_priv *priv)
|
|
|
|
{
|
|
|
|
struct mstp_clock *clock = NULL;
|
|
|
|
struct device *dev = priv->dev;
|
|
|
|
unsigned int id = mod->id;
|
2021-03-26 13:54:34 +03:00
|
|
|
struct clk_init_data init = {};
|
2015-10-16 12:41:19 +03:00
|
|
|
struct clk *parent, *clk;
|
|
|
|
const char *parent_name;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
WARN_DEBUG(id < priv->num_core_clks);
|
|
|
|
WARN_DEBUG(id >= priv->num_core_clks + priv->num_mod_clks);
|
|
|
|
WARN_DEBUG(mod->parent >= priv->num_core_clks + priv->num_mod_clks);
|
|
|
|
WARN_DEBUG(PTR_ERR(priv->clks[id]) != -ENOENT);
|
|
|
|
|
2016-09-29 15:47:58 +03:00
|
|
|
if (!mod->name) {
|
|
|
|
/* Skip NULLified clock */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-16 12:41:19 +03:00
|
|
|
parent = priv->clks[mod->parent];
|
|
|
|
if (IS_ERR(parent)) {
|
|
|
|
clk = parent;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
clock = kzalloc(sizeof(*clock), GFP_KERNEL);
|
|
|
|
if (!clock) {
|
|
|
|
clk = ERR_PTR(-ENOMEM);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
init.name = mod->name;
|
|
|
|
init.ops = &cpg_mstp_clock_ops;
|
2018-11-30 22:05:35 +03:00
|
|
|
init.flags = CLK_SET_RATE_PARENT;
|
2015-10-16 12:41:19 +03:00
|
|
|
parent_name = __clk_get_name(parent);
|
|
|
|
init.parent_names = &parent_name;
|
|
|
|
init.num_parents = 1;
|
|
|
|
|
|
|
|
clock->index = id - priv->num_core_clks;
|
|
|
|
clock->priv = priv;
|
|
|
|
clock->hw.init = &init;
|
|
|
|
|
2020-06-16 19:26:24 +03:00
|
|
|
for (i = 0; i < info->num_crit_mod_clks; i++)
|
|
|
|
if (id == info->crit_mod_clks[i] &&
|
|
|
|
cpg_mstp_clock_is_enabled(&clock->hw)) {
|
|
|
|
dev_dbg(dev, "MSTP %s setting CLK_IS_CRITICAL\n",
|
|
|
|
mod->name);
|
|
|
|
init.flags |= CLK_IS_CRITICAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-16 12:41:19 +03:00
|
|
|
clk = clk_register(NULL, &clock->hw);
|
|
|
|
if (IS_ERR(clk))
|
|
|
|
goto fail;
|
|
|
|
|
2018-06-01 12:28:19 +03:00
|
|
|
dev_dbg(dev, "Module clock %pC at %lu Hz\n", clk, clk_get_rate(clk));
|
2015-10-16 12:41:19 +03:00
|
|
|
priv->clks[id] = clk;
|
clk: renesas: cpg-mssr: Restore module clocks during resume
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
clock register state is lost. Note that as the boot loader skips most
initialization after system resume, clock register state differs from
the state encountered during normal system boot, too.
Hence after s2ram, some operations may fail because module clocks are
disabled, while drivers expect them to be still enabled. E.g. EtherAVB
fails when Wake-on-LAN has been enabled using "ethtool -s eth0 wol g":
ravb e6800000.ethernet eth0: failed to switch device to config mode
ravb e6800000.ethernet eth0: device will be stopped after h/w processes are done.
ravb e6800000.ethernet eth0: failed to switch device to config
PM: Device e6800000.ethernet failed to resume: error -110
In addition, some module clocks that were disabled by
clk_disable_unused() may have been re-enabled, wasting power.
To fix this, restore all bits of the SMSTPCR registers that represent
clocks under control of Linux.
Notes:
- While this fixes EtherAVB operation after resume from s2ram,
EtherAVB cannot be used as an actual wake-up source from s2ram, only
from s2idle, due to PSCI limitations,
- To avoid overhead on platforms not needing it, the suspend/resume
code has a build time dependency on sleep and PSCI support, and a
runtime dependency on PSCI.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
2017-06-07 14:20:06 +03:00
|
|
|
priv->smstpcr_saved[clock->index / 32].mask |= BIT(clock->index % 32);
|
2015-10-16 12:41:19 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
fail:
|
2016-10-18 16:59:13 +03:00
|
|
|
dev_err(dev, "Failed to register %s clock %s: %ld\n", "module",
|
2015-10-16 12:41:19 +03:00
|
|
|
mod->name, PTR_ERR(clk));
|
|
|
|
kfree(clock);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cpg_mssr_clk_domain {
|
|
|
|
struct generic_pm_domain genpd;
|
|
|
|
unsigned int num_core_pm_clks;
|
2019-06-17 14:58:58 +03:00
|
|
|
unsigned int core_pm_clks[];
|
2015-10-16 12:41:19 +03:00
|
|
|
};
|
|
|
|
|
2016-03-04 19:03:46 +03:00
|
|
|
static struct cpg_mssr_clk_domain *cpg_mssr_clk_domain;
|
|
|
|
|
2015-10-16 12:41:19 +03:00
|
|
|
static bool cpg_mssr_is_pm_clk(const struct of_phandle_args *clkspec,
|
|
|
|
struct cpg_mssr_clk_domain *pd)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2019-05-27 11:55:26 +03:00
|
|
|
if (clkspec->np != pd->genpd.dev.of_node || clkspec->args_count != 2)
|
2015-10-16 12:41:19 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (clkspec->args[0]) {
|
|
|
|
case CPG_CORE:
|
|
|
|
for (i = 0; i < pd->num_core_pm_clks; i++)
|
|
|
|
if (clkspec->args[1] == pd->core_pm_clks[i])
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
case CPG_MOD:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-04 19:03:46 +03:00
|
|
|
int cpg_mssr_attach_dev(struct generic_pm_domain *unused, struct device *dev)
|
2015-10-16 12:41:19 +03:00
|
|
|
{
|
2016-03-04 19:03:46 +03:00
|
|
|
struct cpg_mssr_clk_domain *pd = cpg_mssr_clk_domain;
|
2015-10-16 12:41:19 +03:00
|
|
|
struct device_node *np = dev->of_node;
|
|
|
|
struct of_phandle_args clkspec;
|
|
|
|
struct clk *clk;
|
|
|
|
int i = 0;
|
|
|
|
int error;
|
|
|
|
|
2016-03-04 19:03:46 +03:00
|
|
|
if (!pd) {
|
|
|
|
dev_dbg(dev, "CPG/MSSR clock domain not yet available\n");
|
|
|
|
return -EPROBE_DEFER;
|
|
|
|
}
|
|
|
|
|
2015-10-16 12:41:19 +03:00
|
|
|
while (!of_parse_phandle_with_args(np, "clocks", "#clock-cells", i,
|
|
|
|
&clkspec)) {
|
|
|
|
if (cpg_mssr_is_pm_clk(&clkspec, pd))
|
|
|
|
goto found;
|
|
|
|
|
|
|
|
of_node_put(clkspec.np);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
found:
|
|
|
|
clk = of_clk_get_from_provider(&clkspec);
|
|
|
|
of_node_put(clkspec.np);
|
|
|
|
|
|
|
|
if (IS_ERR(clk))
|
|
|
|
return PTR_ERR(clk);
|
|
|
|
|
|
|
|
error = pm_clk_create(dev);
|
2019-05-27 12:26:42 +03:00
|
|
|
if (error)
|
2015-10-16 12:41:19 +03:00
|
|
|
goto fail_put;
|
|
|
|
|
|
|
|
error = pm_clk_add_clk(dev, clk);
|
2019-05-27 12:26:42 +03:00
|
|
|
if (error)
|
2015-10-16 12:41:19 +03:00
|
|
|
goto fail_destroy;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_destroy:
|
|
|
|
pm_clk_destroy(dev);
|
|
|
|
fail_put:
|
|
|
|
clk_put(clk);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2016-03-04 19:03:46 +03:00
|
|
|
void cpg_mssr_detach_dev(struct generic_pm_domain *unused, struct device *dev)
|
2015-10-16 12:41:19 +03:00
|
|
|
{
|
2017-02-08 21:08:44 +03:00
|
|
|
if (!pm_clk_no_clocks(dev))
|
2015-10-16 12:41:19 +03:00
|
|
|
pm_clk_destroy(dev);
|
|
|
|
}
|
|
|
|
|
2021-11-17 14:51:00 +03:00
|
|
|
static void cpg_mssr_genpd_remove(void *data)
|
|
|
|
{
|
|
|
|
pm_genpd_remove(data);
|
|
|
|
}
|
|
|
|
|
2015-10-16 12:41:19 +03:00
|
|
|
static int __init cpg_mssr_add_clk_domain(struct device *dev,
|
|
|
|
const unsigned int *core_pm_clks,
|
|
|
|
unsigned int num_core_pm_clks)
|
|
|
|
{
|
|
|
|
struct device_node *np = dev->of_node;
|
|
|
|
struct generic_pm_domain *genpd;
|
|
|
|
struct cpg_mssr_clk_domain *pd;
|
|
|
|
size_t pm_size = num_core_pm_clks * sizeof(core_pm_clks[0]);
|
2021-11-17 14:51:00 +03:00
|
|
|
int ret;
|
2015-10-16 12:41:19 +03:00
|
|
|
|
|
|
|
pd = devm_kzalloc(dev, sizeof(*pd) + pm_size, GFP_KERNEL);
|
|
|
|
if (!pd)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pd->num_core_pm_clks = num_core_pm_clks;
|
|
|
|
memcpy(pd->core_pm_clks, core_pm_clks, pm_size);
|
|
|
|
|
|
|
|
genpd = &pd->genpd;
|
|
|
|
genpd->name = np->name;
|
2019-08-09 16:44:51 +03:00
|
|
|
genpd->flags = GENPD_FLAG_PM_CLK | GENPD_FLAG_ALWAYS_ON |
|
|
|
|
GENPD_FLAG_ACTIVE_WAKEUP;
|
2015-10-16 12:41:19 +03:00
|
|
|
genpd->attach_dev = cpg_mssr_attach_dev;
|
|
|
|
genpd->detach_dev = cpg_mssr_detach_dev;
|
2021-11-17 14:51:00 +03:00
|
|
|
ret = pm_genpd_init(genpd, &pm_domain_always_on_gov, false);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = devm_add_action_or_reset(dev, cpg_mssr_genpd_remove, genpd);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2016-03-04 19:03:46 +03:00
|
|
|
cpg_mssr_clk_domain = pd;
|
2015-10-16 12:41:19 +03:00
|
|
|
|
2021-11-17 14:51:01 +03:00
|
|
|
return of_genpd_add_provider_simple(np, genpd);
|
2015-10-16 12:41:19 +03:00
|
|
|
}
|
|
|
|
|
2017-01-20 13:03:03 +03:00
|
|
|
#ifdef CONFIG_RESET_CONTROLLER
|
|
|
|
|
|
|
|
#define rcdev_to_priv(x) container_of(x, struct cpg_mssr_priv, rcdev)
|
|
|
|
|
|
|
|
static int cpg_mssr_reset(struct reset_controller_dev *rcdev,
|
|
|
|
unsigned long id)
|
|
|
|
{
|
|
|
|
struct cpg_mssr_priv *priv = rcdev_to_priv(rcdev);
|
|
|
|
unsigned int reg = id / 32;
|
|
|
|
unsigned int bit = id % 32;
|
|
|
|
u32 bitmask = BIT(bit);
|
|
|
|
|
|
|
|
dev_dbg(priv->dev, "reset %u%02u\n", reg, bit);
|
|
|
|
|
|
|
|
/* Reset module */
|
2020-09-11 10:43:50 +03:00
|
|
|
writel(bitmask, priv->base + priv->reset_regs[reg]);
|
2017-01-20 13:03:03 +03:00
|
|
|
|
|
|
|
/* Wait for at least one cycle of the RCLK clock (@ ca. 32 kHz) */
|
|
|
|
udelay(35);
|
|
|
|
|
|
|
|
/* Release module from reset state */
|
2020-09-11 10:43:50 +03:00
|
|
|
writel(bitmask, priv->base + priv->reset_clear_regs[reg]);
|
2017-01-20 13:03:03 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpg_mssr_assert(struct reset_controller_dev *rcdev, unsigned long id)
|
|
|
|
{
|
|
|
|
struct cpg_mssr_priv *priv = rcdev_to_priv(rcdev);
|
|
|
|
unsigned int reg = id / 32;
|
|
|
|
unsigned int bit = id % 32;
|
|
|
|
u32 bitmask = BIT(bit);
|
|
|
|
|
|
|
|
dev_dbg(priv->dev, "assert %u%02u\n", reg, bit);
|
|
|
|
|
2020-09-11 10:43:50 +03:00
|
|
|
writel(bitmask, priv->base + priv->reset_regs[reg]);
|
2017-01-20 13:03:03 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpg_mssr_deassert(struct reset_controller_dev *rcdev,
|
|
|
|
unsigned long id)
|
|
|
|
{
|
|
|
|
struct cpg_mssr_priv *priv = rcdev_to_priv(rcdev);
|
|
|
|
unsigned int reg = id / 32;
|
|
|
|
unsigned int bit = id % 32;
|
|
|
|
u32 bitmask = BIT(bit);
|
|
|
|
|
|
|
|
dev_dbg(priv->dev, "deassert %u%02u\n", reg, bit);
|
|
|
|
|
2020-09-11 10:43:50 +03:00
|
|
|
writel(bitmask, priv->base + priv->reset_clear_regs[reg]);
|
2017-01-20 13:03:03 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpg_mssr_status(struct reset_controller_dev *rcdev,
|
|
|
|
unsigned long id)
|
|
|
|
{
|
|
|
|
struct cpg_mssr_priv *priv = rcdev_to_priv(rcdev);
|
|
|
|
unsigned int reg = id / 32;
|
|
|
|
unsigned int bit = id % 32;
|
|
|
|
u32 bitmask = BIT(bit);
|
|
|
|
|
2020-09-11 10:43:50 +03:00
|
|
|
return !!(readl(priv->base + priv->reset_regs[reg]) & bitmask);
|
2017-01-20 13:03:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct reset_control_ops cpg_mssr_reset_ops = {
|
|
|
|
.reset = cpg_mssr_reset,
|
|
|
|
.assert = cpg_mssr_assert,
|
|
|
|
.deassert = cpg_mssr_deassert,
|
|
|
|
.status = cpg_mssr_status,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int cpg_mssr_reset_xlate(struct reset_controller_dev *rcdev,
|
|
|
|
const struct of_phandle_args *reset_spec)
|
|
|
|
{
|
|
|
|
struct cpg_mssr_priv *priv = rcdev_to_priv(rcdev);
|
|
|
|
unsigned int unpacked = reset_spec->args[0];
|
|
|
|
unsigned int idx = MOD_CLK_PACK(unpacked);
|
|
|
|
|
|
|
|
if (unpacked % 100 > 31 || idx >= rcdev->nr_resets) {
|
|
|
|
dev_err(priv->dev, "Invalid reset index %u\n", unpacked);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpg_mssr_reset_controller_register(struct cpg_mssr_priv *priv)
|
|
|
|
{
|
|
|
|
priv->rcdev.ops = &cpg_mssr_reset_ops;
|
|
|
|
priv->rcdev.of_node = priv->dev->of_node;
|
|
|
|
priv->rcdev.of_reset_n_cells = 1;
|
|
|
|
priv->rcdev.of_xlate = cpg_mssr_reset_xlate;
|
|
|
|
priv->rcdev.nr_resets = priv->num_mod_clks;
|
|
|
|
return devm_reset_controller_register(priv->dev, &priv->rcdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* !CONFIG_RESET_CONTROLLER */
|
|
|
|
static inline int cpg_mssr_reset_controller_register(struct cpg_mssr_priv *priv)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* !CONFIG_RESET_CONTROLLER */
|
|
|
|
|
|
|
|
|
2015-10-16 12:41:19 +03:00
|
|
|
static const struct of_device_id cpg_mssr_match[] = {
|
2018-09-07 19:58:49 +03:00
|
|
|
#ifdef CONFIG_CLK_R7S9210
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r7s9210-cpg-mssr",
|
|
|
|
.data = &r7s9210_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
2020-04-27 17:41:00 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A7742
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a7742-cpg-mssr",
|
|
|
|
.data = &r8a7742_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
clk: renesas: Rework Kconfig and Makefile logic
The goals are to:
- Allow precise control over and automatic selection of which
(sub)drivers are used for which SoC (which may change in the
future),
- Allow adding support for new SoCs easily,
- Allow compile-testing of all (sub)drivers,
- Keep driver selection logic in the subsystem-specific Kconfig,
independent from the architecture-specific Kconfig (i.e. no "select"
from arch/arm64/Kconfig.platforms), to avoid dependencies.
This is implemented by:
- Introducing Kconfig symbols for all drivers and sub-drivers,
- Introducing the Kconfig symbol CLK_RENESAS, which is enabled
automatically when building for a Renesas ARM platform, and which
enables all required drivers without interaction of the user, based
on SoC-specific ARCH_* symbols,
- Allowing the user to enable any Kconfig symbol manually if
COMPILE_TEST is enabled,
- Using the new Kconfig symbols instead of the ARCH_* symbols to
control compilation in the Makefile,
- Always entering drivers/clk/renesas/ during the build.
Note that currently not all (sub)drivers are enabled for
compile-testing, as they depend on independent fixes in other
subsystems.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Simon Horman <horms+renesas@verge.net.au>
Acked-by: Stephen Boyd <sboyd@codeaurora.org>
2017-04-24 17:54:14 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A7743
|
2016-11-09 00:21:50 +03:00
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a7743-cpg-mssr",
|
|
|
|
.data = &r8a7743_cpg_mssr_info,
|
|
|
|
},
|
2018-09-11 13:12:49 +03:00
|
|
|
/* RZ/G1N is (almost) identical to RZ/G1M w.r.t. clocks. */
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a7744-cpg-mssr",
|
|
|
|
.data = &r8a7743_cpg_mssr_info,
|
|
|
|
},
|
2016-11-09 00:21:50 +03:00
|
|
|
#endif
|
clk: renesas: Rework Kconfig and Makefile logic
The goals are to:
- Allow precise control over and automatic selection of which
(sub)drivers are used for which SoC (which may change in the
future),
- Allow adding support for new SoCs easily,
- Allow compile-testing of all (sub)drivers,
- Keep driver selection logic in the subsystem-specific Kconfig,
independent from the architecture-specific Kconfig (i.e. no "select"
from arch/arm64/Kconfig.platforms), to avoid dependencies.
This is implemented by:
- Introducing Kconfig symbols for all drivers and sub-drivers,
- Introducing the Kconfig symbol CLK_RENESAS, which is enabled
automatically when building for a Renesas ARM platform, and which
enables all required drivers without interaction of the user, based
on SoC-specific ARCH_* symbols,
- Allowing the user to enable any Kconfig symbol manually if
COMPILE_TEST is enabled,
- Using the new Kconfig symbols instead of the ARCH_* symbols to
control compilation in the Makefile,
- Always entering drivers/clk/renesas/ during the build.
Note that currently not all (sub)drivers are enabled for
compile-testing, as they depend on independent fixes in other
subsystems.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Simon Horman <horms+renesas@verge.net.au>
Acked-by: Stephen Boyd <sboyd@codeaurora.org>
2017-04-24 17:54:14 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A7745
|
2016-11-09 00:25:08 +03:00
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a7745-cpg-mssr",
|
|
|
|
.data = &r8a7745_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
2018-03-28 22:26:12 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A77470
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a77470-cpg-mssr",
|
|
|
|
.data = &r8a77470_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
2018-08-02 17:57:51 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A774A1
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a774a1-cpg-mssr",
|
|
|
|
.data = &r8a774a1_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
2019-09-19 11:17:14 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A774B1
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a774b1-cpg-mssr",
|
|
|
|
.data = &r8a774b1_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
2018-09-12 13:41:53 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A774C0
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a774c0-cpg-mssr",
|
|
|
|
.data = &r8a774c0_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
2020-07-07 19:18:10 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A774E1
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a774e1-cpg-mssr",
|
|
|
|
.data = &r8a774e1_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
2017-03-19 20:05:42 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A7790
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a7790-cpg-mssr",
|
|
|
|
.data = &r8a7790_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
2015-10-16 12:41:19 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A7791
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a7791-cpg-mssr",
|
|
|
|
.data = &r8a7791_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
/* R-Car M2-N is (almost) identical to R-Car M2-W w.r.t. clocks. */
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a7793-cpg-mssr",
|
|
|
|
.data = &r8a7791_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
2017-03-19 20:08:59 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A7792
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a7792-cpg-mssr",
|
|
|
|
.data = &r8a7792_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
2017-03-19 20:12:51 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A7794
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a7794-cpg-mssr",
|
|
|
|
.data = &r8a7794_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
clk: renesas: Rework Kconfig and Makefile logic
The goals are to:
- Allow precise control over and automatic selection of which
(sub)drivers are used for which SoC (which may change in the
future),
- Allow adding support for new SoCs easily,
- Allow compile-testing of all (sub)drivers,
- Keep driver selection logic in the subsystem-specific Kconfig,
independent from the architecture-specific Kconfig (i.e. no "select"
from arch/arm64/Kconfig.platforms), to avoid dependencies.
This is implemented by:
- Introducing Kconfig symbols for all drivers and sub-drivers,
- Introducing the Kconfig symbol CLK_RENESAS, which is enabled
automatically when building for a Renesas ARM platform, and which
enables all required drivers without interaction of the user, based
on SoC-specific ARCH_* symbols,
- Allowing the user to enable any Kconfig symbol manually if
COMPILE_TEST is enabled,
- Using the new Kconfig symbols instead of the ARCH_* symbols to
control compilation in the Makefile,
- Always entering drivers/clk/renesas/ during the build.
Note that currently not all (sub)drivers are enabled for
compile-testing, as they depend on independent fixes in other
subsystems.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Simon Horman <horms+renesas@verge.net.au>
Acked-by: Stephen Boyd <sboyd@codeaurora.org>
2017-04-24 17:54:14 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A7795
|
2015-10-16 12:41:19 +03:00
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a7795-cpg-mssr",
|
|
|
|
.data = &r8a7795_cpg_mssr_info,
|
|
|
|
},
|
2016-05-03 12:06:15 +03:00
|
|
|
#endif
|
2019-10-23 15:29:40 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A77960
|
2016-05-03 12:06:15 +03:00
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a7796-cpg-mssr",
|
|
|
|
.data = &r8a7796_cpg_mssr_info,
|
|
|
|
},
|
2017-07-12 11:47:36 +03:00
|
|
|
#endif
|
2019-10-23 15:29:41 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A77961
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a77961-cpg-mssr",
|
|
|
|
.data = &r8a7796_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
2018-02-20 18:12:03 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A77965
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a77965-cpg-mssr",
|
|
|
|
.data = &r8a77965_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
2017-09-09 00:34:20 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A77970
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a77970-cpg-mssr",
|
|
|
|
.data = &r8a77970_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
2018-03-20 10:40:16 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A77980
|
2018-02-15 14:58:45 +03:00
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a77980-cpg-mssr",
|
|
|
|
.data = &r8a77980_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
2018-04-20 15:27:44 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A77990
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a77990-cpg-mssr",
|
|
|
|
.data = &r8a77990_cpg_mssr_info,
|
|
|
|
},
|
|
|
|
#endif
|
2017-07-12 11:47:36 +03:00
|
|
|
#ifdef CONFIG_CLK_R8A77995
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a77995-cpg-mssr",
|
|
|
|
.data = &r8a77995_cpg_mssr_info,
|
|
|
|
},
|
2020-09-11 10:43:51 +03:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_CLK_R8A779A0
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a779a0-cpg-mssr",
|
|
|
|
.data = &r8a779a0_cpg_mssr_info,
|
|
|
|
},
|
2021-12-01 10:33:03 +03:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_CLK_R8A779F0
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a779f0-cpg-mssr",
|
|
|
|
.data = &r8a779f0_cpg_mssr_info,
|
|
|
|
},
|
2022-04-28 16:50:56 +03:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_CLK_R8A779G0
|
|
|
|
{
|
|
|
|
.compatible = "renesas,r8a779g0-cpg-mssr",
|
|
|
|
.data = &r8a779g0_cpg_mssr_info,
|
|
|
|
},
|
2015-10-16 12:41:19 +03:00
|
|
|
#endif
|
2015-10-16 12:41:19 +03:00
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void cpg_mssr_del_clk_provider(void *data)
|
|
|
|
{
|
|
|
|
of_clk_del_provider(data);
|
|
|
|
}
|
|
|
|
|
clk: renesas: cpg-mssr: Restore module clocks during resume
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
clock register state is lost. Note that as the boot loader skips most
initialization after system resume, clock register state differs from
the state encountered during normal system boot, too.
Hence after s2ram, some operations may fail because module clocks are
disabled, while drivers expect them to be still enabled. E.g. EtherAVB
fails when Wake-on-LAN has been enabled using "ethtool -s eth0 wol g":
ravb e6800000.ethernet eth0: failed to switch device to config mode
ravb e6800000.ethernet eth0: device will be stopped after h/w processes are done.
ravb e6800000.ethernet eth0: failed to switch device to config
PM: Device e6800000.ethernet failed to resume: error -110
In addition, some module clocks that were disabled by
clk_disable_unused() may have been re-enabled, wasting power.
To fix this, restore all bits of the SMSTPCR registers that represent
clocks under control of Linux.
Notes:
- While this fixes EtherAVB operation after resume from s2ram,
EtherAVB cannot be used as an actual wake-up source from s2ram, only
from s2idle, due to PSCI limitations,
- To avoid overhead on platforms not needing it, the suspend/resume
code has a build time dependency on sleep and PSCI support, and a
runtime dependency on PSCI.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
2017-06-07 14:20:06 +03:00
|
|
|
#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM_PSCI_FW)
|
|
|
|
static int cpg_mssr_suspend_noirq(struct device *dev)
|
|
|
|
{
|
|
|
|
struct cpg_mssr_priv *priv = dev_get_drvdata(dev);
|
|
|
|
unsigned int reg;
|
|
|
|
|
|
|
|
/* This is the best we can do to check for the presence of PSCI */
|
|
|
|
if (!psci_ops.cpu_suspend)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Save module registers with bits under our control */
|
|
|
|
for (reg = 0; reg < ARRAY_SIZE(priv->smstpcr_saved); reg++) {
|
|
|
|
if (priv->smstpcr_saved[reg].mask)
|
2020-09-11 10:43:49 +03:00
|
|
|
priv->smstpcr_saved[reg].val =
|
|
|
|
priv->reg_layout == CLK_REG_LAYOUT_RZ_A ?
|
2020-09-11 10:43:50 +03:00
|
|
|
readb(priv->base + priv->control_regs[reg]) :
|
|
|
|
readl(priv->base + priv->control_regs[reg]);
|
clk: renesas: cpg-mssr: Restore module clocks during resume
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
clock register state is lost. Note that as the boot loader skips most
initialization after system resume, clock register state differs from
the state encountered during normal system boot, too.
Hence after s2ram, some operations may fail because module clocks are
disabled, while drivers expect them to be still enabled. E.g. EtherAVB
fails when Wake-on-LAN has been enabled using "ethtool -s eth0 wol g":
ravb e6800000.ethernet eth0: failed to switch device to config mode
ravb e6800000.ethernet eth0: device will be stopped after h/w processes are done.
ravb e6800000.ethernet eth0: failed to switch device to config
PM: Device e6800000.ethernet failed to resume: error -110
In addition, some module clocks that were disabled by
clk_disable_unused() may have been re-enabled, wasting power.
To fix this, restore all bits of the SMSTPCR registers that represent
clocks under control of Linux.
Notes:
- While this fixes EtherAVB operation after resume from s2ram,
EtherAVB cannot be used as an actual wake-up source from s2ram, only
from s2idle, due to PSCI limitations,
- To avoid overhead on platforms not needing it, the suspend/resume
code has a build time dependency on sleep and PSCI support, and a
runtime dependency on PSCI.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
2017-06-07 14:20:06 +03:00
|
|
|
}
|
|
|
|
|
2017-06-21 23:24:15 +03:00
|
|
|
/* Save core clocks */
|
|
|
|
raw_notifier_call_chain(&priv->notifiers, PM_EVENT_SUSPEND, NULL);
|
|
|
|
|
clk: renesas: cpg-mssr: Restore module clocks during resume
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
clock register state is lost. Note that as the boot loader skips most
initialization after system resume, clock register state differs from
the state encountered during normal system boot, too.
Hence after s2ram, some operations may fail because module clocks are
disabled, while drivers expect them to be still enabled. E.g. EtherAVB
fails when Wake-on-LAN has been enabled using "ethtool -s eth0 wol g":
ravb e6800000.ethernet eth0: failed to switch device to config mode
ravb e6800000.ethernet eth0: device will be stopped after h/w processes are done.
ravb e6800000.ethernet eth0: failed to switch device to config
PM: Device e6800000.ethernet failed to resume: error -110
In addition, some module clocks that were disabled by
clk_disable_unused() may have been re-enabled, wasting power.
To fix this, restore all bits of the SMSTPCR registers that represent
clocks under control of Linux.
Notes:
- While this fixes EtherAVB operation after resume from s2ram,
EtherAVB cannot be used as an actual wake-up source from s2ram, only
from s2idle, due to PSCI limitations,
- To avoid overhead on platforms not needing it, the suspend/resume
code has a build time dependency on sleep and PSCI support, and a
runtime dependency on PSCI.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
2017-06-07 14:20:06 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cpg_mssr_resume_noirq(struct device *dev)
|
|
|
|
{
|
|
|
|
struct cpg_mssr_priv *priv = dev_get_drvdata(dev);
|
|
|
|
unsigned int reg, i;
|
|
|
|
u32 mask, oldval, newval;
|
|
|
|
|
|
|
|
/* This is the best we can do to check for the presence of PSCI */
|
|
|
|
if (!psci_ops.cpu_suspend)
|
|
|
|
return 0;
|
|
|
|
|
2017-06-21 23:24:15 +03:00
|
|
|
/* Restore core clocks */
|
|
|
|
raw_notifier_call_chain(&priv->notifiers, PM_EVENT_RESUME, NULL);
|
|
|
|
|
clk: renesas: cpg-mssr: Restore module clocks during resume
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
clock register state is lost. Note that as the boot loader skips most
initialization after system resume, clock register state differs from
the state encountered during normal system boot, too.
Hence after s2ram, some operations may fail because module clocks are
disabled, while drivers expect them to be still enabled. E.g. EtherAVB
fails when Wake-on-LAN has been enabled using "ethtool -s eth0 wol g":
ravb e6800000.ethernet eth0: failed to switch device to config mode
ravb e6800000.ethernet eth0: device will be stopped after h/w processes are done.
ravb e6800000.ethernet eth0: failed to switch device to config
PM: Device e6800000.ethernet failed to resume: error -110
In addition, some module clocks that were disabled by
clk_disable_unused() may have been re-enabled, wasting power.
To fix this, restore all bits of the SMSTPCR registers that represent
clocks under control of Linux.
Notes:
- While this fixes EtherAVB operation after resume from s2ram,
EtherAVB cannot be used as an actual wake-up source from s2ram, only
from s2idle, due to PSCI limitations,
- To avoid overhead on platforms not needing it, the suspend/resume
code has a build time dependency on sleep and PSCI support, and a
runtime dependency on PSCI.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
2017-06-07 14:20:06 +03:00
|
|
|
/* Restore module clocks */
|
|
|
|
for (reg = 0; reg < ARRAY_SIZE(priv->smstpcr_saved); reg++) {
|
|
|
|
mask = priv->smstpcr_saved[reg].mask;
|
|
|
|
if (!mask)
|
|
|
|
continue;
|
|
|
|
|
2020-09-11 10:43:49 +03:00
|
|
|
if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A)
|
2020-09-11 10:43:50 +03:00
|
|
|
oldval = readb(priv->base + priv->control_regs[reg]);
|
2018-09-07 19:58:49 +03:00
|
|
|
else
|
2020-09-11 10:43:50 +03:00
|
|
|
oldval = readl(priv->base + priv->control_regs[reg]);
|
clk: renesas: cpg-mssr: Restore module clocks during resume
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
clock register state is lost. Note that as the boot loader skips most
initialization after system resume, clock register state differs from
the state encountered during normal system boot, too.
Hence after s2ram, some operations may fail because module clocks are
disabled, while drivers expect them to be still enabled. E.g. EtherAVB
fails when Wake-on-LAN has been enabled using "ethtool -s eth0 wol g":
ravb e6800000.ethernet eth0: failed to switch device to config mode
ravb e6800000.ethernet eth0: device will be stopped after h/w processes are done.
ravb e6800000.ethernet eth0: failed to switch device to config
PM: Device e6800000.ethernet failed to resume: error -110
In addition, some module clocks that were disabled by
clk_disable_unused() may have been re-enabled, wasting power.
To fix this, restore all bits of the SMSTPCR registers that represent
clocks under control of Linux.
Notes:
- While this fixes EtherAVB operation after resume from s2ram,
EtherAVB cannot be used as an actual wake-up source from s2ram, only
from s2idle, due to PSCI limitations,
- To avoid overhead on platforms not needing it, the suspend/resume
code has a build time dependency on sleep and PSCI support, and a
runtime dependency on PSCI.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
2017-06-07 14:20:06 +03:00
|
|
|
newval = oldval & ~mask;
|
|
|
|
newval |= priv->smstpcr_saved[reg].val & mask;
|
|
|
|
if (newval == oldval)
|
|
|
|
continue;
|
|
|
|
|
2020-09-11 10:43:49 +03:00
|
|
|
if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) {
|
2020-09-11 10:43:50 +03:00
|
|
|
writeb(newval, priv->base + priv->control_regs[reg]);
|
2018-09-07 19:58:49 +03:00
|
|
|
/* dummy read to ensure write has completed */
|
2020-09-11 10:43:50 +03:00
|
|
|
readb(priv->base + priv->control_regs[reg]);
|
|
|
|
barrier_data(priv->base + priv->control_regs[reg]);
|
2018-09-07 19:58:49 +03:00
|
|
|
continue;
|
|
|
|
} else
|
2020-09-11 10:43:50 +03:00
|
|
|
writel(newval, priv->base + priv->control_regs[reg]);
|
clk: renesas: cpg-mssr: Restore module clocks during resume
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
clock register state is lost. Note that as the boot loader skips most
initialization after system resume, clock register state differs from
the state encountered during normal system boot, too.
Hence after s2ram, some operations may fail because module clocks are
disabled, while drivers expect them to be still enabled. E.g. EtherAVB
fails when Wake-on-LAN has been enabled using "ethtool -s eth0 wol g":
ravb e6800000.ethernet eth0: failed to switch device to config mode
ravb e6800000.ethernet eth0: device will be stopped after h/w processes are done.
ravb e6800000.ethernet eth0: failed to switch device to config
PM: Device e6800000.ethernet failed to resume: error -110
In addition, some module clocks that were disabled by
clk_disable_unused() may have been re-enabled, wasting power.
To fix this, restore all bits of the SMSTPCR registers that represent
clocks under control of Linux.
Notes:
- While this fixes EtherAVB operation after resume from s2ram,
EtherAVB cannot be used as an actual wake-up source from s2ram, only
from s2idle, due to PSCI limitations,
- To avoid overhead on platforms not needing it, the suspend/resume
code has a build time dependency on sleep and PSCI support, and a
runtime dependency on PSCI.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
2017-06-07 14:20:06 +03:00
|
|
|
|
|
|
|
/* Wait until enabled clocks are really enabled */
|
|
|
|
mask &= ~priv->smstpcr_saved[reg].val;
|
|
|
|
if (!mask)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (i = 1000; i > 0; --i) {
|
2020-09-11 10:43:50 +03:00
|
|
|
oldval = readl(priv->base + priv->status_regs[reg]);
|
clk: renesas: cpg-mssr: Restore module clocks during resume
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
clock register state is lost. Note that as the boot loader skips most
initialization after system resume, clock register state differs from
the state encountered during normal system boot, too.
Hence after s2ram, some operations may fail because module clocks are
disabled, while drivers expect them to be still enabled. E.g. EtherAVB
fails when Wake-on-LAN has been enabled using "ethtool -s eth0 wol g":
ravb e6800000.ethernet eth0: failed to switch device to config mode
ravb e6800000.ethernet eth0: device will be stopped after h/w processes are done.
ravb e6800000.ethernet eth0: failed to switch device to config
PM: Device e6800000.ethernet failed to resume: error -110
In addition, some module clocks that were disabled by
clk_disable_unused() may have been re-enabled, wasting power.
To fix this, restore all bits of the SMSTPCR registers that represent
clocks under control of Linux.
Notes:
- While this fixes EtherAVB operation after resume from s2ram,
EtherAVB cannot be used as an actual wake-up source from s2ram, only
from s2idle, due to PSCI limitations,
- To avoid overhead on platforms not needing it, the suspend/resume
code has a build time dependency on sleep and PSCI support, and a
runtime dependency on PSCI.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
2017-06-07 14:20:06 +03:00
|
|
|
if (!(oldval & mask))
|
|
|
|
break;
|
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!i)
|
2023-01-11 11:23:34 +03:00
|
|
|
dev_warn(dev, "Failed to enable SMSTP%u[0x%x]\n", reg,
|
|
|
|
oldval & mask);
|
clk: renesas: cpg-mssr: Restore module clocks during resume
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
clock register state is lost. Note that as the boot loader skips most
initialization after system resume, clock register state differs from
the state encountered during normal system boot, too.
Hence after s2ram, some operations may fail because module clocks are
disabled, while drivers expect them to be still enabled. E.g. EtherAVB
fails when Wake-on-LAN has been enabled using "ethtool -s eth0 wol g":
ravb e6800000.ethernet eth0: failed to switch device to config mode
ravb e6800000.ethernet eth0: device will be stopped after h/w processes are done.
ravb e6800000.ethernet eth0: failed to switch device to config
PM: Device e6800000.ethernet failed to resume: error -110
In addition, some module clocks that were disabled by
clk_disable_unused() may have been re-enabled, wasting power.
To fix this, restore all bits of the SMSTPCR registers that represent
clocks under control of Linux.
Notes:
- While this fixes EtherAVB operation after resume from s2ram,
EtherAVB cannot be used as an actual wake-up source from s2ram, only
from s2idle, due to PSCI limitations,
- To avoid overhead on platforms not needing it, the suspend/resume
code has a build time dependency on sleep and PSCI support, and a
runtime dependency on PSCI.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
2017-06-07 14:20:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dev_pm_ops cpg_mssr_pm = {
|
|
|
|
SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(cpg_mssr_suspend_noirq,
|
|
|
|
cpg_mssr_resume_noirq)
|
|
|
|
};
|
|
|
|
#define DEV_PM_OPS &cpg_mssr_pm
|
|
|
|
#else
|
|
|
|
#define DEV_PM_OPS NULL
|
|
|
|
#endif /* CONFIG_PM_SLEEP && CONFIG_ARM_PSCI_FW */
|
|
|
|
|
2018-09-24 19:49:35 +03:00
|
|
|
static int __init cpg_mssr_common_init(struct device *dev,
|
|
|
|
struct device_node *np,
|
|
|
|
const struct cpg_mssr_info *info)
|
2015-10-16 12:41:19 +03:00
|
|
|
{
|
|
|
|
struct cpg_mssr_priv *priv;
|
|
|
|
unsigned int nclks, i;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (info->init) {
|
|
|
|
error = info->init(dev);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2019-06-12 18:27:56 +03:00
|
|
|
nclks = info->num_total_core_clks + info->num_hw_mod_clks;
|
|
|
|
priv = kzalloc(struct_size(priv, clks, nclks), GFP_KERNEL);
|
2015-10-16 12:41:19 +03:00
|
|
|
if (!priv)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2018-09-24 19:49:35 +03:00
|
|
|
priv->np = np;
|
2015-10-16 12:41:19 +03:00
|
|
|
priv->dev = dev;
|
2017-01-20 12:58:11 +03:00
|
|
|
spin_lock_init(&priv->rmw_lock);
|
2015-10-16 12:41:19 +03:00
|
|
|
|
2018-09-24 19:49:35 +03:00
|
|
|
priv->base = of_iomap(np, 0);
|
|
|
|
if (!priv->base) {
|
|
|
|
error = -ENOMEM;
|
|
|
|
goto out_err;
|
|
|
|
}
|
2015-10-16 12:41:19 +03:00
|
|
|
|
|
|
|
priv->num_core_clks = info->num_total_core_clks;
|
|
|
|
priv->num_mod_clks = info->num_hw_mod_clks;
|
|
|
|
priv->last_dt_core_clk = info->last_dt_core_clk;
|
2017-06-21 23:24:15 +03:00
|
|
|
RAW_INIT_NOTIFIER_HEAD(&priv->notifiers);
|
2020-09-11 10:43:49 +03:00
|
|
|
priv->reg_layout = info->reg_layout;
|
2020-09-11 10:43:50 +03:00
|
|
|
if (priv->reg_layout == CLK_REG_LAYOUT_RCAR_GEN2_AND_GEN3) {
|
|
|
|
priv->status_regs = mstpsr;
|
|
|
|
priv->control_regs = smstpcr;
|
|
|
|
priv->reset_regs = srcr;
|
|
|
|
priv->reset_clear_regs = srstclr;
|
|
|
|
} else if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A) {
|
|
|
|
priv->control_regs = stbcr;
|
2021-12-01 10:33:02 +03:00
|
|
|
} else if (priv->reg_layout == CLK_REG_LAYOUT_RCAR_GEN4) {
|
|
|
|
priv->status_regs = mstpsr_for_gen4;
|
|
|
|
priv->control_regs = mstpcr_for_gen4;
|
|
|
|
priv->reset_regs = srcr_for_gen4;
|
|
|
|
priv->reset_clear_regs = srstclr_for_gen4;
|
2020-09-11 10:43:50 +03:00
|
|
|
} else {
|
|
|
|
error = -EINVAL;
|
|
|
|
goto out_err;
|
|
|
|
}
|
2015-10-16 12:41:19 +03:00
|
|
|
|
|
|
|
for (i = 0; i < nclks; i++)
|
2019-06-12 18:27:56 +03:00
|
|
|
priv->clks[i] = ERR_PTR(-ENOENT);
|
2015-10-16 12:41:19 +03:00
|
|
|
|
2018-09-24 19:49:35 +03:00
|
|
|
error = of_clk_add_provider(np, cpg_mssr_clk_src_twocell_get, priv);
|
|
|
|
if (error)
|
|
|
|
goto out_err;
|
|
|
|
|
2022-12-23 17:40:17 +03:00
|
|
|
cpg_mssr_priv = priv;
|
|
|
|
|
2018-09-24 19:49:35 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
if (priv->base)
|
|
|
|
iounmap(priv->base);
|
|
|
|
kfree(priv);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __init cpg_mssr_early_init(struct device_node *np,
|
|
|
|
const struct cpg_mssr_info *info)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
error = cpg_mssr_common_init(NULL, np, info);
|
|
|
|
if (error)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < info->num_early_core_clks; i++)
|
|
|
|
cpg_mssr_register_core_clk(&info->early_core_clks[i], info,
|
|
|
|
cpg_mssr_priv);
|
|
|
|
|
|
|
|
for (i = 0; i < info->num_early_mod_clks; i++)
|
|
|
|
cpg_mssr_register_mod_clk(&info->early_mod_clks[i], info,
|
|
|
|
cpg_mssr_priv);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init cpg_mssr_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct device_node *np = dev->of_node;
|
|
|
|
const struct cpg_mssr_info *info;
|
|
|
|
struct cpg_mssr_priv *priv;
|
|
|
|
unsigned int i;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
info = of_device_get_match_data(dev);
|
|
|
|
|
|
|
|
if (!cpg_mssr_priv) {
|
|
|
|
error = cpg_mssr_common_init(dev, dev->of_node, info);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv = cpg_mssr_priv;
|
|
|
|
priv->dev = dev;
|
|
|
|
dev_set_drvdata(dev, priv);
|
|
|
|
|
2015-10-16 12:41:19 +03:00
|
|
|
for (i = 0; i < info->num_core_clks; i++)
|
|
|
|
cpg_mssr_register_core_clk(&info->core_clks[i], info, priv);
|
|
|
|
|
|
|
|
for (i = 0; i < info->num_mod_clks; i++)
|
|
|
|
cpg_mssr_register_mod_clk(&info->mod_clks[i], info, priv);
|
|
|
|
|
2016-02-23 12:30:03 +03:00
|
|
|
error = devm_add_action_or_reset(dev,
|
|
|
|
cpg_mssr_del_clk_provider,
|
|
|
|
np);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2015-10-16 12:41:19 +03:00
|
|
|
|
|
|
|
error = cpg_mssr_add_clk_domain(dev, info->core_pm_clks,
|
|
|
|
info->num_core_pm_clks);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2018-09-07 19:58:49 +03:00
|
|
|
/* Reset Controller not supported for Standby Control SoCs */
|
2020-09-11 10:43:49 +03:00
|
|
|
if (priv->reg_layout == CLK_REG_LAYOUT_RZ_A)
|
2018-09-07 19:58:49 +03:00
|
|
|
return 0;
|
|
|
|
|
2017-01-20 13:03:03 +03:00
|
|
|
error = cpg_mssr_reset_controller_register(priv);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2015-10-16 12:41:19 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver cpg_mssr_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "renesas-cpg-mssr",
|
|
|
|
.of_match_table = cpg_mssr_match,
|
clk: renesas: cpg-mssr: Restore module clocks during resume
During PSCI system suspend, R-Car Gen3 SoCs are powered down, and their
clock register state is lost. Note that as the boot loader skips most
initialization after system resume, clock register state differs from
the state encountered during normal system boot, too.
Hence after s2ram, some operations may fail because module clocks are
disabled, while drivers expect them to be still enabled. E.g. EtherAVB
fails when Wake-on-LAN has been enabled using "ethtool -s eth0 wol g":
ravb e6800000.ethernet eth0: failed to switch device to config mode
ravb e6800000.ethernet eth0: device will be stopped after h/w processes are done.
ravb e6800000.ethernet eth0: failed to switch device to config
PM: Device e6800000.ethernet failed to resume: error -110
In addition, some module clocks that were disabled by
clk_disable_unused() may have been re-enabled, wasting power.
To fix this, restore all bits of the SMSTPCR registers that represent
clocks under control of Linux.
Notes:
- While this fixes EtherAVB operation after resume from s2ram,
EtherAVB cannot be used as an actual wake-up source from s2ram, only
from s2idle, due to PSCI limitations,
- To avoid overhead on platforms not needing it, the suspend/resume
code has a build time dependency on sleep and PSCI support, and a
runtime dependency on PSCI.
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
2017-06-07 14:20:06 +03:00
|
|
|
.pm = DEV_PM_OPS,
|
2015-10-16 12:41:19 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init cpg_mssr_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_probe(&cpg_mssr_driver, cpg_mssr_probe);
|
|
|
|
}
|
|
|
|
|
|
|
|
subsys_initcall(cpg_mssr_init);
|
|
|
|
|
2016-09-29 15:47:58 +03:00
|
|
|
void __init mssr_mod_nullify(struct mssr_mod_clk *mod_clks,
|
|
|
|
unsigned int num_mod_clks,
|
|
|
|
const unsigned int *clks, unsigned int n)
|
|
|
|
{
|
|
|
|
unsigned int i, j;
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < num_mod_clks && j < n; i++)
|
|
|
|
if (mod_clks[i].id == clks[j]) {
|
|
|
|
mod_clks[i].name = NULL;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-16 12:41:19 +03:00
|
|
|
MODULE_DESCRIPTION("Renesas CPG/MSSR Driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|