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