fsl_tcon.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright 2015 Toradex AG
  4. *
  5. * Stefan Agner <[email protected]>
  6. *
  7. * Freescale TCON device driver
  8. */
  9. #include <linux/clk.h>
  10. #include <linux/io.h>
  11. #include <linux/mm.h>
  12. #include <linux/of_address.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/regmap.h>
  15. #include "fsl_tcon.h"
  16. void fsl_tcon_bypass_disable(struct fsl_tcon *tcon)
  17. {
  18. regmap_update_bits(tcon->regs, FSL_TCON_CTRL1,
  19. FSL_TCON_CTRL1_TCON_BYPASS, 0);
  20. }
  21. void fsl_tcon_bypass_enable(struct fsl_tcon *tcon)
  22. {
  23. regmap_update_bits(tcon->regs, FSL_TCON_CTRL1,
  24. FSL_TCON_CTRL1_TCON_BYPASS,
  25. FSL_TCON_CTRL1_TCON_BYPASS);
  26. }
  27. static struct regmap_config fsl_tcon_regmap_config = {
  28. .reg_bits = 32,
  29. .reg_stride = 4,
  30. .val_bits = 32,
  31. .name = "tcon",
  32. };
  33. static int fsl_tcon_init_regmap(struct device *dev,
  34. struct fsl_tcon *tcon,
  35. struct device_node *np)
  36. {
  37. struct resource res;
  38. void __iomem *regs;
  39. if (of_address_to_resource(np, 0, &res))
  40. return -EINVAL;
  41. regs = devm_ioremap_resource(dev, &res);
  42. if (IS_ERR(regs))
  43. return PTR_ERR(regs);
  44. tcon->regs = devm_regmap_init_mmio(dev, regs,
  45. &fsl_tcon_regmap_config);
  46. return PTR_ERR_OR_ZERO(tcon->regs);
  47. }
  48. struct fsl_tcon *fsl_tcon_init(struct device *dev)
  49. {
  50. struct fsl_tcon *tcon;
  51. struct device_node *np;
  52. int ret;
  53. /* TCON node is not mandatory, some devices do not provide TCON */
  54. np = of_parse_phandle(dev->of_node, "fsl,tcon", 0);
  55. if (!np)
  56. return NULL;
  57. tcon = devm_kzalloc(dev, sizeof(*tcon), GFP_KERNEL);
  58. if (!tcon)
  59. goto err_node_put;
  60. ret = fsl_tcon_init_regmap(dev, tcon, np);
  61. if (ret) {
  62. dev_err(dev, "Couldn't create the TCON regmap\n");
  63. goto err_node_put;
  64. }
  65. tcon->ipg_clk = of_clk_get_by_name(np, "ipg");
  66. if (IS_ERR(tcon->ipg_clk)) {
  67. dev_err(dev, "Couldn't get the TCON bus clock\n");
  68. goto err_node_put;
  69. }
  70. ret = clk_prepare_enable(tcon->ipg_clk);
  71. if (ret) {
  72. dev_err(dev, "Couldn't enable the TCON clock\n");
  73. goto err_node_put;
  74. }
  75. of_node_put(np);
  76. dev_info(dev, "Using TCON in bypass mode\n");
  77. return tcon;
  78. err_node_put:
  79. of_node_put(np);
  80. return NULL;
  81. }
  82. void fsl_tcon_free(struct fsl_tcon *tcon)
  83. {
  84. clk_disable_unprepare(tcon->ipg_clk);
  85. clk_put(tcon->ipg_clk);
  86. }