aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei Ni <wni@nvidia.com>2016-03-29 06:29:21 -0400
committerEduardo Valentin <edubezval@gmail.com>2016-05-17 10:28:29 -0400
commit1ed895c2a27ebc862241926945f4adcbc88c6cd6 (patch)
treedd77efc71e2ac7fd97302dc0dc4285eadfc2ca49
parent8de2ab023598bcb874e2182ab6ea7355bbf33af6 (diff)
thermal: tegra: handle HW initialization in one funcotion
Handle HW initialization in one function soctherm_init(), so that the codes are more clear. Signed-off-by: Wei Ni <wni@nvidia.com> Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
-rw-r--r--drivers/thermal/tegra/soctherm.c85
1 files changed, 44 insertions, 41 deletions
diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c
index deeb3b7e4dac..d2b7c255d71f 100644
--- a/drivers/thermal/tegra/soctherm.c
+++ b/drivers/thermal/tegra/soctherm.c
@@ -95,19 +95,11 @@ struct tegra_soctherm {
95 struct dentry *debugfs_dir; 95 struct dentry *debugfs_dir;
96}; 96};
97 97
98static int enable_tsensor(struct tegra_soctherm *tegra, 98static void enable_tsensor(struct tegra_soctherm *tegra, unsigned int i)
99 unsigned int i,
100 const struct tsensor_shared_calib *shared)
101{ 99{
102 const struct tegra_tsensor *sensor = &tegra->soc->tsensors[i]; 100 const struct tegra_tsensor *sensor = &tegra->soc->tsensors[i];
103 void __iomem *base = tegra->regs + sensor->base; 101 void __iomem *base = tegra->regs + sensor->base;
104 u32 *calib = &tegra->calib[i];
105 unsigned int val; 102 unsigned int val;
106 int err;
107
108 err = tegra_calc_tsensor_calib(sensor, shared, calib);
109 if (err)
110 return err;
111 103
112 val = sensor->config->tall << SENSOR_CONFIG0_TALL_SHIFT; 104 val = sensor->config->tall << SENSOR_CONFIG0_TALL_SHIFT;
113 writel(val, base + SENSOR_CONFIG0); 105 writel(val, base + SENSOR_CONFIG0);
@@ -118,9 +110,7 @@ static int enable_tsensor(struct tegra_soctherm *tegra,
118 val |= SENSOR_CONFIG1_TEMP_ENABLE; 110 val |= SENSOR_CONFIG1_TEMP_ENABLE;
119 writel(val, base + SENSOR_CONFIG1); 111 writel(val, base + SENSOR_CONFIG1);
120 112
121 writel(*calib, base + SENSOR_CONFIG2); 113 writel(tegra->calib[i], base + SENSOR_CONFIG2);
122
123 return 0;
124} 114}
125 115
126/* 116/*
@@ -461,6 +451,34 @@ static int soctherm_clk_enable(struct platform_device *pdev, bool enable)
461 return 0; 451 return 0;
462} 452}
463 453
454static void soctherm_init(struct platform_device *pdev)
455{
456 struct tegra_soctherm *tegra = platform_get_drvdata(pdev);
457 const struct tegra_tsensor_group **ttgs = tegra->soc->ttgs;
458 int i;
459 u32 pdiv, hotspot;
460
461 /* Initialize raw sensors */
462 for (i = 0; i < tegra->soc->num_tsensors; ++i)
463 enable_tsensor(tegra, i);
464
465 /* program pdiv and hotspot offsets per THERM */
466 pdiv = readl(tegra->regs + SENSOR_PDIV);
467 hotspot = readl(tegra->regs + SENSOR_HOTSPOT_OFF);
468 for (i = 0; i < tegra->soc->num_ttgs; ++i) {
469 pdiv = REG_SET_MASK(pdiv, ttgs[i]->pdiv_mask,
470 ttgs[i]->pdiv);
471 /* hotspot offset from PLLX, doesn't need to configure PLLX */
472 if (ttgs[i]->id == TEGRA124_SOCTHERM_SENSOR_PLLX)
473 continue;
474 hotspot = REG_SET_MASK(hotspot,
475 ttgs[i]->pllx_hotspot_mask,
476 ttgs[i]->pllx_hotspot_diff);
477 }
478 writel(pdiv, tegra->regs + SENSOR_PDIV);
479 writel(hotspot, tegra->regs + SENSOR_HOTSPOT_OFF);
480}
481
464static const struct of_device_id tegra_soctherm_of_match[] = { 482static const struct of_device_id tegra_soctherm_of_match[] = {
465#ifdef CONFIG_ARCH_TEGRA_124_SOC 483#ifdef CONFIG_ARCH_TEGRA_124_SOC
466 { 484 {
@@ -488,7 +506,6 @@ static int tegra_soctherm_probe(struct platform_device *pdev)
488 struct tegra_soctherm_soc *soc; 506 struct tegra_soctherm_soc *soc;
489 unsigned int i; 507 unsigned int i;
490 int err; 508 int err;
491 u32 pdiv, hotspot;
492 509
493 match = of_match_node(tegra_soctherm_of_match, pdev->dev.of_node); 510 match = of_match_node(tegra_soctherm_of_match, pdev->dev.of_node);
494 if (!match) 511 if (!match)
@@ -529,45 +546,31 @@ static int tegra_soctherm_probe(struct platform_device *pdev)
529 return PTR_ERR(tegra->clock_soctherm); 546 return PTR_ERR(tegra->clock_soctherm);
530 } 547 }
531 548
532 err = soctherm_clk_enable(pdev, true);
533 if (err)
534 return err;
535
536 /* Initialize raw sensors */
537
538 tegra->calib = devm_kzalloc(&pdev->dev, 549 tegra->calib = devm_kzalloc(&pdev->dev,
539 sizeof(u32) * soc->num_tsensors, 550 sizeof(u32) * soc->num_tsensors,
540 GFP_KERNEL); 551 GFP_KERNEL);
541 if (!tegra->calib) { 552 if (!tegra->calib)
542 err = -ENOMEM; 553 return -ENOMEM;
543 goto disable_clocks;
544 }
545 554
555 /* calculate shared calibration data */
546 err = tegra_calc_shared_calib(soc->tfuse, &shared_calib); 556 err = tegra_calc_shared_calib(soc->tfuse, &shared_calib);
547 if (err) 557 if (err)
548 goto disable_clocks; 558 return err;
549 559
560 /* calculate tsensor calibaration data */
550 for (i = 0; i < soc->num_tsensors; ++i) { 561 for (i = 0; i < soc->num_tsensors; ++i) {
551 err = enable_tsensor(tegra, i, &shared_calib); 562 err = tegra_calc_tsensor_calib(&soc->tsensors[i],
563 &shared_calib,
564 &tegra->calib[i]);
552 if (err) 565 if (err)
553 goto disable_clocks; 566 return err;
554 } 567 }
555 568
556 /* Program pdiv and hotspot offsets per THERM */ 569 err = soctherm_clk_enable(pdev, true);
557 pdiv = readl(tegra->regs + SENSOR_PDIV); 570 if (err)
558 hotspot = readl(tegra->regs + SENSOR_HOTSPOT_OFF); 571 return err;
559 for (i = 0; i < soc->num_ttgs; ++i) { 572
560 pdiv = REG_SET_MASK(pdiv, soc->ttgs[i]->pdiv_mask, 573 soctherm_init(pdev);
561 soc->ttgs[i]->pdiv);
562 /* hotspot offset from PLLX, doesn't need to configure PLLX */
563 if (soc->ttgs[i]->id == TEGRA124_SOCTHERM_SENSOR_PLLX)
564 continue;
565 hotspot = REG_SET_MASK(hotspot,
566 soc->ttgs[i]->pllx_hotspot_mask,
567 soc->ttgs[i]->pllx_hotspot_diff);
568 }
569 writel(pdiv, tegra->regs + SENSOR_PDIV);
570 writel(hotspot, tegra->regs + SENSOR_HOTSPOT_OFF);
571 574
572 for (i = 0; i < soc->num_ttgs; ++i) { 575 for (i = 0; i < soc->num_ttgs; ++i) {
573 struct tegra_thermctl_zone *zone = 576 struct tegra_thermctl_zone *zone =