| /* |
| * Copyright (c) 2015 MediaTek Inc. |
| * Author: James Liao <jamesjj.liao@mediatek.com> |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 2 as |
| * published by the Free Software Foundation. |
| * |
| * This program is distributed in the hope that it will be useful, |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| * GNU General Public License for more details. |
| */ |
| |
| #include <linux/clk.h> |
| #include <linux/clk-provider.h> |
| #include <linux/kernel.h> |
| #include <linux/module.h> |
| #include <linux/of.h> |
| #include <linux/of_platform.h> |
| |
| static const struct of_device_id bring_up_id_table[] = { |
| { .compatible = "mediatek,clk-bring-up", .data = (void *)300}, |
| { .compatible = "mediatek,mt2731-bring-up", .data = (void *)120}, |
| { .compatible = "mediatek,mt8163-bring-up", .data = (void *)300}, |
| { .compatible = "mediatek,mt8173-bring-up", .data = (void *)300}, |
| { }, |
| }; |
| MODULE_DEVICE_TABLE(of, bring_up_id_table); |
| |
| static int bring_up_probe(struct platform_device *pdev) |
| { |
| struct device *dev = &pdev->dev; |
| unsigned int nr_clks; |
| char clk_name_buf[10]; |
| struct clk *clk, *last_ok_clk = NULL; |
| int i, r = 0; |
| |
| nr_clks = (unsigned long)of_device_get_match_data(dev); /* clk nr */ |
| if (!nr_clks) |
| return -EINVAL; |
| |
| for (i = 0; i < nr_clks; i++) { |
| memset(clk_name_buf, 0, 10); |
| sprintf(clk_name_buf, "%d", i); |
| |
| clk = devm_clk_get(dev, clk_name_buf); |
| if (!IS_ERR(clk)) { |
| r = clk_prepare_enable(clk); |
| if (r) |
| dev_warn(dev, "clk_prepare_enable(%s): %d\n", |
| __clk_get_name(clk), r); |
| else |
| last_ok_clk = clk; |
| } |
| } |
| if (!r) |
| dev_info(dev, "clk enable(nr%d) suc. the end clk is: %s\n", |
| nr_clks, __clk_get_name(last_ok_clk)); |
| |
| return 0; |
| } |
| |
| static int bring_up_remove(struct platform_device *pdev) |
| { |
| return 0; |
| } |
| |
| static struct platform_driver bring_up = { |
| .probe = bring_up_probe, |
| .remove = bring_up_remove, |
| .driver = { |
| .name = "bring_up", |
| .owner = THIS_MODULE, |
| .of_match_table = bring_up_id_table, |
| }, |
| }; |
| |
| module_platform_driver(bring_up); |