xref: /openbmc/linux/arch/arm/include/asm/cti.h (revision 498495dba268b20e8eadd7fe93c140c68b6cc9d2)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
214eec97fSMing Lei #ifndef __ASMARM_CTI_H
314eec97fSMing Lei #define __ASMARM_CTI_H
414eec97fSMing Lei 
514eec97fSMing Lei #include	<asm/io.h>
602051eadSDietmar Eggemann #include	<asm/hardware/coresight.h>
714eec97fSMing Lei 
814eec97fSMing Lei /* The registers' definition is from section 3.2 of
914eec97fSMing Lei  * Embedded Cross Trigger Revision: r0p0
1014eec97fSMing Lei  */
1114eec97fSMing Lei #define		CTICONTROL		0x000
1214eec97fSMing Lei #define		CTISTATUS		0x004
1314eec97fSMing Lei #define		CTILOCK			0x008
1414eec97fSMing Lei #define		CTIPROTECTION		0x00C
1514eec97fSMing Lei #define		CTIINTACK		0x010
1614eec97fSMing Lei #define		CTIAPPSET		0x014
1714eec97fSMing Lei #define		CTIAPPCLEAR		0x018
1814eec97fSMing Lei #define		CTIAPPPULSE		0x01c
1914eec97fSMing Lei #define		CTIINEN			0x020
2014eec97fSMing Lei #define		CTIOUTEN		0x0A0
2114eec97fSMing Lei #define		CTITRIGINSTATUS		0x130
2214eec97fSMing Lei #define		CTITRIGOUTSTATUS	0x134
2314eec97fSMing Lei #define		CTICHINSTATUS		0x138
2414eec97fSMing Lei #define		CTICHOUTSTATUS		0x13c
2514eec97fSMing Lei #define		CTIPERIPHID0		0xFE0
2614eec97fSMing Lei #define		CTIPERIPHID1		0xFE4
2714eec97fSMing Lei #define		CTIPERIPHID2		0xFE8
2814eec97fSMing Lei #define		CTIPERIPHID3		0xFEC
2914eec97fSMing Lei #define		CTIPCELLID0		0xFF0
3014eec97fSMing Lei #define		CTIPCELLID1		0xFF4
3114eec97fSMing Lei #define		CTIPCELLID2		0xFF8
3214eec97fSMing Lei #define		CTIPCELLID3		0xFFC
3314eec97fSMing Lei 
3414eec97fSMing Lei /* The below are from section 3.6.4 of
3514eec97fSMing Lei  * CoreSight v1.0 Architecture Specification
3614eec97fSMing Lei  */
3714eec97fSMing Lei #define		LOCKACCESS		0xFB0
3814eec97fSMing Lei #define		LOCKSTATUS		0xFB4
3914eec97fSMing Lei 
4014eec97fSMing Lei /**
4114eec97fSMing Lei  * struct cti - cross trigger interface struct
4214eec97fSMing Lei  * @base: mapped virtual address for the cti base
4314eec97fSMing Lei  * @irq: irq number for the cti
4414eec97fSMing Lei  * @trig_out_for_irq: triger out number which will cause
4514eec97fSMing Lei  *	the @irq happen
4614eec97fSMing Lei  *
4714eec97fSMing Lei  * cti struct used to operate cti registers.
4814eec97fSMing Lei  */
4914eec97fSMing Lei struct cti {
5014eec97fSMing Lei 	void __iomem *base;
5114eec97fSMing Lei 	int irq;
5214eec97fSMing Lei 	int trig_out_for_irq;
5314eec97fSMing Lei };
5414eec97fSMing Lei 
5514eec97fSMing Lei /**
5614eec97fSMing Lei  * cti_init - initialize the cti instance
5714eec97fSMing Lei  * @cti: cti instance
5814eec97fSMing Lei  * @base: mapped virtual address for the cti base
5914eec97fSMing Lei  * @irq: irq number for the cti
6014eec97fSMing Lei  * @trig_out: triger out number which will cause
6114eec97fSMing Lei  *	the @irq happen
6214eec97fSMing Lei  *
6314eec97fSMing Lei  * called by machine code to pass the board dependent
6414eec97fSMing Lei  * @base, @irq and @trig_out to cti.
6514eec97fSMing Lei  */
cti_init(struct cti * cti,void __iomem * base,int irq,int trig_out)6614eec97fSMing Lei static inline void cti_init(struct cti *cti,
6714eec97fSMing Lei 	void __iomem *base, int irq, int trig_out)
6814eec97fSMing Lei {
6914eec97fSMing Lei 	cti->base = base;
7014eec97fSMing Lei 	cti->irq  = irq;
7114eec97fSMing Lei 	cti->trig_out_for_irq = trig_out;
7214eec97fSMing Lei }
7314eec97fSMing Lei 
7414eec97fSMing Lei /**
7514eec97fSMing Lei  * cti_map_trigger - use the @chan to map @trig_in to @trig_out
7614eec97fSMing Lei  * @cti: cti instance
7714eec97fSMing Lei  * @trig_in: trigger in number
7814eec97fSMing Lei  * @trig_out: trigger out number
7914eec97fSMing Lei  * @channel: channel number
8014eec97fSMing Lei  *
8114eec97fSMing Lei  * This function maps one trigger in of @trig_in to one trigger
8214eec97fSMing Lei  * out of @trig_out using the channel @chan.
8314eec97fSMing Lei  */
cti_map_trigger(struct cti * cti,int trig_in,int trig_out,int chan)8414eec97fSMing Lei static inline void cti_map_trigger(struct cti *cti,
8514eec97fSMing Lei 	int trig_in, int trig_out, int chan)
8614eec97fSMing Lei {
8714eec97fSMing Lei 	void __iomem *base = cti->base;
8814eec97fSMing Lei 	unsigned long val;
8914eec97fSMing Lei 
9014eec97fSMing Lei 	val = __raw_readl(base + CTIINEN + trig_in * 4);
9114eec97fSMing Lei 	val |= BIT(chan);
9214eec97fSMing Lei 	__raw_writel(val, base + CTIINEN + trig_in * 4);
9314eec97fSMing Lei 
9414eec97fSMing Lei 	val = __raw_readl(base + CTIOUTEN + trig_out * 4);
9514eec97fSMing Lei 	val |= BIT(chan);
9614eec97fSMing Lei 	__raw_writel(val, base + CTIOUTEN + trig_out * 4);
9714eec97fSMing Lei }
9814eec97fSMing Lei 
9914eec97fSMing Lei /**
10014eec97fSMing Lei  * cti_enable - enable the cti module
10114eec97fSMing Lei  * @cti: cti instance
10214eec97fSMing Lei  *
10314eec97fSMing Lei  * enable the cti module
10414eec97fSMing Lei  */
cti_enable(struct cti * cti)10514eec97fSMing Lei static inline void cti_enable(struct cti *cti)
10614eec97fSMing Lei {
10714eec97fSMing Lei 	__raw_writel(0x1, cti->base + CTICONTROL);
10814eec97fSMing Lei }
10914eec97fSMing Lei 
11014eec97fSMing Lei /**
11114eec97fSMing Lei  * cti_disable - disable the cti module
11214eec97fSMing Lei  * @cti: cti instance
11314eec97fSMing Lei  *
11414eec97fSMing Lei  * enable the cti module
11514eec97fSMing Lei  */
cti_disable(struct cti * cti)11614eec97fSMing Lei static inline void cti_disable(struct cti *cti)
11714eec97fSMing Lei {
11814eec97fSMing Lei 	__raw_writel(0, cti->base + CTICONTROL);
11914eec97fSMing Lei }
12014eec97fSMing Lei 
12114eec97fSMing Lei /**
12214eec97fSMing Lei  * cti_irq_ack - clear the cti irq
12314eec97fSMing Lei  * @cti: cti instance
12414eec97fSMing Lei  *
12514eec97fSMing Lei  * clear the cti irq
12614eec97fSMing Lei  */
cti_irq_ack(struct cti * cti)12714eec97fSMing Lei static inline void cti_irq_ack(struct cti *cti)
12814eec97fSMing Lei {
12914eec97fSMing Lei 	void __iomem *base = cti->base;
13014eec97fSMing Lei 	unsigned long val;
13114eec97fSMing Lei 
13214eec97fSMing Lei 	val = __raw_readl(base + CTIINTACK);
13314eec97fSMing Lei 	val |= BIT(cti->trig_out_for_irq);
13414eec97fSMing Lei 	__raw_writel(val, base + CTIINTACK);
13514eec97fSMing Lei }
13614eec97fSMing Lei 
13714eec97fSMing Lei /**
13814eec97fSMing Lei  * cti_unlock - unlock cti module
13914eec97fSMing Lei  * @cti: cti instance
14014eec97fSMing Lei  *
14114eec97fSMing Lei  * unlock the cti module, or else any writes to the cti
14214eec97fSMing Lei  * module is not allowed.
14314eec97fSMing Lei  */
cti_unlock(struct cti * cti)14414eec97fSMing Lei static inline void cti_unlock(struct cti *cti)
14514eec97fSMing Lei {
14602051eadSDietmar Eggemann 	__raw_writel(CS_LAR_KEY, cti->base + LOCKACCESS);
14714eec97fSMing Lei }
14814eec97fSMing Lei 
14914eec97fSMing Lei /**
15014eec97fSMing Lei  * cti_lock - lock cti module
15114eec97fSMing Lei  * @cti: cti instance
15214eec97fSMing Lei  *
15314eec97fSMing Lei  * lock the cti module, so any writes to the cti
15414eec97fSMing Lei  * module will be not allowed.
15514eec97fSMing Lei  */
cti_lock(struct cti * cti)15614eec97fSMing Lei static inline void cti_lock(struct cti *cti)
15714eec97fSMing Lei {
15802051eadSDietmar Eggemann 	__raw_writel(~CS_LAR_KEY, cti->base + LOCKACCESS);
15914eec97fSMing Lei }
16014eec97fSMing Lei #endif
161