driver_chipcommon_b.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. writel(offset, ccb->mii + 0x00);
  31. bcma_wait_reg(bus, ccb->mii + 0x00, 0x0100, 0x0000, 100);
  32. writel(value, ccb->mii + 0x04);
  33. bcma_wait_reg(bus, ccb->mii + 0x00, 0x0100, 0x0000, 100);
  34. }
  35. EXPORT_SYMBOL_GPL(bcma_chipco_b_mii_write);
  36. int bcma_core_chipcommon_b_init(struct bcma_drv_cc_b *ccb)
  37. {
  38. if (ccb->setup_done)
  39. return 0;
  40. ccb->setup_done = 1;
  41. ccb->mii = ioremap_nocache(ccb->core->addr_s[1], BCMA_CORE_SIZE);
  42. if (!ccb->mii)
  43. return -ENOMEM;
  44. return 0;
  45. }
  46. void bcma_core_chipcommon_b_free(struct bcma_drv_cc_b *ccb)
  47. {
  48. if (ccb->mii)
  49. iounmap(ccb->mii);
  50. }