cregit-Linux how code gets into the kernel

Release 4.16 drivers/thermal/ti-soc-thermal/ti-thermal-common.c

/*
 * OMAP thermal driver interface
 *
 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
 * Contact:
 *   Eduardo Valentin <eduardo.valentin@ti.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */

#include <linux/device.h>
#include <linux/err.h>
#include <linux/mutex.h>
#include <linux/gfp.h>
#include <linux/kernel.h>
#include <linux/workqueue.h>
#include <linux/thermal.h>
#include <linux/cpufreq.h>
#include <linux/cpumask.h>
#include <linux/cpu_cooling.h>
#include <linux/of.h>

#include "ti-thermal.h"
#include "ti-bandgap.h"

/* common data structures */

struct ti_thermal_data {
	
struct cpufreq_policy *policy;
	
struct thermal_zone_device *ti_thermal;
	
struct thermal_zone_device *pcb_tz;
	
struct thermal_cooling_device *cool_dev;
	
struct ti_bandgap *bgp;
	
enum thermal_device_mode mode;
	
struct work_struct thermal_wq;
	
int sensor_id;
	
bool our_zone;
};


static void ti_thermal_work(struct work_struct *work) { struct ti_thermal_data *data = container_of(work, struct ti_thermal_data, thermal_wq); thermal_zone_device_update(data->ti_thermal, THERMAL_EVENT_UNSPECIFIED); dev_dbg(&data->ti_thermal->device, "updated thermal zone %s\n", data->ti_thermal->type); }

Contributors

PersonTokensPropCommitsCommitProp
Eduardo Valentin5196.23%266.67%
Srinivas Pandruvada23.77%133.33%
Total53100.00%3100.00%

/** * ti_thermal_hotspot_temperature - returns sensor extrapolated temperature * @t: omap sensor temperature * @s: omap sensor slope value * @c: omap sensor const value */
static inline int ti_thermal_hotspot_temperature(int t, int s, int c) { int delta = t * s / 1000 + c; if (delta < 0) delta = 0; return t + delta; }

Contributors

PersonTokensPropCommitsCommitProp
Eduardo Valentin42100.00%2100.00%
Total42100.00%2100.00%

/* thermal zone ops */ /* Get temperature callback function for thermal zone */
static inline int __ti_thermal_get_temp(void *devdata, int *temp) { struct thermal_zone_device *pcb_tz = NULL; struct ti_thermal_data *data = devdata; struct ti_bandgap *bgp; const struct ti_temp_sensor *s; int ret, tmp, slope, constant; int pcb_temp; if (!data) return 0; bgp = data->bgp; s = &bgp->conf->sensors[data->sensor_id]; ret = ti_bandgap_read_temperature(bgp, data->sensor_id, &tmp); if (ret) return ret; /* Default constants */ slope = thermal_zone_get_slope(data->ti_thermal); constant = thermal_zone_get_offset(data->ti_thermal); pcb_tz = data->pcb_tz; /* In case pcb zone is available, use the extrapolation rule with it */ if (!IS_ERR(pcb_tz)) { ret = thermal_zone_get_temp(pcb_tz, &pcb_temp); if (!ret) { tmp -= pcb_temp; /* got a valid PCB temp */ slope = s->slope_pcb; constant = s->constant_pcb; } else { dev_err(bgp->dev, "Failed to read PCB state. Using defaults\n"); ret = 0; } } *temp = ti_thermal_hotspot_temperature(tmp, slope, constant); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Eduardo Valentin19094.06%981.82%
J Keerthy104.95%19.09%
Sascha Hauer20.99%19.09%
Total202100.00%11100.00%


static inline int ti_thermal_get_temp(struct thermal_zone_device *thermal, int *temp) { struct ti_thermal_data *data = thermal->devdata; return __ti_thermal_get_temp(data, temp); }

Contributors

PersonTokensPropCommitsCommitProp
Eduardo Valentin3296.97%150.00%
Sascha Hauer13.03%150.00%
Total33100.00%2100.00%


static int __ti_thermal_get_trend(void *p, int trip, enum thermal_trend *trend) { struct ti_thermal_data *data = p; struct ti_bandgap *bgp; int id, tr, ret = 0; bgp = data->bgp; id = data->sensor_id; ret = ti_bandgap_get_trend(bgp, id, &tr); if (ret) return ret; if (tr > 0) *trend = THERMAL_TREND_RAISING; else if (tr < 0) *trend = THERMAL_TREND_DROPPING; else *trend = THERMAL_TREND_STABLE; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
J Keerthy6058.82%133.33%
Sascha Hauer2928.43%133.33%
Eduardo Valentin1312.75%133.33%
Total102100.00%3100.00%

static const struct thermal_zone_of_device_ops ti_of_thermal_ops = { .get_temp = __ti_thermal_get_temp, .get_trend = __ti_thermal_get_trend, };
static struct ti_thermal_data *ti_thermal_build_data(struct ti_bandgap *bgp, int id) { struct ti_thermal_data *data; data = devm_kzalloc(bgp->dev, sizeof(*data), GFP_KERNEL); if (!data) { dev_err(bgp->dev, "kzalloc fail\n"); return NULL; } data->sensor_id = id; data->bgp = bgp; data->mode = THERMAL_DEVICE_ENABLED; /* pcb_tz will be either valid or PTR_ERR() */ data->pcb_tz = thermal_zone_get_zone_by_name("pcb"); INIT_WORK(&data->thermal_wq, ti_thermal_work); return data; }

Contributors

PersonTokensPropCommitsCommitProp
Eduardo Valentin98100.00%6100.00%
Total98100.00%6100.00%


int ti_thermal_expose_sensor(struct ti_bandgap *bgp, int id, char *domain) { struct ti_thermal_data *data; data = ti_bandgap_get_sensor_data(bgp, id); if (!data || IS_ERR(data)) data = ti_thermal_build_data(bgp, id); if (!data) return -EINVAL; /* in case this is specified by DT */ data->ti_thermal = devm_thermal_zone_of_sensor_register(bgp->dev, id, data, &ti_of_thermal_ops); if (IS_ERR(data->ti_thermal)) { dev_err(bgp->dev, "thermal zone device is NULL\n"); return PTR_ERR(data->ti_thermal); } ti_bandgap_set_sensor_data(bgp, id, data); ti_bandgap_write_update_interval(bgp, data->sensor_id, data->ti_thermal->polling_delay); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Eduardo Valentin11687.22%981.82%
Ranganath Krishnan1511.28%19.09%
Cyril Roelandt21.50%19.09%
Total133100.00%11100.00%


int ti_thermal_remove_sensor(struct ti_bandgap *bgp, int id) { struct ti_thermal_data *data; data = ti_bandgap_get_sensor_data(bgp, id); if (data && data->ti_thermal) { if (data->our_zone) thermal_zone_device_unregister(data->ti_thermal); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Eduardo Valentin53100.00%4100.00%
Total53100.00%4100.00%


int ti_thermal_report_sensor_temperature(struct ti_bandgap *bgp, int id) { struct ti_thermal_data *data; data = ti_bandgap_get_sensor_data(bgp, id); schedule_work(&data->thermal_wq); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Eduardo Valentin38100.00%3100.00%
Total38100.00%3100.00%


int ti_thermal_register_cpu_cooling(struct ti_bandgap *bgp, int id) { struct ti_thermal_data *data; struct device_node *np = bgp->dev->of_node; /* * We are assuming here that if one deploys the zone * using DT, then it must be aware that the cooling device * loading has to happen via cpufreq driver. */ if (of_find_property(np, "#thermal-sensor-cells", NULL)) return 0; data = ti_bandgap_get_sensor_data(bgp, id); if (!data || IS_ERR(data)) data = ti_thermal_build_data(bgp, id); if (!data) return -EINVAL; data->policy = cpufreq_cpu_get(0); if (!data->policy) { pr_debug("%s: CPUFreq policy not found\n", __func__); return -EPROBE_DEFER; } /* Register cooling device */ data->cool_dev = cpufreq_cooling_register(data->policy); if (IS_ERR(data->cool_dev)) { int ret = PTR_ERR(data->cool_dev); dev_err(bgp->dev, "Failed to register cpu cooling device %d\n", ret); cpufreq_cpu_put(data->policy); return ret; } ti_bandgap_set_sensor_data(bgp, id, data); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Eduardo Valentin13576.70%777.78%
Viresh Kumar3922.16%111.11%
Cyril Roelandt21.14%111.11%
Total176100.00%9100.00%


int ti_thermal_unregister_cpu_cooling(struct ti_bandgap *bgp, int id) { struct ti_thermal_data *data; data = ti_bandgap_get_sensor_data(bgp, id); if (data) { cpufreq_cooling_unregister(data->cool_dev); if (data->policy) cpufreq_cpu_put(data->policy); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Eduardo Valentin4173.21%466.67%
Viresh Kumar916.07%116.67%
Tony Lindgren610.71%116.67%
Total56100.00%6100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Eduardo Valentin90682.97%1560.00%
J Keerthy706.41%28.00%
Viresh Kumar565.13%14.00%
Sascha Hauer322.93%28.00%
Ranganath Krishnan151.37%14.00%
Tony Lindgren60.55%14.00%
Cyril Roelandt40.37%14.00%
Srinivas Pandruvada20.18%14.00%
Pavel Machek10.09%14.00%
Total1092100.00%25100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.