hyperbus.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com/
  4. */
  5. #ifndef __LINUX_MTD_HYPERBUS_H__
  6. #define __LINUX_MTD_HYPERBUS_H__
  7. #include <linux/mtd/map.h>
  8. /* HyperBus command bits */
  9. #define HYPERBUS_RW 0x80 /* R/W# */
  10. #define HYPERBUS_RW_WRITE 0
  11. #define HYPERBUS_RW_READ 0x80
  12. #define HYPERBUS_AS 0x40 /* Address Space */
  13. #define HYPERBUS_AS_MEM 0
  14. #define HYPERBUS_AS_REG 0x40
  15. #define HYPERBUS_BT 0x20 /* Burst Type */
  16. #define HYPERBUS_BT_WRAPPED 0
  17. #define HYPERBUS_BT_LINEAR 0x20
  18. enum hyperbus_memtype {
  19. HYPERFLASH,
  20. HYPERRAM,
  21. };
  22. /**
  23. * struct hyperbus_device - struct representing HyperBus slave device
  24. * @map: map_info struct for accessing MMIO HyperBus flash memory
  25. * @np: pointer to HyperBus slave device node
  26. * @mtd: pointer to MTD struct
  27. * @ctlr: pointer to HyperBus controller struct
  28. * @memtype: type of memory device: HyperFlash or HyperRAM
  29. * @priv: pointer to controller specific per device private data
  30. */
  31. struct hyperbus_device {
  32. struct map_info map;
  33. struct device_node *np;
  34. struct mtd_info *mtd;
  35. struct hyperbus_ctlr *ctlr;
  36. enum hyperbus_memtype memtype;
  37. void *priv;
  38. };
  39. /**
  40. * struct hyperbus_ops - struct representing custom HyperBus operations
  41. * @read16: read 16 bit of data from flash in a single burst. Used to read
  42. * from non default address space, such as ID/CFI space
  43. * @write16: write 16 bit of data to flash in a single burst. Used to
  44. * send cmd to flash or write single 16 bit word at a time.
  45. * @copy_from: copy data from flash memory
  46. * @copy_to: copy data to flash memory
  47. * @calibrate: calibrate HyperBus controller
  48. */
  49. struct hyperbus_ops {
  50. u16 (*read16)(struct hyperbus_device *hbdev, unsigned long addr);
  51. void (*write16)(struct hyperbus_device *hbdev,
  52. unsigned long addr, u16 val);
  53. void (*copy_from)(struct hyperbus_device *hbdev, void *to,
  54. unsigned long from, ssize_t len);
  55. void (*copy_to)(struct hyperbus_device *dev, unsigned long to,
  56. const void *from, ssize_t len);
  57. int (*calibrate)(struct hyperbus_device *dev);
  58. };
  59. /**
  60. * struct hyperbus_ctlr - struct representing HyperBus controller
  61. * @dev: pointer to HyperBus controller device
  62. * @calibrated: flag to indicate ctlr calibration sequence is complete
  63. * @ops: HyperBus controller ops
  64. */
  65. struct hyperbus_ctlr {
  66. struct device *dev;
  67. bool calibrated;
  68. const struct hyperbus_ops *ops;
  69. };
  70. /**
  71. * hyperbus_register_device - probe and register a HyperBus slave memory device
  72. * @hbdev: hyperbus_device struct with dev, np and ctlr field populated
  73. *
  74. * Return: 0 for success, others for failure.
  75. */
  76. int hyperbus_register_device(struct hyperbus_device *hbdev);
  77. /**
  78. * hyperbus_unregister_device - deregister HyperBus slave memory device
  79. * @hbdev: hyperbus_device to be unregistered
  80. */
  81. void hyperbus_unregister_device(struct hyperbus_device *hbdev);
  82. #endif /* __LINUX_MTD_HYPERBUS_H__ */