clk-mt6797-img.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Copyright (c) 2017 MediaTek Inc.
  2. * Author: Kevin Chen <kevin-cw.chen@mediatek.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/clk-provider.h>
  14. #include <linux/platform_device.h>
  15. #include <dt-bindings/clock/mt6797-clk.h>
  16. #include "clk-mtk.h"
  17. #include "clk-gate.h"
  18. static const struct mtk_gate_regs img_cg_regs = {
  19. .set_ofs = 0x0004,
  20. .clr_ofs = 0x0008,
  21. .sta_ofs = 0x0000,
  22. };
  23. #define GATE_IMG(_id, _name, _parent, _shift) { \
  24. .id = _id, \
  25. .name = _name, \
  26. .parent_name = _parent, \
  27. .regs = &img_cg_regs, \
  28. .shift = _shift, \
  29. .ops = &mtk_clk_gate_ops_setclr, \
  30. }
  31. static const struct mtk_gate img_clks[] = {
  32. GATE_IMG(CLK_IMG_FDVT, "img_fdvt", "mm_sel", 11),
  33. GATE_IMG(CLK_IMG_DPE, "img_dpe", "mm_sel", 10),
  34. GATE_IMG(CLK_IMG_DIP, "img_dip", "mm_sel", 6),
  35. GATE_IMG(CLK_IMG_LARB6, "img_larb6", "mm_sel", 0),
  36. };
  37. static const struct of_device_id of_match_clk_mt6797_img[] = {
  38. { .compatible = "mediatek,mt6797-imgsys", },
  39. {}
  40. };
  41. static int clk_mt6797_img_probe(struct platform_device *pdev)
  42. {
  43. struct clk_onecell_data *clk_data;
  44. int r;
  45. struct device_node *node = pdev->dev.of_node;
  46. clk_data = mtk_alloc_clk_data(CLK_IMG_NR);
  47. mtk_clk_register_gates(node, img_clks, ARRAY_SIZE(img_clks),
  48. clk_data);
  49. r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
  50. if (r)
  51. dev_err(&pdev->dev,
  52. "could not register clock provider: %s: %d\n",
  53. pdev->name, r);
  54. return r;
  55. }
  56. static struct platform_driver clk_mt6797_img_drv = {
  57. .probe = clk_mt6797_img_probe,
  58. .driver = {
  59. .name = "clk-mt6797-img",
  60. .of_match_table = of_match_clk_mt6797_img,
  61. },
  62. };
  63. builtin_platform_driver(clk_mt6797_img_drv);