static int hisi_thermal_register_sensor(struct platform_device *pdev, struct hisi_thermal_data *data, struct hisi_thermal_sensor *sensor, int index) { int ret, i; const struct thermal_trip *trip; sensor->id = index; sensor->thermal = data; sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, sensor->id, sensor, &hisi_of_thermal_ops); if (IS_ERR(sensor->tzd)) { ret = PTR_ERR(sensor->tzd); sensor->tzd = NULL; dev_err(&pdev->dev, "failed to register sensor id %d: %d\n", sensor->id, ret); return ret; } trip = of_thermal_get_trip_points(sensor->tzd); for (i = 0; i < of_thermal_get_ntrips(sensor->tzd); i++) { if (trip[i].type == THERMAL_TRIP_PASSIVE) { sensor->thres_temp = trip[i].temperature; break; } } return 0; }
static int uniphier_tm_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct regmap *regmap; struct device_node *parent; struct uniphier_tm_dev *tdev; const struct thermal_trip *trips; int i, ret, irq, ntrips, crit_temp = INT_MAX; tdev = devm_kzalloc(dev, sizeof(*tdev), GFP_KERNEL); if (!tdev) return -ENOMEM; tdev->dev = dev; tdev->data = of_device_get_match_data(dev); if (WARN_ON(!tdev->data)) return -EINVAL; irq = platform_get_irq(pdev, 0); if (irq < 0) return irq; /* get regmap from syscon node */ parent = of_get_parent(dev->of_node); /* parent should be syscon node */ regmap = syscon_node_to_regmap(parent); of_node_put(parent); if (IS_ERR(regmap)) { dev_err(dev, "failed to get regmap (error %ld)\n", PTR_ERR(regmap)); return PTR_ERR(regmap); } tdev->regmap = regmap; ret = uniphier_tm_initialize_sensor(tdev); if (ret) { dev_err(dev, "failed to initialize sensor\n"); return ret; } ret = devm_request_threaded_irq(dev, irq, uniphier_tm_alarm_irq, uniphier_tm_alarm_irq_thread, 0, "thermal", tdev); if (ret) return ret; platform_set_drvdata(pdev, tdev); tdev->tz_dev = devm_thermal_zone_of_sensor_register(dev, 0, tdev, &uniphier_of_thermal_ops); if (IS_ERR(tdev->tz_dev)) { dev_err(dev, "failed to register sensor device\n"); return PTR_ERR(tdev->tz_dev); } /* get trip points */ trips = of_thermal_get_trip_points(tdev->tz_dev); ntrips = of_thermal_get_ntrips(tdev->tz_dev); if (ntrips > ALERT_CH_NUM) { dev_err(dev, "thermal zone has too many trips\n"); return -E2BIG; } /* set alert temperatures */ for (i = 0; i < ntrips; i++) { if (trips[i].type == THERMAL_TRIP_CRITICAL && trips[i].temperature < crit_temp) crit_temp = trips[i].temperature; uniphier_tm_set_alert(tdev, i, trips[i].temperature); tdev->alert_en[i] = true; } if (crit_temp > CRITICAL_TEMP_LIMIT) { dev_err(dev, "critical trip is over limit(>%d), or not set\n", CRITICAL_TEMP_LIMIT); return -EINVAL; } uniphier_tm_enable_sensor(tdev); return 0; }