fsl_tcon.c 2.3 KB

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