blob: 7d91ccfb26f1c7764deb59aa75663b4e5ed56393 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peng Fane2fd36cc2016-02-03 10:06:07 +08002/*
3 * Copyright (C) 2016 Peng Fan <van.freenix@gmail.com>
Peng Fane2fd36cc2016-02-03 10:06:07 +08004 */
5
Simon Glass9bc15642020-02-03 07:36:16 -07006#include <malloc.h>
Peng Fane2fd36cc2016-02-03 10:06:07 +08007#include <mapmem.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06008#include <asm/global_data.h>
Simon Glass9bc15642020-02-03 07:36:16 -07009#include <dm/device_compat.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070010#include <dm/devres.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060011#include <linux/bitops.h>
Peng Fane2fd36cc2016-02-03 10:06:07 +080012#include <linux/io.h>
13#include <linux/err.h>
Simon Glass11c89f32017-05-17 17:18:03 -060014#include <dm.h>
Peng Fane2fd36cc2016-02-03 10:06:07 +080015#include <dm/pinctrl.h>
16
17#include "pinctrl-imx.h"
18
19DECLARE_GLOBAL_DATA_PTR;
20
Marek Vasut964d87c2025-01-24 15:50:56 +010021int imx_pinctrl_set_state_common(struct udevice *dev, struct udevice *config,
22 int pin_size, u32 **pin_data, int *npins)
Peng Fane2fd36cc2016-02-03 10:06:07 +080023{
Tim Harveyadf72e02024-10-23 13:28:52 -070024 ofnode node = dev_ofnode(config);
Peng Fane2fd36cc2016-02-03 10:06:07 +080025 const struct fdt_property *prop;
Marek Vasut964d87c2025-01-24 15:50:56 +010026 int size;
Peng Fane2fd36cc2016-02-03 10:06:07 +080027
28 dev_dbg(dev, "%s: %s\n", __func__, config->name);
29
Tim Harveyadf72e02024-10-23 13:28:52 -070030 prop = ofnode_get_property(node, "fsl,pins", &size);
Peng Fane2fd36cc2016-02-03 10:06:07 +080031 if (!prop) {
32 dev_err(dev, "No fsl,pins property in node %s\n", config->name);
33 return -EINVAL;
34 }
35
36 if (!size || size % pin_size) {
37 dev_err(dev, "Invalid fsl,pins property in node %s\n",
38 config->name);
39 return -EINVAL;
40 }
41
Marek Vasut964d87c2025-01-24 15:50:56 +010042 *pin_data = devm_kzalloc(dev, size, 0);
43 if (!*pin_data)
Peng Fane2fd36cc2016-02-03 10:06:07 +080044 return -ENOMEM;
45
Marek Vasut964d87c2025-01-24 15:50:56 +010046 if (ofnode_read_u32_array(node, "fsl,pins", *pin_data, size >> 2)) {
Peng Fane2fd36cc2016-02-03 10:06:07 +080047 dev_err(dev, "Error reading pin data.\n");
Marek Vasut964d87c2025-01-24 15:50:56 +010048 devm_kfree(dev, *pin_data);
Peng Fane2fd36cc2016-02-03 10:06:07 +080049 return -EINVAL;
50 }
51
Marek Vasut964d87c2025-01-24 15:50:56 +010052 *npins = size / pin_size;
53
54 return 0;
55}
56
Marek Vasutf19a47f2025-01-24 15:50:54 +010057int imx_pinctrl_probe_common(struct udevice *dev)
Peng Fane2fd36cc2016-02-03 10:06:07 +080058{
Marek Vasutc894e132025-01-24 15:50:53 +010059 struct imx_pinctrl_soc_info *info =
60 (struct imx_pinctrl_soc_info *)dev_get_driver_data(dev);
Peng Fane2fd36cc2016-02-03 10:06:07 +080061 struct imx_pinctrl_priv *priv = dev_get_priv(dev);
Peng Fane2fd36cc2016-02-03 10:06:07 +080062
63 if (!info) {
64 dev_err(dev, "wrong pinctrl info\n");
65 return -EINVAL;
66 }
67
68 priv->dev = dev;
69 priv->info = info;
70
Peng Fane2fd36cc2016-02-03 10:06:07 +080071 return 0;
72}