diff --git a/bridge/it66121.h b/bridge/it66121.h index bff9d45..3641dd8 100644 --- a/bridge/it66121.h +++ b/bridge/it66121.h @@ -24,7 +24,7 @@ #include "it66121_registers.h" -#define UNUSED(x) (void)(x) +#define UNUSED(x) ((void)(x)) /* HW defect leading to losing 3 first bytes during EDID read operation */ #define EDID_LOSS_LEN 3 diff --git a/bridge/it66121_drv.c b/bridge/it66121_drv.c index 650b62e..9636b36 100644 --- a/bridge/it66121_drv.c +++ b/bridge/it66121_drv.c @@ -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) @@ -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 @@ -233,7 +234,7 @@ static int it66121_abort_ddc_ops(struct it66121_priv *priv) /* From original driver: According to 2009/01/15 modification by Jau-Chih.Tseng@ite.com.tw * 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; @@ -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; @@ -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; @@ -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)]; @@ -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) { @@ -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 { @@ -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] } diff --git a/fl2000.h b/fl2000.h index 7462018..55873bf 100644 --- a/fl2000.h +++ b/fl2000.h @@ -42,7 +42,7 @@ #include "fl2000_registers.h" -#define UNUSED(x) (void)(x) +#define UNUSED(x) ((void)(x)) /* Known USB interfaces of FL2000 */ enum fl2000_interface { diff --git a/fl2000_drm.c b/fl2000_drm.c index 0e7e6c8..b068c2d 100644 --- a/fl2000_drm.c +++ b/fl2000_drm.c @@ -51,7 +51,8 @@ static const u32 fl2000_pixel_formats[] = { static unsigned int fl2000_get_bytes_pix(enum usb_device_speed speed, unsigned int pixclock) { - unsigned int bytes_pix, max_bw; + unsigned int bytes_pix; + unsigned int max_bw; /* Calculate maximum bandwidth, bytes per second */ switch (speed) { @@ -151,12 +152,11 @@ static inline u32 fl2000_pll_get_divisor(u64 clock_mil, u32 vco_clk, u64 *min_pp 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128 }; - unsigned int divisor_idx; u32 best_divisor = 0; /* Iterate over array */ - for (divisor_idx = 0; divisor_idx < ARRAY_SIZE(divisor_arr); divisor_idx++) { - u32 divisor = divisor_arr[divisor_idx]; + for (int i = 0; i < ARRAY_SIZE(divisor_arr); i++) { + u32 divisor = divisor_arr[i]; u64 ppm_err = fl2000_pll_ppm_err(clock_mil, vco_clk, divisor); if (ppm_err < *min_ppm_err) { @@ -173,12 +173,10 @@ static u64 fl2000_pll_calc(u64 clock_mil, struct fl2000_pll *pll, u32 *clock_cal { static const u32 prescaler_max = 2; static const u32 multiplier_max = 128; - u32 prescaler; - u32 multiplier; u64 min_ppm_err = (u64)(-1); - for (prescaler = 1; prescaler <= prescaler_max; prescaler++) - for (multiplier = 1; multiplier <= multiplier_max; multiplier++) { + for (u32 prescaler = 1; prescaler <= prescaler_max; prescaler++) + for (u32 multiplier = 1; multiplier <= multiplier_max; multiplier++) { /* Do not need precision here yet, no 10^6 multiply */ u32 vco_clk = FL2000_XTAL / prescaler * multiplier; u32 divisor; @@ -193,19 +191,17 @@ static u64 fl2000_pll_calc(u64 clock_mil, struct fl2000_pll *pll, u32 *clock_cal pll->prescaler = prescaler; pll->multiplier = multiplier; pll->divisor = divisor; - if (vco_clk < 125000000) { + if (vco_clk < 125000000) pll->function = 0; - } else if (vco_clk < 250000000) { + else if (vco_clk < 250000000) pll->function = 1; - } else if (vco_clk < 500000000) { + else if (vco_clk < 500000000) pll->function = 2; - } else { + else pll->function = 3; - } *clock_calculated = vco_clk / divisor; } - /* No exact PLL settings found for requested clock */ return min_ppm_err; } @@ -217,17 +213,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 @@ -302,7 +296,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); diff --git a/fl2000_drv.c b/fl2000_drv.c index a152626..ee8f73d 100644 --- a/fl2000_drv.c +++ b/fl2000_drv.c @@ -40,7 +40,6 @@ static struct component_master_ops fl2000_master_ops = { static int fl2000_compare(struct device *dev, void *data) { - int i; struct i2c_client *client = i2c_verify_client(dev); static const char *const fl2000_supported_bridges[] = { "it66121", /* IT66121 driver name*/ @@ -52,7 +51,7 @@ static int fl2000_compare(struct device *dev, void *data) return 0; /* Check this is a supported DRM bridge */ - for (i = 0; i < ARRAY_SIZE(fl2000_supported_bridges); i++) + for (int i = 0; i < ARRAY_SIZE(fl2000_supported_bridges); i++) if (!strncmp(fl2000_supported_bridges[i], client->name, sizeof(client->name))) return 1; /* Must be not 0 for success */ diff --git a/fl2000_i2c.c b/fl2000_i2c.c index ce2718e..1a0c920 100644 --- a/fl2000_i2c.c +++ b/fl2000_i2c.c @@ -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]; diff --git a/fl2000_streaming.c b/fl2000_streaming.c index 973a743..8ee0764 100644 --- a/fl2000_streaming.c +++ b/fl2000_streaming.c @@ -50,13 +50,11 @@ struct fl2000_stream { static void fl2000_free_sb(struct fl2000_stream_buf *sb) { - int i; - vunmap(sb->vaddr); sg_free_table(&sb->sgt); - for (i = 0; i < sb->nr_pages && sb->pages[i]; i++) + for (int i = 0; i < sb->nr_pages && sb->pages[i]; i++) __free_page(sb->pages[i]); kfree(sb->pages); @@ -66,7 +64,7 @@ static void fl2000_free_sb(struct fl2000_stream_buf *sb) static struct fl2000_stream_buf *fl2000_alloc_sb(unsigned int size) { - int i, ret; + int ret; struct fl2000_stream_buf *sb; unsigned int nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT; @@ -80,7 +78,7 @@ static struct fl2000_stream_buf *fl2000_alloc_sb(unsigned int size) if (!sb->pages) goto error; - for (i = 0; i < nr_pages; i++) { + for (int i = 0; i < nr_pages; i++) { sb->pages[i] = alloc_page(GFP_KERNEL); if (!sb->pages[i]) goto error; @@ -107,7 +105,8 @@ static struct fl2000_stream_buf *fl2000_alloc_sb(unsigned int size) static void fl2000_stream_put_buffers(struct fl2000_stream *stream) { - struct fl2000_stream_buf *cur_sb, *temp_sb; + struct fl2000_stream_buf *cur_sb; + struct fl2000_stream_buf *temp_sb; list_for_each_entry_safe(cur_sb, temp_sb, &stream->render_list, list) { list_del(&cur_sb->list); @@ -117,12 +116,12 @@ static void fl2000_stream_put_buffers(struct fl2000_stream *stream) static int fl2000_stream_get_buffers(struct fl2000_stream *stream, unsigned int size) { - int i, ret; + int ret; struct fl2000_stream_buf *cur_sb; BUG_ON(!list_empty(&stream->render_list)); - for (i = 0; i < FL2000_SB_NUM; i++) { + for (int i = 0; i < FL2000_SB_NUM; i++) { cur_sb = fl2000_alloc_sb(size); if (!cur_sb) { ret = -ENOMEM; @@ -178,7 +177,8 @@ static void fl2000_stream_work(struct work_struct *work) int ret; struct fl2000_stream *stream = container_of(work, struct fl2000_stream, work); struct usb_device *usb_dev = stream->usb_dev; - struct fl2000_stream_buf *cur_sb, *last_sb; + struct fl2000_stream_buf *cur_sb; + struct fl2000_stream_buf *last_sb; struct urb *data_urb; while (stream->enabled) { @@ -240,9 +240,9 @@ static void fl2000_stream_work(struct work_struct *work) static void fl2000_xrgb888_to_rgb888_line(u8 *dbuf, u32 *sbuf, u32 pixels) { - unsigned int x, xx = 0; + unsigned int xx = 0; - for (x = 0; x < pixels; x++) { + for (unsigned int x = 0; x < pixels; x++) { dbuf[xx++ ^ 4] = (sbuf[x] & 0x000000FF) >> 0; dbuf[xx++ ^ 4] = (sbuf[x] & 0x0000FF00) >> 8; dbuf[xx++ ^ 4] = (sbuf[x] & 0x00FF0000) >> 16; @@ -251,9 +251,7 @@ static void fl2000_xrgb888_to_rgb888_line(u8 *dbuf, u32 *sbuf, u32 pixels) static void fl2000_xrgb888_to_rgb565_line(u16 *dbuf, u32 *sbuf, u32 pixels) { - unsigned int x; - - for (x = 0; x < pixels; x++) { + for (unsigned int x = 0; x < pixels; x++) { u16 val565 = ((sbuf[x] & 0x00F80000) >> 8) | ((sbuf[x] & 0x0000FC00) >> 5) | ((sbuf[x] & 0x000000F8) >> 3); dbuf[x ^ 2] = val565; @@ -264,7 +262,6 @@ void fl2000_stream_compress(struct fl2000_stream *stream, void *src, unsigned in unsigned int width, unsigned int pitch) { struct fl2000_stream_buf *cur_sb; - unsigned int y; void *dst; u32 dst_line_len; @@ -276,7 +273,7 @@ void fl2000_stream_compress(struct fl2000_stream *stream, void *src, unsigned in dst = cur_sb->vaddr; dst_line_len = width * stream->bytes_pix; - for (y = 0; y < height; y++) { + for (unsigned int y = 0; y < height; y++) { switch (stream->bytes_pix) { case 2: fl2000_xrgb888_to_rgb565_line(dst, src, width); @@ -301,7 +298,7 @@ int fl2000_stream_mode_set(struct fl2000_stream *stream, int pixels, u32 bytes_p unsigned int size; /* Round buffer size up to multiple of 8 to meet HW expectations */ - size = (pixels * bytes_pix + 7) & ~(unsigned int)7; + size = (pixels * bytes_pix + 7) & ~7U; stream->bytes_pix = bytes_pix; @@ -328,8 +325,6 @@ int fl2000_stream_mode_set(struct fl2000_stream *stream, int pixels, u32 bytes_p int fl2000_stream_enable(struct fl2000_stream *stream) { - int i; - BUG_ON(list_empty(&stream->transmit_list)); sema_init(&stream->work_sem, 0); @@ -337,7 +332,7 @@ int fl2000_stream_enable(struct fl2000_stream *stream) queue_work(stream->work_queue, &stream->work); /* Kick transmit workqueue with minimum buffers submitted */ - for (i = 0; i < FL2000_SB_MIN; i++) + for (int i = 0; i < FL2000_SB_MIN; i++) up(&stream->work_sem); return 0;