brcmnand.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright © 2015 Broadcom Corporation
  4. */
  5. #ifndef __BRCMNAND_H__
  6. #define __BRCMNAND_H__
  7. #include <linux/types.h>
  8. #include <linux/io.h>
  9. struct platform_device;
  10. struct dev_pm_ops;
  11. struct brcmnand_io_ops;
  12. /* Special register offset constant to intercept a non-MMIO access
  13. * to the flash cache register space. This is intentionally large
  14. * not to overlap with an existing offset.
  15. */
  16. #define BRCMNAND_NON_MMIO_FC_ADDR 0xffffffff
  17. struct brcmnand_soc {
  18. bool (*ctlrdy_ack)(struct brcmnand_soc *soc);
  19. void (*ctlrdy_set_enabled)(struct brcmnand_soc *soc, bool en);
  20. void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare,
  21. bool is_param);
  22. const struct brcmnand_io_ops *ops;
  23. };
  24. struct brcmnand_io_ops {
  25. u32 (*read_reg)(struct brcmnand_soc *soc, u32 offset);
  26. void (*write_reg)(struct brcmnand_soc *soc, u32 val, u32 offset);
  27. };
  28. static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc,
  29. bool is_param)
  30. {
  31. if (soc && soc->prepare_data_bus)
  32. soc->prepare_data_bus(soc, true, is_param);
  33. }
  34. static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc,
  35. bool is_param)
  36. {
  37. if (soc && soc->prepare_data_bus)
  38. soc->prepare_data_bus(soc, false, is_param);
  39. }
  40. static inline u32 brcmnand_readl(void __iomem *addr)
  41. {
  42. /*
  43. * MIPS endianness is configured by boot strap, which also reverses all
  44. * bus endianness (i.e., big-endian CPU + big endian bus ==> native
  45. * endian I/O).
  46. *
  47. * Other architectures (e.g., ARM) either do not support big endian, or
  48. * else leave I/O in little endian mode.
  49. */
  50. if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
  51. return __raw_readl(addr);
  52. else
  53. return readl_relaxed(addr);
  54. }
  55. static inline void brcmnand_writel(u32 val, void __iomem *addr)
  56. {
  57. /* See brcmnand_readl() comments */
  58. if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN))
  59. __raw_writel(val, addr);
  60. else
  61. writel_relaxed(val, addr);
  62. }
  63. static inline bool brcmnand_soc_has_ops(struct brcmnand_soc *soc)
  64. {
  65. return soc && soc->ops && soc->ops->read_reg && soc->ops->write_reg;
  66. }
  67. static inline u32 brcmnand_soc_read(struct brcmnand_soc *soc, u32 offset)
  68. {
  69. return soc->ops->read_reg(soc, offset);
  70. }
  71. static inline void brcmnand_soc_write(struct brcmnand_soc *soc, u32 val,
  72. u32 offset)
  73. {
  74. soc->ops->write_reg(soc, val, offset);
  75. }
  76. int brcmnand_probe(struct platform_device *pdev, struct brcmnand_soc *soc);
  77. int brcmnand_remove(struct platform_device *pdev);
  78. extern const struct dev_pm_ops brcmnand_pm_ops;
  79. #endif /* __BRCMNAND_H__ */