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