cs5535-mfd.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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/mfd/core.h>
  26. #include <linux/module.h>
  27. #include <linux/pci.h>
  28. #include <asm/olpc.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 struct resource cs5535_mfd_resources[NR_BARS];
  64. static 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. #ifdef CONFIG_OLPC
  101. static void cs5535_clone_olpc_cells(void)
  102. {
  103. const char *acpi_clones[] = { "olpc-xo1-pm-acpi", "olpc-xo1-sci-acpi" };
  104. if (!machine_is_olpc())
  105. return;
  106. mfd_clone_cell("cs5535-acpi", acpi_clones, ARRAY_SIZE(acpi_clones));
  107. }
  108. #else
  109. static void cs5535_clone_olpc_cells(void) { }
  110. #endif
  111. static int cs5535_mfd_probe(struct pci_dev *pdev,
  112. const struct pci_device_id *id)
  113. {
  114. int err, i;
  115. err = pci_enable_device(pdev);
  116. if (err)
  117. return err;
  118. /* fill in IO range for each cell; subdrivers handle the region */
  119. for (i = 0; i < ARRAY_SIZE(cs5535_mfd_cells); i++) {
  120. int bar = cs5535_mfd_cells[i].id;
  121. struct resource *r = &cs5535_mfd_resources[bar];
  122. r->flags = IORESOURCE_IO;
  123. r->start = pci_resource_start(pdev, bar);
  124. r->end = pci_resource_end(pdev, bar);
  125. /* id is used for temporarily storing BAR; unset it now */
  126. cs5535_mfd_cells[i].id = 0;
  127. }
  128. err = mfd_add_devices(&pdev->dev, -1, cs5535_mfd_cells,
  129. ARRAY_SIZE(cs5535_mfd_cells), NULL, 0, NULL);
  130. if (err) {
  131. dev_err(&pdev->dev, "MFD add devices failed: %d\n", err);
  132. goto err_disable;
  133. }
  134. cs5535_clone_olpc_cells();
  135. dev_info(&pdev->dev, "%zu devices registered.\n",
  136. ARRAY_SIZE(cs5535_mfd_cells));
  137. return 0;
  138. err_disable:
  139. pci_disable_device(pdev);
  140. return err;
  141. }
  142. static void cs5535_mfd_remove(struct pci_dev *pdev)
  143. {
  144. mfd_remove_devices(&pdev->dev);
  145. pci_disable_device(pdev);
  146. }
  147. static const struct pci_device_id cs5535_mfd_pci_tbl[] = {
  148. { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
  149. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
  150. { 0, }
  151. };
  152. MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl);
  153. static struct pci_driver cs5535_mfd_driver = {
  154. .name = DRV_NAME,
  155. .id_table = cs5535_mfd_pci_tbl,
  156. .probe = cs5535_mfd_probe,
  157. .remove = cs5535_mfd_remove,
  158. };
  159. module_pci_driver(cs5535_mfd_driver);
  160. MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>");
  161. MODULE_DESCRIPTION("MFD driver for CS5535/CS5536 southbridge's ISA PCI device");
  162. MODULE_LICENSE("GPL");