Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Copyright (C) 2016 Free Electrons
0004  *
0005  * Maxime Ripard <maxime.ripard@free-electrons.com>
0006  */
0007 
0008 #include <linux/clk.h>
0009 #include <linux/component.h>
0010 #include <linux/module.h>
0011 #include <linux/mod_devicetable.h>
0012 #include <linux/platform_device.h>
0013 #include <linux/regmap.h>
0014 #include <linux/reset.h>
0015 
0016 struct sun6i_drc {
0017     struct clk      *bus_clk;
0018     struct clk      *mod_clk;
0019     struct reset_control    *reset;
0020 };
0021 
0022 static int sun6i_drc_bind(struct device *dev, struct device *master,
0023              void *data)
0024 {
0025     struct sun6i_drc *drc;
0026     int ret;
0027 
0028     drc = devm_kzalloc(dev, sizeof(*drc), GFP_KERNEL);
0029     if (!drc)
0030         return -ENOMEM;
0031     dev_set_drvdata(dev, drc);
0032 
0033     drc->reset = devm_reset_control_get(dev, NULL);
0034     if (IS_ERR(drc->reset)) {
0035         dev_err(dev, "Couldn't get our reset line\n");
0036         return PTR_ERR(drc->reset);
0037     }
0038 
0039     ret = reset_control_deassert(drc->reset);
0040     if (ret) {
0041         dev_err(dev, "Couldn't deassert our reset line\n");
0042         return ret;
0043     }
0044 
0045     drc->bus_clk = devm_clk_get(dev, "ahb");
0046     if (IS_ERR(drc->bus_clk)) {
0047         dev_err(dev, "Couldn't get our bus clock\n");
0048         ret = PTR_ERR(drc->bus_clk);
0049         goto err_assert_reset;
0050     }
0051     clk_prepare_enable(drc->bus_clk);
0052 
0053     drc->mod_clk = devm_clk_get(dev, "mod");
0054     if (IS_ERR(drc->mod_clk)) {
0055         dev_err(dev, "Couldn't get our mod clock\n");
0056         ret = PTR_ERR(drc->mod_clk);
0057         goto err_disable_bus_clk;
0058     }
0059 
0060     ret = clk_set_rate_exclusive(drc->mod_clk, 300000000);
0061     if (ret) {
0062         dev_err(dev, "Couldn't set the module clock frequency\n");
0063         goto err_disable_bus_clk;
0064     }
0065 
0066     clk_prepare_enable(drc->mod_clk);
0067 
0068     return 0;
0069 
0070 err_disable_bus_clk:
0071     clk_disable_unprepare(drc->bus_clk);
0072 err_assert_reset:
0073     reset_control_assert(drc->reset);
0074     return ret;
0075 }
0076 
0077 static void sun6i_drc_unbind(struct device *dev, struct device *master,
0078                 void *data)
0079 {
0080     struct sun6i_drc *drc = dev_get_drvdata(dev);
0081 
0082     clk_rate_exclusive_put(drc->mod_clk);
0083     clk_disable_unprepare(drc->mod_clk);
0084     clk_disable_unprepare(drc->bus_clk);
0085     reset_control_assert(drc->reset);
0086 }
0087 
0088 static const struct component_ops sun6i_drc_ops = {
0089     .bind   = sun6i_drc_bind,
0090     .unbind = sun6i_drc_unbind,
0091 };
0092 
0093 static int sun6i_drc_probe(struct platform_device *pdev)
0094 {
0095     return component_add(&pdev->dev, &sun6i_drc_ops);
0096 }
0097 
0098 static int sun6i_drc_remove(struct platform_device *pdev)
0099 {
0100     component_del(&pdev->dev, &sun6i_drc_ops);
0101 
0102     return 0;
0103 }
0104 
0105 static const struct of_device_id sun6i_drc_of_table[] = {
0106     { .compatible = "allwinner,sun6i-a31-drc" },
0107     { .compatible = "allwinner,sun6i-a31s-drc" },
0108     { .compatible = "allwinner,sun8i-a23-drc" },
0109     { .compatible = "allwinner,sun8i-a33-drc" },
0110     { .compatible = "allwinner,sun9i-a80-drc" },
0111     { }
0112 };
0113 MODULE_DEVICE_TABLE(of, sun6i_drc_of_table);
0114 
0115 static struct platform_driver sun6i_drc_platform_driver = {
0116     .probe      = sun6i_drc_probe,
0117     .remove     = sun6i_drc_remove,
0118     .driver     = {
0119         .name       = "sun6i-drc",
0120         .of_match_table = sun6i_drc_of_table,
0121     },
0122 };
0123 module_platform_driver(sun6i_drc_platform_driver);
0124 
0125 MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
0126 MODULE_DESCRIPTION("Allwinner A31 Dynamic Range Control (DRC) Driver");
0127 MODULE_LICENSE("GPL");