aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/bus/da8xx-mstpri.c
blob: 9af9bcc68059e9c50ea3aaba71817e51b9f35a15 (plain)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*
 * TI da8xx master peripheral priority driver
 *
 * Copyright (C) 2016 BayLibre SAS
 *
 * Author:
 *   Bartosz Golaszewski <bgolaszewski@baylibre.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/io.h>
#include <linux/regmap.h>

/*
 * REVISIT: Linux doesn't have a good framework for the kind of performance
 * knobs this driver controls. We can't use device tree properties as it deals
 * with hardware configuration rather than description. We also don't want to
 * commit to maintaining some random sysfs attributes.
 *
 * For now we just hardcode the register values for the boards that need
 * some changes (as is the case for the LCD controller on da850-lcdk - the
 * first board we support here). When linux gets an appropriate framework,
 * we'll easily convert the driver to it.
 */

#define DA8XX_MSTPRI0_OFFSET		0
#define DA8XX_MSTPRI1_OFFSET		4
#define DA8XX_MSTPRI2_OFFSET		8

enum {
	DA8XX_MSTPRI_ARM_I = 0,
	DA8XX_MSTPRI_ARM_D,
	DA8XX_MSTPRI_UPP,
	DA8XX_MSTPRI_SATA,
	DA8XX_MSTPRI_PRU0,
	DA8XX_MSTPRI_PRU1,
	DA8XX_MSTPRI_EDMA30TC0,
	DA8XX_MSTPRI_EDMA30TC1,
	DA8XX_MSTPRI_EDMA31TC0,
	DA8XX_MSTPRI_VPIF_DMA_0,
	DA8XX_MSTPRI_VPIF_DMA_1,
	DA8XX_MSTPRI_EMAC,
	DA8XX_MSTPRI_USB0CFG,
	DA8XX_MSTPRI_USB0CDMA,
	DA8XX_MSTPRI_UHPI,
	DA8XX_MSTPRI_USB1,
	DA8XX_MSTPRI_LCDC,
};

struct da8xx_mstpri_descr {
	int reg;
	int shift;
	int mask;
};

static const struct da8xx_mstpri_descr da8xx_mstpri_priority_list[] = {
	[DA8XX_MSTPRI_ARM_I] = {
		.reg = DA8XX_MSTPRI0_OFFSET,
		.shift = 0,
		.mask = 0x0000000f,
	},
	[DA8XX_MSTPRI_ARM_D] = {
		.reg = DA8XX_MSTPRI0_OFFSET,
		.shift = 4,
		.mask = 0x000000f0,
	},
	[DA8XX_MSTPRI_UPP] = {
		.reg = DA8XX_MSTPRI0_OFFSET,
		.shift = 16,
		.mask = 0x000f0000,
	},
	[DA8XX_MSTPRI_SATA] = {
		.reg = DA8XX_MSTPRI0_OFFSET,
		.shift = 20,
		.mask = 0x00f00000,
	},
	[DA8XX_MSTPRI_PRU0] = {
		.reg = DA8XX_MSTPRI1_OFFSET,
		.shift = 0,
		.mask = 0x0000000f,
	},
	[DA8XX_MSTPRI_PRU1] = {
		.reg = DA8XX_MSTPRI1_OFFSET,
		.shift = 4,
		.mask = 0x000000f0,
	},
	[DA8XX_MSTPRI_EDMA30TC0] = {
		.reg = DA8XX_MSTPRI1_OFFSET,
		.shift = 8,
		.mask = 0x00000f00,
	},
	[DA8XX_MSTPRI_EDMA30TC1] = {
		.reg = DA8XX_MSTPRI1_OFFSET,
		.shift = 12,
		.mask = 0x0000f000,
	},
	[DA8XX_MSTPRI_EDMA31TC0] = {
		.reg = DA8XX_MSTPRI1_OFFSET,
		.shift = 16,
		.mask = 0x000f0000,
	},
	[DA8XX_MSTPRI_VPIF_DMA_0] = {
		.reg = DA8XX_MSTPRI1_OFFSET,
		.shift = 24,
		.mask = 0x0f000000,
	},
	[DA8XX_MSTPRI_VPIF_DMA_1] = {
		.reg = DA8XX_MSTPRI1_OFFSET,
		.shift = 28,
		.mask = 0xf0000000,
	},
	[DA8XX_MSTPRI_EMAC] = {
		.reg = DA8XX_MSTPRI2_OFFSET,
		.shift = 0,
		.mask = 0x0000000f,
	},
	[DA8XX_MSTPRI_USB0CFG] = {
		.reg = DA8XX_MSTPRI2_OFFSET,
		.shift = 8,
		.mask = 0x00000f00,
	},
	[DA8XX_MSTPRI_USB0CDMA] = {
		.reg = DA8XX_MSTPRI2_OFFSET,
		.shift = 12,
		.mask = 0x0000f000,
	},
	[DA8XX_MSTPRI_UHPI] = {
		.reg = DA8XX_MSTPRI2_OFFSET,
		.shift = 20,
		.mask = 0x00f00000,
	},
	[DA8XX_MSTPRI_USB1] = {
		.reg = DA8XX_MSTPRI2_OFFSET,
		.shift = 24,
		.mask = 0x0f000000,
	},
	[DA8XX_MSTPRI_LCDC] = {
		.reg = DA8XX_MSTPRI2_OFFSET,
		.shift = 28,
		.mask = 0xf0000000,
	},
};

struct da8xx_mstpri_priority {
	int which;
	u32 val;
};

struct da8xx_mstpri_board_priorities {
	const char *board;
	const struct da8xx_mstpri_priority *priorities;
	size_t numprio;
};

/*
 * Default memory settings of da850 do not meet the throughput/latency
 * requirements of tilcdc. This results in the image displayed being
 * incorrect and the following warning being displayed by the LCDC
 * drm driver:
 *
 *   tilcdc da8xx_lcdc.0: tilcdc_crtc_irq(0x00000020): FIFO underfow
 */
static const struct da8xx_mstpri_priority da850_lcdk_priorities[] = {
	{
		.which = DA8XX_MSTPRI_LCDC,
		.val = 0,
	},
	{
		.which = DA8XX_MSTPRI_EDMA30TC1,
		.val = 0,
	},
	{
		.which = DA8XX_MSTPRI_EDMA30TC0,
		.val = 1,
	},
};

static const struct da8xx_mstpri_board_priorities da8xx_mstpri_board_confs[] = {
	{
		.board = "ti,da850-lcdk",
		.priorities = da850_lcdk_priorities,
		.numprio = ARRAY_SIZE(da850_lcdk_priorities),
	},
};

static const struct da8xx_mstpri_board_priorities *
da8xx_mstpri_get_board_prio(void)
{
	const struct da8xx_mstpri_board_priorities *board_prio;
	int i;

	for (i = 0; i < ARRAY_SIZE(da8xx_mstpri_board_confs); i++) {
		board_prio = &da8xx_mstpri_board_confs[i];

		if (of_machine_is_compatible(board_prio->board))
			return board_prio;
	}

	return NULL;
}

static int da8xx_mstpri_probe(struct platform_device *pdev)
{
	const struct da8xx_mstpri_board_priorities *prio_list;
	const struct da8xx_mstpri_descr *prio_descr;
	const struct da8xx_mstpri_priority *prio;
	struct device *dev = &pdev->dev;
	struct resource *res;
	void __iomem *mstpri;
	u32 reg;
	int i;

	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
	mstpri = devm_ioremap_resource(dev, res);
	if (IS_ERR(mstpri)) {
		dev_err(dev, "unable to map MSTPRI registers\n");
		return PTR_ERR(mstpri);
	}

	prio_list = da8xx_mstpri_get_board_prio();
	if (!prio_list) {
		dev_err(dev, "no master priorities defined for this board\n");
		return -EINVAL;
	}

	for (i = 0; i < prio_list->numprio; i++) {
		prio = &prio_list->priorities[i];
		prio_descr = &da8xx_mstpri_priority_list[prio->which];

		if (prio_descr->reg + sizeof(u32) > resource_size(res)) {
			dev_warn(dev, "register offset out of range\n");
			continue;
		}

		reg = readl(mstpri + prio_descr->reg);
		reg &= ~prio_descr->mask;
		reg |= prio->val << prio_descr->shift;

		writel(reg, mstpri + prio_descr->reg);
	}

	return 0;
}

static const struct of_device_id da8xx_mstpri_of_match[] = {
	{ .compatible = "ti,da850-mstpri", },
	{ },
};

static struct platform_driver da8xx_mstpri_driver = {
	.probe = da8xx_mstpri_probe,
	.driver = {
		.name = "da8xx-mstpri",
		.of_match_table = da8xx_mstpri_of_match,
	},
};
module_platform_driver(da8xx_mstpri_driver);

MODULE_AUTHOR("Bartosz Golaszewski <bgolaszewski@baylibre.com>");
MODULE_DESCRIPTION("TI da8xx master peripheral priority driver");
MODULE_LICENSE("GPL v2");

Privacy Policy