io.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * This file is part of wl18xx
  3. *
  4. * Copyright (C) 2011 Texas Instruments
  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
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * 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, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include "../wlcore/wlcore.h"
  22. #include "../wlcore/io.h"
  23. #include "io.h"
  24. int wl18xx_top_reg_write(struct wl1271 *wl, int addr, u16 val)
  25. {
  26. u32 tmp;
  27. int ret;
  28. if (WARN_ON(addr % 2))
  29. return -EINVAL;
  30. if ((addr % 4) == 0) {
  31. ret = wlcore_read32(wl, addr, &tmp);
  32. if (ret < 0)
  33. goto out;
  34. tmp = (tmp & 0xffff0000) | val;
  35. ret = wlcore_write32(wl, addr, tmp);
  36. } else {
  37. ret = wlcore_read32(wl, addr - 2, &tmp);
  38. if (ret < 0)
  39. goto out;
  40. tmp = (tmp & 0xffff) | (val << 16);
  41. ret = wlcore_write32(wl, addr - 2, tmp);
  42. }
  43. out:
  44. return ret;
  45. }
  46. int wl18xx_top_reg_read(struct wl1271 *wl, int addr, u16 *out)
  47. {
  48. u32 val = 0;
  49. int ret;
  50. if (WARN_ON(addr % 2))
  51. return -EINVAL;
  52. if ((addr % 4) == 0) {
  53. /* address is 4-bytes aligned */
  54. ret = wlcore_read32(wl, addr, &val);
  55. if (ret >= 0 && out)
  56. *out = val & 0xffff;
  57. } else {
  58. ret = wlcore_read32(wl, addr - 2, &val);
  59. if (ret >= 0 && out)
  60. *out = (val & 0xffff0000) >> 16;
  61. }
  62. return ret;
  63. }