1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright 2024 NXP
*/
#include <linux/component.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/regmap.h>
#include "dc-drv.h"
#include "dc-de.h"
#define TCON_CTRL 0x410
#define CTRL_RST_VAL 0x01401408
/* red: MAPBIT 29-20, green: MAPBIT 19-10, blue: MAPBIT 9-0 */
#define MAPBIT3_0 0x418
#define MAPBIT7_4 0x41c
#define MAPBIT11_8 0x420
#define MAPBIT15_12 0x424
#define MAPBIT19_16 0x428
#define MAPBIT23_20 0x42c
#define MAPBIT27_24 0x430
#define MAPBIT31_28 0x434
static const struct dc_subdev_info dc_tc_info[] = {
{ .reg_start = 0x5618c800, .id = 0, },
{ .reg_start = 0x5618e400, .id = 1, },
};
static const struct regmap_range dc_tc_regmap_ranges[] = {
regmap_reg_range(TCON_CTRL, TCON_CTRL),
regmap_reg_range(MAPBIT3_0, MAPBIT31_28),
};
static const struct regmap_access_table dc_tc_regmap_access_table = {
.yes_ranges = dc_tc_regmap_ranges,
.n_yes_ranges = ARRAY_SIZE(dc_tc_regmap_ranges),
};
static const struct regmap_config dc_tc_regmap_config = {
.reg_bits = 32,
.reg_stride = 4,
.val_bits = 32,
.fast_io = true,
.wr_table = &dc_tc_regmap_access_table,
.rd_table = &dc_tc_regmap_access_table,
.max_register = MAPBIT31_28,
};
/*
* The pixels reach TCON are always in 30-bit BGR format.
* The first bridge always receives pixels in 30-bit RGB format.
* So, map the format to MEDIA_BUS_FMT_RGB101010_1X30.
*/
static const u32 dc_tc_mapbit[] = {
0x17161514, 0x1b1a1918, 0x0b0a1d1c, 0x0f0e0d0c,
0x13121110, 0x03020100, 0x07060504, 0x00000908,
};
void dc_tc_init(struct dc_tc *tc)
{
/* reset TCON_CTRL to POR default so that TCON works in bypass mode */
regmap_write(tc->reg, TCON_CTRL, CTRL_RST_VAL);
/* set format */
regmap_bulk_write(tc->reg, MAPBIT3_0, dc_tc_mapbit,
ARRAY_SIZE(dc_tc_mapbit));
}
static int dc_tc_bind(struct device *dev, struct device *master, void *data)
{
struct platform_device *pdev = to_platform_device(dev);
struct dc_drm_device *dc_drm = data;
struct resource *res;
void __iomem *base;
struct dc_tc *tc;
int id;
tc = devm_kzalloc(dev, sizeof(*tc), GFP_KERNEL);
if (!tc)
return -ENOMEM;
base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
if (IS_ERR(base))
return PTR_ERR(base);
tc->reg = devm_regmap_init_mmio(dev, base, &dc_tc_regmap_config);
if (IS_ERR(tc->reg))
return PTR_ERR(tc->reg);
id = dc_subdev_get_id(dc_tc_info, ARRAY_SIZE(dc_tc_info), res);
if (id < 0) {
dev_err(dev, "failed to get instance number: %d\n", id);
return id;
}
tc->dev = dev;
dc_drm->tc[id] = tc;
return 0;
}
static const struct component_ops dc_tc_ops = {
.bind = dc_tc_bind,
};
static int dc_tc_probe(struct platform_device *pdev)
{
int ret;
ret = component_add(&pdev->dev, &dc_tc_ops);
if (ret)
return dev_err_probe(&pdev->dev, ret,
"failed to add component\n");
return 0;
}
static void dc_tc_remove(struct platform_device *pdev)
{
component_del(&pdev->dev, &dc_tc_ops);
}
static const struct of_device_id dc_tc_dt_ids[] = {
{ .compatible = "fsl,imx8qxp-dc-tcon" },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, dc_tc_dt_ids);
struct platform_driver dc_tc_driver = {
.probe = dc_tc_probe,
.remove = dc_tc_remove,
.driver = {
.name = "imx8-dc-tcon",
.suppress_bind_attrs = true,
.of_match_table = dc_tc_dt_ids,
},
};
|