Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Clock driver for the ARM Integrator/IM-PD1 board
0004  * Copyright (C) 2012-2013 Linus Walleij
0005  */
0006 #include <linux/clk-provider.h>
0007 #include <linux/clkdev.h>
0008 #include <linux/err.h>
0009 #include <linux/io.h>
0010 #include <linux/platform_device.h>
0011 #include <linux/module.h>
0012 #include <linux/mfd/syscon.h>
0013 #include <linux/regmap.h>
0014 
0015 #include "icst.h"
0016 #include "clk-icst.h"
0017 
0018 #define IMPD1_OSC1  0x00
0019 #define IMPD1_OSC2  0x04
0020 #define IMPD1_LOCK  0x08
0021 
0022 /*
0023  * There are two VCO's on the IM-PD1
0024  */
0025 
0026 static const struct icst_params impd1_vco1_params = {
0027     .ref        = 24000000, /* 24 MHz */
0028     .vco_max    = ICST525_VCO_MAX_3V,
0029     .vco_min    = ICST525_VCO_MIN,
0030     .vd_min     = 12,
0031     .vd_max     = 519,
0032     .rd_min     = 3,
0033     .rd_max     = 120,
0034     .s2div      = icst525_s2div,
0035     .idx2s      = icst525_idx2s,
0036 };
0037 
0038 static const struct clk_icst_desc impd1_icst1_desc = {
0039     .params = &impd1_vco1_params,
0040     .vco_offset = IMPD1_OSC1,
0041     .lock_offset = IMPD1_LOCK,
0042 };
0043 
0044 static const struct icst_params impd1_vco2_params = {
0045     .ref        = 24000000, /* 24 MHz */
0046     .vco_max    = ICST525_VCO_MAX_3V,
0047     .vco_min    = ICST525_VCO_MIN,
0048     .vd_min     = 12,
0049     .vd_max     = 519,
0050     .rd_min     = 3,
0051     .rd_max     = 120,
0052     .s2div      = icst525_s2div,
0053     .idx2s      = icst525_idx2s,
0054 };
0055 
0056 static const struct clk_icst_desc impd1_icst2_desc = {
0057     .params = &impd1_vco2_params,
0058     .vco_offset = IMPD1_OSC2,
0059     .lock_offset = IMPD1_LOCK,
0060 };
0061 
0062 static int integrator_impd1_clk_spawn(struct device *dev,
0063                       struct device_node *parent,
0064                       struct device_node *np)
0065 {
0066     struct regmap *map;
0067     struct clk *clk = ERR_PTR(-EINVAL);
0068     const char *name = np->name;
0069     const char *parent_name;
0070     const struct clk_icst_desc *desc;
0071     int ret;
0072 
0073     map = syscon_node_to_regmap(parent);
0074     if (IS_ERR(map)) {
0075         pr_err("no regmap for syscon IM-PD1 ICST clock parent\n");
0076         return PTR_ERR(map);
0077     }
0078 
0079     if (of_device_is_compatible(np, "arm,impd1-vco1")) {
0080         desc = &impd1_icst1_desc;
0081     } else if (of_device_is_compatible(np, "arm,impd1-vco2")) {
0082         desc = &impd1_icst2_desc;
0083     } else {
0084         dev_err(dev, "not a clock node %s\n", name);
0085         return -ENODEV;
0086     }
0087 
0088     of_property_read_string(np, "clock-output-names", &name);
0089     parent_name = of_clk_get_parent_name(np, 0);
0090     clk = icst_clk_setup(NULL, desc, name, parent_name, map,
0091                  ICST_INTEGRATOR_IM_PD1);
0092     if (!IS_ERR(clk)) {
0093         of_clk_add_provider(np, of_clk_src_simple_get, clk);
0094         ret = 0;
0095     } else {
0096         dev_err(dev, "error setting up IM-PD1 ICST clock\n");
0097         ret = PTR_ERR(clk);
0098     }
0099 
0100     return ret;
0101 }
0102 
0103 static int integrator_impd1_clk_probe(struct platform_device *pdev)
0104 {
0105     struct device *dev = &pdev->dev;
0106     struct device_node *np = dev->of_node;
0107     struct device_node *child;
0108     int ret = 0;
0109 
0110     for_each_available_child_of_node(np, child) {
0111         ret = integrator_impd1_clk_spawn(dev, np, child);
0112         if (ret) {
0113             of_node_put(child);
0114             break;
0115         }
0116     }
0117 
0118     return ret;
0119 }
0120 
0121 static const struct of_device_id impd1_syscon_match[] = {
0122     { .compatible = "arm,im-pd1-syscon", },
0123     {}
0124 };
0125 MODULE_DEVICE_TABLE(of, impd1_syscon_match);
0126 
0127 static struct platform_driver impd1_clk_driver = {
0128     .driver = {
0129         .name = "impd1-clk",
0130         .of_match_table = impd1_syscon_match,
0131     },
0132     .probe  = integrator_impd1_clk_probe,
0133 };
0134 builtin_platform_driver(impd1_clk_driver);
0135 
0136 MODULE_AUTHOR("Linus Walleij <linusw@kernel.org>");
0137 MODULE_DESCRIPTION("Arm IM-PD1 module clock driver");
0138 MODULE_LICENSE("GPL v2");