Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal: intel_pch_thermal: Support skylake PCH 100 series thermal

This patch uses .driver_data and board_info[] to make per pci device
behavior table (name and ops), instead of adding the code for each pci
device in switch-case. This will make easier to add new pci device
ids.

Then this adds new device id actually for skylake PCH 100 series
(using registers are compatible with currently driver, so no need to
change except adding device id to table).

Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>

authored by

OGAWA Hirofumi and committed by
Zhang Rui
c6068a6e 23400ac9

+39 -25
+39 -25
drivers/thermal/intel_pch_thermal.c
··· 29 29 #define PCH_THERMAL_DID_HSW_2 0x8C24 /* Haswell PCH */ 30 30 #define PCH_THERMAL_DID_WPT 0x9CA4 /* Wildcat Point */ 31 31 #define PCH_THERMAL_DID_SKL 0x9D31 /* Skylake PCH */ 32 + #define PCH_THERMAL_DID_SKL_H 0xA131 /* Skylake PCH 100 series */ 32 33 33 34 /* Wildcat Point-LP PCH Thermal registers */ 34 35 #define WPT_TEMP 0x0000 /* Temperature */ ··· 274 273 .get_trip_temp = pch_get_trip_temp, 275 274 }; 276 275 276 + enum board_ids { 277 + board_hsw, 278 + board_wpt, 279 + board_skl, 280 + }; 281 + 282 + static const struct board_info { 283 + const char *name; 284 + const struct pch_dev_ops *ops; 285 + } board_info[] = { 286 + [board_hsw] = { 287 + .name = "pch_haswell", 288 + .ops = &pch_dev_ops_wpt, 289 + }, 290 + [board_wpt] = { 291 + .name = "pch_wildcat_point", 292 + .ops = &pch_dev_ops_wpt, 293 + }, 294 + [board_skl] = { 295 + .name = "pch_skylake", 296 + .ops = &pch_dev_ops_wpt, 297 + }, 298 + }; 277 299 278 300 static int intel_pch_thermal_probe(struct pci_dev *pdev, 279 301 const struct pci_device_id *id) 280 302 { 303 + enum board_ids board_id = id->driver_data; 304 + const struct board_info *bi = &board_info[board_id]; 281 305 struct pch_thermal_device *ptd; 282 306 int err; 283 307 int nr_trips; 284 - char *dev_name; 285 308 286 309 ptd = devm_kzalloc(&pdev->dev, sizeof(*ptd), GFP_KERNEL); 287 310 if (!ptd) 288 311 return -ENOMEM; 289 312 290 - switch (pdev->device) { 291 - case PCH_THERMAL_DID_WPT: 292 - ptd->ops = &pch_dev_ops_wpt; 293 - dev_name = "pch_wildcat_point"; 294 - break; 295 - case PCH_THERMAL_DID_SKL: 296 - ptd->ops = &pch_dev_ops_wpt; 297 - dev_name = "pch_skylake"; 298 - break; 299 - case PCH_THERMAL_DID_HSW_1: 300 - case PCH_THERMAL_DID_HSW_2: 301 - ptd->ops = &pch_dev_ops_wpt; 302 - dev_name = "pch_haswell"; 303 - break; 304 - default: 305 - dev_err(&pdev->dev, "unknown pch thermal device\n"); 306 - return -ENODEV; 307 - } 313 + ptd->ops = bi->ops; 308 314 309 315 pci_set_drvdata(pdev, ptd); 310 316 ptd->pdev = pdev; ··· 339 331 if (err) 340 332 goto error_cleanup; 341 333 342 - ptd->tzd = thermal_zone_device_register(dev_name, nr_trips, 0, ptd, 334 + ptd->tzd = thermal_zone_device_register(bi->name, nr_trips, 0, ptd, 343 335 &tzd_ops, NULL, 0, 0); 344 336 if (IS_ERR(ptd->tzd)) { 345 337 dev_err(&pdev->dev, "Failed to register thermal zone %s\n", 346 - dev_name); 338 + bi->name); 347 339 err = PTR_ERR(ptd->tzd); 348 340 goto error_cleanup; 349 341 } ··· 388 380 } 389 381 390 382 static struct pci_device_id intel_pch_thermal_id[] = { 391 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_WPT) }, 392 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL) }, 393 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_HSW_1) }, 394 - { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_HSW_2) }, 383 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_HSW_1), 384 + .driver_data = board_hsw, }, 385 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_HSW_2), 386 + .driver_data = board_hsw, }, 387 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_WPT), 388 + .driver_data = board_wpt, }, 389 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL), 390 + .driver_data = board_skl, }, 391 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCH_THERMAL_DID_SKL_H), 392 + .driver_data = board_skl, }, 395 393 { 0, }, 396 394 }; 397 395 MODULE_DEVICE_TABLE(pci, intel_pch_thermal_id);