Message ID | 20210324214404.798-2-ansuelsmth@gmail.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
Series | Add support for ipq8064 tsens | expand |
Hi Ansuel, url: https://github.com/0day-ci/linux/commits/Ansuel-Smith/drivers-thermal-tsens-Add-VER_0-tsens-version/20210325-064422 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next config: riscv-randconfig-m031-20210330 (attached as .config) compiler: riscv32-linux-gcc (GCC) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> New smatch warnings: drivers/thermal/qcom/tsens.c:792 init_common() warn: passing zero to 'PTR_ERR' vim +/PTR_ERR +792 drivers/thermal/qcom/tsens.c a7ff82976122eb Amit Kucheria 2020-04-29 741 int __init init_common(struct tsens_priv *priv) a7ff82976122eb Amit Kucheria 2020-04-29 742 { a7ff82976122eb Amit Kucheria 2020-04-29 743 void __iomem *tm_base, *srot_base; a7ff82976122eb Amit Kucheria 2020-04-29 744 struct device *dev = priv->dev; a7ff82976122eb Amit Kucheria 2020-04-29 745 u32 ver_minor; a7ff82976122eb Amit Kucheria 2020-04-29 746 struct resource *res; a7ff82976122eb Amit Kucheria 2020-04-29 747 u32 enabled; a7ff82976122eb Amit Kucheria 2020-04-29 748 int ret, i, j; a7ff82976122eb Amit Kucheria 2020-04-29 749 struct platform_device *op = of_find_device_by_node(priv->dev->of_node); a7ff82976122eb Amit Kucheria 2020-04-29 750 a7ff82976122eb Amit Kucheria 2020-04-29 751 if (!op) a7ff82976122eb Amit Kucheria 2020-04-29 752 return -EINVAL; a7ff82976122eb Amit Kucheria 2020-04-29 753 a7ff82976122eb Amit Kucheria 2020-04-29 754 if (op->num_resources > 1) { a7ff82976122eb Amit Kucheria 2020-04-29 755 /* DT with separate SROT and TM address space */ a7ff82976122eb Amit Kucheria 2020-04-29 756 priv->tm_offset = 0; a7ff82976122eb Amit Kucheria 2020-04-29 757 res = platform_get_resource(op, IORESOURCE_MEM, 1); a7ff82976122eb Amit Kucheria 2020-04-29 758 srot_base = devm_ioremap_resource(dev, res); a7ff82976122eb Amit Kucheria 2020-04-29 759 if (IS_ERR(srot_base)) { a7ff82976122eb Amit Kucheria 2020-04-29 760 ret = PTR_ERR(srot_base); a7ff82976122eb Amit Kucheria 2020-04-29 761 goto err_put_device; a7ff82976122eb Amit Kucheria 2020-04-29 762 } a7ff82976122eb Amit Kucheria 2020-04-29 763 a7ff82976122eb Amit Kucheria 2020-04-29 764 priv->srot_map = devm_regmap_init_mmio(dev, srot_base, a7ff82976122eb Amit Kucheria 2020-04-29 765 &tsens_srot_config); a7ff82976122eb Amit Kucheria 2020-04-29 766 if (IS_ERR(priv->srot_map)) { a7ff82976122eb Amit Kucheria 2020-04-29 767 ret = PTR_ERR(priv->srot_map); a7ff82976122eb Amit Kucheria 2020-04-29 768 goto err_put_device; a7ff82976122eb Amit Kucheria 2020-04-29 769 } a7ff82976122eb Amit Kucheria 2020-04-29 770 } else { a7ff82976122eb Amit Kucheria 2020-04-29 771 /* old DTs where SROT and TM were in a contiguous 2K block */ a7ff82976122eb Amit Kucheria 2020-04-29 772 priv->tm_offset = 0x1000; a7ff82976122eb Amit Kucheria 2020-04-29 773 } a7ff82976122eb Amit Kucheria 2020-04-29 774 fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 775 if (tsens_version(priv) >= VER_0_1) { a7ff82976122eb Amit Kucheria 2020-04-29 776 res = platform_get_resource(op, IORESOURCE_MEM, 0); a7ff82976122eb Amit Kucheria 2020-04-29 777 tm_base = devm_ioremap_resource(dev, res); a7ff82976122eb Amit Kucheria 2020-04-29 778 if (IS_ERR(tm_base)) { a7ff82976122eb Amit Kucheria 2020-04-29 779 ret = PTR_ERR(tm_base); a7ff82976122eb Amit Kucheria 2020-04-29 780 goto err_put_device; a7ff82976122eb Amit Kucheria 2020-04-29 781 } a7ff82976122eb Amit Kucheria 2020-04-29 782 a7ff82976122eb Amit Kucheria 2020-04-29 783 priv->tm_map = devm_regmap_init_mmio(dev, tm_base, &tsens_config); fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 784 } else { /* VER_0 share the same gcc regs using a syscon */ fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 785 struct device *parent = priv->dev->parent; fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 786 fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 787 if (parent) fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 788 priv->tm_map = syscon_node_to_regmap(parent->of_node); fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 789 } fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 790 fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 791 if (IS_ERR_OR_NULL(priv->tm_map)) { This used to be an IS_ERR() check, but now if "priv->tm_map" is NULL we short cut the rest of the function and return success. It's hard to tell without more context if that's intentional or if it should be something like: if (IS_ERR_OR_NULL(priv->tm_map)) { if (!priv->tm_map) ret = -ENODEV; else ret = PTR_ERR(priv->tm_map); goto err_put_device; } a7ff82976122eb Amit Kucheria 2020-04-29 @792 ret = PTR_ERR(priv->tm_map); a7ff82976122eb Amit Kucheria 2020-04-29 793 goto err_put_device; a7ff82976122eb Amit Kucheria 2020-04-29 794 } a7ff82976122eb Amit Kucheria 2020-04-29 795 fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 796 /* VER_0 have only tm_map */ fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 797 if (!priv->srot_map) fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 798 priv->srot_map = priv->tm_map; fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 799 a7ff82976122eb Amit Kucheria 2020-04-29 800 if (tsens_version(priv) > VER_0_1) { a7ff82976122eb Amit Kucheria 2020-04-29 801 for (i = VER_MAJOR; i <= VER_STEP; i++) { a7ff82976122eb Amit Kucheria 2020-04-29 802 priv->rf[i] = devm_regmap_field_alloc(dev, priv->srot_map, a7ff82976122eb Amit Kucheria 2020-04-29 803 priv->fields[i]); a7ff82976122eb Amit Kucheria 2020-04-29 804 if (IS_ERR(priv->rf[i])) a7ff82976122eb Amit Kucheria 2020-04-29 805 return PTR_ERR(priv->rf[i]); a7ff82976122eb Amit Kucheria 2020-04-29 806 } a7ff82976122eb Amit Kucheria 2020-04-29 807 ret = regmap_field_read(priv->rf[VER_MINOR], &ver_minor); a7ff82976122eb Amit Kucheria 2020-04-29 808 if (ret) a7ff82976122eb Amit Kucheria 2020-04-29 809 goto err_put_device; a7ff82976122eb Amit Kucheria 2020-04-29 810 } a7ff82976122eb Amit Kucheria 2020-04-29 811 a7ff82976122eb Amit Kucheria 2020-04-29 812 priv->rf[TSENS_EN] = devm_regmap_field_alloc(dev, priv->srot_map, a7ff82976122eb Amit Kucheria 2020-04-29 813 priv->fields[TSENS_EN]); a7ff82976122eb Amit Kucheria 2020-04-29 814 if (IS_ERR(priv->rf[TSENS_EN])) { a7ff82976122eb Amit Kucheria 2020-04-29 815 ret = PTR_ERR(priv->rf[TSENS_EN]); a7ff82976122eb Amit Kucheria 2020-04-29 816 goto err_put_device; a7ff82976122eb Amit Kucheria 2020-04-29 817 } fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 818 /* in VER_0 TSENS need to be explicitly enabled */ fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 819 if (tsens_version(priv) == VER_0) fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 820 regmap_field_write(priv->rf[TSENS_EN], 1); fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 821 a7ff82976122eb Amit Kucheria 2020-04-29 822 ret = regmap_field_read(priv->rf[TSENS_EN], &enabled); a7ff82976122eb Amit Kucheria 2020-04-29 823 if (ret) a7ff82976122eb Amit Kucheria 2020-04-29 824 goto err_put_device; a7ff82976122eb Amit Kucheria 2020-04-29 825 if (!enabled) { a7ff82976122eb Amit Kucheria 2020-04-29 826 dev_err(dev, "%s: device not enabled\n", __func__); a7ff82976122eb Amit Kucheria 2020-04-29 827 ret = -ENODEV; a7ff82976122eb Amit Kucheria 2020-04-29 828 goto err_put_device; a7ff82976122eb Amit Kucheria 2020-04-29 829 } a7ff82976122eb Amit Kucheria 2020-04-29 830 a7ff82976122eb Amit Kucheria 2020-04-29 831 priv->rf[SENSOR_EN] = devm_regmap_field_alloc(dev, priv->srot_map, a7ff82976122eb Amit Kucheria 2020-04-29 832 priv->fields[SENSOR_EN]); a7ff82976122eb Amit Kucheria 2020-04-29 833 if (IS_ERR(priv->rf[SENSOR_EN])) { a7ff82976122eb Amit Kucheria 2020-04-29 834 ret = PTR_ERR(priv->rf[SENSOR_EN]); a7ff82976122eb Amit Kucheria 2020-04-29 835 goto err_put_device; a7ff82976122eb Amit Kucheria 2020-04-29 836 } a7ff82976122eb Amit Kucheria 2020-04-29 837 priv->rf[INT_EN] = devm_regmap_field_alloc(dev, priv->tm_map, a7ff82976122eb Amit Kucheria 2020-04-29 838 priv->fields[INT_EN]); a7ff82976122eb Amit Kucheria 2020-04-29 839 if (IS_ERR(priv->rf[INT_EN])) { a7ff82976122eb Amit Kucheria 2020-04-29 840 ret = PTR_ERR(priv->rf[INT_EN]); a7ff82976122eb Amit Kucheria 2020-04-29 841 goto err_put_device; a7ff82976122eb Amit Kucheria 2020-04-29 842 } a7ff82976122eb Amit Kucheria 2020-04-29 843 fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 844 priv->rf[TSENS_SW_RST] = fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 845 devm_regmap_field_alloc(dev, priv->srot_map, priv->fields[TSENS_SW_RST]); fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 846 if (IS_ERR(priv->rf[TSENS_SW_RST])) { fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 847 ret = PTR_ERR(priv->rf[TSENS_SW_RST]); fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 848 goto err_put_device; fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 849 } fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 850 fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 851 priv->rf[TRDY] = devm_regmap_field_alloc(dev, priv->tm_map, priv->fields[TRDY]); fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 852 if (IS_ERR(priv->rf[TRDY])) { fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 853 ret = PTR_ERR(priv->rf[TRDY]); fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 854 goto err_put_device; fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 855 } fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 856 a7ff82976122eb Amit Kucheria 2020-04-29 857 /* This loop might need changes if enum regfield_ids is reordered */ a7ff82976122eb Amit Kucheria 2020-04-29 858 for (j = LAST_TEMP_0; j <= UP_THRESH_15; j += 16) { a7ff82976122eb Amit Kucheria 2020-04-29 859 for (i = 0; i < priv->feat->max_sensors; i++) { a7ff82976122eb Amit Kucheria 2020-04-29 860 int idx = j + i; a7ff82976122eb Amit Kucheria 2020-04-29 861 a7ff82976122eb Amit Kucheria 2020-04-29 862 priv->rf[idx] = devm_regmap_field_alloc(dev, a7ff82976122eb Amit Kucheria 2020-04-29 863 priv->tm_map, a7ff82976122eb Amit Kucheria 2020-04-29 864 priv->fields[idx]); a7ff82976122eb Amit Kucheria 2020-04-29 865 if (IS_ERR(priv->rf[idx])) { a7ff82976122eb Amit Kucheria 2020-04-29 866 ret = PTR_ERR(priv->rf[idx]); a7ff82976122eb Amit Kucheria 2020-04-29 867 goto err_put_device; a7ff82976122eb Amit Kucheria 2020-04-29 868 } a7ff82976122eb Amit Kucheria 2020-04-29 869 } a7ff82976122eb Amit Kucheria 2020-04-29 870 } a7ff82976122eb Amit Kucheria 2020-04-29 871 fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 872 if (priv->feat->crit_int || tsens_version(priv) < VER_0_1) { a7ff82976122eb Amit Kucheria 2020-04-29 873 /* Loop might need changes if enum regfield_ids is reordered */ a7ff82976122eb Amit Kucheria 2020-04-29 874 for (j = CRITICAL_STATUS_0; j <= CRIT_THRESH_15; j += 16) { a7ff82976122eb Amit Kucheria 2020-04-29 875 for (i = 0; i < priv->feat->max_sensors; i++) { a7ff82976122eb Amit Kucheria 2020-04-29 876 int idx = j + i; a7ff82976122eb Amit Kucheria 2020-04-29 877 a7ff82976122eb Amit Kucheria 2020-04-29 878 priv->rf[idx] = a7ff82976122eb Amit Kucheria 2020-04-29 879 devm_regmap_field_alloc(dev, a7ff82976122eb Amit Kucheria 2020-04-29 880 priv->tm_map, a7ff82976122eb Amit Kucheria 2020-04-29 881 priv->fields[idx]); a7ff82976122eb Amit Kucheria 2020-04-29 882 if (IS_ERR(priv->rf[idx])) { a7ff82976122eb Amit Kucheria 2020-04-29 883 ret = PTR_ERR(priv->rf[idx]); a7ff82976122eb Amit Kucheria 2020-04-29 884 goto err_put_device; a7ff82976122eb Amit Kucheria 2020-04-29 885 } a7ff82976122eb Amit Kucheria 2020-04-29 886 } a7ff82976122eb Amit Kucheria 2020-04-29 887 } a7ff82976122eb Amit Kucheria 2020-04-29 888 } a7ff82976122eb Amit Kucheria 2020-04-29 889 a7ff82976122eb Amit Kucheria 2020-04-29 890 if (tsens_version(priv) > VER_1_X && ver_minor > 2) { a7ff82976122eb Amit Kucheria 2020-04-29 891 /* Watchdog is present only on v2.3+ */ a7ff82976122eb Amit Kucheria 2020-04-29 892 priv->feat->has_watchdog = 1; a7ff82976122eb Amit Kucheria 2020-04-29 893 for (i = WDOG_BARK_STATUS; i <= CC_MON_MASK; i++) { a7ff82976122eb Amit Kucheria 2020-04-29 894 priv->rf[i] = devm_regmap_field_alloc(dev, priv->tm_map, a7ff82976122eb Amit Kucheria 2020-04-29 895 priv->fields[i]); a7ff82976122eb Amit Kucheria 2020-04-29 896 if (IS_ERR(priv->rf[i])) { a7ff82976122eb Amit Kucheria 2020-04-29 897 ret = PTR_ERR(priv->rf[i]); a7ff82976122eb Amit Kucheria 2020-04-29 898 goto err_put_device; a7ff82976122eb Amit Kucheria 2020-04-29 899 } a7ff82976122eb Amit Kucheria 2020-04-29 900 } a7ff82976122eb Amit Kucheria 2020-04-29 901 /* a7ff82976122eb Amit Kucheria 2020-04-29 902 * Watchdog is already enabled, unmask the bark. a7ff82976122eb Amit Kucheria 2020-04-29 903 * Disable cycle completion monitoring a7ff82976122eb Amit Kucheria 2020-04-29 904 */ a7ff82976122eb Amit Kucheria 2020-04-29 905 regmap_field_write(priv->rf[WDOG_BARK_MASK], 0); a7ff82976122eb Amit Kucheria 2020-04-29 906 regmap_field_write(priv->rf[CC_MON_MASK], 1); a7ff82976122eb Amit Kucheria 2020-04-29 907 } a7ff82976122eb Amit Kucheria 2020-04-29 908 a7ff82976122eb Amit Kucheria 2020-04-29 909 spin_lock_init(&priv->ul_lock); fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 910 fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 911 /* VER_0 interrupt doesn't need to be enabled */ fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 912 if (tsens_version(priv) >= VER_0_1) a7ff82976122eb Amit Kucheria 2020-04-29 913 tsens_enable_irq(priv); fea5c5e6f2e2a0 Ansuel Smith 2021-03-24 914 a7ff82976122eb Amit Kucheria 2020-04-29 915 tsens_debug_init(op); a7ff82976122eb Amit Kucheria 2020-04-29 916 a7ff82976122eb Amit Kucheria 2020-04-29 917 err_put_device: a7ff82976122eb Amit Kucheria 2020-04-29 918 put_device(&op->dev); a7ff82976122eb Amit Kucheria 2020-04-29 919 return ret; a7ff82976122eb Amit Kucheria 2020-04-29 920 } --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Hi Ansuel, I would like to close up the two series which are pending for this cycle. Is it possible to send a fixed series? Thanks -- Daniel On 31/03/2021 10:35, Dan Carpenter wrote: > Hi Ansuel, > > url: https://github.com/0day-ci/linux/commits/Ansuel-Smith/drivers-thermal-tsens-Add-VER_0-tsens-version/20210325-064422 > base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next > config: riscv-randconfig-m031-20210330 (attached as .config) > compiler: riscv32-linux-gcc (GCC) 9.3.0 > > If you fix the issue, kindly add following tag as appropriate > Reported-by: kernel test robot <lkp@intel.com> > Reported-by: Dan Carpenter <dan.carpenter@oracle.com> > > New smatch warnings: > drivers/thermal/qcom/tsens.c:792 init_common() warn: passing zero to 'PTR_ERR' > > vim +/PTR_ERR +792 drivers/thermal/qcom/tsens.c
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index d8ce3a687b80..6b582a81358f 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -12,6 +12,7 @@ #include <linux/of.h> #include <linux/of_address.h> #include <linux/of_platform.h> +#include <linux/mfd/syscon.h> #include <linux/platform_device.h> #include <linux/pm.h> #include <linux/regmap.h> @@ -515,6 +516,15 @@ static irqreturn_t tsens_irq_thread(int irq, void *data) dev_dbg(priv->dev, "[%u] %s: no violation: %d\n", hw_id, __func__, temp); } + + if (tsens_version(priv) < VER_0_1) { + /* Constraint: There is only 1 interrupt control register for all + * 11 temperature sensor. So monitoring more than 1 sensor based + * on interrupts will yield inconsistent result. To overcome this + * issue we will monitor only sensor 0 which is the master sensor. + */ + break; + } } return IRQ_HANDLED; @@ -530,6 +540,13 @@ static int tsens_set_trips(void *_sensor, int low, int high) int high_val, low_val, cl_high, cl_low; u32 hw_id = s->hw_id; + if (tsens_version(priv) < VER_0_1) { + /* Pre v0.1 IP had a single register for each type of interrupt + * and thresholds + */ + hw_id = 0; + } + dev_dbg(dev, "[%u] %s: proposed thresholds: (%d:%d)\n", hw_id, __func__, low, high); @@ -584,18 +601,21 @@ int get_temp_tsens_valid(const struct tsens_sensor *s, int *temp) u32 valid; int ret; - ret = regmap_field_read(priv->rf[valid_idx], &valid); - if (ret) - return ret; - while (!valid) { - /* Valid bit is 0 for 6 AHB clock cycles. - * At 19.2MHz, 1 AHB clock is ~60ns. - * We should enter this loop very, very rarely. - */ - ndelay(400); + /* VER_0 doesn't have VALID bit */ + if (tsens_version(priv) >= VER_0_1) { ret = regmap_field_read(priv->rf[valid_idx], &valid); if (ret) return ret; + while (!valid) { + /* Valid bit is 0 for 6 AHB clock cycles. + * At 19.2MHz, 1 AHB clock is ~60ns. + * We should enter this loop very, very rarely. + */ + ndelay(400); + ret = regmap_field_read(priv->rf[valid_idx], &valid); + if (ret) + return ret; + } } /* Valid bit is set, OK to read the temperature */ @@ -608,15 +628,29 @@ int get_temp_common(const struct tsens_sensor *s, int *temp) { struct tsens_priv *priv = s->priv; int hw_id = s->hw_id; - int last_temp = 0, ret; + int last_temp = 0, ret, trdy; + unsigned long timeout; - ret = regmap_field_read(priv->rf[LAST_TEMP_0 + hw_id], &last_temp); - if (ret) - return ret; + timeout = jiffies + usecs_to_jiffies(TIMEOUT_US); + do { + if (tsens_version(priv) == VER_0) { + ret = regmap_field_read(priv->rf[TRDY], &trdy); + if (ret) + return ret; + if (!trdy) + continue; + } - *temp = code_to_degc(last_temp, s) * 1000; + ret = regmap_field_read(priv->rf[LAST_TEMP_0 + hw_id], &last_temp); + if (ret) + return ret; - return 0; + *temp = code_to_degc(last_temp, s) * 1000; + + return 0; + } while (time_before(jiffies, timeout)); + + return -ETIMEDOUT; } #ifdef CONFIG_DEBUG_FS @@ -738,19 +772,31 @@ int __init init_common(struct tsens_priv *priv) priv->tm_offset = 0x1000; } - res = platform_get_resource(op, IORESOURCE_MEM, 0); - tm_base = devm_ioremap_resource(dev, res); - if (IS_ERR(tm_base)) { - ret = PTR_ERR(tm_base); - goto err_put_device; + if (tsens_version(priv) >= VER_0_1) { + res = platform_get_resource(op, IORESOURCE_MEM, 0); + tm_base = devm_ioremap_resource(dev, res); + if (IS_ERR(tm_base)) { + ret = PTR_ERR(tm_base); + goto err_put_device; + } + + priv->tm_map = devm_regmap_init_mmio(dev, tm_base, &tsens_config); + } else { /* VER_0 share the same gcc regs using a syscon */ + struct device *parent = priv->dev->parent; + + if (parent) + priv->tm_map = syscon_node_to_regmap(parent->of_node); } - priv->tm_map = devm_regmap_init_mmio(dev, tm_base, &tsens_config); - if (IS_ERR(priv->tm_map)) { + if (IS_ERR_OR_NULL(priv->tm_map)) { ret = PTR_ERR(priv->tm_map); goto err_put_device; } + /* VER_0 have only tm_map */ + if (!priv->srot_map) + priv->srot_map = priv->tm_map; + if (tsens_version(priv) > VER_0_1) { for (i = VER_MAJOR; i <= VER_STEP; i++) { priv->rf[i] = devm_regmap_field_alloc(dev, priv->srot_map, @@ -769,6 +815,10 @@ int __init init_common(struct tsens_priv *priv) ret = PTR_ERR(priv->rf[TSENS_EN]); goto err_put_device; } + /* in VER_0 TSENS need to be explicitly enabled */ + if (tsens_version(priv) == VER_0) + regmap_field_write(priv->rf[TSENS_EN], 1); + ret = regmap_field_read(priv->rf[TSENS_EN], &enabled); if (ret) goto err_put_device; @@ -791,6 +841,19 @@ int __init init_common(struct tsens_priv *priv) goto err_put_device; } + priv->rf[TSENS_SW_RST] = + devm_regmap_field_alloc(dev, priv->srot_map, priv->fields[TSENS_SW_RST]); + if (IS_ERR(priv->rf[TSENS_SW_RST])) { + ret = PTR_ERR(priv->rf[TSENS_SW_RST]); + goto err_put_device; + } + + priv->rf[TRDY] = devm_regmap_field_alloc(dev, priv->tm_map, priv->fields[TRDY]); + if (IS_ERR(priv->rf[TRDY])) { + ret = PTR_ERR(priv->rf[TRDY]); + goto err_put_device; + } + /* This loop might need changes if enum regfield_ids is reordered */ for (j = LAST_TEMP_0; j <= UP_THRESH_15; j += 16) { for (i = 0; i < priv->feat->max_sensors; i++) { @@ -806,7 +869,7 @@ int __init init_common(struct tsens_priv *priv) } } - if (priv->feat->crit_int) { + if (priv->feat->crit_int || tsens_version(priv) < VER_0_1) { /* Loop might need changes if enum regfield_ids is reordered */ for (j = CRITICAL_STATUS_0; j <= CRIT_THRESH_15; j += 16) { for (i = 0; i < priv->feat->max_sensors; i++) { @@ -844,7 +907,11 @@ int __init init_common(struct tsens_priv *priv) } spin_lock_init(&priv->ul_lock); - tsens_enable_irq(priv); + + /* VER_0 interrupt doesn't need to be enabled */ + if (tsens_version(priv) >= VER_0_1) + tsens_enable_irq(priv); + tsens_debug_init(op); err_put_device: @@ -943,10 +1010,19 @@ static int tsens_register_irq(struct tsens_priv *priv, char *irqname, if (irq == -ENXIO) ret = 0; } else { - ret = devm_request_threaded_irq(&pdev->dev, irq, - NULL, thread_fn, - IRQF_ONESHOT, - dev_name(&pdev->dev), priv); + /* VER_0 interrupt is TRIGGER_RISING, VER_0_1 and up is ONESHOT */ + if (tsens_version(priv) == VER_0) + ret = devm_request_threaded_irq(&pdev->dev, irq, + thread_fn, NULL, + IRQF_TRIGGER_RISING, + dev_name(&pdev->dev), + priv); + else + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, + thread_fn, IRQF_ONESHOT, + dev_name(&pdev->dev), + priv); + if (ret) dev_err(&pdev->dev, "%s: failed to get irq\n", __func__); @@ -975,6 +1051,19 @@ static int tsens_register(struct tsens_priv *priv) priv->ops->enable(priv, i); } + /* VER_0 require to set MIN and MAX THRESH + * These 2 regs are set using the: + * - CRIT_THRESH_0 for MAX THRESH hardcoded to 120°C + * - CRIT_THRESH_1 for MIN THRESH hardcoded to 0°C + */ + if (tsens_version(priv) < VER_0_1) { + regmap_field_write(priv->rf[CRIT_THRESH_0], + tsens_mC_to_hw(priv->sensor, 120000)); + + regmap_field_write(priv->rf[CRIT_THRESH_1], + tsens_mC_to_hw(priv->sensor, 0)); + } + ret = tsens_register_irq(priv, "uplow", tsens_irq_thread); if (ret < 0) return ret; diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h index f40b625f897e..8e6c1fd3ccf5 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -13,6 +13,7 @@ #define CAL_DEGC_PT2 120 #define SLOPE_FACTOR 1000 #define SLOPE_DEFAULT 3200 +#define TIMEOUT_US 100 #define THRESHOLD_MAX_ADC_CODE 0x3ff #define THRESHOLD_MIN_ADC_CODE 0x0 @@ -25,7 +26,8 @@ struct tsens_priv; /* IP version numbers in ascending order */ enum tsens_ver { - VER_0_1 = 0, + VER_0 = 0, + VER_0_1, VER_1_X, VER_2_X, };