blob: d6960de64d4a08dbae5cdcd2bb9a27b16803b2e3 [file] [log] [blame]
Linus Walleij401301c2012-11-20 22:39:31 +01001/*
Rob Herringa54c9592014-03-01 22:05:44 -06002 * Clock driver for the ARM Integrator/AP, Integrator/CP, Versatile AB and
3 * Versatile PB boards.
Linus Walleij401301c2012-11-20 22:39:31 +01004 * Copyright (C) 2012 Linus Walleij
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#include <linux/clk-provider.h>
Linus Walleija6131632012-06-11 17:33:12 +020011#include <linux/err.h>
Linus Walleij09c978b2014-01-10 15:57:27 +010012#include <linux/of.h>
13#include <linux/of_address.h>
Linus Walleija6131632012-06-11 17:33:12 +020014
Linus Walleijba3fae02017-02-01 10:41:43 +010015#include "icst.h"
Linus Walleija6131632012-06-11 17:33:12 +020016#include "clk-icst.h"
17
Linus Walleij09c978b2014-01-10 15:57:27 +010018#define INTEGRATOR_HDR_LOCK_OFFSET 0x14
Linus Walleija6131632012-06-11 17:33:12 +020019
Rob Herringa54c9592014-03-01 22:05:44 -060020#define VERSATILE_SYS_OSCCLCD_OFFSET 0x1c
21#define VERSATILE_SYS_LOCK_OFFSET 0x20
22
Linus Walleij09c978b2014-01-10 15:57:27 +010023/* Base offset for the core module */
24static void __iomem *cm_base;
25
26static const struct icst_params cp_auxosc_params = {
Linus Walleija6131632012-06-11 17:33:12 +020027 .vco_max = ICST525_VCO_MAX_5V,
28 .vco_min = ICST525_VCO_MIN,
29 .vd_min = 8,
30 .vd_max = 263,
31 .rd_min = 3,
32 .rd_max = 65,
33 .s2div = icst525_s2div,
34 .idx2s = icst525_idx2s,
35};
36
Nicolas Pitree3ee2762015-07-28 19:43:20 -040037static const struct clk_icst_desc cm_auxosc_desc __initconst = {
Linus Walleij09c978b2014-01-10 15:57:27 +010038 .params = &cp_auxosc_params,
Linus Walleij7a9ad672012-11-20 23:01:04 +010039 .vco_offset = 0x1c,
40 .lock_offset = INTEGRATOR_HDR_LOCK_OFFSET,
Linus Walleija6131632012-06-11 17:33:12 +020041};
42
Rob Herringa54c9592014-03-01 22:05:44 -060043static const struct icst_params versatile_auxosc_params = {
44 .vco_max = ICST307_VCO_MAX,
45 .vco_min = ICST307_VCO_MIN,
46 .vd_min = 4 + 8,
47 .vd_max = 511 + 8,
48 .rd_min = 1 + 2,
49 .rd_max = 127 + 2,
50 .s2div = icst307_s2div,
51 .idx2s = icst307_idx2s,
52};
53
54static const struct clk_icst_desc versatile_auxosc_desc __initconst = {
55 .params = &versatile_auxosc_params,
56 .vco_offset = VERSATILE_SYS_OSCCLCD_OFFSET,
57 .lock_offset = VERSATILE_SYS_LOCK_OFFSET,
58};
59static void __init cm_osc_setup(struct device_node *np,
60 const struct clk_icst_desc *desc)
Linus Walleija6131632012-06-11 17:33:12 +020061{
Linus Walleij09c978b2014-01-10 15:57:27 +010062 struct clk *clk = ERR_PTR(-EINVAL);
63 const char *clk_name = np->name;
Linus Walleijbf6edb42014-01-20 21:31:41 +010064 const char *parent_name;
Linus Walleija6131632012-06-11 17:33:12 +020065
Linus Walleij09c978b2014-01-10 15:57:27 +010066 if (!cm_base) {
67 /* Remap the core module base if not done yet */
68 struct device_node *parent;
Linus Walleija6131632012-06-11 17:33:12 +020069
Linus Walleij09c978b2014-01-10 15:57:27 +010070 parent = of_get_parent(np);
Julia Lawalle52786a2015-04-04 16:59:29 +020071 if (!parent) {
Linus Walleij09c978b2014-01-10 15:57:27 +010072 pr_err("no parent on core module clock\n");
73 return;
74 }
75 cm_base = of_iomap(parent, 0);
76 if (!cm_base) {
77 pr_err("could not remap core module base\n");
78 return;
79 }
80 }
Linus Walleija6131632012-06-11 17:33:12 +020081
Linus Walleijbf6edb42014-01-20 21:31:41 +010082 parent_name = of_clk_get_parent_name(np, 0);
83 clk = icst_clk_register(NULL, desc, clk_name, parent_name, cm_base);
Linus Walleij09c978b2014-01-10 15:57:27 +010084 if (!IS_ERR(clk))
85 of_clk_add_provider(np, of_clk_src_simple_get, clk);
Linus Walleija6131632012-06-11 17:33:12 +020086}
Rob Herringa54c9592014-03-01 22:05:44 -060087
88static void __init of_integrator_cm_osc_setup(struct device_node *np)
89{
90 cm_osc_setup(np, &cm_auxosc_desc);
91}
Linus Walleij09c978b2014-01-10 15:57:27 +010092CLK_OF_DECLARE(integrator_cm_auxosc_clk,
93 "arm,integrator-cm-auxosc", of_integrator_cm_osc_setup);
Rob Herringa54c9592014-03-01 22:05:44 -060094
95static void __init of_versatile_cm_osc_setup(struct device_node *np)
96{
97 cm_osc_setup(np, &versatile_auxosc_desc);
98}
99CLK_OF_DECLARE(versatile_cm_auxosc_clk,
100 "arm,versatile-cm-auxosc", of_versatile_cm_osc_setup);