forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-09 244b2c5ca8b14627e4a17755e5922221e121c771
kernel/drivers/video/fbdev/i740fb.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * i740fb - framebuffer driver for Intel740
34 * Copyright (c) 2011 Ondrej Zary
....@@ -399,7 +400,7 @@
399400 u32 xres, right, hslen, left, xtotal;
400401 u32 yres, lower, vslen, upper, ytotal;
401402 u32 vxres, xoffset, vyres, yoffset;
402
- u32 bpp, base, dacspeed24, mem;
403
+ u32 bpp, base, dacspeed24, mem, freq;
403404 u8 r7;
404405 int i;
405406
....@@ -429,7 +430,7 @@
429430 break;
430431 case 9 ... 15:
431432 bpp = 15;
432
- /* fall through */
433
+ fallthrough;
433434 case 16:
434435 if ((1000000 / var->pixclock) > DACSPEED16) {
435436 dev_err(info->device, "requested pixclock %i MHz out of range (max. %i MHz at 15/16bpp)\n",
....@@ -642,7 +643,12 @@
642643 par->atc[VGA_ATC_OVERSCAN] = 0;
643644
644645 /* Calculate VCLK that most closely matches the requested dot clock */
645
- i740_calc_vclk((((u32)1e9) / var->pixclock) * (u32)(1e3), par);
646
+ freq = (((u32)1e9) / var->pixclock) * (u32)(1e3);
647
+ if (freq < I740_RFREQ_FIX) {
648
+ fb_dbg(info, "invalid pixclock\n");
649
+ freq = I740_RFREQ_FIX;
650
+ }
651
+ i740_calc_vclk(freq, par);
646652
647653 /* Since we program the clocks ourselves, always use VCLK2. */
648654 par->misc |= 0x0C;
....@@ -656,6 +662,9 @@
656662
657663 static int i740fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
658664 {
665
+ if (!var->pixclock)
666
+ return -EINVAL;
667
+
659668 switch (var->bits_per_pixel) {
660669 case 8:
661670 var->red.offset = var->green.offset = var->blue.offset = 0;
....@@ -980,7 +989,7 @@
980989 return (blank_mode == FB_BLANK_NORMAL) ? 1 : 0;
981990 }
982991
983
-static struct fb_ops i740fb_ops = {
992
+static const struct fb_ops i740fb_ops = {
984993 .owner = THIS_MODULE,
985994 .fb_open = i740fb_open,
986995 .fb_release = i740fb_release,
....@@ -1005,10 +1014,8 @@
10051014 u8 *edid;
10061015
10071016 info = framebuffer_alloc(sizeof(struct i740fb_par), &(dev->dev));
1008
- if (!info) {
1009
- dev_err(&(dev->dev), "cannot allocate framebuffer\n");
1017
+ if (!info)
10101018 return -ENOMEM;
1011
- }
10121019
10131020 par = info->par;
10141021 mutex_init(&par->open_lock);
....@@ -1176,15 +1183,10 @@
11761183 }
11771184 }
11781185
1179
-#ifdef CONFIG_PM
1180
-static int i740fb_suspend(struct pci_dev *dev, pm_message_t state)
1186
+static int __maybe_unused i740fb_suspend(struct device *dev)
11811187 {
1182
- struct fb_info *info = pci_get_drvdata(dev);
1188
+ struct fb_info *info = dev_get_drvdata(dev);
11831189 struct i740fb_par *par = info->par;
1184
-
1185
- /* don't disable console during hibernation and wakeup from it */
1186
- if (state.event == PM_EVENT_FREEZE || state.event == PM_EVENT_PRETHAW)
1187
- return 0;
11881190
11891191 console_lock();
11901192 mutex_lock(&(par->open_lock));
....@@ -1198,30 +1200,21 @@
11981200
11991201 fb_set_suspend(info, 1);
12001202
1201
- pci_save_state(dev);
1202
- pci_disable_device(dev);
1203
- pci_set_power_state(dev, pci_choose_state(dev, state));
1204
-
12051203 mutex_unlock(&(par->open_lock));
12061204 console_unlock();
12071205
12081206 return 0;
12091207 }
12101208
1211
-static int i740fb_resume(struct pci_dev *dev)
1209
+static int __maybe_unused i740fb_resume(struct device *dev)
12121210 {
1213
- struct fb_info *info = pci_get_drvdata(dev);
1211
+ struct fb_info *info = dev_get_drvdata(dev);
12141212 struct i740fb_par *par = info->par;
12151213
12161214 console_lock();
12171215 mutex_lock(&(par->open_lock));
12181216
12191217 if (par->ref_count == 0)
1220
- goto fail;
1221
-
1222
- pci_set_power_state(dev, PCI_D0);
1223
- pci_restore_state(dev);
1224
- if (pci_enable_device(dev))
12251218 goto fail;
12261219
12271220 i740fb_set_par(info);
....@@ -1232,10 +1225,17 @@
12321225 console_unlock();
12331226 return 0;
12341227 }
1235
-#else
1236
-#define i740fb_suspend NULL
1237
-#define i740fb_resume NULL
1238
-#endif /* CONFIG_PM */
1228
+
1229
+static const struct dev_pm_ops i740fb_pm_ops = {
1230
+#ifdef CONFIG_PM_SLEEP
1231
+ .suspend = i740fb_suspend,
1232
+ .resume = i740fb_resume,
1233
+ .freeze = NULL,
1234
+ .thaw = i740fb_resume,
1235
+ .poweroff = i740fb_suspend,
1236
+ .restore = i740fb_resume,
1237
+#endif /* CONFIG_PM_SLEEP */
1238
+};
12391239
12401240 #define I740_ID_PCI 0x00d1
12411241 #define I740_ID_AGP 0x7800
....@@ -1252,8 +1252,7 @@
12521252 .id_table = i740fb_id_table,
12531253 .probe = i740fb_probe,
12541254 .remove = i740fb_remove,
1255
- .suspend = i740fb_suspend,
1256
- .resume = i740fb_resume,
1255
+ .driver.pm = &i740fb_pm_ops,
12571256 };
12581257
12591258 #ifndef MODULE