pci.c 37 KB

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