diff options
Diffstat (limited to 'drivers/i2c/busses/i2c-s3c2410.c')
-rw-r--r-- | drivers/i2c/busses/i2c-s3c2410.c | 109 |
1 files changed, 65 insertions, 44 deletions
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index 737f7218a32c..fa0b13490873 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -44,8 +44,12 @@ #include <plat/regs-iic.h> #include <plat/iic.h> -/* i2c controller state */ +/* Treat S3C2410 as baseline hardware, anything else is supported via quirks */ +#define QUIRK_S3C2440 (1 << 0) +#define QUIRK_HDMIPHY (1 << 1) +#define QUIRK_NO_GPIO (1 << 2) +/* i2c controller state */ enum s3c24xx_i2c_state { STATE_IDLE, STATE_START, @@ -54,14 +58,10 @@ enum s3c24xx_i2c_state { STATE_STOP }; -enum s3c24xx_i2c_type { - TYPE_S3C2410, - TYPE_S3C2440, -}; - struct s3c24xx_i2c { spinlock_t lock; wait_queue_head_t wait; + unsigned int quirks; unsigned int suspended:1; struct i2c_msg *msg; @@ -88,26 +88,45 @@ struct s3c24xx_i2c { #endif }; -/* default platform data removed, dev should always carry data. */ +static struct platform_device_id s3c24xx_driver_ids[] = { + { + .name = "s3c2410-i2c", + .driver_data = 0, + }, { + .name = "s3c2440-i2c", + .driver_data = QUIRK_S3C2440, + }, { + .name = "s3c2440-hdmiphy-i2c", + .driver_data = QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO, + }, { }, +}; +MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids); + +#ifdef CONFIG_OF +static const struct of_device_id s3c24xx_i2c_match[] = { + { .compatible = "samsung,s3c2410-i2c", .data = (void *)0 }, + { .compatible = "samsung,s3c2440-i2c", .data = (void *)QUIRK_S3C2440 }, + { .compatible = "samsung,s3c2440-hdmiphy-i2c", + .data = (void *)(QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO) }, + {}, +}; +MODULE_DEVICE_TABLE(of, s3c24xx_i2c_match); +#endif -/* s3c24xx_i2c_is2440() +/* s3c24xx_get_device_quirks * - * return true is this is an s3c2440 + * Get controller type either from device tree or platform device variant. */ -static inline int s3c24xx_i2c_is2440(struct s3c24xx_i2c *i2c) +static inline unsigned int s3c24xx_get_device_quirks(struct platform_device *pdev) { - struct platform_device *pdev = to_platform_device(i2c->dev); - enum s3c24xx_i2c_type type; - -#ifdef CONFIG_OF - if (i2c->dev->of_node) - return of_device_is_compatible(i2c->dev->of_node, - "samsung,s3c2440-i2c"); -#endif + if (pdev->dev.of_node) { + const struct of_device_id *match; + match = of_match_node(&s3c24xx_i2c_match, pdev->dev.of_node); + return (unsigned int)match->data; + } - type = platform_get_device_id(pdev)->driver_data; - return type == TYPE_S3C2440; + return platform_get_device_id(pdev)->driver_data; } /* s3c24xx_i2c_master_complete @@ -471,6 +490,13 @@ static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c) unsigned long iicstat; int timeout = 400; + /* the timeout for HDMIPHY is reduced to 10 ms because + * the hangup is expected to happen, so waiting 400 ms + * causes only unnecessary system hangup + */ + if (i2c->quirks & QUIRK_HDMIPHY) + timeout = 10; + while (timeout-- > 0) { iicstat = readl(i2c->regs + S3C2410_IICSTAT); @@ -480,6 +506,15 @@ static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c) msleep(1); } + /* hang-up of bus dedicated for HDMIPHY occurred, resetting */ + if (i2c->quirks & QUIRK_HDMIPHY) { + writel(0, i2c->regs + S3C2410_IICCON); + writel(0, i2c->regs + S3C2410_IICSTAT); + writel(0, i2c->regs + S3C2410_IICDS); + + return 0; + } + return -ETIMEDOUT; } @@ -676,7 +711,7 @@ static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got) writel(iiccon, i2c->regs + S3C2410_IICCON); - if (s3c24xx_i2c_is2440(i2c)) { + if (i2c->quirks & QUIRK_S3C2440) { unsigned long sda_delay; if (pdata->sda_delay) { @@ -761,6 +796,9 @@ static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c) { int idx, gpio, ret; + if (i2c->quirks & QUIRK_NO_GPIO) + return 0; + for (idx = 0; idx < 2; idx++) { gpio = of_get_gpio(i2c->dev->of_node, idx); if (!gpio_is_valid(gpio)) { @@ -785,6 +823,10 @@ free_gpio: static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c) { unsigned int idx; + + if (i2c->quirks & QUIRK_NO_GPIO) + return; + for (idx = 0; idx < 2; idx++) gpio_free(i2c->gpios[idx]); } @@ -906,6 +948,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev) goto err_noclk; } + i2c->quirks = s3c24xx_get_device_quirks(pdev); if (pdata) memcpy(i2c->pdata, pdata, sizeof(*pdata)); else @@ -1110,28 +1153,6 @@ static const struct dev_pm_ops s3c24xx_i2c_dev_pm_ops = { /* device driver for platform bus bits */ -static struct platform_device_id s3c24xx_driver_ids[] = { - { - .name = "s3c2410-i2c", - .driver_data = TYPE_S3C2410, - }, { - .name = "s3c2440-i2c", - .driver_data = TYPE_S3C2440, - }, { }, -}; -MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids); - -#ifdef CONFIG_OF -static const struct of_device_id s3c24xx_i2c_match[] = { - { .compatible = "samsung,s3c2410-i2c" }, - { .compatible = "samsung,s3c2440-i2c" }, - {}, -}; -MODULE_DEVICE_TABLE(of, s3c24xx_i2c_match); -#else -#define s3c24xx_i2c_match NULL -#endif - static struct platform_driver s3c24xx_i2c_driver = { .probe = s3c24xx_i2c_probe, .remove = s3c24xx_i2c_remove, @@ -1140,7 +1161,7 @@ static struct platform_driver s3c24xx_i2c_driver = { .owner = THIS_MODULE, .name = "s3c-i2c", .pm = S3C24XX_DEV_PM_OPS, - .of_match_table = s3c24xx_i2c_match, + .of_match_table = of_match_ptr(s3c24xx_i2c_match), }, }; |