aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrzej Hajda <a.hajda@samsung.com>2017-02-24 06:16:01 -0500
committerWolfram Sang <wsa@the-dreams.de>2017-04-21 08:01:16 -0400
commitb9d5b31a0dee47e3a1351589d361443e66f4f125 (patch)
treeb5c7f6160a4afcb940fc50dc8ad14a41347ef425
parentb917d4fd5050e46979835486a70c99b5cb688689 (diff)
i2c: exynos5: simplify clock frequency handling
There is no need to keep separate settings for high and fast speed clock. Signed-off-by: Andrzej Hajda <a.hajda@samsung.com> Reviewed-by: Javier Martinez Canillas <javier@osg.samsung.com> Tested-by: Javier Martinez Canillas <javier@osg.samsung.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r--drivers/i2c/busses/i2c-exynos5.c45
1 files changed, 12 insertions, 33 deletions
diff --git a/drivers/i2c/busses/i2c-exynos5.c b/drivers/i2c/busses/i2c-exynos5.c
index 5f24c3ef7d1d..3d21bc280927 100644
--- a/drivers/i2c/busses/i2c-exynos5.c
+++ b/drivers/i2c/busses/i2c-exynos5.c
@@ -168,8 +168,6 @@
168 */ 168 */
169#define HSI2C_HS_TX_CLOCK 1000000 169#define HSI2C_HS_TX_CLOCK 1000000
170#define HSI2C_FS_TX_CLOCK 100000 170#define HSI2C_FS_TX_CLOCK 100000
171#define HSI2C_HIGH_SPD 1
172#define HSI2C_FAST_SPD 0
173 171
174#define EXYNOS5_I2C_TIMEOUT (msecs_to_jiffies(1000)) 172#define EXYNOS5_I2C_TIMEOUT (msecs_to_jiffies(1000))
175 173
@@ -200,15 +198,7 @@ struct exynos5_i2c {
200 int trans_done; 198 int trans_done;
201 199
202 /* Controller operating frequency */ 200 /* Controller operating frequency */
203 unsigned int fs_clock; 201 unsigned int op_clock;
204 unsigned int hs_clock;
205
206 /*
207 * HSI2C Controller can operate in
208 * 1. High speed upto 3.4Mbps
209 * 2. Fast speed upto 1Mbps
210 */
211 int speed_mode;
212 202
213 /* Version of HS-I2C Hardware */ 203 /* Version of HS-I2C Hardware */
214 struct exynos_hsi2c_variant *variant; 204 struct exynos_hsi2c_variant *variant;
@@ -279,7 +269,7 @@ static void exynos5_i2c_clr_pend_irq(struct exynos5_i2c *i2c)
279 * Returns 0 on success, -EINVAL if the cycle length cannot 269 * Returns 0 on success, -EINVAL if the cycle length cannot
280 * be calculated. 270 * be calculated.
281 */ 271 */
282static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, int mode) 272static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, bool hs_timings)
283{ 273{
284 u32 i2c_timing_s1; 274 u32 i2c_timing_s1;
285 u32 i2c_timing_s2; 275 u32 i2c_timing_s2;
@@ -292,8 +282,9 @@ static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, int mode)
292 unsigned int t_sr_release; 282 unsigned int t_sr_release;
293 unsigned int t_ftl_cycle; 283 unsigned int t_ftl_cycle;
294 unsigned int clkin = clk_get_rate(i2c->clk); 284 unsigned int clkin = clk_get_rate(i2c->clk);
295 unsigned int op_clk = (mode == HSI2C_HIGH_SPD) ? 285 unsigned int op_clk = hs_timings ? i2c->op_clock :
296 i2c->hs_clock : i2c->fs_clock; 286 (i2c->op_clock >= HSI2C_HS_TX_CLOCK) ? HSI2C_FS_TX_CLOCK :
287 i2c->op_clock;
297 int div, clk_cycle, temp; 288 int div, clk_cycle, temp;
298 289
299 /* 290 /*
@@ -344,7 +335,7 @@ static int exynos5_i2c_set_timing(struct exynos5_i2c *i2c, int mode)
344 div, t_sr_release); 335 div, t_sr_release);
345 dev_dbg(i2c->dev, "tDATA_HD: %X\n", t_data_hd); 336 dev_dbg(i2c->dev, "tDATA_HD: %X\n", t_data_hd);
346 337
347 if (mode == HSI2C_HIGH_SPD) { 338 if (hs_timings) {
348 writel(i2c_timing_s1, i2c->regs + HSI2C_TIMING_HS1); 339 writel(i2c_timing_s1, i2c->regs + HSI2C_TIMING_HS1);
349 writel(i2c_timing_s2, i2c->regs + HSI2C_TIMING_HS2); 340 writel(i2c_timing_s2, i2c->regs + HSI2C_TIMING_HS2);
350 writel(i2c_timing_s3, i2c->regs + HSI2C_TIMING_HS3); 341 writel(i2c_timing_s3, i2c->regs + HSI2C_TIMING_HS3);
@@ -364,14 +355,14 @@ static int exynos5_hsi2c_clock_setup(struct exynos5_i2c *i2c)
364 * Configure the Fast speed timing values 355 * Configure the Fast speed timing values
365 * Even the High Speed mode initially starts with Fast mode 356 * Even the High Speed mode initially starts with Fast mode
366 */ 357 */
367 if (exynos5_i2c_set_timing(i2c, HSI2C_FAST_SPD)) { 358 if (exynos5_i2c_set_timing(i2c, false)) {
368 dev_err(i2c->dev, "HSI2C FS Clock set up failed\n"); 359 dev_err(i2c->dev, "HSI2C FS Clock set up failed\n");
369 return -EINVAL; 360 return -EINVAL;
370 } 361 }
371 362
372 /* configure the High speed timing values */ 363 /* configure the High speed timing values */
373 if (i2c->speed_mode == HSI2C_HIGH_SPD) { 364 if (i2c->op_clock >= HSI2C_HS_TX_CLOCK) {
374 if (exynos5_i2c_set_timing(i2c, HSI2C_HIGH_SPD)) { 365 if (exynos5_i2c_set_timing(i2c, true)) {
375 dev_err(i2c->dev, "HSI2C HS Clock set up failed\n"); 366 dev_err(i2c->dev, "HSI2C HS Clock set up failed\n");
376 return -EINVAL; 367 return -EINVAL;
377 } 368 }
@@ -397,7 +388,7 @@ static void exynos5_i2c_init(struct exynos5_i2c *i2c)
397 i2c->regs + HSI2C_CTL); 388 i2c->regs + HSI2C_CTL);
398 writel(HSI2C_TRAILING_COUNT, i2c->regs + HSI2C_TRAILIG_CTL); 389 writel(HSI2C_TRAILING_COUNT, i2c->regs + HSI2C_TRAILIG_CTL);
399 390
400 if (i2c->speed_mode == HSI2C_HIGH_SPD) { 391 if (i2c->op_clock >= HSI2C_HS_TX_CLOCK) {
401 writel(HSI2C_MASTER_ID(MASTER_ID(i2c->adap.nr)), 392 writel(HSI2C_MASTER_ID(MASTER_ID(i2c->adap.nr)),
402 i2c->regs + HSI2C_ADDR); 393 i2c->regs + HSI2C_ADDR);
403 i2c_conf |= HSI2C_HS_MODE; 394 i2c_conf |= HSI2C_HS_MODE;
@@ -735,26 +726,14 @@ static int exynos5_i2c_probe(struct platform_device *pdev)
735 struct device_node *np = pdev->dev.of_node; 726 struct device_node *np = pdev->dev.of_node;
736 struct exynos5_i2c *i2c; 727 struct exynos5_i2c *i2c;
737 struct resource *mem; 728 struct resource *mem;
738 unsigned int op_clock;
739 int ret; 729 int ret;
740 730
741 i2c = devm_kzalloc(&pdev->dev, sizeof(struct exynos5_i2c), GFP_KERNEL); 731 i2c = devm_kzalloc(&pdev->dev, sizeof(struct exynos5_i2c), GFP_KERNEL);
742 if (!i2c) 732 if (!i2c)
743 return -ENOMEM; 733 return -ENOMEM;
744 734
745 if (of_property_read_u32(np, "clock-frequency", &op_clock)) { 735 if (of_property_read_u32(np, "clock-frequency", &i2c->op_clock))
746 i2c->speed_mode = HSI2C_FAST_SPD; 736 i2c->op_clock = HSI2C_FS_TX_CLOCK;
747 i2c->fs_clock = HSI2C_FS_TX_CLOCK;
748 } else {
749 if (op_clock >= HSI2C_HS_TX_CLOCK) {
750 i2c->speed_mode = HSI2C_HIGH_SPD;
751 i2c->fs_clock = HSI2C_FS_TX_CLOCK;
752 i2c->hs_clock = op_clock;
753 } else {
754 i2c->speed_mode = HSI2C_FAST_SPD;
755 i2c->fs_clock = op_clock;
756 }
757 }
758 737
759 strlcpy(i2c->adap.name, "exynos5-i2c", sizeof(i2c->adap.name)); 738 strlcpy(i2c->adap.name, "exynos5-i2c", sizeof(i2c->adap.name));
760 i2c->adap.owner = THIS_MODULE; 739 i2c->adap.owner = THIS_MODULE;