1 // SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2 /*
3  * Copyright (c) 2018 Microsemi Coprporation
4  */
5 
6 #include <common.h>
7 #include <asm/io.h>
8 #include <spi.h>
9 #include <linux/bitops.h>
10 
external_cs_manage(struct udevice * dev,bool enable)11 void external_cs_manage(struct udevice *dev, bool enable)
12 {
13 	u32 cs = spi_chip_select(dev);
14 	/* IF_SI0_OWNER, select the owner of the SI interface
15 	 * Encoding: 0: SI Slave
16 	 *	     1: SI Boot Master
17 	 *	     2: SI Master Controller
18 	 */
19 	if (!enable) {
20 		writel(ICPU_SW_MODE_SW_PIN_CTRL_MODE |
21 		       ICPU_SW_MODE_SW_SPI_CS(BIT(cs)),
22 		       BASE_CFG + ICPU_SW_MODE);
23 		clrsetbits_le32(BASE_CFG + ICPU_GENERAL_CTRL,
24 				ICPU_GENERAL_CTRL_IF_SI_OWNER_M,
25 				ICPU_GENERAL_CTRL_IF_SI_OWNER(2));
26 	} else {
27 		writel(0, BASE_CFG + ICPU_SW_MODE);
28 		clrsetbits_le32(BASE_CFG + ICPU_GENERAL_CTRL,
29 				ICPU_GENERAL_CTRL_IF_SI_OWNER_M,
30 				ICPU_GENERAL_CTRL_IF_SI_OWNER(1));
31 	}
32 }
33