| .. | .. |
|---|
| 230 | 230 | #define TSADCV2_AUTO_PERIOD_HT 0x6c |
|---|
| 231 | 231 | #define TSADCV3_AUTO_PERIOD 0x154 |
|---|
| 232 | 232 | #define TSADCV3_AUTO_PERIOD_HT 0x158 |
|---|
| 233 | +#define TSADCV3_Q_MAX 0x210 |
|---|
| 233 | 234 | |
|---|
| 234 | 235 | #define TSADCV2_AUTO_EN BIT(0) |
|---|
| 235 | 236 | #define TSADCV2_AUTO_EN_MASK BIT(16) |
|---|
| .. | .. |
|---|
| 240 | 241 | #define TSADCV2_AUTO_TSHUT_POLARITY_MASK BIT(24) |
|---|
| 241 | 242 | |
|---|
| 242 | 243 | #define TSADCV3_AUTO_Q_SEL_EN BIT(1) |
|---|
| 244 | +#define TSADCV3_AUTO_Q_SEL_EN_MASK BIT(17) |
|---|
| 243 | 245 | |
|---|
| 244 | 246 | #define TSADCV2_INT_SRC_EN(chn) BIT(chn) |
|---|
| 245 | 247 | #define TSADCV2_INT_SRC_EN_MASK(chn) BIT(16 + (chn)) |
|---|
| .. | .. |
|---|
| 253 | 255 | #define TSADCV2_DATA_MASK 0xfff |
|---|
| 254 | 256 | #define TSADCV3_DATA_MASK 0x3ff |
|---|
| 255 | 257 | #define TSADCV4_DATA_MASK 0x1ff |
|---|
| 258 | +#define TSADCV5_DATA_MASK 0x7ff |
|---|
| 256 | 259 | |
|---|
| 257 | 260 | #define TSADCV2_HIGHT_INT_DEBOUNCE_COUNT 4 |
|---|
| 258 | 261 | #define TSADCV2_HIGHT_TSHUT_DEBOUNCE_COUNT 4 |
|---|
| .. | .. |
|---|
| 264 | 267 | #define TSADCV5_AUTO_PERIOD_HT_TIME 1622 /* 2.5ms */ |
|---|
| 265 | 268 | #define TSADCV6_AUTO_PERIOD_TIME 5000 /* 2.5ms */ |
|---|
| 266 | 269 | #define TSADCV6_AUTO_PERIOD_HT_TIME 5000 /* 2.5ms */ |
|---|
| 270 | +#define TSADCV7_AUTO_PERIOD_TIME 3000 /* 2.5ms */ |
|---|
| 271 | +#define TSADCV7_AUTO_PERIOD_HT_TIME 3000 /* 2.5ms */ |
|---|
| 272 | +#define TSADCV3_Q_MAX_VAL 0x7ff /* 11bit 2047 */ |
|---|
| 267 | 273 | |
|---|
| 268 | 274 | #define TSADCV2_USER_INTER_PD_SOC 0x340 /* 13 clocks */ |
|---|
| 269 | 275 | #define TSADCV5_USER_INTER_PD_SOC 0xfc0 /* 97us, at least 90us */ |
|---|
| .. | .. |
|---|
| 278 | 284 | #define RK1808_BUS_GRF_SOC_CON0 0x0400 |
|---|
| 279 | 285 | |
|---|
| 280 | 286 | #define RK3568_GRF_TSADC_CON 0x0600 |
|---|
| 287 | +#define RK3528_GRF_TSADC_CON 0x40030 |
|---|
| 281 | 288 | #define RK3568_GRF_TSADC_ANA_REG0 (0x10001 << 0) |
|---|
| 282 | 289 | #define RK3568_GRF_TSADC_ANA_REG1 (0x10001 << 1) |
|---|
| 283 | 290 | #define RK3568_GRF_TSADC_ANA_REG2 (0x10001 << 2) |
|---|
| .. | .. |
|---|
| 299 | 306 | #define PX30S_TSADC_TDC_MODE (0x10001 << 4) |
|---|
| 300 | 307 | #define PX30S_TSADC_TRIM (0xf0007 << 0) |
|---|
| 301 | 308 | |
|---|
| 302 | | -#define MIN_TEMP (-40000) |
|---|
| 309 | + |
|---|
| 310 | +/* -40 to 125 is reliable, outside the range existed unreliability */ |
|---|
| 311 | +#define MIN_TEMP (-60000) |
|---|
| 303 | 312 | #define LOWEST_TEMP (-273000) |
|---|
| 304 | | -#define MAX_TEMP (125000) |
|---|
| 313 | +#define MAX_TEMP (180000) |
|---|
| 305 | 314 | #define MAX_ENV_TEMP (85000) |
|---|
| 306 | 315 | |
|---|
| 307 | 316 | #define BASE (1024) |
|---|
| .. | .. |
|---|
| 325 | 334 | int temp; |
|---|
| 326 | 335 | }; |
|---|
| 327 | 336 | |
|---|
| 328 | | - |
|---|
| 329 | 337 | static const struct tsadc_table rv1108_table[] = { |
|---|
| 330 | | - {0, -40000}, |
|---|
| 338 | + {0, MIN_TEMP}, |
|---|
| 339 | + {342, MIN_TEMP}, |
|---|
| 331 | 340 | {374, -40000}, |
|---|
| 332 | 341 | {382, -35000}, |
|---|
| 333 | 342 | {389, -30000}, |
|---|
| .. | .. |
|---|
| 362 | 371 | {618, 115000}, |
|---|
| 363 | 372 | {626, 120000}, |
|---|
| 364 | 373 | {634, 125000}, |
|---|
| 365 | | - {TSADCV2_DATA_MASK, 125000}, |
|---|
| 374 | + {722, MAX_TEMP}, |
|---|
| 375 | + {TSADCV2_DATA_MASK, MAX_TEMP}, |
|---|
| 366 | 376 | }; |
|---|
| 367 | 377 | |
|---|
| 368 | 378 | static const struct tsadc_table rk1808_code_table[] = { |
|---|
| 369 | | - {0, -40000}, |
|---|
| 379 | + {0, MIN_TEMP}, |
|---|
| 380 | + {3423, MIN_TEMP}, |
|---|
| 370 | 381 | {3455, -40000}, |
|---|
| 371 | 382 | {3463, -35000}, |
|---|
| 372 | 383 | {3471, -30000}, |
|---|
| .. | .. |
|---|
| 401 | 412 | {3709, 115000}, |
|---|
| 402 | 413 | {3718, 120000}, |
|---|
| 403 | 414 | {3726, 125000}, |
|---|
| 404 | | - {TSADCV2_DATA_MASK, 125000}, |
|---|
| 415 | + {3820, MAX_TEMP}, |
|---|
| 416 | + {TSADCV2_DATA_MASK, MAX_TEMP}, |
|---|
| 405 | 417 | }; |
|---|
| 406 | 418 | |
|---|
| 407 | 419 | static const struct tsadc_table rk3228_code_table[] = { |
|---|
| 408 | | - {0, -40000}, |
|---|
| 420 | + {0, MIN_TEMP}, |
|---|
| 421 | + {568, MIN_TEMP}, |
|---|
| 409 | 422 | {588, -40000}, |
|---|
| 410 | 423 | {593, -35000}, |
|---|
| 411 | 424 | {598, -30000}, |
|---|
| .. | .. |
|---|
| 440 | 453 | {749, 115000}, |
|---|
| 441 | 454 | {754, 120000}, |
|---|
| 442 | 455 | {760, 125000}, |
|---|
| 443 | | - {TSADCV2_DATA_MASK, 125000}, |
|---|
| 456 | + {821, MAX_TEMP}, |
|---|
| 457 | + {TSADCV2_DATA_MASK, MAX_TEMP}, |
|---|
| 444 | 458 | }; |
|---|
| 445 | 459 | |
|---|
| 446 | 460 | static const struct tsadc_table rk3288_code_table[] = { |
|---|
| 447 | | - {TSADCV2_DATA_MASK, -40000}, |
|---|
| 461 | + {TSADCV2_DATA_MASK, MIN_TEMP}, |
|---|
| 462 | + {3833, MIN_TEMP}, |
|---|
| 448 | 463 | {3800, -40000}, |
|---|
| 449 | 464 | {3792, -35000}, |
|---|
| 450 | 465 | {3783, -30000}, |
|---|
| .. | .. |
|---|
| 479 | 494 | {3452, 115000}, |
|---|
| 480 | 495 | {3437, 120000}, |
|---|
| 481 | 496 | {3421, 125000}, |
|---|
| 482 | | - {0, 125000}, |
|---|
| 497 | + {3350, 145000}, |
|---|
| 498 | + {3270, 165000}, |
|---|
| 499 | + {3195, MAX_TEMP}, |
|---|
| 500 | + {0, MAX_TEMP}, |
|---|
| 483 | 501 | }; |
|---|
| 484 | 502 | |
|---|
| 485 | 503 | static const struct tsadc_table rk3328_code_table[] = { |
|---|
| 486 | | - {0, -40000}, |
|---|
| 504 | + {0, MIN_TEMP}, |
|---|
| 505 | + {261, MIN_TEMP}, |
|---|
| 487 | 506 | {296, -40000}, |
|---|
| 488 | 507 | {304, -35000}, |
|---|
| 489 | 508 | {313, -30000}, |
|---|
| .. | .. |
|---|
| 517 | 536 | {644, 115000}, |
|---|
| 518 | 537 | {659, 120000}, |
|---|
| 519 | 538 | {675, 125000}, |
|---|
| 520 | | - {TSADCV2_DATA_MASK, 125000}, |
|---|
| 539 | + {745, 145000}, |
|---|
| 540 | + {825, 165000}, |
|---|
| 541 | + {900, MAX_TEMP}, |
|---|
| 542 | + {TSADCV2_DATA_MASK, MAX_TEMP}, |
|---|
| 521 | 543 | }; |
|---|
| 522 | 544 | |
|---|
| 523 | 545 | static const struct tsadc_table rk3368_code_table[] = { |
|---|
| 524 | | - {0, -40000}, |
|---|
| 546 | + {0, MIN_TEMP}, |
|---|
| 547 | + {98, MIN_TEMP}, |
|---|
| 525 | 548 | {106, -40000}, |
|---|
| 526 | 549 | {108, -35000}, |
|---|
| 527 | 550 | {110, -30000}, |
|---|
| .. | .. |
|---|
| 556 | 579 | {167, 115000}, |
|---|
| 557 | 580 | {169, 120000}, |
|---|
| 558 | 581 | {171, 125000}, |
|---|
| 559 | | - {TSADCV3_DATA_MASK, 125000}, |
|---|
| 582 | + {193, MAX_TEMP}, |
|---|
| 583 | + {TSADCV3_DATA_MASK, MAX_TEMP}, |
|---|
| 560 | 584 | }; |
|---|
| 561 | 585 | |
|---|
| 562 | 586 | static const struct tsadc_table rk3399_code_table[] = { |
|---|
| 563 | | - {0, -40000}, |
|---|
| 587 | + {0, MIN_TEMP}, |
|---|
| 588 | + {368, MIN_TEMP}, |
|---|
| 564 | 589 | {402, -40000}, |
|---|
| 565 | 590 | {410, -35000}, |
|---|
| 566 | 591 | {419, -30000}, |
|---|
| .. | .. |
|---|
| 595 | 620 | {668, 115000}, |
|---|
| 596 | 621 | {677, 120000}, |
|---|
| 597 | 622 | {685, 125000}, |
|---|
| 598 | | - {TSADCV3_DATA_MASK, 125000}, |
|---|
| 623 | + {782, MAX_TEMP}, |
|---|
| 624 | + {TSADCV3_DATA_MASK, MAX_TEMP}, |
|---|
| 625 | +}; |
|---|
| 626 | + |
|---|
| 627 | +static const struct tsadc_table rk3528_code_table[] = { |
|---|
| 628 | + {0, MIN_TEMP}, |
|---|
| 629 | + {1386, MIN_TEMP}, |
|---|
| 630 | + {1419, -40000}, |
|---|
| 631 | + {1427, -35000}, |
|---|
| 632 | + {1435, -30000}, |
|---|
| 633 | + {1443, -25000}, |
|---|
| 634 | + {1452, -20000}, |
|---|
| 635 | + {1460, -15000}, |
|---|
| 636 | + {1468, -10000}, |
|---|
| 637 | + {1477, -5000}, |
|---|
| 638 | + {1486, 0}, |
|---|
| 639 | + {1494, 5000}, |
|---|
| 640 | + {1502, 10000}, |
|---|
| 641 | + {1510, 15000}, |
|---|
| 642 | + {1519, 20000}, |
|---|
| 643 | + {1527, 25000}, |
|---|
| 644 | + {1535, 30000}, |
|---|
| 645 | + {1544, 35000}, |
|---|
| 646 | + {1552, 40000}, |
|---|
| 647 | + {1561, 45000}, |
|---|
| 648 | + {1569, 50000}, |
|---|
| 649 | + {1578, 55000}, |
|---|
| 650 | + {1586, 60000}, |
|---|
| 651 | + {1594, 65000}, |
|---|
| 652 | + {1603, 70000}, |
|---|
| 653 | + {1612, 75000}, |
|---|
| 654 | + {1620, 80000}, |
|---|
| 655 | + {1628, 85000}, |
|---|
| 656 | + {1637, 90000}, |
|---|
| 657 | + {1646, 95000}, |
|---|
| 658 | + {1654, 100000}, |
|---|
| 659 | + {1662, 105000}, |
|---|
| 660 | + {1671, 110000}, |
|---|
| 661 | + {1679, 115000}, |
|---|
| 662 | + {1688, 120000}, |
|---|
| 663 | + {1696, 125000}, |
|---|
| 664 | + {1790, MAX_TEMP}, |
|---|
| 665 | + {TSADCV5_DATA_MASK, MAX_TEMP}, |
|---|
| 599 | 666 | }; |
|---|
| 600 | 667 | |
|---|
| 601 | 668 | static const struct tsadc_table rk3568_code_table[] = { |
|---|
| 602 | | - {0, -40000}, |
|---|
| 669 | + {0, MIN_TEMP}, |
|---|
| 670 | + {1448, MIN_TEMP}, |
|---|
| 603 | 671 | {1584, -40000}, |
|---|
| 604 | 672 | {1620, -35000}, |
|---|
| 605 | 673 | {1652, -30000}, |
|---|
| .. | .. |
|---|
| 634 | 702 | {2636, 115000}, |
|---|
| 635 | 703 | {2672, 120000}, |
|---|
| 636 | 704 | {2704, 125000}, |
|---|
| 637 | | - {TSADCV2_DATA_MASK, 125000}, |
|---|
| 705 | + {3076, MAX_TEMP}, |
|---|
| 706 | + {TSADCV2_DATA_MASK, MAX_TEMP}, |
|---|
| 638 | 707 | }; |
|---|
| 639 | 708 | |
|---|
| 640 | 709 | static const struct tsadc_table rk3588_code_table[] = { |
|---|
| 641 | | - {0, -40000}, |
|---|
| 710 | + {0, MIN_TEMP}, |
|---|
| 711 | + {194, MIN_TEMP}, |
|---|
| 642 | 712 | {215, -40000}, |
|---|
| 643 | 713 | {285, 25000}, |
|---|
| 644 | 714 | {350, 85000}, |
|---|
| 645 | 715 | {395, 125000}, |
|---|
| 646 | | - {TSADCV4_DATA_MASK, 125000}, |
|---|
| 716 | + {455, MAX_TEMP}, |
|---|
| 717 | + {TSADCV4_DATA_MASK, MAX_TEMP}, |
|---|
| 647 | 718 | }; |
|---|
| 648 | 719 | |
|---|
| 649 | 720 | static u32 rk_tsadcv2_temp_to_code(const struct chip_tsadc_table *table, |
|---|
| .. | .. |
|---|
| 968 | 1039 | if (!IS_ERR(grf)) { |
|---|
| 969 | 1040 | regmap_write(grf, PX30_GRF_SOC_CON0, PX30S_TSADC_TDC_MODE); |
|---|
| 970 | 1041 | regmap_write(grf, PX30_GRF_SOC_CON0, PX30S_TSADC_TRIM); |
|---|
| 1042 | + } |
|---|
| 1043 | +} |
|---|
| 1044 | + |
|---|
| 1045 | +static void rk_tsadcv11_initialize(struct regmap *grf, void __iomem *regs, |
|---|
| 1046 | + enum tshut_polarity tshut_polarity) |
|---|
| 1047 | +{ |
|---|
| 1048 | + writel_relaxed(TSADCV7_AUTO_PERIOD_TIME, regs + TSADCV3_AUTO_PERIOD); |
|---|
| 1049 | + writel_relaxed(TSADCV7_AUTO_PERIOD_HT_TIME, |
|---|
| 1050 | + regs + TSADCV3_AUTO_PERIOD_HT); |
|---|
| 1051 | + writel_relaxed(TSADCV2_HIGHT_INT_DEBOUNCE_COUNT, |
|---|
| 1052 | + regs + TSADCV3_HIGHT_INT_DEBOUNCE); |
|---|
| 1053 | + writel_relaxed(TSADCV2_HIGHT_TSHUT_DEBOUNCE_COUNT, |
|---|
| 1054 | + regs + TSADCV3_HIGHT_TSHUT_DEBOUNCE); |
|---|
| 1055 | + writel_relaxed(TSADCV3_Q_MAX_VAL, regs + TSADCV3_Q_MAX); |
|---|
| 1056 | + writel_relaxed(TSADCV3_AUTO_Q_SEL_EN | TSADCV3_AUTO_Q_SEL_EN_MASK, |
|---|
| 1057 | + regs + TSADCV2_AUTO_CON); |
|---|
| 1058 | + if (tshut_polarity == TSHUT_HIGH_ACTIVE) |
|---|
| 1059 | + writel_relaxed(TSADCV2_AUTO_TSHUT_POLARITY_HIGH | |
|---|
| 1060 | + TSADCV2_AUTO_TSHUT_POLARITY_MASK, |
|---|
| 1061 | + regs + TSADCV2_AUTO_CON); |
|---|
| 1062 | + else |
|---|
| 1063 | + writel_relaxed(TSADCV2_AUTO_TSHUT_POLARITY_MASK, |
|---|
| 1064 | + regs + TSADCV2_AUTO_CON); |
|---|
| 1065 | + |
|---|
| 1066 | + if (!IS_ERR(grf)) { |
|---|
| 1067 | + regmap_write(grf, RK3528_GRF_TSADC_CON, RK3568_GRF_TSADC_TSEN); |
|---|
| 1068 | + udelay(15); |
|---|
| 1069 | + regmap_write(grf, RK3528_GRF_TSADC_CON, RK3568_GRF_TSADC_ANA_REG0); |
|---|
| 1070 | + regmap_write(grf, RK3528_GRF_TSADC_CON, RK3568_GRF_TSADC_ANA_REG1); |
|---|
| 1071 | + regmap_write(grf, RK3528_GRF_TSADC_CON, RK3568_GRF_TSADC_ANA_REG2); |
|---|
| 1072 | + usleep_range(100, 200); |
|---|
| 971 | 1073 | } |
|---|
| 972 | 1074 | } |
|---|
| 973 | 1075 | |
|---|
| .. | .. |
|---|
| 1639 | 1741 | }, |
|---|
| 1640 | 1742 | }; |
|---|
| 1641 | 1743 | |
|---|
| 1744 | +static const struct rockchip_tsadc_chip rk3528_tsadc_data = { |
|---|
| 1745 | + .chn_id[SENSOR_CPU] = 0, /* cpu sensor is channel 0 */ |
|---|
| 1746 | + .chn_num = 1, /* one channels for tsadc */ |
|---|
| 1747 | + |
|---|
| 1748 | + .tshut_mode = TSHUT_MODE_OTP, /* default TSHUT via GPIO give PMIC */ |
|---|
| 1749 | + .tshut_polarity = TSHUT_LOW_ACTIVE, /* default TSHUT LOW ACTIVE */ |
|---|
| 1750 | + .tshut_temp = 95000, |
|---|
| 1751 | + |
|---|
| 1752 | + .initialize = rk_tsadcv11_initialize, |
|---|
| 1753 | + .irq_ack = rk_tsadcv4_irq_ack, |
|---|
| 1754 | + .control = rk_tsadcv4_control, |
|---|
| 1755 | + .get_temp = rk_tsadcv4_get_temp, |
|---|
| 1756 | + .set_alarm_temp = rk_tsadcv3_alarm_temp, |
|---|
| 1757 | + .set_tshut_temp = rk_tsadcv3_tshut_temp, |
|---|
| 1758 | + .set_tshut_mode = rk_tsadcv4_tshut_mode, |
|---|
| 1759 | + |
|---|
| 1760 | + .table = { |
|---|
| 1761 | + .id = rk3528_code_table, |
|---|
| 1762 | + .length = ARRAY_SIZE(rk3528_code_table), |
|---|
| 1763 | + .data_mask = TSADCV2_DATA_MASK, |
|---|
| 1764 | + .mode = ADC_INCREMENT, |
|---|
| 1765 | + }, |
|---|
| 1766 | +}; |
|---|
| 1767 | + |
|---|
| 1642 | 1768 | static const struct rockchip_tsadc_chip rk3568_tsadc_data = { |
|---|
| 1643 | 1769 | .chn_id[SENSOR_CPU] = 0, /* cpu sensor is channel 0 */ |
|---|
| 1644 | 1770 | .chn_id[SENSOR_GPU] = 1, /* gpu sensor is channel 1 */ |
|---|
| .. | .. |
|---|
| 1757 | 1883 | .data = (void *)&rk3399_tsadc_data, |
|---|
| 1758 | 1884 | }, |
|---|
| 1759 | 1885 | #endif |
|---|
| 1886 | +#ifdef CONFIG_CPU_RK3528 |
|---|
| 1887 | + { |
|---|
| 1888 | + .compatible = "rockchip,rk3528-tsadc", |
|---|
| 1889 | + .data = (void *)&rk3528_tsadc_data, |
|---|
| 1890 | + }, |
|---|
| 1891 | +#endif |
|---|
| 1760 | 1892 | #ifdef CONFIG_CPU_RK3568 |
|---|
| 1761 | 1893 | { |
|---|
| 1762 | 1894 | .compatible = "rockchip,rk3568-tsadc", |
|---|