18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2016-2017 Synopsys, Inc. (www.synopsys.com)
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef __SOC_ARC_AUX_H__
78c2ecf20Sopenharmony_ci#define __SOC_ARC_AUX_H__
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifdef CONFIG_ARC
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#define read_aux_reg(r)		__builtin_arc_lr(r)
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/* gcc builtin sr needs reg param to be long immediate */
148c2ecf20Sopenharmony_ci#define write_aux_reg(r, v)	__builtin_arc_sr((unsigned int)(v), r)
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#else	/* !CONFIG_ARC */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistatic inline int read_aux_reg(u32 r)
198c2ecf20Sopenharmony_ci{
208c2ecf20Sopenharmony_ci	return 0;
218c2ecf20Sopenharmony_ci}
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/*
248c2ecf20Sopenharmony_ci * function helps elide unused variable warning
258c2ecf20Sopenharmony_ci * see: https://lists.infradead.org/pipermail/linux-snps-arc/2016-November/001748.html
268c2ecf20Sopenharmony_ci */
278c2ecf20Sopenharmony_cistatic inline void write_aux_reg(u32 r, u32 v)
288c2ecf20Sopenharmony_ci{
298c2ecf20Sopenharmony_ci	;
308c2ecf20Sopenharmony_ci}
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#endif
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define READ_BCR(reg, into)				\
358c2ecf20Sopenharmony_ci{							\
368c2ecf20Sopenharmony_ci	unsigned int tmp;				\
378c2ecf20Sopenharmony_ci	tmp = read_aux_reg(reg);			\
388c2ecf20Sopenharmony_ci	if (sizeof(tmp) == sizeof(into)) {		\
398c2ecf20Sopenharmony_ci		into = *((typeof(into) *)&tmp);		\
408c2ecf20Sopenharmony_ci	} else {					\
418c2ecf20Sopenharmony_ci		extern void bogus_undefined(void);	\
428c2ecf20Sopenharmony_ci		bogus_undefined();			\
438c2ecf20Sopenharmony_ci	}						\
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define WRITE_AUX(reg, into)				\
478c2ecf20Sopenharmony_ci{							\
488c2ecf20Sopenharmony_ci	unsigned int tmp;				\
498c2ecf20Sopenharmony_ci	if (sizeof(tmp) == sizeof(into)) {		\
508c2ecf20Sopenharmony_ci		tmp = (*(unsigned int *)&(into));	\
518c2ecf20Sopenharmony_ci		write_aux_reg(reg, tmp);		\
528c2ecf20Sopenharmony_ci	} else  {					\
538c2ecf20Sopenharmony_ci		extern void bogus_undefined(void);	\
548c2ecf20Sopenharmony_ci		bogus_undefined();			\
558c2ecf20Sopenharmony_ci	}						\
568c2ecf20Sopenharmony_ci}
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#endif
60