Skip to content

Commit 1ef5a9f

Browse files
cyndisdlezcano
authored andcommitted
thermal/drivers/tegra-bpmp: Check if BPMP supports trip points
Check if BPMP supports thermal trip points, and if not, do not expose the .set_trips callback to the thermal core framework. This can happen in virtualized environments where asynchronous communication with VM BPMP drivers is not available. Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com> Acked-by: Thierry Reding <treding@nvidia.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://lore.kernel.org/r/20221129153914.2699041-1-cyndis@kapsi.fi
1 parent 72684d9 commit 1ef5a9f

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

drivers/thermal/tegra/tegra-bpmp-thermal.c

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,69 @@ static int tegra_bpmp_thermal_get_num_zones(struct tegra_bpmp *bpmp,
167167
return 0;
168168
}
169169

170+
static int tegra_bpmp_thermal_trips_supported(struct tegra_bpmp *bpmp, bool *supported)
171+
{
172+
struct mrq_thermal_host_to_bpmp_request req;
173+
union mrq_thermal_bpmp_to_host_response reply;
174+
struct tegra_bpmp_message msg;
175+
int err;
176+
177+
memset(&req, 0, sizeof(req));
178+
req.type = CMD_THERMAL_QUERY_ABI;
179+
req.query_abi.type = CMD_THERMAL_SET_TRIP;
180+
181+
memset(&msg, 0, sizeof(msg));
182+
msg.mrq = MRQ_THERMAL;
183+
msg.tx.data = &req;
184+
msg.tx.size = sizeof(req);
185+
msg.rx.data = &reply;
186+
msg.rx.size = sizeof(reply);
187+
188+
err = tegra_bpmp_transfer(bpmp, &msg);
189+
if (err)
190+
return err;
191+
192+
if (msg.rx.ret == 0) {
193+
*supported = true;
194+
return 0;
195+
} else if (msg.rx.ret == -BPMP_ENODEV) {
196+
*supported = false;
197+
return 0;
198+
} else {
199+
return -EINVAL;
200+
}
201+
}
202+
170203
static const struct thermal_zone_device_ops tegra_bpmp_of_thermal_ops = {
171204
.get_temp = tegra_bpmp_thermal_get_temp,
172205
.set_trips = tegra_bpmp_thermal_set_trips,
173206
};
174207

208+
static const struct thermal_zone_device_ops tegra_bpmp_of_thermal_ops_notrips = {
209+
.get_temp = tegra_bpmp_thermal_get_temp,
210+
};
211+
175212
static int tegra_bpmp_thermal_probe(struct platform_device *pdev)
176213
{
177214
struct tegra_bpmp *bpmp = dev_get_drvdata(pdev->dev.parent);
215+
const struct thermal_zone_device_ops *thermal_ops;
178216
struct tegra_bpmp_thermal *tegra;
179217
struct thermal_zone_device *tzd;
180218
unsigned int i, max_num_zones;
219+
bool supported;
181220
int err;
182221

222+
err = tegra_bpmp_thermal_trips_supported(bpmp, &supported);
223+
if (err) {
224+
dev_err(&pdev->dev, "failed to determine if trip points are supported\n");
225+
return err;
226+
}
227+
228+
if (supported)
229+
thermal_ops = &tegra_bpmp_of_thermal_ops;
230+
else
231+
thermal_ops = &tegra_bpmp_of_thermal_ops_notrips;
232+
183233
tegra = devm_kzalloc(&pdev->dev, sizeof(*tegra), GFP_KERNEL);
184234
if (!tegra)
185235
return -ENOMEM;
@@ -222,7 +272,7 @@ static int tegra_bpmp_thermal_probe(struct platform_device *pdev)
222272
}
223273

224274
tzd = devm_thermal_of_zone_register(
225-
&pdev->dev, i, zone, &tegra_bpmp_of_thermal_ops);
275+
&pdev->dev, i, zone, thermal_ops);
226276
if (IS_ERR(tzd)) {
227277
if (PTR_ERR(tzd) == -EPROBE_DEFER)
228278
return -EPROBE_DEFER;

0 commit comments

Comments
 (0)