18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __MACH_SE_MRSHPC_H
38c2ecf20Sopenharmony_ci#define __MACH_SE_MRSHPC_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/io.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_cistatic inline void __init mrshpc_setup_windows(void)
88c2ecf20Sopenharmony_ci{
98c2ecf20Sopenharmony_ci	if ((__raw_readw(MRSHPC_CSR) & 0x000c) != 0)
108c2ecf20Sopenharmony_ci		return;	/* Not detected */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci	if ((__raw_readw(MRSHPC_CSR) & 0x0080) == 0) {
138c2ecf20Sopenharmony_ci		__raw_writew(0x0674, MRSHPC_CPWCR); /* Card Vcc is 3.3v? */
148c2ecf20Sopenharmony_ci	} else {
158c2ecf20Sopenharmony_ci		__raw_writew(0x0678, MRSHPC_CPWCR); /* Card Vcc is 5V */
168c2ecf20Sopenharmony_ci	}
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci	/*
198c2ecf20Sopenharmony_ci	 *  PC-Card window open
208c2ecf20Sopenharmony_ci	 *  flag == COMMON/ATTRIBUTE/IO
218c2ecf20Sopenharmony_ci	 */
228c2ecf20Sopenharmony_ci	/* common window open */
238c2ecf20Sopenharmony_ci	__raw_writew(0x8a84, MRSHPC_MW0CR1);
248c2ecf20Sopenharmony_ci	if((__raw_readw(MRSHPC_CSR) & 0x4000) != 0)
258c2ecf20Sopenharmony_ci		/* common mode & bus width 16bit SWAP = 1*/
268c2ecf20Sopenharmony_ci		__raw_writew(0x0b00, MRSHPC_MW0CR2);
278c2ecf20Sopenharmony_ci	else
288c2ecf20Sopenharmony_ci		/* common mode & bus width 16bit SWAP = 0*/
298c2ecf20Sopenharmony_ci		__raw_writew(0x0300, MRSHPC_MW0CR2);
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci	/* attribute window open */
328c2ecf20Sopenharmony_ci	__raw_writew(0x8a85, MRSHPC_MW1CR1);
338c2ecf20Sopenharmony_ci	if ((__raw_readw(MRSHPC_CSR) & 0x4000) != 0)
348c2ecf20Sopenharmony_ci		/* attribute mode & bus width 16bit SWAP = 1*/
358c2ecf20Sopenharmony_ci		__raw_writew(0x0a00, MRSHPC_MW1CR2);
368c2ecf20Sopenharmony_ci	else
378c2ecf20Sopenharmony_ci		/* attribute mode & bus width 16bit SWAP = 0*/
388c2ecf20Sopenharmony_ci		__raw_writew(0x0200, MRSHPC_MW1CR2);
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	/* I/O window open */
418c2ecf20Sopenharmony_ci	__raw_writew(0x8a86, MRSHPC_IOWCR1);
428c2ecf20Sopenharmony_ci	__raw_writew(0x0008, MRSHPC_CDCR);	 /* I/O card mode */
438c2ecf20Sopenharmony_ci	if ((__raw_readw(MRSHPC_CSR) & 0x4000) != 0)
448c2ecf20Sopenharmony_ci		__raw_writew(0x0a00, MRSHPC_IOWCR2); /* bus width 16bit SWAP = 1*/
458c2ecf20Sopenharmony_ci	else
468c2ecf20Sopenharmony_ci		__raw_writew(0x0200, MRSHPC_IOWCR2); /* bus width 16bit SWAP = 0*/
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	__raw_writew(0x2000, MRSHPC_ICR);
498c2ecf20Sopenharmony_ci	__raw_writeb(0x00, PA_MRSHPC_MW2 + 0x206);
508c2ecf20Sopenharmony_ci	__raw_writeb(0x42, PA_MRSHPC_MW2 + 0x200);
518c2ecf20Sopenharmony_ci}
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#endif /* __MACH_SE_MRSHPC_H */
54