2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-05-08 00:02:15 +08:00
|
|
|
/*
|
|
|
|
* drivers/clk/at91/clk-slow.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Boris BREZILLON <b.brezillon@overkiz.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk-provider.h>
|
|
|
|
#include <linux/clkdev.h>
|
|
|
|
#include <linux/clk/at91_pmc.h>
|
|
|
|
#include <linux/of.h>
|
2014-09-07 14:14:29 +08:00
|
|
|
#include <linux/mfd/syscon.h>
|
|
|
|
#include <linux/regmap.h>
|
2014-05-08 00:02:15 +08:00
|
|
|
|
|
|
|
#include "pmc.h"
|
|
|
|
|
|
|
|
struct clk_sam9260_slow {
|
|
|
|
struct clk_hw hw;
|
2014-09-07 14:14:29 +08:00
|
|
|
struct regmap *regmap;
|
2014-05-08 00:02:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define to_clk_sam9260_slow(hw) container_of(hw, struct clk_sam9260_slow, hw)
|
|
|
|
|
|
|
|
static u8 clk_sam9260_slow_get_parent(struct clk_hw *hw)
|
|
|
|
{
|
|
|
|
struct clk_sam9260_slow *slowck = to_clk_sam9260_slow(hw);
|
2014-09-07 14:14:29 +08:00
|
|
|
unsigned int status;
|
2014-05-08 00:02:15 +08:00
|
|
|
|
2014-09-07 14:14:29 +08:00
|
|
|
regmap_read(slowck->regmap, AT91_PMC_SR, &status);
|
|
|
|
|
|
|
|
return status & AT91_PMC_OSCSEL ? 1 : 0;
|
2014-05-08 00:02:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct clk_ops sam9260_slow_ops = {
|
|
|
|
.get_parent = clk_sam9260_slow_get_parent,
|
|
|
|
};
|
|
|
|
|
2018-10-16 22:21:44 +08:00
|
|
|
struct clk_hw * __init
|
2014-09-07 14:14:29 +08:00
|
|
|
at91_clk_register_sam9260_slow(struct regmap *regmap,
|
2014-05-08 00:02:15 +08:00
|
|
|
const char *name,
|
|
|
|
const char **parent_names,
|
|
|
|
int num_parents)
|
|
|
|
{
|
|
|
|
struct clk_sam9260_slow *slowck;
|
2016-06-02 05:31:22 +08:00
|
|
|
struct clk_hw *hw;
|
2014-05-08 00:02:15 +08:00
|
|
|
struct clk_init_data init;
|
2016-06-02 05:31:22 +08:00
|
|
|
int ret;
|
2014-05-08 00:02:15 +08:00
|
|
|
|
2014-09-07 14:14:29 +08:00
|
|
|
if (!name)
|
2014-05-08 00:02:15 +08:00
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
if (!parent_names || !num_parents)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
slowck = kzalloc(sizeof(*slowck), GFP_KERNEL);
|
|
|
|
if (!slowck)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
init.name = name;
|
|
|
|
init.ops = &sam9260_slow_ops;
|
|
|
|
init.parent_names = parent_names;
|
|
|
|
init.num_parents = num_parents;
|
|
|
|
init.flags = 0;
|
|
|
|
|
|
|
|
slowck->hw.init = &init;
|
2014-09-07 14:14:29 +08:00
|
|
|
slowck->regmap = regmap;
|
2014-05-08 00:02:15 +08:00
|
|
|
|
2016-06-02 05:31:22 +08:00
|
|
|
hw = &slowck->hw;
|
|
|
|
ret = clk_hw_register(NULL, &slowck->hw);
|
|
|
|
if (ret) {
|
2014-05-08 00:02:15 +08:00
|
|
|
kfree(slowck);
|
2016-06-02 05:31:22 +08:00
|
|
|
hw = ERR_PTR(ret);
|
|
|
|
}
|
2014-05-08 00:02:15 +08:00
|
|
|
|
2016-06-02 05:31:22 +08:00
|
|
|
return hw;
|
2014-05-08 00:02:15 +08:00
|
|
|
}
|