18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2016 Freescale Semiconductor, Inc. 48c2ecf20Sopenharmony_ci * Copyright 2017-2018 NXP 58c2ecf20Sopenharmony_ci * Dong Aisheng <aisheng.dong@nxp.com> 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ci#include <linux/err.h> 98c2ecf20Sopenharmony_ci#include <linux/firmware/imx/sci.h> 108c2ecf20Sopenharmony_ci#include <linux/module.h> 118c2ecf20Sopenharmony_ci#include <linux/of_address.h> 128c2ecf20Sopenharmony_ci#include <linux/pinctrl/pinctrl.h> 138c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include "../core.h" 168c2ecf20Sopenharmony_ci#include "pinctrl-imx.h" 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cienum pad_func_e { 198c2ecf20Sopenharmony_ci IMX_SC_PAD_FUNC_SET = 15, 208c2ecf20Sopenharmony_ci IMX_SC_PAD_FUNC_GET = 16, 218c2ecf20Sopenharmony_ci}; 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistruct imx_sc_msg_req_pad_set { 248c2ecf20Sopenharmony_ci struct imx_sc_rpc_msg hdr; 258c2ecf20Sopenharmony_ci u32 val; 268c2ecf20Sopenharmony_ci u16 pad; 278c2ecf20Sopenharmony_ci} __packed __aligned(4); 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_cistruct imx_sc_msg_req_pad_get { 308c2ecf20Sopenharmony_ci struct imx_sc_rpc_msg hdr; 318c2ecf20Sopenharmony_ci u16 pad; 328c2ecf20Sopenharmony_ci} __packed __aligned(4); 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cistruct imx_sc_msg_resp_pad_get { 358c2ecf20Sopenharmony_ci struct imx_sc_rpc_msg hdr; 368c2ecf20Sopenharmony_ci u32 val; 378c2ecf20Sopenharmony_ci} __packed; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistatic struct imx_sc_ipc *pinctrl_ipc_handle; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ciint imx_pinctrl_sc_ipc_init(struct platform_device *pdev) 428c2ecf20Sopenharmony_ci{ 438c2ecf20Sopenharmony_ci return imx_scu_get_handle(&pinctrl_ipc_handle); 448c2ecf20Sopenharmony_ci} 458c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(imx_pinctrl_sc_ipc_init); 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ciint imx_pinconf_get_scu(struct pinctrl_dev *pctldev, unsigned pin_id, 488c2ecf20Sopenharmony_ci unsigned long *config) 498c2ecf20Sopenharmony_ci{ 508c2ecf20Sopenharmony_ci struct imx_sc_msg_req_pad_get msg; 518c2ecf20Sopenharmony_ci struct imx_sc_msg_resp_pad_get *resp; 528c2ecf20Sopenharmony_ci struct imx_sc_rpc_msg *hdr = &msg.hdr; 538c2ecf20Sopenharmony_ci int ret; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci hdr->ver = IMX_SC_RPC_VERSION; 568c2ecf20Sopenharmony_ci hdr->svc = IMX_SC_RPC_SVC_PAD; 578c2ecf20Sopenharmony_ci hdr->func = IMX_SC_PAD_FUNC_GET; 588c2ecf20Sopenharmony_ci hdr->size = 2; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci msg.pad = pin_id; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci ret = imx_scu_call_rpc(pinctrl_ipc_handle, &msg, true); 638c2ecf20Sopenharmony_ci if (ret) 648c2ecf20Sopenharmony_ci return ret; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci resp = (struct imx_sc_msg_resp_pad_get *)&msg; 678c2ecf20Sopenharmony_ci *config = resp->val; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci return 0; 708c2ecf20Sopenharmony_ci} 718c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(imx_pinconf_get_scu); 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ciint imx_pinconf_set_scu(struct pinctrl_dev *pctldev, unsigned pin_id, 748c2ecf20Sopenharmony_ci unsigned long *configs, unsigned num_configs) 758c2ecf20Sopenharmony_ci{ 768c2ecf20Sopenharmony_ci struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev); 778c2ecf20Sopenharmony_ci struct imx_sc_msg_req_pad_set msg; 788c2ecf20Sopenharmony_ci struct imx_sc_rpc_msg *hdr = &msg.hdr; 798c2ecf20Sopenharmony_ci unsigned int mux = configs[0]; 808c2ecf20Sopenharmony_ci unsigned int conf = configs[1]; 818c2ecf20Sopenharmony_ci unsigned int val; 828c2ecf20Sopenharmony_ci int ret; 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci /* 858c2ecf20Sopenharmony_ci * Set mux and conf together in one IPC call 868c2ecf20Sopenharmony_ci */ 878c2ecf20Sopenharmony_ci WARN_ON(num_configs != 2); 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci val = conf | BM_PAD_CTL_IFMUX_ENABLE | BM_PAD_CTL_GP_ENABLE; 908c2ecf20Sopenharmony_ci val |= mux << BP_PAD_CTL_IFMUX; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci hdr->ver = IMX_SC_RPC_VERSION; 938c2ecf20Sopenharmony_ci hdr->svc = IMX_SC_RPC_SVC_PAD; 948c2ecf20Sopenharmony_ci hdr->func = IMX_SC_PAD_FUNC_SET; 958c2ecf20Sopenharmony_ci hdr->size = 3; 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci msg.pad = pin_id; 988c2ecf20Sopenharmony_ci msg.val = val; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci ret = imx_scu_call_rpc(pinctrl_ipc_handle, &msg, true); 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci dev_dbg(ipctl->dev, "write: pin_id %u config 0x%x val 0x%x\n", 1038c2ecf20Sopenharmony_ci pin_id, conf, val); 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci return ret; 1068c2ecf20Sopenharmony_ci} 1078c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(imx_pinconf_set_scu); 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_civoid imx_pinctrl_parse_pin_scu(struct imx_pinctrl *ipctl, 1108c2ecf20Sopenharmony_ci unsigned int *pin_id, struct imx_pin *pin, 1118c2ecf20Sopenharmony_ci const __be32 **list_p) 1128c2ecf20Sopenharmony_ci{ 1138c2ecf20Sopenharmony_ci const struct imx_pinctrl_soc_info *info = ipctl->info; 1148c2ecf20Sopenharmony_ci struct imx_pin_scu *pin_scu = &pin->conf.scu; 1158c2ecf20Sopenharmony_ci const __be32 *list = *list_p; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci pin->pin = be32_to_cpu(*list++); 1188c2ecf20Sopenharmony_ci *pin_id = pin->pin; 1198c2ecf20Sopenharmony_ci pin_scu->mux_mode = be32_to_cpu(*list++); 1208c2ecf20Sopenharmony_ci pin_scu->config = be32_to_cpu(*list++); 1218c2ecf20Sopenharmony_ci *list_p = list; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci dev_dbg(ipctl->dev, "%s: 0x%x 0x%08lx", info->pins[pin->pin].name, 1248c2ecf20Sopenharmony_ci pin_scu->mux_mode, pin_scu->config); 1258c2ecf20Sopenharmony_ci} 1268c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(imx_pinctrl_parse_pin_scu); 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ciMODULE_AUTHOR("Dong Aisheng <aisheng.dong@nxp.com>"); 1298c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("NXP i.MX SCU common pinctrl driver"); 1308c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 131