xref: /linux-6.15/include/linux/mtd/hyperbus.h (revision 714fb2fb)
1 /* SPDX-License-Identifier: GPL-2.0
2  *
3  * Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com/
4  */
5 
6 #ifndef __LINUX_MTD_HYPERBUS_H__
7 #define __LINUX_MTD_HYPERBUS_H__
8 
9 #include <linux/mtd/map.h>
10 
11 enum hyperbus_memtype {
12 	HYPERFLASH,
13 	HYPERRAM,
14 };
15 
16 /**
17  * struct hyperbus_device - struct representing HyperBus slave device
18  * @map: map_info struct for accessing MMIO HyperBus flash memory
19  * @np: pointer to HyperBus slave device node
20  * @mtd: pointer to MTD struct
21  * @ctlr: pointer to HyperBus controller struct
22  * @memtype: type of memory device: HyperFlash or HyperRAM
23  * @priv: pointer to controller specific per device private data
24  */
25 
26 struct hyperbus_device {
27 	struct map_info map;
28 	struct device_node *np;
29 	struct mtd_info *mtd;
30 	struct hyperbus_ctlr *ctlr;
31 	enum hyperbus_memtype memtype;
32 	void *priv;
33 };
34 
35 /**
36  * struct hyperbus_ops - struct representing custom HyperBus operations
37  * @read16: read 16 bit of data from flash in a single burst. Used to read
38  *          from non default address space, such as ID/CFI space
39  * @write16: write 16 bit of data to flash in a single burst. Used to
40  *           send cmd to flash or write single 16 bit word at a time.
41  * @copy_from: copy data from flash memory
42  * @copy_to: copy data to flash memory
43  * @calibrate: calibrate HyperBus controller
44  */
45 
46 struct hyperbus_ops {
47 	u16 (*read16)(struct hyperbus_device *hbdev, unsigned long addr);
48 	void (*write16)(struct hyperbus_device *hbdev,
49 			unsigned long addr, u16 val);
50 	void (*copy_from)(struct hyperbus_device *hbdev, void *to,
51 			  unsigned long from, ssize_t len);
52 	void (*copy_to)(struct hyperbus_device *dev, unsigned long to,
53 			const void *from, ssize_t len);
54 	int (*calibrate)(struct hyperbus_device *dev);
55 };
56 
57 /**
58  * struct hyperbus_ctlr - struct representing HyperBus controller
59  * @dev: pointer to HyperBus controller device
60  * @calibrated: flag to indicate ctlr calibration sequence is complete
61  * @ops: HyperBus controller ops
62  */
63 struct hyperbus_ctlr {
64 	struct device *dev;
65 	bool calibrated;
66 
67 	const struct hyperbus_ops *ops;
68 };
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 /**
79  * hyperbus_unregister_device - deregister HyperBus slave memory device
80  * @hbdev: hyperbus_device to be unregistered
81  *
82  * Return: 0 for success, others for failure.
83  */
84 int hyperbus_unregister_device(struct hyperbus_device *hbdev);
85 
86 #endif /* __LINUX_MTD_HYPERBUS_H__ */
87