pch9.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2014 Google, Inc
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <pch.h>
  8. #define GPIO_BASE 0x48
  9. #define IO_BASE 0x4c
  10. #define SBASE_ADDR 0x54
  11. static int pch9_get_spi_base(struct udevice *dev, ulong *sbasep)
  12. {
  13. uint32_t sbase_addr;
  14. dm_pci_read_config32(dev, SBASE_ADDR, &sbase_addr);
  15. *sbasep = sbase_addr & 0xfffffe00;
  16. return 0;
  17. }
  18. static int pch9_get_gpio_base(struct udevice *dev, u32 *gbasep)
  19. {
  20. u32 base;
  21. /*
  22. * GPIO_BASE moved to its current offset with ICH6, but prior to
  23. * that it was unused (or undocumented). Check that it looks
  24. * okay: not all ones or zeros.
  25. *
  26. * Note we don't need check bit0 here, because the Tunnel Creek
  27. * GPIO base address register bit0 is reserved (read returns 0),
  28. * while on the Ivybridge the bit0 is used to indicate it is an
  29. * I/O space.
  30. */
  31. dm_pci_read_config32(dev, GPIO_BASE, &base);
  32. if (base == 0x00000000 || base == 0xffffffff) {
  33. debug("%s: unexpected BASE value\n", __func__);
  34. return -ENODEV;
  35. }
  36. /*
  37. * Okay, I guess we're looking at the right device. The actual
  38. * GPIO registers are in the PCI device's I/O space, starting
  39. * at the offset that we just read. Bit 0 indicates that it's
  40. * an I/O address, not a memory address, so mask that off.
  41. */
  42. *gbasep = base & 1 ? base & ~3 : base & ~15;
  43. return 0;
  44. }
  45. static int pch9_get_io_base(struct udevice *dev, u32 *iobasep)
  46. {
  47. u32 base;
  48. dm_pci_read_config32(dev, IO_BASE, &base);
  49. if (base == 0x00000000 || base == 0xffffffff) {
  50. debug("%s: unexpected BASE value\n", __func__);
  51. return -ENODEV;
  52. }
  53. *iobasep = base & 1 ? base & ~3 : base & ~15;
  54. return 0;
  55. }
  56. static const struct pch_ops pch9_ops = {
  57. .get_spi_base = pch9_get_spi_base,
  58. .get_gpio_base = pch9_get_gpio_base,
  59. .get_io_base = pch9_get_io_base,
  60. };
  61. static const struct udevice_id pch9_ids[] = {
  62. { .compatible = "intel,pch9" },
  63. { }
  64. };
  65. U_BOOT_DRIVER(pch9_drv) = {
  66. .name = "intel-pch9",
  67. .id = UCLASS_PCH,
  68. .of_match = pch9_ids,
  69. .ops = &pch9_ops,
  70. };