aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/thermal/qcom/tsens.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/thermal/qcom/tsens.c')
-rw-r--r--drivers/thermal/qcom/tsens.c100
1 files changed, 54 insertions, 46 deletions
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c
index f1ec9bbe4717..36b0b52db524 100644
--- a/drivers/thermal/qcom/tsens.c
+++ b/drivers/thermal/qcom/tsens.c
@@ -15,38 +15,38 @@
15static int tsens_get_temp(void *data, int *temp) 15static int tsens_get_temp(void *data, int *temp)
16{ 16{
17 const struct tsens_sensor *s = data; 17 const struct tsens_sensor *s = data;
18 struct tsens_device *tmdev = s->tmdev; 18 struct tsens_priv *priv = s->priv;
19 19
20 return tmdev->ops->get_temp(tmdev, s->id, temp); 20 return priv->ops->get_temp(priv, s->id, temp);
21} 21}
22 22
23static int tsens_get_trend(void *p, int trip, enum thermal_trend *trend) 23static int tsens_get_trend(void *data, int trip, enum thermal_trend *trend)
24{ 24{
25 const struct tsens_sensor *s = p; 25 const struct tsens_sensor *s = data;
26 struct tsens_device *tmdev = s->tmdev; 26 struct tsens_priv *priv = s->priv;
27 27
28 if (tmdev->ops->get_trend) 28 if (priv->ops->get_trend)
29 return tmdev->ops->get_trend(tmdev, s->id, trend); 29 return priv->ops->get_trend(priv, s->id, trend);
30 30
31 return -ENOTSUPP; 31 return -ENOTSUPP;
32} 32}
33 33
34static int __maybe_unused tsens_suspend(struct device *dev) 34static int __maybe_unused tsens_suspend(struct device *dev)
35{ 35{
36 struct tsens_device *tmdev = dev_get_drvdata(dev); 36 struct tsens_priv *priv = dev_get_drvdata(dev);
37 37
38 if (tmdev->ops && tmdev->ops->suspend) 38 if (priv->ops && priv->ops->suspend)
39 return tmdev->ops->suspend(tmdev); 39 return priv->ops->suspend(priv);
40 40
41 return 0; 41 return 0;
42} 42}
43 43
44static int __maybe_unused tsens_resume(struct device *dev) 44static int __maybe_unused tsens_resume(struct device *dev)
45{ 45{
46 struct tsens_device *tmdev = dev_get_drvdata(dev); 46 struct tsens_priv *priv = dev_get_drvdata(dev);
47 47
48 if (tmdev->ops && tmdev->ops->resume) 48 if (priv->ops && priv->ops->resume)
49 return tmdev->ops->resume(tmdev); 49 return priv->ops->resume(priv);
50 50
51 return 0; 51 return 0;
52} 52}
@@ -64,6 +64,9 @@ static const struct of_device_id tsens_table[] = {
64 .compatible = "qcom,msm8996-tsens", 64 .compatible = "qcom,msm8996-tsens",
65 .data = &data_8996, 65 .data = &data_8996,
66 }, { 66 }, {
67 .compatible = "qcom,tsens-v1",
68 .data = &data_tsens_v1,
69 }, {
67 .compatible = "qcom,tsens-v2", 70 .compatible = "qcom,tsens-v2",
68 .data = &data_tsens_v2, 71 .data = &data_tsens_v2,
69 }, 72 },
@@ -76,22 +79,27 @@ static const struct thermal_zone_of_device_ops tsens_of_ops = {
76 .get_trend = tsens_get_trend, 79 .get_trend = tsens_get_trend,
77}; 80};
78 81
79static int tsens_register(struct tsens_device *tmdev) 82static int tsens_register(struct tsens_priv *priv)
80{ 83{
81 int i; 84 int i;
82 struct thermal_zone_device *tzd; 85 struct thermal_zone_device *tzd;
83 86
84 for (i = 0; i < tmdev->num_sensors; i++) { 87 for (i = 0; i < priv->num_sensors; i++) {
85 tmdev->sensor[i].tmdev = tmdev; 88 if (!is_sensor_enabled(priv, priv->sensor[i].hw_id)) {
86 tmdev->sensor[i].id = i; 89 dev_err(priv->dev, "sensor %d: disabled\n",
87 tzd = devm_thermal_zone_of_sensor_register(tmdev->dev, i, 90 priv->sensor[i].hw_id);
88 &tmdev->sensor[i], 91 continue;
92 }
93 priv->sensor[i].priv = priv;
94 priv->sensor[i].id = i;
95 tzd = devm_thermal_zone_of_sensor_register(priv->dev, i,
96 &priv->sensor[i],
89 &tsens_of_ops); 97 &tsens_of_ops);
90 if (IS_ERR(tzd)) 98 if (IS_ERR(tzd))
91 continue; 99 continue;
92 tmdev->sensor[i].tzd = tzd; 100 priv->sensor[i].tzd = tzd;
93 if (tmdev->ops->enable) 101 if (priv->ops->enable)
94 tmdev->ops->enable(tmdev, i); 102 priv->ops->enable(priv, i);
95 } 103 }
96 return 0; 104 return 0;
97} 105}
@@ -101,8 +109,8 @@ static int tsens_probe(struct platform_device *pdev)
101 int ret, i; 109 int ret, i;
102 struct device *dev; 110 struct device *dev;
103 struct device_node *np; 111 struct device_node *np;
104 struct tsens_device *tmdev; 112 struct tsens_priv *priv;
105 const struct tsens_data *data; 113 const struct tsens_plat_data *data;
106 const struct of_device_id *id; 114 const struct of_device_id *id;
107 u32 num_sensors; 115 u32 num_sensors;
108 116
@@ -129,55 +137,55 @@ static int tsens_probe(struct platform_device *pdev)
129 return -EINVAL; 137 return -EINVAL;
130 } 138 }
131 139
132 tmdev = devm_kzalloc(dev, 140 priv = devm_kzalloc(dev,
133 struct_size(tmdev, sensor, num_sensors), 141 struct_size(priv, sensor, num_sensors),
134 GFP_KERNEL); 142 GFP_KERNEL);
135 if (!tmdev) 143 if (!priv)
136 return -ENOMEM; 144 return -ENOMEM;
137 145
138 tmdev->dev = dev; 146 priv->dev = dev;
139 tmdev->num_sensors = num_sensors; 147 priv->num_sensors = num_sensors;
140 tmdev->ops = data->ops; 148 priv->ops = data->ops;
141 for (i = 0; i < tmdev->num_sensors; i++) { 149 for (i = 0; i < priv->num_sensors; i++) {
142 if (data->hw_ids) 150 if (data->hw_ids)
143 tmdev->sensor[i].hw_id = data->hw_ids[i]; 151 priv->sensor[i].hw_id = data->hw_ids[i];
144 else 152 else
145 tmdev->sensor[i].hw_id = i; 153 priv->sensor[i].hw_id = i;
146 }
147 for (i = 0; i < REG_ARRAY_SIZE; i++) {
148 tmdev->reg_offsets[i] = data->reg_offsets[i];
149 } 154 }
155 priv->feat = data->feat;
156 priv->fields = data->fields;
150 157
151 if (!tmdev->ops || !tmdev->ops->init || !tmdev->ops->get_temp) 158 if (!priv->ops || !priv->ops->init || !priv->ops->get_temp)
152 return -EINVAL; 159 return -EINVAL;
153 160
154 ret = tmdev->ops->init(tmdev); 161 ret = priv->ops->init(priv);
155 if (ret < 0) { 162 if (ret < 0) {
156 dev_err(dev, "tsens init failed\n"); 163 dev_err(dev, "tsens init failed\n");
157 return ret; 164 return ret;
158 } 165 }
159 166
160 if (tmdev->ops->calibrate) { 167 if (priv->ops->calibrate) {
161 ret = tmdev->ops->calibrate(tmdev); 168 ret = priv->ops->calibrate(priv);
162 if (ret < 0) { 169 if (ret < 0) {
163 dev_err(dev, "tsens calibration failed\n"); 170 if (ret != -EPROBE_DEFER)
171 dev_err(dev, "tsens calibration failed\n");
164 return ret; 172 return ret;
165 } 173 }
166 } 174 }
167 175
168 ret = tsens_register(tmdev); 176 ret = tsens_register(priv);
169 177
170 platform_set_drvdata(pdev, tmdev); 178 platform_set_drvdata(pdev, priv);
171 179
172 return ret; 180 return ret;
173} 181}
174 182
175static int tsens_remove(struct platform_device *pdev) 183static int tsens_remove(struct platform_device *pdev)
176{ 184{
177 struct tsens_device *tmdev = platform_get_drvdata(pdev); 185 struct tsens_priv *priv = platform_get_drvdata(pdev);
178 186
179 if (tmdev->ops->disable) 187 if (priv->ops->disable)
180 tmdev->ops->disable(tmdev); 188 priv->ops->disable(priv);
181 189
182 return 0; 190 return 0;
183} 191}