ddbridge-io.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * ddbridge-io.h: Digital Devices bridge I/O inline functions
  3. *
  4. * Copyright (C) 2010-2017 Digital Devices GmbH
  5. * Ralph Metzler <rjkm@metzlerbros.de>
  6. * Marcus Metzler <mocm@metzlerbros.de>
  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 only, as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. */
  18. #ifndef __DDBRIDGE_IO_H__
  19. #define __DDBRIDGE_IO_H__
  20. #include <linux/io.h>
  21. #include "ddbridge.h"
  22. /******************************************************************************/
  23. static inline u32 ddblreadl(struct ddb_link *link, u32 adr)
  24. {
  25. return readl(link->dev->regs + adr);
  26. }
  27. static inline void ddblwritel(struct ddb_link *link, u32 val, u32 adr)
  28. {
  29. writel(val, link->dev->regs + adr);
  30. }
  31. static inline u32 ddbreadl(struct ddb *dev, u32 adr)
  32. {
  33. return readl(dev->regs + adr);
  34. }
  35. static inline void ddbwritel(struct ddb *dev, u32 val, u32 adr)
  36. {
  37. writel(val, dev->regs + adr);
  38. }
  39. static inline void ddbcpyto(struct ddb *dev, u32 adr, void *src, long count)
  40. {
  41. memcpy_toio(dev->regs + adr, src, count);
  42. }
  43. static inline void ddbcpyfrom(struct ddb *dev, void *dst, u32 adr, long count)
  44. {
  45. memcpy_fromio(dst, dev->regs + adr, count);
  46. }
  47. static inline u32 safe_ddbreadl(struct ddb *dev, u32 adr)
  48. {
  49. u32 val = ddbreadl(dev, adr);
  50. /* (ddb)readl returns (uint)-1 (all bits set) on failure, catch that */
  51. if (val == ~0) {
  52. dev_err(&dev->pdev->dev, "ddbreadl failure, adr=%08x\n", adr);
  53. return 0;
  54. }
  55. return val;
  56. }
  57. #endif /* __DDBRIDGE_IO_H__ */