···119119}120120121121/**122122+ * ti_errata814_bandgap_read_temp() - helper function to read dra7 sensor temperature123123+ * @bgp: pointer to ti_bandgap structure124124+ * @reg: desired register (offset) to be read125125+ *126126+ * Function to read dra7 bandgap sensor temperature. This is done separately127127+ * so as to workaround the errata "Bandgap Temperature read Dtemp can be128128+ * corrupted" - Errata ID: i814".129129+ * Read accesses to registers listed below can be corrupted due to incorrect130130+ * resynchronization between clock domains.131131+ * Read access to registers below can be corrupted :132132+ * CTRL_CORE_DTEMP_MPU/GPU/CORE/DSPEVE/IVA_n (n = 0 to 4)133133+ * CTRL_CORE_TEMP_SENSOR_MPU/GPU/CORE/DSPEVE/IVA_n134134+ *135135+ * Return: the register value.136136+ */137137+static u32 ti_errata814_bandgap_read_temp(struct ti_bandgap *bgp, u32 reg)138138+{139139+ u32 val1, val2;140140+141141+ val1 = ti_bandgap_readl(bgp, reg);142142+ val2 = ti_bandgap_readl(bgp, reg);143143+144144+ /* If both times we read the same value then that is right */145145+ if (val1 == val2)146146+ return val1;147147+148148+ /* if val1 and val2 are different read it third time */149149+ return ti_bandgap_readl(bgp, reg);150150+}151151+152152+/**122153 * ti_bandgap_read_temp() - helper function to read sensor temperature123154 * @bgp: pointer to ti_bandgap structure124155 * @id: bandgap sensor id···179148 }180149181150 /* read temperature */182182- temp = ti_bandgap_readl(bgp, reg);151151+ if (TI_BANDGAP_HAS(bgp, ERRATA_814))152152+ temp = ti_errata814_bandgap_read_temp(bgp, reg);153153+ else154154+ temp = ti_bandgap_readl(bgp, reg);155155+183156 temp &= tsr->bgap_dtemp_mask;184157185158 if (TI_BANDGAP_HAS(bgp, FREEZE_BIT))···445410{446411 struct temp_sensor_data *ts_data = bgp->conf->sensors[id].ts_data;447412 struct temp_sensor_registers *tsr;448448- u32 thresh_val, reg_val, t_hot, t_cold;413413+ u32 thresh_val, reg_val, t_hot, t_cold, ctrl;449414 int err = 0;450415451416 tsr = bgp->conf->sensors[id].registers;···477442 ~(tsr->threshold_thot_mask | tsr->threshold_tcold_mask);478443 reg_val |= (t_hot << __ffs(tsr->threshold_thot_mask)) |479444 (t_cold << __ffs(tsr->threshold_tcold_mask));445445+446446+ /**447447+ * Errata i813:448448+ * Spurious Thermal Alert: Talert can happen randomly while the device449449+ * remains under the temperature limit defined for this event to trig.450450+ * This spurious event is caused by a incorrect re-synchronization451451+ * between clock domains. The comparison between configured threshold452452+ * and current temperature value can happen while the value is453453+ * transitioning (metastable), thus causing inappropriate event454454+ * generation. No spurious event occurs as long as the threshold value455455+ * stays unchanged. Spurious event can be generated while a thermal456456+ * alert threshold is modified in457457+ * CONTROL_BANDGAP_THRESHOLD_MPU/GPU/CORE/DSPEVE/IVA_n.458458+ */459459+460460+ if (TI_BANDGAP_HAS(bgp, ERRATA_813)) {461461+ /* Mask t_hot and t_cold events at the IP Level */462462+ ctrl = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl);463463+464464+ if (hot)465465+ ctrl &= ~tsr->mask_hot_mask;466466+ else467467+ ctrl &= ~tsr->mask_cold_mask;468468+469469+ ti_bandgap_writel(bgp, ctrl, tsr->bgap_mask_ctrl);470470+ }471471+472472+ /* Write the threshold value */480473 ti_bandgap_writel(bgp, reg_val, tsr->bgap_threshold);474474+475475+ if (TI_BANDGAP_HAS(bgp, ERRATA_813)) {476476+ /* Unmask t_hot and t_cold events at the IP Level */477477+ ctrl = ti_bandgap_readl(bgp, tsr->bgap_mask_ctrl);478478+ if (hot)479479+ ctrl |= tsr->mask_hot_mask;480480+ else481481+ ctrl |= tsr->mask_cold_mask;482482+483483+ ti_bandgap_writel(bgp, ctrl, tsr->bgap_mask_ctrl);484484+ }481485482486 if (err) {483487 dev_err(bgp->dev, "failed to reprogram thot threshold\n");
+6
drivers/thermal/ti-soc-thermal/ti-bandgap.h
···318318 * TI_BANDGAP_FEATURE_HISTORY_BUFFER - used when the bandgap device features319319 * a history buffer of temperatures.320320 *321321+ * TI_BANDGAP_FEATURE_ERRATA_814 - used to workaorund when the bandgap device322322+ * has Errata 814323323+ * TI_BANDGAP_FEATURE_ERRATA_813 - used to workaorund when the bandgap device324324+ * has Errata 813321325 * TI_BANDGAP_HAS(b, f) - macro to check if a bandgap device is capable of a322326 * specific feature (above) or not. Return non-zero, if yes.323327 */···335331#define TI_BANDGAP_FEATURE_FREEZE_BIT BIT(7)336332#define TI_BANDGAP_FEATURE_COUNTER_DELAY BIT(8)337333#define TI_BANDGAP_FEATURE_HISTORY_BUFFER BIT(9)334334+#define TI_BANDGAP_FEATURE_ERRATA_814 BIT(10)335335+#define TI_BANDGAP_FEATURE_ERRATA_813 BIT(11)338336#define TI_BANDGAP_HAS(b, f) \339337 ((b)->conf->features & TI_BANDGAP_FEATURE_ ## f)340338