ops-lantiq.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * This program is free software; you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License version 2 as published
  4. * by the Free Software Foundation.
  5. *
  6. * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
  7. */
  8. #include <linux/types.h>
  9. #include <linux/pci.h>
  10. #include <linux/kernel.h>
  11. #include <linux/delay.h>
  12. #include <linux/mm.h>
  13. #include <asm/addrspace.h>
  14. #include <linux/vmalloc.h>
  15. #include <lantiq_soc.h>
  16. #include "pci-lantiq.h"
  17. #define LTQ_PCI_CFG_BUSNUM_SHF 16
  18. #define LTQ_PCI_CFG_DEVNUM_SHF 11
  19. #define LTQ_PCI_CFG_FUNNUM_SHF 8
  20. #define PCI_ACCESS_READ 0
  21. #define PCI_ACCESS_WRITE 1
  22. static int ltq_pci_config_access(unsigned char access_type, struct pci_bus *bus,
  23. unsigned int devfn, unsigned int where, u32 *data)
  24. {
  25. unsigned long cfg_base;
  26. unsigned long flags;
  27. u32 temp;
  28. /* we support slot from 0 to 15 dev_fn & 0x68 (AD29) is the
  29. SoC itself */
  30. if ((bus->number != 0) || ((devfn & 0xf8) > 0x78)
  31. || ((devfn & 0xf8) == 0) || ((devfn & 0xf8) == 0x68))
  32. return 1;
  33. spin_lock_irqsave(&ebu_lock, flags);
  34. cfg_base = (unsigned long) ltq_pci_mapped_cfg;
  35. cfg_base |= (bus->number << LTQ_PCI_CFG_BUSNUM_SHF) | (devfn <<
  36. LTQ_PCI_CFG_FUNNUM_SHF) | (where & ~0x3);
  37. /* Perform access */
  38. if (access_type == PCI_ACCESS_WRITE) {
  39. ltq_w32(swab32(*data), ((u32 *)cfg_base));
  40. } else {
  41. *data = ltq_r32(((u32 *)(cfg_base)));
  42. *data = swab32(*data);
  43. }
  44. wmb();
  45. /* clean possible Master abort */
  46. cfg_base = (unsigned long) ltq_pci_mapped_cfg;
  47. cfg_base |= (0x0 << LTQ_PCI_CFG_FUNNUM_SHF) + 4;
  48. temp = ltq_r32(((u32 *)(cfg_base)));
  49. temp = swab32(temp);
  50. cfg_base = (unsigned long) ltq_pci_mapped_cfg;
  51. cfg_base |= (0x68 << LTQ_PCI_CFG_FUNNUM_SHF) + 4;
  52. ltq_w32(temp, ((u32 *)cfg_base));
  53. spin_unlock_irqrestore(&ebu_lock, flags);
  54. if (((*data) == 0xffffffff) && (access_type == PCI_ACCESS_READ))
  55. return 1;
  56. return 0;
  57. }
  58. int ltq_pci_read_config_dword(struct pci_bus *bus, unsigned int devfn,
  59. int where, int size, u32 *val)
  60. {
  61. u32 data = 0;
  62. if (ltq_pci_config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
  63. return PCIBIOS_DEVICE_NOT_FOUND;
  64. if (size == 1)
  65. *val = (data >> ((where & 3) << 3)) & 0xff;
  66. else if (size == 2)
  67. *val = (data >> ((where & 3) << 3)) & 0xffff;
  68. else
  69. *val = data;
  70. return PCIBIOS_SUCCESSFUL;
  71. }
  72. int ltq_pci_write_config_dword(struct pci_bus *bus, unsigned int devfn,
  73. int where, int size, u32 val)
  74. {
  75. u32 data = 0;
  76. if (size == 4) {
  77. data = val;
  78. } else {
  79. if (ltq_pci_config_access(PCI_ACCESS_READ, bus,
  80. devfn, where, &data))
  81. return PCIBIOS_DEVICE_NOT_FOUND;
  82. if (size == 1)
  83. data = (data & ~(0xff << ((where & 3) << 3))) |
  84. (val << ((where & 3) << 3));
  85. else if (size == 2)
  86. data = (data & ~(0xffff << ((where & 3) << 3))) |
  87. (val << ((where & 3) << 3));
  88. }
  89. if (ltq_pci_config_access(PCI_ACCESS_WRITE, bus, devfn, where, &data))
  90. return PCIBIOS_DEVICE_NOT_FOUND;
  91. return PCIBIOS_SUCCESSFUL;
  92. }