driver_chipcommon.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Broadcom specific AMBA
  3. * ChipCommon core driver
  4. *
  5. * Copyright 2005, Broadcom Corporation
  6. * Copyright 2006, 2007, Michael Buesch <mb@bu3sch.de>
  7. *
  8. * Licensed under the GNU/GPL. See COPYING for details.
  9. */
  10. #include "bcma_private.h"
  11. #include <linux/bcma/bcma.h>
  12. static inline u32 bcma_cc_write32_masked(struct bcma_drv_cc *cc, u16 offset,
  13. u32 mask, u32 value)
  14. {
  15. value &= mask;
  16. value |= bcma_cc_read32(cc, offset) & ~mask;
  17. bcma_cc_write32(cc, offset, value);
  18. return value;
  19. }
  20. void bcma_core_chipcommon_init(struct bcma_drv_cc *cc)
  21. {
  22. if (cc->core->id.rev >= 11)
  23. cc->status = bcma_cc_read32(cc, BCMA_CC_CHIPSTAT);
  24. cc->capabilities = bcma_cc_read32(cc, BCMA_CC_CAP);
  25. if (cc->core->id.rev >= 35)
  26. cc->capabilities_ext = bcma_cc_read32(cc, BCMA_CC_CAP_EXT);
  27. if (cc->core->id.rev >= 20) {
  28. bcma_cc_write32(cc, BCMA_CC_GPIOPULLUP, 0);
  29. bcma_cc_write32(cc, BCMA_CC_GPIOPULLDOWN, 0);
  30. }
  31. if (cc->capabilities & BCMA_CC_CAP_PMU)
  32. bcma_pmu_init(cc);
  33. if (cc->capabilities & BCMA_CC_CAP_PCTL)
  34. pr_err("Power control not implemented!\n");
  35. }
  36. /* Set chip watchdog reset timer to fire in 'ticks' backplane cycles */
  37. void bcma_chipco_watchdog_timer_set(struct bcma_drv_cc *cc, u32 ticks)
  38. {
  39. /* instant NMI */
  40. bcma_cc_write32(cc, BCMA_CC_WATCHDOG, ticks);
  41. }
  42. void bcma_chipco_irq_mask(struct bcma_drv_cc *cc, u32 mask, u32 value)
  43. {
  44. bcma_cc_write32_masked(cc, BCMA_CC_IRQMASK, mask, value);
  45. }
  46. u32 bcma_chipco_irq_status(struct bcma_drv_cc *cc, u32 mask)
  47. {
  48. return bcma_cc_read32(cc, BCMA_CC_IRQSTAT) & mask;
  49. }
  50. u32 bcma_chipco_gpio_in(struct bcma_drv_cc *cc, u32 mask)
  51. {
  52. return bcma_cc_read32(cc, BCMA_CC_GPIOIN) & mask;
  53. }
  54. u32 bcma_chipco_gpio_out(struct bcma_drv_cc *cc, u32 mask, u32 value)
  55. {
  56. return bcma_cc_write32_masked(cc, BCMA_CC_GPIOOUT, mask, value);
  57. }
  58. u32 bcma_chipco_gpio_outen(struct bcma_drv_cc *cc, u32 mask, u32 value)
  59. {
  60. return bcma_cc_write32_masked(cc, BCMA_CC_GPIOOUTEN, mask, value);
  61. }
  62. u32 bcma_chipco_gpio_control(struct bcma_drv_cc *cc, u32 mask, u32 value)
  63. {
  64. return bcma_cc_write32_masked(cc, BCMA_CC_GPIOCTL, mask, value);
  65. }
  66. EXPORT_SYMBOL_GPL(bcma_chipco_gpio_control);
  67. u32 bcma_chipco_gpio_intmask(struct bcma_drv_cc *cc, u32 mask, u32 value)
  68. {
  69. return bcma_cc_write32_masked(cc, BCMA_CC_GPIOIRQ, mask, value);
  70. }
  71. u32 bcma_chipco_gpio_polarity(struct bcma_drv_cc *cc, u32 mask, u32 value)
  72. {
  73. return bcma_cc_write32_masked(cc, BCMA_CC_GPIOPOL, mask, value);
  74. }