2005-08-18 11:08:15 +02:00
|
|
|
/*
|
|
|
|
* linux/drivers/mfd/mcp-sa11x0.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001-2005 Russell King
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License.
|
|
|
|
*
|
|
|
|
* SA11x0 MCP (Multimedia Communications Port) driver.
|
|
|
|
*
|
|
|
|
* MCP read/write timeouts from Jordi Colomer, rehacked by rmk.
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/spinlock.h>
|
2005-10-29 20:07:23 +02:00
|
|
|
#include <linux/platform_device.h>
|
2009-02-10 14:54:57 +01:00
|
|
|
#include <linux/mfd/mcp.h>
|
2011-11-27 22:00:55 +01:00
|
|
|
#include <linux/io.h>
|
2005-08-18 11:08:15 +02:00
|
|
|
|
2008-11-29 12:40:28 +01:00
|
|
|
#include <mach/dma.h>
|
2008-08-05 17:14:15 +02:00
|
|
|
#include <mach/hardware.h>
|
2005-08-18 11:08:15 +02:00
|
|
|
#include <asm/mach-types.h>
|
|
|
|
#include <asm/system.h>
|
2008-08-05 17:14:15 +02:00
|
|
|
#include <mach/mcp.h>
|
2005-08-18 11:08:15 +02:00
|
|
|
|
2011-11-27 22:00:55 +01:00
|
|
|
/* Register offsets */
|
|
|
|
#define MCCR0 0x00
|
|
|
|
#define MCDR0 0x08
|
|
|
|
#define MCDR1 0x0C
|
|
|
|
#define MCDR2 0x10
|
|
|
|
#define MCSR 0x18
|
|
|
|
#define MCCR1 0x00
|
2005-08-18 11:08:15 +02:00
|
|
|
|
|
|
|
struct mcp_sa11x0 {
|
2011-11-27 22:00:55 +01:00
|
|
|
u32 mccr0;
|
|
|
|
u32 mccr1;
|
|
|
|
unsigned char *mccr0_base;
|
|
|
|
unsigned char *mccr1_base;
|
2005-08-18 11:08:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define priv(mcp) ((struct mcp_sa11x0 *)mcp_priv(mcp))
|
|
|
|
|
|
|
|
static void
|
|
|
|
mcp_sa11x0_set_telecom_divisor(struct mcp *mcp, unsigned int divisor)
|
|
|
|
{
|
2011-11-27 22:00:55 +01:00
|
|
|
struct mcp_sa11x0 *priv = priv(mcp);
|
2005-08-18 11:08:15 +02:00
|
|
|
|
|
|
|
divisor /= 32;
|
|
|
|
|
2011-11-27 22:00:55 +01:00
|
|
|
priv->mccr0 &= ~0x00007f00;
|
|
|
|
priv->mccr0 |= divisor << 8;
|
|
|
|
__raw_writel(priv->mccr0, priv->mccr0_base + MCCR0);
|
2005-08-18 11:08:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mcp_sa11x0_set_audio_divisor(struct mcp *mcp, unsigned int divisor)
|
|
|
|
{
|
2011-11-27 22:00:55 +01:00
|
|
|
struct mcp_sa11x0 *priv = priv(mcp);
|
2005-08-18 11:08:15 +02:00
|
|
|
|
|
|
|
divisor /= 32;
|
|
|
|
|
2011-11-27 22:00:55 +01:00
|
|
|
priv->mccr0 &= ~0x0000007f;
|
|
|
|
priv->mccr0 |= divisor;
|
|
|
|
__raw_writel(priv->mccr0, priv->mccr0_base + MCCR0);
|
2005-08-18 11:08:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write data to the device. The bit should be set after 3 subframe
|
|
|
|
* times (each frame is 64 clocks). We wait a maximum of 6 subframes.
|
|
|
|
* We really should try doing something more productive while we
|
|
|
|
* wait.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
mcp_sa11x0_write(struct mcp *mcp, unsigned int reg, unsigned int val)
|
|
|
|
{
|
|
|
|
int ret = -ETIME;
|
|
|
|
int i;
|
2011-11-27 22:00:55 +01:00
|
|
|
u32 mcpreg;
|
|
|
|
struct mcp_sa11x0 *priv = priv(mcp);
|
2005-08-18 11:08:15 +02:00
|
|
|
|
2011-11-27 22:00:55 +01:00
|
|
|
mcpreg = reg << 17 | MCDR2_Wr | (val & 0xffff);
|
|
|
|
__raw_writel(mcpreg, priv->mccr0_base + MCDR2);
|
2005-08-18 11:08:15 +02:00
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
udelay(mcp->rw_timeout);
|
2011-11-27 22:00:55 +01:00
|
|
|
mcpreg = __raw_readl(priv->mccr0_base + MCSR);
|
|
|
|
if (mcpreg & MCSR_CWC) {
|
2005-08-18 11:08:15 +02:00
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
printk(KERN_WARNING "mcp: write timed out\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read data from the device. The bit should be set after 3 subframe
|
|
|
|
* times (each frame is 64 clocks). We wait a maximum of 6 subframes.
|
|
|
|
* We really should try doing something more productive while we
|
|
|
|
* wait.
|
|
|
|
*/
|
|
|
|
static unsigned int
|
|
|
|
mcp_sa11x0_read(struct mcp *mcp, unsigned int reg)
|
|
|
|
{
|
|
|
|
int ret = -ETIME;
|
|
|
|
int i;
|
2011-11-27 22:00:55 +01:00
|
|
|
u32 mcpreg;
|
|
|
|
struct mcp_sa11x0 *priv = priv(mcp);
|
2005-08-18 11:08:15 +02:00
|
|
|
|
2011-11-27 22:00:55 +01:00
|
|
|
mcpreg = reg << 17 | MCDR2_Rd;
|
|
|
|
__raw_writel(mcpreg, priv->mccr0_base + MCDR2);
|
2005-08-18 11:08:15 +02:00
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
udelay(mcp->rw_timeout);
|
2011-11-27 22:00:55 +01:00
|
|
|
mcpreg = __raw_readl(priv->mccr0_base + MCSR);
|
|
|
|
if (mcpreg & MCSR_CRC) {
|
|
|
|
ret = __raw_readl(priv->mccr0_base + MCDR2)
|
|
|
|
& 0xffff;
|
2005-08-18 11:08:15 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
printk(KERN_WARNING "mcp: read timed out\n");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mcp_sa11x0_enable(struct mcp *mcp)
|
|
|
|
{
|
2011-11-27 22:00:55 +01:00
|
|
|
struct mcp_sa11x0 *priv = priv(mcp);
|
|
|
|
|
|
|
|
__raw_writel(-1, priv->mccr0_base + MCSR);
|
|
|
|
priv->mccr0 |= MCCR0_MCE;
|
|
|
|
__raw_writel(priv->mccr0, priv->mccr0_base + MCCR0);
|
2005-08-18 11:08:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mcp_sa11x0_disable(struct mcp *mcp)
|
|
|
|
{
|
2011-11-27 22:00:55 +01:00
|
|
|
struct mcp_sa11x0 *priv = priv(mcp);
|
|
|
|
|
|
|
|
priv->mccr0 &= ~MCCR0_MCE;
|
|
|
|
__raw_writel(priv->mccr0, priv->mccr0_base + MCCR0);
|
2005-08-18 11:08:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our methods.
|
|
|
|
*/
|
|
|
|
static struct mcp_ops mcp_sa11x0 = {
|
|
|
|
.set_telecom_divisor = mcp_sa11x0_set_telecom_divisor,
|
|
|
|
.set_audio_divisor = mcp_sa11x0_set_audio_divisor,
|
|
|
|
.reg_write = mcp_sa11x0_write,
|
|
|
|
.reg_read = mcp_sa11x0_read,
|
|
|
|
.enable = mcp_sa11x0_enable,
|
|
|
|
.disable = mcp_sa11x0_disable,
|
|
|
|
};
|
|
|
|
|
2005-11-09 23:32:44 +01:00
|
|
|
static int mcp_sa11x0_probe(struct platform_device *pdev)
|
2005-08-18 11:08:15 +02:00
|
|
|
{
|
2005-08-18 11:10:46 +02:00
|
|
|
struct mcp_plat_data *data = pdev->dev.platform_data;
|
2005-08-18 11:08:15 +02:00
|
|
|
struct mcp *mcp;
|
|
|
|
int ret;
|
2011-11-27 22:00:55 +01:00
|
|
|
struct mcp_sa11x0 *priv;
|
|
|
|
struct resource *res_mem0, *res_mem1;
|
|
|
|
u32 size0, size1;
|
2005-08-18 11:08:15 +02:00
|
|
|
|
2005-08-18 11:10:46 +02:00
|
|
|
if (!data)
|
2005-08-18 11:08:15 +02:00
|
|
|
return -ENODEV;
|
|
|
|
|
2011-11-27 22:00:54 +01:00
|
|
|
if (!data->codec)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2011-11-27 22:00:55 +01:00
|
|
|
res_mem0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!res_mem0)
|
|
|
|
return -ENODEV;
|
|
|
|
size0 = res_mem0->end - res_mem0->start + 1;
|
|
|
|
|
|
|
|
res_mem1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
|
|
|
|
if (!res_mem1)
|
|
|
|
return -ENODEV;
|
|
|
|
size1 = res_mem1->end - res_mem1->start + 1;
|
|
|
|
|
|
|
|
if (!request_mem_region(res_mem0->start, size0, "sa11x0-mcp"))
|
2005-08-18 11:08:15 +02:00
|
|
|
return -EBUSY;
|
|
|
|
|
2011-11-27 22:00:55 +01:00
|
|
|
if (!request_mem_region(res_mem1->start, size1, "sa11x0-mcp")) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
|
2005-08-18 11:08:15 +02:00
|
|
|
mcp = mcp_host_alloc(&pdev->dev, sizeof(struct mcp_sa11x0));
|
|
|
|
if (!mcp) {
|
|
|
|
ret = -ENOMEM;
|
2011-11-27 22:00:55 +01:00
|
|
|
goto release2;
|
2005-08-18 11:08:15 +02:00
|
|
|
}
|
|
|
|
|
2011-11-27 22:00:55 +01:00
|
|
|
priv = priv(mcp);
|
|
|
|
|
2005-08-18 11:08:15 +02:00
|
|
|
mcp->owner = THIS_MODULE;
|
|
|
|
mcp->ops = &mcp_sa11x0;
|
2005-08-18 11:10:46 +02:00
|
|
|
mcp->sclk_rate = data->sclk_rate;
|
2011-11-27 22:00:55 +01:00
|
|
|
mcp->dma_audio_rd = DDAR_DevAdd(res_mem0->start + MCDR0)
|
|
|
|
+ DDAR_DevRd + DDAR_Brst4 + DDAR_8BitDev;
|
|
|
|
mcp->dma_audio_wr = DDAR_DevAdd(res_mem0->start + MCDR0)
|
|
|
|
+ DDAR_DevWr + DDAR_Brst4 + DDAR_8BitDev;
|
|
|
|
mcp->dma_telco_rd = DDAR_DevAdd(res_mem0->start + MCDR1)
|
|
|
|
+ DDAR_DevRd + DDAR_Brst4 + DDAR_8BitDev;
|
|
|
|
mcp->dma_telco_wr = DDAR_DevAdd(res_mem0->start + MCDR1)
|
|
|
|
+ DDAR_DevWr + DDAR_Brst4 + DDAR_8BitDev;
|
2011-11-27 22:00:54 +01:00
|
|
|
mcp->codec = data->codec;
|
2005-08-18 11:08:15 +02:00
|
|
|
|
2005-11-09 23:32:44 +01:00
|
|
|
platform_set_drvdata(pdev, mcp);
|
2005-08-18 11:08:15 +02:00
|
|
|
|
2005-08-18 11:10:46 +02:00
|
|
|
/*
|
|
|
|
* Initialise device. Note that we initially
|
|
|
|
* set the sampling rate to minimum.
|
|
|
|
*/
|
2011-11-27 22:00:55 +01:00
|
|
|
priv->mccr0_base = ioremap(res_mem0->start, size0);
|
|
|
|
priv->mccr1_base = ioremap(res_mem1->start, size1);
|
|
|
|
|
|
|
|
__raw_writel(-1, priv->mccr0_base + MCSR);
|
|
|
|
priv->mccr1 = data->mccr1;
|
|
|
|
priv->mccr0 = data->mccr0 | 0x7f7f;
|
|
|
|
__raw_writel(priv->mccr0, priv->mccr0_base + MCCR0);
|
|
|
|
__raw_writel(priv->mccr1, priv->mccr1_base + MCCR1);
|
2005-08-18 11:08:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the read/write timeout (us) from the bit clock
|
|
|
|
* rate. This is the period for 3 64-bit frames. Always
|
|
|
|
* round this time up.
|
|
|
|
*/
|
|
|
|
mcp->rw_timeout = (64 * 3 * 1000000 + mcp->sclk_rate - 1) /
|
|
|
|
mcp->sclk_rate;
|
|
|
|
|
2011-11-27 22:00:54 +01:00
|
|
|
ret = mcp_host_register(mcp, data->codec_pdata);
|
2005-08-18 11:08:15 +02:00
|
|
|
if (ret == 0)
|
|
|
|
goto out;
|
|
|
|
|
2011-11-27 22:00:55 +01:00
|
|
|
release2:
|
|
|
|
release_mem_region(res_mem1->start, size1);
|
2005-08-18 11:08:15 +02:00
|
|
|
release:
|
2011-11-27 22:00:55 +01:00
|
|
|
release_mem_region(res_mem0->start, size0);
|
2005-11-09 23:32:44 +01:00
|
|
|
platform_set_drvdata(pdev, NULL);
|
2005-08-18 11:08:15 +02:00
|
|
|
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-27 22:00:55 +01:00
|
|
|
static int mcp_sa11x0_remove(struct platform_device *pdev)
|
2005-08-18 11:08:15 +02:00
|
|
|
{
|
2011-11-27 22:00:55 +01:00
|
|
|
struct mcp *mcp = platform_get_drvdata(pdev);
|
|
|
|
struct mcp_sa11x0 *priv = priv(mcp);
|
|
|
|
struct resource *res_mem;
|
|
|
|
u32 size;
|
2005-08-18 11:08:15 +02:00
|
|
|
|
2011-11-27 22:00:55 +01:00
|
|
|
platform_set_drvdata(pdev, NULL);
|
2005-08-18 11:08:15 +02:00
|
|
|
mcp_host_unregister(mcp);
|
|
|
|
|
2011-11-27 22:00:55 +01:00
|
|
|
res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (res_mem) {
|
|
|
|
size = res_mem->end - res_mem->start + 1;
|
|
|
|
release_mem_region(res_mem->start, size);
|
|
|
|
}
|
|
|
|
res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
|
|
|
|
if (res_mem) {
|
|
|
|
size = res_mem->end - res_mem->start + 1;
|
|
|
|
release_mem_region(res_mem->start, size);
|
|
|
|
}
|
|
|
|
iounmap(priv->mccr0_base);
|
|
|
|
iounmap(priv->mccr1_base);
|
2005-08-18 11:08:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-09 23:32:44 +01:00
|
|
|
static int mcp_sa11x0_suspend(struct platform_device *dev, pm_message_t state)
|
2005-08-18 11:08:15 +02:00
|
|
|
{
|
2005-11-09 23:32:44 +01:00
|
|
|
struct mcp *mcp = platform_get_drvdata(dev);
|
2011-11-27 22:00:55 +01:00
|
|
|
struct mcp_sa11x0 *priv = priv(mcp);
|
|
|
|
u32 mccr0;
|
2005-08-18 11:08:15 +02:00
|
|
|
|
2011-11-27 22:00:55 +01:00
|
|
|
mccr0 = priv->mccr0 & ~MCCR0_MCE;
|
|
|
|
__raw_writel(mccr0, priv->mccr0_base + MCCR0);
|
2005-10-28 18:52:56 +02:00
|
|
|
|
2005-08-18 11:08:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-09 23:32:44 +01:00
|
|
|
static int mcp_sa11x0_resume(struct platform_device *dev)
|
2005-08-18 11:08:15 +02:00
|
|
|
{
|
2005-11-09 23:32:44 +01:00
|
|
|
struct mcp *mcp = platform_get_drvdata(dev);
|
2011-11-27 22:00:55 +01:00
|
|
|
struct mcp_sa11x0 *priv = priv(mcp);
|
2005-08-18 11:08:15 +02:00
|
|
|
|
2011-11-27 22:00:55 +01:00
|
|
|
__raw_writel(priv->mccr0, priv->mccr0_base + MCCR0);
|
|
|
|
__raw_writel(priv->mccr1, priv->mccr1_base + MCCR1);
|
2005-10-28 18:52:56 +02:00
|
|
|
|
2005-08-18 11:08:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The driver for the SA11x0 MCP port.
|
|
|
|
*/
|
2008-07-25 10:45:47 +02:00
|
|
|
MODULE_ALIAS("platform:sa11x0-mcp");
|
|
|
|
|
2005-11-09 23:32:44 +01:00
|
|
|
static struct platform_driver mcp_sa11x0_driver = {
|
2005-08-18 11:08:15 +02:00
|
|
|
.probe = mcp_sa11x0_probe,
|
|
|
|
.remove = mcp_sa11x0_remove,
|
|
|
|
.suspend = mcp_sa11x0_suspend,
|
|
|
|
.resume = mcp_sa11x0_resume,
|
2005-11-09 23:32:44 +01:00
|
|
|
.driver = {
|
|
|
|
.name = "sa11x0-mcp",
|
2011-11-27 22:00:55 +01:00
|
|
|
.owner = THIS_MODULE,
|
2005-11-09 23:32:44 +01:00
|
|
|
},
|
2005-08-18 11:08:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This needs re-working
|
|
|
|
*/
|
2011-11-23 23:58:34 +01:00
|
|
|
module_platform_driver(mcp_sa11x0_driver);
|
2005-08-18 11:08:15 +02:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
|
|
|
|
MODULE_DESCRIPTION("SA11x0 multimedia communications port driver");
|
|
|
|
MODULE_LICENSE("GPL");
|