Lines Matching +full:bus +full:- +full:err

2  * Sonics Silicon Backplane PCI-Hostbus related functions.
4 * Copyright (C) 2005-2006 Michael Buesch <m@bues.ch>
5 * Copyright (C) 2005 Martin Langer <martin-langer@gmx.de>
32 int ssb_pci_switch_coreidx(struct ssb_bus *bus, u8 coreidx) in ssb_pci_switch_coreidx() argument
34 int err; in ssb_pci_switch_coreidx() local
39 err = pci_write_config_dword(bus->host_pci, SSB_BAR0_WIN, in ssb_pci_switch_coreidx()
42 if (err) in ssb_pci_switch_coreidx()
44 err = pci_read_config_dword(bus->host_pci, SSB_BAR0_WIN, in ssb_pci_switch_coreidx()
46 if (err) in ssb_pci_switch_coreidx()
48 cur_core = (cur_core - SSB_ENUM_BASE) in ssb_pci_switch_coreidx()
60 return -ENODEV; in ssb_pci_switch_coreidx()
63 int ssb_pci_switch_core(struct ssb_bus *bus, in ssb_pci_switch_core() argument
66 int err; in ssb_pci_switch_core() local
71 ssb_core_name(dev->id.coreid), dev->core_index); in ssb_pci_switch_core()
74 spin_lock_irqsave(&bus->bar_lock, flags); in ssb_pci_switch_core()
75 err = ssb_pci_switch_coreidx(bus, dev->core_index); in ssb_pci_switch_core()
76 if (!err) in ssb_pci_switch_core()
77 bus->mapped_device = dev; in ssb_pci_switch_core()
78 spin_unlock_irqrestore(&bus->bar_lock, flags); in ssb_pci_switch_core()
80 return err; in ssb_pci_switch_core()
84 int ssb_pci_xtal(struct ssb_bus *bus, u32 what, int turn_on) in ssb_pci_xtal() argument
86 int err; in ssb_pci_xtal() local
90 if (bus->bustype != SSB_BUSTYPE_PCI) in ssb_pci_xtal()
93 err = pci_read_config_dword(bus->host_pci, SSB_GPIO_IN, &in); in ssb_pci_xtal()
94 if (err) in ssb_pci_xtal()
96 err = pci_read_config_dword(bus->host_pci, SSB_GPIO_OUT, &out); in ssb_pci_xtal()
97 if (err) in ssb_pci_xtal()
99 err = pci_read_config_dword(bus->host_pci, SSB_GPIO_OUT_ENABLE, &outenable); in ssb_pci_xtal()
100 if (err) in ssb_pci_xtal()
116 err = pci_write_config_dword(bus->host_pci, SSB_GPIO_OUT, out); in ssb_pci_xtal()
117 if (err) in ssb_pci_xtal()
119 err = pci_write_config_dword(bus->host_pci, SSB_GPIO_OUT_ENABLE, in ssb_pci_xtal()
121 if (err) in ssb_pci_xtal()
128 err = pci_write_config_dword(bus->host_pci, SSB_GPIO_OUT, out); in ssb_pci_xtal()
129 if (err) in ssb_pci_xtal()
135 err = pci_read_config_word(bus->host_pci, PCI_STATUS, &pci_status); in ssb_pci_xtal()
136 if (err) in ssb_pci_xtal()
139 err = pci_write_config_word(bus->host_pci, PCI_STATUS, pci_status); in ssb_pci_xtal()
140 if (err) in ssb_pci_xtal()
151 err = pci_write_config_dword(bus->host_pci, SSB_GPIO_OUT, out); in ssb_pci_xtal()
152 if (err) in ssb_pci_xtal()
154 err = pci_write_config_dword(bus->host_pci, SSB_GPIO_OUT_ENABLE, outenable); in ssb_pci_xtal()
155 if (err) in ssb_pci_xtal()
160 return err; in ssb_pci_xtal()
164 err = -EBUSY; in ssb_pci_xtal()
168 /* Get the word-offset for a SSB_SPROM_XXX define. */
172 out->_outvar = ((in[SPOFF(_offset)] & (_mask)) >> (_shift))
174 out->_outvar = ((((u32)in[SPOFF((_offset)+2)] << 16 | \
246 for (word = 0; word < size - 1; word++) { in ssb_sprom_crc()
250 crc = ssb_crc8(crc, sprom[size - 1] & 0x00FF); in ssb_sprom_crc()
263 tmp = sprom[size - 1] & SSB_SPROM_REVISION_CRC; in sprom_check_crc()
266 return -EPROTO; in sprom_check_crc()
271 static int sprom_do_read(struct ssb_bus *bus, u16 *sprom) in sprom_do_read() argument
275 for (i = 0; i < bus->sprom_size; i++) in sprom_do_read()
276 sprom[i] = ioread16(bus->mmio + bus->sprom_offset + (i * 2)); in sprom_do_read()
281 static int sprom_do_write(struct ssb_bus *bus, const u16 *sprom) in sprom_do_write() argument
283 struct pci_dev *pdev = bus->host_pci; in sprom_do_write()
284 int i, err; in sprom_do_write() local
286 u16 size = bus->sprom_size; in sprom_do_write()
289 err = pci_read_config_dword(pdev, SSB_SPROMCTL, &spromctl); in sprom_do_write()
290 if (err) in sprom_do_write()
293 err = pci_write_config_dword(pdev, SSB_SPROMCTL, spromctl); in sprom_do_write()
294 if (err) in sprom_do_write()
307 writew(sprom[i], bus->mmio + bus->sprom_offset + (i * 2)); in sprom_do_write()
310 err = pci_read_config_dword(pdev, SSB_SPROMCTL, &spromctl); in sprom_do_write()
311 if (err) in sprom_do_write()
314 err = pci_write_config_dword(pdev, SSB_SPROMCTL, spromctl); in sprom_do_write()
315 if (err) in sprom_do_write()
324 return err; in sprom_do_write()
367 if (out->revision == 3) /* rev 3 moved MAC */ in sprom_extract_r123()
374 sprom_get_mac(out->il0mac, &in[SPOFF(loc[0])]); in sprom_extract_r123()
375 if (out->revision < 3) { /* only rev 1-2 have et0, et1 */ in sprom_extract_r123()
376 sprom_get_mac(out->et0mac, &in[SPOFF(loc[1])]); in sprom_extract_r123()
377 sprom_get_mac(out->et1mac, &in[SPOFF(loc[2])]); in sprom_extract_r123()
386 if (out->revision == 1) in sprom_extract_r123()
417 out->antenna_gain.a0 = sprom_extract_antgain(out->revision, in, in sprom_extract_r123()
421 out->antenna_gain.a1 = sprom_extract_antgain(out->revision, in, in sprom_extract_r123()
425 if (out->revision >= 2) in sprom_extract_r123()
479 ARRAY_SIZE(out->core_pwr_info)); in sprom_extract_r45()
481 if (out->revision == 4) in sprom_extract_r45()
486 sprom_get_mac(out->il0mac, &in[SPOFF(il0mac_offset)]); in sprom_extract_r45()
493 if (out->revision == 4) { in sprom_extract_r45()
518 if (out->revision == 4) { in sprom_extract_r45()
535 out->antenna_gain.a0 = sprom_extract_antgain(out->revision, in, in sprom_extract_r45()
539 out->antenna_gain.a1 = sprom_extract_antgain(out->revision, in, in sprom_extract_r45()
543 out->antenna_gain.a2 = sprom_extract_antgain(out->revision, in, in sprom_extract_r45()
547 out->antenna_gain.a3 = sprom_extract_antgain(out->revision, in, in sprom_extract_r45()
591 /* TODO - get remaining rev 4 stuff needed */ in sprom_extract_r45()
603 ARRAY_SIZE(out->core_pwr_info)); in sprom_extract_r8()
606 sprom_get_mac(out->il0mac, &in[SPOFF(SSB_SPROM8_IL0MAC)]); in sprom_extract_r8()
677 out->antenna_gain.a0 = sprom_extract_antgain(out->revision, in, in sprom_extract_r8()
681 out->antenna_gain.a1 = sprom_extract_antgain(out->revision, in, in sprom_extract_r8()
685 out->antenna_gain.a2 = sprom_extract_antgain(out->revision, in, in sprom_extract_r8()
689 out->antenna_gain.a3 = sprom_extract_antgain(out->revision, in, in sprom_extract_r8()
808 /* TODO - get remaining rev 8 stuff needed */ in sprom_extract_r8()
811 static int sprom_extract(struct ssb_bus *bus, struct ssb_sprom *out, in sprom_extract() argument
816 out->revision = in[size - 1] & 0x00FF; in sprom_extract()
817 pr_debug("SPROM revision %d detected\n", out->revision); in sprom_extract()
818 memset(out->et0mac, 0xFF, 6); /* preset et0 and et1 mac */ in sprom_extract()
819 memset(out->et1mac, 0xFF, 6); in sprom_extract()
821 if ((bus->chip_id & 0xFF00) == 0x4400) { in sprom_extract()
825 out->revision = 1; in sprom_extract()
826 pr_debug("SPROM treated as revision %d\n", out->revision); in sprom_extract()
829 switch (out->revision) { in sprom_extract()
844 out->revision); in sprom_extract()
845 out->revision = 1; in sprom_extract()
849 if (out->boardflags_lo == 0xFFFF) in sprom_extract()
850 out->boardflags_lo = 0; /* per specs */ in sprom_extract()
851 if (out->boardflags_hi == 0xFFFF) in sprom_extract()
852 out->boardflags_hi = 0; /* per specs */ in sprom_extract()
857 static int ssb_pci_sprom_get(struct ssb_bus *bus, in ssb_pci_sprom_get() argument
860 int err; in ssb_pci_sprom_get() local
863 if (!ssb_is_sprom_available(bus)) { in ssb_pci_sprom_get()
865 return -ENODEV; in ssb_pci_sprom_get()
867 if (bus->chipco.dev) { /* can be unavailable! */ in ssb_pci_sprom_get()
873 if (bus->chipco.dev->id.revision >= 31) in ssb_pci_sprom_get()
874 bus->sprom_offset = SSB_SPROM_BASE31; in ssb_pci_sprom_get()
875 else if (bus->chip_id == 0x4312 && in ssb_pci_sprom_get()
876 (bus->chipco.status & 0x03) == 2) in ssb_pci_sprom_get()
877 bus->sprom_offset = SSB_SPROM_BASE31; in ssb_pci_sprom_get()
879 bus->sprom_offset = SSB_SPROM_BASE1; in ssb_pci_sprom_get()
881 bus->sprom_offset = SSB_SPROM_BASE1; in ssb_pci_sprom_get()
883 pr_debug("SPROM offset is 0x%x\n", bus->sprom_offset); in ssb_pci_sprom_get()
887 return -ENOMEM; in ssb_pci_sprom_get()
888 bus->sprom_size = SSB_SPROMSIZE_WORDS_R123; in ssb_pci_sprom_get()
889 sprom_do_read(bus, buf); in ssb_pci_sprom_get()
890 err = sprom_check_crc(buf, bus->sprom_size); in ssb_pci_sprom_get()
891 if (err) { in ssb_pci_sprom_get()
892 /* try for a 440 byte SPROM - revision 4 and higher */ in ssb_pci_sprom_get()
897 return -ENOMEM; in ssb_pci_sprom_get()
898 bus->sprom_size = SSB_SPROMSIZE_WORDS_R4; in ssb_pci_sprom_get()
899 sprom_do_read(bus, buf); in ssb_pci_sprom_get()
900 err = sprom_check_crc(buf, bus->sprom_size); in ssb_pci_sprom_get()
901 if (err) { in ssb_pci_sprom_get()
906 err = ssb_fill_sprom_with_fallback(bus, sprom); in ssb_pci_sprom_get()
907 if (err) { in ssb_pci_sprom_get()
908 pr_warn("WARNING: Using fallback SPROM failed (err %d)\n", in ssb_pci_sprom_get()
909 err); in ssb_pci_sprom_get()
913 sprom->revision); in ssb_pci_sprom_get()
914 err = 0; in ssb_pci_sprom_get()
919 err = sprom_extract(bus, sprom, buf, bus->sprom_size); in ssb_pci_sprom_get()
923 return err; in ssb_pci_sprom_get()
926 static void ssb_pci_get_boardinfo(struct ssb_bus *bus, in ssb_pci_get_boardinfo() argument
929 bi->vendor = bus->host_pci->subsystem_vendor; in ssb_pci_get_boardinfo()
930 bi->type = bus->host_pci->subsystem_device; in ssb_pci_get_boardinfo()
933 int ssb_pci_get_invariants(struct ssb_bus *bus, in ssb_pci_get_invariants() argument
936 int err; in ssb_pci_get_invariants() local
938 err = ssb_pci_sprom_get(bus, &iv->sprom); in ssb_pci_get_invariants()
939 if (err) in ssb_pci_get_invariants()
941 ssb_pci_get_boardinfo(bus, &iv->boardinfo); in ssb_pci_get_invariants()
944 return err; in ssb_pci_get_invariants()
947 static int ssb_pci_assert_buspower(struct ssb_bus *bus) in ssb_pci_assert_buspower() argument
949 if (likely(bus->powered_up)) in ssb_pci_assert_buspower()
952 pr_err("FATAL ERROR: Bus powered down while accessing PCI MMIO space\n"); in ssb_pci_assert_buspower()
953 if (bus->power_warn_count <= 10) { in ssb_pci_assert_buspower()
954 bus->power_warn_count++; in ssb_pci_assert_buspower()
958 return -ENODEV; in ssb_pci_assert_buspower()
963 struct ssb_bus *bus = dev->bus; in ssb_pci_read8() local
965 if (unlikely(ssb_pci_assert_buspower(bus))) in ssb_pci_read8()
967 if (unlikely(bus->mapped_device != dev)) { in ssb_pci_read8()
968 if (unlikely(ssb_pci_switch_core(bus, dev))) in ssb_pci_read8()
971 return ioread8(bus->mmio + offset); in ssb_pci_read8()
976 struct ssb_bus *bus = dev->bus; in ssb_pci_read16() local
978 if (unlikely(ssb_pci_assert_buspower(bus))) in ssb_pci_read16()
980 if (unlikely(bus->mapped_device != dev)) { in ssb_pci_read16()
981 if (unlikely(ssb_pci_switch_core(bus, dev))) in ssb_pci_read16()
984 return ioread16(bus->mmio + offset); in ssb_pci_read16()
989 struct ssb_bus *bus = dev->bus; in ssb_pci_read32() local
991 if (unlikely(ssb_pci_assert_buspower(bus))) in ssb_pci_read32()
993 if (unlikely(bus->mapped_device != dev)) { in ssb_pci_read32()
994 if (unlikely(ssb_pci_switch_core(bus, dev))) in ssb_pci_read32()
997 return ioread32(bus->mmio + offset); in ssb_pci_read32()
1004 struct ssb_bus *bus = dev->bus; in ssb_pci_block_read() local
1005 void __iomem *addr = bus->mmio + offset; in ssb_pci_block_read()
1007 if (unlikely(ssb_pci_assert_buspower(bus))) in ssb_pci_block_read()
1009 if (unlikely(bus->mapped_device != dev)) { in ssb_pci_block_read()
1010 if (unlikely(ssb_pci_switch_core(bus, dev))) in ssb_pci_block_read()
1037 struct ssb_bus *bus = dev->bus; in ssb_pci_write8() local
1039 if (unlikely(ssb_pci_assert_buspower(bus))) in ssb_pci_write8()
1041 if (unlikely(bus->mapped_device != dev)) { in ssb_pci_write8()
1042 if (unlikely(ssb_pci_switch_core(bus, dev))) in ssb_pci_write8()
1045 iowrite8(value, bus->mmio + offset); in ssb_pci_write8()
1050 struct ssb_bus *bus = dev->bus; in ssb_pci_write16() local
1052 if (unlikely(ssb_pci_assert_buspower(bus))) in ssb_pci_write16()
1054 if (unlikely(bus->mapped_device != dev)) { in ssb_pci_write16()
1055 if (unlikely(ssb_pci_switch_core(bus, dev))) in ssb_pci_write16()
1058 iowrite16(value, bus->mmio + offset); in ssb_pci_write16()
1063 struct ssb_bus *bus = dev->bus; in ssb_pci_write32() local
1065 if (unlikely(ssb_pci_assert_buspower(bus))) in ssb_pci_write32()
1067 if (unlikely(bus->mapped_device != dev)) { in ssb_pci_write32()
1068 if (unlikely(ssb_pci_switch_core(bus, dev))) in ssb_pci_write32()
1071 iowrite32(value, bus->mmio + offset); in ssb_pci_write32()
1078 struct ssb_bus *bus = dev->bus; in ssb_pci_block_write() local
1079 void __iomem *addr = bus->mmio + offset; in ssb_pci_block_write()
1081 if (unlikely(ssb_pci_assert_buspower(bus))) in ssb_pci_block_write()
1083 if (unlikely(bus->mapped_device != dev)) { in ssb_pci_block_write()
1084 if (unlikely(ssb_pci_switch_core(bus, dev))) in ssb_pci_block_write()
1124 struct ssb_bus *bus; in ssb_sprom_show() local
1126 bus = ssb_pci_dev_to_bus(pdev); in ssb_sprom_show()
1127 if (!bus) in ssb_sprom_show()
1128 return -ENODEV; in ssb_sprom_show()
1130 return ssb_attr_sprom_show(bus, buf, sprom_do_read); in ssb_sprom_show()
1138 struct ssb_bus *bus; in ssb_sprom_store() local
1140 bus = ssb_pci_dev_to_bus(pdev); in ssb_sprom_store()
1141 if (!bus) in ssb_sprom_store()
1142 return -ENODEV; in ssb_sprom_store()
1144 return ssb_attr_sprom_store(bus, buf, count, in ssb_sprom_store()
1150 void ssb_pci_exit(struct ssb_bus *bus) in ssb_pci_exit() argument
1154 if (bus->bustype != SSB_BUSTYPE_PCI) in ssb_pci_exit()
1157 pdev = bus->host_pci; in ssb_pci_exit()
1158 device_remove_file(&pdev->dev, &dev_attr_ssb_sprom); in ssb_pci_exit()
1161 int ssb_pci_init(struct ssb_bus *bus) in ssb_pci_init() argument
1165 if (bus->bustype != SSB_BUSTYPE_PCI) in ssb_pci_init()
1168 pdev = bus->host_pci; in ssb_pci_init()
1169 mutex_init(&bus->sprom_mutex); in ssb_pci_init()
1171 return device_create_file(&pdev->dev, &dev_attr_ssb_sprom); in ssb_pci_init()