031-12-MIPS-BCM47xx-Add-generic-function-filling-SPROM-entr.patch 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. From d55a52ccf8f80cdf51af2c5c6e56c825f98c4f85 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  3. Date: Thu, 2 Apr 2015 09:13:49 +0200
  4. Subject: [PATCH] MIPS: BCM47xx: Add generic function filling SPROM entries
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Handling many SPROM revisions became messy, we have tons of functions
  9. specific to various revision groups which are quite hard to track.
  10. For years there is yet another revision 11 asking for support, but
  11. adding it in current the form would make things even worse.
  12. To resolve this problem let's add new function with table-like entries
  13. that will contain revision bitmask for every SPROM variable.
  14. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  15. Cc: linux-mips@linux-mips.org
  16. Cc: Hauke Mehrtens <hauke@hauke-m.de>
  17. Cc: Jonas Gorski <jonas.gorski@gmail.com>
  18. Patchwork: https://patchwork.linux-mips.org/patch/9659/
  19. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
  20. ---
  21. arch/mips/bcm47xx/sprom.c | 32 +++++++++++++++++++++++++++++---
  22. 1 file changed, 29 insertions(+), 3 deletions(-)
  23. --- a/arch/mips/bcm47xx/sprom.c
  24. +++ b/arch/mips/bcm47xx/sprom.c
  25. @@ -180,6 +180,33 @@ static void nvram_read_alpha2(const char
  26. memcpy(val, buf, 2);
  27. }
  28. +/* This is one-function-only macro, it uses local "sprom" variable! */
  29. +#define ENTRY(_revmask, _type, _prefix, _name, _val, _allset, _fallback) \
  30. + if (_revmask & BIT(sprom->revision)) \
  31. + nvram_read_ ## _type(_prefix, NULL, _name, &sprom->_val, \
  32. + _allset, _fallback)
  33. +/*
  34. + * Special version of filling function that can be safely called for any SPROM
  35. + * revision. For every NVRAM to SPROM mapping it contains bitmask of revisions
  36. + * for which the mapping is valid.
  37. + * It obviously requires some hexadecimal/bitmasks knowledge, but allows
  38. + * writing cleaner code (easy revisions handling).
  39. + * Note that while SPROM revision 0 was never used, we still keep BIT(0)
  40. + * reserved for it, just to keep numbering sane.
  41. + */
  42. +static void bcm47xx_sprom_fill_auto(struct ssb_sprom *sprom,
  43. + const char *prefix, bool fallback)
  44. +{
  45. + const char *pre = prefix;
  46. + bool fb = fallback;
  47. +
  48. + ENTRY(0xfffffffe, u16, pre, "boardrev", board_rev, 0, true);
  49. + ENTRY(0xfffffffe, u16, pre, "boardnum", board_num, 0, fb);
  50. +
  51. + /* TODO: Move more mappings here */
  52. +}
  53. +#undef ENTRY /* It's specififc, uses local variable, don't use it (again). */
  54. +
  55. static void bcm47xx_fill_sprom_r1234589(struct ssb_sprom *sprom,
  56. const char *prefix, bool fallback)
  57. {
  58. @@ -714,9 +741,6 @@ static void bcm47xx_fill_sprom_ethernet(
  59. static void bcm47xx_fill_board_data(struct ssb_sprom *sprom, const char *prefix,
  60. bool fallback)
  61. {
  62. - nvram_read_u16(prefix, NULL, "boardrev", &sprom->board_rev, 0, true);
  63. - nvram_read_u16(prefix, NULL, "boardnum", &sprom->board_num, 0,
  64. - fallback);
  65. nvram_read_u16(prefix, NULL, "boardtype", &sprom->board_type, 0, true);
  66. nvram_read_u32_2(prefix, "boardflags", &sprom->boardflags_lo,
  67. &sprom->boardflags_hi, fallback);
  68. @@ -787,6 +811,8 @@ void bcm47xx_fill_sprom(struct ssb_sprom
  69. bcm47xx_fill_sprom_r12389(sprom, prefix, fallback);
  70. bcm47xx_fill_sprom_r1(sprom, prefix, fallback);
  71. }
  72. +
  73. + bcm47xx_sprom_fill_auto(sprom, prefix, fallback);
  74. }
  75. #ifdef CONFIG_BCM47XX_SSB