1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2015 Toradex AG
5 * Stefan Agner <stefan@agner.ch>
7 * Freescale TCON device driver
10 #include <linux/clk.h>
13 #include <linux/of_address.h>
14 #include <linux/platform_device.h>
15 #include <linux/regmap.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
= {
40 static int fsl_tcon_init_regmap(struct device
*dev
,
41 struct fsl_tcon
*tcon
,
42 struct device_node
*np
)
47 if (of_address_to_resource(np
, 0, &res
))
50 regs
= devm_ioremap_resource(dev
, &res
);
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
;
65 /* TCON node is not mandatory, some devices do not provide TCON */
66 np
= of_parse_phandle(dev
->of_node
, "fsl,tcon", 0);
70 tcon
= devm_kzalloc(dev
, sizeof(*tcon
), GFP_KERNEL
);
74 ret
= fsl_tcon_init_regmap(dev
, tcon
, np
);
76 dev_err(dev
, "Couldn't create the TCON regmap\n");
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");
86 ret
= clk_prepare_enable(tcon
->ipg_clk
);
88 dev_err(dev
, "Couldn't enable the TCON clock\n");
93 dev_info(dev
, "Using TCON in bypass mode\n");
102 void fsl_tcon_free(struct fsl_tcon
*tcon
)
104 clk_disable_unprepare(tcon
->ipg_clk
);
105 clk_put(tcon
->ipg_clk
);