vexpress-sysreg.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. *
  4. * Copyright (C) 2012 ARM Limited
  5. */
  6. #include <linux/gpio/driver.h>
  7. #include <linux/err.h>
  8. #include <linux/io.h>
  9. #include <linux/mfd/core.h>
  10. #include <linux/module.h>
  11. #include <linux/of_platform.h>
  12. #include <linux/platform_data/syscon.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/slab.h>
  15. #include <linux/stat.h>
  16. #define SYS_ID 0x000
  17. #define SYS_SW 0x004
  18. #define SYS_LED 0x008
  19. #define SYS_100HZ 0x024
  20. #define SYS_FLAGSSET 0x030
  21. #define SYS_FLAGSCLR 0x034
  22. #define SYS_NVFLAGS 0x038
  23. #define SYS_NVFLAGSSET 0x038
  24. #define SYS_NVFLAGSCLR 0x03c
  25. #define SYS_MCI 0x048
  26. #define SYS_FLASH 0x04c
  27. #define SYS_CFGSW 0x058
  28. #define SYS_24MHZ 0x05c
  29. #define SYS_MISC 0x060
  30. #define SYS_DMA 0x064
  31. #define SYS_PROCID0 0x084
  32. #define SYS_PROCID1 0x088
  33. #define SYS_CFGDATA 0x0a0
  34. #define SYS_CFGCTRL 0x0a4
  35. #define SYS_CFGSTAT 0x0a8
  36. /* The sysreg block is just a random collection of various functions... */
  37. static struct bgpio_pdata vexpress_sysreg_sys_led_pdata = {
  38. .label = "sys_led",
  39. .base = -1,
  40. .ngpio = 8,
  41. };
  42. static struct bgpio_pdata vexpress_sysreg_sys_mci_pdata = {
  43. .label = "sys_mci",
  44. .base = -1,
  45. .ngpio = 2,
  46. };
  47. static struct bgpio_pdata vexpress_sysreg_sys_flash_pdata = {
  48. .label = "sys_flash",
  49. .base = -1,
  50. .ngpio = 1,
  51. };
  52. static struct mfd_cell vexpress_sysreg_cells[] = {
  53. {
  54. .name = "basic-mmio-gpio",
  55. .of_compatible = "arm,vexpress-sysreg,sys_led",
  56. .num_resources = 1,
  57. .resources = (struct resource []) {
  58. DEFINE_RES_MEM_NAMED(SYS_LED, 0x4, "dat"),
  59. },
  60. .platform_data = &vexpress_sysreg_sys_led_pdata,
  61. .pdata_size = sizeof(vexpress_sysreg_sys_led_pdata),
  62. }, {
  63. .name = "basic-mmio-gpio",
  64. .of_compatible = "arm,vexpress-sysreg,sys_mci",
  65. .num_resources = 1,
  66. .resources = (struct resource []) {
  67. DEFINE_RES_MEM_NAMED(SYS_MCI, 0x4, "dat"),
  68. },
  69. .platform_data = &vexpress_sysreg_sys_mci_pdata,
  70. .pdata_size = sizeof(vexpress_sysreg_sys_mci_pdata),
  71. }, {
  72. .name = "basic-mmio-gpio",
  73. .of_compatible = "arm,vexpress-sysreg,sys_flash",
  74. .num_resources = 1,
  75. .resources = (struct resource []) {
  76. DEFINE_RES_MEM_NAMED(SYS_FLASH, 0x4, "dat"),
  77. },
  78. .platform_data = &vexpress_sysreg_sys_flash_pdata,
  79. .pdata_size = sizeof(vexpress_sysreg_sys_flash_pdata),
  80. }, {
  81. .name = "vexpress-syscfg",
  82. .num_resources = 1,
  83. .resources = (struct resource []) {
  84. DEFINE_RES_MEM(SYS_MISC, 0x4c),
  85. },
  86. }
  87. };
  88. static int vexpress_sysreg_probe(struct platform_device *pdev)
  89. {
  90. struct resource *mem;
  91. void __iomem *base;
  92. struct gpio_chip *mmc_gpio_chip;
  93. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  94. if (!mem)
  95. return -EINVAL;
  96. base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
  97. if (!base)
  98. return -ENOMEM;
  99. /*
  100. * Duplicated SYS_MCI pseudo-GPIO controller for compatibility with
  101. * older trees using sysreg node for MMC control lines.
  102. */
  103. mmc_gpio_chip = devm_kzalloc(&pdev->dev, sizeof(*mmc_gpio_chip),
  104. GFP_KERNEL);
  105. if (!mmc_gpio_chip)
  106. return -ENOMEM;
  107. bgpio_init(mmc_gpio_chip, &pdev->dev, 0x4, base + SYS_MCI,
  108. NULL, NULL, NULL, NULL, 0);
  109. mmc_gpio_chip->ngpio = 2;
  110. devm_gpiochip_add_data(&pdev->dev, mmc_gpio_chip, NULL);
  111. return devm_mfd_add_devices(&pdev->dev, PLATFORM_DEVID_AUTO,
  112. vexpress_sysreg_cells,
  113. ARRAY_SIZE(vexpress_sysreg_cells), mem, 0, NULL);
  114. }
  115. static const struct of_device_id vexpress_sysreg_match[] = {
  116. { .compatible = "arm,vexpress-sysreg", },
  117. {},
  118. };
  119. MODULE_DEVICE_TABLE(of, vexpress_sysreg_match);
  120. static struct platform_driver vexpress_sysreg_driver = {
  121. .driver = {
  122. .name = "vexpress-sysreg",
  123. .of_match_table = vexpress_sysreg_match,
  124. },
  125. .probe = vexpress_sysreg_probe,
  126. };
  127. module_platform_driver(vexpress_sysreg_driver);
  128. MODULE_LICENSE("GPL v2");