Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b221797b authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "drivers: of-thermal: Group sensor related information" into msm-4.9

parents a689190c e34ced65
Loading
Loading
Loading
Loading
+45 −23
Original line number Diff line number Diff line
@@ -53,6 +53,16 @@ struct __thermal_bind_params {
	unsigned long max;
};

/**
 * struct __sensor_param - Holds individual sensor data
 * @sensor_data: sensor driver private data passed as input argument
 * @ops: sensor driver ops
 */
struct __sensor_param {
	void *sensor_data;
	const struct thermal_zone_of_device_ops *ops;
};

/**
 * struct __thermal_zone - internal representation of a thermal zone
 * @mode: current thermal zone device mode (enabled/disabled)
@@ -64,8 +74,7 @@ struct __thermal_bind_params {
 * @trips: an array of trip points (0..ntrips - 1)
 * @num_tbps: number of thermal bind params
 * @tbps: an array of thermal bind params (0..num_tbps - 1)
 * @sensor_data: sensor private data used while reading temperature and trend
 * @ops: set of callbacks to handle the thermal zone based on DT
 * @senps: sensor related parameters
 */

struct __thermal_zone {
@@ -84,8 +93,7 @@ struct __thermal_zone {
	struct __thermal_bind_params *tbps;

	/* sensor interface */
	void *sensor_data;
	const struct thermal_zone_of_device_ops *ops;
	struct __sensor_param *senps;
};

/***   DT thermal zone device callbacks   ***/
@@ -95,10 +103,10 @@ static int of_thermal_get_temp(struct thermal_zone_device *tz,
{
	struct __thermal_zone *data = tz->devdata;

	if (!data->ops->get_temp)
	if (!data->senps || !data->senps->ops->get_temp)
		return -EINVAL;

	return data->ops->get_temp(data->sensor_data, temp);
	return data->senps->ops->get_temp(data->senps->sensor_data, temp);
}

static int of_thermal_set_trips(struct thermal_zone_device *tz,
@@ -106,10 +114,10 @@ static int of_thermal_set_trips(struct thermal_zone_device *tz,
{
	struct __thermal_zone *data = tz->devdata;

	if (!data->ops || !data->ops->set_trips)
	if (!data->senps || !data->senps->ops->set_trips)
		return -EINVAL;

	return data->ops->set_trips(data->sensor_data, low, high);
	return data->senps->ops->set_trips(data->senps->sensor_data, low, high);
}

/**
@@ -192,7 +200,10 @@ static int of_thermal_set_emul_temp(struct thermal_zone_device *tz,
{
	struct __thermal_zone *data = tz->devdata;

	return data->ops->set_emul_temp(data->sensor_data, temp);
	if (!data->senps || !data->senps->ops->set_emul_temp)
		return -EINVAL;

	return data->senps->ops->set_emul_temp(data->senps->sensor_data, temp);
}

static int of_thermal_get_trend(struct thermal_zone_device *tz, int trip,
@@ -200,10 +211,11 @@ static int of_thermal_get_trend(struct thermal_zone_device *tz, int trip,
{
	struct __thermal_zone *data = tz->devdata;

	if (!data->ops->get_trend)
	if (!data->senps || !data->senps->ops->get_trend)
		return -EINVAL;

	return data->ops->get_trend(data->sensor_data, trip, trend);
	return data->senps->ops->get_trend(data->senps->sensor_data,
					   trip, trend);
}

static int of_thermal_bind(struct thermal_zone_device *thermal,
@@ -325,10 +337,11 @@ static int of_thermal_set_trip_temp(struct thermal_zone_device *tz, int trip,
	if (trip >= data->ntrips || trip < 0)
		return -EDOM;

	if (data->ops->set_trip_temp) {
	if (data->senps && data->senps->ops->set_trip_temp) {
		int ret;

		ret = data->ops->set_trip_temp(data->sensor_data, trip, temp);
		ret = data->senps->ops->set_trip_temp(data->senps->sensor_data,
						      trip, temp);
		if (ret)
			return ret;
	}
@@ -400,8 +413,8 @@ static struct thermal_zone_device_ops of_thermal_ops = {

static struct thermal_zone_device *
thermal_zone_of_add_sensor(struct device_node *zone,
			   struct device_node *sensor, void *data,
			   const struct thermal_zone_of_device_ops *ops)
			   struct device_node *sensor,
			   struct __sensor_param *sens_param)
{
	struct thermal_zone_device *tzd;
	struct __thermal_zone *tz;
@@ -412,12 +425,11 @@ thermal_zone_of_add_sensor(struct device_node *zone,

	tz = tzd->devdata;

	if (!ops)
	if (!sens_param->ops)
		return ERR_PTR(-EINVAL);

	mutex_lock(&tzd->lock);
	tz->ops = ops;
	tz->sensor_data = data;
	tz->senps = sens_param;

	tzd->ops->get_temp = of_thermal_get_temp;
	tzd->ops->get_trend = of_thermal_get_trend;
@@ -426,10 +438,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
	 * The thermal zone core will calculate the window if they have set the
	 * optional set_trips pointer.
	 */
	if (ops->set_trips)
	if (sens_param->ops->set_trips)
		tzd->ops->set_trips = of_thermal_set_trips;

	if (ops->set_emul_temp)
	if (sens_param->ops->set_emul_temp)
		tzd->ops->set_emul_temp = of_thermal_set_emul_temp;

	mutex_unlock(&tzd->lock);
@@ -475,6 +487,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data,
{
	struct device_node *np, *child, *sensor_np;
	struct thermal_zone_device *tzd = ERR_PTR(-ENODEV);
	struct __sensor_param *sens_param = NULL;

	np = of_find_node_by_name(NULL, "thermal-zones");
	if (!np)
@@ -485,6 +498,13 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data,
		return ERR_PTR(-EINVAL);
	}

	sens_param = kzalloc(sizeof(*sens_param), GFP_KERNEL);
	if (!sens_param) {
		of_node_put(np);
		return ERR_PTR(-ENOMEM);
	}
	sens_param->sensor_data = data;
	sens_param->ops = ops;
	sensor_np = of_node_get(dev->of_node);

	for_each_available_child_of_node(np, child) {
@@ -509,7 +529,7 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data,

		if (sensor_specs.np == sensor_np && id == sensor_id) {
			tzd = thermal_zone_of_add_sensor(child, sensor_np,
							 data, ops);
							 sens_param);
			if (!IS_ERR(tzd))
				tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED);

@@ -523,6 +543,8 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id, void *data,
	of_node_put(sensor_np);
	of_node_put(np);

	if (tzd == ERR_PTR(-ENODEV))
		kfree(sens_param);
	return tzd;
}
EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_register);
@@ -561,8 +583,8 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
	tzd->ops->get_trend = NULL;
	tzd->ops->set_emul_temp = NULL;

	tz->ops = NULL;
	tz->sensor_data = NULL;
	kfree(tz->senps);
	tz->senps = NULL;
	mutex_unlock(&tzd->lock);
}
EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_unregister);