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/platform_device.h>
17 * REVISIT: Linux doesn't have a good framework for the kind of performance
18 * knobs this driver controls. We can't use device tree properties as it deals
19 * with hardware configuration rather than description. We also don't want to
20 * commit to maintaining some random sysfs attributes.
22 * For now we just hardcode the register values for the boards that need
23 * some changes (as is the case for the LCD controller on da850-lcdk - the
24 * first board we support here). When linux gets an appropriate framework,
25 * we'll easily convert the driver to it.
28 struct da8xx_ddrctl_config_knob {
35 static const struct da8xx_ddrctl_config_knob da8xx_ddrctl_knobs[] = {
37 .name = "da850-pbbpr",
44 struct da8xx_ddrctl_setting {
49 struct da8xx_ddrctl_board_settings {
51 const struct da8xx_ddrctl_setting *settings;
54 static const struct da8xx_ddrctl_setting da850_lcdk_ddrctl_settings[] = {
56 .name = "da850-pbbpr",
62 static const struct da8xx_ddrctl_board_settings da8xx_ddrctl_board_confs[] = {
64 .board = "ti,da850-lcdk",
65 .settings = da850_lcdk_ddrctl_settings,
69 static const struct da8xx_ddrctl_config_knob *
70 da8xx_ddrctl_match_knob(const struct da8xx_ddrctl_setting *setting)
72 const struct da8xx_ddrctl_config_knob *knob;
75 for (i = 0; i < ARRAY_SIZE(da8xx_ddrctl_knobs); i++) {
76 knob = &da8xx_ddrctl_knobs[i];
78 if (strcmp(knob->name, setting->name) == 0)
85 static const struct da8xx_ddrctl_setting *da8xx_ddrctl_get_board_settings(void)
87 const struct da8xx_ddrctl_board_settings *board_settings;
90 for (i = 0; i < ARRAY_SIZE(da8xx_ddrctl_board_confs); i++) {
91 board_settings = &da8xx_ddrctl_board_confs[i];
93 if (of_machine_is_compatible(board_settings->board))
94 return board_settings->settings;
100 static int da8xx_ddrctl_probe(struct platform_device *pdev)
102 const struct da8xx_ddrctl_config_knob *knob;
103 const struct da8xx_ddrctl_setting *setting;
104 struct resource *res;
105 void __iomem *ddrctl;
111 setting = da8xx_ddrctl_get_board_settings();
113 dev_err(dev, "no settings defined for this board\n");
117 ddrctl = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
118 if (IS_ERR(ddrctl)) {
119 dev_err(dev, "unable to map memory controller registers\n");
120 return PTR_ERR(ddrctl);
123 for (; setting->name; setting++) {
124 knob = da8xx_ddrctl_match_knob(setting);
127 "no such config option: %s\n", setting->name);
131 if (knob->reg + sizeof(u32) > resource_size(res)) {
133 "register offset of '%s' exceeds mapped memory size\n",
138 reg = readl(ddrctl + knob->reg);
140 reg |= setting->val << knob->shift;
142 dev_dbg(dev, "writing 0x%08x to %s\n", reg, setting->name);
144 writel(reg, ddrctl + knob->reg);
150 static const struct of_device_id da8xx_ddrctl_of_match[] = {
151 { .compatible = "ti,da850-ddr-controller", },
155 static struct platform_driver da8xx_ddrctl_driver = {
156 .probe = da8xx_ddrctl_probe,
158 .name = "da850-ddr-controller",
159 .of_match_table = da8xx_ddrctl_of_match,
162 module_platform_driver(da8xx_ddrctl_driver);
164 MODULE_AUTHOR("Bartosz Golaszewski <bgolaszewski@baylibre.com>");
165 MODULE_DESCRIPTION("TI da8xx DDR2/mDDR controller driver");