vx855.c 3.2 KB

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