summaryrefslogtreecommitdiff
path: root/arch/arm/mach-mx51/sdram_autogating.c
blob: 1d47e5aaf606edd6b2ed89112667244189d6846a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
 */

/*
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 */

/*!
 * @file sdram_autogating.c
 *
 * @brief Enable auto clock gating of the EMI_FAST clock using M4IF.
 *
 * The APIs are for enabling and disabling automatic clock gating of EMI_FAST.
 *
 * @ingroup PM
 */
#include <asm/io.h>
#include <linux/proc_fs.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
#include <mach/hardware.h>
#include <mach/clock.h>
#include <mach/mxc_dvfs.h>
#include "crm_regs.h"

int sdram_autogating_is_active;
static struct device *sdram_autogating_dev;
#define M4IF_CNTL_REG0		0x8c
#define M4IF_CNTL_REG1		0x90

void enable_sdram_autogating(void);
void disable_sdram_autogating(void);

void enable_sdram_autogating()
{
	u32 reg;

	/* Set the Fast arbitration Power saving timer */
	reg = __raw_readl((IO_ADDRESS(M4IF_BASE_ADDR) + M4IF_CNTL_REG1));
	reg &= ~0xFF;
	reg |= 0x09;
	__raw_writel(reg, (IO_ADDRESS(M4IF_BASE_ADDR) + M4IF_CNTL_REG1));
	/*Allow for automatic gating of the EMI internal clock.
	 * If this is done, emi_intr CCGR bits should be set to 11.
	 */
	reg = __raw_readl((IO_ADDRESS(M4IF_BASE_ADDR) + M4IF_CNTL_REG0));
	reg &= ~0x5;
	__raw_writel(reg, (IO_ADDRESS(M4IF_BASE_ADDR) + M4IF_CNTL_REG0));

	sdram_autogating_is_active = 1;
}

void disable_sdram_autogating()
{
	u32 reg;

	reg = __raw_readl((IO_ADDRESS(M4IF_BASE_ADDR) + M4IF_CNTL_REG0));
	reg |= 0x4;
	__raw_writel(reg, (IO_ADDRESS(M4IF_BASE_ADDR) + M4IF_CNTL_REG0));
	sdram_autogating_is_active = 0;
}

static ssize_t sdram_autogating_enable_show(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	if (sdram_autogating_is_active)
		return sprintf(buf,
			"M4IF autoclock gating for EMI_FAST enabled\n");
	else
		return sprintf(buf,
			"M4IF autoclock gating for EMI_FAST disabled\n");
}

static ssize_t sdram_autogating_enable_store(struct device *dev,
				 struct device_attribute *attr,
				 const char *buf, size_t size)
{
	if (strstr(buf, "1") != NULL)
		enable_sdram_autogating();
	else if (strstr(buf, "0") != NULL) {
		if (sdram_autogating_is_active)
			disable_sdram_autogating();
	}
	return size;
}

static DEVICE_ATTR(enable, 0644, sdram_autogating_enable_show,
			sdram_autogating_enable_store);

/*!
 * This is the probe routine for the auto clockgating of sdram driver.
 *
 * @param   pdev   The platform device structure
 *
 * @return         The function returns 0 on success
 *
 */
static int __devinit sdram_autogating_probe(struct platform_device *pdev)
{
	int err = 0;

	sdram_autogating_dev = &pdev->dev;

	err = sysfs_create_file(&sdram_autogating_dev->kobj,
							&dev_attr_enable.attr);
	if (err) {
		printk(KERN_ERR
		       "Unable to register sysdev entry for sdram_autogating");
		return err;
	}

	sdram_autogating_is_active = 0;
	if (mxc_cpu_is_rev(CHIP_REV_3_0) >= 1)
		enable_sdram_autogating();
	return 0;
}

static struct platform_driver sdram_autogating_driver = {
	.driver = {
		   .name = "sdram_autogating",
		},
	.probe = sdram_autogating_probe,
};

/*!
 * Initialise the sdram_autogating_driver.
 *
 * @return  The function always returns 0.
 */

static int __init sdram_autogating_init(void)
{
	if (platform_driver_register(&sdram_autogating_driver) != 0) {
		printk(KERN_ERR "sdram_autogating_driver register failed\n");
		return -ENODEV;
	}

	printk(KERN_INFO "sdram autogating driver module loaded\n");
	return 0;
}

static void __exit sdram_autogating_cleanup(void)
{
	sysfs_remove_file(&sdram_autogating_dev->kobj, &dev_attr_enable.attr);

	/* Unregister the device structure */
	platform_driver_unregister(&sdram_autogating_driver);
}

module_init(sdram_autogating_init);
module_exit(sdram_autogating_cleanup);

MODULE_AUTHOR("Freescale Semiconductor, Inc.");
MODULE_DESCRIPTION("sdram_autogating driver");
MODULE_LICENSE("GPL");