2 * Copyright 2015 Toradex AG
4 * Stefan Agner <stefan@agner.ch>
6 * Freescale TCON device driver
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include <linux/clk.h>
17 #include <linux/of_address.h>
18 #include <linux/platform_device.h>
19 #include <linux/regmap.h>
23 void fsl_tcon_bypass_disable(struct fsl_tcon
*tcon
)
25 regmap_update_bits(tcon
->regs
, FSL_TCON_CTRL1
,
26 FSL_TCON_CTRL1_TCON_BYPASS
, 0);
29 void fsl_tcon_bypass_enable(struct fsl_tcon
*tcon
)
31 regmap_update_bits(tcon
->regs
, FSL_TCON_CTRL1
,
32 FSL_TCON_CTRL1_TCON_BYPASS
,
33 FSL_TCON_CTRL1_TCON_BYPASS
);
36 static struct regmap_config fsl_tcon_regmap_config
= {
44 static int fsl_tcon_init_regmap(struct device
*dev
,
45 struct fsl_tcon
*tcon
,
46 struct device_node
*np
)
51 if (of_address_to_resource(np
, 0, &res
))
54 regs
= devm_ioremap_resource(dev
, &res
);
58 tcon
->regs
= devm_regmap_init_mmio(dev
, regs
,
59 &fsl_tcon_regmap_config
);
60 return PTR_ERR_OR_ZERO(tcon
->regs
);
63 struct fsl_tcon
*fsl_tcon_init(struct device
*dev
)
65 struct fsl_tcon
*tcon
;
66 struct device_node
*np
;
69 /* TCON node is not mandatory, some devices do not provide TCON */
70 np
= of_parse_phandle(dev
->of_node
, "fsl,tcon", 0);
74 tcon
= devm_kzalloc(dev
, sizeof(*tcon
), GFP_KERNEL
);
78 ret
= fsl_tcon_init_regmap(dev
, tcon
, np
);
80 dev_err(dev
, "Couldn't create the TCON regmap\n");
84 tcon
->ipg_clk
= of_clk_get_by_name(np
, "ipg");
85 if (IS_ERR(tcon
->ipg_clk
)) {
86 dev_err(dev
, "Couldn't get the TCON bus clock\n");
90 ret
= clk_prepare_enable(tcon
->ipg_clk
);
92 dev_err(dev
, "Couldn't enable the TCON clock\n");
97 dev_info(dev
, "Using TCON in bypass mode\n");
106 void fsl_tcon_free(struct fsl_tcon
*tcon
)
108 clk_disable_unprepare(tcon
->ipg_clk
);
109 clk_put(tcon
->ipg_clk
);