loki-main.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Code for Fenrir's Loki.
  4. */
  5. #include <linux/delay.h>
  6. #include <linux/irq.h>
  7. #include <linux/bitops.h>
  8. #include <linux/module.h>
  9. #include <linux/moduleparam.h>
  10. #include <linux/of.h>
  11. #include <linux/of_address.h>
  12. #include <linux/of_irq.h>
  13. #include <linux/of_platform.h>
  14. #include "loki.h"
  15. static inline unsigned int loki_readreg32(struct loki_drvdata *pdata, unsigned long offset)
  16. {
  17. void __iomem *reg = (void __iomem *)pdata->regbase + offset;
  18. return ioread32(reg);
  19. }
  20. static inline void loki_writereg32(struct loki_drvdata *pdata, unsigned long offset, int val)
  21. {
  22. void __iomem *reg = (void __iomem *)pdata->regbase + offset;
  23. iowrite32(val, reg);
  24. }
  25. static int loki_probe(struct platform_device *pdev)
  26. {
  27. struct device *dev = &pdev->dev;
  28. struct device_node *of_node = pdev->dev.of_node;
  29. int ret = 0;
  30. struct loki_drvdata *priv_data;
  31. uint32_t memif_cache, memif_prot;
  32. dev_dbg(dev, "Probe...");
  33. priv_data = devm_kzalloc(dev, sizeof(struct loki_drvdata), GFP_KERNEL);
  34. if (!priv_data) {
  35. pr_err("Memory allocation error, aborting.\n");
  36. ret = -ENOMEM;
  37. goto exit;
  38. }
  39. priv_data->regbase = of_iomap(of_node, 0);
  40. if (!priv_data->regbase) {
  41. dev_err(dev, "Unable to map local interrupt registers\n");
  42. ret = -ENXIO;
  43. goto exit;
  44. }
  45. priv_data->writereg32 = loki_writereg32;
  46. priv_data->readreg32 = loki_readreg32;
  47. /* Reset the DUT */
  48. priv_data->writereg32(priv_data, REG_LOKI_EXTERNAL_RESET, 0);
  49. udelay(10);
  50. priv_data->writereg32(priv_data, REG_LOKI_EXTERNAL_RESET, 1);
  51. platform_set_drvdata(pdev, priv_data);
  52. /* Get optional data from the Device Tree */
  53. if (!of_property_read_u64(pdev->dev.of_node, "memif-cache",
  54. (uint64_t *)&memif_cache)) {
  55. dev_info(dev, "Setting memif_cache to %X from the DT\n", memif_cache);
  56. }
  57. priv_data->writereg32(priv_data, REG_LOKI_MEMIF_CACHE_SET, memif_cache);
  58. if (!of_property_read_u64(pdev->dev.of_node, "memif-prot",
  59. (uint64_t *)&memif_prot)) {
  60. dev_info(dev, "Setting memif_prot to %X from the DT\n", memif_prot);
  61. }
  62. priv_data->writereg32(priv_data, REG_LOKI_MEMIF_PROT_SET, memif_prot);
  63. loki_intc_probe(pdev);
  64. exit:
  65. return ret;
  66. }
  67. static int loki_remove(struct platform_device *pdev)
  68. {
  69. struct loki_drvdata *pdata = platform_get_drvdata(pdev);
  70. loki_intc_remove(pdev);
  71. return 0;
  72. }
  73. static const struct of_device_id loki_dt_ids[] = {
  74. { .compatible = "img,loki", },
  75. {},
  76. };
  77. MODULE_DEVICE_TABLE(of, loki_dt_ids);
  78. static struct platform_driver loki_device_driver = {
  79. .probe = loki_probe,
  80. .remove = loki_remove,
  81. .driver = {
  82. .name = DEVICE_NAME,
  83. .of_match_table = of_match_ptr(loki_dt_ids),
  84. }
  85. };
  86. module_platform_driver(loki_device_driver);
  87. MODULE_AUTHOR("Imagination Technologies");
  88. MODULE_DESCRIPTION("Fenrir Loki driver");
  89. MODULE_LICENSE("GPL v2");