Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / fsl-dcu / fsl_tcon.c
blob9eb5abaf7d660229fffc8db8d75b989757f5d60b
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright 2015 Toradex AG
5 * Stefan Agner <stefan@agner.ch>
7 * Freescale TCON device driver
8 */
10 #include <linux/clk.h>
11 #include <linux/io.h>
12 #include <linux/mm.h>
13 #include <linux/of_address.h>
14 #include <linux/platform_device.h>
15 #include <linux/regmap.h>
17 #include "fsl_tcon.h"
19 void fsl_tcon_bypass_disable(struct fsl_tcon *tcon)
21 regmap_update_bits(tcon->regs, FSL_TCON_CTRL1,
22 FSL_TCON_CTRL1_TCON_BYPASS, 0);
25 void fsl_tcon_bypass_enable(struct fsl_tcon *tcon)
27 regmap_update_bits(tcon->regs, FSL_TCON_CTRL1,
28 FSL_TCON_CTRL1_TCON_BYPASS,
29 FSL_TCON_CTRL1_TCON_BYPASS);
32 static struct regmap_config fsl_tcon_regmap_config = {
33 .reg_bits = 32,
34 .reg_stride = 4,
35 .val_bits = 32,
37 .name = "tcon",
40 static int fsl_tcon_init_regmap(struct device *dev,
41 struct fsl_tcon *tcon,
42 struct device_node *np)
44 struct resource res;
45 void __iomem *regs;
47 if (of_address_to_resource(np, 0, &res))
48 return -EINVAL;
50 regs = devm_ioremap_resource(dev, &res);
51 if (IS_ERR(regs))
52 return PTR_ERR(regs);
54 tcon->regs = devm_regmap_init_mmio(dev, regs,
55 &fsl_tcon_regmap_config);
56 return PTR_ERR_OR_ZERO(tcon->regs);
59 struct fsl_tcon *fsl_tcon_init(struct device *dev)
61 struct fsl_tcon *tcon;
62 struct device_node *np;
63 int ret;
65 /* TCON node is not mandatory, some devices do not provide TCON */
66 np = of_parse_phandle(dev->of_node, "fsl,tcon", 0);
67 if (!np)
68 return NULL;
70 tcon = devm_kzalloc(dev, sizeof(*tcon), GFP_KERNEL);
71 if (!tcon)
72 goto err_node_put;
74 ret = fsl_tcon_init_regmap(dev, tcon, np);
75 if (ret) {
76 dev_err(dev, "Couldn't create the TCON regmap\n");
77 goto err_node_put;
80 tcon->ipg_clk = of_clk_get_by_name(np, "ipg");
81 if (IS_ERR(tcon->ipg_clk)) {
82 dev_err(dev, "Couldn't get the TCON bus clock\n");
83 goto err_node_put;
86 ret = clk_prepare_enable(tcon->ipg_clk);
87 if (ret) {
88 dev_err(dev, "Couldn't enable the TCON clock\n");
89 goto err_node_put;
92 of_node_put(np);
93 dev_info(dev, "Using TCON in bypass mode\n");
95 return tcon;
97 err_node_put:
98 of_node_put(np);
99 return NULL;
102 void fsl_tcon_free(struct fsl_tcon *tcon)
104 clk_disable_unprepare(tcon->ipg_clk);
105 clk_put(tcon->ipg_clk);