2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-07-20 09:55:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Atmel Corporation
|
|
|
|
* Wenyou.Yang <wenyou.yang@atmel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <clk-uclass.h>
|
2017-05-17 23:18:03 +00:00
|
|
|
#include <dm.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2016-07-20 09:55:12 +00:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <mach/at91_pmc.h>
|
|
|
|
#include "pmc.h"
|
|
|
|
|
|
|
|
#define PERIPHERAL_ID_MIN 2
|
|
|
|
#define PERIPHERAL_ID_MAX 31
|
|
|
|
#define PERIPHERAL_MASK(id) (1 << ((id) & PERIPHERAL_ID_MAX))
|
|
|
|
|
2017-04-14 06:53:22 +00:00
|
|
|
enum periph_clk_type {
|
|
|
|
CLK_PERIPH_AT91RM9200 = 0,
|
|
|
|
CLK_PERIPH_AT91SAM9X5,
|
|
|
|
};
|
2016-09-27 03:00:29 +00:00
|
|
|
/**
|
|
|
|
* sam9x5_periph_clk_bind() - for the periph clock driver
|
|
|
|
* Recursively bind its children as clk devices.
|
|
|
|
*
|
|
|
|
* @return: 0 on success, or negative error code on failure
|
|
|
|
*/
|
|
|
|
static int sam9x5_periph_clk_bind(struct udevice *dev)
|
|
|
|
{
|
|
|
|
return at91_clk_sub_device_bind(dev, "periph-clk");
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id sam9x5_periph_clk_match[] = {
|
2017-04-14 06:53:22 +00:00
|
|
|
{
|
|
|
|
.compatible = "atmel,at91rm9200-clk-peripheral",
|
|
|
|
.data = CLK_PERIPH_AT91RM9200,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.compatible = "atmel,at91sam9x5-clk-peripheral",
|
|
|
|
.data = CLK_PERIPH_AT91SAM9X5,
|
|
|
|
},
|
2016-09-27 03:00:29 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2020-06-25 04:10:04 +00:00
|
|
|
U_BOOT_DRIVER(atmel_at91rm9200_clk_peripheral) = {
|
|
|
|
.name = "atmel_at91rm9200_clk_peripheral",
|
2016-09-27 03:00:29 +00:00
|
|
|
.id = UCLASS_MISC,
|
|
|
|
.of_match = sam9x5_periph_clk_match,
|
|
|
|
.bind = sam9x5_periph_clk_bind,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*---------------------------------------------------------*/
|
|
|
|
|
|
|
|
static int periph_clk_enable(struct clk *clk)
|
2016-07-20 09:55:12 +00:00
|
|
|
{
|
|
|
|
struct pmc_platdata *plat = dev_get_platdata(clk->dev);
|
|
|
|
struct at91_pmc *pmc = plat->reg_base;
|
2017-04-14 06:53:22 +00:00
|
|
|
enum periph_clk_type clk_type;
|
|
|
|
void *addr;
|
2016-07-20 09:55:12 +00:00
|
|
|
|
|
|
|
if (clk->id < PERIPHERAL_ID_MIN)
|
|
|
|
return -1;
|
|
|
|
|
2017-04-14 06:53:22 +00:00
|
|
|
clk_type = dev_get_driver_data(dev_get_parent(clk->dev));
|
|
|
|
if (clk_type == CLK_PERIPH_AT91RM9200) {
|
|
|
|
addr = &pmc->pcer;
|
|
|
|
if (clk->id > PERIPHERAL_ID_MAX)
|
|
|
|
addr = &pmc->pcer1;
|
|
|
|
|
|
|
|
setbits_le32(addr, PERIPHERAL_MASK(clk->id));
|
|
|
|
} else {
|
|
|
|
writel(clk->id & AT91_PMC_PCR_PID_MASK, &pmc->pcr);
|
|
|
|
setbits_le32(&pmc->pcr,
|
|
|
|
AT91_PMC_PCR_CMD_WRITE | AT91_PMC_PCR_EN);
|
|
|
|
}
|
2016-07-20 09:55:12 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-27 03:00:29 +00:00
|
|
|
static ulong periph_get_rate(struct clk *clk)
|
2016-07-20 09:55:12 +00:00
|
|
|
{
|
2016-09-27 03:00:29 +00:00
|
|
|
struct udevice *dev;
|
|
|
|
struct clk clk_dev;
|
|
|
|
ulong clk_rate;
|
|
|
|
int ret;
|
2016-07-20 09:55:12 +00:00
|
|
|
|
2016-09-27 03:00:29 +00:00
|
|
|
dev = dev_get_parent(clk->dev);
|
|
|
|
|
|
|
|
ret = clk_get_by_index(dev, 0, &clk_dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
clk_rate = clk_get_rate(&clk_dev);
|
|
|
|
|
|
|
|
clk_free(&clk_dev);
|
|
|
|
|
|
|
|
return clk_rate;
|
2016-07-20 09:55:12 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 03:00:29 +00:00
|
|
|
static struct clk_ops periph_clk_ops = {
|
|
|
|
.of_xlate = at91_clk_of_xlate,
|
|
|
|
.enable = periph_clk_enable,
|
|
|
|
.get_rate = periph_get_rate,
|
2016-07-20 09:55:12 +00:00
|
|
|
};
|
|
|
|
|
2016-09-27 03:00:29 +00:00
|
|
|
U_BOOT_DRIVER(clk_periph) = {
|
|
|
|
.name = "periph-clk",
|
|
|
|
.id = UCLASS_CLK,
|
2016-07-20 09:55:12 +00:00
|
|
|
.platdata_auto_alloc_size = sizeof(struct pmc_platdata),
|
2016-09-27 03:00:29 +00:00
|
|
|
.probe = at91_clk_probe,
|
|
|
|
.ops = &periph_clk_ops,
|
2016-07-20 09:55:12 +00:00
|
|
|
};
|