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