Commit 17711dbf authored by Olof Johansson's avatar Olof Johansson

ARM: tegra: emc: convert tegra2_emc to a platform driver

This is the first step in making it device-tree aware and get rid of the
in-kernel EMC tables (of which there are none in mainline, thankfully).

Changes since v3:

* moved to devm_request_and_ioremap() in probe()

Changes since v2:

* D'oh -- missed a couple of variables that were added, never used and then
  later removed in a later patch.

Changes since v1:

* Fixed messed up indentation
* Removed code that should be gone (was added here and removed later in series)
Signed-off-by: default avatarOlof Johansson <olof@lixom.net>
Acked-by: default avatarStephen Warren <swarren@nvidia.com>
parent dee47183
...@@ -16,10 +16,13 @@ ...@@ -16,10 +16,13 @@
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/device.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/platform_data/tegra_emc.h>
#include <mach/iomap.h> #include <mach/iomap.h>
...@@ -32,18 +35,17 @@ static bool emc_enable; ...@@ -32,18 +35,17 @@ static bool emc_enable;
#endif #endif
module_param(emc_enable, bool, 0644); module_param(emc_enable, bool, 0644);
static void __iomem *emc = IO_ADDRESS(TEGRA_EMC_BASE); static struct platform_device *emc_pdev;
static const struct tegra_emc_table *tegra_emc_table; static void __iomem *emc_regbase;
static int tegra_emc_table_size;
static inline void emc_writel(u32 val, unsigned long addr) static inline void emc_writel(u32 val, unsigned long addr)
{ {
writel(val, emc + addr); writel(val, emc_regbase + addr);
} }
static inline u32 emc_readl(unsigned long addr) static inline u32 emc_readl(unsigned long addr)
{ {
return readl(emc + addr); return readl(emc_regbase + addr);
} }
static const unsigned long emc_reg_addr[TEGRA_EMC_NUM_REGS] = { static const unsigned long emc_reg_addr[TEGRA_EMC_NUM_REGS] = {
...@@ -98,15 +100,15 @@ static const unsigned long emc_reg_addr[TEGRA_EMC_NUM_REGS] = { ...@@ -98,15 +100,15 @@ static const unsigned long emc_reg_addr[TEGRA_EMC_NUM_REGS] = {
/* Select the closest EMC rate that is higher than the requested rate */ /* Select the closest EMC rate that is higher than the requested rate */
long tegra_emc_round_rate(unsigned long rate) long tegra_emc_round_rate(unsigned long rate)
{ {
struct tegra_emc_pdata *pdata;
int i; int i;
int best = -1; int best = -1;
unsigned long distance = ULONG_MAX; unsigned long distance = ULONG_MAX;
if (!tegra_emc_table) if (!emc_pdev)
return -EINVAL; return -EINVAL;
if (!emc_enable) pdata = emc_pdev->dev.platform_data;
return -EINVAL;
pr_debug("%s: %lu\n", __func__, rate); pr_debug("%s: %lu\n", __func__, rate);
...@@ -116,10 +118,10 @@ long tegra_emc_round_rate(unsigned long rate) ...@@ -116,10 +118,10 @@ long tegra_emc_round_rate(unsigned long rate)
*/ */
rate = rate / 2 / 1000; rate = rate / 2 / 1000;
for (i = 0; i < tegra_emc_table_size; i++) { for (i = 0; i < pdata->num_tables; i++) {
if (tegra_emc_table[i].rate >= rate && if (pdata->tables[i].rate >= rate &&
(tegra_emc_table[i].rate - rate) < distance) { (pdata->tables[i].rate - rate) < distance) {
distance = tegra_emc_table[i].rate - rate; distance = pdata->tables[i].rate - rate;
best = i; best = i;
} }
} }
...@@ -127,9 +129,9 @@ long tegra_emc_round_rate(unsigned long rate) ...@@ -127,9 +129,9 @@ long tegra_emc_round_rate(unsigned long rate)
if (best < 0) if (best < 0)
return -EINVAL; return -EINVAL;
pr_debug("%s: using %lu\n", __func__, tegra_emc_table[best].rate); pr_debug("%s: using %lu\n", __func__, pdata->tables[best].rate);
return tegra_emc_table[best].rate * 2 * 1000; return pdata->tables[best].rate * 2 * 1000;
} }
/* /*
...@@ -142,37 +144,81 @@ long tegra_emc_round_rate(unsigned long rate) ...@@ -142,37 +144,81 @@ long tegra_emc_round_rate(unsigned long rate)
*/ */
int tegra_emc_set_rate(unsigned long rate) int tegra_emc_set_rate(unsigned long rate)
{ {
struct tegra_emc_pdata *pdata;
int i; int i;
int j; int j;
if (!tegra_emc_table) if (!emc_pdev)
return -EINVAL; return -EINVAL;
pdata = emc_pdev->dev.platform_data;
/* /*
* The EMC clock rate is twice the bus rate, and the bus rate is * The EMC clock rate is twice the bus rate, and the bus rate is
* measured in kHz * measured in kHz
*/ */
rate = rate / 2 / 1000; rate = rate / 2 / 1000;
for (i = 0; i < tegra_emc_table_size; i++) for (i = 0; i < pdata->num_tables; i++)
if (tegra_emc_table[i].rate == rate) if (pdata->tables[i].rate == rate)
break; break;
if (i >= tegra_emc_table_size) if (i >= pdata->num_tables)
return -EINVAL; return -EINVAL;
pr_debug("%s: setting to %lu\n", __func__, rate); pr_debug("%s: setting to %lu\n", __func__, rate);
for (j = 0; j < TEGRA_EMC_NUM_REGS; j++) for (j = 0; j < TEGRA_EMC_NUM_REGS; j++)
emc_writel(tegra_emc_table[i].regs[j], emc_reg_addr[j]); emc_writel(pdata->tables[i].regs[j], emc_reg_addr[j]);
emc_readl(pdata->tables[i].regs[TEGRA_EMC_NUM_REGS - 1]);
return 0;
}
static int __devinit tegra_emc_probe(struct platform_device *pdev)
{
struct tegra_emc_pdata *pdata;
struct resource *res;
if (!emc_enable) {
dev_err(&pdev->dev, "disabled per module parameter\n");
return -ENODEV;
}
pdata = pdev->dev.platform_data;
emc_readl(tegra_emc_table[i].regs[TEGRA_EMC_NUM_REGS - 1]); if (!pdata) {
dev_err(&pdev->dev, "missing platform data\n");
return -ENXIO;
}
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(&pdev->dev, "missing register base\n");
return -ENOMEM;
}
emc_regbase = devm_request_and_ioremap(&pdev->dev, res);
if (!emc_regbase) {
dev_err(&pdev->dev, "failed to remap registers\n");
return -ENOMEM;
}
emc_pdev = pdev;
return 0; return 0;
} }
void tegra_init_emc(const struct tegra_emc_table *table, int table_size) static struct platform_driver tegra_emc_driver = {
.driver = {
.name = "tegra-emc",
.owner = THIS_MODULE,
},
.probe = tegra_emc_probe,
};
static int __init tegra_emc_init(void)
{ {
tegra_emc_table = table; return platform_driver_register(&tegra_emc_driver);
tegra_emc_table_size = table_size;
} }
device_initcall(tegra_emc_init);
...@@ -15,13 +15,10 @@ ...@@ -15,13 +15,10 @@
* *
*/ */
#define TEGRA_EMC_NUM_REGS 46 #ifndef __MACH_TEGRA_TEGRA2_EMC_H_
#define __MACH_TEGRA_TEGRA2_EMC_H
struct tegra_emc_table {
unsigned long rate;
u32 regs[TEGRA_EMC_NUM_REGS];
};
int tegra_emc_set_rate(unsigned long rate); int tegra_emc_set_rate(unsigned long rate);
long tegra_emc_round_rate(unsigned long rate); long tegra_emc_round_rate(unsigned long rate);
void tegra_init_emc(const struct tegra_emc_table *table, int table_size);
#endif
/*
* Copyright (C) 2011 Google, Inc.
*
* Author:
* Colin Cross <ccross@android.com>
* Olof Johansson <olof@lixom.net>
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef __TEGRA_EMC_H_
#define __TEGRA_EMC_H_
#define TEGRA_EMC_NUM_REGS 46
struct tegra_emc_table {
unsigned long rate;
u32 regs[TEGRA_EMC_NUM_REGS];
};
struct tegra_emc_pdata {
int num_tables;
struct tegra_emc_table *tables;
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment