1*71f56b27SPaul Boddie // SPDX-License-Identifier: GPL-2.0
2*71f56b27SPaul Boddie /* Copyright (C) 2011-2013 Freescale Semiconductor, Inc.
3*71f56b27SPaul Boddie * Copyright (C) 2019, 2020 Paul Boddie <paul@boddie.org.uk>
4*71f56b27SPaul Boddie *
5*71f56b27SPaul Boddie * Derived from dw_hdmi-imx.c with i.MX portions removed.
6*71f56b27SPaul Boddie */
7*71f56b27SPaul Boddie
8*71f56b27SPaul Boddie #include <linux/module.h>
9*71f56b27SPaul Boddie #include <linux/of_platform.h>
10*71f56b27SPaul Boddie #include <linux/platform_device.h>
11*71f56b27SPaul Boddie
12*71f56b27SPaul Boddie #include <drm/bridge/dw_hdmi.h>
13*71f56b27SPaul Boddie #include <drm/drm_of.h>
14*71f56b27SPaul Boddie #include <drm/drm_print.h>
15*71f56b27SPaul Boddie
16*71f56b27SPaul Boddie static const struct dw_hdmi_mpll_config ingenic_mpll_cfg[] = {
17*71f56b27SPaul Boddie { 45250000, { { 0x01e0, 0x0000 }, { 0x21e1, 0x0000 }, { 0x41e2, 0x0000 } } },
18*71f56b27SPaul Boddie { 92500000, { { 0x0140, 0x0005 }, { 0x2141, 0x0005 }, { 0x4142, 0x0005 } } },
19*71f56b27SPaul Boddie { 148500000, { { 0x00a0, 0x000a }, { 0x20a1, 0x000a }, { 0x40a2, 0x000a } } },
20*71f56b27SPaul Boddie { 216000000, { { 0x00a0, 0x000a }, { 0x2001, 0x000f }, { 0x4002, 0x000f } } },
21*71f56b27SPaul Boddie { ~0UL, { { 0x0000, 0x0000 }, { 0x0000, 0x0000 }, { 0x0000, 0x0000 } } }
22*71f56b27SPaul Boddie };
23*71f56b27SPaul Boddie
24*71f56b27SPaul Boddie static const struct dw_hdmi_curr_ctrl ingenic_cur_ctr[] = {
25*71f56b27SPaul Boddie /*pixelclk bpp8 bpp10 bpp12 */
26*71f56b27SPaul Boddie { 54000000, { 0x091c, 0x091c, 0x06dc } },
27*71f56b27SPaul Boddie { 58400000, { 0x091c, 0x06dc, 0x06dc } },
28*71f56b27SPaul Boddie { 72000000, { 0x06dc, 0x06dc, 0x091c } },
29*71f56b27SPaul Boddie { 74250000, { 0x06dc, 0x0b5c, 0x091c } },
30*71f56b27SPaul Boddie { 118800000, { 0x091c, 0x091c, 0x06dc } },
31*71f56b27SPaul Boddie { 216000000, { 0x06dc, 0x0b5c, 0x091c } },
32*71f56b27SPaul Boddie { ~0UL, { 0x0000, 0x0000, 0x0000 } },
33*71f56b27SPaul Boddie };
34*71f56b27SPaul Boddie
35*71f56b27SPaul Boddie /*
36*71f56b27SPaul Boddie * Resistance term 133Ohm Cfg
37*71f56b27SPaul Boddie * PREEMP config 0.00
38*71f56b27SPaul Boddie * TX/CK level 10
39*71f56b27SPaul Boddie */
40*71f56b27SPaul Boddie static const struct dw_hdmi_phy_config ingenic_phy_config[] = {
41*71f56b27SPaul Boddie /*pixelclk symbol term vlev */
42*71f56b27SPaul Boddie { 216000000, 0x800d, 0x0005, 0x01ad},
43*71f56b27SPaul Boddie { ~0UL, 0x0000, 0x0000, 0x0000}
44*71f56b27SPaul Boddie };
45*71f56b27SPaul Boddie
46*71f56b27SPaul Boddie static enum drm_mode_status
ingenic_dw_hdmi_mode_valid(struct dw_hdmi * hdmi,void * data,const struct drm_display_info * info,const struct drm_display_mode * mode)47*71f56b27SPaul Boddie ingenic_dw_hdmi_mode_valid(struct dw_hdmi *hdmi, void *data,
48*71f56b27SPaul Boddie const struct drm_display_info *info,
49*71f56b27SPaul Boddie const struct drm_display_mode *mode)
50*71f56b27SPaul Boddie {
51*71f56b27SPaul Boddie if (mode->clock < 13500)
52*71f56b27SPaul Boddie return MODE_CLOCK_LOW;
53*71f56b27SPaul Boddie /* FIXME: Hardware is capable of 270MHz, but setup data is missing. */
54*71f56b27SPaul Boddie if (mode->clock > 216000)
55*71f56b27SPaul Boddie return MODE_CLOCK_HIGH;
56*71f56b27SPaul Boddie
57*71f56b27SPaul Boddie return MODE_OK;
58*71f56b27SPaul Boddie }
59*71f56b27SPaul Boddie
60*71f56b27SPaul Boddie static struct dw_hdmi_plat_data ingenic_dw_hdmi_plat_data = {
61*71f56b27SPaul Boddie .mpll_cfg = ingenic_mpll_cfg,
62*71f56b27SPaul Boddie .cur_ctr = ingenic_cur_ctr,
63*71f56b27SPaul Boddie .phy_config = ingenic_phy_config,
64*71f56b27SPaul Boddie .mode_valid = ingenic_dw_hdmi_mode_valid,
65*71f56b27SPaul Boddie .output_port = 1,
66*71f56b27SPaul Boddie };
67*71f56b27SPaul Boddie
68*71f56b27SPaul Boddie static const struct of_device_id ingenic_dw_hdmi_dt_ids[] = {
69*71f56b27SPaul Boddie { .compatible = "ingenic,jz4780-dw-hdmi" },
70*71f56b27SPaul Boddie { /* Sentinel */ },
71*71f56b27SPaul Boddie };
72*71f56b27SPaul Boddie MODULE_DEVICE_TABLE(of, ingenic_dw_hdmi_dt_ids);
73*71f56b27SPaul Boddie
ingenic_dw_hdmi_cleanup(void * data)74*71f56b27SPaul Boddie static void ingenic_dw_hdmi_cleanup(void *data)
75*71f56b27SPaul Boddie {
76*71f56b27SPaul Boddie struct dw_hdmi *hdmi = (struct dw_hdmi *)data;
77*71f56b27SPaul Boddie
78*71f56b27SPaul Boddie dw_hdmi_remove(hdmi);
79*71f56b27SPaul Boddie }
80*71f56b27SPaul Boddie
ingenic_dw_hdmi_probe(struct platform_device * pdev)81*71f56b27SPaul Boddie static int ingenic_dw_hdmi_probe(struct platform_device *pdev)
82*71f56b27SPaul Boddie {
83*71f56b27SPaul Boddie struct dw_hdmi *hdmi;
84*71f56b27SPaul Boddie
85*71f56b27SPaul Boddie hdmi = dw_hdmi_probe(pdev, &ingenic_dw_hdmi_plat_data);
86*71f56b27SPaul Boddie if (IS_ERR(hdmi))
87*71f56b27SPaul Boddie return PTR_ERR(hdmi);
88*71f56b27SPaul Boddie
89*71f56b27SPaul Boddie return devm_add_action_or_reset(&pdev->dev, ingenic_dw_hdmi_cleanup, hdmi);
90*71f56b27SPaul Boddie }
91*71f56b27SPaul Boddie
92*71f56b27SPaul Boddie static struct platform_driver ingenic_dw_hdmi_driver = {
93*71f56b27SPaul Boddie .probe = ingenic_dw_hdmi_probe,
94*71f56b27SPaul Boddie .driver = {
95*71f56b27SPaul Boddie .name = "dw-hdmi-ingenic",
96*71f56b27SPaul Boddie .of_match_table = ingenic_dw_hdmi_dt_ids,
97*71f56b27SPaul Boddie },
98*71f56b27SPaul Boddie };
99*71f56b27SPaul Boddie module_platform_driver(ingenic_dw_hdmi_driver);
100*71f56b27SPaul Boddie
101*71f56b27SPaul Boddie MODULE_DESCRIPTION("JZ4780 Specific DW-HDMI Driver Extension");
102*71f56b27SPaul Boddie MODULE_LICENSE("GPL v2");
103*71f56b27SPaul Boddie MODULE_ALIAS("platform:dw-hdmi-ingenic");
104