rtw_sdio.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2015 - 2016 Realtek Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. ******************************************************************************/
  19. #define _RTW_SDIO_C_
  20. #include <drv_types.h> /* struct dvobj_priv and etc. */
  21. #include <drv_types_sdio.h> /* RTW_SDIO_ADDR_CMD52_GEN */
  22. /*
  23. * Description:
  24. * Use SDIO cmd52 or cmd53 to read/write data
  25. *
  26. * Parameters:
  27. * d pointer of device object(struct dvobj_priv)
  28. * addr SDIO address, 17 bits
  29. * buf buffer for I/O
  30. * len length
  31. * write 0:read, 1:write
  32. * cmd52 0:cmd52, 1:cmd53
  33. *
  34. * Return:
  35. * _SUCCESS I/O ok.
  36. * _FAIL I/O fail.
  37. */
  38. static u8 sdio_io(struct dvobj_priv *d, u32 addr, void *buf, size_t len, u8 write, u8 cmd52)
  39. {
  40. int err;
  41. if (cmd52)
  42. addr = RTW_SDIO_ADDR_CMD52_GEN(addr);
  43. if (write)
  44. err = d->intf_ops->write(d, addr, buf, len, 0);
  45. else
  46. err = d->intf_ops->read(d, addr, buf, len, 0);
  47. if (err) {
  48. RTW_INFO("%s: [ERROR] %s FAIL! error(%d)\n",
  49. __FUNCTION__, write ? "write" : "read", err);
  50. return _FAIL;
  51. }
  52. return _SUCCESS;
  53. }
  54. u8 rtw_sdio_read_cmd52(struct dvobj_priv *d, u32 addr, void *buf, size_t len)
  55. {
  56. return sdio_io(d, addr, buf, len, 0, 1);
  57. }
  58. u8 rtw_sdio_read_cmd53(struct dvobj_priv *d, u32 addr, void *buf, size_t len)
  59. {
  60. return sdio_io(d, addr, buf, len, 0, 0);
  61. }
  62. u8 rtw_sdio_write_cmd52(struct dvobj_priv *d, u32 addr, void *buf, size_t len)
  63. {
  64. return sdio_io(d, addr, buf, len, 1, 1);
  65. }
  66. u8 rtw_sdio_write_cmd53(struct dvobj_priv *d, u32 addr, void *buf, size_t len)
  67. {
  68. return sdio_io(d, addr, buf, len, 1, 0);
  69. }
  70. u8 rtw_sdio_f0_read(struct dvobj_priv *d, u32 addr, void *buf, size_t len)
  71. {
  72. int err;
  73. u8 ret;
  74. ret = _SUCCESS;
  75. addr = RTW_SDIO_ADDR_F0_GEN(addr);
  76. err = d->intf_ops->read(d, addr, buf, len, 0);
  77. if (err) {
  78. RTW_INFO("%s: [ERROR] Read f0 register FAIL!\n", __FUNCTION__);
  79. ret = _FAIL;
  80. }
  81. return ret;
  82. }