xref: /kernel/linux/linux-6.6/include/soc/arc/aux.h (revision 62306a36)
162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2016-2017 Synopsys, Inc. (www.synopsys.com)
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef __SOC_ARC_AUX_H__
762306a36Sopenharmony_ci#define __SOC_ARC_AUX_H__
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifdef CONFIG_ARC
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#define read_aux_reg(r)		__builtin_arc_lr(r)
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/* gcc builtin sr needs reg param to be long immediate */
1462306a36Sopenharmony_ci#define write_aux_reg(r, v)	__builtin_arc_sr((unsigned int)(v), r)
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#else	/* !CONFIG_ARC */
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistatic inline int read_aux_reg(u32 r)
1962306a36Sopenharmony_ci{
2062306a36Sopenharmony_ci	return 0;
2162306a36Sopenharmony_ci}
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci/*
2462306a36Sopenharmony_ci * function helps elide unused variable warning
2562306a36Sopenharmony_ci * see: https://lists.infradead.org/pipermail/linux-snps-arc/2016-November/001748.html
2662306a36Sopenharmony_ci */
2762306a36Sopenharmony_cistatic inline void write_aux_reg(u32 r, u32 v)
2862306a36Sopenharmony_ci{
2962306a36Sopenharmony_ci	;
3062306a36Sopenharmony_ci}
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#endif
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#define READ_BCR(reg, into)				\
3562306a36Sopenharmony_ci{							\
3662306a36Sopenharmony_ci	unsigned int tmp;				\
3762306a36Sopenharmony_ci	tmp = read_aux_reg(reg);			\
3862306a36Sopenharmony_ci	if (sizeof(tmp) == sizeof(into)) {		\
3962306a36Sopenharmony_ci		into = *((typeof(into) *)&tmp);		\
4062306a36Sopenharmony_ci	} else {					\
4162306a36Sopenharmony_ci		extern void bogus_undefined(void);	\
4262306a36Sopenharmony_ci		bogus_undefined();			\
4362306a36Sopenharmony_ci	}						\
4462306a36Sopenharmony_ci}
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci#define WRITE_AUX(reg, into)				\
4762306a36Sopenharmony_ci{							\
4862306a36Sopenharmony_ci	unsigned int tmp;				\
4962306a36Sopenharmony_ci	if (sizeof(tmp) == sizeof(into)) {		\
5062306a36Sopenharmony_ci		tmp = (*(unsigned int *)&(into));	\
5162306a36Sopenharmony_ci		write_aux_reg(reg, tmp);		\
5262306a36Sopenharmony_ci	} else  {					\
5362306a36Sopenharmony_ci		extern void bogus_undefined(void);	\
5462306a36Sopenharmony_ci		bogus_undefined();			\
5562306a36Sopenharmony_ci	}						\
5662306a36Sopenharmony_ci}
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#endif
60