1 // SPDX-License-Identifier: GPL-2.0-only
3 * TI da8xx master peripheral priority driver
5 * Copyright (C) 2016 BayLibre SAS
8 * Bartosz Golaszewski <bgolaszewski@baylibre.com>
11 #include <linux/module.h>
13 #include <linux/platform_device.h>
15 #include <linux/regmap.h>
18 * REVISIT: Linux doesn't have a good framework for the kind of performance
19 * knobs this driver controls. We can't use device tree properties as it deals
20 * with hardware configuration rather than description. We also don't want to
21 * commit to maintaining some random sysfs attributes.
23 * For now we just hardcode the register values for the boards that need
24 * some changes (as is the case for the LCD controller on da850-lcdk - the
25 * first board we support here). When linux gets an appropriate framework,
26 * we'll easily convert the driver to it.
29 #define DA8XX_MSTPRI0_OFFSET 0
30 #define DA8XX_MSTPRI1_OFFSET 4
31 #define DA8XX_MSTPRI2_OFFSET 8
34 DA8XX_MSTPRI_ARM_I = 0,
40 DA8XX_MSTPRI_EDMA30TC0,
41 DA8XX_MSTPRI_EDMA30TC1,
42 DA8XX_MSTPRI_EDMA31TC0,
43 DA8XX_MSTPRI_VPIF_DMA_0,
44 DA8XX_MSTPRI_VPIF_DMA_1,
47 DA8XX_MSTPRI_USB0CDMA,
53 struct da8xx_mstpri_descr {
59 static const struct da8xx_mstpri_descr da8xx_mstpri_priority_list[] = {
60 [DA8XX_MSTPRI_ARM_I] = {
61 .reg = DA8XX_MSTPRI0_OFFSET,
65 [DA8XX_MSTPRI_ARM_D] = {
66 .reg = DA8XX_MSTPRI0_OFFSET,
70 [DA8XX_MSTPRI_UPP] = {
71 .reg = DA8XX_MSTPRI0_OFFSET,
75 [DA8XX_MSTPRI_SATA] = {
76 .reg = DA8XX_MSTPRI0_OFFSET,
80 [DA8XX_MSTPRI_PRU0] = {
81 .reg = DA8XX_MSTPRI1_OFFSET,
85 [DA8XX_MSTPRI_PRU1] = {
86 .reg = DA8XX_MSTPRI1_OFFSET,
90 [DA8XX_MSTPRI_EDMA30TC0] = {
91 .reg = DA8XX_MSTPRI1_OFFSET,
95 [DA8XX_MSTPRI_EDMA30TC1] = {
96 .reg = DA8XX_MSTPRI1_OFFSET,
100 [DA8XX_MSTPRI_EDMA31TC0] = {
101 .reg = DA8XX_MSTPRI1_OFFSET,
105 [DA8XX_MSTPRI_VPIF_DMA_0] = {
106 .reg = DA8XX_MSTPRI1_OFFSET,
110 [DA8XX_MSTPRI_VPIF_DMA_1] = {
111 .reg = DA8XX_MSTPRI1_OFFSET,
115 [DA8XX_MSTPRI_EMAC] = {
116 .reg = DA8XX_MSTPRI2_OFFSET,
120 [DA8XX_MSTPRI_USB0CFG] = {
121 .reg = DA8XX_MSTPRI2_OFFSET,
125 [DA8XX_MSTPRI_USB0CDMA] = {
126 .reg = DA8XX_MSTPRI2_OFFSET,
130 [DA8XX_MSTPRI_UHPI] = {
131 .reg = DA8XX_MSTPRI2_OFFSET,
135 [DA8XX_MSTPRI_USB1] = {
136 .reg = DA8XX_MSTPRI2_OFFSET,
140 [DA8XX_MSTPRI_LCDC] = {
141 .reg = DA8XX_MSTPRI2_OFFSET,
147 struct da8xx_mstpri_priority {
152 struct da8xx_mstpri_board_priorities {
154 const struct da8xx_mstpri_priority *priorities;
159 * Default memory settings of da850 do not meet the throughput/latency
160 * requirements of tilcdc. This results in the image displayed being
161 * incorrect and the following warning being displayed by the LCDC
164 * tilcdc da8xx_lcdc.0: tilcdc_crtc_irq(0x00000020): FIFO underfow
166 static const struct da8xx_mstpri_priority da850_lcdk_priorities[] = {
168 .which = DA8XX_MSTPRI_LCDC,
172 .which = DA8XX_MSTPRI_EDMA30TC1,
176 .which = DA8XX_MSTPRI_EDMA30TC0,
181 static const struct da8xx_mstpri_board_priorities da8xx_mstpri_board_confs[] = {
183 .board = "ti,da850-lcdk",
184 .priorities = da850_lcdk_priorities,
185 .numprio = ARRAY_SIZE(da850_lcdk_priorities),
189 static const struct da8xx_mstpri_board_priorities *
190 da8xx_mstpri_get_board_prio(void)
192 const struct da8xx_mstpri_board_priorities *board_prio;
195 for (i = 0; i < ARRAY_SIZE(da8xx_mstpri_board_confs); i++) {
196 board_prio = &da8xx_mstpri_board_confs[i];
198 if (of_machine_is_compatible(board_prio->board))
205 static int da8xx_mstpri_probe(struct platform_device *pdev)
207 const struct da8xx_mstpri_board_priorities *prio_list;
208 const struct da8xx_mstpri_descr *prio_descr;
209 const struct da8xx_mstpri_priority *prio;
210 struct device *dev = &pdev->dev;
211 struct resource *res;
212 void __iomem *mstpri;
216 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
217 mstpri = devm_ioremap_resource(dev, res);
218 if (IS_ERR(mstpri)) {
219 dev_err(dev, "unable to map MSTPRI registers\n");
220 return PTR_ERR(mstpri);
223 prio_list = da8xx_mstpri_get_board_prio();
225 dev_err(dev, "no master priorities defined for this board\n");
229 for (i = 0; i < prio_list->numprio; i++) {
230 prio = &prio_list->priorities[i];
231 prio_descr = &da8xx_mstpri_priority_list[prio->which];
233 if (prio_descr->reg + sizeof(u32) > resource_size(res)) {
234 dev_warn(dev, "register offset out of range\n");
238 reg = readl(mstpri + prio_descr->reg);
239 reg &= ~prio_descr->mask;
240 reg |= prio->val << prio_descr->shift;
242 writel(reg, mstpri + prio_descr->reg);
248 static const struct of_device_id da8xx_mstpri_of_match[] = {
249 { .compatible = "ti,da850-mstpri", },
253 static struct platform_driver da8xx_mstpri_driver = {
254 .probe = da8xx_mstpri_probe,
256 .name = "da8xx-mstpri",
257 .of_match_table = da8xx_mstpri_of_match,
260 module_platform_driver(da8xx_mstpri_driver);
262 MODULE_AUTHOR("Bartosz Golaszewski <bgolaszewski@baylibre.com>");
263 MODULE_DESCRIPTION("TI da8xx master peripheral priority driver");
264 MODULE_LICENSE("GPL v2");