1 /* 2 * Copyright (C) 2016 Free Electrons 3 * 4 * Maxime Ripard <maxime.ripard@free-electrons.com> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 */ 11 12 #include <linux/clk.h> 13 #include <linux/component.h> 14 #include <linux/module.h> 15 #include <linux/platform_device.h> 16 #include <linux/regmap.h> 17 #include <linux/reset.h> 18 19 struct sun6i_drc { 20 struct clk *bus_clk; 21 struct clk *mod_clk; 22 struct reset_control *reset; 23 }; 24 25 static int sun6i_drc_bind(struct device *dev, struct device *master, 26 void *data) 27 { 28 struct sun6i_drc *drc; 29 int ret; 30 31 drc = devm_kzalloc(dev, sizeof(*drc), GFP_KERNEL); 32 if (!drc) 33 return -ENOMEM; 34 dev_set_drvdata(dev, drc); 35 36 drc->reset = devm_reset_control_get(dev, NULL); 37 if (IS_ERR(drc->reset)) { 38 dev_err(dev, "Couldn't get our reset line\n"); 39 return PTR_ERR(drc->reset); 40 } 41 42 ret = reset_control_deassert(drc->reset); 43 if (ret) { 44 dev_err(dev, "Couldn't deassert our reset line\n"); 45 return ret; 46 } 47 48 drc->bus_clk = devm_clk_get(dev, "ahb"); 49 if (IS_ERR(drc->bus_clk)) { 50 dev_err(dev, "Couldn't get our bus clock\n"); 51 ret = PTR_ERR(drc->bus_clk); 52 goto err_assert_reset; 53 } 54 clk_prepare_enable(drc->bus_clk); 55 56 drc->mod_clk = devm_clk_get(dev, "mod"); 57 if (IS_ERR(drc->mod_clk)) { 58 dev_err(dev, "Couldn't get our mod clock\n"); 59 ret = PTR_ERR(drc->mod_clk); 60 goto err_disable_bus_clk; 61 } 62 clk_prepare_enable(drc->mod_clk); 63 64 return 0; 65 66 err_disable_bus_clk: 67 clk_disable_unprepare(drc->bus_clk); 68 err_assert_reset: 69 reset_control_assert(drc->reset); 70 return ret; 71 } 72 73 static void sun6i_drc_unbind(struct device *dev, struct device *master, 74 void *data) 75 { 76 struct sun6i_drc *drc = dev_get_drvdata(dev); 77 78 clk_disable_unprepare(drc->mod_clk); 79 clk_disable_unprepare(drc->bus_clk); 80 reset_control_assert(drc->reset); 81 } 82 83 static const struct component_ops sun6i_drc_ops = { 84 .bind = sun6i_drc_bind, 85 .unbind = sun6i_drc_unbind, 86 }; 87 88 static int sun6i_drc_probe(struct platform_device *pdev) 89 { 90 return component_add(&pdev->dev, &sun6i_drc_ops); 91 } 92 93 static int sun6i_drc_remove(struct platform_device *pdev) 94 { 95 component_del(&pdev->dev, &sun6i_drc_ops); 96 97 return 0; 98 } 99 100 static const struct of_device_id sun6i_drc_of_table[] = { 101 { .compatible = "allwinner,sun8i-a33-drc" }, 102 { } 103 }; 104 MODULE_DEVICE_TABLE(of, sun6i_drc_of_table); 105 106 static struct platform_driver sun6i_drc_platform_driver = { 107 .probe = sun6i_drc_probe, 108 .remove = sun6i_drc_remove, 109 .driver = { 110 .name = "sun6i-drc", 111 .of_match_table = sun6i_drc_of_table, 112 }, 113 }; 114 module_platform_driver(sun6i_drc_platform_driver); 115 116 MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>"); 117 MODULE_DESCRIPTION("Allwinner A31 Dynamic Range Control (DRC) Driver"); 118 MODULE_LICENSE("GPL"); 119