Commit 117053f7 authored by Vasanth Ananthan's avatar Vasanth Ananthan Committed by Wolfram Sang

i2c: s3c2410: Add polling mode support

This patch adds polling mode support for i2c-s3c2410 driver.The
SATA PHY controller's CMU and TRSV block's are of I2C register
map in exynos5250.These blocks can be configured using i2c.

But i2c controller instance on which these block's sits lacks an
interrupt line.Also the current i2c-s3c2410 driver is only interrupt
driven, thus a polling mode support is required in the driver for
supporting this controller. This patch adds this support to the driver.
Signed-off-by: default avatarVasanth Ananthan <vasanth.a@samsung.com>
Signed-off-by: default avatarYuvaraj Kumar C D <yuvaraj.cd@samsung.com>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent 46a4e737
...@@ -10,6 +10,8 @@ Required properties: ...@@ -10,6 +10,8 @@ Required properties:
inside HDMIPHY block found on several samsung SoCs inside HDMIPHY block found on several samsung SoCs
(d) "samsung, exynos5440-i2c", for s3c2440-like i2c used (d) "samsung, exynos5440-i2c", for s3c2440-like i2c used
on EXYNOS5440 which does not need GPIO configuration. on EXYNOS5440 which does not need GPIO configuration.
(e) "samsung, exynos5-sata-phy-i2c", for s3c2440-like i2c used as
a host to SATA PHY controller on an internal bus.
- reg: physical base address of the controller and length of memory mapped - reg: physical base address of the controller and length of memory mapped
region. region.
- interrupts: interrupt number to the cpu. - interrupts: interrupt number to the cpu.
......
...@@ -86,6 +86,7 @@ ...@@ -86,6 +86,7 @@
#define QUIRK_S3C2440 (1 << 0) #define QUIRK_S3C2440 (1 << 0)
#define QUIRK_HDMIPHY (1 << 1) #define QUIRK_HDMIPHY (1 << 1)
#define QUIRK_NO_GPIO (1 << 2) #define QUIRK_NO_GPIO (1 << 2)
#define QUIRK_POLL (1 << 3)
/* Max time to wait for bus to become idle after a xfer (in us) */ /* Max time to wait for bus to become idle after a xfer (in us) */
#define S3C2410_IDLE_TIMEOUT 5000 #define S3C2410_IDLE_TIMEOUT 5000
...@@ -142,6 +143,8 @@ static struct platform_device_id s3c24xx_driver_ids[] = { ...@@ -142,6 +143,8 @@ static struct platform_device_id s3c24xx_driver_ids[] = {
}; };
MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids); MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids);
static int i2c_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat);
#ifdef CONFIG_OF #ifdef CONFIG_OF
static const struct of_device_id s3c24xx_i2c_match[] = { static const struct of_device_id s3c24xx_i2c_match[] = {
{ .compatible = "samsung,s3c2410-i2c", .data = (void *)0 }, { .compatible = "samsung,s3c2410-i2c", .data = (void *)0 },
...@@ -150,6 +153,8 @@ static const struct of_device_id s3c24xx_i2c_match[] = { ...@@ -150,6 +153,8 @@ static const struct of_device_id s3c24xx_i2c_match[] = {
.data = (void *)(QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO) }, .data = (void *)(QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO) },
{ .compatible = "samsung,exynos5440-i2c", { .compatible = "samsung,exynos5440-i2c",
.data = (void *)(QUIRK_S3C2440 | QUIRK_NO_GPIO) }, .data = (void *)(QUIRK_S3C2440 | QUIRK_NO_GPIO) },
{ .compatible = "samsung,exynos5-sata-phy-i2c",
.data = (void *)(QUIRK_S3C2440 | QUIRK_POLL | QUIRK_NO_GPIO) },
{}, {},
}; };
MODULE_DEVICE_TABLE(of, s3c24xx_i2c_match); MODULE_DEVICE_TABLE(of, s3c24xx_i2c_match);
...@@ -188,7 +193,8 @@ static inline void s3c24xx_i2c_master_complete(struct s3c24xx_i2c *i2c, int ret) ...@@ -188,7 +193,8 @@ static inline void s3c24xx_i2c_master_complete(struct s3c24xx_i2c *i2c, int ret)
if (ret) if (ret)
i2c->msg_idx = ret; i2c->msg_idx = ret;
wake_up(&i2c->wait); if (!(i2c->quirks & QUIRK_POLL))
wake_up(&i2c->wait);
} }
static inline void s3c24xx_i2c_disable_ack(struct s3c24xx_i2c *i2c) static inline void s3c24xx_i2c_disable_ack(struct s3c24xx_i2c *i2c)
...@@ -225,6 +231,22 @@ static inline void s3c24xx_i2c_enable_irq(struct s3c24xx_i2c *i2c) ...@@ -225,6 +231,22 @@ static inline void s3c24xx_i2c_enable_irq(struct s3c24xx_i2c *i2c)
writel(tmp | S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON); writel(tmp | S3C2410_IICCON_IRQEN, i2c->regs + S3C2410_IICCON);
} }
static bool is_ack(struct s3c24xx_i2c *i2c)
{
int tries;
for (tries = 50; tries; --tries) {
if (readl(i2c->regs + S3C2410_IICCON)
& S3C2410_IICCON_IRQPEND) {
if (!(readl(i2c->regs + S3C2410_IICSTAT)
& S3C2410_IICSTAT_LASTBIT))
return true;
}
usleep_range(1000, 2000);
}
dev_err(i2c->dev, "ack was not recieved\n");
return false;
}
/* s3c24xx_i2c_message_start /* s3c24xx_i2c_message_start
* *
...@@ -269,6 +291,16 @@ static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c, ...@@ -269,6 +291,16 @@ static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c,
stat |= S3C2410_IICSTAT_START; stat |= S3C2410_IICSTAT_START;
writel(stat, i2c->regs + S3C2410_IICSTAT); writel(stat, i2c->regs + S3C2410_IICSTAT);
if (i2c->quirks & QUIRK_POLL) {
while ((i2c->msg_num != 0) && is_ack(i2c)) {
i2c_s3c_irq_nextbyte(i2c, stat);
stat = readl(i2c->regs + S3C2410_IICSTAT);
if (stat & S3C2410_IICSTAT_ARBITR)
dev_err(i2c->dev, "deal with arbitration loss\n");
}
}
} }
static inline void s3c24xx_i2c_stop(struct s3c24xx_i2c *i2c, int ret) static inline void s3c24xx_i2c_stop(struct s3c24xx_i2c *i2c, int ret)
...@@ -676,6 +708,15 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, ...@@ -676,6 +708,15 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c,
s3c24xx_i2c_enable_irq(i2c); s3c24xx_i2c_enable_irq(i2c);
s3c24xx_i2c_message_start(i2c, msgs); s3c24xx_i2c_message_start(i2c, msgs);
if (i2c->quirks & QUIRK_POLL) {
ret = i2c->msg_idx;
if (ret != num)
dev_dbg(i2c->dev, "incomplete xfer (%d)\n", ret);
goto out;
}
timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5);
ret = i2c->msg_idx; ret = i2c->msg_idx;
...@@ -821,6 +862,9 @@ static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got) ...@@ -821,6 +862,9 @@ static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got)
if (div1 == 512) if (div1 == 512)
iiccon |= S3C2410_IICCON_TXDIV_512; iiccon |= S3C2410_IICCON_TXDIV_512;
if (i2c->quirks & QUIRK_POLL)
iiccon |= S3C2410_IICCON_SCALE(2);
writel(iiccon, i2c->regs + S3C2410_IICCON); writel(iiccon, i2c->regs + S3C2410_IICCON);
if (i2c->quirks & QUIRK_S3C2440) { if (i2c->quirks & QUIRK_S3C2440) {
...@@ -1118,18 +1162,20 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) ...@@ -1118,18 +1162,20 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
* ensure no current IRQs pending * ensure no current IRQs pending
*/ */
i2c->irq = ret = platform_get_irq(pdev, 0); if (!(i2c->quirks & QUIRK_POLL)) {
if (ret <= 0) { i2c->irq = ret = platform_get_irq(pdev, 0);
dev_err(&pdev->dev, "cannot find IRQ\n"); if (ret <= 0) {
return ret; dev_err(&pdev->dev, "cannot find IRQ\n");
} return ret;
}
ret = devm_request_irq(&pdev->dev, i2c->irq, s3c24xx_i2c_irq, 0, ret = devm_request_irq(&pdev->dev, i2c->irq, s3c24xx_i2c_irq, 0,
dev_name(&pdev->dev), i2c); dev_name(&pdev->dev), i2c);
if (ret != 0) { if (ret != 0) {
dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq); dev_err(&pdev->dev, "cannot claim IRQ %d\n", i2c->irq);
return ret; return ret;
}
} }
ret = s3c24xx_i2c_register_cpufreq(i2c); ret = s3c24xx_i2c_register_cpufreq(i2c);
......
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