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

Configure Feed

Select the types of activity you want to include in your feed.

media: rcar-csi2: Add helper to lookup mbps settings

The structure mapping a configuration information to a particular mpbs
setting needs to be extended with more information to support future
SoCs. Before it is extended reduce code duplication by creating a helper
to lookup information from an array of mbps setting, the lookup code
has already been copied to two speared locations.

While at it rename the structure to make it clear it contains
information related to a mbps setting, not just a single register value.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Niklas Söderlund and committed by
Mauro Carvalho Chehab
e5be5622 28a034da

+45 -45
+45 -45
drivers/media/platform/renesas/rcar-csi2.c
··· 242 242 u8 code; 243 243 }; 244 244 245 - struct rcsi2_mbps_reg { 245 + struct rcsi2_mbps_info { 246 246 u16 mbps; 247 247 u8 reg; 248 248 }; 249 249 250 - static const struct rcsi2_mbps_reg phtw_mbps_v3u[] = { 250 + static const struct rcsi2_mbps_info phtw_mbps_v3u[] = { 251 251 { .mbps = 1500, .reg = 0xcc }, 252 252 { .mbps = 1550, .reg = 0x1d }, 253 253 { .mbps = 1600, .reg = 0x27 }, ··· 272 272 { /* sentinel */ }, 273 273 }; 274 274 275 - static const struct rcsi2_mbps_reg phtw_mbps_h3_v3h_m3n[] = { 275 + static const struct rcsi2_mbps_info phtw_mbps_h3_v3h_m3n[] = { 276 276 { .mbps = 80, .reg = 0x86 }, 277 277 { .mbps = 90, .reg = 0x86 }, 278 278 { .mbps = 100, .reg = 0x87 }, ··· 292 292 { /* sentinel */ }, 293 293 }; 294 294 295 - static const struct rcsi2_mbps_reg phtw_mbps_v3m_e3[] = { 295 + static const struct rcsi2_mbps_info phtw_mbps_v3m_e3[] = { 296 296 { .mbps = 80, .reg = 0x00 }, 297 297 { .mbps = 90, .reg = 0x20 }, 298 298 { .mbps = 100, .reg = 0x40 }, ··· 336 336 #define PHYPLL_REG 0x68 337 337 #define PHYPLL_HSFREQRANGE(n) ((n) << 16) 338 338 339 - static const struct rcsi2_mbps_reg hsfreqrange_v3u[] = { 339 + static const struct rcsi2_mbps_info hsfreqrange_v3u[] = { 340 340 { .mbps = 80, .reg = 0x00 }, 341 341 { .mbps = 90, .reg = 0x10 }, 342 342 { .mbps = 100, .reg = 0x20 }, ··· 402 402 { /* sentinel */ }, 403 403 }; 404 404 405 - static const struct rcsi2_mbps_reg hsfreqrange_h3_v3h_m3n[] = { 405 + static const struct rcsi2_mbps_info hsfreqrange_h3_v3h_m3n[] = { 406 406 { .mbps = 80, .reg = 0x00 }, 407 407 { .mbps = 90, .reg = 0x10 }, 408 408 { .mbps = 100, .reg = 0x20 }, ··· 449 449 { /* sentinel */ }, 450 450 }; 451 451 452 - static const struct rcsi2_mbps_reg hsfreqrange_m3w[] = { 452 + static const struct rcsi2_mbps_info hsfreqrange_m3w[] = { 453 453 { .mbps = 80, .reg = 0x00 }, 454 454 { .mbps = 90, .reg = 0x10 }, 455 455 { .mbps = 100, .reg = 0x20 }, ··· 596 596 int (*start_receiver)(struct rcar_csi2 *priv, 597 597 struct v4l2_subdev_state *state); 598 598 void (*enter_standby)(struct rcar_csi2 *priv); 599 - const struct rcsi2_mbps_reg *hsfreqrange; 599 + const struct rcsi2_mbps_info *hsfreqrange; 600 600 unsigned int csi0clkfreqrange; 601 601 unsigned int num_channels; 602 602 bool clear_ulps; ··· 662 662 iowrite16(data, priv->base + reg); 663 663 } 664 664 665 + static const struct rcsi2_mbps_info * 666 + rcsi2_mbps_to_info(struct rcar_csi2 *priv, 667 + const struct rcsi2_mbps_info *infotable, unsigned int mbps) 668 + { 669 + const struct rcsi2_mbps_info *info; 670 + const struct rcsi2_mbps_info *prev = NULL; 671 + 672 + if (mbps < infotable->mbps) 673 + dev_warn(priv->dev, "%u Mbps less than min PHY speed %u Mbps", 674 + mbps, infotable->mbps); 675 + 676 + for (info = infotable; info->mbps != 0; info++) { 677 + if (info->mbps >= mbps) 678 + break; 679 + prev = info; 680 + } 681 + 682 + if (!info->mbps) { 683 + dev_err(priv->dev, "Unsupported PHY speed (%u Mbps)", mbps); 684 + return NULL; 685 + } 686 + 687 + if (prev && ((mbps - prev->mbps) <= (info->mbps - mbps))) 688 + info = prev; 689 + 690 + return info; 691 + } 692 + 665 693 static void rcsi2_enter_standby_gen3(struct rcar_csi2 *priv) 666 694 { 667 695 rcsi2_write(priv, PHYCNT_REG, 0); ··· 742 714 743 715 static int rcsi2_set_phypll(struct rcar_csi2 *priv, unsigned int mbps) 744 716 { 745 - const struct rcsi2_mbps_reg *hsfreq; 746 - const struct rcsi2_mbps_reg *hsfreq_prev = NULL; 717 + const struct rcsi2_mbps_info *info; 747 718 748 - if (mbps < priv->info->hsfreqrange->mbps) 749 - dev_warn(priv->dev, "%u Mbps less than min PHY speed %u Mbps", 750 - mbps, priv->info->hsfreqrange->mbps); 751 - 752 - for (hsfreq = priv->info->hsfreqrange; hsfreq->mbps != 0; hsfreq++) { 753 - if (hsfreq->mbps >= mbps) 754 - break; 755 - hsfreq_prev = hsfreq; 756 - } 757 - 758 - if (!hsfreq->mbps) { 759 - dev_err(priv->dev, "Unsupported PHY speed (%u Mbps)", mbps); 719 + info = rcsi2_mbps_to_info(priv, priv->info->hsfreqrange, mbps); 720 + if (!info) 760 721 return -ERANGE; 761 - } 762 722 763 - if (hsfreq_prev && 764 - ((mbps - hsfreq_prev->mbps) <= (hsfreq->mbps - mbps))) 765 - hsfreq = hsfreq_prev; 766 - 767 - rcsi2_write(priv, priv->info->regs->phypll, PHYPLL_HSFREQRANGE(hsfreq->reg)); 723 + rcsi2_write(priv, priv->info->regs->phypll, PHYPLL_HSFREQRANGE(info->reg)); 768 724 769 725 return 0; 770 726 } ··· 1506 1494 } 1507 1495 1508 1496 static int rcsi2_phtw_write_mbps(struct rcar_csi2 *priv, unsigned int mbps, 1509 - const struct rcsi2_mbps_reg *values, u8 code) 1497 + const struct rcsi2_mbps_info *values, u8 code) 1510 1498 { 1511 - const struct rcsi2_mbps_reg *value; 1512 - const struct rcsi2_mbps_reg *prev_value = NULL; 1499 + const struct rcsi2_mbps_info *info; 1513 1500 1514 - for (value = values; value->mbps; value++) { 1515 - if (value->mbps >= mbps) 1516 - break; 1517 - prev_value = value; 1518 - } 1519 - 1520 - if (prev_value && 1521 - ((mbps - prev_value->mbps) <= (value->mbps - mbps))) 1522 - value = prev_value; 1523 - 1524 - if (!value->mbps) { 1525 - dev_err(priv->dev, "Unsupported PHY speed (%u Mbps)", mbps); 1501 + info = rcsi2_mbps_to_info(priv, values, mbps); 1502 + if (!info) 1526 1503 return -ERANGE; 1527 - } 1528 1504 1529 - return rcsi2_phtw_write(priv, value->reg, code); 1505 + return rcsi2_phtw_write(priv, info->reg, code); 1530 1506 } 1531 1507 1532 1508 static int __rcsi2_init_phtw_h3_v3h_m3n(struct rcar_csi2 *priv,