xref: /openbmc/u-boot/drivers/pinctrl/nxp/pinctrl-scu.c (revision cf033e04da315ba949e804c127abae0134bda30f)
1*38b6686fSPeng Fan // SPDX-License-Identifier: GPL-2.0+
2*38b6686fSPeng Fan /*
3*38b6686fSPeng Fan  * Copyright 2018 NXP
4*38b6686fSPeng Fan  */
5*38b6686fSPeng Fan 
6*38b6686fSPeng Fan #include <common.h>
7*38b6686fSPeng Fan #include <errno.h>
8*38b6686fSPeng Fan #include <linux/bitops.h>
9*38b6686fSPeng Fan #include <asm/io.h>
10*38b6686fSPeng Fan #include <asm/arch/sci/sci.h>
11*38b6686fSPeng Fan #include <misc.h>
12*38b6686fSPeng Fan 
13*38b6686fSPeng Fan #include "pinctrl-imx.h"
14*38b6686fSPeng Fan 
15*38b6686fSPeng Fan #define PADRING_IFMUX_EN_SHIFT		31
16*38b6686fSPeng Fan #define PADRING_IFMUX_EN_MASK		BIT(31)
17*38b6686fSPeng Fan #define PADRING_GP_EN_SHIFT		30
18*38b6686fSPeng Fan #define PADRING_GP_EN_MASK		BIT(30)
19*38b6686fSPeng Fan #define PADRING_IFMUX_SHIFT		27
20*38b6686fSPeng Fan #define PADRING_IFMUX_MASK		GENMASK(29, 27)
21*38b6686fSPeng Fan 
imx_pinconf_scu_set(struct imx_pinctrl_soc_info * info,u32 pad,u32 mux,u32 val)22*38b6686fSPeng Fan static int imx_pinconf_scu_set(struct imx_pinctrl_soc_info *info, u32 pad,
23*38b6686fSPeng Fan 			       u32 mux, u32 val)
24*38b6686fSPeng Fan {
25*38b6686fSPeng Fan 	int ret;
26*38b6686fSPeng Fan 
27*38b6686fSPeng Fan 	/*
28*38b6686fSPeng Fan 	 * Mux should be done in pmx set, but we do not have a good api
29*38b6686fSPeng Fan 	 * to handle that in scfw, so config it in pad conf func
30*38b6686fSPeng Fan 	 */
31*38b6686fSPeng Fan 
32*38b6686fSPeng Fan 	val |= PADRING_IFMUX_EN_MASK;
33*38b6686fSPeng Fan 	val |= PADRING_GP_EN_MASK;
34*38b6686fSPeng Fan 	val |= (mux << PADRING_IFMUX_SHIFT) & PADRING_IFMUX_MASK;
35*38b6686fSPeng Fan 
36*38b6686fSPeng Fan 	ret = sc_pad_set(-1, pad, val);
37*38b6686fSPeng Fan 	if (ret)
38*38b6686fSPeng Fan 		printf("%s %d\n", __func__, ret);
39*38b6686fSPeng Fan 
40*38b6686fSPeng Fan 	return 0;
41*38b6686fSPeng Fan }
42*38b6686fSPeng Fan 
imx_pinctrl_scu_conf_pins(struct imx_pinctrl_soc_info * info,u32 * pin_data,int npins)43*38b6686fSPeng Fan int imx_pinctrl_scu_conf_pins(struct imx_pinctrl_soc_info *info, u32 *pin_data,
44*38b6686fSPeng Fan 			      int npins)
45*38b6686fSPeng Fan {
46*38b6686fSPeng Fan 	int pin_id, mux, config_val;
47*38b6686fSPeng Fan 	int i, j = 0;
48*38b6686fSPeng Fan 	int ret;
49*38b6686fSPeng Fan 
50*38b6686fSPeng Fan 	/*
51*38b6686fSPeng Fan 	 * Refer to linux documentation for details:
52*38b6686fSPeng Fan 	 * Documentation/devicetree/bindings/pinctrl/fsl,imx-pinctrl.txt
53*38b6686fSPeng Fan 	 */
54*38b6686fSPeng Fan 	for (i = 0; i < npins; i++) {
55*38b6686fSPeng Fan 		pin_id = pin_data[j++];
56*38b6686fSPeng Fan 		mux = pin_data[j++];
57*38b6686fSPeng Fan 		config_val = pin_data[j++];
58*38b6686fSPeng Fan 
59*38b6686fSPeng Fan 		ret = imx_pinconf_scu_set(info, pin_id, mux, config_val);
60*38b6686fSPeng Fan 		if (ret)
61*38b6686fSPeng Fan 			printf("Set pin %d, mux %d, val %d, error\n", pin_id,
62*38b6686fSPeng Fan 			       mux, config_val);
63*38b6686fSPeng Fan 	}
64*38b6686fSPeng Fan 
65*38b6686fSPeng Fan 	return 0;
66*38b6686fSPeng Fan }
67