mediatek: Add support for Xiaomi Redmi Router AX6S
[openwrt/staging/mkresin.git] / target / linux / layerscape / patches-5.4 / 301-arch-0011-drivers-soc-fsl-add-qixis-driver.patch
1 From 68e332146b6f0a1d2a4514810986a7cf3c3117e3 Mon Sep 17 00:00:00 2001
2 From: Pankaj Bansal <pankaj.bansal@nxp.com>
3 Date: Thu, 28 Feb 2019 17:22:28 +0530
4 Subject: [PATCH] drivers: soc: fsl: add qixis driver
5
6 FPGA on LX2160AQDS/LX2160ARDB connected on I2C bus, so add qixis driver
7 which is basically an i2c client driver to control FPGA.
8
9 Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
10 ---
11 drivers/soc/fsl/Kconfig | 11 +++++
12 drivers/soc/fsl/Makefile | 1 +
13 drivers/soc/fsl/qixis_ctrl.c | 105 +++++++++++++++++++++++++++++++++++++++++++
14 3 files changed, 117 insertions(+)
15 create mode 100644 drivers/soc/fsl/qixis_ctrl.c
16
17 --- a/drivers/soc/fsl/Kconfig
18 +++ b/drivers/soc/fsl/Kconfig
19 @@ -40,4 +40,15 @@ config DPAA2_CONSOLE
20 /dev/dpaa2_mc_console and /dev/dpaa2_aiop_console,
21 which can be used to dump the Management Complex and AIOP
22 firmware logs.
23 +
24 +config FSL_QIXIS
25 + tristate "QIXIS system controller driver"
26 + depends on OF
27 + select REGMAP_I2C
28 + select REGMAP_MMIO
29 + default n
30 + help
31 + Say y here to enable QIXIS system controller api. The qixis driver
32 + provides FPGA functions to control system.
33 +
34 endmenu
35 --- a/drivers/soc/fsl/Makefile
36 +++ b/drivers/soc/fsl/Makefile
37 @@ -6,6 +6,7 @@
38 obj-$(CONFIG_FSL_DPAA) += qbman/
39 obj-$(CONFIG_QUICC_ENGINE) += qe/
40 obj-$(CONFIG_CPM) += qe/
41 +obj-$(CONFIG_FSL_QIXIS) += qixis_ctrl.o
42 obj-$(CONFIG_FSL_GUTS) += guts.o
43 obj-$(CONFIG_FSL_MC_DPIO) += dpio/
44 obj-$(CONFIG_DPAA2_CONSOLE) += dpaa2-console.o
45 --- /dev/null
46 +++ b/drivers/soc/fsl/qixis_ctrl.c
47 @@ -0,0 +1,105 @@
48 +// SPDX-License-Identifier: GPL-2.0+
49 +
50 +/* Freescale QIXIS system controller driver.
51 + *
52 + * Copyright 2015 Freescale Semiconductor, Inc.
53 + * Copyright 2018-2019 NXP
54 + */
55 +
56 +#include <linux/err.h>
57 +#include <linux/i2c.h>
58 +#include <linux/module.h>
59 +#include <linux/mfd/core.h>
60 +#include <linux/of.h>
61 +#include <linux/regmap.h>
62 +
63 +/* QIXIS MAP */
64 +struct fsl_qixis_regs {
65 + u8 id; /* Identification Registers */
66 + u8 version; /* Version Register */
67 + u8 qixis_ver; /* QIXIS Version Register */
68 + u8 reserved1[0x1f];
69 +};
70 +
71 +struct qixis_priv {
72 + struct regmap *regmap;
73 +};
74 +
75 +static struct regmap_config qixis_regmap_config = {
76 + .reg_bits = 8,
77 + .val_bits = 8,
78 +};
79 +
80 +static const struct mfd_cell fsl_qixis_devs[] = {
81 + {
82 + .name = "reg-mux",
83 + .of_compatible = "reg-mux",
84 + },
85 +};
86 +
87 +static int fsl_qixis_i2c_probe(struct i2c_client *client)
88 +{
89 + struct qixis_priv *priv;
90 + int ret = 0;
91 + u32 qver;
92 +
93 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
94 + return -EOPNOTSUPP;
95 +
96 + priv = devm_kzalloc(&client->dev, sizeof(struct qixis_priv),
97 + GFP_KERNEL);
98 + if (!priv)
99 + return -ENOMEM;
100 +
101 + priv->regmap = regmap_init_i2c(client, &qixis_regmap_config);
102 + regmap_read(priv->regmap, offsetof(struct fsl_qixis_regs, qixis_ver),
103 + &qver);
104 + pr_info("Freescale QIXIS Version: 0x%08x\n", qver);
105 +
106 + i2c_set_clientdata(client, priv);
107 +
108 + if (of_device_is_compatible(client->dev.of_node, "simple-mfd"))
109 + ret = devm_mfd_add_devices(&client->dev, -1, fsl_qixis_devs,
110 + ARRAY_SIZE(fsl_qixis_devs), NULL, 0,
111 + NULL);
112 + if (ret)
113 + goto error;
114 +
115 + return ret;
116 +error:
117 + regmap_exit(priv->regmap);
118 +
119 + return ret;
120 +}
121 +
122 +static int fsl_qixis_i2c_remove(struct i2c_client *client)
123 +{
124 + struct qixis_priv *priv;
125 +
126 + priv = i2c_get_clientdata(client);
127 + regmap_exit(priv->regmap);
128 +
129 + return 0;
130 +}
131 +
132 +static const struct of_device_id fsl_qixis_i2c_of_match[] = {
133 + { .compatible = "fsl,fpga-qixis-i2c" },
134 + {}
135 +};
136 +MODULE_DEVICE_TABLE(of, fsl_qixis_i2c_of_match);
137 +
138 +static struct i2c_driver fsl_qixis_i2c_driver = {
139 + .driver = {
140 + .name = "qixis_ctrl_i2c",
141 + .owner = THIS_MODULE,
142 + .of_match_table = of_match_ptr(fsl_qixis_i2c_of_match),
143 + },
144 + .probe_new = fsl_qixis_i2c_probe,
145 + .remove = fsl_qixis_i2c_remove,
146 +};
147 +module_i2c_driver(fsl_qixis_i2c_driver);
148 +
149 +MODULE_AUTHOR("Wang Dongsheng <dongsheng.wang@freescale.com>");
150 +MODULE_DESCRIPTION("Freescale QIXIS system controller driver");
151 +MODULE_LICENSE("GPL");
152 +