162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef __MACH_SE_MRSHPC_H
362306a36Sopenharmony_ci#define __MACH_SE_MRSHPC_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#include <linux/io.h>
662306a36Sopenharmony_ci
762306a36Sopenharmony_cistatic inline void __init mrshpc_setup_windows(void)
862306a36Sopenharmony_ci{
962306a36Sopenharmony_ci	if ((__raw_readw(MRSHPC_CSR) & 0x000c) != 0)
1062306a36Sopenharmony_ci		return;	/* Not detected */
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci	if ((__raw_readw(MRSHPC_CSR) & 0x0080) == 0) {
1362306a36Sopenharmony_ci		__raw_writew(0x0674, MRSHPC_CPWCR); /* Card Vcc is 3.3v? */
1462306a36Sopenharmony_ci	} else {
1562306a36Sopenharmony_ci		__raw_writew(0x0678, MRSHPC_CPWCR); /* Card Vcc is 5V */
1662306a36Sopenharmony_ci	}
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci	/*
1962306a36Sopenharmony_ci	 *  PC-Card window open
2062306a36Sopenharmony_ci	 *  flag == COMMON/ATTRIBUTE/IO
2162306a36Sopenharmony_ci	 */
2262306a36Sopenharmony_ci	/* common window open */
2362306a36Sopenharmony_ci	__raw_writew(0x8a84, MRSHPC_MW0CR1);
2462306a36Sopenharmony_ci	if((__raw_readw(MRSHPC_CSR) & 0x4000) != 0)
2562306a36Sopenharmony_ci		/* common mode & bus width 16bit SWAP = 1*/
2662306a36Sopenharmony_ci		__raw_writew(0x0b00, MRSHPC_MW0CR2);
2762306a36Sopenharmony_ci	else
2862306a36Sopenharmony_ci		/* common mode & bus width 16bit SWAP = 0*/
2962306a36Sopenharmony_ci		__raw_writew(0x0300, MRSHPC_MW0CR2);
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci	/* attribute window open */
3262306a36Sopenharmony_ci	__raw_writew(0x8a85, MRSHPC_MW1CR1);
3362306a36Sopenharmony_ci	if ((__raw_readw(MRSHPC_CSR) & 0x4000) != 0)
3462306a36Sopenharmony_ci		/* attribute mode & bus width 16bit SWAP = 1*/
3562306a36Sopenharmony_ci		__raw_writew(0x0a00, MRSHPC_MW1CR2);
3662306a36Sopenharmony_ci	else
3762306a36Sopenharmony_ci		/* attribute mode & bus width 16bit SWAP = 0*/
3862306a36Sopenharmony_ci		__raw_writew(0x0200, MRSHPC_MW1CR2);
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci	/* I/O window open */
4162306a36Sopenharmony_ci	__raw_writew(0x8a86, MRSHPC_IOWCR1);
4262306a36Sopenharmony_ci	__raw_writew(0x0008, MRSHPC_CDCR);	 /* I/O card mode */
4362306a36Sopenharmony_ci	if ((__raw_readw(MRSHPC_CSR) & 0x4000) != 0)
4462306a36Sopenharmony_ci		__raw_writew(0x0a00, MRSHPC_IOWCR2); /* bus width 16bit SWAP = 1*/
4562306a36Sopenharmony_ci	else
4662306a36Sopenharmony_ci		__raw_writew(0x0200, MRSHPC_IOWCR2); /* bus width 16bit SWAP = 0*/
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci	__raw_writew(0x2000, MRSHPC_ICR);
4962306a36Sopenharmony_ci	__raw_writeb(0x00, PA_MRSHPC_MW2 + 0x206);
5062306a36Sopenharmony_ci	__raw_writeb(0x42, PA_MRSHPC_MW2 + 0x200);
5162306a36Sopenharmony_ci}
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci#endif /* __MACH_SE_MRSHPC_H */
54