1 // SPDX-License-Identifier: GPL-2.0-only
3 * TI da8xx DDR2/mDDR controller driver
5 * Copyright (C) 2016 BayLibre SAS
8 * Bartosz Golaszewski <bgolaszewski@baylibre.com>
11 #include <linux/module.h>
13 #include <linux/of_device.h>
14 #include <linux/platform_device.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 struct da8xx_ddrctl_config_knob {
36 static const struct da8xx_ddrctl_config_knob da8xx_ddrctl_knobs[] = {
38 .name = "da850-pbbpr",
45 struct da8xx_ddrctl_setting {
50 struct da8xx_ddrctl_board_settings {
52 const struct da8xx_ddrctl_setting *settings;
55 static const struct da8xx_ddrctl_setting da850_lcdk_ddrctl_settings[] = {
57 .name = "da850-pbbpr",
63 static const struct da8xx_ddrctl_board_settings da8xx_ddrctl_board_confs[] = {
65 .board = "ti,da850-lcdk",
66 .settings = da850_lcdk_ddrctl_settings,
70 static const struct da8xx_ddrctl_config_knob *
71 da8xx_ddrctl_match_knob(const struct da8xx_ddrctl_setting *setting)
73 const struct da8xx_ddrctl_config_knob *knob;
76 for (i = 0; i < ARRAY_SIZE(da8xx_ddrctl_knobs); i++) {
77 knob = &da8xx_ddrctl_knobs[i];
79 if (strcmp(knob->name, setting->name) == 0)
86 static const struct da8xx_ddrctl_setting *da8xx_ddrctl_get_board_settings(void)
88 const struct da8xx_ddrctl_board_settings *board_settings;
91 for (i = 0; i < ARRAY_SIZE(da8xx_ddrctl_board_confs); i++) {
92 board_settings = &da8xx_ddrctl_board_confs[i];
94 if (of_machine_is_compatible(board_settings->board))
95 return board_settings->settings;
101 static int da8xx_ddrctl_probe(struct platform_device *pdev)
103 const struct da8xx_ddrctl_config_knob *knob;
104 const struct da8xx_ddrctl_setting *setting;
105 struct resource *res;
106 void __iomem *ddrctl;
112 setting = da8xx_ddrctl_get_board_settings();
114 dev_err(dev, "no settings defined for this board\n");
118 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
119 ddrctl = devm_ioremap_resource(dev, res);
120 if (IS_ERR(ddrctl)) {
121 dev_err(dev, "unable to map memory controller registers\n");
122 return PTR_ERR(ddrctl);
125 for (; setting->name; setting++) {
126 knob = da8xx_ddrctl_match_knob(setting);
129 "no such config option: %s\n", setting->name);
133 if (knob->reg + sizeof(u32) > resource_size(res)) {
135 "register offset of '%s' exceeds mapped memory size\n",
140 reg = readl(ddrctl + knob->reg);
142 reg |= setting->val << knob->shift;
144 dev_dbg(dev, "writing 0x%08x to %s\n", reg, setting->name);
146 writel(reg, ddrctl + knob->reg);
152 static const struct of_device_id da8xx_ddrctl_of_match[] = {
153 { .compatible = "ti,da850-ddr-controller", },
157 static struct platform_driver da8xx_ddrctl_driver = {
158 .probe = da8xx_ddrctl_probe,
160 .name = "da850-ddr-controller",
161 .of_match_table = da8xx_ddrctl_of_match,
164 module_platform_driver(da8xx_ddrctl_driver);
166 MODULE_AUTHOR("Bartosz Golaszewski <bgolaszewski@baylibre.com>");
167 MODULE_DESCRIPTION("TI da8xx DDR2/mDDR controller driver");
168 MODULE_LICENSE("GPL v2");