pci.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190
  1. /*
  2. * Sonics Silicon Backplane PCI-Hostbus related functions.
  3. *
  4. * Copyright (C) 2005-2006 Michael Buesch <m@bues.ch>
  5. * Copyright (C) 2005 Martin Langer <martin-langer@gmx.de>
  6. * Copyright (C) 2005 Stefano Brivio <st3@riseup.net>
  7. * Copyright (C) 2005 Danny van Dyk <kugelfang@gentoo.org>
  8. * Copyright (C) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
  9. *
  10. * Derived from the Broadcom 4400 device driver.
  11. * Copyright (C) 2002 David S. Miller (davem@redhat.com)
  12. * Fixed by Pekka Pietikainen (pp@ee.oulu.fi)
  13. * Copyright (C) 2006 Broadcom Corporation.
  14. *
  15. * Licensed under the GNU/GPL. See COPYING for details.
  16. */
  17. #include <linux/ssb/ssb.h>
  18. #include <linux/ssb/ssb_regs.h>
  19. #include <linux/slab.h>
  20. #include <linux/pci.h>
  21. #include <linux/delay.h>
  22. #include "ssb_private.h"
  23. /* Define the following to 1 to enable a printk on each coreswitch. */
  24. #define SSB_VERBOSE_PCICORESWITCH_DEBUG 0
  25. /* Lowlevel coreswitching */
  26. int ssb_pci_switch_coreidx(struct ssb_bus *bus, u8 coreidx)
  27. {
  28. int err;
  29. int attempts = 0;
  30. u32 cur_core;
  31. while (1) {
  32. err = pci_write_config_dword(bus->host_pci, SSB_BAR0_WIN,
  33. (coreidx * SSB_CORE_SIZE)
  34. + SSB_ENUM_BASE);
  35. if (err)
  36. goto error;
  37. err = pci_read_config_dword(bus->host_pci, SSB_BAR0_WIN,
  38. &cur_core);
  39. if (err)
  40. goto error;
  41. cur_core = (cur_core - SSB_ENUM_BASE)
  42. / SSB_CORE_SIZE;
  43. if (cur_core == coreidx)
  44. break;
  45. if (attempts++ > SSB_BAR0_MAX_RETRIES)
  46. goto error;
  47. udelay(10);
  48. }
  49. return 0;
  50. error:
  51. ssb_err("Failed to switch to core %u\n", coreidx);
  52. return -ENODEV;
  53. }
  54. int ssb_pci_switch_core(struct ssb_bus *bus,
  55. struct ssb_device *dev)
  56. {
  57. int err;
  58. unsigned long flags;
  59. #if SSB_VERBOSE_PCICORESWITCH_DEBUG
  60. ssb_info("Switching to %s core, index %d\n",
  61. ssb_core_name(dev->id.coreid),
  62. dev->core_index);
  63. #endif
  64. spin_lock_irqsave(&bus->bar_lock, flags);
  65. err = ssb_pci_switch_coreidx(bus, dev->core_index);
  66. if (!err)
  67. bus->mapped_device = dev;
  68. spin_unlock_irqrestore(&bus->bar_lock, flags);
  69. return err;
  70. }
  71. /* Enable/disable the on board crystal oscillator and/or PLL. */
  72. int ssb_pci_xtal(struct ssb_bus *bus, u32 what, int turn_on)
  73. {
  74. int err;
  75. u32 in, out, outenable;
  76. u16 pci_status;
  77. if (bus->bustype != SSB_BUSTYPE_PCI)
  78. return 0;
  79. err = pci_read_config_dword(bus->host_pci, SSB_GPIO_IN, &in);
  80. if (err)
  81. goto err_pci;
  82. err = pci_read_config_dword(bus->host_pci, SSB_GPIO_OUT, &out);
  83. if (err)
  84. goto err_pci;
  85. err = pci_read_config_dword(bus->host_pci, SSB_GPIO_OUT_ENABLE, &outenable);
  86. if (err)
  87. goto err_pci;
  88. outenable |= what;
  89. if (turn_on) {
  90. /* Avoid glitching the clock if GPRS is already using it.
  91. * We can't actually read the state of the PLLPD so we infer it
  92. * by the value of XTAL_PU which *is* readable via gpioin.
  93. */
  94. if (!(in & SSB_GPIO_XTAL)) {
  95. if (what & SSB_GPIO_XTAL) {
  96. /* Turn the crystal on */
  97. out |= SSB_GPIO_XTAL;
  98. if (what & SSB_GPIO_PLL)
  99. out |= SSB_GPIO_PLL;
  100. err = pci_write_config_dword(bus->host_pci, SSB_GPIO_OUT, out);
  101. if (err)
  102. goto err_pci;
  103. err = pci_write_config_dword(bus->host_pci, SSB_GPIO_OUT_ENABLE,
  104. outenable);
  105. if (err)
  106. goto err_pci;
  107. msleep(1);
  108. }
  109. if (what & SSB_GPIO_PLL) {
  110. /* Turn the PLL on */
  111. out &= ~SSB_GPIO_PLL;
  112. err = pci_write_config_dword(bus->host_pci, SSB_GPIO_OUT, out);
  113. if (err)
  114. goto err_pci;
  115. msleep(5);
  116. }
  117. }
  118. err = pci_read_config_word(bus->host_pci, PCI_STATUS, &pci_status);
  119. if (err)
  120. goto err_pci;
  121. pci_status &= ~PCI_STATUS_SIG_TARGET_ABORT;
  122. err = pci_write_config_word(bus->host_pci, PCI_STATUS, pci_status);
  123. if (err)
  124. goto err_pci;
  125. } else {
  126. if (what & SSB_GPIO_XTAL) {
  127. /* Turn the crystal off */
  128. out &= ~SSB_GPIO_XTAL;
  129. }
  130. if (what & SSB_GPIO_PLL) {
  131. /* Turn the PLL off */
  132. out |= SSB_GPIO_PLL;
  133. }
  134. err = pci_write_config_dword(bus->host_pci, SSB_GPIO_OUT, out);
  135. if (err)
  136. goto err_pci;
  137. err = pci_write_config_dword(bus->host_pci, SSB_GPIO_OUT_ENABLE, outenable);
  138. if (err)
  139. goto err_pci;
  140. }
  141. out:
  142. return err;
  143. err_pci:
  144. printk(KERN_ERR PFX "Error: ssb_pci_xtal() could not access PCI config space!\n");
  145. err = -EBUSY;
  146. goto out;
  147. }
  148. /* Get the word-offset for a SSB_SPROM_XXX define. */
  149. #define SPOFF(offset) ((offset) / sizeof(u16))
  150. /* Helper to extract some _offset, which is one of the SSB_SPROM_XXX defines. */
  151. #define SPEX16(_outvar, _offset, _mask, _shift) \
  152. out->_outvar = ((in[SPOFF(_offset)] & (_mask)) >> (_shift))
  153. #define SPEX32(_outvar, _offset, _mask, _shift) \
  154. out->_outvar = ((((u32)in[SPOFF((_offset)+2)] << 16 | \
  155. in[SPOFF(_offset)]) & (_mask)) >> (_shift))
  156. #define SPEX(_outvar, _offset, _mask, _shift) \
  157. SPEX16(_outvar, _offset, _mask, _shift)
  158. #define SPEX_ARRAY8(_field, _offset, _mask, _shift) \
  159. do { \
  160. SPEX(_field[0], _offset + 0, _mask, _shift); \
  161. SPEX(_field[1], _offset + 2, _mask, _shift); \
  162. SPEX(_field[2], _offset + 4, _mask, _shift); \
  163. SPEX(_field[3], _offset + 6, _mask, _shift); \
  164. SPEX(_field[4], _offset + 8, _mask, _shift); \
  165. SPEX(_field[5], _offset + 10, _mask, _shift); \
  166. SPEX(_field[6], _offset + 12, _mask, _shift); \
  167. SPEX(_field[7], _offset + 14, _mask, _shift); \
  168. } while (0)
  169. static inline u8 ssb_crc8(u8 crc, u8 data)
  170. {
  171. /* Polynomial: x^8 + x^7 + x^6 + x^4 + x^2 + 1 */
  172. static const u8 t[] = {
  173. 0x00, 0xF7, 0xB9, 0x4E, 0x25, 0xD2, 0x9C, 0x6B,
  174. 0x4A, 0xBD, 0xF3, 0x04, 0x6F, 0x98, 0xD6, 0x21,
  175. 0x94, 0x63, 0x2D, 0xDA, 0xB1, 0x46, 0x08, 0xFF,
  176. 0xDE, 0x29, 0x67, 0x90, 0xFB, 0x0C, 0x42, 0xB5,
  177. 0x7F, 0x88, 0xC6, 0x31, 0x5A, 0xAD, 0xE3, 0x14,
  178. 0x35, 0xC2, 0x8C, 0x7B, 0x10, 0xE7, 0xA9, 0x5E,
  179. 0xEB, 0x1C, 0x52, 0xA5, 0xCE, 0x39, 0x77, 0x80,
  180. 0xA1, 0x56, 0x18, 0xEF, 0x84, 0x73, 0x3D, 0xCA,
  181. 0xFE, 0x09, 0x47, 0xB0, 0xDB, 0x2C, 0x62, 0x95,
  182. 0xB4, 0x43, 0x0D, 0xFA, 0x91, 0x66, 0x28, 0xDF,
  183. 0x6A, 0x9D, 0xD3, 0x24, 0x4F, 0xB8, 0xF6, 0x01,
  184. 0x20, 0xD7, 0x99, 0x6E, 0x05, 0xF2, 0xBC, 0x4B,
  185. 0x81, 0x76, 0x38, 0xCF, 0xA4, 0x53, 0x1D, 0xEA,
  186. 0xCB, 0x3C, 0x72, 0x85, 0xEE, 0x19, 0x57, 0xA0,
  187. 0x15, 0xE2, 0xAC, 0x5B, 0x30, 0xC7, 0x89, 0x7E,
  188. 0x5F, 0xA8, 0xE6, 0x11, 0x7A, 0x8D, 0xC3, 0x34,
  189. 0xAB, 0x5C, 0x12, 0xE5, 0x8E, 0x79, 0x37, 0xC0,
  190. 0xE1, 0x16, 0x58, 0xAF, 0xC4, 0x33, 0x7D, 0x8A,
  191. 0x3F, 0xC8, 0x86, 0x71, 0x1A, 0xED, 0xA3, 0x54,
  192. 0x75, 0x82, 0xCC, 0x3B, 0x50, 0xA7, 0xE9, 0x1E,
  193. 0xD4, 0x23, 0x6D, 0x9A, 0xF1, 0x06, 0x48, 0xBF,
  194. 0x9E, 0x69, 0x27, 0xD0, 0xBB, 0x4C, 0x02, 0xF5,
  195. 0x40, 0xB7, 0xF9, 0x0E, 0x65, 0x92, 0xDC, 0x2B,
  196. 0x0A, 0xFD, 0xB3, 0x44, 0x2F, 0xD8, 0x96, 0x61,
  197. 0x55, 0xA2, 0xEC, 0x1B, 0x70, 0x87, 0xC9, 0x3E,
  198. 0x1F, 0xE8, 0xA6, 0x51, 0x3A, 0xCD, 0x83, 0x74,
  199. 0xC1, 0x36, 0x78, 0x8F, 0xE4, 0x13, 0x5D, 0xAA,
  200. 0x8B, 0x7C, 0x32, 0xC5, 0xAE, 0x59, 0x17, 0xE0,
  201. 0x2A, 0xDD, 0x93, 0x64, 0x0F, 0xF8, 0xB6, 0x41,
  202. 0x60, 0x97, 0xD9, 0x2E, 0x45, 0xB2, 0xFC, 0x0B,
  203. 0xBE, 0x49, 0x07, 0xF0, 0x9B, 0x6C, 0x22, 0xD5,
  204. 0xF4, 0x03, 0x4D, 0xBA, 0xD1, 0x26, 0x68, 0x9F,
  205. };
  206. return t[crc ^ data];
  207. }
  208. static void sprom_get_mac(char *mac, const u16 *in)
  209. {
  210. int i;
  211. for (i = 0; i < 3; i++) {
  212. *mac++ = in[i] >> 8;
  213. *mac++ = in[i];
  214. }
  215. }
  216. static u8 ssb_sprom_crc(const u16 *sprom, u16 size)
  217. {
  218. int word;
  219. u8 crc = 0xFF;
  220. for (word = 0; word < size - 1; word++) {
  221. crc = ssb_crc8(crc, sprom[word] & 0x00FF);
  222. crc = ssb_crc8(crc, (sprom[word] & 0xFF00) >> 8);
  223. }
  224. crc = ssb_crc8(crc, sprom[size - 1] & 0x00FF);
  225. crc ^= 0xFF;
  226. return crc;
  227. }
  228. static int sprom_check_crc(const u16 *sprom, size_t size)
  229. {
  230. u8 crc;
  231. u8 expected_crc;
  232. u16 tmp;
  233. crc = ssb_sprom_crc(sprom, size);
  234. tmp = sprom[size - 1] & SSB_SPROM_REVISION_CRC;
  235. expected_crc = tmp >> SSB_SPROM_REVISION_CRC_SHIFT;
  236. if (crc != expected_crc)
  237. return -EPROTO;
  238. return 0;
  239. }
  240. static int sprom_do_read(struct ssb_bus *bus, u16 *sprom)
  241. {
  242. int i;
  243. for (i = 0; i < bus->sprom_size; i++)
  244. sprom[i] = ioread16(bus->mmio + bus->sprom_offset + (i * 2));
  245. return 0;
  246. }
  247. static int sprom_do_write(struct ssb_bus *bus, const u16 *sprom)
  248. {
  249. struct pci_dev *pdev = bus->host_pci;
  250. int i, err;
  251. u32 spromctl;
  252. u16 size = bus->sprom_size;
  253. ssb_notice("Writing SPROM. Do NOT turn off the power! Please stand by...\n");
  254. err = pci_read_config_dword(pdev, SSB_SPROMCTL, &spromctl);
  255. if (err)
  256. goto err_ctlreg;
  257. spromctl |= SSB_SPROMCTL_WE;
  258. err = pci_write_config_dword(pdev, SSB_SPROMCTL, spromctl);
  259. if (err)
  260. goto err_ctlreg;
  261. ssb_notice("[ 0%%");
  262. msleep(500);
  263. for (i = 0; i < size; i++) {
  264. if (i == size / 4)
  265. ssb_cont("25%%");
  266. else if (i == size / 2)
  267. ssb_cont("50%%");
  268. else if (i == (size * 3) / 4)
  269. ssb_cont("75%%");
  270. else if (i % 2)
  271. ssb_cont(".");
  272. writew(sprom[i], bus->mmio + bus->sprom_offset + (i * 2));
  273. mmiowb();
  274. msleep(20);
  275. }
  276. err = pci_read_config_dword(pdev, SSB_SPROMCTL, &spromctl);
  277. if (err)
  278. goto err_ctlreg;
  279. spromctl &= ~SSB_SPROMCTL_WE;
  280. err = pci_write_config_dword(pdev, SSB_SPROMCTL, spromctl);
  281. if (err)
  282. goto err_ctlreg;
  283. msleep(500);
  284. ssb_cont("100%% ]\n");
  285. ssb_notice("SPROM written\n");
  286. return 0;
  287. err_ctlreg:
  288. ssb_err("Could not access SPROM control register.\n");
  289. return err;
  290. }
  291. static s8 sprom_extract_antgain(u8 sprom_revision, const u16 *in, u16 offset,
  292. u16 mask, u16 shift)
  293. {
  294. u16 v;
  295. u8 gain;
  296. v = in[SPOFF(offset)];
  297. gain = (v & mask) >> shift;
  298. if (gain == 0xFF)
  299. gain = 2; /* If unset use 2dBm */
  300. if (sprom_revision == 1) {
  301. /* Convert to Q5.2 */
  302. gain <<= 2;
  303. } else {
  304. /* Q5.2 Fractional part is stored in 0xC0 */
  305. gain = ((gain & 0xC0) >> 6) | ((gain & 0x3F) << 2);
  306. }
  307. return (s8)gain;
  308. }
  309. static void sprom_extract_r23(struct ssb_sprom *out, const u16 *in)
  310. {
  311. SPEX(boardflags_hi, SSB_SPROM2_BFLHI, 0xFFFF, 0);
  312. SPEX(opo, SSB_SPROM2_OPO, SSB_SPROM2_OPO_VALUE, 0);
  313. SPEX(pa1lob0, SSB_SPROM2_PA1LOB0, 0xFFFF, 0);
  314. SPEX(pa1lob1, SSB_SPROM2_PA1LOB1, 0xFFFF, 0);
  315. SPEX(pa1lob2, SSB_SPROM2_PA1LOB2, 0xFFFF, 0);
  316. SPEX(pa1hib0, SSB_SPROM2_PA1HIB0, 0xFFFF, 0);
  317. SPEX(pa1hib1, SSB_SPROM2_PA1HIB1, 0xFFFF, 0);
  318. SPEX(pa1hib2, SSB_SPROM2_PA1HIB2, 0xFFFF, 0);
  319. SPEX(maxpwr_ah, SSB_SPROM2_MAXP_A, SSB_SPROM2_MAXP_A_HI, 0);
  320. SPEX(maxpwr_al, SSB_SPROM2_MAXP_A, SSB_SPROM2_MAXP_A_LO,
  321. SSB_SPROM2_MAXP_A_LO_SHIFT);
  322. }
  323. static void sprom_extract_r123(struct ssb_sprom *out, const u16 *in)
  324. {
  325. u16 loc[3];
  326. if (out->revision == 3) /* rev 3 moved MAC */
  327. loc[0] = SSB_SPROM3_IL0MAC;
  328. else {
  329. loc[0] = SSB_SPROM1_IL0MAC;
  330. loc[1] = SSB_SPROM1_ET0MAC;
  331. loc[2] = SSB_SPROM1_ET1MAC;
  332. }
  333. sprom_get_mac(out->il0mac, &in[SPOFF(loc[0])]);
  334. if (out->revision < 3) { /* only rev 1-2 have et0, et1 */
  335. sprom_get_mac(out->et0mac, &in[SPOFF(loc[1])]);
  336. sprom_get_mac(out->et1mac, &in[SPOFF(loc[2])]);
  337. }
  338. SPEX(et0phyaddr, SSB_SPROM1_ETHPHY, SSB_SPROM1_ETHPHY_ET0A, 0);
  339. SPEX(et1phyaddr, SSB_SPROM1_ETHPHY, SSB_SPROM1_ETHPHY_ET1A,
  340. SSB_SPROM1_ETHPHY_ET1A_SHIFT);
  341. SPEX(et0mdcport, SSB_SPROM1_ETHPHY, SSB_SPROM1_ETHPHY_ET0M, 14);
  342. SPEX(et1mdcport, SSB_SPROM1_ETHPHY, SSB_SPROM1_ETHPHY_ET1M, 15);
  343. SPEX(board_rev, SSB_SPROM1_BINF, SSB_SPROM1_BINF_BREV, 0);
  344. SPEX(board_type, SSB_SPROM1_SPID, 0xFFFF, 0);
  345. if (out->revision == 1)
  346. SPEX(country_code, SSB_SPROM1_BINF, SSB_SPROM1_BINF_CCODE,
  347. SSB_SPROM1_BINF_CCODE_SHIFT);
  348. SPEX(ant_available_a, SSB_SPROM1_BINF, SSB_SPROM1_BINF_ANTA,
  349. SSB_SPROM1_BINF_ANTA_SHIFT);
  350. SPEX(ant_available_bg, SSB_SPROM1_BINF, SSB_SPROM1_BINF_ANTBG,
  351. SSB_SPROM1_BINF_ANTBG_SHIFT);
  352. SPEX(pa0b0, SSB_SPROM1_PA0B0, 0xFFFF, 0);
  353. SPEX(pa0b1, SSB_SPROM1_PA0B1, 0xFFFF, 0);
  354. SPEX(pa0b2, SSB_SPROM1_PA0B2, 0xFFFF, 0);
  355. SPEX(pa1b0, SSB_SPROM1_PA1B0, 0xFFFF, 0);
  356. SPEX(pa1b1, SSB_SPROM1_PA1B1, 0xFFFF, 0);
  357. SPEX(pa1b2, SSB_SPROM1_PA1B2, 0xFFFF, 0);
  358. SPEX(gpio0, SSB_SPROM1_GPIOA, SSB_SPROM1_GPIOA_P0, 0);
  359. SPEX(gpio1, SSB_SPROM1_GPIOA, SSB_SPROM1_GPIOA_P1,
  360. SSB_SPROM1_GPIOA_P1_SHIFT);
  361. SPEX(gpio2, SSB_SPROM1_GPIOB, SSB_SPROM1_GPIOB_P2, 0);
  362. SPEX(gpio3, SSB_SPROM1_GPIOB, SSB_SPROM1_GPIOB_P3,
  363. SSB_SPROM1_GPIOB_P3_SHIFT);
  364. SPEX(maxpwr_a, SSB_SPROM1_MAXPWR, SSB_SPROM1_MAXPWR_A,
  365. SSB_SPROM1_MAXPWR_A_SHIFT);
  366. SPEX(maxpwr_bg, SSB_SPROM1_MAXPWR, SSB_SPROM1_MAXPWR_BG, 0);
  367. SPEX(itssi_a, SSB_SPROM1_ITSSI, SSB_SPROM1_ITSSI_A,
  368. SSB_SPROM1_ITSSI_A_SHIFT);
  369. SPEX(itssi_bg, SSB_SPROM1_ITSSI, SSB_SPROM1_ITSSI_BG, 0);
  370. SPEX(boardflags_lo, SSB_SPROM1_BFLLO, 0xFFFF, 0);
  371. SPEX(alpha2[0], SSB_SPROM1_CCODE, 0xff00, 8);
  372. SPEX(alpha2[1], SSB_SPROM1_CCODE, 0x00ff, 0);
  373. /* Extract the antenna gain values. */
  374. out->antenna_gain.a0 = sprom_extract_antgain(out->revision, in,
  375. SSB_SPROM1_AGAIN,
  376. SSB_SPROM1_AGAIN_BG,
  377. SSB_SPROM1_AGAIN_BG_SHIFT);
  378. out->antenna_gain.a1 = sprom_extract_antgain(out->revision, in,
  379. SSB_SPROM1_AGAIN,
  380. SSB_SPROM1_AGAIN_A,
  381. SSB_SPROM1_AGAIN_A_SHIFT);
  382. if (out->revision >= 2)
  383. sprom_extract_r23(out, in);
  384. }
  385. /* Revs 4 5 and 8 have partially shared layout */
  386. static void sprom_extract_r458(struct ssb_sprom *out, const u16 *in)
  387. {
  388. SPEX(txpid2g[0], SSB_SPROM4_TXPID2G01,
  389. SSB_SPROM4_TXPID2G0, SSB_SPROM4_TXPID2G0_SHIFT);
  390. SPEX(txpid2g[1], SSB_SPROM4_TXPID2G01,
  391. SSB_SPROM4_TXPID2G1, SSB_SPROM4_TXPID2G1_SHIFT);
  392. SPEX(txpid2g[2], SSB_SPROM4_TXPID2G23,
  393. SSB_SPROM4_TXPID2G2, SSB_SPROM4_TXPID2G2_SHIFT);
  394. SPEX(txpid2g[3], SSB_SPROM4_TXPID2G23,
  395. SSB_SPROM4_TXPID2G3, SSB_SPROM4_TXPID2G3_SHIFT);
  396. SPEX(txpid5gl[0], SSB_SPROM4_TXPID5GL01,
  397. SSB_SPROM4_TXPID5GL0, SSB_SPROM4_TXPID5GL0_SHIFT);
  398. SPEX(txpid5gl[1], SSB_SPROM4_TXPID5GL01,
  399. SSB_SPROM4_TXPID5GL1, SSB_SPROM4_TXPID5GL1_SHIFT);
  400. SPEX(txpid5gl[2], SSB_SPROM4_TXPID5GL23,
  401. SSB_SPROM4_TXPID5GL2, SSB_SPROM4_TXPID5GL2_SHIFT);
  402. SPEX(txpid5gl[3], SSB_SPROM4_TXPID5GL23,
  403. SSB_SPROM4_TXPID5GL3, SSB_SPROM4_TXPID5GL3_SHIFT);
  404. SPEX(txpid5g[0], SSB_SPROM4_TXPID5G01,
  405. SSB_SPROM4_TXPID5G0, SSB_SPROM4_TXPID5G0_SHIFT);
  406. SPEX(txpid5g[1], SSB_SPROM4_TXPID5G01,
  407. SSB_SPROM4_TXPID5G1, SSB_SPROM4_TXPID5G1_SHIFT);
  408. SPEX(txpid5g[2], SSB_SPROM4_TXPID5G23,
  409. SSB_SPROM4_TXPID5G2, SSB_SPROM4_TXPID5G2_SHIFT);
  410. SPEX(txpid5g[3], SSB_SPROM4_TXPID5G23,
  411. SSB_SPROM4_TXPID5G3, SSB_SPROM4_TXPID5G3_SHIFT);
  412. SPEX(txpid5gh[0], SSB_SPROM4_TXPID5GH01,
  413. SSB_SPROM4_TXPID5GH0, SSB_SPROM4_TXPID5GH0_SHIFT);
  414. SPEX(txpid5gh[1], SSB_SPROM4_TXPID5GH01,
  415. SSB_SPROM4_TXPID5GH1, SSB_SPROM4_TXPID5GH1_SHIFT);
  416. SPEX(txpid5gh[2], SSB_SPROM4_TXPID5GH23,
  417. SSB_SPROM4_TXPID5GH2, SSB_SPROM4_TXPID5GH2_SHIFT);
  418. SPEX(txpid5gh[3], SSB_SPROM4_TXPID5GH23,
  419. SSB_SPROM4_TXPID5GH3, SSB_SPROM4_TXPID5GH3_SHIFT);
  420. }
  421. static void sprom_extract_r45(struct ssb_sprom *out, const u16 *in)
  422. {
  423. static const u16 pwr_info_offset[] = {
  424. SSB_SPROM4_PWR_INFO_CORE0, SSB_SPROM4_PWR_INFO_CORE1,
  425. SSB_SPROM4_PWR_INFO_CORE2, SSB_SPROM4_PWR_INFO_CORE3
  426. };
  427. u16 il0mac_offset;
  428. int i;
  429. BUILD_BUG_ON(ARRAY_SIZE(pwr_info_offset) !=
  430. ARRAY_SIZE(out->core_pwr_info));
  431. if (out->revision == 4)
  432. il0mac_offset = SSB_SPROM4_IL0MAC;
  433. else
  434. il0mac_offset = SSB_SPROM5_IL0MAC;
  435. sprom_get_mac(out->il0mac, &in[SPOFF(il0mac_offset)]);
  436. SPEX(et0phyaddr, SSB_SPROM4_ETHPHY, SSB_SPROM4_ETHPHY_ET0A, 0);
  437. SPEX(et1phyaddr, SSB_SPROM4_ETHPHY, SSB_SPROM4_ETHPHY_ET1A,
  438. SSB_SPROM4_ETHPHY_ET1A_SHIFT);
  439. SPEX(board_rev, SSB_SPROM4_BOARDREV, 0xFFFF, 0);
  440. SPEX(board_type, SSB_SPROM1_SPID, 0xFFFF, 0);
  441. if (out->revision == 4) {
  442. SPEX(alpha2[0], SSB_SPROM4_CCODE, 0xff00, 8);
  443. SPEX(alpha2[1], SSB_SPROM4_CCODE, 0x00ff, 0);
  444. SPEX(boardflags_lo, SSB_SPROM4_BFLLO, 0xFFFF, 0);
  445. SPEX(boardflags_hi, SSB_SPROM4_BFLHI, 0xFFFF, 0);
  446. SPEX(boardflags2_lo, SSB_SPROM4_BFL2LO, 0xFFFF, 0);
  447. SPEX(boardflags2_hi, SSB_SPROM4_BFL2HI, 0xFFFF, 0);
  448. } else {
  449. SPEX(alpha2[0], SSB_SPROM5_CCODE, 0xff00, 8);
  450. SPEX(alpha2[1], SSB_SPROM5_CCODE, 0x00ff, 0);
  451. SPEX(boardflags_lo, SSB_SPROM5_BFLLO, 0xFFFF, 0);
  452. SPEX(boardflags_hi, SSB_SPROM5_BFLHI, 0xFFFF, 0);
  453. SPEX(boardflags2_lo, SSB_SPROM5_BFL2LO, 0xFFFF, 0);
  454. SPEX(boardflags2_hi, SSB_SPROM5_BFL2HI, 0xFFFF, 0);
  455. }
  456. SPEX(ant_available_a, SSB_SPROM4_ANTAVAIL, SSB_SPROM4_ANTAVAIL_A,
  457. SSB_SPROM4_ANTAVAIL_A_SHIFT);
  458. SPEX(ant_available_bg, SSB_SPROM4_ANTAVAIL, SSB_SPROM4_ANTAVAIL_BG,
  459. SSB_SPROM4_ANTAVAIL_BG_SHIFT);
  460. SPEX(maxpwr_bg, SSB_SPROM4_MAXP_BG, SSB_SPROM4_MAXP_BG_MASK, 0);
  461. SPEX(itssi_bg, SSB_SPROM4_MAXP_BG, SSB_SPROM4_ITSSI_BG,
  462. SSB_SPROM4_ITSSI_BG_SHIFT);
  463. SPEX(maxpwr_a, SSB_SPROM4_MAXP_A, SSB_SPROM4_MAXP_A_MASK, 0);
  464. SPEX(itssi_a, SSB_SPROM4_MAXP_A, SSB_SPROM4_ITSSI_A,
  465. SSB_SPROM4_ITSSI_A_SHIFT);
  466. if (out->revision == 4) {
  467. SPEX(gpio0, SSB_SPROM4_GPIOA, SSB_SPROM4_GPIOA_P0, 0);
  468. SPEX(gpio1, SSB_SPROM4_GPIOA, SSB_SPROM4_GPIOA_P1,
  469. SSB_SPROM4_GPIOA_P1_SHIFT);
  470. SPEX(gpio2, SSB_SPROM4_GPIOB, SSB_SPROM4_GPIOB_P2, 0);
  471. SPEX(gpio3, SSB_SPROM4_GPIOB, SSB_SPROM4_GPIOB_P3,
  472. SSB_SPROM4_GPIOB_P3_SHIFT);
  473. } else {
  474. SPEX(gpio0, SSB_SPROM5_GPIOA, SSB_SPROM5_GPIOA_P0, 0);
  475. SPEX(gpio1, SSB_SPROM5_GPIOA, SSB_SPROM5_GPIOA_P1,
  476. SSB_SPROM5_GPIOA_P1_SHIFT);
  477. SPEX(gpio2, SSB_SPROM5_GPIOB, SSB_SPROM5_GPIOB_P2, 0);
  478. SPEX(gpio3, SSB_SPROM5_GPIOB, SSB_SPROM5_GPIOB_P3,
  479. SSB_SPROM5_GPIOB_P3_SHIFT);
  480. }
  481. /* Extract the antenna gain values. */
  482. out->antenna_gain.a0 = sprom_extract_antgain(out->revision, in,
  483. SSB_SPROM4_AGAIN01,
  484. SSB_SPROM4_AGAIN0,
  485. SSB_SPROM4_AGAIN0_SHIFT);
  486. out->antenna_gain.a1 = sprom_extract_antgain(out->revision, in,
  487. SSB_SPROM4_AGAIN01,
  488. SSB_SPROM4_AGAIN1,
  489. SSB_SPROM4_AGAIN1_SHIFT);
  490. out->antenna_gain.a2 = sprom_extract_antgain(out->revision, in,
  491. SSB_SPROM4_AGAIN23,
  492. SSB_SPROM4_AGAIN2,
  493. SSB_SPROM4_AGAIN2_SHIFT);
  494. out->antenna_gain.a3 = sprom_extract_antgain(out->revision, in,
  495. SSB_SPROM4_AGAIN23,
  496. SSB_SPROM4_AGAIN3,
  497. SSB_SPROM4_AGAIN3_SHIFT);
  498. /* Extract cores power info info */
  499. for (i = 0; i < ARRAY_SIZE(pwr_info_offset); i++) {
  500. u16 o = pwr_info_offset[i];
  501. SPEX(core_pwr_info[i].itssi_2g, o + SSB_SPROM4_2G_MAXP_ITSSI,
  502. SSB_SPROM4_2G_ITSSI, SSB_SPROM4_2G_ITSSI_SHIFT);
  503. SPEX(core_pwr_info[i].maxpwr_2g, o + SSB_SPROM4_2G_MAXP_ITSSI,
  504. SSB_SPROM4_2G_MAXP, 0);
  505. SPEX(core_pwr_info[i].pa_2g[0], o + SSB_SPROM4_2G_PA_0, ~0, 0);
  506. SPEX(core_pwr_info[i].pa_2g[1], o + SSB_SPROM4_2G_PA_1, ~0, 0);
  507. SPEX(core_pwr_info[i].pa_2g[2], o + SSB_SPROM4_2G_PA_2, ~0, 0);
  508. SPEX(core_pwr_info[i].pa_2g[3], o + SSB_SPROM4_2G_PA_3, ~0, 0);
  509. SPEX(core_pwr_info[i].itssi_5g, o + SSB_SPROM4_5G_MAXP_ITSSI,
  510. SSB_SPROM4_5G_ITSSI, SSB_SPROM4_5G_ITSSI_SHIFT);
  511. SPEX(core_pwr_info[i].maxpwr_5g, o + SSB_SPROM4_5G_MAXP_ITSSI,
  512. SSB_SPROM4_5G_MAXP, 0);
  513. SPEX(core_pwr_info[i].maxpwr_5gh, o + SSB_SPROM4_5GHL_MAXP,
  514. SSB_SPROM4_5GH_MAXP, 0);
  515. SPEX(core_pwr_info[i].maxpwr_5gl, o + SSB_SPROM4_5GHL_MAXP,
  516. SSB_SPROM4_5GL_MAXP, SSB_SPROM4_5GL_MAXP_SHIFT);
  517. SPEX(core_pwr_info[i].pa_5gl[0], o + SSB_SPROM4_5GL_PA_0, ~0, 0);
  518. SPEX(core_pwr_info[i].pa_5gl[1], o + SSB_SPROM4_5GL_PA_1, ~0, 0);
  519. SPEX(core_pwr_info[i].pa_5gl[2], o + SSB_SPROM4_5GL_PA_2, ~0, 0);
  520. SPEX(core_pwr_info[i].pa_5gl[3], o + SSB_SPROM4_5GL_PA_3, ~0, 0);
  521. SPEX(core_pwr_info[i].pa_5g[0], o + SSB_SPROM4_5G_PA_0, ~0, 0);
  522. SPEX(core_pwr_info[i].pa_5g[1], o + SSB_SPROM4_5G_PA_1, ~0, 0);
  523. SPEX(core_pwr_info[i].pa_5g[2], o + SSB_SPROM4_5G_PA_2, ~0, 0);
  524. SPEX(core_pwr_info[i].pa_5g[3], o + SSB_SPROM4_5G_PA_3, ~0, 0);
  525. SPEX(core_pwr_info[i].pa_5gh[0], o + SSB_SPROM4_5GH_PA_0, ~0, 0);
  526. SPEX(core_pwr_info[i].pa_5gh[1], o + SSB_SPROM4_5GH_PA_1, ~0, 0);
  527. SPEX(core_pwr_info[i].pa_5gh[2], o + SSB_SPROM4_5GH_PA_2, ~0, 0);
  528. SPEX(core_pwr_info[i].pa_5gh[3], o + SSB_SPROM4_5GH_PA_3, ~0, 0);
  529. }
  530. sprom_extract_r458(out, in);
  531. /* TODO - get remaining rev 4 stuff needed */
  532. }
  533. static void sprom_extract_r8(struct ssb_sprom *out, const u16 *in)
  534. {
  535. int i;
  536. u16 o;
  537. u16 pwr_info_offset[] = {
  538. SSB_SROM8_PWR_INFO_CORE0, SSB_SROM8_PWR_INFO_CORE1,
  539. SSB_SROM8_PWR_INFO_CORE2, SSB_SROM8_PWR_INFO_CORE3
  540. };
  541. BUILD_BUG_ON(ARRAY_SIZE(pwr_info_offset) !=
  542. ARRAY_SIZE(out->core_pwr_info));
  543. /* extract the MAC address */
  544. sprom_get_mac(out->il0mac, &in[SPOFF(SSB_SPROM8_IL0MAC)]);
  545. SPEX(board_rev, SSB_SPROM8_BOARDREV, 0xFFFF, 0);
  546. SPEX(board_type, SSB_SPROM1_SPID, 0xFFFF, 0);
  547. SPEX(alpha2[0], SSB_SPROM8_CCODE, 0xff00, 8);
  548. SPEX(alpha2[1], SSB_SPROM8_CCODE, 0x00ff, 0);
  549. SPEX(boardflags_lo, SSB_SPROM8_BFLLO, 0xFFFF, 0);
  550. SPEX(boardflags_hi, SSB_SPROM8_BFLHI, 0xFFFF, 0);
  551. SPEX(boardflags2_lo, SSB_SPROM8_BFL2LO, 0xFFFF, 0);
  552. SPEX(boardflags2_hi, SSB_SPROM8_BFL2HI, 0xFFFF, 0);
  553. SPEX(ant_available_a, SSB_SPROM8_ANTAVAIL, SSB_SPROM8_ANTAVAIL_A,
  554. SSB_SPROM8_ANTAVAIL_A_SHIFT);
  555. SPEX(ant_available_bg, SSB_SPROM8_ANTAVAIL, SSB_SPROM8_ANTAVAIL_BG,
  556. SSB_SPROM8_ANTAVAIL_BG_SHIFT);
  557. SPEX(maxpwr_bg, SSB_SPROM8_MAXP_BG, SSB_SPROM8_MAXP_BG_MASK, 0);
  558. SPEX(itssi_bg, SSB_SPROM8_MAXP_BG, SSB_SPROM8_ITSSI_BG,
  559. SSB_SPROM8_ITSSI_BG_SHIFT);
  560. SPEX(maxpwr_a, SSB_SPROM8_MAXP_A, SSB_SPROM8_MAXP_A_MASK, 0);
  561. SPEX(itssi_a, SSB_SPROM8_MAXP_A, SSB_SPROM8_ITSSI_A,
  562. SSB_SPROM8_ITSSI_A_SHIFT);
  563. SPEX(maxpwr_ah, SSB_SPROM8_MAXP_AHL, SSB_SPROM8_MAXP_AH_MASK, 0);
  564. SPEX(maxpwr_al, SSB_SPROM8_MAXP_AHL, SSB_SPROM8_MAXP_AL_MASK,
  565. SSB_SPROM8_MAXP_AL_SHIFT);
  566. SPEX(gpio0, SSB_SPROM8_GPIOA, SSB_SPROM8_GPIOA_P0, 0);
  567. SPEX(gpio1, SSB_SPROM8_GPIOA, SSB_SPROM8_GPIOA_P1,
  568. SSB_SPROM8_GPIOA_P1_SHIFT);
  569. SPEX(gpio2, SSB_SPROM8_GPIOB, SSB_SPROM8_GPIOB_P2, 0);
  570. SPEX(gpio3, SSB_SPROM8_GPIOB, SSB_SPROM8_GPIOB_P3,
  571. SSB_SPROM8_GPIOB_P3_SHIFT);
  572. SPEX(tri2g, SSB_SPROM8_TRI25G, SSB_SPROM8_TRI2G, 0);
  573. SPEX(tri5g, SSB_SPROM8_TRI25G, SSB_SPROM8_TRI5G,
  574. SSB_SPROM8_TRI5G_SHIFT);
  575. SPEX(tri5gl, SSB_SPROM8_TRI5GHL, SSB_SPROM8_TRI5GL, 0);
  576. SPEX(tri5gh, SSB_SPROM8_TRI5GHL, SSB_SPROM8_TRI5GH,
  577. SSB_SPROM8_TRI5GH_SHIFT);
  578. SPEX(rxpo2g, SSB_SPROM8_RXPO, SSB_SPROM8_RXPO2G, 0);
  579. SPEX(rxpo5g, SSB_SPROM8_RXPO, SSB_SPROM8_RXPO5G,
  580. SSB_SPROM8_RXPO5G_SHIFT);
  581. SPEX(rssismf2g, SSB_SPROM8_RSSIPARM2G, SSB_SPROM8_RSSISMF2G, 0);
  582. SPEX(rssismc2g, SSB_SPROM8_RSSIPARM2G, SSB_SPROM8_RSSISMC2G,
  583. SSB_SPROM8_RSSISMC2G_SHIFT);
  584. SPEX(rssisav2g, SSB_SPROM8_RSSIPARM2G, SSB_SPROM8_RSSISAV2G,
  585. SSB_SPROM8_RSSISAV2G_SHIFT);
  586. SPEX(bxa2g, SSB_SPROM8_RSSIPARM2G, SSB_SPROM8_BXA2G,
  587. SSB_SPROM8_BXA2G_SHIFT);
  588. SPEX(rssismf5g, SSB_SPROM8_RSSIPARM5G, SSB_SPROM8_RSSISMF5G, 0);
  589. SPEX(rssismc5g, SSB_SPROM8_RSSIPARM5G, SSB_SPROM8_RSSISMC5G,
  590. SSB_SPROM8_RSSISMC5G_SHIFT);
  591. SPEX(rssisav5g, SSB_SPROM8_RSSIPARM5G, SSB_SPROM8_RSSISAV5G,
  592. SSB_SPROM8_RSSISAV5G_SHIFT);
  593. SPEX(bxa5g, SSB_SPROM8_RSSIPARM5G, SSB_SPROM8_BXA5G,
  594. SSB_SPROM8_BXA5G_SHIFT);
  595. SPEX(pa0b0, SSB_SPROM8_PA0B0, 0xFFFF, 0);
  596. SPEX(pa0b1, SSB_SPROM8_PA0B1, 0xFFFF, 0);
  597. SPEX(pa0b2, SSB_SPROM8_PA0B2, 0xFFFF, 0);
  598. SPEX(pa1b0, SSB_SPROM8_PA1B0, 0xFFFF, 0);
  599. SPEX(pa1b1, SSB_SPROM8_PA1B1, 0xFFFF, 0);
  600. SPEX(pa1b2, SSB_SPROM8_PA1B2, 0xFFFF, 0);
  601. SPEX(pa1lob0, SSB_SPROM8_PA1LOB0, 0xFFFF, 0);
  602. SPEX(pa1lob1, SSB_SPROM8_PA1LOB1, 0xFFFF, 0);
  603. SPEX(pa1lob2, SSB_SPROM8_PA1LOB2, 0xFFFF, 0);
  604. SPEX(pa1hib0, SSB_SPROM8_PA1HIB0, 0xFFFF, 0);
  605. SPEX(pa1hib1, SSB_SPROM8_PA1HIB1, 0xFFFF, 0);
  606. SPEX(pa1hib2, SSB_SPROM8_PA1HIB2, 0xFFFF, 0);
  607. SPEX(cck2gpo, SSB_SPROM8_CCK2GPO, 0xFFFF, 0);
  608. SPEX32(ofdm2gpo, SSB_SPROM8_OFDM2GPO, 0xFFFFFFFF, 0);
  609. SPEX32(ofdm5glpo, SSB_SPROM8_OFDM5GLPO, 0xFFFFFFFF, 0);
  610. SPEX32(ofdm5gpo, SSB_SPROM8_OFDM5GPO, 0xFFFFFFFF, 0);
  611. SPEX32(ofdm5ghpo, SSB_SPROM8_OFDM5GHPO, 0xFFFFFFFF, 0);
  612. /* Extract the antenna gain values. */
  613. out->antenna_gain.a0 = sprom_extract_antgain(out->revision, in,
  614. SSB_SPROM8_AGAIN01,
  615. SSB_SPROM8_AGAIN0,
  616. SSB_SPROM8_AGAIN0_SHIFT);
  617. out->antenna_gain.a1 = sprom_extract_antgain(out->revision, in,
  618. SSB_SPROM8_AGAIN01,
  619. SSB_SPROM8_AGAIN1,
  620. SSB_SPROM8_AGAIN1_SHIFT);
  621. out->antenna_gain.a2 = sprom_extract_antgain(out->revision, in,
  622. SSB_SPROM8_AGAIN23,
  623. SSB_SPROM8_AGAIN2,
  624. SSB_SPROM8_AGAIN2_SHIFT);
  625. out->antenna_gain.a3 = sprom_extract_antgain(out->revision, in,
  626. SSB_SPROM8_AGAIN23,
  627. SSB_SPROM8_AGAIN3,
  628. SSB_SPROM8_AGAIN3_SHIFT);
  629. /* Extract cores power info info */
  630. for (i = 0; i < ARRAY_SIZE(pwr_info_offset); i++) {
  631. o = pwr_info_offset[i];
  632. SPEX(core_pwr_info[i].itssi_2g, o + SSB_SROM8_2G_MAXP_ITSSI,
  633. SSB_SPROM8_2G_ITSSI, SSB_SPROM8_2G_ITSSI_SHIFT);
  634. SPEX(core_pwr_info[i].maxpwr_2g, o + SSB_SROM8_2G_MAXP_ITSSI,
  635. SSB_SPROM8_2G_MAXP, 0);
  636. SPEX(core_pwr_info[i].pa_2g[0], o + SSB_SROM8_2G_PA_0, ~0, 0);
  637. SPEX(core_pwr_info[i].pa_2g[1], o + SSB_SROM8_2G_PA_1, ~0, 0);
  638. SPEX(core_pwr_info[i].pa_2g[2], o + SSB_SROM8_2G_PA_2, ~0, 0);
  639. SPEX(core_pwr_info[i].itssi_5g, o + SSB_SROM8_5G_MAXP_ITSSI,
  640. SSB_SPROM8_5G_ITSSI, SSB_SPROM8_5G_ITSSI_SHIFT);
  641. SPEX(core_pwr_info[i].maxpwr_5g, o + SSB_SROM8_5G_MAXP_ITSSI,
  642. SSB_SPROM8_5G_MAXP, 0);
  643. SPEX(core_pwr_info[i].maxpwr_5gh, o + SSB_SPROM8_5GHL_MAXP,
  644. SSB_SPROM8_5GH_MAXP, 0);
  645. SPEX(core_pwr_info[i].maxpwr_5gl, o + SSB_SPROM8_5GHL_MAXP,
  646. SSB_SPROM8_5GL_MAXP, SSB_SPROM8_5GL_MAXP_SHIFT);
  647. SPEX(core_pwr_info[i].pa_5gl[0], o + SSB_SROM8_5GL_PA_0, ~0, 0);
  648. SPEX(core_pwr_info[i].pa_5gl[1], o + SSB_SROM8_5GL_PA_1, ~0, 0);
  649. SPEX(core_pwr_info[i].pa_5gl[2], o + SSB_SROM8_5GL_PA_2, ~0, 0);
  650. SPEX(core_pwr_info[i].pa_5g[0], o + SSB_SROM8_5G_PA_0, ~0, 0);
  651. SPEX(core_pwr_info[i].pa_5g[1], o + SSB_SROM8_5G_PA_1, ~0, 0);
  652. SPEX(core_pwr_info[i].pa_5g[2], o + SSB_SROM8_5G_PA_2, ~0, 0);
  653. SPEX(core_pwr_info[i].pa_5gh[0], o + SSB_SROM8_5GH_PA_0, ~0, 0);
  654. SPEX(core_pwr_info[i].pa_5gh[1], o + SSB_SROM8_5GH_PA_1, ~0, 0);
  655. SPEX(core_pwr_info[i].pa_5gh[2], o + SSB_SROM8_5GH_PA_2, ~0, 0);
  656. }
  657. /* Extract FEM info */
  658. SPEX(fem.ghz2.tssipos, SSB_SPROM8_FEM2G,
  659. SSB_SROM8_FEM_TSSIPOS, SSB_SROM8_FEM_TSSIPOS_SHIFT);
  660. SPEX(fem.ghz2.extpa_gain, SSB_SPROM8_FEM2G,
  661. SSB_SROM8_FEM_EXTPA_GAIN, SSB_SROM8_FEM_EXTPA_GAIN_SHIFT);
  662. SPEX(fem.ghz2.pdet_range, SSB_SPROM8_FEM2G,
  663. SSB_SROM8_FEM_PDET_RANGE, SSB_SROM8_FEM_PDET_RANGE_SHIFT);
  664. SPEX(fem.ghz2.tr_iso, SSB_SPROM8_FEM2G,
  665. SSB_SROM8_FEM_TR_ISO, SSB_SROM8_FEM_TR_ISO_SHIFT);
  666. SPEX(fem.ghz2.antswlut, SSB_SPROM8_FEM2G,
  667. SSB_SROM8_FEM_ANTSWLUT, SSB_SROM8_FEM_ANTSWLUT_SHIFT);
  668. SPEX(fem.ghz5.tssipos, SSB_SPROM8_FEM5G,
  669. SSB_SROM8_FEM_TSSIPOS, SSB_SROM8_FEM_TSSIPOS_SHIFT);
  670. SPEX(fem.ghz5.extpa_gain, SSB_SPROM8_FEM5G,
  671. SSB_SROM8_FEM_EXTPA_GAIN, SSB_SROM8_FEM_EXTPA_GAIN_SHIFT);
  672. SPEX(fem.ghz5.pdet_range, SSB_SPROM8_FEM5G,
  673. SSB_SROM8_FEM_PDET_RANGE, SSB_SROM8_FEM_PDET_RANGE_SHIFT);
  674. SPEX(fem.ghz5.tr_iso, SSB_SPROM8_FEM5G,
  675. SSB_SROM8_FEM_TR_ISO, SSB_SROM8_FEM_TR_ISO_SHIFT);
  676. SPEX(fem.ghz5.antswlut, SSB_SPROM8_FEM5G,
  677. SSB_SROM8_FEM_ANTSWLUT, SSB_SROM8_FEM_ANTSWLUT_SHIFT);
  678. SPEX(leddc_on_time, SSB_SPROM8_LEDDC, SSB_SPROM8_LEDDC_ON,
  679. SSB_SPROM8_LEDDC_ON_SHIFT);
  680. SPEX(leddc_off_time, SSB_SPROM8_LEDDC, SSB_SPROM8_LEDDC_OFF,
  681. SSB_SPROM8_LEDDC_OFF_SHIFT);
  682. SPEX(txchain, SSB_SPROM8_TXRXC, SSB_SPROM8_TXRXC_TXCHAIN,
  683. SSB_SPROM8_TXRXC_TXCHAIN_SHIFT);
  684. SPEX(rxchain, SSB_SPROM8_TXRXC, SSB_SPROM8_TXRXC_RXCHAIN,
  685. SSB_SPROM8_TXRXC_RXCHAIN_SHIFT);
  686. SPEX(antswitch, SSB_SPROM8_TXRXC, SSB_SPROM8_TXRXC_SWITCH,
  687. SSB_SPROM8_TXRXC_SWITCH_SHIFT);
  688. SPEX(opo, SSB_SPROM8_OFDM2GPO, 0x00ff, 0);
  689. SPEX_ARRAY8(mcs2gpo, SSB_SPROM8_2G_MCSPO, ~0, 0);
  690. SPEX_ARRAY8(mcs5gpo, SSB_SPROM8_5G_MCSPO, ~0, 0);
  691. SPEX_ARRAY8(mcs5glpo, SSB_SPROM8_5GL_MCSPO, ~0, 0);
  692. SPEX_ARRAY8(mcs5ghpo, SSB_SPROM8_5GH_MCSPO, ~0, 0);
  693. SPEX(rawtempsense, SSB_SPROM8_RAWTS, SSB_SPROM8_RAWTS_RAWTEMP,
  694. SSB_SPROM8_RAWTS_RAWTEMP_SHIFT);
  695. SPEX(measpower, SSB_SPROM8_RAWTS, SSB_SPROM8_RAWTS_MEASPOWER,
  696. SSB_SPROM8_RAWTS_MEASPOWER_SHIFT);
  697. SPEX(tempsense_slope, SSB_SPROM8_OPT_CORRX,
  698. SSB_SPROM8_OPT_CORRX_TEMP_SLOPE,
  699. SSB_SPROM8_OPT_CORRX_TEMP_SLOPE_SHIFT);
  700. SPEX(tempcorrx, SSB_SPROM8_OPT_CORRX, SSB_SPROM8_OPT_CORRX_TEMPCORRX,
  701. SSB_SPROM8_OPT_CORRX_TEMPCORRX_SHIFT);
  702. SPEX(tempsense_option, SSB_SPROM8_OPT_CORRX,
  703. SSB_SPROM8_OPT_CORRX_TEMP_OPTION,
  704. SSB_SPROM8_OPT_CORRX_TEMP_OPTION_SHIFT);
  705. SPEX(freqoffset_corr, SSB_SPROM8_HWIQ_IQSWP,
  706. SSB_SPROM8_HWIQ_IQSWP_FREQ_CORR,
  707. SSB_SPROM8_HWIQ_IQSWP_FREQ_CORR_SHIFT);
  708. SPEX(iqcal_swp_dis, SSB_SPROM8_HWIQ_IQSWP,
  709. SSB_SPROM8_HWIQ_IQSWP_IQCAL_SWP,
  710. SSB_SPROM8_HWIQ_IQSWP_IQCAL_SWP_SHIFT);
  711. SPEX(hw_iqcal_en, SSB_SPROM8_HWIQ_IQSWP, SSB_SPROM8_HWIQ_IQSWP_HW_IQCAL,
  712. SSB_SPROM8_HWIQ_IQSWP_HW_IQCAL_SHIFT);
  713. SPEX(bw40po, SSB_SPROM8_BW40PO, ~0, 0);
  714. SPEX(cddpo, SSB_SPROM8_CDDPO, ~0, 0);
  715. SPEX(stbcpo, SSB_SPROM8_STBCPO, ~0, 0);
  716. SPEX(bwduppo, SSB_SPROM8_BWDUPPO, ~0, 0);
  717. SPEX(tempthresh, SSB_SPROM8_THERMAL, SSB_SPROM8_THERMAL_TRESH,
  718. SSB_SPROM8_THERMAL_TRESH_SHIFT);
  719. SPEX(tempoffset, SSB_SPROM8_THERMAL, SSB_SPROM8_THERMAL_OFFSET,
  720. SSB_SPROM8_THERMAL_OFFSET_SHIFT);
  721. SPEX(phycal_tempdelta, SSB_SPROM8_TEMPDELTA,
  722. SSB_SPROM8_TEMPDELTA_PHYCAL,
  723. SSB_SPROM8_TEMPDELTA_PHYCAL_SHIFT);
  724. SPEX(temps_period, SSB_SPROM8_TEMPDELTA, SSB_SPROM8_TEMPDELTA_PERIOD,
  725. SSB_SPROM8_TEMPDELTA_PERIOD_SHIFT);
  726. SPEX(temps_hysteresis, SSB_SPROM8_TEMPDELTA,
  727. SSB_SPROM8_TEMPDELTA_HYSTERESIS,
  728. SSB_SPROM8_TEMPDELTA_HYSTERESIS_SHIFT);
  729. sprom_extract_r458(out, in);
  730. /* TODO - get remaining rev 8 stuff needed */
  731. }
  732. static int sprom_extract(struct ssb_bus *bus, struct ssb_sprom *out,
  733. const u16 *in, u16 size)
  734. {
  735. memset(out, 0, sizeof(*out));
  736. out->revision = in[size - 1] & 0x00FF;
  737. ssb_dbg("SPROM revision %d detected\n", out->revision);
  738. memset(out->et0mac, 0xFF, 6); /* preset et0 and et1 mac */
  739. memset(out->et1mac, 0xFF, 6);
  740. if ((bus->chip_id & 0xFF00) == 0x4400) {
  741. /* Workaround: The BCM44XX chip has a stupid revision
  742. * number stored in the SPROM.
  743. * Always extract r1. */
  744. out->revision = 1;
  745. ssb_dbg("SPROM treated as revision %d\n", out->revision);
  746. }
  747. switch (out->revision) {
  748. case 1:
  749. case 2:
  750. case 3:
  751. sprom_extract_r123(out, in);
  752. break;
  753. case 4:
  754. case 5:
  755. sprom_extract_r45(out, in);
  756. break;
  757. case 8:
  758. sprom_extract_r8(out, in);
  759. break;
  760. default:
  761. ssb_warn("Unsupported SPROM revision %d detected. Will extract v1\n",
  762. out->revision);
  763. out->revision = 1;
  764. sprom_extract_r123(out, in);
  765. }
  766. if (out->boardflags_lo == 0xFFFF)
  767. out->boardflags_lo = 0; /* per specs */
  768. if (out->boardflags_hi == 0xFFFF)
  769. out->boardflags_hi = 0; /* per specs */
  770. return 0;
  771. }
  772. static int ssb_pci_sprom_get(struct ssb_bus *bus,
  773. struct ssb_sprom *sprom)
  774. {
  775. int err;
  776. u16 *buf;
  777. if (!ssb_is_sprom_available(bus)) {
  778. ssb_err("No SPROM available!\n");
  779. return -ENODEV;
  780. }
  781. if (bus->chipco.dev) { /* can be unavailable! */
  782. /*
  783. * get SPROM offset: SSB_SPROM_BASE1 except for
  784. * chipcommon rev >= 31 or chip ID is 0x4312 and
  785. * chipcommon status & 3 == 2
  786. */
  787. if (bus->chipco.dev->id.revision >= 31)
  788. bus->sprom_offset = SSB_SPROM_BASE31;
  789. else if (bus->chip_id == 0x4312 &&
  790. (bus->chipco.status & 0x03) == 2)
  791. bus->sprom_offset = SSB_SPROM_BASE31;
  792. else
  793. bus->sprom_offset = SSB_SPROM_BASE1;
  794. } else {
  795. bus->sprom_offset = SSB_SPROM_BASE1;
  796. }
  797. ssb_dbg("SPROM offset is 0x%x\n", bus->sprom_offset);
  798. buf = kcalloc(SSB_SPROMSIZE_WORDS_R123, sizeof(u16), GFP_KERNEL);
  799. if (!buf)
  800. return -ENOMEM;
  801. bus->sprom_size = SSB_SPROMSIZE_WORDS_R123;
  802. sprom_do_read(bus, buf);
  803. err = sprom_check_crc(buf, bus->sprom_size);
  804. if (err) {
  805. /* try for a 440 byte SPROM - revision 4 and higher */
  806. kfree(buf);
  807. buf = kcalloc(SSB_SPROMSIZE_WORDS_R4, sizeof(u16),
  808. GFP_KERNEL);
  809. if (!buf)
  810. return -ENOMEM;
  811. bus->sprom_size = SSB_SPROMSIZE_WORDS_R4;
  812. sprom_do_read(bus, buf);
  813. err = sprom_check_crc(buf, bus->sprom_size);
  814. if (err) {
  815. /* All CRC attempts failed.
  816. * Maybe there is no SPROM on the device?
  817. * Now we ask the arch code if there is some sprom
  818. * available for this device in some other storage */
  819. err = ssb_fill_sprom_with_fallback(bus, sprom);
  820. if (err) {
  821. ssb_warn("WARNING: Using fallback SPROM failed (err %d)\n",
  822. err);
  823. goto out_free;
  824. } else {
  825. ssb_dbg("Using SPROM revision %d provided by platform\n",
  826. sprom->revision);
  827. err = 0;
  828. goto out_free;
  829. }
  830. ssb_warn("WARNING: Invalid SPROM CRC (corrupt SPROM)\n");
  831. }
  832. }
  833. err = sprom_extract(bus, sprom, buf, bus->sprom_size);
  834. out_free:
  835. kfree(buf);
  836. return err;
  837. }
  838. static void ssb_pci_get_boardinfo(struct ssb_bus *bus,
  839. struct ssb_boardinfo *bi)
  840. {
  841. bi->vendor = bus->host_pci->subsystem_vendor;
  842. bi->type = bus->host_pci->subsystem_device;
  843. }
  844. int ssb_pci_get_invariants(struct ssb_bus *bus,
  845. struct ssb_init_invariants *iv)
  846. {
  847. int err;
  848. err = ssb_pci_sprom_get(bus, &iv->sprom);
  849. if (err)
  850. goto out;
  851. ssb_pci_get_boardinfo(bus, &iv->boardinfo);
  852. out:
  853. return err;
  854. }
  855. #ifdef CONFIG_SSB_DEBUG
  856. static int ssb_pci_assert_buspower(struct ssb_bus *bus)
  857. {
  858. if (likely(bus->powered_up))
  859. return 0;
  860. printk(KERN_ERR PFX "FATAL ERROR: Bus powered down "
  861. "while accessing PCI MMIO space\n");
  862. if (bus->power_warn_count <= 10) {
  863. bus->power_warn_count++;
  864. dump_stack();
  865. }
  866. return -ENODEV;
  867. }
  868. #else /* DEBUG */
  869. static inline int ssb_pci_assert_buspower(struct ssb_bus *bus)
  870. {
  871. return 0;
  872. }
  873. #endif /* DEBUG */
  874. static u8 ssb_pci_read8(struct ssb_device *dev, u16 offset)
  875. {
  876. struct ssb_bus *bus = dev->bus;
  877. if (unlikely(ssb_pci_assert_buspower(bus)))
  878. return 0xFF;
  879. if (unlikely(bus->mapped_device != dev)) {
  880. if (unlikely(ssb_pci_switch_core(bus, dev)))
  881. return 0xFF;
  882. }
  883. return ioread8(bus->mmio + offset);
  884. }
  885. static u16 ssb_pci_read16(struct ssb_device *dev, u16 offset)
  886. {
  887. struct ssb_bus *bus = dev->bus;
  888. if (unlikely(ssb_pci_assert_buspower(bus)))
  889. return 0xFFFF;
  890. if (unlikely(bus->mapped_device != dev)) {
  891. if (unlikely(ssb_pci_switch_core(bus, dev)))
  892. return 0xFFFF;
  893. }
  894. return ioread16(bus->mmio + offset);
  895. }
  896. static u32 ssb_pci_read32(struct ssb_device *dev, u16 offset)
  897. {
  898. struct ssb_bus *bus = dev->bus;
  899. if (unlikely(ssb_pci_assert_buspower(bus)))
  900. return 0xFFFFFFFF;
  901. if (unlikely(bus->mapped_device != dev)) {
  902. if (unlikely(ssb_pci_switch_core(bus, dev)))
  903. return 0xFFFFFFFF;
  904. }
  905. return ioread32(bus->mmio + offset);
  906. }
  907. #ifdef CONFIG_SSB_BLOCKIO
  908. static void ssb_pci_block_read(struct ssb_device *dev, void *buffer,
  909. size_t count, u16 offset, u8 reg_width)
  910. {
  911. struct ssb_bus *bus = dev->bus;
  912. void __iomem *addr = bus->mmio + offset;
  913. if (unlikely(ssb_pci_assert_buspower(bus)))
  914. goto error;
  915. if (unlikely(bus->mapped_device != dev)) {
  916. if (unlikely(ssb_pci_switch_core(bus, dev)))
  917. goto error;
  918. }
  919. switch (reg_width) {
  920. case sizeof(u8):
  921. ioread8_rep(addr, buffer, count);
  922. break;
  923. case sizeof(u16):
  924. SSB_WARN_ON(count & 1);
  925. ioread16_rep(addr, buffer, count >> 1);
  926. break;
  927. case sizeof(u32):
  928. SSB_WARN_ON(count & 3);
  929. ioread32_rep(addr, buffer, count >> 2);
  930. break;
  931. default:
  932. SSB_WARN_ON(1);
  933. }
  934. return;
  935. error:
  936. memset(buffer, 0xFF, count);
  937. }
  938. #endif /* CONFIG_SSB_BLOCKIO */
  939. static void ssb_pci_write8(struct ssb_device *dev, u16 offset, u8 value)
  940. {
  941. struct ssb_bus *bus = dev->bus;
  942. if (unlikely(ssb_pci_assert_buspower(bus)))
  943. return;
  944. if (unlikely(bus->mapped_device != dev)) {
  945. if (unlikely(ssb_pci_switch_core(bus, dev)))
  946. return;
  947. }
  948. iowrite8(value, bus->mmio + offset);
  949. }
  950. static void ssb_pci_write16(struct ssb_device *dev, u16 offset, u16 value)
  951. {
  952. struct ssb_bus *bus = dev->bus;
  953. if (unlikely(ssb_pci_assert_buspower(bus)))
  954. return;
  955. if (unlikely(bus->mapped_device != dev)) {
  956. if (unlikely(ssb_pci_switch_core(bus, dev)))
  957. return;
  958. }
  959. iowrite16(value, bus->mmio + offset);
  960. }
  961. static void ssb_pci_write32(struct ssb_device *dev, u16 offset, u32 value)
  962. {
  963. struct ssb_bus *bus = dev->bus;
  964. if (unlikely(ssb_pci_assert_buspower(bus)))
  965. return;
  966. if (unlikely(bus->mapped_device != dev)) {
  967. if (unlikely(ssb_pci_switch_core(bus, dev)))
  968. return;
  969. }
  970. iowrite32(value, bus->mmio + offset);
  971. }
  972. #ifdef CONFIG_SSB_BLOCKIO
  973. static void ssb_pci_block_write(struct ssb_device *dev, const void *buffer,
  974. size_t count, u16 offset, u8 reg_width)
  975. {
  976. struct ssb_bus *bus = dev->bus;
  977. void __iomem *addr = bus->mmio + offset;
  978. if (unlikely(ssb_pci_assert_buspower(bus)))
  979. return;
  980. if (unlikely(bus->mapped_device != dev)) {
  981. if (unlikely(ssb_pci_switch_core(bus, dev)))
  982. return;
  983. }
  984. switch (reg_width) {
  985. case sizeof(u8):
  986. iowrite8_rep(addr, buffer, count);
  987. break;
  988. case sizeof(u16):
  989. SSB_WARN_ON(count & 1);
  990. iowrite16_rep(addr, buffer, count >> 1);
  991. break;
  992. case sizeof(u32):
  993. SSB_WARN_ON(count & 3);
  994. iowrite32_rep(addr, buffer, count >> 2);
  995. break;
  996. default:
  997. SSB_WARN_ON(1);
  998. }
  999. }
  1000. #endif /* CONFIG_SSB_BLOCKIO */
  1001. /* Not "static", as it's used in main.c */
  1002. const struct ssb_bus_ops ssb_pci_ops = {
  1003. .read8 = ssb_pci_read8,
  1004. .read16 = ssb_pci_read16,
  1005. .read32 = ssb_pci_read32,
  1006. .write8 = ssb_pci_write8,
  1007. .write16 = ssb_pci_write16,
  1008. .write32 = ssb_pci_write32,
  1009. #ifdef CONFIG_SSB_BLOCKIO
  1010. .block_read = ssb_pci_block_read,
  1011. .block_write = ssb_pci_block_write,
  1012. #endif
  1013. };
  1014. static ssize_t ssb_pci_attr_sprom_show(struct device *pcidev,
  1015. struct device_attribute *attr,
  1016. char *buf)
  1017. {
  1018. struct pci_dev *pdev = container_of(pcidev, struct pci_dev, dev);
  1019. struct ssb_bus *bus;
  1020. bus = ssb_pci_dev_to_bus(pdev);
  1021. if (!bus)
  1022. return -ENODEV;
  1023. return ssb_attr_sprom_show(bus, buf, sprom_do_read);
  1024. }
  1025. static ssize_t ssb_pci_attr_sprom_store(struct device *pcidev,
  1026. struct device_attribute *attr,
  1027. const char *buf, size_t count)
  1028. {
  1029. struct pci_dev *pdev = container_of(pcidev, struct pci_dev, dev);
  1030. struct ssb_bus *bus;
  1031. bus = ssb_pci_dev_to_bus(pdev);
  1032. if (!bus)
  1033. return -ENODEV;
  1034. return ssb_attr_sprom_store(bus, buf, count,
  1035. sprom_check_crc, sprom_do_write);
  1036. }
  1037. static DEVICE_ATTR(ssb_sprom, 0600,
  1038. ssb_pci_attr_sprom_show,
  1039. ssb_pci_attr_sprom_store);
  1040. void ssb_pci_exit(struct ssb_bus *bus)
  1041. {
  1042. struct pci_dev *pdev;
  1043. if (bus->bustype != SSB_BUSTYPE_PCI)
  1044. return;
  1045. pdev = bus->host_pci;
  1046. device_remove_file(&pdev->dev, &dev_attr_ssb_sprom);
  1047. }
  1048. int ssb_pci_init(struct ssb_bus *bus)
  1049. {
  1050. struct pci_dev *pdev;
  1051. int err;
  1052. if (bus->bustype != SSB_BUSTYPE_PCI)
  1053. return 0;
  1054. pdev = bus->host_pci;
  1055. mutex_init(&bus->sprom_mutex);
  1056. err = device_create_file(&pdev->dev, &dev_attr_ssb_sprom);
  1057. if (err)
  1058. goto out;
  1059. out:
  1060. return err;
  1061. }