vx855.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Linux multi-function-device driver (MFD) for the integrated peripherals
  3. * of the VIA VX855 chipset
  4. *
  5. * Copyright (C) 2009 VIA Technologies, Inc.
  6. * Copyright (C) 2010 One Laptop per Child
  7. * Author: Harald Welte <HaraldWelte@viatech.com>
  8. * All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  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., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. *
  25. */
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/device.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/pci.h>
  31. #include <linux/mfd/core.h>
  32. /* offset into pci config space indicating the 16bit register containing
  33. * the power management IO space base */
  34. #define VX855_CFG_PMIO_OFFSET 0x88
  35. /* ACPI I/O Space registers */
  36. #define VX855_PMIO_ACPI 0x00
  37. #define VX855_PMIO_ACPI_LEN 0x0b
  38. /* Processor Power Management */
  39. #define VX855_PMIO_PPM 0x10
  40. #define VX855_PMIO_PPM_LEN 0x08
  41. /* General Purpose Power Management */
  42. #define VX855_PMIO_GPPM 0x20
  43. #define VX855_PMIO_R_GPI 0x48
  44. #define VX855_PMIO_R_GPO 0x4c
  45. #define VX855_PMIO_GPPM_LEN 0x33
  46. #define VSPIC_MMIO_SIZE 0x1000
  47. static struct resource vx855_gpio_resources[] = {
  48. {
  49. .flags = IORESOURCE_IO,
  50. },
  51. {
  52. .flags = IORESOURCE_IO,
  53. },
  54. };
  55. static const struct mfd_cell vx855_cells[] = {
  56. {
  57. .name = "vx855_gpio",
  58. .num_resources = ARRAY_SIZE(vx855_gpio_resources),
  59. .resources = vx855_gpio_resources,
  60. /* we must ignore resource conflicts, for reasons outlined in
  61. * the vx855_gpio driver */
  62. .ignore_resource_conflicts = true,
  63. },
  64. };
  65. static int vx855_probe(struct pci_dev *pdev,
  66. const struct pci_device_id *id)
  67. {
  68. int ret;
  69. u16 gpio_io_offset;
  70. ret = pci_enable_device(pdev);
  71. if (ret)
  72. return -ENODEV;
  73. pci_read_config_word(pdev, VX855_CFG_PMIO_OFFSET, &gpio_io_offset);
  74. if (!gpio_io_offset) {
  75. dev_warn(&pdev->dev,
  76. "BIOS did not assign PMIO base offset?!?\n");
  77. ret = -ENODEV;
  78. goto out;
  79. }
  80. /* mask out the lowest seven bits, as they are always zero, but
  81. * hardware returns them as 0x01 */
  82. gpio_io_offset &= 0xff80;
  83. /* As the region identified here includes many non-GPIO things, we
  84. * only work with the specific registers that concern us. */
  85. vx855_gpio_resources[0].start = gpio_io_offset + VX855_PMIO_R_GPI;
  86. vx855_gpio_resources[0].end = vx855_gpio_resources[0].start + 3;
  87. vx855_gpio_resources[1].start = gpio_io_offset + VX855_PMIO_R_GPO;
  88. vx855_gpio_resources[1].end = vx855_gpio_resources[1].start + 3;
  89. ret = mfd_add_devices(&pdev->dev, -1, vx855_cells, ARRAY_SIZE(vx855_cells),
  90. NULL, 0, NULL);
  91. /* we always return -ENODEV here in order to enable other
  92. * drivers like old, not-yet-platform_device ported i2c-viapro */
  93. return -ENODEV;
  94. out:
  95. pci_disable_device(pdev);
  96. return ret;
  97. }
  98. static void vx855_remove(struct pci_dev *pdev)
  99. {
  100. mfd_remove_devices(&pdev->dev);
  101. pci_disable_device(pdev);
  102. }
  103. static const struct pci_device_id vx855_pci_tbl[] = {
  104. { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX855) },
  105. { 0, }
  106. };
  107. MODULE_DEVICE_TABLE(pci, vx855_pci_tbl);
  108. static struct pci_driver vx855_pci_driver = {
  109. .name = "vx855",
  110. .id_table = vx855_pci_tbl,
  111. .probe = vx855_probe,
  112. .remove = vx855_remove,
  113. };
  114. module_pci_driver(vx855_pci_driver);
  115. MODULE_LICENSE("GPL");
  116. MODULE_AUTHOR("Harald Welte <HaraldWelte@viatech.com>");
  117. MODULE_DESCRIPTION("Driver for the VIA VX855 chipset");