linux/arch/blackfin/mach-bf609/clock.c

410 lines
8.8 KiB
C
Raw Normal View History

License cleanup: add SPDX GPL-2.0 license identifier to files with no license Many source files in the tree are missing licensing information, which makes it harder for compliance tools to determine the correct license. By default all files without license information are under the default license of the kernel, which is GPL version 2. Update the files which contain no license information with the 'GPL-2.0' SPDX license identifier. The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. This patch is based on work done by Thomas Gleixner and Kate Stewart and Philippe Ombredanne. How this work was done: Patches were generated and checked against linux-4.14-rc6 for a subset of the use cases: - file had no licensing information it it. - file was a */uapi/* one with no licensing information in it, - file was a */uapi/* one with existing licensing information, Further patches will be generated in subsequent months to fix up cases where non-standard license headers were used, and references to license had to be inferred by heuristics based on keywords. The analysis to determine which SPDX License Identifier to be applied to a file was done in a spreadsheet of side by side results from of the output of two independent scanners (ScanCode & Windriver) producing SPDX tag:value files created by Philippe Ombredanne. Philippe prepared the base worksheet, and did an initial spot review of a few 1000 files. The 4.13 kernel was the starting point of the analysis with 60,537 files assessed. Kate Stewart did a file by file comparison of the scanner results in the spreadsheet to determine which SPDX license identifier(s) to be applied to the file. She confirmed any determination that was not immediately clear with lawyers working with the Linux Foundation. Criteria used to select files for SPDX license identifier tagging was: - Files considered eligible had to be source code files. - Make and config files were included as candidates if they contained >5 lines of source - File already had some variant of a license header in it (even if <5 lines). All documentation files were explicitly excluded. The following heuristics were used to determine which SPDX license identifiers to apply. - when both scanners couldn't find any license traces, file was considered to have no license information in it, and the top level COPYING file license applied. For non */uapi/* files that summary was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 11139 and resulted in the first patch in this series. If that file was a */uapi/* path one, it was "GPL-2.0 WITH Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 WITH Linux-syscall-note 930 and resulted in the second patch in this series. - if a file had some form of licensing information in it, and was one of the */uapi/* ones, it was denoted with the Linux-syscall-note if any GPL family license was found in the file or had no licensing in it (per prior point). Results summary: SPDX license identifier # files ---------------------------------------------------|------ GPL-2.0 WITH Linux-syscall-note 270 GPL-2.0+ WITH Linux-syscall-note 169 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17 LGPL-2.1+ WITH Linux-syscall-note 15 GPL-1.0+ WITH Linux-syscall-note 14 ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5 LGPL-2.0+ WITH Linux-syscall-note 4 LGPL-2.1 WITH Linux-syscall-note 3 ((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3 ((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1 and that resulted in the third patch in this series. - when the two scanners agreed on the detected license(s), that became the concluded license(s). - when there was disagreement between the two scanners (one detected a license but the other didn't, or they both detected different licenses) a manual inspection of the file occurred. - In most cases a manual inspection of the information in the file resulted in a clear resolution of the license that should apply (and which scanner probably needed to revisit its heuristics). - When it was not immediately clear, the license identifier was confirmed with lawyers working with the Linux Foundation. - If there was any question as to the appropriate license identifier, the file was flagged for further research and to be revisited later in time. In total, over 70 hours of logged manual review was done on the spreadsheet to determine the SPDX license identifiers to apply to the source files by Kate, Philippe, Thomas and, in some cases, confirmation by lawyers working with the Linux Foundation. Kate also obtained a third independent scan of the 4.13 code base from FOSSology, and compared selected files where the other two scanners disagreed against that SPDX file, to see if there was new insights. The Windriver scanner is based on an older version of FOSSology in part, so they are related. Thomas did random spot checks in about 500 files from the spreadsheets for the uapi headers and agreed with SPDX license identifier in the files he inspected. For the non-uapi files Thomas did random spot checks in about 15000 files. In initial set of patches against 4.14-rc6, 3 files were found to have copy/paste license identifier errors, and have been fixed to reflect the correct identifier. Additionally Philippe spent 10 hours this week doing a detailed manual inspection and review of the 12,461 patched files from the initial patch version early this week with: - a full scancode scan run, collecting the matched texts, detected license ids and scores - reviewing anything where there was a license detected (about 500+ files) to ensure that the applied SPDX license was correct - reviewing anything where there was no detection but the patch license was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied SPDX license was correct This produced a worksheet with 20 files needing minor correction. This worksheet was then exported into 3 different .csv files for the different types of files to be modified. These .csv files were then reviewed by Greg. Thomas wrote a script to parse the csv files and add the proper SPDX tag to the file, in the format that the file expected. This script was further refined by Greg based on the output to detect more types of files automatically and to distinguish between header and source .c files (which need different comment types.) Finally Greg ran the script using the .csv files to generate the patches. Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 14:07:57 +00:00
// SPDX-License-Identifier: GPL-2.0
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/errno.h>
#include <linux/err.h>
#include <linux/string.h>
#include <linux/clk.h>
#include <linux/mutex.h>
#include <linux/spinlock.h>
#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/init.h>
#include <linux/timer.h>
#include <linux/io.h>
#include <linux/seq_file.h>
#include <linux/clkdev.h>
#include <asm/clocks.h>
#define CGU0_CTL_DF (1 << 0)
#define CGU0_CTL_MSEL_SHIFT 8
#define CGU0_CTL_MSEL_MASK (0x7f << 8)
#define CGU0_STAT_PLLEN (1 << 0)
#define CGU0_STAT_PLLBP (1 << 1)
#define CGU0_STAT_PLLLK (1 << 2)
#define CGU0_STAT_CLKSALGN (1 << 3)
#define CGU0_STAT_CCBF0 (1 << 4)
#define CGU0_STAT_CCBF1 (1 << 5)
#define CGU0_STAT_SCBF0 (1 << 6)
#define CGU0_STAT_SCBF1 (1 << 7)
#define CGU0_STAT_DCBF (1 << 8)
#define CGU0_STAT_OCBF (1 << 9)
#define CGU0_STAT_ADDRERR (1 << 16)
#define CGU0_STAT_LWERR (1 << 17)
#define CGU0_STAT_DIVERR (1 << 18)
#define CGU0_STAT_WDFMSERR (1 << 19)
#define CGU0_STAT_WDIVERR (1 << 20)
#define CGU0_STAT_PLOCKERR (1 << 21)
#define CGU0_DIV_CSEL_SHIFT 0
#define CGU0_DIV_CSEL_MASK 0x0000001F
#define CGU0_DIV_S0SEL_SHIFT 5
#define CGU0_DIV_S0SEL_MASK (0x3 << CGU0_DIV_S0SEL_SHIFT)
#define CGU0_DIV_SYSSEL_SHIFT 8
#define CGU0_DIV_SYSSEL_MASK (0x1f << CGU0_DIV_SYSSEL_SHIFT)
#define CGU0_DIV_S1SEL_SHIFT 13
#define CGU0_DIV_S1SEL_MASK (0x3 << CGU0_DIV_S1SEL_SHIFT)
#define CGU0_DIV_DSEL_SHIFT 16
#define CGU0_DIV_DSEL_MASK (0x1f << CGU0_DIV_DSEL_SHIFT)
#define CGU0_DIV_OSEL_SHIFT 22
#define CGU0_DIV_OSEL_MASK (0x7f << CGU0_DIV_OSEL_SHIFT)
#define CLK(_clk, _devname, _conname) \
{ \
.clk = &_clk, \
.dev_id = _devname, \
.con_id = _conname, \
}
#define NEEDS_INITIALIZATION 0x11
static LIST_HEAD(clk_list);
static void clk_reg_write_mask(u32 reg, uint32_t val, uint32_t mask)
{
u32 val2;
val2 = bfin_read32(reg);
val2 &= ~mask;
val2 |= val;
bfin_write32(reg, val2);
}
int wait_for_pll_align(void)
{
int i = 10000;
while (i-- && (bfin_read32(CGU0_STAT) & CGU0_STAT_CLKSALGN));
if (bfin_read32(CGU0_STAT) & CGU0_STAT_CLKSALGN) {
printk(KERN_CRIT "fail to align clk\n");
return -1;
}
return 0;
}
int clk_enable(struct clk *clk)
{
int ret = -EIO;
if (clk->ops && clk->ops->enable)
ret = clk->ops->enable(clk);
return ret;
}
EXPORT_SYMBOL(clk_enable);
void clk_disable(struct clk *clk)
{
if (!clk)
return;
if (clk->ops && clk->ops->disable)
clk->ops->disable(clk);
}
EXPORT_SYMBOL(clk_disable);
unsigned long clk_get_rate(struct clk *clk)
{
unsigned long ret = 0;
if (clk->ops && clk->ops->get_rate)
ret = clk->ops->get_rate(clk);
return ret;
}
EXPORT_SYMBOL(clk_get_rate);
long clk_round_rate(struct clk *clk, unsigned long rate)
{
long ret = 0;
if (clk->ops && clk->ops->round_rate)
ret = clk->ops->round_rate(clk, rate);
return ret;
}
EXPORT_SYMBOL(clk_round_rate);
int clk_set_rate(struct clk *clk, unsigned long rate)
{
int ret = -EIO;
if (clk->ops && clk->ops->set_rate)
ret = clk->ops->set_rate(clk, rate);
return ret;
}
EXPORT_SYMBOL(clk_set_rate);
unsigned long vco_get_rate(struct clk *clk)
{
return clk->rate;
}
unsigned long pll_get_rate(struct clk *clk)
{
u32 df;
u32 msel;
u32 ctl = bfin_read32(CGU0_CTL);
u32 stat = bfin_read32(CGU0_STAT);
if (stat & CGU0_STAT_PLLBP)
return 0;
msel = (ctl & CGU0_CTL_MSEL_MASK) >> CGU0_CTL_MSEL_SHIFT;
df = (ctl & CGU0_CTL_DF);
clk->parent->rate = clk_get_rate(clk->parent);
return clk->parent->rate / (df + 1) * msel * 2;
}
unsigned long pll_round_rate(struct clk *clk, unsigned long rate)
{
u32 div;
div = rate / clk->parent->rate;
return clk->parent->rate * div;
}
int pll_set_rate(struct clk *clk, unsigned long rate)
{
u32 msel;
u32 stat = bfin_read32(CGU0_STAT);
if (!(stat & CGU0_STAT_PLLEN))
return -EBUSY;
if (!(stat & CGU0_STAT_PLLLK))
return -EBUSY;
if (wait_for_pll_align())
return -EBUSY;
msel = rate / clk->parent->rate / 2;
clk_reg_write_mask(CGU0_CTL, msel << CGU0_CTL_MSEL_SHIFT,
CGU0_CTL_MSEL_MASK);
clk->rate = rate;
return 0;
}
unsigned long cclk_get_rate(struct clk *clk)
{
if (clk->parent)
return clk->parent->rate;
else
return 0;
}
unsigned long sys_clk_get_rate(struct clk *clk)
{
unsigned long drate;
u32 msel;
u32 df;
u32 ctl = bfin_read32(CGU0_CTL);
u32 div = bfin_read32(CGU0_DIV);
div = (div & clk->mask) >> clk->shift;
msel = (ctl & CGU0_CTL_MSEL_MASK) >> CGU0_CTL_MSEL_SHIFT;
df = (ctl & CGU0_CTL_DF);
if (!strcmp(clk->parent->name, "SYS_CLKIN")) {
drate = clk->parent->rate / (df + 1);
drate *= msel;
drate /= div;
return drate;
} else {
clk->parent->rate = clk_get_rate(clk->parent);
return clk->parent->rate / div;
}
}
unsigned long dummy_get_rate(struct clk *clk)
{
clk->parent->rate = clk_get_rate(clk->parent);
return clk->parent->rate;
}
unsigned long sys_clk_round_rate(struct clk *clk, unsigned long rate)
{
unsigned long max_rate;
unsigned long drate;
int i;
u32 msel;
u32 df;
u32 ctl = bfin_read32(CGU0_CTL);
msel = (ctl & CGU0_CTL_MSEL_MASK) >> CGU0_CTL_MSEL_SHIFT;
df = (ctl & CGU0_CTL_DF);
max_rate = clk->parent->rate / (df + 1) * msel;
if (rate > max_rate)
return 0;
for (i = 1; i < clk->mask; i++) {
drate = max_rate / i;
if (rate >= drate)
return drate;
}
return 0;
}
int sys_clk_set_rate(struct clk *clk, unsigned long rate)
{
u32 div = bfin_read32(CGU0_DIV);
div = (div & clk->mask) >> clk->shift;
rate = clk_round_rate(clk, rate);
if (!rate)
return -EINVAL;
div = (clk_get_rate(clk) * div) / rate;
if (wait_for_pll_align())
return -EBUSY;
clk_reg_write_mask(CGU0_DIV, div << clk->shift,
clk->mask);
clk->rate = rate;
return 0;
}
static struct clk_ops vco_ops = {
.get_rate = vco_get_rate,
};
static struct clk_ops pll_ops = {
.get_rate = pll_get_rate,
.set_rate = pll_set_rate,
};
static struct clk_ops cclk_ops = {
.get_rate = cclk_get_rate,
};
static struct clk_ops sys_clk_ops = {
.get_rate = sys_clk_get_rate,
.set_rate = sys_clk_set_rate,
.round_rate = sys_clk_round_rate,
};
static struct clk_ops dummy_clk_ops = {
.get_rate = dummy_get_rate,
};
static struct clk sys_clkin = {
.name = "SYS_CLKIN",
.rate = CONFIG_CLKIN_HZ,
.ops = &vco_ops,
};
static struct clk pll_clk = {
.name = "PLLCLK",
.rate = 500000000,
.parent = &sys_clkin,
.ops = &pll_ops,
.flags = NEEDS_INITIALIZATION,
};
static struct clk cclk = {
.name = "CCLK",
.rate = 500000000,
.mask = CGU0_DIV_CSEL_MASK,
.shift = CGU0_DIV_CSEL_SHIFT,
.parent = &sys_clkin,
.ops = &sys_clk_ops,
.flags = NEEDS_INITIALIZATION,
};
static struct clk cclk0 = {
.name = "CCLK0",
.parent = &cclk,
.ops = &cclk_ops,
};
static struct clk cclk1 = {
.name = "CCLK1",
.parent = &cclk,
.ops = &cclk_ops,
};
static struct clk sysclk = {
.name = "SYSCLK",
.rate = 500000000,
.mask = CGU0_DIV_SYSSEL_MASK,
.shift = CGU0_DIV_SYSSEL_SHIFT,
.parent = &sys_clkin,
.ops = &sys_clk_ops,
.flags = NEEDS_INITIALIZATION,
};
static struct clk sclk0 = {
.name = "SCLK0",
.rate = 500000000,
.mask = CGU0_DIV_S0SEL_MASK,
.shift = CGU0_DIV_S0SEL_SHIFT,
.parent = &sysclk,
.ops = &sys_clk_ops,
};
static struct clk sclk1 = {
.name = "SCLK1",
.rate = 500000000,
.mask = CGU0_DIV_S1SEL_MASK,
.shift = CGU0_DIV_S1SEL_SHIFT,
.parent = &sysclk,
.ops = &sys_clk_ops,
};
static struct clk dclk = {
.name = "DCLK",
.rate = 500000000,
.mask = CGU0_DIV_DSEL_MASK,
.shift = CGU0_DIV_DSEL_SHIFT,
.parent = &sys_clkin,
.ops = &sys_clk_ops,
};
static struct clk oclk = {
.name = "OCLK",
.rate = 500000000,
.mask = CGU0_DIV_OSEL_MASK,
.shift = CGU0_DIV_OSEL_SHIFT,
.parent = &pll_clk,
};
static struct clk ethclk = {
.name = "stmmaceth",
.parent = &sclk0,
.ops = &dummy_clk_ops,
};
static struct clk ethpclk = {
.name = "pclk",
.parent = &sclk0,
.ops = &dummy_clk_ops,
};
static struct clk spiclk = {
.name = "spi",
.parent = &sclk1,
.ops = &dummy_clk_ops,
};
static struct clk_lookup bf609_clks[] = {
CLK(sys_clkin, NULL, "SYS_CLKIN"),
CLK(pll_clk, NULL, "PLLCLK"),
CLK(cclk, NULL, "CCLK"),
CLK(cclk0, NULL, "CCLK0"),
CLK(cclk1, NULL, "CCLK1"),
CLK(sysclk, NULL, "SYSCLK"),
CLK(sclk0, NULL, "SCLK0"),
CLK(sclk1, NULL, "SCLK1"),
CLK(dclk, NULL, "DCLK"),
CLK(oclk, NULL, "OCLK"),
CLK(ethclk, NULL, "stmmaceth"),
CLK(ethpclk, NULL, "pclk"),
CLK(spiclk, NULL, "spi"),
};
int __init clk_init(void)
{
int i;
struct clk *clkp;
for (i = 0; i < ARRAY_SIZE(bf609_clks); i++) {
clkp = bf609_clks[i].clk;
if (clkp->flags & NEEDS_INITIALIZATION)
clk_get_rate(clkp);
}
clkdev_add_table(bf609_clks, ARRAY_SIZE(bf609_clks));
return 0;
}