Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  *  linux/include/amba/bus.h
0004  *
0005  *  This device type deals with ARM PrimeCells and anything else that
0006  *  presents a proper CID (0xB105F00D) at the end of the I/O register
0007  *  region or that is derived from a PrimeCell.
0008  *
0009  *  Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved.
0010  */
0011 #ifndef ASMARM_AMBA_H
0012 #define ASMARM_AMBA_H
0013 
0014 #include <linux/clk.h>
0015 #include <linux/device.h>
0016 #include <linux/mod_devicetable.h>
0017 #include <linux/err.h>
0018 #include <linux/resource.h>
0019 #include <linux/regulator/consumer.h>
0020 
0021 #define AMBA_NR_IRQS    9
0022 #define AMBA_CID    0xb105f00d
0023 #define CORESIGHT_CID   0xb105900d
0024 
0025 /*
0026  * CoreSight Architecture specification updates the ID specification
0027  * for components on the AMBA bus. (ARM IHI 0029E)
0028  *
0029  * Bits 15:12 of the CID are the device class.
0030  *
0031  * Class 0xF remains for PrimeCell and legacy components. (AMBA_CID above)
0032  * Class 0x9 defines the component as CoreSight (CORESIGHT_CID above)
0033  * Class 0x0, 0x1, 0xB, 0xE define components that do not have driver support
0034  * at present.
0035  * Class 0x2-0x8,0xA and 0xD-0xD are presently reserved.
0036  *
0037  * Remaining CID bits stay as 0xb105-00d
0038  */
0039 
0040 /**
0041  * Class 0x9 components use additional values to form a Unique Component
0042  * Identifier (UCI), where peripheral ID values are identical for different
0043  * components. Passed to the amba bus code from the component driver via
0044  * the amba_id->data pointer.
0045  * @devarch : coresight devarch register value
0046  * @devarch_mask: mask bits used for matching. 0 indicates UCI not used.
0047  * @devtype : coresight device type value
0048  * @data    : additional driver data. As we have usurped the original
0049  *      pointer some devices may still need additional data
0050  */
0051 struct amba_cs_uci_id {
0052     unsigned int devarch;
0053     unsigned int devarch_mask;
0054     unsigned int devtype;
0055     void *data;
0056 };
0057 
0058 /* define offsets for registers used by UCI */
0059 #define UCI_REG_DEVTYPE_OFFSET  0xFCC
0060 #define UCI_REG_DEVARCH_OFFSET  0xFBC
0061 
0062 struct clk;
0063 
0064 struct amba_device {
0065     struct device       dev;
0066     struct resource     res;
0067     struct clk      *pclk;
0068     struct device_dma_parameters dma_parms;
0069     unsigned int        periphid;
0070     struct mutex        periphid_lock;
0071     unsigned int        cid;
0072     struct amba_cs_uci_id   uci;
0073     unsigned int        irq[AMBA_NR_IRQS];
0074     /*
0075      * Driver name to force a match.  Do not set directly, because core
0076      * frees it.  Use driver_set_override() to set or clear it.
0077      */
0078     const char      *driver_override;
0079 };
0080 
0081 struct amba_driver {
0082     struct device_driver    drv;
0083     int         (*probe)(struct amba_device *, const struct amba_id *);
0084     void            (*remove)(struct amba_device *);
0085     void            (*shutdown)(struct amba_device *);
0086     const struct amba_id    *id_table;
0087     /*
0088      * For most device drivers, no need to care about this flag as long as
0089      * all DMAs are handled through the kernel DMA API. For some special
0090      * ones, for example VFIO drivers, they know how to manage the DMA
0091      * themselves and set this flag so that the IOMMU layer will allow them
0092      * to setup and manage their own I/O address space.
0093      */
0094     bool driver_managed_dma;
0095 };
0096 
0097 /*
0098  * Constants for the designer field of the Peripheral ID register. When bit 7
0099  * is set to '1', bits [6:0] should be the JEP106 manufacturer identity code.
0100  */
0101 enum amba_vendor {
0102     AMBA_VENDOR_ARM = 0x41,
0103     AMBA_VENDOR_ST = 0x80,
0104     AMBA_VENDOR_QCOM = 0x51,
0105     AMBA_VENDOR_LSI = 0xb6,
0106 };
0107 
0108 extern struct bus_type amba_bustype;
0109 
0110 #define to_amba_device(d)   container_of(d, struct amba_device, dev)
0111 
0112 #define amba_get_drvdata(d) dev_get_drvdata(&d->dev)
0113 #define amba_set_drvdata(d,p)   dev_set_drvdata(&d->dev, p)
0114 
0115 #ifdef CONFIG_ARM_AMBA
0116 int amba_driver_register(struct amba_driver *);
0117 void amba_driver_unregister(struct amba_driver *);
0118 #else
0119 static inline int amba_driver_register(struct amba_driver *drv)
0120 {
0121     return -EINVAL;
0122 }
0123 static inline void amba_driver_unregister(struct amba_driver *drv)
0124 {
0125 }
0126 #endif
0127 
0128 struct amba_device *amba_device_alloc(const char *, resource_size_t, size_t);
0129 void amba_device_put(struct amba_device *);
0130 int amba_device_add(struct amba_device *, struct resource *);
0131 int amba_device_register(struct amba_device *, struct resource *);
0132 void amba_device_unregister(struct amba_device *);
0133 int amba_request_regions(struct amba_device *, const char *);
0134 void amba_release_regions(struct amba_device *);
0135 
0136 /* Some drivers don't use the struct amba_device */
0137 #define AMBA_CONFIG_BITS(a) (((a) >> 24) & 0xff)
0138 #define AMBA_REV_BITS(a) (((a) >> 20) & 0x0f)
0139 #define AMBA_MANF_BITS(a) (((a) >> 12) & 0xff)
0140 #define AMBA_PART_BITS(a) ((a) & 0xfff)
0141 
0142 #define amba_config(d)  AMBA_CONFIG_BITS((d)->periphid)
0143 #define amba_rev(d) AMBA_REV_BITS((d)->periphid)
0144 #define amba_manf(d)    AMBA_MANF_BITS((d)->periphid)
0145 #define amba_part(d)    AMBA_PART_BITS((d)->periphid)
0146 
0147 #define __AMBA_DEV(busid, data, mask)               \
0148     {                           \
0149         .coherent_dma_mask = mask,          \
0150         .init_name = busid,             \
0151         .platform_data = data,              \
0152     }
0153 
0154 /*
0155  * APB devices do not themselves have the ability to address memory,
0156  * so DMA masks should be zero (much like USB peripheral devices.)
0157  * The DMA controller DMA masks should be used instead (much like
0158  * USB host controllers in conventional PCs.)
0159  */
0160 #define AMBA_APB_DEVICE(name, busid, id, base, irqs, data)  \
0161 struct amba_device name##_device = {                \
0162     .dev = __AMBA_DEV(busid, data, 0),          \
0163     .res = DEFINE_RES_MEM(base, SZ_4K),         \
0164     .irq = irqs,                        \
0165     .periphid = id,                     \
0166 }
0167 
0168 /*
0169  * AHB devices are DMA capable, so set their DMA masks
0170  */
0171 #define AMBA_AHB_DEVICE(name, busid, id, base, irqs, data)  \
0172 struct amba_device name##_device = {                \
0173     .dev = __AMBA_DEV(busid, data, ~0ULL),          \
0174     .res = DEFINE_RES_MEM(base, SZ_4K),         \
0175     .irq = irqs,                        \
0176     .periphid = id,                     \
0177 }
0178 
0179 /*
0180  * module_amba_driver() - Helper macro for drivers that don't do anything
0181  * special in module init/exit.  This eliminates a lot of boilerplate.  Each
0182  * module may only use this macro once, and calling it replaces module_init()
0183  * and module_exit()
0184  */
0185 #define module_amba_driver(__amba_drv) \
0186     module_driver(__amba_drv, amba_driver_register, amba_driver_unregister)
0187 
0188 /*
0189  * builtin_amba_driver() - Helper macro for drivers that don't do anything
0190  * special in driver initcall.  This eliminates a lot of boilerplate.  Each
0191  * driver may only use this macro once, and calling it replaces the instance
0192  * device_initcall().
0193  */
0194 #define builtin_amba_driver(__amba_drv) \
0195     builtin_driver(__amba_drv, amba_driver_register)
0196 
0197 #endif