hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/video/fbdev/da8xx-fb.c
....@@ -1,23 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2008-2009 MontaVista Software Inc.
34 * Copyright (C) 2008-2009 Texas Instruments Inc
45 *
56 * Based on the LCD driver for TI Avalanche processors written by
67 * Ajay Singh and Shalom Hai.
7
- *
8
- * This program is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option)any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
218 */
229 #include <linux/module.h>
2310 #include <linux/kernel.h>
....@@ -32,6 +19,7 @@
3219 #include <linux/clk.h>
3320 #include <linux/cpufreq.h>
3421 #include <linux/console.h>
22
+#include <linux/regulator/consumer.h>
3523 #include <linux/spinlock.h>
3624 #include <linux/slab.h>
3725 #include <linux/delay.h>
....@@ -177,7 +165,7 @@
177165 struct notifier_block freq_transition;
178166 #endif
179167 unsigned int lcdc_clk_rate;
180
- void (*panel_power_ctrl)(int);
168
+ struct regulator *lcd_supply;
181169 u32 pseudo_palette[16];
182170 struct fb_videomode mode;
183171 struct lcd_ctrl_config cfg;
....@@ -1079,33 +1067,30 @@
10791067 static int fb_remove(struct platform_device *dev)
10801068 {
10811069 struct fb_info *info = dev_get_drvdata(&dev->dev);
1082
-
1083
- if (info) {
1084
- struct da8xx_fb_par *par = info->par;
1070
+ struct da8xx_fb_par *par = info->par;
1071
+ int ret;
10851072
10861073 #ifdef CONFIG_CPU_FREQ
1087
- lcd_da8xx_cpufreq_deregister(par);
1074
+ lcd_da8xx_cpufreq_deregister(par);
10881075 #endif
1089
- if (par->panel_power_ctrl)
1090
- par->panel_power_ctrl(0);
1091
-
1092
- lcd_disable_raster(DA8XX_FRAME_WAIT);
1093
- lcdc_write(0, LCD_RASTER_CTRL_REG);
1094
-
1095
- /* disable DMA */
1096
- lcdc_write(0, LCD_DMA_CTRL_REG);
1097
-
1098
- unregister_framebuffer(info);
1099
- fb_dealloc_cmap(&info->cmap);
1100
- dma_free_coherent(NULL, PALETTE_SIZE, par->v_palette_base,
1101
- par->p_palette_base);
1102
- dma_free_coherent(NULL, par->vram_size, par->vram_virt,
1103
- par->vram_phys);
1104
- pm_runtime_put_sync(&dev->dev);
1105
- pm_runtime_disable(&dev->dev);
1106
- framebuffer_release(info);
1107
-
1076
+ if (par->lcd_supply) {
1077
+ ret = regulator_disable(par->lcd_supply);
1078
+ if (ret)
1079
+ return ret;
11081080 }
1081
+
1082
+ lcd_disable_raster(DA8XX_FRAME_WAIT);
1083
+ lcdc_write(0, LCD_RASTER_CTRL_REG);
1084
+
1085
+ /* disable DMA */
1086
+ lcdc_write(0, LCD_DMA_CTRL_REG);
1087
+
1088
+ unregister_framebuffer(info);
1089
+ fb_dealloc_cmap(&info->cmap);
1090
+ pm_runtime_put_sync(&dev->dev);
1091
+ pm_runtime_disable(&dev->dev);
1092
+ framebuffer_release(info);
1093
+
11091094 return 0;
11101095 }
11111096
....@@ -1192,15 +1177,21 @@
11921177 case FB_BLANK_UNBLANK:
11931178 lcd_enable_raster();
11941179
1195
- if (par->panel_power_ctrl)
1196
- par->panel_power_ctrl(1);
1180
+ if (par->lcd_supply) {
1181
+ ret = regulator_enable(par->lcd_supply);
1182
+ if (ret)
1183
+ return ret;
1184
+ }
11971185 break;
11981186 case FB_BLANK_NORMAL:
11991187 case FB_BLANK_VSYNC_SUSPEND:
12001188 case FB_BLANK_HSYNC_SUSPEND:
12011189 case FB_BLANK_POWERDOWN:
1202
- if (par->panel_power_ctrl)
1203
- par->panel_power_ctrl(0);
1190
+ if (par->lcd_supply) {
1191
+ ret = regulator_disable(par->lcd_supply);
1192
+ if (ret)
1193
+ return ret;
1194
+ }
12041195
12051196 lcd_disable_raster(DA8XX_FRAME_WAIT);
12061197 break;
....@@ -1303,7 +1294,7 @@
13031294 return 0;
13041295 }
13051296
1306
-static struct fb_ops da8xx_fb_ops = {
1297
+static const struct fb_ops da8xx_fb_ops = {
13071298 .owner = THIS_MODULE,
13081299 .fb_check_var = fb_check_var,
13091300 .fb_set_par = da8xxfb_set_par,
....@@ -1341,7 +1332,6 @@
13411332 {
13421333 struct da8xx_lcdc_platform_data *fb_pdata =
13431334 dev_get_platdata(&device->dev);
1344
- struct resource *lcdc_regs;
13451335 struct lcd_ctrl_config *lcd_cfg;
13461336 struct fb_videomode *lcdc_info;
13471337 struct fb_info *da8xx_fb_info;
....@@ -1359,8 +1349,7 @@
13591349 if (lcdc_info == NULL)
13601350 return -ENODEV;
13611351
1362
- lcdc_regs = platform_get_resource(device, IORESOURCE_MEM, 0);
1363
- da8xx_fb_reg_base = devm_ioremap_resource(&device->dev, lcdc_regs);
1352
+ da8xx_fb_reg_base = devm_platform_ioremap_resource(device, 0);
13641353 if (IS_ERR(da8xx_fb_reg_base))
13651354 return PTR_ERR(da8xx_fb_reg_base);
13661355
....@@ -1400,7 +1389,6 @@
14001389 da8xx_fb_info = framebuffer_alloc(sizeof(struct da8xx_fb_par),
14011390 &device->dev);
14021391 if (!da8xx_fb_info) {
1403
- dev_dbg(&device->dev, "Memory allocation failed for fb_info\n");
14041392 ret = -ENOMEM;
14051393 goto err_pm_runtime_disable;
14061394 }
....@@ -1409,9 +1397,19 @@
14091397 par->dev = &device->dev;
14101398 par->lcdc_clk = tmp_lcdc_clk;
14111399 par->lcdc_clk_rate = clk_get_rate(par->lcdc_clk);
1412
- if (fb_pdata->panel_power_ctrl) {
1413
- par->panel_power_ctrl = fb_pdata->panel_power_ctrl;
1414
- par->panel_power_ctrl(1);
1400
+
1401
+ par->lcd_supply = devm_regulator_get_optional(&device->dev, "lcd");
1402
+ if (IS_ERR(par->lcd_supply)) {
1403
+ if (PTR_ERR(par->lcd_supply) == -EPROBE_DEFER) {
1404
+ ret = -EPROBE_DEFER;
1405
+ goto err_release_fb;
1406
+ }
1407
+
1408
+ par->lcd_supply = NULL;
1409
+ } else {
1410
+ ret = regulator_enable(par->lcd_supply);
1411
+ if (ret)
1412
+ goto err_release_fb;
14151413 }
14161414
14171415 fb_videomode_to_var(&da8xx_fb_var, lcdc_info);
....@@ -1425,10 +1423,10 @@
14251423 par->vram_size = roundup(par->vram_size/8, ulcm);
14261424 par->vram_size = par->vram_size * LCD_NUM_BUFFERS;
14271425
1428
- par->vram_virt = dma_alloc_coherent(NULL,
1429
- par->vram_size,
1430
- &par->vram_phys,
1431
- GFP_KERNEL | GFP_DMA);
1426
+ par->vram_virt = dmam_alloc_coherent(par->dev,
1427
+ par->vram_size,
1428
+ &par->vram_phys,
1429
+ GFP_KERNEL | GFP_DMA);
14321430 if (!par->vram_virt) {
14331431 dev_err(&device->dev,
14341432 "GLCD: kmalloc for frame buffer failed\n");
....@@ -1446,20 +1444,20 @@
14461444 da8xx_fb_fix.line_length - 1;
14471445
14481446 /* allocate palette buffer */
1449
- par->v_palette_base = dma_zalloc_coherent(NULL, PALETTE_SIZE,
1447
+ par->v_palette_base = dmam_alloc_coherent(par->dev, PALETTE_SIZE,
14501448 &par->p_palette_base,
14511449 GFP_KERNEL | GFP_DMA);
14521450 if (!par->v_palette_base) {
14531451 dev_err(&device->dev,
14541452 "GLCD: kmalloc for palette buffer failed\n");
14551453 ret = -EINVAL;
1456
- goto err_release_fb_mem;
1454
+ goto err_release_fb;
14571455 }
14581456
14591457 par->irq = platform_get_irq(device, 0);
14601458 if (par->irq < 0) {
14611459 ret = -ENOENT;
1462
- goto err_release_pl_mem;
1460
+ goto err_release_fb;
14631461 }
14641462
14651463 da8xx_fb_var.grayscale =
....@@ -1477,7 +1475,7 @@
14771475
14781476 ret = fb_alloc_cmap(&da8xx_fb_info->cmap, PALETTE_SIZE, 0);
14791477 if (ret)
1480
- goto err_release_pl_mem;
1478
+ goto err_release_fb;
14811479 da8xx_fb_info->cmap.len = par->palette_sz;
14821480
14831481 /* initialize var_screeninfo */
....@@ -1530,13 +1528,6 @@
15301528
15311529 err_dealloc_cmap:
15321530 fb_dealloc_cmap(&da8xx_fb_info->cmap);
1533
-
1534
-err_release_pl_mem:
1535
- dma_free_coherent(NULL, PALETTE_SIZE, par->v_palette_base,
1536
- par->p_palette_base);
1537
-
1538
-err_release_fb_mem:
1539
- dma_free_coherent(NULL, par->vram_size, par->vram_virt, par->vram_phys);
15401531
15411532 err_release_fb:
15421533 framebuffer_release(da8xx_fb_info);
....@@ -1616,10 +1607,14 @@
16161607 {
16171608 struct fb_info *info = dev_get_drvdata(dev);
16181609 struct da8xx_fb_par *par = info->par;
1610
+ int ret;
16191611
16201612 console_lock();
1621
- if (par->panel_power_ctrl)
1622
- par->panel_power_ctrl(0);
1613
+ if (par->lcd_supply) {
1614
+ ret = regulator_disable(par->lcd_supply);
1615
+ if (ret)
1616
+ return ret;
1617
+ }
16231618
16241619 fb_set_suspend(info, 1);
16251620 lcd_disable_raster(DA8XX_FRAME_WAIT);
....@@ -1633,6 +1628,7 @@
16331628 {
16341629 struct fb_info *info = dev_get_drvdata(dev);
16351630 struct da8xx_fb_par *par = info->par;
1631
+ int ret;
16361632
16371633 console_lock();
16381634 pm_runtime_get_sync(dev);
....@@ -1640,8 +1636,11 @@
16401636 if (par->blank == FB_BLANK_UNBLANK) {
16411637 lcd_enable_raster();
16421638
1643
- if (par->panel_power_ctrl)
1644
- par->panel_power_ctrl(1);
1639
+ if (par->lcd_supply) {
1640
+ ret = regulator_enable(par->lcd_supply);
1641
+ if (ret)
1642
+ return ret;
1643
+ }
16451644 }
16461645
16471646 fb_set_suspend(info, 0);