static int add_dts_thermal_zone()

in intel/intel_soc_dts_iosf.c [283:345]


static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts,
				bool notification_support, int trip_cnt,
				int read_only_trip_cnt)
{
	char name[10];
	unsigned long trip;
	int trip_count = 0;
	int trip_mask = 0;
	int writable_trip_cnt = 0;
	unsigned long ptps;
	u32 store_ptps;
	unsigned long i;
	int ret;

	/* Store status to restor on exit */
	ret = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ,
			    SOC_DTS_OFFSET_ENABLE, &dts->store_status);
	if (ret)
		goto err_ret;

	dts->id = id;
	if (notification_support) {
		trip_count = min(SOC_MAX_DTS_TRIPS, trip_cnt);
		writable_trip_cnt = trip_count - read_only_trip_cnt;
		trip_mask = GENMASK(writable_trip_cnt - 1, 0);
	}

	/* Check if the writable trip we provide is not used by BIOS */
	ret = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ,
			    SOC_DTS_OFFSET_PTPS, &store_ptps);
	if (ret)
		trip_mask = 0;
	else {
		ptps = store_ptps;
		for_each_set_clump8(i, trip, &ptps, writable_trip_cnt * 8)
			trip_mask &= ~BIT(i / 8);
	}
	dts->trip_mask = trip_mask;
	dts->trip_count = trip_count;
	snprintf(name, sizeof(name), "soc_dts%d", id);
	dts->tzone = thermal_zone_device_register(name,
						  trip_count,
						  trip_mask,
						  dts, &tzone_ops,
						  NULL, 0, 0);
	if (IS_ERR(dts->tzone)) {
		ret = PTR_ERR(dts->tzone);
		goto err_ret;
	}
	ret = thermal_zone_device_enable(dts->tzone);
	if (ret)
		goto err_enable;

	ret = soc_dts_enable(id);
	if (ret)
		goto err_enable;

	return 0;
err_enable:
	thermal_zone_device_unregister(dts->tzone);
err_ret:
	return ret;
}