| .. | .. |
|---|
| 55 | 55 | #define HI3660_TEMP_STEP (205) |
|---|
| 56 | 56 | #define HI3660_TEMP_LAG (4000) |
|---|
| 57 | 57 | |
|---|
| 58 | | -#define HI6220_DEFAULT_SENSOR 2 |
|---|
| 59 | | -#define HI3660_DEFAULT_SENSOR 1 |
|---|
| 58 | +#define HI6220_CLUSTER0_SENSOR 2 |
|---|
| 59 | +#define HI6220_CLUSTER1_SENSOR 1 |
|---|
| 60 | + |
|---|
| 61 | +#define HI3660_LITTLE_SENSOR 0 |
|---|
| 62 | +#define HI3660_BIG_SENSOR 1 |
|---|
| 63 | +#define HI3660_G3D_SENSOR 2 |
|---|
| 64 | +#define HI3660_MODEM_SENSOR 3 |
|---|
| 65 | + |
|---|
| 66 | +struct hisi_thermal_data; |
|---|
| 60 | 67 | |
|---|
| 61 | 68 | struct hisi_thermal_sensor { |
|---|
| 69 | + struct hisi_thermal_data *data; |
|---|
| 62 | 70 | struct thermal_zone_device *tzd; |
|---|
| 71 | + const char *irq_name; |
|---|
| 63 | 72 | uint32_t id; |
|---|
| 64 | 73 | uint32_t thres_temp; |
|---|
| 65 | 74 | }; |
|---|
| 66 | 75 | |
|---|
| 76 | +struct hisi_thermal_ops { |
|---|
| 77 | + int (*get_temp)(struct hisi_thermal_sensor *sensor); |
|---|
| 78 | + int (*enable_sensor)(struct hisi_thermal_sensor *sensor); |
|---|
| 79 | + int (*disable_sensor)(struct hisi_thermal_sensor *sensor); |
|---|
| 80 | + int (*irq_handler)(struct hisi_thermal_sensor *sensor); |
|---|
| 81 | + int (*probe)(struct hisi_thermal_data *data); |
|---|
| 82 | +}; |
|---|
| 83 | + |
|---|
| 67 | 84 | struct hisi_thermal_data { |
|---|
| 68 | | - int (*get_temp)(struct hisi_thermal_data *data); |
|---|
| 69 | | - int (*enable_sensor)(struct hisi_thermal_data *data); |
|---|
| 70 | | - int (*disable_sensor)(struct hisi_thermal_data *data); |
|---|
| 71 | | - int (*irq_handler)(struct hisi_thermal_data *data); |
|---|
| 85 | + const struct hisi_thermal_ops *ops; |
|---|
| 86 | + struct hisi_thermal_sensor *sensor; |
|---|
| 72 | 87 | struct platform_device *pdev; |
|---|
| 73 | 88 | struct clk *clk; |
|---|
| 74 | | - struct hisi_thermal_sensor sensor; |
|---|
| 75 | 89 | void __iomem *regs; |
|---|
| 76 | | - int irq; |
|---|
| 90 | + int nr_sensors; |
|---|
| 77 | 91 | }; |
|---|
| 78 | 92 | |
|---|
| 79 | 93 | /* |
|---|
| .. | .. |
|---|
| 266 | 280 | (value << 4), addr + HI6220_TEMP0_CFG); |
|---|
| 267 | 281 | } |
|---|
| 268 | 282 | |
|---|
| 269 | | -static int hi6220_thermal_irq_handler(struct hisi_thermal_data *data) |
|---|
| 283 | +static int hi6220_thermal_irq_handler(struct hisi_thermal_sensor *sensor) |
|---|
| 270 | 284 | { |
|---|
| 285 | + struct hisi_thermal_data *data = sensor->data; |
|---|
| 286 | + |
|---|
| 271 | 287 | hi6220_thermal_alarm_clear(data->regs, 1); |
|---|
| 272 | 288 | return 0; |
|---|
| 273 | 289 | } |
|---|
| 274 | 290 | |
|---|
| 275 | | -static int hi3660_thermal_irq_handler(struct hisi_thermal_data *data) |
|---|
| 291 | +static int hi3660_thermal_irq_handler(struct hisi_thermal_sensor *sensor) |
|---|
| 276 | 292 | { |
|---|
| 277 | | - hi3660_thermal_alarm_clear(data->regs, data->sensor.id, 1); |
|---|
| 293 | + struct hisi_thermal_data *data = sensor->data; |
|---|
| 294 | + |
|---|
| 295 | + hi3660_thermal_alarm_clear(data->regs, sensor->id, 1); |
|---|
| 278 | 296 | return 0; |
|---|
| 279 | 297 | } |
|---|
| 280 | 298 | |
|---|
| 281 | | -static int hi6220_thermal_get_temp(struct hisi_thermal_data *data) |
|---|
| 299 | +static int hi6220_thermal_get_temp(struct hisi_thermal_sensor *sensor) |
|---|
| 282 | 300 | { |
|---|
| 301 | + struct hisi_thermal_data *data = sensor->data; |
|---|
| 302 | + |
|---|
| 283 | 303 | return hi6220_thermal_get_temperature(data->regs); |
|---|
| 284 | 304 | } |
|---|
| 285 | 305 | |
|---|
| 286 | | -static int hi3660_thermal_get_temp(struct hisi_thermal_data *data) |
|---|
| 306 | +static int hi3660_thermal_get_temp(struct hisi_thermal_sensor *sensor) |
|---|
| 287 | 307 | { |
|---|
| 288 | | - return hi3660_thermal_get_temperature(data->regs, data->sensor.id); |
|---|
| 308 | + struct hisi_thermal_data *data = sensor->data; |
|---|
| 309 | + |
|---|
| 310 | + return hi3660_thermal_get_temperature(data->regs, sensor->id); |
|---|
| 289 | 311 | } |
|---|
| 290 | 312 | |
|---|
| 291 | | -static int hi6220_thermal_disable_sensor(struct hisi_thermal_data *data) |
|---|
| 313 | +static int hi6220_thermal_disable_sensor(struct hisi_thermal_sensor *sensor) |
|---|
| 292 | 314 | { |
|---|
| 315 | + struct hisi_thermal_data *data = sensor->data; |
|---|
| 316 | + |
|---|
| 293 | 317 | /* disable sensor module */ |
|---|
| 294 | 318 | hi6220_thermal_enable(data->regs, 0); |
|---|
| 295 | 319 | hi6220_thermal_alarm_enable(data->regs, 0); |
|---|
| .. | .. |
|---|
| 300 | 324 | return 0; |
|---|
| 301 | 325 | } |
|---|
| 302 | 326 | |
|---|
| 303 | | -static int hi3660_thermal_disable_sensor(struct hisi_thermal_data *data) |
|---|
| 327 | +static int hi3660_thermal_disable_sensor(struct hisi_thermal_sensor *sensor) |
|---|
| 304 | 328 | { |
|---|
| 329 | + struct hisi_thermal_data *data = sensor->data; |
|---|
| 330 | + |
|---|
| 305 | 331 | /* disable sensor module */ |
|---|
| 306 | | - hi3660_thermal_alarm_enable(data->regs, data->sensor.id, 0); |
|---|
| 332 | + hi3660_thermal_alarm_enable(data->regs, sensor->id, 0); |
|---|
| 307 | 333 | return 0; |
|---|
| 308 | 334 | } |
|---|
| 309 | 335 | |
|---|
| 310 | | -static int hi6220_thermal_enable_sensor(struct hisi_thermal_data *data) |
|---|
| 336 | +static int hi6220_thermal_enable_sensor(struct hisi_thermal_sensor *sensor) |
|---|
| 311 | 337 | { |
|---|
| 312 | | - struct hisi_thermal_sensor *sensor = &data->sensor; |
|---|
| 338 | + struct hisi_thermal_data *data = sensor->data; |
|---|
| 313 | 339 | int ret; |
|---|
| 314 | 340 | |
|---|
| 315 | 341 | /* enable clock for tsensor */ |
|---|
| .. | .. |
|---|
| 345 | 371 | return 0; |
|---|
| 346 | 372 | } |
|---|
| 347 | 373 | |
|---|
| 348 | | -static int hi3660_thermal_enable_sensor(struct hisi_thermal_data *data) |
|---|
| 374 | +static int hi3660_thermal_enable_sensor(struct hisi_thermal_sensor *sensor) |
|---|
| 349 | 375 | { |
|---|
| 350 | 376 | unsigned int value; |
|---|
| 351 | | - struct hisi_thermal_sensor *sensor = &data->sensor; |
|---|
| 377 | + struct hisi_thermal_data *data = sensor->data; |
|---|
| 352 | 378 | |
|---|
| 353 | 379 | /* disable interrupt */ |
|---|
| 354 | 380 | hi3660_thermal_alarm_enable(data->regs, sensor->id, 0); |
|---|
| .. | .. |
|---|
| 371 | 397 | { |
|---|
| 372 | 398 | struct platform_device *pdev = data->pdev; |
|---|
| 373 | 399 | struct device *dev = &pdev->dev; |
|---|
| 374 | | - struct resource *res; |
|---|
| 375 | 400 | int ret; |
|---|
| 376 | | - |
|---|
| 377 | | - data->get_temp = hi6220_thermal_get_temp; |
|---|
| 378 | | - data->enable_sensor = hi6220_thermal_enable_sensor; |
|---|
| 379 | | - data->disable_sensor = hi6220_thermal_disable_sensor; |
|---|
| 380 | | - data->irq_handler = hi6220_thermal_irq_handler; |
|---|
| 381 | | - |
|---|
| 382 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 383 | | - data->regs = devm_ioremap_resource(dev, res); |
|---|
| 384 | | - if (IS_ERR(data->regs)) { |
|---|
| 385 | | - dev_err(dev, "failed to get io address\n"); |
|---|
| 386 | | - return PTR_ERR(data->regs); |
|---|
| 387 | | - } |
|---|
| 388 | 401 | |
|---|
| 389 | 402 | data->clk = devm_clk_get(dev, "thermal_clk"); |
|---|
| 390 | 403 | if (IS_ERR(data->clk)) { |
|---|
| .. | .. |
|---|
| 394 | 407 | return ret; |
|---|
| 395 | 408 | } |
|---|
| 396 | 409 | |
|---|
| 397 | | - data->irq = platform_get_irq(pdev, 0); |
|---|
| 398 | | - if (data->irq < 0) |
|---|
| 399 | | - return data->irq; |
|---|
| 410 | + data->sensor = devm_kzalloc(dev, sizeof(*data->sensor), GFP_KERNEL); |
|---|
| 411 | + if (!data->sensor) |
|---|
| 412 | + return -ENOMEM; |
|---|
| 400 | 413 | |
|---|
| 401 | | - data->sensor.id = HI6220_DEFAULT_SENSOR; |
|---|
| 414 | + data->sensor[0].id = HI6220_CLUSTER0_SENSOR; |
|---|
| 415 | + data->sensor[0].irq_name = "tsensor_intr"; |
|---|
| 416 | + data->sensor[0].data = data; |
|---|
| 417 | + data->nr_sensors = 1; |
|---|
| 402 | 418 | |
|---|
| 403 | 419 | return 0; |
|---|
| 404 | 420 | } |
|---|
| .. | .. |
|---|
| 407 | 423 | { |
|---|
| 408 | 424 | struct platform_device *pdev = data->pdev; |
|---|
| 409 | 425 | struct device *dev = &pdev->dev; |
|---|
| 410 | | - struct resource *res; |
|---|
| 411 | 426 | |
|---|
| 412 | | - data->get_temp = hi3660_thermal_get_temp; |
|---|
| 413 | | - data->enable_sensor = hi3660_thermal_enable_sensor; |
|---|
| 414 | | - data->disable_sensor = hi3660_thermal_disable_sensor; |
|---|
| 415 | | - data->irq_handler = hi3660_thermal_irq_handler; |
|---|
| 427 | + data->nr_sensors = 1; |
|---|
| 416 | 428 | |
|---|
| 417 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 418 | | - data->regs = devm_ioremap_resource(dev, res); |
|---|
| 419 | | - if (IS_ERR(data->regs)) { |
|---|
| 420 | | - dev_err(dev, "failed to get io address\n"); |
|---|
| 421 | | - return PTR_ERR(data->regs); |
|---|
| 422 | | - } |
|---|
| 429 | + data->sensor = devm_kzalloc(dev, sizeof(*data->sensor) * |
|---|
| 430 | + data->nr_sensors, GFP_KERNEL); |
|---|
| 431 | + if (!data->sensor) |
|---|
| 432 | + return -ENOMEM; |
|---|
| 423 | 433 | |
|---|
| 424 | | - data->irq = platform_get_irq(pdev, 0); |
|---|
| 425 | | - if (data->irq < 0) |
|---|
| 426 | | - return data->irq; |
|---|
| 434 | + data->sensor[0].id = HI3660_BIG_SENSOR; |
|---|
| 435 | + data->sensor[0].irq_name = "tsensor_a73"; |
|---|
| 436 | + data->sensor[0].data = data; |
|---|
| 427 | 437 | |
|---|
| 428 | | - data->sensor.id = HI3660_DEFAULT_SENSOR; |
|---|
| 438 | + data->sensor[1].id = HI3660_LITTLE_SENSOR; |
|---|
| 439 | + data->sensor[1].irq_name = "tsensor_a53"; |
|---|
| 440 | + data->sensor[1].data = data; |
|---|
| 429 | 441 | |
|---|
| 430 | 442 | return 0; |
|---|
| 431 | 443 | } |
|---|
| 432 | 444 | |
|---|
| 433 | 445 | static int hisi_thermal_get_temp(void *__data, int *temp) |
|---|
| 434 | 446 | { |
|---|
| 435 | | - struct hisi_thermal_data *data = __data; |
|---|
| 436 | | - struct hisi_thermal_sensor *sensor = &data->sensor; |
|---|
| 447 | + struct hisi_thermal_sensor *sensor = __data; |
|---|
| 448 | + struct hisi_thermal_data *data = sensor->data; |
|---|
| 437 | 449 | |
|---|
| 438 | | - *temp = data->get_temp(data); |
|---|
| 450 | + *temp = data->ops->get_temp(sensor); |
|---|
| 439 | 451 | |
|---|
| 440 | | - dev_dbg(&data->pdev->dev, "id=%d, temp=%d, thres=%d\n", |
|---|
| 441 | | - sensor->id, *temp, sensor->thres_temp); |
|---|
| 452 | + dev_dbg(&data->pdev->dev, "tzd=%p, id=%d, temp=%d, thres=%d\n", |
|---|
| 453 | + sensor->tzd, sensor->id, *temp, sensor->thres_temp); |
|---|
| 442 | 454 | |
|---|
| 443 | 455 | return 0; |
|---|
| 444 | 456 | } |
|---|
| .. | .. |
|---|
| 449 | 461 | |
|---|
| 450 | 462 | static irqreturn_t hisi_thermal_alarm_irq_thread(int irq, void *dev) |
|---|
| 451 | 463 | { |
|---|
| 452 | | - struct hisi_thermal_data *data = dev; |
|---|
| 453 | | - struct hisi_thermal_sensor *sensor = &data->sensor; |
|---|
| 464 | + struct hisi_thermal_sensor *sensor = dev; |
|---|
| 465 | + struct hisi_thermal_data *data = sensor->data; |
|---|
| 454 | 466 | int temp = 0; |
|---|
| 455 | 467 | |
|---|
| 456 | | - data->irq_handler(data); |
|---|
| 468 | + data->ops->irq_handler(sensor); |
|---|
| 457 | 469 | |
|---|
| 458 | | - hisi_thermal_get_temp(data, &temp); |
|---|
| 470 | + hisi_thermal_get_temp(sensor, &temp); |
|---|
| 459 | 471 | |
|---|
| 460 | 472 | if (temp >= sensor->thres_temp) { |
|---|
| 461 | | - dev_crit(&data->pdev->dev, "THERMAL ALARM: %d > %d\n", |
|---|
| 462 | | - temp, sensor->thres_temp); |
|---|
| 473 | + dev_crit(&data->pdev->dev, |
|---|
| 474 | + "sensor <%d> THERMAL ALARM: %d > %d\n", |
|---|
| 475 | + sensor->id, temp, sensor->thres_temp); |
|---|
| 463 | 476 | |
|---|
| 464 | | - thermal_zone_device_update(data->sensor.tzd, |
|---|
| 477 | + thermal_zone_device_update(sensor->tzd, |
|---|
| 465 | 478 | THERMAL_EVENT_UNSPECIFIED); |
|---|
| 466 | 479 | |
|---|
| 467 | 480 | } else { |
|---|
| 468 | | - dev_crit(&data->pdev->dev, "THERMAL ALARM stopped: %d < %d\n", |
|---|
| 469 | | - temp, sensor->thres_temp); |
|---|
| 481 | + dev_crit(&data->pdev->dev, |
|---|
| 482 | + "sensor <%d> THERMAL ALARM stopped: %d < %d\n", |
|---|
| 483 | + sensor->id, temp, sensor->thres_temp); |
|---|
| 470 | 484 | } |
|---|
| 471 | 485 | |
|---|
| 472 | 486 | return IRQ_HANDLED; |
|---|
| 473 | 487 | } |
|---|
| 474 | 488 | |
|---|
| 475 | 489 | static int hisi_thermal_register_sensor(struct platform_device *pdev, |
|---|
| 476 | | - struct hisi_thermal_data *data, |
|---|
| 477 | 490 | struct hisi_thermal_sensor *sensor) |
|---|
| 478 | 491 | { |
|---|
| 479 | 492 | int ret, i; |
|---|
| 480 | 493 | const struct thermal_trip *trip; |
|---|
| 481 | 494 | |
|---|
| 482 | 495 | sensor->tzd = devm_thermal_zone_of_sensor_register(&pdev->dev, |
|---|
| 483 | | - sensor->id, data, |
|---|
| 496 | + sensor->id, sensor, |
|---|
| 484 | 497 | &hisi_of_thermal_ops); |
|---|
| 485 | 498 | if (IS_ERR(sensor->tzd)) { |
|---|
| 486 | 499 | ret = PTR_ERR(sensor->tzd); |
|---|
| .. | .. |
|---|
| 502 | 515 | return 0; |
|---|
| 503 | 516 | } |
|---|
| 504 | 517 | |
|---|
| 518 | +static const struct hisi_thermal_ops hi6220_ops = { |
|---|
| 519 | + .get_temp = hi6220_thermal_get_temp, |
|---|
| 520 | + .enable_sensor = hi6220_thermal_enable_sensor, |
|---|
| 521 | + .disable_sensor = hi6220_thermal_disable_sensor, |
|---|
| 522 | + .irq_handler = hi6220_thermal_irq_handler, |
|---|
| 523 | + .probe = hi6220_thermal_probe, |
|---|
| 524 | +}; |
|---|
| 525 | + |
|---|
| 526 | +static const struct hisi_thermal_ops hi3660_ops = { |
|---|
| 527 | + .get_temp = hi3660_thermal_get_temp, |
|---|
| 528 | + .enable_sensor = hi3660_thermal_enable_sensor, |
|---|
| 529 | + .disable_sensor = hi3660_thermal_disable_sensor, |
|---|
| 530 | + .irq_handler = hi3660_thermal_irq_handler, |
|---|
| 531 | + .probe = hi3660_thermal_probe, |
|---|
| 532 | +}; |
|---|
| 533 | + |
|---|
| 505 | 534 | static const struct of_device_id of_hisi_thermal_match[] = { |
|---|
| 506 | 535 | { |
|---|
| 507 | 536 | .compatible = "hisilicon,tsensor", |
|---|
| 508 | | - .data = hi6220_thermal_probe |
|---|
| 537 | + .data = &hi6220_ops, |
|---|
| 509 | 538 | }, |
|---|
| 510 | 539 | { |
|---|
| 511 | 540 | .compatible = "hisilicon,hi3660-tsensor", |
|---|
| 512 | | - .data = hi3660_thermal_probe |
|---|
| 541 | + .data = &hi3660_ops, |
|---|
| 513 | 542 | }, |
|---|
| 514 | 543 | { /* end */ } |
|---|
| 515 | 544 | }; |
|---|
| .. | .. |
|---|
| 520 | 549 | { |
|---|
| 521 | 550 | struct thermal_zone_device *tzd = sensor->tzd; |
|---|
| 522 | 551 | |
|---|
| 523 | | - tzd->ops->set_mode(tzd, |
|---|
| 524 | | - on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED); |
|---|
| 552 | + if (on) |
|---|
| 553 | + thermal_zone_device_enable(tzd); |
|---|
| 554 | + else |
|---|
| 555 | + thermal_zone_device_disable(tzd); |
|---|
| 525 | 556 | } |
|---|
| 526 | 557 | |
|---|
| 527 | 558 | static int hisi_thermal_probe(struct platform_device *pdev) |
|---|
| 528 | 559 | { |
|---|
| 529 | 560 | struct hisi_thermal_data *data; |
|---|
| 530 | | - int (*platform_probe)(struct hisi_thermal_data *); |
|---|
| 531 | 561 | struct device *dev = &pdev->dev; |
|---|
| 532 | | - int ret; |
|---|
| 562 | + struct resource *res; |
|---|
| 563 | + int i, ret; |
|---|
| 533 | 564 | |
|---|
| 534 | 565 | data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); |
|---|
| 535 | 566 | if (!data) |
|---|
| .. | .. |
|---|
| 537 | 568 | |
|---|
| 538 | 569 | data->pdev = pdev; |
|---|
| 539 | 570 | platform_set_drvdata(pdev, data); |
|---|
| 571 | + data->ops = of_device_get_match_data(dev); |
|---|
| 540 | 572 | |
|---|
| 541 | | - platform_probe = of_device_get_match_data(dev); |
|---|
| 542 | | - if (!platform_probe) { |
|---|
| 543 | | - dev_err(dev, "failed to get probe func\n"); |
|---|
| 544 | | - return -EINVAL; |
|---|
| 573 | + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| 574 | + data->regs = devm_ioremap_resource(dev, res); |
|---|
| 575 | + if (IS_ERR(data->regs)) { |
|---|
| 576 | + dev_err(dev, "failed to get io address\n"); |
|---|
| 577 | + return PTR_ERR(data->regs); |
|---|
| 545 | 578 | } |
|---|
| 546 | 579 | |
|---|
| 547 | | - ret = platform_probe(data); |
|---|
| 580 | + ret = data->ops->probe(data); |
|---|
| 548 | 581 | if (ret) |
|---|
| 549 | 582 | return ret; |
|---|
| 550 | 583 | |
|---|
| 551 | | - ret = hisi_thermal_register_sensor(pdev, data, |
|---|
| 552 | | - &data->sensor); |
|---|
| 553 | | - if (ret) { |
|---|
| 554 | | - dev_err(dev, "failed to register thermal sensor: %d\n", ret); |
|---|
| 555 | | - return ret; |
|---|
| 556 | | - } |
|---|
| 584 | + for (i = 0; i < data->nr_sensors; i++) { |
|---|
| 585 | + struct hisi_thermal_sensor *sensor = &data->sensor[i]; |
|---|
| 557 | 586 | |
|---|
| 558 | | - ret = data->enable_sensor(data); |
|---|
| 559 | | - if (ret) { |
|---|
| 560 | | - dev_err(dev, "Failed to setup the sensor: %d\n", ret); |
|---|
| 561 | | - return ret; |
|---|
| 562 | | - } |
|---|
| 563 | | - |
|---|
| 564 | | - if (data->irq) { |
|---|
| 565 | | - ret = devm_request_threaded_irq(dev, data->irq, NULL, |
|---|
| 566 | | - hisi_thermal_alarm_irq_thread, |
|---|
| 567 | | - IRQF_ONESHOT, "hisi_thermal", data); |
|---|
| 568 | | - if (ret < 0) { |
|---|
| 569 | | - dev_err(dev, "failed to request alarm irq: %d\n", ret); |
|---|
| 587 | + ret = hisi_thermal_register_sensor(pdev, sensor); |
|---|
| 588 | + if (ret) { |
|---|
| 589 | + dev_err(dev, "failed to register thermal sensor: %d\n", |
|---|
| 590 | + ret); |
|---|
| 570 | 591 | return ret; |
|---|
| 571 | 592 | } |
|---|
| 572 | | - } |
|---|
| 573 | 593 | |
|---|
| 574 | | - hisi_thermal_toggle_sensor(&data->sensor, true); |
|---|
| 594 | + ret = platform_get_irq(pdev, 0); |
|---|
| 595 | + if (ret < 0) |
|---|
| 596 | + return ret; |
|---|
| 597 | + |
|---|
| 598 | + ret = devm_request_threaded_irq(dev, ret, NULL, |
|---|
| 599 | + hisi_thermal_alarm_irq_thread, |
|---|
| 600 | + IRQF_ONESHOT, sensor->irq_name, |
|---|
| 601 | + sensor); |
|---|
| 602 | + if (ret < 0) { |
|---|
| 603 | + dev_err(dev, "Failed to request alarm irq: %d\n", ret); |
|---|
| 604 | + return ret; |
|---|
| 605 | + } |
|---|
| 606 | + |
|---|
| 607 | + ret = data->ops->enable_sensor(sensor); |
|---|
| 608 | + if (ret) { |
|---|
| 609 | + dev_err(dev, "Failed to setup the sensor: %d\n", ret); |
|---|
| 610 | + return ret; |
|---|
| 611 | + } |
|---|
| 612 | + |
|---|
| 613 | + hisi_thermal_toggle_sensor(sensor, true); |
|---|
| 614 | + } |
|---|
| 575 | 615 | |
|---|
| 576 | 616 | return 0; |
|---|
| 577 | 617 | } |
|---|
| .. | .. |
|---|
| 579 | 619 | static int hisi_thermal_remove(struct platform_device *pdev) |
|---|
| 580 | 620 | { |
|---|
| 581 | 621 | struct hisi_thermal_data *data = platform_get_drvdata(pdev); |
|---|
| 582 | | - struct hisi_thermal_sensor *sensor = &data->sensor; |
|---|
| 622 | + int i; |
|---|
| 583 | 623 | |
|---|
| 584 | | - hisi_thermal_toggle_sensor(sensor, false); |
|---|
| 624 | + for (i = 0; i < data->nr_sensors; i++) { |
|---|
| 625 | + struct hisi_thermal_sensor *sensor = &data->sensor[i]; |
|---|
| 585 | 626 | |
|---|
| 586 | | - data->disable_sensor(data); |
|---|
| 627 | + hisi_thermal_toggle_sensor(sensor, false); |
|---|
| 628 | + data->ops->disable_sensor(sensor); |
|---|
| 629 | + } |
|---|
| 587 | 630 | |
|---|
| 588 | 631 | return 0; |
|---|
| 589 | 632 | } |
|---|
| .. | .. |
|---|
| 592 | 635 | static int hisi_thermal_suspend(struct device *dev) |
|---|
| 593 | 636 | { |
|---|
| 594 | 637 | struct hisi_thermal_data *data = dev_get_drvdata(dev); |
|---|
| 638 | + int i; |
|---|
| 595 | 639 | |
|---|
| 596 | | - data->disable_sensor(data); |
|---|
| 640 | + for (i = 0; i < data->nr_sensors; i++) |
|---|
| 641 | + data->ops->disable_sensor(&data->sensor[i]); |
|---|
| 597 | 642 | |
|---|
| 598 | 643 | return 0; |
|---|
| 599 | 644 | } |
|---|
| .. | .. |
|---|
| 601 | 646 | static int hisi_thermal_resume(struct device *dev) |
|---|
| 602 | 647 | { |
|---|
| 603 | 648 | struct hisi_thermal_data *data = dev_get_drvdata(dev); |
|---|
| 649 | + int i, ret = 0; |
|---|
| 604 | 650 | |
|---|
| 605 | | - return data->enable_sensor(data); |
|---|
| 651 | + for (i = 0; i < data->nr_sensors; i++) |
|---|
| 652 | + ret |= data->ops->enable_sensor(&data->sensor[i]); |
|---|
| 653 | + |
|---|
| 654 | + return ret; |
|---|
| 606 | 655 | } |
|---|
| 607 | 656 | #endif |
|---|
| 608 | 657 | |
|---|