kernel: bump 4.14 to 4.14.128
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.14 / 950-0297-Cleanup-of-bcm2708_fb-file-to-kernel-coding-standard.patch
1 From dc1c33574c4dcf24192cb219ea6caaf2c7804eef Mon Sep 17 00:00:00 2001
2 From: James Hughes <james.hughes@raspberrypi.org>
3 Date: Thu, 10 May 2018 11:34:38 +0100
4 Subject: [PATCH 297/454] Cleanup of bcm2708_fb file to kernel coding standards
5
6 Some minor change to function - remove a use of
7 in_atomic, plus replacing various debug messages
8 that manually specify the function name with
9 ("%s",.__func__)
10
11 Signed-off-by: James Hughes <james.hughes@raspberrypi.org>
12 ---
13 drivers/video/fbdev/bcm2708_fb.c | 136 ++++++++++++++++++-------------
14 1 file changed, 81 insertions(+), 55 deletions(-)
15
16 --- a/drivers/video/fbdev/bcm2708_fb.c
17 +++ b/drivers/video/fbdev/bcm2708_fb.c
18 @@ -41,9 +41,10 @@
19 #define MODULE_NAME "bcm2708_fb"
20
21 #ifdef BCM2708_FB_DEBUG
22 -#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
23 +#define print_debug(fmt, ...) pr_debug("%s:%s:%d: "fmt, \
24 + MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
25 #else
26 -#define print_debug(fmt,...)
27 +#define print_debug(fmt, ...)
28 #endif
29
30 /* This is limited to 16 characters when displayed by X startup */
31 @@ -51,10 +52,10 @@ static const char *bcm2708_name = "BCM27
32
33 #define DRIVER_NAME "bcm2708_fb"
34
35 -static int fbwidth = 800; /* module parameter */
36 -static int fbheight = 480; /* module parameter */
37 -static int fbdepth = 32; /* module parameter */
38 -static int fbswap = 0; /* module parameter */
39 +static int fbwidth = 800; /* module parameter */
40 +static int fbheight = 480; /* module parameter */
41 +static int fbdepth = 32; /* module parameter */
42 +static int fbswap; /* module parameter */
43
44 static u32 dma_busy_wait_threshold = 1<<15;
45 module_param(dma_busy_wait_threshold, int, 0644);
46 @@ -221,11 +222,13 @@ static int bcm2708_fb_check_var(struct f
47 struct fb_info *info)
48 {
49 /* info input, var output */
50 - print_debug("bcm2708_fb_check_var info(%p) %dx%d (%dx%d), %d, %d\n", info,
51 + print_debug("%s(%p) %dx%d (%dx%d), %d, %d\n",
52 + __func__,
53 + info,
54 info->var.xres, info->var.yres, info->var.xres_virtual,
55 info->var.yres_virtual, (int)info->screen_size,
56 info->var.bits_per_pixel);
57 - print_debug("bcm2708_fb_check_var var(%p) %dx%d (%dx%d), %d\n", var,
58 + print_debug("%s(%p) %dx%d (%dx%d), %d\n", __func__, var,
59 var->xres, var->yres, var->xres_virtual, var->yres_virtual,
60 var->bits_per_pixel);
61
62 @@ -233,7 +236,7 @@ static int bcm2708_fb_check_var(struct f
63 var->bits_per_pixel = 16;
64
65 if (bcm2708_fb_set_bitfields(var) != 0) {
66 - pr_err("bcm2708_fb_check_var: invalid bits_per_pixel %d\n",
67 + pr_err("%s: invalid bits_per_pixel %d\n", __func__,
68 var->bits_per_pixel);
69 return -EINVAL;
70 }
71 @@ -245,9 +248,8 @@ static int bcm2708_fb_check_var(struct f
72 if (var->yres_virtual == -1) {
73 var->yres_virtual = 480;
74
75 - pr_err
76 - ("bcm2708_fb_check_var: virtual resolution set to maximum of %dx%d\n",
77 - var->xres_virtual, var->yres_virtual);
78 + pr_err("%s: virtual resolution set to maximum of %dx%d\n",
79 + __func__, var->xres_virtual, var->yres_virtual);
80 }
81 if (var->yres_virtual < var->yres)
82 var->yres_virtual = var->yres;
83 @@ -291,7 +293,7 @@ static int bcm2708_fb_set_par(struct fb_
84 };
85 int ret;
86
87 - print_debug("bcm2708_fb_set_par info(%p) %dx%d (%dx%d), %d, %d\n", info,
88 + print_debug("%s(%p) %dx%d (%dx%d), %d, %d\n", __func__, info,
89 info->var.xres, info->var.yres, info->var.xres_virtual,
90 info->var.yres_virtual, (int)info->screen_size,
91 info->var.bits_per_pixel);
92 @@ -326,11 +328,12 @@ static int bcm2708_fb_set_par(struct fb_
93 return -ENOMEM;
94 }
95
96 - print_debug
97 - ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d\n",
98 - (void *)fb->fb.screen_base, (void *)fb->fb_bus_address,
99 - fbinfo.xres, fbinfo.yres, fbinfo.bpp,
100 - fbinfo.pitch, (int)fb->fb.screen_size);
101 + print_debug(
102 + "%s: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d\n",
103 + __func__,
104 + (void *)fb->fb.screen_base, (void *)fb->fb_bus_address,
105 + fbinfo.xres, fbinfo.yres, fbinfo.bpp,
106 + fbinfo.pitch, (int)fb->fb.screen_size);
107
108 return 0;
109 }
110 @@ -349,7 +352,6 @@ static int bcm2708_fb_setcolreg(unsigned
111 {
112 struct bcm2708_fb *fb = to_bcm2708(info);
113
114 - /*print_debug("BCM2708FB: setcolreg %d:(%02x,%02x,%02x,%02x) %x\n", regno, red, green, blue, transp, fb->fb.fix.visual);*/
115 if (fb->fb.var.bits_per_pixel <= 8) {
116 if (regno < 256) {
117 /* blue [23:16], green [15:8], red [7:0] */
118 @@ -357,8 +359,12 @@ static int bcm2708_fb_setcolreg(unsigned
119 ((green >> 8) & 0xff) << 8 |
120 ((blue >> 8) & 0xff) << 16;
121 }
122 - /* Hack: we need to tell GPU the palette has changed, but currently bcm2708_fb_set_par takes noticable time when called for every (256) colour */
123 - /* So just call it for what looks like the last colour in a list for now. */
124 + /* Hack: we need to tell GPU the palette has changed, but
125 + * currently bcm2708_fb_set_par takes noticeable time when
126 + * called for every (256) colour
127 + * So just call it for what looks like the last colour in a
128 + * list for now.
129 + */
130 if (regno == 15 || regno == 255) {
131 struct packet {
132 u32 offset;
133 @@ -372,19 +378,23 @@ static int bcm2708_fb_setcolreg(unsigned
134 return -ENOMEM;
135 packet->offset = 0;
136 packet->length = regno + 1;
137 - memcpy(packet->cmap, fb->gpu_cmap, sizeof(packet->cmap));
138 - ret = rpi_firmware_property(fb->fw, RPI_FIRMWARE_FRAMEBUFFER_SET_PALETTE,
139 - packet, (2 + packet->length) * sizeof(u32));
140 + memcpy(packet->cmap, fb->gpu_cmap,
141 + sizeof(packet->cmap));
142 + ret = rpi_firmware_property(fb->fw,
143 + RPI_FIRMWARE_FRAMEBUFFER_SET_PALETTE,
144 + packet,
145 + (2 + packet->length) * sizeof(u32));
146 if (ret || packet->offset)
147 - dev_err(info->device, "Failed to set palette (%d,%u)\n",
148 + dev_err(info->device,
149 + "Failed to set palette (%d,%u)\n",
150 ret, packet->offset);
151 kfree(packet);
152 }
153 - } else if (regno < 16) {
154 + } else if (regno < 16) {
155 fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
156 - convert_bitfield(blue, &fb->fb.var.blue) |
157 - convert_bitfield(green, &fb->fb.var.green) |
158 - convert_bitfield(red, &fb->fb.var.red);
159 + convert_bitfield(blue, &fb->fb.var.blue) |
160 + convert_bitfield(green, &fb->fb.var.green) |
161 + convert_bitfield(red, &fb->fb.var.red);
162 }
163 return regno > 255;
164 }
165 @@ -412,24 +422,28 @@ static int bcm2708_fb_blank(int blank_mo
166 ret = rpi_firmware_property(fb->fw, RPI_FIRMWARE_FRAMEBUFFER_BLANK,
167 &value, sizeof(value));
168 if (ret)
169 - dev_err(info->device, "bcm2708_fb_blank(%d) failed: %d\n",
170 + dev_err(info->device, "%s(%d) failed: %d\n", __func__,
171 blank_mode, ret);
172
173 return ret;
174 }
175
176 -static int bcm2708_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
177 +static int bcm2708_fb_pan_display(struct fb_var_screeninfo *var,
178 + struct fb_info *info)
179 {
180 s32 result;
181 +
182 info->var.xoffset = var->xoffset;
183 info->var.yoffset = var->yoffset;
184 result = bcm2708_fb_set_par(info);
185 if (result != 0)
186 - pr_err("bcm2708_fb_pan_display(%d,%d) returns=%d\n", var->xoffset, var->yoffset, result);
187 + pr_err("%s(%d,%d) returns=%d\n", __func__,
188 + var->xoffset, var->yoffset, result);
189 return result;
190 }
191
192 -static void dma_memcpy(struct bcm2708_fb *fb, dma_addr_t dst, dma_addr_t src, int size)
193 +static void dma_memcpy(struct bcm2708_fb *fb, dma_addr_t dst, dma_addr_t src,
194 + int size)
195 {
196 int burst_size = (fb->dma_chan == 0) ? 8 : 2;
197 struct bcm2708_dma_cb *cb = fb->cb_base;
198 @@ -450,6 +464,7 @@ static void dma_memcpy(struct bcm2708_fb
199 bcm_dma_wait_idle(fb->dma_chan_base);
200 } else {
201 void __iomem *dma_chan = fb->dma_chan_base;
202 +
203 cb->info |= BCM2708_DMA_INT_EN;
204 bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
205 while (bcm_dma_is_busy(dma_chan)) {
206 @@ -462,8 +477,10 @@ static void dma_memcpy(struct bcm2708_fb
207 fb->stats.dma_copies++;
208 }
209
210 -#define INTALIAS_NORMAL(x) ((x)&~0xc0000000) // address with no aliases
211 -#define INTALIAS_L1L2_NONALLOCATING(x) (((x)&~0xc0000000)|0x80000000) // cache coherent but non-allocating in L1 and L2
212 +/* address with no aliases */
213 +#define INTALIAS_NORMAL(x) ((x)&~0xc0000000)
214 +/* cache coherent but non-allocating in L1 and L2 */
215 +#define INTALIAS_L1L2_NONALLOCATING(x) (((x)&~0xc0000000)|0x80000000)
216
217 static long vc_mem_copy(struct bcm2708_fb *fb, unsigned long arg)
218 {
219 @@ -475,8 +492,7 @@ static long vc_mem_copy(struct bcm2708_f
220 size_t offset;
221
222 /* restrict this to root user */
223 - if (!uid_eq(current_euid(), GLOBAL_ROOT_UID))
224 - {
225 + if (!uid_eq(current_euid(), GLOBAL_ROOT_UID)) {
226 rc = -EFAULT;
227 goto out;
228 }
229 @@ -492,12 +508,16 @@ static long vc_mem_copy(struct bcm2708_f
230 }
231
232 if (fb->gpu.base == 0 || fb->gpu.length == 0) {
233 - pr_err("[%s]: Unable to determine gpu memory (%x,%x)\n", __func__, fb->gpu.base, fb->gpu.length);
234 + pr_err("[%s]: Unable to determine gpu memory (%x,%x)\n",
235 + __func__, fb->gpu.base, fb->gpu.length);
236 return -EFAULT;
237 }
238
239 - if (INTALIAS_NORMAL(ioparam.src) < fb->gpu.base || INTALIAS_NORMAL(ioparam.src) >= fb->gpu.base + fb->gpu.length) {
240 - pr_err("[%s]: Invalid memory access %x (%x-%x)", __func__, INTALIAS_NORMAL(ioparam.src), fb->gpu.base, fb->gpu.base + fb->gpu.length);
241 + if (INTALIAS_NORMAL(ioparam.src) < fb->gpu.base ||
242 + INTALIAS_NORMAL(ioparam.src) >= fb->gpu.base + fb->gpu.length) {
243 + pr_err("[%s]: Invalid memory access %x (%x-%x)", __func__,
244 + INTALIAS_NORMAL(ioparam.src), fb->gpu.base,
245 + fb->gpu.base + fb->gpu.length);
246 return -EFAULT;
247 }
248
249 @@ -515,7 +535,9 @@ static long vc_mem_copy(struct bcm2708_f
250 size_t s = min(size, remaining);
251 unsigned char *p = (unsigned char *)ioparam.src + offset;
252 unsigned char *q = (unsigned char *)ioparam.dst + offset;
253 - dma_memcpy(fb, bus_addr, INTALIAS_L1L2_NONALLOCATING((dma_addr_t)p), size);
254 +
255 + dma_memcpy(fb, bus_addr,
256 + INTALIAS_L1L2_NONALLOCATING((dma_addr_t)p), size);
257 if (copy_to_user(q, buf, s) != 0) {
258 pr_err("[%s]: failed to copy-to-user\n",
259 __func__);
260 @@ -525,11 +547,13 @@ static long vc_mem_copy(struct bcm2708_f
261 }
262 out:
263 if (buf)
264 - dma_free_coherent(fb->fb.device, PAGE_ALIGN(size), buf, bus_addr);
265 + dma_free_coherent(fb->fb.device, PAGE_ALIGN(size), buf,
266 + bus_addr);
267 return rc;
268 }
269
270 -static int bcm2708_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
271 +static int bcm2708_ioctl(struct fb_info *info, unsigned int cmd,
272 + unsigned long arg)
273 {
274 struct bcm2708_fb *fb = to_bcm2708(info);
275 u32 dummy = 0;
276 @@ -593,13 +617,13 @@ static void bcm2708_fb_copyarea(struct f
277 struct bcm2708_fb *fb = to_bcm2708(info);
278 struct bcm2708_dma_cb *cb = fb->cb_base;
279 int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
280 +
281 /* Channel 0 supports larger bursts and is a bit faster */
282 int burst_size = (fb->dma_chan == 0) ? 8 : 2;
283 int pixels = region->width * region->height;
284
285 /* Fallback to cfb_copyarea() if we don't like something */
286 - if (in_atomic() ||
287 - bytes_per_pixel > 4 ||
288 + if (bytes_per_pixel > 4 ||
289 info->var.xres * info->var.yres > 1920 * 1200 ||
290 region->width <= 0 || region->width > info->var.xres ||
291 region->height <= 0 || region->height > info->var.yres ||
292 @@ -663,6 +687,7 @@ static void bcm2708_fb_copyarea(struct f
293 } else {
294 /* A single dma control block is enough. */
295 int sy, dy, stride;
296 +
297 if (region->dy <= region->sy) {
298 /* processing from top to bottom */
299 dy = region->dy;
300 @@ -694,6 +719,7 @@ static void bcm2708_fb_copyarea(struct f
301 bcm_dma_wait_idle(fb->dma_chan_base);
302 } else {
303 void __iomem *dma_chan = fb->dma_chan_base;
304 +
305 cb->info |= BCM2708_DMA_INT_EN;
306 bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
307 while (bcm_dma_is_busy(dma_chan)) {
308 @@ -791,8 +817,8 @@ static int bcm2708_fb_register(struct bc
309 if (ret)
310 return ret;
311
312 - print_debug("BCM2708FB: registering framebuffer (%dx%d@%d) (%d)\n", fbwidth,
313 - fbheight, fbdepth, fbswap);
314 + print_debug("BCM2708FB: registering framebuffer (%dx%d@%d) (%d)\n",
315 + fbwidth, fbheight, fbdepth, fbswap);
316
317 ret = register_framebuffer(&fb->fb);
318 print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
319 @@ -813,19 +839,17 @@ static int bcm2708_fb_probe(struct platf
320
321 fw_np = of_parse_phandle(dev->dev.of_node, "firmware", 0);
322 /* Remove comment when booting without Device Tree is no longer supported
323 - if (!fw_np) {
324 - dev_err(&dev->dev, "Missing firmware node\n");
325 - return -ENOENT;
326 - }
327 -*/
328 + * if (!fw_np) {
329 + * dev_err(&dev->dev, "Missing firmware node\n");
330 + * return -ENOENT;
331 + * }
332 + */
333 fw = rpi_firmware_get(fw_np);
334 if (!fw)
335 return -EPROBE_DEFER;
336
337 fb = kzalloc(sizeof(struct bcm2708_fb), GFP_KERNEL);
338 if (!fb) {
339 - dev_err(&dev->dev,
340 - "could not allocate new bcm2708_fb struct\n");
341 ret = -ENOMEM;
342 goto free_region;
343 }
344 @@ -866,7 +890,9 @@ static int bcm2708_fb_probe(struct platf
345 fb->dev = dev;
346 fb->fb.device = &dev->dev;
347
348 - // failure here isn't fatal, but we'll fail in vc_mem_copy if fb->gpu is not valid
349 + /* failure here isn't fatal, but we'll fail in vc_mem_copy if
350 + * fb->gpu is not valid
351 + */
352 rpi_firmware_property(fb->fw,
353 RPI_FIRMWARE_GET_VC_MEMORY,
354 &fb->gpu, sizeof(fb->gpu));