Linus Walleij | 401301c | 2012-11-20 22:39:31 +0100 | [diff] [blame] | 1 | /* |
Rob Herring | a54c959 | 2014-03-01 22:05:44 -0600 | [diff] [blame] | 2 | * Clock driver for the ARM Integrator/AP, Integrator/CP, Versatile AB and |
| 3 | * Versatile PB boards. |
Linus Walleij | 401301c | 2012-11-20 22:39:31 +0100 | [diff] [blame] | 4 | * 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 Walleij | a613163 | 2012-06-11 17:33:12 +0200 | [diff] [blame] | 11 | #include <linux/err.h> |
Linus Walleij | 09c978b | 2014-01-10 15:57:27 +0100 | [diff] [blame] | 12 | #include <linux/of.h> |
| 13 | #include <linux/of_address.h> |
Linus Walleij | a613163 | 2012-06-11 17:33:12 +0200 | [diff] [blame] | 14 | |
| 15 | #include "clk-icst.h" |
| 16 | |
Linus Walleij | 09c978b | 2014-01-10 15:57:27 +0100 | [diff] [blame] | 17 | #define INTEGRATOR_HDR_LOCK_OFFSET 0x14 |
Linus Walleij | a613163 | 2012-06-11 17:33:12 +0200 | [diff] [blame] | 18 | |
Rob Herring | a54c959 | 2014-03-01 22:05:44 -0600 | [diff] [blame] | 19 | #define VERSATILE_SYS_OSCCLCD_OFFSET 0x1c |
| 20 | #define VERSATILE_SYS_LOCK_OFFSET 0x20 |
| 21 | |
Linus Walleij | 09c978b | 2014-01-10 15:57:27 +0100 | [diff] [blame] | 22 | /* Base offset for the core module */ |
| 23 | static void __iomem *cm_base; |
| 24 | |
| 25 | static const struct icst_params cp_auxosc_params = { |
Linus Walleij | a613163 | 2012-06-11 17:33:12 +0200 | [diff] [blame] | 26 | .vco_max = ICST525_VCO_MAX_5V, |
| 27 | .vco_min = ICST525_VCO_MIN, |
| 28 | .vd_min = 8, |
| 29 | .vd_max = 263, |
| 30 | .rd_min = 3, |
| 31 | .rd_max = 65, |
| 32 | .s2div = icst525_s2div, |
| 33 | .idx2s = icst525_idx2s, |
| 34 | }; |
| 35 | |
Nicolas Pitre | e3ee276 | 2015-07-28 19:43:20 -0400 | [diff] [blame] | 36 | static const struct clk_icst_desc cm_auxosc_desc __initconst = { |
Linus Walleij | 09c978b | 2014-01-10 15:57:27 +0100 | [diff] [blame] | 37 | .params = &cp_auxosc_params, |
Linus Walleij | 7a9ad67 | 2012-11-20 23:01:04 +0100 | [diff] [blame] | 38 | .vco_offset = 0x1c, |
| 39 | .lock_offset = INTEGRATOR_HDR_LOCK_OFFSET, |
Linus Walleij | a613163 | 2012-06-11 17:33:12 +0200 | [diff] [blame] | 40 | }; |
| 41 | |
Rob Herring | a54c959 | 2014-03-01 22:05:44 -0600 | [diff] [blame] | 42 | static const struct icst_params versatile_auxosc_params = { |
| 43 | .vco_max = ICST307_VCO_MAX, |
| 44 | .vco_min = ICST307_VCO_MIN, |
| 45 | .vd_min = 4 + 8, |
| 46 | .vd_max = 511 + 8, |
| 47 | .rd_min = 1 + 2, |
| 48 | .rd_max = 127 + 2, |
| 49 | .s2div = icst307_s2div, |
| 50 | .idx2s = icst307_idx2s, |
| 51 | }; |
| 52 | |
| 53 | static const struct clk_icst_desc versatile_auxosc_desc __initconst = { |
| 54 | .params = &versatile_auxosc_params, |
| 55 | .vco_offset = VERSATILE_SYS_OSCCLCD_OFFSET, |
| 56 | .lock_offset = VERSATILE_SYS_LOCK_OFFSET, |
| 57 | }; |
| 58 | static void __init cm_osc_setup(struct device_node *np, |
| 59 | const struct clk_icst_desc *desc) |
Linus Walleij | a613163 | 2012-06-11 17:33:12 +0200 | [diff] [blame] | 60 | { |
Linus Walleij | 09c978b | 2014-01-10 15:57:27 +0100 | [diff] [blame] | 61 | struct clk *clk = ERR_PTR(-EINVAL); |
| 62 | const char *clk_name = np->name; |
Linus Walleij | bf6edb4 | 2014-01-20 21:31:41 +0100 | [diff] [blame] | 63 | const char *parent_name; |
Linus Walleij | a613163 | 2012-06-11 17:33:12 +0200 | [diff] [blame] | 64 | |
Linus Walleij | 09c978b | 2014-01-10 15:57:27 +0100 | [diff] [blame] | 65 | if (!cm_base) { |
| 66 | /* Remap the core module base if not done yet */ |
| 67 | struct device_node *parent; |
Linus Walleij | a613163 | 2012-06-11 17:33:12 +0200 | [diff] [blame] | 68 | |
Linus Walleij | 09c978b | 2014-01-10 15:57:27 +0100 | [diff] [blame] | 69 | parent = of_get_parent(np); |
Julia Lawall | e52786a | 2015-04-04 16:59:29 +0200 | [diff] [blame] | 70 | if (!parent) { |
Linus Walleij | 09c978b | 2014-01-10 15:57:27 +0100 | [diff] [blame] | 71 | pr_err("no parent on core module clock\n"); |
| 72 | return; |
| 73 | } |
| 74 | cm_base = of_iomap(parent, 0); |
| 75 | if (!cm_base) { |
| 76 | pr_err("could not remap core module base\n"); |
| 77 | return; |
| 78 | } |
| 79 | } |
Linus Walleij | a613163 | 2012-06-11 17:33:12 +0200 | [diff] [blame] | 80 | |
Linus Walleij | bf6edb4 | 2014-01-20 21:31:41 +0100 | [diff] [blame] | 81 | parent_name = of_clk_get_parent_name(np, 0); |
| 82 | clk = icst_clk_register(NULL, desc, clk_name, parent_name, cm_base); |
Linus Walleij | 09c978b | 2014-01-10 15:57:27 +0100 | [diff] [blame] | 83 | if (!IS_ERR(clk)) |
| 84 | of_clk_add_provider(np, of_clk_src_simple_get, clk); |
Linus Walleij | a613163 | 2012-06-11 17:33:12 +0200 | [diff] [blame] | 85 | } |
Rob Herring | a54c959 | 2014-03-01 22:05:44 -0600 | [diff] [blame] | 86 | |
| 87 | static void __init of_integrator_cm_osc_setup(struct device_node *np) |
| 88 | { |
| 89 | cm_osc_setup(np, &cm_auxosc_desc); |
| 90 | } |
Linus Walleij | 09c978b | 2014-01-10 15:57:27 +0100 | [diff] [blame] | 91 | CLK_OF_DECLARE(integrator_cm_auxosc_clk, |
| 92 | "arm,integrator-cm-auxosc", of_integrator_cm_osc_setup); |
Rob Herring | a54c959 | 2014-03-01 22:05:44 -0600 | [diff] [blame] | 93 | |
| 94 | static void __init of_versatile_cm_osc_setup(struct device_node *np) |
| 95 | { |
| 96 | cm_osc_setup(np, &versatile_auxosc_desc); |
| 97 | } |
| 98 | CLK_OF_DECLARE(versatile_cm_auxosc_clk, |
| 99 | "arm,versatile-cm-auxosc", of_versatile_cm_osc_setup); |