xref: /linux-6.15/include/linux/mtd/hyperbus.h (revision 0c90466a)
1dcc7d344SVignesh Raghavendra /* SPDX-License-Identifier: GPL-2.0
2dcc7d344SVignesh Raghavendra  *
3614a895fSAlexander A. Klimov  * Copyright (C) 2019 Texas Instruments Incorporated - https://www.ti.com/
4dcc7d344SVignesh Raghavendra  */
5dcc7d344SVignesh Raghavendra 
6dcc7d344SVignesh Raghavendra #ifndef __LINUX_MTD_HYPERBUS_H__
7dcc7d344SVignesh Raghavendra #define __LINUX_MTD_HYPERBUS_H__
8dcc7d344SVignesh Raghavendra 
9dcc7d344SVignesh Raghavendra #include <linux/mtd/map.h>
10dcc7d344SVignesh Raghavendra 
115de15b61SSergei Shtylyov /* HyperBus command bits */
125de15b61SSergei Shtylyov #define HYPERBUS_RW	0x80	/* R/W# */
135de15b61SSergei Shtylyov #define HYPERBUS_RW_WRITE 0
145de15b61SSergei Shtylyov #define HYPERBUS_RW_READ 0x80
155de15b61SSergei Shtylyov #define HYPERBUS_AS	0x40	/* Address Space */
165de15b61SSergei Shtylyov #define HYPERBUS_AS_MEM	0
175de15b61SSergei Shtylyov #define HYPERBUS_AS_REG	0x40
185de15b61SSergei Shtylyov #define HYPERBUS_BT	0x20	/* Burst Type */
195de15b61SSergei Shtylyov #define HYPERBUS_BT_WRAPPED 0
205de15b61SSergei Shtylyov #define HYPERBUS_BT_LINEAR 0x20
215de15b61SSergei Shtylyov 
22dcc7d344SVignesh Raghavendra enum hyperbus_memtype {
23dcc7d344SVignesh Raghavendra 	HYPERFLASH,
24dcc7d344SVignesh Raghavendra 	HYPERRAM,
25dcc7d344SVignesh Raghavendra };
26dcc7d344SVignesh Raghavendra 
27dcc7d344SVignesh Raghavendra /**
28dcc7d344SVignesh Raghavendra  * struct hyperbus_device - struct representing HyperBus slave device
29dcc7d344SVignesh Raghavendra  * @map: map_info struct for accessing MMIO HyperBus flash memory
30dcc7d344SVignesh Raghavendra  * @np: pointer to HyperBus slave device node
31dcc7d344SVignesh Raghavendra  * @mtd: pointer to MTD struct
32dcc7d344SVignesh Raghavendra  * @ctlr: pointer to HyperBus controller struct
33dcc7d344SVignesh Raghavendra  * @memtype: type of memory device: HyperFlash or HyperRAM
34714fb2fbSVignesh Raghavendra  * @priv: pointer to controller specific per device private data
35dcc7d344SVignesh Raghavendra  */
36dcc7d344SVignesh Raghavendra 
37dcc7d344SVignesh Raghavendra struct hyperbus_device {
38dcc7d344SVignesh Raghavendra 	struct map_info map;
39dcc7d344SVignesh Raghavendra 	struct device_node *np;
40dcc7d344SVignesh Raghavendra 	struct mtd_info *mtd;
41dcc7d344SVignesh Raghavendra 	struct hyperbus_ctlr *ctlr;
42dcc7d344SVignesh Raghavendra 	enum hyperbus_memtype memtype;
43714fb2fbSVignesh Raghavendra 	void *priv;
44dcc7d344SVignesh Raghavendra };
45dcc7d344SVignesh Raghavendra 
46dcc7d344SVignesh Raghavendra /**
47dcc7d344SVignesh Raghavendra  * struct hyperbus_ops - struct representing custom HyperBus operations
48dcc7d344SVignesh Raghavendra  * @read16: read 16 bit of data from flash in a single burst. Used to read
49dcc7d344SVignesh Raghavendra  *          from non default address space, such as ID/CFI space
50dcc7d344SVignesh Raghavendra  * @write16: write 16 bit of data to flash in a single burst. Used to
51dcc7d344SVignesh Raghavendra  *           send cmd to flash or write single 16 bit word at a time.
52dcc7d344SVignesh Raghavendra  * @copy_from: copy data from flash memory
53dcc7d344SVignesh Raghavendra  * @copy_to: copy data to flash memory
54dcc7d344SVignesh Raghavendra  * @calibrate: calibrate HyperBus controller
55dcc7d344SVignesh Raghavendra  */
56dcc7d344SVignesh Raghavendra 
57dcc7d344SVignesh Raghavendra struct hyperbus_ops {
58dcc7d344SVignesh Raghavendra 	u16 (*read16)(struct hyperbus_device *hbdev, unsigned long addr);
59dcc7d344SVignesh Raghavendra 	void (*write16)(struct hyperbus_device *hbdev,
60dcc7d344SVignesh Raghavendra 			unsigned long addr, u16 val);
61dcc7d344SVignesh Raghavendra 	void (*copy_from)(struct hyperbus_device *hbdev, void *to,
62dcc7d344SVignesh Raghavendra 			  unsigned long from, ssize_t len);
63dcc7d344SVignesh Raghavendra 	void (*copy_to)(struct hyperbus_device *dev, unsigned long to,
64dcc7d344SVignesh Raghavendra 			const void *from, ssize_t len);
65dcc7d344SVignesh Raghavendra 	int (*calibrate)(struct hyperbus_device *dev);
66dcc7d344SVignesh Raghavendra };
67dcc7d344SVignesh Raghavendra 
68dcc7d344SVignesh Raghavendra /**
69dcc7d344SVignesh Raghavendra  * struct hyperbus_ctlr - struct representing HyperBus controller
70dcc7d344SVignesh Raghavendra  * @dev: pointer to HyperBus controller device
71dcc7d344SVignesh Raghavendra  * @calibrated: flag to indicate ctlr calibration sequence is complete
72dcc7d344SVignesh Raghavendra  * @ops: HyperBus controller ops
73dcc7d344SVignesh Raghavendra  */
74dcc7d344SVignesh Raghavendra struct hyperbus_ctlr {
75dcc7d344SVignesh Raghavendra 	struct device *dev;
76dcc7d344SVignesh Raghavendra 	bool calibrated;
77dcc7d344SVignesh Raghavendra 
78dcc7d344SVignesh Raghavendra 	const struct hyperbus_ops *ops;
79dcc7d344SVignesh Raghavendra };
80dcc7d344SVignesh Raghavendra 
81dcc7d344SVignesh Raghavendra /**
82dcc7d344SVignesh Raghavendra  * hyperbus_register_device - probe and register a HyperBus slave memory device
83dcc7d344SVignesh Raghavendra  * @hbdev: hyperbus_device struct with dev, np and ctlr field populated
84dcc7d344SVignesh Raghavendra  *
85dcc7d344SVignesh Raghavendra  * Return: 0 for success, others for failure.
86dcc7d344SVignesh Raghavendra  */
87dcc7d344SVignesh Raghavendra int hyperbus_register_device(struct hyperbus_device *hbdev);
88dcc7d344SVignesh Raghavendra 
89dcc7d344SVignesh Raghavendra /**
90dcc7d344SVignesh Raghavendra  * hyperbus_unregister_device - deregister HyperBus slave memory device
91dcc7d344SVignesh Raghavendra  * @hbdev: hyperbus_device to be unregistered
92dcc7d344SVignesh Raghavendra  */
93*0c90466aSUwe Kleine-König void hyperbus_unregister_device(struct hyperbus_device *hbdev);
94dcc7d344SVignesh Raghavendra 
95dcc7d344SVignesh Raghavendra #endif /* __LINUX_MTD_HYPERBUS_H__ */
96