Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
Move loop indexes into loops
Return on errors instead of loop breaks
Some variables cleanup
  • Loading branch information
klogg committed May 11, 2024
1 parent 7c2a33e commit f69e683
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
40 changes: 22 additions & 18 deletions bridge/it66121_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ static int it66121_configure_afe(struct it66121_priv *priv, int clock_khz)

static int it66121_wait_ddc_ready(struct it66121_priv *priv)
{
int ret, val;
int ret;
unsigned int val;

ret = regmap_field_read_poll_timeout(priv->ddc_done, val, true, EDID_SLEEP, EDID_TIMEOUT);
if (ret)
Expand Down Expand Up @@ -221,7 +222,7 @@ static int it66121_clear_ddc_fifo(struct it66121_priv *priv)

static int it66121_abort_ddc_ops(struct it66121_priv *priv)
{
int i, ret;
int ret;

/* Prior to DDC abort command there was also a reset of HDCP:
* 1. HDCP_DESIRE clear bit CP DESIRE
Expand All @@ -233,7 +234,7 @@ static int it66121_abort_ddc_ops(struct it66121_priv *priv)
/* From original driver: According to 2009/01/15 modification by [email protected]
* do abort DDC twice
*/
for (i = 0; i < 2; i++) {
for (int i = 0; i < 2; i++) {
ret = regmap_write(priv->regmap, IT66121_DDC_COMMAND, DDC_CMD_ABORT);
if (ret)
return ret;
Expand Down Expand Up @@ -326,9 +327,11 @@ static void it66121_intr_work(struct work_struct *work_item)

static int it66121_get_edid_block(void *context, u8 *buf, unsigned int block, size_t len)
{
int i, ret, offset = block & 1 ? 128 : 0;
int ret;
size_t remain = len;
unsigned int rd_fifo_val, segment = block >> 1;
unsigned int val;
unsigned int segment = block >> 1;
unsigned int offset = block & 1 ? 128 : 0;
static const u8 header[EDID_LOSS_LEN] = { 0x00, 0xFF, 0xFF };
struct it66121_priv *priv = context;

Expand All @@ -354,35 +357,36 @@ static int it66121_get_edid_block(void *context, u8 *buf, unsigned int block, si
/* Clear DDC FIFO */
ret = it66121_clear_ddc_fifo(priv);
if (ret)
break;
return ret;

ret = regmap_write(priv->regmap, IT66121_DDC_ADDRESS, EDID_DDC_ADDR);
if (ret)
break;
return ret;

/* Account 3 bytes that will be lost */
ret = regmap_write(priv->regmap, IT66121_DDC_OFFSET, offset - EDID_LOSS_LEN);
if (ret)
break;
return ret;

ret = regmap_write(priv->regmap, IT66121_DDC_SIZE, (unsigned int)size);
if (ret)
break;
return ret;
ret = regmap_write(priv->regmap, IT66121_DDC_SEGMENT, segment);
if (ret)
break;
return ret;
ret = regmap_write(priv->regmap, IT66121_DDC_COMMAND, DDC_CMD_EDID_READ);
if (ret)
break;
return ret;

/* Deduct lost bytes when reading from FIFO */
size -= EDID_LOSS_LEN;

for (i = 0; i < size; i++) {
ret = regmap_read(priv->regmap, IT66121_DDC_RD_FIFO, &rd_fifo_val);
for (int i = 0; i < size; i++) {
ret = regmap_read(priv->regmap, IT66121_DDC_RD_FIFO, &val);
if (ret)
return ret;

*(buf++) = rd_fifo_val & 0xFF;
*(buf++) = val & 0xFF;
}

remain -= size;
Expand Down Expand Up @@ -601,7 +605,7 @@ static void it66121_bridge_mode_set(struct drm_bridge *bridge, const struct drm_
const struct drm_display_mode *adjusted_mode)

{
int i, ret;
int ret;
ssize_t frame_size;
struct it66121_priv *priv = container_of(bridge, struct it66121_priv, bridge);
u8 buf[HDMI_INFOFRAME_SIZE(AVI)];
Expand Down Expand Up @@ -658,7 +662,7 @@ static void it66121_bridge_mode_set(struct drm_bridge *bridge, const struct drm_
}

/* Write new AVI infoframe packet */
for (i = 0; i < HDMI_AVI_INFOFRAME_SIZE; i++) {
for (int i = 0; i < HDMI_AVI_INFOFRAME_SIZE; i++) {
ret = regmap_write(priv->regmap, aviinfo_reg[i],
buf[i + HDMI_INFOFRAME_HEADER_SIZE]);
if (ret) {
Expand Down Expand Up @@ -764,7 +768,7 @@ static int it66121_regs_init(struct it66121_priv *priv, struct i2c_client *clien

static int it66121_i2c_probe(struct i2c_adapter *adapter, unsigned short address)
{
int i, ret;
int ret;
u8 id_regs[] = { IT66121_VENDOR_ID_1, IT66121_VENDOR_ID_2, IT66121_DEVICE_ID_1,
IT66121_DEVICE_ID_2 };
union {
Expand All @@ -784,7 +788,7 @@ static int it66121_i2c_probe(struct i2c_adapter *adapter, unsigned short address
return -ENODEV;
}

for (i = 0; i < ARRAY_SIZE(id_regs); i++) {
for (int i = 0; i < ARRAY_SIZE(id_regs); i++) {
struct i2c_msg msgs[] = {
{ .addr = address, .flags = 0, .len = 1, .buf = &id_regs[i] },
{ .addr = address, .flags = I2C_M_RD, .len = 1, .buf = &id.b[i] }
Expand Down
15 changes: 7 additions & 8 deletions fl2000_drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,15 @@ static int fl2000_mode_calc(const struct drm_display_mode *mode,
u64 clock_mil_adjusted;
const u64 clock_mil = (u64)mode->clock * 1000 * FL2000_PLL_PRECISION;
const int max_h_adjustment = 10;
int s, m;
int d = 0;

if (mode->clock * 1000 > FL2000_MAX_PIXCLOCK)
return -1;

/* Try to match pixel clock slightly adjusting htotal value */
for (m = 0, s = 0; m <= max_h_adjustment * 2; m++, s = -s) {
/* 0, -1, 1, -2, 2, -3, 3, -3, 4, -4, 5, -5, ... */
d += m * s;

/* Try to match pixel clock slightly adjusting htotal value, sequence is:
0, -1, 1, -2, 2, -3, 3, -3, 4, -4, 5, -5, ...
Here, 's' is used for sign, 'm' is used for modulo, and 'd' is the adjustment value
*/
for (int m = 0, s = 0, d = 0; m <= max_h_adjustment * 2; m++, s = -s, d += m * s) {
/* Maximum pixel clock 1GHz, or 10^9Hz. Multiply by 10^6 we get 10^15Hz. Assume
* maximum htotal is 10000 pix (no way) we get 10^19 max value and using u64 which
* is 1.8*10^19 no overflow can occur. Assume all this was checked before
Expand Down Expand Up @@ -302,7 +300,8 @@ static void fl2000_display_disable(struct drm_simple_display_pipe *pipe)

static void fb2000_dirty(struct drm_framebuffer *fb, struct drm_rect *rect)
{
int idx, ret;
int ret;
int idx;
struct drm_device *drm = fb->dev;
struct fl2000_drm_if *drm_if = drm->dev_private;
struct drm_gem_dma_object *dma_obj = drm_fb_dma_get_gem_obj(fb, 0);
Expand Down
3 changes: 2 additions & 1 deletion fl2000_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ static int fl2000_i2c_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, in
int ret;
bool read;
u16 addr;
u8 idx, offset;
u8 idx;
u8 offset;
union {
u32 w;
u8 b[4];
Expand Down

0 comments on commit f69e683

Please sign in to comment.