hw.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Wireless Host Controller (WHC) hardware access helpers.
  3. *
  4. * Copyright (C) 2007 Cambridge Silicon Radio Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version
  8. * 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/dma-mapping.h>
  20. #include <linux/uwb/umc.h>
  21. #include "../../wusbcore/wusbhc.h"
  22. #include "whcd.h"
  23. void whc_write_wusbcmd(struct whc *whc, u32 mask, u32 val)
  24. {
  25. unsigned long flags;
  26. u32 cmd;
  27. spin_lock_irqsave(&whc->lock, flags);
  28. cmd = le_readl(whc->base + WUSBCMD);
  29. cmd = (cmd & ~mask) | val;
  30. le_writel(cmd, whc->base + WUSBCMD);
  31. spin_unlock_irqrestore(&whc->lock, flags);
  32. }
  33. /**
  34. * whc_do_gencmd - start a generic command via the WUSBGENCMDSTS register
  35. * @whc: the WHCI HC
  36. * @cmd: command to start.
  37. * @params: parameters for the command (the WUSBGENCMDPARAMS register value).
  38. * @addr: pointer to any data for the command (may be NULL).
  39. * @len: length of the data (if any).
  40. */
  41. int whc_do_gencmd(struct whc *whc, u32 cmd, u32 params, void *addr, size_t len)
  42. {
  43. unsigned long flags;
  44. dma_addr_t dma_addr;
  45. int t;
  46. int ret = 0;
  47. mutex_lock(&whc->mutex);
  48. /* Wait for previous command to complete. */
  49. t = wait_event_timeout(whc->cmd_wq,
  50. (le_readl(whc->base + WUSBGENCMDSTS) & WUSBGENCMDSTS_ACTIVE) == 0,
  51. WHC_GENCMD_TIMEOUT_MS);
  52. if (t == 0) {
  53. dev_err(&whc->umc->dev, "generic command timeout (%04x/%04x)\n",
  54. le_readl(whc->base + WUSBGENCMDSTS),
  55. le_readl(whc->base + WUSBGENCMDPARAMS));
  56. ret = -ETIMEDOUT;
  57. goto out;
  58. }
  59. if (addr) {
  60. memcpy(whc->gen_cmd_buf, addr, len);
  61. dma_addr = whc->gen_cmd_buf_dma;
  62. } else
  63. dma_addr = 0;
  64. /* Poke registers to start cmd. */
  65. spin_lock_irqsave(&whc->lock, flags);
  66. le_writel(params, whc->base + WUSBGENCMDPARAMS);
  67. le_writeq(dma_addr, whc->base + WUSBGENADDR);
  68. le_writel(WUSBGENCMDSTS_ACTIVE | WUSBGENCMDSTS_IOC | cmd,
  69. whc->base + WUSBGENCMDSTS);
  70. spin_unlock_irqrestore(&whc->lock, flags);
  71. out:
  72. mutex_unlock(&whc->mutex);
  73. return ret;
  74. }
  75. /**
  76. * whc_hw_error - recover from a hardware error
  77. * @whc: the WHCI HC that broke.
  78. * @reason: a description of the failure.
  79. *
  80. * Recover from broken hardware with a full reset.
  81. */
  82. void whc_hw_error(struct whc *whc, const char *reason)
  83. {
  84. struct wusbhc *wusbhc = &whc->wusbhc;
  85. dev_err(&whc->umc->dev, "hardware error: %s\n", reason);
  86. wusbhc_reset_all(wusbhc);
  87. }