2 * TI da8xx DDR2/mDDR controller driver
4 * Copyright (C) 2016 BayLibre SAS
7 * Bartosz Golaszewski <bgolaszewski@baylibre.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/module.h>
16 #include <linux/of_device.h>
17 #include <linux/platform_device.h>
21 * REVISIT: Linux doesn't have a good framework for the kind of performance
22 * knobs this driver controls. We can't use device tree properties as it deals
23 * with hardware configuration rather than description. We also don't want to
24 * commit to maintaining some random sysfs attributes.
26 * For now we just hardcode the register values for the boards that need
27 * some changes (as is the case for the LCD controller on da850-lcdk - the
28 * first board we support here). When linux gets an appropriate framework,
29 * we'll easily convert the driver to it.
32 struct da8xx_ddrctl_config_knob
{
39 static const struct da8xx_ddrctl_config_knob da8xx_ddrctl_knobs
[] = {
41 .name
= "da850-pbbpr",
48 struct da8xx_ddrctl_setting
{
53 struct da8xx_ddrctl_board_settings
{
55 const struct da8xx_ddrctl_setting
*settings
;
58 static const struct da8xx_ddrctl_setting da850_lcdk_ddrctl_settings
[] = {
60 .name
= "da850-pbbpr",
66 static const struct da8xx_ddrctl_board_settings da8xx_ddrctl_board_confs
[] = {
68 .board
= "ti,da850-lcdk",
69 .settings
= da850_lcdk_ddrctl_settings
,
73 static const struct da8xx_ddrctl_config_knob
*
74 da8xx_ddrctl_match_knob(const struct da8xx_ddrctl_setting
*setting
)
76 const struct da8xx_ddrctl_config_knob
*knob
;
79 for (i
= 0; i
< ARRAY_SIZE(da8xx_ddrctl_knobs
); i
++) {
80 knob
= &da8xx_ddrctl_knobs
[i
];
82 if (strcmp(knob
->name
, setting
->name
) == 0)
89 static const struct da8xx_ddrctl_setting
*da8xx_ddrctl_get_board_settings(void)
91 const struct da8xx_ddrctl_board_settings
*board_settings
;
94 for (i
= 0; i
< ARRAY_SIZE(da8xx_ddrctl_board_confs
); i
++) {
95 board_settings
= &da8xx_ddrctl_board_confs
[i
];
97 if (of_machine_is_compatible(board_settings
->board
))
98 return board_settings
->settings
;
104 static int da8xx_ddrctl_probe(struct platform_device
*pdev
)
106 const struct da8xx_ddrctl_config_knob
*knob
;
107 const struct da8xx_ddrctl_setting
*setting
;
108 struct device_node
*node
;
109 struct resource
*res
;
110 void __iomem
*ddrctl
;
117 setting
= da8xx_ddrctl_get_board_settings();
119 dev_err(dev
, "no settings defined for this board\n");
123 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
124 ddrctl
= devm_ioremap_resource(dev
, res
);
125 if (IS_ERR(ddrctl
)) {
126 dev_err(dev
, "unable to map memory controller registers\n");
127 return PTR_ERR(ddrctl
);
130 for (; setting
->name
; setting
++) {
131 knob
= da8xx_ddrctl_match_knob(setting
);
134 "no such config option: %s\n", setting
->name
);
138 if (knob
->reg
+ sizeof(u32
) > resource_size(res
)) {
140 "register offset of '%s' exceeds mapped memory size\n",
145 reg
= readl(ddrctl
+ knob
->reg
);
147 reg
|= setting
->val
<< knob
->shift
;
149 dev_dbg(dev
, "writing 0x%08x to %s\n", reg
, setting
->name
);
151 writel(reg
, ddrctl
+ knob
->reg
);
157 static const struct of_device_id da8xx_ddrctl_of_match
[] = {
158 { .compatible
= "ti,da850-ddr-controller", },
162 static struct platform_driver da8xx_ddrctl_driver
= {
163 .probe
= da8xx_ddrctl_probe
,
165 .name
= "da850-ddr-controller",
166 .of_match_table
= da8xx_ddrctl_of_match
,
169 module_platform_driver(da8xx_ddrctl_driver
);
171 MODULE_AUTHOR("Bartosz Golaszewski <bgolaszewski@baylibre.com>");
172 MODULE_DESCRIPTION("TI da8xx DDR2/mDDR controller driver");
173 MODULE_LICENSE("GPL v2");