cs5535-mfd.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. #include <asm/olpc.h>
  30. #define DRV_NAME "cs5535-mfd"
  31. enum cs5535_mfd_bars {
  32. SMB_BAR = 0,
  33. GPIO_BAR = 1,
  34. MFGPT_BAR = 2,
  35. PMS_BAR = 4,
  36. ACPI_BAR = 5,
  37. NR_BARS,
  38. };
  39. static int cs5535_mfd_res_enable(struct platform_device *pdev)
  40. {
  41. struct resource *res;
  42. res = platform_get_resource(pdev, IORESOURCE_IO, 0);
  43. if (!res) {
  44. dev_err(&pdev->dev, "can't fetch device resource info\n");
  45. return -EIO;
  46. }
  47. if (!request_region(res->start, resource_size(res), DRV_NAME)) {
  48. dev_err(&pdev->dev, "can't request region\n");
  49. return -EIO;
  50. }
  51. return 0;
  52. }
  53. static int cs5535_mfd_res_disable(struct platform_device *pdev)
  54. {
  55. struct resource *res;
  56. res = platform_get_resource(pdev, IORESOURCE_IO, 0);
  57. if (!res) {
  58. dev_err(&pdev->dev, "can't fetch device resource info\n");
  59. return -EIO;
  60. }
  61. release_region(res->start, resource_size(res));
  62. return 0;
  63. }
  64. static __devinitdata struct resource cs5535_mfd_resources[NR_BARS];
  65. static __devinitdata struct mfd_cell cs5535_mfd_cells[] = {
  66. {
  67. .id = SMB_BAR,
  68. .name = "cs5535-smb",
  69. .num_resources = 1,
  70. .resources = &cs5535_mfd_resources[SMB_BAR],
  71. },
  72. {
  73. .id = GPIO_BAR,
  74. .name = "cs5535-gpio",
  75. .num_resources = 1,
  76. .resources = &cs5535_mfd_resources[GPIO_BAR],
  77. },
  78. {
  79. .id = MFGPT_BAR,
  80. .name = "cs5535-mfgpt",
  81. .num_resources = 1,
  82. .resources = &cs5535_mfd_resources[MFGPT_BAR],
  83. },
  84. {
  85. .id = PMS_BAR,
  86. .name = "cs5535-pms",
  87. .num_resources = 1,
  88. .resources = &cs5535_mfd_resources[PMS_BAR],
  89. .enable = cs5535_mfd_res_enable,
  90. .disable = cs5535_mfd_res_disable,
  91. },
  92. {
  93. .id = ACPI_BAR,
  94. .name = "cs5535-acpi",
  95. .num_resources = 1,
  96. .resources = &cs5535_mfd_resources[ACPI_BAR],
  97. .enable = cs5535_mfd_res_enable,
  98. .disable = cs5535_mfd_res_disable,
  99. },
  100. };
  101. #ifdef CONFIG_OLPC
  102. static void __devinit cs5535_clone_olpc_cells(void)
  103. {
  104. const char *acpi_clones[] = { "olpc-xo1-pm-acpi", "olpc-xo1-sci-acpi" };
  105. if (!machine_is_olpc())
  106. return;
  107. mfd_clone_cell("cs5535-acpi", acpi_clones, ARRAY_SIZE(acpi_clones));
  108. }
  109. #else
  110. static void cs5535_clone_olpc_cells(void) { }
  111. #endif
  112. static int __devinit cs5535_mfd_probe(struct pci_dev *pdev,
  113. const struct pci_device_id *id)
  114. {
  115. int err, i;
  116. err = pci_enable_device(pdev);
  117. if (err)
  118. return err;
  119. /* fill in IO range for each cell; subdrivers handle the region */
  120. for (i = 0; i < ARRAY_SIZE(cs5535_mfd_cells); i++) {
  121. int bar = cs5535_mfd_cells[i].id;
  122. struct resource *r = &cs5535_mfd_resources[bar];
  123. r->flags = IORESOURCE_IO;
  124. r->start = pci_resource_start(pdev, bar);
  125. r->end = pci_resource_end(pdev, bar);
  126. /* id is used for temporarily storing BAR; unset it now */
  127. cs5535_mfd_cells[i].id = 0;
  128. }
  129. err = mfd_add_devices(&pdev->dev, -1, cs5535_mfd_cells,
  130. ARRAY_SIZE(cs5535_mfd_cells), NULL, 0);
  131. if (err) {
  132. dev_err(&pdev->dev, "MFD add devices failed: %d\n", err);
  133. goto err_disable;
  134. }
  135. cs5535_clone_olpc_cells();
  136. dev_info(&pdev->dev, "%zu devices registered.\n",
  137. ARRAY_SIZE(cs5535_mfd_cells));
  138. return 0;
  139. err_disable:
  140. pci_disable_device(pdev);
  141. return err;
  142. }
  143. static void __devexit cs5535_mfd_remove(struct pci_dev *pdev)
  144. {
  145. mfd_remove_devices(&pdev->dev);
  146. pci_disable_device(pdev);
  147. }
  148. static struct pci_device_id cs5535_mfd_pci_tbl[] = {
  149. { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
  150. { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
  151. { 0, }
  152. };
  153. MODULE_DEVICE_TABLE(pci, cs5535_mfd_pci_tbl);
  154. static struct pci_driver cs5535_mfd_driver = {
  155. .name = DRV_NAME,
  156. .id_table = cs5535_mfd_pci_tbl,
  157. .probe = cs5535_mfd_probe,
  158. .remove = __devexit_p(cs5535_mfd_remove),
  159. };
  160. static int __init cs5535_mfd_init(void)
  161. {
  162. return pci_register_driver(&cs5535_mfd_driver);
  163. }
  164. static void __exit cs5535_mfd_exit(void)
  165. {
  166. pci_unregister_driver(&cs5535_mfd_driver);
  167. }
  168. module_init(cs5535_mfd_init);
  169. module_exit(cs5535_mfd_exit);
  170. MODULE_AUTHOR("Andres Salomon <dilinger@queued.net>");
  171. MODULE_DESCRIPTION("MFD driver for CS5535/CS5536 southbridge's ISA PCI device");
  172. MODULE_LICENSE("GPL");