driver_chipcommon_b.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Broadcom specific AMBA
  3. * ChipCommon B Unit driver
  4. *
  5. * Copyright 2014, Hauke Mehrtens <hauke@hauke-m.de>
  6. *
  7. * Licensed under the GNU/GPL. See COPYING for details.
  8. */
  9. #include "bcma_private.h"
  10. #include <linux/export.h>
  11. #include <linux/bcma/bcma.h>
  12. static bool bcma_wait_reg(struct bcma_bus *bus, void __iomem *addr, u32 mask,
  13. u32 value, int timeout)
  14. {
  15. unsigned long deadline = jiffies + timeout;
  16. u32 val;
  17. do {
  18. val = readl(addr);
  19. if ((val & mask) == value)
  20. return true;
  21. cpu_relax();
  22. udelay(10);
  23. } while (!time_after_eq(jiffies, deadline));
  24. bcma_err(bus, "Timeout waiting for register %p\n", addr);
  25. return false;
  26. }
  27. void bcma_chipco_b_mii_write(struct bcma_drv_cc_b *ccb, u32 offset, u32 value)
  28. {
  29. struct bcma_bus *bus = ccb->core->bus;
  30. void __iomem *mii = ccb->mii;
  31. writel(offset, mii + BCMA_CCB_MII_MNG_CTL);
  32. bcma_wait_reg(bus, mii + BCMA_CCB_MII_MNG_CTL, 0x0100, 0x0000, 100);
  33. writel(value, mii + BCMA_CCB_MII_MNG_CMD_DATA);
  34. bcma_wait_reg(bus, mii + BCMA_CCB_MII_MNG_CTL, 0x0100, 0x0000, 100);
  35. }
  36. EXPORT_SYMBOL_GPL(bcma_chipco_b_mii_write);
  37. int bcma_core_chipcommon_b_init(struct bcma_drv_cc_b *ccb)
  38. {
  39. if (ccb->setup_done)
  40. return 0;
  41. ccb->setup_done = 1;
  42. ccb->mii = ioremap_nocache(ccb->core->addr_s[1], BCMA_CORE_SIZE);
  43. if (!ccb->mii)
  44. return -ENOMEM;
  45. return 0;
  46. }
  47. void bcma_core_chipcommon_b_free(struct bcma_drv_cc_b *ccb)
  48. {
  49. if (ccb->mii)
  50. iounmap(ccb->mii);
  51. }