xref: /linux-6.15/include/linux/amba/bus.h (revision ad8d1e32)
1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2a62c80e5SRussell King /*
34e10ae11SLinus Walleij  *  linux/include/amba/bus.h
44e10ae11SLinus Walleij  *
54e10ae11SLinus Walleij  *  This device type deals with ARM PrimeCells and anything else that
64e10ae11SLinus Walleij  *  presents a proper CID (0xB105F00D) at the end of the I/O register
74e10ae11SLinus Walleij  *  region or that is derived from a PrimeCell.
8a62c80e5SRussell King  *
9a62c80e5SRussell King  *  Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved.
10a62c80e5SRussell King  */
11a62c80e5SRussell King #ifndef ASMARM_AMBA_H
12a62c80e5SRussell King #define ASMARM_AMBA_H
13a62c80e5SRussell King 
147cfe2494SRussell King #include <linux/clk.h>
15c36207a4Sviresh kumar #include <linux/device.h>
161e5f9a23SDave Martin #include <linux/mod_devicetable.h>
177cfe2494SRussell King #include <linux/err.h>
18c36207a4Sviresh kumar #include <linux/resource.h>
1965500fa9SLinus Walleij #include <linux/regulator/consumer.h>
20c36207a4Sviresh kumar 
214d8981f6SMichal Simek #define AMBA_NR_IRQS	9
2201723a95SLinus Walleij #define AMBA_CID	0xb105f00d
23a06ae860SPratik Patel #define CORESIGHT_CID	0xb105900d
24a62c80e5SRussell King 
25e85fa28eSMike Leach /*
26e85fa28eSMike Leach  * CoreSight Architecture specification updates the ID specification
27e85fa28eSMike Leach  * for components on the AMBA bus. (ARM IHI 0029E)
28e85fa28eSMike Leach  *
29e85fa28eSMike Leach  * Bits 15:12 of the CID are the device class.
30e85fa28eSMike Leach  *
31e85fa28eSMike Leach  * Class 0xF remains for PrimeCell and legacy components. (AMBA_CID above)
32e85fa28eSMike Leach  * Class 0x9 defines the component as CoreSight (CORESIGHT_CID above)
33e85fa28eSMike Leach  * Class 0x0, 0x1, 0xB, 0xE define components that do not have driver support
34e85fa28eSMike Leach  * at present.
35e85fa28eSMike Leach  * Class 0x2-0x8,0xA and 0xD-0xD are presently reserved.
36e85fa28eSMike Leach  *
37e85fa28eSMike Leach  * Remaining CID bits stay as 0xb105-00d
38e85fa28eSMike Leach  */
39e85fa28eSMike Leach 
40e85fa28eSMike Leach /**
41e85fa28eSMike Leach  * Class 0x9 components use additional values to form a Unique Component
42e85fa28eSMike Leach  * Identifier (UCI), where peripheral ID values are identical for different
43e85fa28eSMike Leach  * components. Passed to the amba bus code from the component driver via
44e85fa28eSMike Leach  * the amba_id->data pointer.
45e85fa28eSMike Leach  * @devarch	: coresight devarch register value
46e85fa28eSMike Leach  * @devarch_mask: mask bits used for matching. 0 indicates UCI not used.
47e85fa28eSMike Leach  * @devtype	: coresight device type value
48e85fa28eSMike Leach  * @data	: additional driver data. As we have usurped the original
49e85fa28eSMike Leach  *		pointer some devices may still need additional data
50e85fa28eSMike Leach  */
51e85fa28eSMike Leach struct amba_cs_uci_id {
52e85fa28eSMike Leach 	unsigned int devarch;
53e85fa28eSMike Leach 	unsigned int devarch_mask;
54e85fa28eSMike Leach 	unsigned int devtype;
55e85fa28eSMike Leach 	void *data;
56e85fa28eSMike Leach };
57e85fa28eSMike Leach 
584a2910faSMike Leach /* define offsets for registers used by UCI */
594a2910faSMike Leach #define UCI_REG_DEVTYPE_OFFSET	0xFCC
604a2910faSMike Leach #define UCI_REG_DEVARCH_OFFSET	0xFBC
614a2910faSMike Leach 
627cfe2494SRussell King struct clk;
637cfe2494SRussell King 
64a62c80e5SRussell King struct amba_device {
65a62c80e5SRussell King 	struct device		dev;
66a62c80e5SRussell King 	struct resource		res;
677cfe2494SRussell King 	struct clk		*pclk;
68f4584884SUlf Hansson 	struct device_dma_parameters dma_parms;
69a62c80e5SRussell King 	unsigned int		periphid;
7025af7406SIsaac Manjarres 	struct mutex		periphid_lock;
714a2910faSMike Leach 	unsigned int		cid;
724a2910faSMike Leach 	struct amba_cs_uci_id	uci;
73a62c80e5SRussell King 	unsigned int		irq[AMBA_NR_IRQS];
746e679550SKrzysztof Kozlowski 	/*
756e679550SKrzysztof Kozlowski 	 * Driver name to force a match.  Do not set directly, because core
766e679550SKrzysztof Kozlowski 	 * frees it.  Use driver_set_override() to set or clear it.
776e679550SKrzysztof Kozlowski 	 */
786e679550SKrzysztof Kozlowski 	const char		*driver_override;
79a62c80e5SRussell King };
80a62c80e5SRussell King 
81a62c80e5SRussell King struct amba_driver {
82a62c80e5SRussell King 	struct device_driver	drv;
83aa25afadSRussell King 	int			(*probe)(struct amba_device *, const struct amba_id *);
843fd269e7SUwe Kleine-König 	void			(*remove)(struct amba_device *);
85a62c80e5SRussell King 	void			(*shutdown)(struct amba_device *);
862d00880fSRussell King 	const struct amba_id	*id_table;
87512881eaSLu Baolu 	/*
88512881eaSLu Baolu 	 * For most device drivers, no need to care about this flag as long as
89512881eaSLu Baolu 	 * all DMAs are handled through the kernel DMA API. For some special
90512881eaSLu Baolu 	 * ones, for example VFIO drivers, they know how to manage the DMA
91512881eaSLu Baolu 	 * themselves and set this flag so that the IOMMU layer will allow them
92512881eaSLu Baolu 	 * to setup and manage their own I/O address space.
93512881eaSLu Baolu 	 */
94512881eaSLu Baolu 	bool driver_managed_dma;
95a62c80e5SRussell King };
96a62c80e5SRussell King 
97db4fa45eSAnders Berg /*
98db4fa45eSAnders Berg  * Constants for the designer field of the Peripheral ID register. When bit 7
99db4fa45eSAnders Berg  * is set to '1', bits [6:0] should be the JEP106 manufacturer identity code.
100db4fa45eSAnders Berg  */
101f17a1f06SLinus Walleij enum amba_vendor {
102f17a1f06SLinus Walleij 	AMBA_VENDOR_ARM = 0x41,
103f17a1f06SLinus Walleij 	AMBA_VENDOR_ST = 0x80,
104fbebf597Ssrinik 	AMBA_VENDOR_QCOM = 0x51,
105db4fa45eSAnders Berg 	AMBA_VENDOR_LSI = 0xb6,
106f17a1f06SLinus Walleij };
107f17a1f06SLinus Walleij 
108a4d398a5SKunwu Chan extern const struct bus_type amba_bustype;
109394d5aefSRob Herring 
110ab7f17fbSPrathu Baronia #define to_amba_device(d)	container_of_const(d, struct amba_device, dev)
111ba74ec7fSRabin Vincent 
112a62c80e5SRussell King #define amba_get_drvdata(d)	dev_get_drvdata(&d->dev)
113a62c80e5SRussell King #define amba_set_drvdata(d,p)	dev_set_drvdata(&d->dev, p)
114a62c80e5SRussell King 
1155677b17cSKrzysztof Kozlowski /*
1165677b17cSKrzysztof Kozlowski  * use a macro to avoid include chaining to get THIS_MODULE
1175677b17cSKrzysztof Kozlowski  */
1185677b17cSKrzysztof Kozlowski #define amba_driver_register(drv) \
1195677b17cSKrzysztof Kozlowski 	__amba_driver_register(drv, THIS_MODULE)
1205677b17cSKrzysztof Kozlowski 
1213b49dfb0SJason Gunthorpe #ifdef CONFIG_ARM_AMBA
1225677b17cSKrzysztof Kozlowski int __amba_driver_register(struct amba_driver *, struct module *);
123a62c80e5SRussell King void amba_driver_unregister(struct amba_driver *);
124*ad8d1e32SKunwu Chan bool dev_is_amba(const struct device *dev);
1253b49dfb0SJason Gunthorpe #else
__amba_driver_register(struct amba_driver * drv,struct module * owner)1265677b17cSKrzysztof Kozlowski static inline int __amba_driver_register(struct amba_driver *drv,
1275677b17cSKrzysztof Kozlowski 					 struct module *owner)
1283b49dfb0SJason Gunthorpe {
1293b49dfb0SJason Gunthorpe 	return -EINVAL;
1303b49dfb0SJason Gunthorpe }
amba_driver_unregister(struct amba_driver * drv)1313b49dfb0SJason Gunthorpe static inline void amba_driver_unregister(struct amba_driver *drv)
1323b49dfb0SJason Gunthorpe {
1333b49dfb0SJason Gunthorpe }
dev_is_amba(const struct device * dev)134*ad8d1e32SKunwu Chan static inline bool dev_is_amba(const struct device *dev)
135*ad8d1e32SKunwu Chan {
136*ad8d1e32SKunwu Chan 	return false;
137*ad8d1e32SKunwu Chan }
1383b49dfb0SJason Gunthorpe #endif
1393b49dfb0SJason Gunthorpe 
140d5dc9271SRussell King struct amba_device *amba_device_alloc(const char *, resource_size_t, size_t);
141d5dc9271SRussell King void amba_device_put(struct amba_device *);
142d5dc9271SRussell King int amba_device_add(struct amba_device *, struct resource *);
143a62c80e5SRussell King int amba_device_register(struct amba_device *, struct resource *);
144a62c80e5SRussell King void amba_device_unregister(struct amba_device *);
145a62c80e5SRussell King int amba_request_regions(struct amba_device *, const char *);
146a62c80e5SRussell King void amba_release_regions(struct amba_device *);
147a62c80e5SRussell King 
14801723a95SLinus Walleij /* Some drivers don't use the struct amba_device */
14901723a95SLinus Walleij #define AMBA_CONFIG_BITS(a) (((a) >> 24) & 0xff)
15001723a95SLinus Walleij #define AMBA_REV_BITS(a) (((a) >> 20) & 0x0f)
15101723a95SLinus Walleij #define AMBA_MANF_BITS(a) (((a) >> 12) & 0xff)
15201723a95SLinus Walleij #define AMBA_PART_BITS(a) ((a) & 0xfff)
15301723a95SLinus Walleij 
15401723a95SLinus Walleij #define amba_config(d)	AMBA_CONFIG_BITS((d)->periphid)
15501723a95SLinus Walleij #define amba_rev(d)	AMBA_REV_BITS((d)->periphid)
15601723a95SLinus Walleij #define amba_manf(d)	AMBA_MANF_BITS((d)->periphid)
15701723a95SLinus Walleij #define amba_part(d)	AMBA_PART_BITS((d)->periphid)
158a62c80e5SRussell King 
159cc6e75afSRussell King #define __AMBA_DEV(busid, data, mask)				\
160cc6e75afSRussell King 	{							\
161cc6e75afSRussell King 		.coherent_dma_mask = mask,			\
162cc6e75afSRussell King 		.init_name = busid,				\
163cc6e75afSRussell King 		.platform_data = data,				\
164cc6e75afSRussell King 	}
165cc6e75afSRussell King 
166cc6e75afSRussell King /*
167cc6e75afSRussell King  * APB devices do not themselves have the ability to address memory,
168cc6e75afSRussell King  * so DMA masks should be zero (much like USB peripheral devices.)
169cc6e75afSRussell King  * The DMA controller DMA masks should be used instead (much like
170cc6e75afSRussell King  * USB host controllers in conventional PCs.)
171cc6e75afSRussell King  */
172cc6e75afSRussell King #define AMBA_APB_DEVICE(name, busid, id, base, irqs, data)	\
173cc6e75afSRussell King struct amba_device name##_device = {				\
174cc6e75afSRussell King 	.dev = __AMBA_DEV(busid, data, 0),			\
175cc6e75afSRussell King 	.res = DEFINE_RES_MEM(base, SZ_4K),			\
176cc6e75afSRussell King 	.irq = irqs,						\
177cc6e75afSRussell King 	.periphid = id,						\
178cc6e75afSRussell King }
179cc6e75afSRussell King 
180cc6e75afSRussell King /*
181cc6e75afSRussell King  * AHB devices are DMA capable, so set their DMA masks
182cc6e75afSRussell King  */
183cc6e75afSRussell King #define AMBA_AHB_DEVICE(name, busid, id, base, irqs, data)	\
184cc6e75afSRussell King struct amba_device name##_device = {				\
185cc6e75afSRussell King 	.dev = __AMBA_DEV(busid, data, ~0ULL),			\
186cc6e75afSRussell King 	.res = DEFINE_RES_MEM(base, SZ_4K),			\
187cc6e75afSRussell King 	.irq = irqs,						\
188cc6e75afSRussell King 	.periphid = id,						\
189cc6e75afSRussell King }
190cc6e75afSRussell King 
1919e5ed094Sviresh kumar /*
1929e5ed094Sviresh kumar  * module_amba_driver() - Helper macro for drivers that don't do anything
1939e5ed094Sviresh kumar  * special in module init/exit.  This eliminates a lot of boilerplate.  Each
1949e5ed094Sviresh kumar  * module may only use this macro once, and calling it replaces module_init()
1959e5ed094Sviresh kumar  * and module_exit()
1969e5ed094Sviresh kumar  */
1979e5ed094Sviresh kumar #define module_amba_driver(__amba_drv) \
1989e5ed094Sviresh kumar 	module_driver(__amba_drv, amba_driver_register, amba_driver_unregister)
1999e5ed094Sviresh kumar 
200941943cfSPaul Gortmaker /*
201941943cfSPaul Gortmaker  * builtin_amba_driver() - Helper macro for drivers that don't do anything
202941943cfSPaul Gortmaker  * special in driver initcall.  This eliminates a lot of boilerplate.  Each
203941943cfSPaul Gortmaker  * driver may only use this macro once, and calling it replaces the instance
204941943cfSPaul Gortmaker  * device_initcall().
205941943cfSPaul Gortmaker  */
206941943cfSPaul Gortmaker #define builtin_amba_driver(__amba_drv) \
207941943cfSPaul Gortmaker 	builtin_driver(__amba_drv, amba_driver_register)
208941943cfSPaul Gortmaker 
209a62c80e5SRussell King #endif
210