wl1251_io.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * This file is part of wl12xx
  3. *
  4. * Copyright (C) 2008 Nokia Corporation
  5. *
  6. * Contact: Kalle Valo <kalle.valo@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include "wl1251.h"
  24. #include "reg.h"
  25. #include "wl1251_io.h"
  26. static int wl1251_translate_reg_addr(struct wl1251 *wl, int addr)
  27. {
  28. /* If the address is lower than REGISTERS_BASE, it means that this is
  29. * a chip-specific register address, so look it up in the registers
  30. * table */
  31. if (addr < REGISTERS_BASE) {
  32. /* Make sure we don't go over the table */
  33. if (addr >= ACX_REG_TABLE_LEN) {
  34. wl1251_error("address out of range (%d)", addr);
  35. return -EINVAL;
  36. }
  37. addr = wl->chip.acx_reg_table[addr];
  38. }
  39. return addr - wl->physical_reg_addr + wl->virtual_reg_addr;
  40. }
  41. static int wl1251_translate_mem_addr(struct wl1251 *wl, int addr)
  42. {
  43. return addr - wl->physical_mem_addr + wl->virtual_mem_addr;
  44. }
  45. void wl1251_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len)
  46. {
  47. int physical;
  48. physical = wl1251_translate_mem_addr(wl, addr);
  49. wl1251_spi_read(wl, physical, buf, len);
  50. }
  51. void wl1251_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len)
  52. {
  53. int physical;
  54. physical = wl1251_translate_mem_addr(wl, addr);
  55. wl1251_spi_write(wl, physical, buf, len);
  56. }
  57. u32 wl1251_mem_read32(struct wl1251 *wl, int addr)
  58. {
  59. return wl1251_read32(wl, wl1251_translate_mem_addr(wl, addr));
  60. }
  61. void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val)
  62. {
  63. wl1251_write32(wl, wl1251_translate_mem_addr(wl, addr), val);
  64. }
  65. u32 wl1251_reg_read32(struct wl1251 *wl, int addr)
  66. {
  67. return wl1251_read32(wl, wl1251_translate_reg_addr(wl, addr));
  68. }
  69. void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val)
  70. {
  71. wl1251_write32(wl, wl1251_translate_reg_addr(wl, addr), val);
  72. }