cs5535-mfd.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * cs5535-mfd.c - core MFD driver for CS5535/CS5536 southbridges
  4. *
  5. * The CS5535 and CS5536 has an ISA bridge on the PCI bus that is
  6. * used for accessing GPIOs, MFGPTs, ACPI, etc. Each subdevice has
  7. * an IO range that's specified in a single BAR. The BAR order is
  8. * hardcoded in the CS553x specifications.
  9. *
  10. * Copyright (c) 2010 Andres Salomon <dilinger@queued.net>
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/mfd/core.h>
  14. #include <linux/module.h>
  15. #include <linux/pci.h>
  16. #include <asm/olpc.h>
  17. #define DRV_NAME "cs5535-mfd"
  18. enum cs5535_mfd_bars {
  19. SMB_BAR = 0,
  20. GPIO_BAR = 1,
  21. MFGPT_BAR = 2,
  22. PMS_BAR = 4,
  23. ACPI_BAR = 5,
  24. NR_BARS,
  25. };
  26. static struct resource cs5535_mfd_resources[NR_BARS];
  27. static struct mfd_cell cs5535_mfd_cells[] = {
  28. {
  29. .name = "cs5535-smb",
  30. .num_resources = 1,
  31. .resources = &cs5535_mfd_resources[SMB_BAR],
  32. },
  33. {
  34. .name = "cs5535-gpio",
  35. .num_resources = 1,
  36. .resources = &cs5535_mfd_resources[GPIO_BAR],
  37. },
  38. {
  39. .name = "cs5535-mfgpt",
  40. .num_resources = 1,
  41. .resources = &cs5535_mfd_resources[MFGPT_BAR],
  42. },
  43. {
  44. .name = "cs5535-pms",
  45. .num_resources = 1,
  46. .resources = &cs5535_mfd_resources[PMS_BAR],
  47. },
  48. };
  49. static struct mfd_cell cs5535_olpc_mfd_cells[] = {
  50. {
  51. .name = "olpc-xo1-pm-acpi",
  52. .num_resources = 1,
  53. .resources = &cs5535_mfd_resources[ACPI_BAR],
  54. },
  55. {
  56. .name = "olpc-xo1-sci-acpi",
  57. .num_resources = 1,
  58. .resources = &cs5535_mfd_resources[ACPI_BAR],
  59. },
  60. };
  61. static int cs5535_mfd_probe(struct pci_dev *pdev,
  62. const struct pci_device_id *id)
  63. {
  64. int err, bar;
  65. err = pci_enable_device(pdev);
  66. if (err)
  67. return err;
  68. for (bar = 0; bar < NR_BARS; bar++) {
  69. struct resource *r = &cs5535_mfd_resources[bar];
  70. r->flags = IORESOURCE_IO;
  71. r->start = pci_resource_start(pdev, bar);
  72. r->end = pci_resource_end(pdev, bar);
  73. }
  74. err = pci_request_region(pdev, PMS_BAR, DRV_NAME);
  75. if (err) {
  76. dev_err(&pdev->dev, "Failed to request PMS_BAR's IO region\n");
  77. goto err_disable;
  78. }
  79. err = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, cs5535_mfd_cells,
  80. ARRAY_SIZE(cs5535_mfd_cells), NULL, 0, NULL);
  81. if (err) {
  82. dev_err(&pdev->dev,
  83. "Failed to add CS5535 sub-devices: %d\n", err);
  84. goto err_release_pms;
  85. }
  86. if (machine_is_olpc()) {
  87. err = pci_request_region(pdev, ACPI_BAR, DRV_NAME);
  88. if (err) {
  89. dev_err(&pdev->dev,
  90. "Failed to request ACPI_BAR's IO region\n");
  91. goto err_remove_devices;
  92. }
  93. err = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE,
  94. cs5535_olpc_mfd_cells,
  95. ARRAY_SIZE(cs5535_olpc_mfd_cells),
  96. NULL, 0, NULL);
  97. if (err) {
  98. dev_err(&pdev->dev,
  99. "Failed to add CS5535 OLPC sub-devices: %d\n",
  100. err);
  101. goto err_release_acpi;
  102. }
  103. }
  104. dev_info(&pdev->dev, "%zu devices registered.\n",
  105. ARRAY_SIZE(cs5535_mfd_cells));
  106. return 0;
  107. err_release_acpi:
  108. pci_release_region(pdev, ACPI_BAR);
  109. err_remove_devices:
  110. mfd_remove_devices(&pdev->dev);
  111. err_release_pms:
  112. pci_release_region(pdev, PMS_BAR);
  113. err_disable:
  114. pci_disable_device(pdev);
  115. return err;
  116. }
  117. static void cs5535_mfd_remove(struct pci_dev *pdev)
  118. {
  119. mfd_remove_devices(&pdev->dev);
  120. if (machine_is_olpc())
  121. pci_release_region(pdev, ACPI_BAR);
  122. pci_release_region(pdev, PMS_BAR);
  123. pci_disable_device(pdev);
  124. }
  125. static const struct pci_device_id cs5535_mfd_pci_tbl[] = {
  126. { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
  127. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
  128. { 0, }
  129. };
  130. MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl);
  131. static struct pci_driver cs5535_mfd_driver = {
  132. .name = DRV_NAME,
  133. .id_table = cs5535_mfd_pci_tbl,
  134. .probe = cs5535_mfd_probe,
  135. .remove = cs5535_mfd_remove,
  136. };
  137. module_pci_driver(cs5535_mfd_driver);
  138. MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>");
  139. MODULE_DESCRIPTION("MFD driver for CS5535/CS5536 southbridge's ISA PCI device");
  140. MODULE_LICENSE("GPL");