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

drivers/video: fsl-diu-fb: use an enum for the AOI index

Each of the five AOIs created by the DIU driver has a special purpose, and
they're not treated equally. It makes sense to identify them with an enum
instead of a hard-coded number.

Since the 'index' is now an enum, it can only contain allowed values, so
there's no need to check for an invalid value. This simplifies some other
code, such as fsl_diu_disable_panel(), which no longer needs to return an
error code.

Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>

authored by

Timur Tabi and committed by
Florian Tobias Schandinat
2572df91 760af8f8

+46 -48
+46 -48
drivers/video/fsl-diu-fb.c
··· 360 360 enum fsl_diu_monitor_port monitor_port; 361 361 }; 362 362 363 + enum mfb_index { 364 + PLANE0 = 0, /* Plane 0, only one AOI that fills the screen */ 365 + PLANE1_AOI0, /* Plane 1, first AOI */ 366 + PLANE1_AOI1, /* Plane 1, second AOI */ 367 + PLANE2_AOI0, /* Plane 2, first AOI */ 368 + PLANE2_AOI1, /* Plane 2, second AOI */ 369 + }; 370 + 363 371 struct mfb_info { 364 - int index; 372 + enum mfb_index index; 365 373 int type; 366 374 char *id; 367 375 int registered; ··· 386 378 387 379 388 380 static struct mfb_info mfb_template[] = { 389 - { /* AOI 0 for plane 0 */ 390 - .index = 0, 381 + { 382 + .index = PLANE0, 391 383 .type = MFB_TYPE_OUTPUT, 392 384 .id = "Panel0", 393 385 .registered = 0, ··· 395 387 .x_aoi_d = 0, 396 388 .y_aoi_d = 0, 397 389 }, 398 - { /* AOI 0 for plane 1 */ 399 - .index = 1, 390 + { 391 + .index = PLANE1_AOI0, 400 392 .type = MFB_TYPE_OUTPUT, 401 393 .id = "Panel1 AOI0", 402 394 .registered = 0, ··· 405 397 .x_aoi_d = 0, 406 398 .y_aoi_d = 0, 407 399 }, 408 - { /* AOI 1 for plane 1 */ 409 - .index = 2, 400 + { 401 + .index = PLANE1_AOI1, 410 402 .type = MFB_TYPE_OUTPUT, 411 403 .id = "Panel1 AOI1", 412 404 .registered = 0, ··· 415 407 .x_aoi_d = 0, 416 408 .y_aoi_d = 480, 417 409 }, 418 - { /* AOI 0 for plane 2 */ 419 - .index = 3, 410 + { 411 + .index = PLANE2_AOI0, 420 412 .type = MFB_TYPE_OUTPUT, 421 413 .id = "Panel2 AOI0", 422 414 .registered = 0, ··· 425 417 .x_aoi_d = 640, 426 418 .y_aoi_d = 0, 427 419 }, 428 - { /* AOI 1 for plane 2 */ 429 - .index = 4, 420 + { 421 + .index = PLANE2_AOI1, 430 422 .type = MFB_TYPE_OUTPUT, 431 423 .id = "Panel2 AOI1", 432 424 .registered = 0, ··· 527 519 528 520 if (mfbi->type != MFB_TYPE_OFF) { 529 521 switch (mfbi->index) { 530 - case 0: /* plane 0 */ 522 + case PLANE0: 531 523 if (hw->desc[0] != ad->paddr) 532 524 wr_reg_wa(&hw->desc[0], ad->paddr); 533 525 break; 534 - case 1: /* plane 1 AOI 0 */ 526 + case PLANE1_AOI0: 535 527 cmfbi = machine_data->fsl_diu_info[2]->par; 536 528 if (hw->desc[1] != ad->paddr) { /* AOI0 closed */ 537 529 if (cmfbi->count > 0) /* AOI1 open */ ··· 542 534 wr_reg_wa(&hw->desc[1], ad->paddr); 543 535 } 544 536 break; 545 - case 3: /* plane 2 AOI 0 */ 537 + case PLANE2_AOI0: 546 538 cmfbi = machine_data->fsl_diu_info[4]->par; 547 539 if (hw->desc[2] != ad->paddr) { /* AOI0 closed */ 548 540 if (cmfbi->count > 0) /* AOI1 open */ ··· 553 545 wr_reg_wa(&hw->desc[2], ad->paddr); 554 546 } 555 547 break; 556 - case 2: /* plane 1 AOI 1 */ 548 + case PLANE1_AOI1: 557 549 pmfbi = machine_data->fsl_diu_info[1]->par; 558 550 ad->next_ad = 0; 559 551 if (hw->desc[1] == machine_data->dummy_ad->paddr) ··· 561 553 else /* AOI0 open */ 562 554 pmfbi->ad->next_ad = cpu_to_le32(ad->paddr); 563 555 break; 564 - case 4: /* plane 2 AOI 1 */ 556 + case PLANE2_AOI1: 565 557 pmfbi = machine_data->fsl_diu_info[3]->par; 566 558 ad->next_ad = 0; 567 559 if (hw->desc[2] == machine_data->dummy_ad->paddr) ··· 569 561 else /* AOI0 was open */ 570 562 pmfbi->ad->next_ad = cpu_to_le32(ad->paddr); 571 563 break; 572 - default: 573 - res = -EINVAL; 574 - break; 575 564 } 576 565 } else 577 566 res = -EINVAL; 578 567 return res; 579 568 } 580 569 581 - static int fsl_diu_disable_panel(struct fb_info *info) 570 + static void fsl_diu_disable_panel(struct fb_info *info) 582 571 { 583 572 struct mfb_info *pmfbi, *cmfbi, *mfbi = info->par; 584 573 struct diu *hw = dr.diu_reg; 585 574 struct diu_ad *ad = mfbi->ad; 586 575 struct fsl_diu_data *machine_data = mfbi->parent; 587 - int res = 0; 588 576 589 577 switch (mfbi->index) { 590 - case 0: /* plane 0 */ 578 + case PLANE0: 591 579 if (hw->desc[0] != machine_data->dummy_ad->paddr) 592 580 wr_reg_wa(&hw->desc[0], machine_data->dummy_ad->paddr); 593 581 break; 594 - case 1: /* plane 1 AOI 0 */ 582 + case PLANE1_AOI0: 595 583 cmfbi = machine_data->fsl_diu_info[2]->par; 596 584 if (cmfbi->count > 0) /* AOI1 is open */ 597 585 wr_reg_wa(&hw->desc[1], cmfbi->ad->paddr); ··· 596 592 wr_reg_wa(&hw->desc[1], machine_data->dummy_ad->paddr); 597 593 /* close AOI 0 */ 598 594 break; 599 - case 3: /* plane 2 AOI 0 */ 595 + case PLANE2_AOI0: 600 596 cmfbi = machine_data->fsl_diu_info[4]->par; 601 597 if (cmfbi->count > 0) /* AOI1 is open */ 602 598 wr_reg_wa(&hw->desc[2], cmfbi->ad->paddr); ··· 605 601 wr_reg_wa(&hw->desc[2], machine_data->dummy_ad->paddr); 606 602 /* close AOI 0 */ 607 603 break; 608 - case 2: /* plane 1 AOI 1 */ 604 + case PLANE1_AOI1: 609 605 pmfbi = machine_data->fsl_diu_info[1]->par; 610 606 if (hw->desc[1] != ad->paddr) { 611 607 /* AOI1 is not the first in the chain */ ··· 616 612 wr_reg_wa(&hw->desc[1], machine_data->dummy_ad->paddr); 617 613 /* close AOI 1 */ 618 614 break; 619 - case 4: /* plane 2 AOI 1 */ 615 + case PLANE2_AOI1: 620 616 pmfbi = machine_data->fsl_diu_info[3]->par; 621 617 if (hw->desc[2] != ad->paddr) { 622 618 /* AOI1 is not the first in the chain */ ··· 627 623 wr_reg_wa(&hw->desc[2], machine_data->dummy_ad->paddr); 628 624 /* close AOI 1 */ 629 625 break; 630 - default: 631 - res = -EINVAL; 632 - break; 633 626 } 634 - 635 - return res; 636 627 } 637 628 638 629 static void enable_lcdc(struct fb_info *info) ··· 659 660 { 660 661 struct mfb_info *lower_aoi_mfbi, *upper_aoi_mfbi, *mfbi = info->par; 661 662 struct fsl_diu_data *machine_data = mfbi->parent; 662 - int available_height, upper_aoi_bottom, index = mfbi->index; 663 + int available_height, upper_aoi_bottom; 664 + enum mfb_index index = mfbi->index; 663 665 int lower_aoi_is_open, upper_aoi_is_open; 664 666 __u32 base_plane_width, base_plane_height, upper_aoi_height; 665 667 ··· 672 672 if (mfbi->y_aoi_d < 0) 673 673 mfbi->y_aoi_d = 0; 674 674 switch (index) { 675 - case 0: 675 + case PLANE0: 676 676 if (mfbi->x_aoi_d != 0) 677 677 mfbi->x_aoi_d = 0; 678 678 if (mfbi->y_aoi_d != 0) 679 679 mfbi->y_aoi_d = 0; 680 680 break; 681 - case 1: /* AOI 0 */ 682 - case 3: 681 + case PLANE1_AOI0: 682 + case PLANE2_AOI0: 683 683 lower_aoi_mfbi = machine_data->fsl_diu_info[index+1]->par; 684 684 lower_aoi_is_open = lower_aoi_mfbi->count > 0 ? 1 : 0; 685 685 if (var->xres > base_plane_width) ··· 696 696 if ((mfbi->y_aoi_d + var->yres) > available_height) 697 697 mfbi->y_aoi_d = available_height - var->yres; 698 698 break; 699 - case 2: /* AOI 1 */ 700 - case 4: 699 + case PLANE1_AOI1: 700 + case PLANE2_AOI1: 701 701 upper_aoi_mfbi = machine_data->fsl_diu_info[index-1]->par; 702 702 upper_aoi_height = 703 703 machine_data->fsl_diu_info[index-1]->var.yres; ··· 1002 1002 ad->ckmin_g = 255; 1003 1003 ad->ckmin_b = 255; 1004 1004 1005 - if (mfbi->index == 0) 1005 + if (mfbi->index == PLANE0) 1006 1006 update_lcdc(info); 1007 1007 return 0; 1008 1008 } ··· 1195 1195 int res = 0; 1196 1196 1197 1197 /* free boot splash memory on first /dev/fb0 open */ 1198 - if (!mfbi->index && diu_ops.release_bootmem) 1198 + if ((mfbi->index == PLANE0) && diu_ops.release_bootmem) 1199 1199 diu_ops.release_bootmem(); 1200 1200 1201 1201 spin_lock(&diu_lock); ··· 1225 1225 1226 1226 spin_lock(&diu_lock); 1227 1227 mfbi->count--; 1228 - if (mfbi->count == 0) { 1229 - res = fsl_diu_disable_panel(info); 1230 - if (res < 0) 1231 - mfbi->count++; 1232 - } 1228 + if (mfbi->count == 0) 1229 + fsl_diu_disable_panel(info); 1230 + 1233 1231 spin_unlock(&diu_lock); 1234 1232 return res; 1235 1233 } ··· 1273 1275 if (init_fbinfo(info)) 1274 1276 return -EINVAL; 1275 1277 1276 - if (mfbi->index == 0) { /* plane 0 */ 1278 + if (mfbi->index == PLANE0) { 1277 1279 if (mfbi->edid_data) { 1278 1280 /* Now build modedb from EDID */ 1279 1281 fb_edid_to_monspecs(mfbi->edid_data, &info->monspecs); ··· 1294 1296 * For plane 0 we continue and look into 1295 1297 * driver's internal modedb. 1296 1298 */ 1297 - if (mfbi->index == 0 && mfbi->edid_data) 1299 + if ((mfbi->index == PLANE0) && mfbi->edid_data) 1298 1300 has_default_mode = 0; 1299 1301 else 1300 1302 return -EINVAL; ··· 1358 1360 if (!mfbi->registered) 1359 1361 return; 1360 1362 1361 - if (mfbi->index == 0) 1363 + if (mfbi->index == PLANE0) 1362 1364 kfree(mfbi->edid_data); 1363 1365 1364 1366 unregister_framebuffer(info); ··· 1563 1565 memcpy(mfbi, &mfb_template[i], sizeof(struct mfb_info)); 1564 1566 mfbi->parent = machine_data; 1565 1567 1566 - if (mfbi->index == 0) { 1568 + if (mfbi->index == PLANE0) { 1567 1569 const u8 *prop; 1568 1570 int len; 1569 1571