cs5535-mfd.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * cs5535-mfd.c - core MFD driver for CS5535/CS5536 southbridges
  3. *
  4. * The CS5535 and CS5536 has an ISA bridge on the PCI bus that is
  5. * used for accessing GPIOs, MFGPTs, ACPI, etc. Each subdevice has
  6. * an IO range that's specified in a single BAR. The BAR order is
  7. * hardcoded in the CS553x specifications.
  8. *
  9. * Copyright (c) 2010 Andres Salomon <dilinger@queued.net>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. */
  24. #include <linux/kernel.h>
  25. #include <linux/init.h>
  26. #include <linux/mfd/core.h>
  27. #include <linux/module.h>
  28. #include <linux/pci.h>
  29. #define DRV_NAME "cs5535-mfd"
  30. enum cs5535_mfd_bars {
  31. SMB_BAR = 0,
  32. GPIO_BAR = 1,
  33. MFGPT_BAR = 2,
  34. PMS_BAR = 4,
  35. ACPI_BAR = 5,
  36. NR_BARS,
  37. };
  38. static int cs5535_mfd_res_enable(struct platform_device *pdev)
  39. {
  40. struct resource *res;
  41. res = platform_get_resource(pdev, IORESOURCE_IO, 0);
  42. if (!res) {
  43. dev_err(&pdev->dev, "can't fetch device resource info\n");
  44. return -EIO;
  45. }
  46. if (!request_region(res->start, resource_size(res), DRV_NAME)) {
  47. dev_err(&pdev->dev, "can't request region\n");
  48. return -EIO;
  49. }
  50. return 0;
  51. }
  52. static int cs5535_mfd_res_disable(struct platform_device *pdev)
  53. {
  54. struct resource *res;
  55. res = platform_get_resource(pdev, IORESOURCE_IO, 0);
  56. if (!res) {
  57. dev_err(&pdev->dev, "can't fetch device resource info\n");
  58. return -EIO;
  59. }
  60. release_region(res->start, resource_size(res));
  61. return 0;
  62. }
  63. static __devinitdata struct resource cs5535_mfd_resources[NR_BARS];
  64. static __devinitdata struct mfd_cell cs5535_mfd_cells[] = {
  65. {
  66. .id = SMB_BAR,
  67. .name = "cs5535-smb",
  68. .num_resources = 1,
  69. .resources = &cs5535_mfd_resources[SMB_BAR],
  70. },
  71. {
  72. .id = GPIO_BAR,
  73. .name = "cs5535-gpio",
  74. .num_resources = 1,
  75. .resources = &cs5535_mfd_resources[GPIO_BAR],
  76. },
  77. {
  78. .id = MFGPT_BAR,
  79. .name = "cs5535-mfgpt",
  80. .num_resources = 1,
  81. .resources = &cs5535_mfd_resources[MFGPT_BAR],
  82. },
  83. {
  84. .id = PMS_BAR,
  85. .name = "cs5535-pms",
  86. .num_resources = 1,
  87. .resources = &cs5535_mfd_resources[PMS_BAR],
  88. .enable = cs5535_mfd_res_enable,
  89. .disable = cs5535_mfd_res_disable,
  90. },
  91. {
  92. .id = ACPI_BAR,
  93. .name = "cs5535-acpi",
  94. .num_resources = 1,
  95. .resources = &cs5535_mfd_resources[ACPI_BAR],
  96. .enable = cs5535_mfd_res_enable,
  97. .disable = cs5535_mfd_res_disable,
  98. },
  99. };
  100. static int __devinit cs5535_mfd_probe(struct pci_dev *pdev,
  101. const struct pci_device_id *id)
  102. {
  103. int err, i;
  104. err = pci_enable_device(pdev);
  105. if (err)
  106. return err;
  107. /* fill in IO range for each cell; subdrivers handle the region */
  108. for (i = 0; i < ARRAY_SIZE(cs5535_mfd_cells); i++) {
  109. int bar = cs5535_mfd_cells[i].id;
  110. struct resource *r = &cs5535_mfd_resources[bar];
  111. r->flags = IORESOURCE_IO;
  112. r->start = pci_resource_start(pdev, bar);
  113. r->end = pci_resource_end(pdev, bar);
  114. /* id is used for temporarily storing BAR; unset it now */
  115. cs5535_mfd_cells[i].id = 0;
  116. }
  117. err = mfd_add_devices(&pdev->dev, -1, cs5535_mfd_cells,
  118. ARRAY_SIZE(cs5535_mfd_cells), NULL, 0);
  119. if (err) {
  120. dev_err(&pdev->dev, "MFD add devices failed: %d\n", err);
  121. goto err_disable;
  122. }
  123. dev_info(&pdev->dev, "%zu devices registered.\n",
  124. ARRAY_SIZE(cs5535_mfd_cells));
  125. return 0;
  126. err_disable:
  127. pci_disable_device(pdev);
  128. return err;
  129. }
  130. static void __devexit cs5535_mfd_remove(struct pci_dev *pdev)
  131. {
  132. mfd_remove_devices(&pdev->dev);
  133. pci_disable_device(pdev);
  134. }
  135. static struct pci_device_id cs5535_mfd_pci_tbl[] = {
  136. { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
  137. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
  138. { 0, }
  139. };
  140. MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl);
  141. static struct pci_driver cs5535_mfd_drv = {
  142. .name = DRV_NAME,
  143. .id_table = cs5535_mfd_pci_tbl,
  144. .probe = cs5535_mfd_probe,
  145. .remove = __devexit_p(cs5535_mfd_remove),
  146. };
  147. static int __init cs5535_mfd_init(void)
  148. {
  149. return pci_register_driver(&cs5535_mfd_drv);
  150. }
  151. static void __exit cs5535_mfd_exit(void)
  152. {
  153. pci_unregister_driver(&cs5535_mfd_drv);
  154. }
  155. module_init(cs5535_mfd_init);
  156. module_exit(cs5535_mfd_exit);
  157. MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>");
  158. MODULE_DESCRIPTION("MFD driver for CS5535/CS5536 southbridge's ISA PCI device");
  159. MODULE_LICENSE("GPL");