18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Frame Buffer Device for Toshiba Mobile IO(TMIO) controller 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright(C) 2005-2006 Chris Humbert 68c2ecf20Sopenharmony_ci * Copyright(C) 2005 Dirk Opfer 78c2ecf20Sopenharmony_ci * Copytight(C) 2007,2008 Dmitry Baryshkov 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Based on: 108c2ecf20Sopenharmony_ci * drivers/video/w100fb.c 118c2ecf20Sopenharmony_ci * code written by Sharp/Lineo for 2.4 kernels 128c2ecf20Sopenharmony_ci */ 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include <linux/kernel.h> 158c2ecf20Sopenharmony_ci#include <linux/module.h> 168c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 178c2ecf20Sopenharmony_ci#include <linux/fb.h> 188c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 198c2ecf20Sopenharmony_ci#include <linux/delay.h> 208c2ecf20Sopenharmony_ci/* Why should fb driver call console functions? because console_lock() */ 218c2ecf20Sopenharmony_ci#include <linux/console.h> 228c2ecf20Sopenharmony_ci#include <linux/mfd/core.h> 238c2ecf20Sopenharmony_ci#include <linux/mfd/tmio.h> 248c2ecf20Sopenharmony_ci#include <linux/uaccess.h> 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci/* 278c2ecf20Sopenharmony_ci * accelerator commands 288c2ecf20Sopenharmony_ci */ 298c2ecf20Sopenharmony_ci#define TMIOFB_ACC_CSADR(x) (0x00000000 | ((x) & 0x001ffffe)) 308c2ecf20Sopenharmony_ci#define TMIOFB_ACC_CHPIX(x) (0x01000000 | ((x) & 0x000003ff)) 318c2ecf20Sopenharmony_ci#define TMIOFB_ACC_CVPIX(x) (0x02000000 | ((x) & 0x000003ff)) 328c2ecf20Sopenharmony_ci#define TMIOFB_ACC_PSADR(x) (0x03000000 | ((x) & 0x00fffffe)) 338c2ecf20Sopenharmony_ci#define TMIOFB_ACC_PHPIX(x) (0x04000000 | ((x) & 0x000003ff)) 348c2ecf20Sopenharmony_ci#define TMIOFB_ACC_PVPIX(x) (0x05000000 | ((x) & 0x000003ff)) 358c2ecf20Sopenharmony_ci#define TMIOFB_ACC_PHOFS(x) (0x06000000 | ((x) & 0x000003ff)) 368c2ecf20Sopenharmony_ci#define TMIOFB_ACC_PVOFS(x) (0x07000000 | ((x) & 0x000003ff)) 378c2ecf20Sopenharmony_ci#define TMIOFB_ACC_POADR(x) (0x08000000 | ((x) & 0x00fffffe)) 388c2ecf20Sopenharmony_ci#define TMIOFB_ACC_RSTR(x) (0x09000000 | ((x) & 0x000000ff)) 398c2ecf20Sopenharmony_ci#define TMIOFB_ACC_TCLOR(x) (0x0A000000 | ((x) & 0x0000ffff)) 408c2ecf20Sopenharmony_ci#define TMIOFB_ACC_FILL(x) (0x0B000000 | ((x) & 0x0000ffff)) 418c2ecf20Sopenharmony_ci#define TMIOFB_ACC_DSADR(x) (0x0C000000 | ((x) & 0x00fffffe)) 428c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SSADR(x) (0x0D000000 | ((x) & 0x00fffffe)) 438c2ecf20Sopenharmony_ci#define TMIOFB_ACC_DHPIX(x) (0x0E000000 | ((x) & 0x000003ff)) 448c2ecf20Sopenharmony_ci#define TMIOFB_ACC_DVPIX(x) (0x0F000000 | ((x) & 0x000003ff)) 458c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SHPIX(x) (0x10000000 | ((x) & 0x000003ff)) 468c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SVPIX(x) (0x11000000 | ((x) & 0x000003ff)) 478c2ecf20Sopenharmony_ci#define TMIOFB_ACC_LBINI(x) (0x12000000 | ((x) & 0x0000ffff)) 488c2ecf20Sopenharmony_ci#define TMIOFB_ACC_LBK2(x) (0x13000000 | ((x) & 0x0000ffff)) 498c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SHBINI(x) (0x14000000 | ((x) & 0x0000ffff)) 508c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SHBK2(x) (0x15000000 | ((x) & 0x0000ffff)) 518c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SVBINI(x) (0x16000000 | ((x) & 0x0000ffff)) 528c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SVBK2(x) (0x17000000 | ((x) & 0x0000ffff)) 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#define TMIOFB_ACC_CMGO 0x20000000 558c2ecf20Sopenharmony_ci#define TMIOFB_ACC_CMGO_CEND 0x00000001 568c2ecf20Sopenharmony_ci#define TMIOFB_ACC_CMGO_INT 0x00000002 578c2ecf20Sopenharmony_ci#define TMIOFB_ACC_CMGO_CMOD 0x00000010 588c2ecf20Sopenharmony_ci#define TMIOFB_ACC_CMGO_CDVRV 0x00000020 598c2ecf20Sopenharmony_ci#define TMIOFB_ACC_CMGO_CDHRV 0x00000040 608c2ecf20Sopenharmony_ci#define TMIOFB_ACC_CMGO_RUND 0x00008000 618c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SCGO 0x21000000 628c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SCGO_CEND 0x00000001 638c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SCGO_INT 0x00000002 648c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SCGO_ROP3 0x00000004 658c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SCGO_TRNS 0x00000008 668c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SCGO_DVRV 0x00000010 678c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SCGO_DHRV 0x00000020 688c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SCGO_SVRV 0x00000040 698c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SCGO_SHRV 0x00000080 708c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SCGO_DSTXY 0x00008000 718c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SBGO 0x22000000 728c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SBGO_CEND 0x00000001 738c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SBGO_INT 0x00000002 748c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SBGO_DVRV 0x00000010 758c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SBGO_DHRV 0x00000020 768c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SBGO_SVRV 0x00000040 778c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SBGO_SHRV 0x00000080 788c2ecf20Sopenharmony_ci#define TMIOFB_ACC_SBGO_SBMD 0x00000100 798c2ecf20Sopenharmony_ci#define TMIOFB_ACC_FLGO 0x23000000 808c2ecf20Sopenharmony_ci#define TMIOFB_ACC_FLGO_CEND 0x00000001 818c2ecf20Sopenharmony_ci#define TMIOFB_ACC_FLGO_INT 0x00000002 828c2ecf20Sopenharmony_ci#define TMIOFB_ACC_FLGO_ROP3 0x00000004 838c2ecf20Sopenharmony_ci#define TMIOFB_ACC_LDGO 0x24000000 848c2ecf20Sopenharmony_ci#define TMIOFB_ACC_LDGO_CEND 0x00000001 858c2ecf20Sopenharmony_ci#define TMIOFB_ACC_LDGO_INT 0x00000002 868c2ecf20Sopenharmony_ci#define TMIOFB_ACC_LDGO_ROP3 0x00000004 878c2ecf20Sopenharmony_ci#define TMIOFB_ACC_LDGO_ENDPX 0x00000008 888c2ecf20Sopenharmony_ci#define TMIOFB_ACC_LDGO_LVRV 0x00000010 898c2ecf20Sopenharmony_ci#define TMIOFB_ACC_LDGO_LHRV 0x00000020 908c2ecf20Sopenharmony_ci#define TMIOFB_ACC_LDGO_LDMOD 0x00000040 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci/* a FIFO is always allocated, even if acceleration is not used */ 938c2ecf20Sopenharmony_ci#define TMIOFB_FIFO_SIZE 512 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci/* 968c2ecf20Sopenharmony_ci * LCD Host Controller Configuration Register 978c2ecf20Sopenharmony_ci * 988c2ecf20Sopenharmony_ci * This iomem area supports only 16-bit IO. 998c2ecf20Sopenharmony_ci */ 1008c2ecf20Sopenharmony_ci#define CCR_CMD 0x04 /* Command */ 1018c2ecf20Sopenharmony_ci#define CCR_REVID 0x08 /* Revision ID */ 1028c2ecf20Sopenharmony_ci#define CCR_BASEL 0x10 /* LCD Control Reg Base Addr Low */ 1038c2ecf20Sopenharmony_ci#define CCR_BASEH 0x12 /* LCD Control Reg Base Addr High */ 1048c2ecf20Sopenharmony_ci#define CCR_UGCC 0x40 /* Unified Gated Clock Control */ 1058c2ecf20Sopenharmony_ci#define CCR_GCC 0x42 /* Gated Clock Control */ 1068c2ecf20Sopenharmony_ci#define CCR_USC 0x50 /* Unified Software Clear */ 1078c2ecf20Sopenharmony_ci#define CCR_VRAMRTC 0x60 /* VRAM Timing Control */ 1088c2ecf20Sopenharmony_ci /* 0x61 VRAM Refresh Control */ 1098c2ecf20Sopenharmony_ci#define CCR_VRAMSAC 0x62 /* VRAM Access Control */ 1108c2ecf20Sopenharmony_ci /* 0x63 VRAM Status */ 1118c2ecf20Sopenharmony_ci#define CCR_VRAMBC 0x64 /* VRAM Block Control */ 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci/* 1148c2ecf20Sopenharmony_ci * LCD Control Register 1158c2ecf20Sopenharmony_ci * 1168c2ecf20Sopenharmony_ci * This iomem area supports only 16-bit IO. 1178c2ecf20Sopenharmony_ci */ 1188c2ecf20Sopenharmony_ci#define LCR_UIS 0x000 /* Unified Interrupt Status */ 1198c2ecf20Sopenharmony_ci#define LCR_VHPN 0x008 /* VRAM Horizontal Pixel Number */ 1208c2ecf20Sopenharmony_ci#define LCR_CFSAL 0x00a /* Command FIFO Start Address Low */ 1218c2ecf20Sopenharmony_ci#define LCR_CFSAH 0x00c /* Command FIFO Start Address High */ 1228c2ecf20Sopenharmony_ci#define LCR_CFS 0x00e /* Command FIFO Size */ 1238c2ecf20Sopenharmony_ci#define LCR_CFWS 0x010 /* Command FIFO Writeable Size */ 1248c2ecf20Sopenharmony_ci#define LCR_BBIE 0x012 /* BitBLT Interrupt Enable */ 1258c2ecf20Sopenharmony_ci#define LCR_BBISC 0x014 /* BitBLT Interrupt Status and Clear */ 1268c2ecf20Sopenharmony_ci#define LCR_CCS 0x016 /* Command Count Status */ 1278c2ecf20Sopenharmony_ci#define LCR_BBES 0x018 /* BitBLT Execution Status */ 1288c2ecf20Sopenharmony_ci#define LCR_CMDL 0x01c /* Command Low */ 1298c2ecf20Sopenharmony_ci#define LCR_CMDH 0x01e /* Command High */ 1308c2ecf20Sopenharmony_ci#define LCR_CFC 0x022 /* Command FIFO Clear */ 1318c2ecf20Sopenharmony_ci#define LCR_CCIFC 0x024 /* CMOS Camera IF Control */ 1328c2ecf20Sopenharmony_ci#define LCR_HWT 0x026 /* Hardware Test */ 1338c2ecf20Sopenharmony_ci#define LCR_LCDCCRC 0x100 /* LCDC Clock and Reset Control */ 1348c2ecf20Sopenharmony_ci#define LCR_LCDCC 0x102 /* LCDC Control */ 1358c2ecf20Sopenharmony_ci#define LCR_LCDCOPC 0x104 /* LCDC Output Pin Control */ 1368c2ecf20Sopenharmony_ci#define LCR_LCDIS 0x108 /* LCD Interrupt Status */ 1378c2ecf20Sopenharmony_ci#define LCR_LCDIM 0x10a /* LCD Interrupt Mask */ 1388c2ecf20Sopenharmony_ci#define LCR_LCDIE 0x10c /* LCD Interrupt Enable */ 1398c2ecf20Sopenharmony_ci#define LCR_GDSAL 0x122 /* Graphics Display Start Address Low */ 1408c2ecf20Sopenharmony_ci#define LCR_GDSAH 0x124 /* Graphics Display Start Address High */ 1418c2ecf20Sopenharmony_ci#define LCR_VHPCL 0x12a /* VRAM Horizontal Pixel Count Low */ 1428c2ecf20Sopenharmony_ci#define LCR_VHPCH 0x12c /* VRAM Horizontal Pixel Count High */ 1438c2ecf20Sopenharmony_ci#define LCR_GM 0x12e /* Graphic Mode(VRAM access enable) */ 1448c2ecf20Sopenharmony_ci#define LCR_HT 0x140 /* Horizontal Total */ 1458c2ecf20Sopenharmony_ci#define LCR_HDS 0x142 /* Horizontal Display Start */ 1468c2ecf20Sopenharmony_ci#define LCR_HSS 0x144 /* H-Sync Start */ 1478c2ecf20Sopenharmony_ci#define LCR_HSE 0x146 /* H-Sync End */ 1488c2ecf20Sopenharmony_ci#define LCR_HNP 0x14c /* Horizontal Number of Pixels */ 1498c2ecf20Sopenharmony_ci#define LCR_VT 0x150 /* Vertical Total */ 1508c2ecf20Sopenharmony_ci#define LCR_VDS 0x152 /* Vertical Display Start */ 1518c2ecf20Sopenharmony_ci#define LCR_VSS 0x154 /* V-Sync Start */ 1528c2ecf20Sopenharmony_ci#define LCR_VSE 0x156 /* V-Sync End */ 1538c2ecf20Sopenharmony_ci#define LCR_CDLN 0x160 /* Current Display Line Number */ 1548c2ecf20Sopenharmony_ci#define LCR_ILN 0x162 /* Interrupt Line Number */ 1558c2ecf20Sopenharmony_ci#define LCR_SP 0x164 /* Sync Polarity */ 1568c2ecf20Sopenharmony_ci#define LCR_MISC 0x166 /* MISC(RGB565 mode) */ 1578c2ecf20Sopenharmony_ci#define LCR_VIHSS 0x16a /* Video Interface H-Sync Start */ 1588c2ecf20Sopenharmony_ci#define LCR_VIVS 0x16c /* Video Interface Vertical Start */ 1598c2ecf20Sopenharmony_ci#define LCR_VIVE 0x16e /* Video Interface Vertical End */ 1608c2ecf20Sopenharmony_ci#define LCR_VIVSS 0x170 /* Video Interface V-Sync Start */ 1618c2ecf20Sopenharmony_ci#define LCR_VCCIS 0x17e /* Video / CMOS Camera Interface Select */ 1628c2ecf20Sopenharmony_ci#define LCR_VIDWSAL 0x180 /* VI Data Write Start Address Low */ 1638c2ecf20Sopenharmony_ci#define LCR_VIDWSAH 0x182 /* VI Data Write Start Address High */ 1648c2ecf20Sopenharmony_ci#define LCR_VIDRSAL 0x184 /* VI Data Read Start Address Low */ 1658c2ecf20Sopenharmony_ci#define LCR_VIDRSAH 0x186 /* VI Data Read Start Address High */ 1668c2ecf20Sopenharmony_ci#define LCR_VIPDDST 0x188 /* VI Picture Data Display Start Timing */ 1678c2ecf20Sopenharmony_ci#define LCR_VIPDDET 0x186 /* VI Picture Data Display End Timing */ 1688c2ecf20Sopenharmony_ci#define LCR_VIE 0x18c /* Video Interface Enable */ 1698c2ecf20Sopenharmony_ci#define LCR_VCS 0x18e /* Video/Camera Select */ 1708c2ecf20Sopenharmony_ci#define LCR_VPHWC 0x194 /* Video Picture Horizontal Wait Count */ 1718c2ecf20Sopenharmony_ci#define LCR_VPHS 0x196 /* Video Picture Horizontal Size */ 1728c2ecf20Sopenharmony_ci#define LCR_VPVWC 0x198 /* Video Picture Vertical Wait Count */ 1738c2ecf20Sopenharmony_ci#define LCR_VPVS 0x19a /* Video Picture Vertical Size */ 1748c2ecf20Sopenharmony_ci#define LCR_PLHPIX 0x1a0 /* PLHPIX */ 1758c2ecf20Sopenharmony_ci#define LCR_XS 0x1a2 /* XStart */ 1768c2ecf20Sopenharmony_ci#define LCR_XCKHW 0x1a4 /* XCK High Width */ 1778c2ecf20Sopenharmony_ci#define LCR_STHS 0x1a8 /* STH Start */ 1788c2ecf20Sopenharmony_ci#define LCR_VT2 0x1aa /* Vertical Total */ 1798c2ecf20Sopenharmony_ci#define LCR_YCKSW 0x1ac /* YCK Start Wait */ 1808c2ecf20Sopenharmony_ci#define LCR_YSTS 0x1ae /* YST Start */ 1818c2ecf20Sopenharmony_ci#define LCR_PPOLS 0x1b0 /* #PPOL Start */ 1828c2ecf20Sopenharmony_ci#define LCR_PRECW 0x1b2 /* PREC Width */ 1838c2ecf20Sopenharmony_ci#define LCR_VCLKHW 0x1b4 /* VCLK High Width */ 1848c2ecf20Sopenharmony_ci#define LCR_OC 0x1b6 /* Output Control */ 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_cistatic char *mode_option; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_cistruct tmiofb_par { 1898c2ecf20Sopenharmony_ci u32 pseudo_palette[16]; 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_TMIO_ACCELL 1928c2ecf20Sopenharmony_ci wait_queue_head_t wait_acc; 1938c2ecf20Sopenharmony_ci bool use_polling; 1948c2ecf20Sopenharmony_ci#endif 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci void __iomem *ccr; 1978c2ecf20Sopenharmony_ci void __iomem *lcr; 1988c2ecf20Sopenharmony_ci}; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci/*--------------------------------------------------------------------------*/ 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci/* 2038c2ecf20Sopenharmony_ci * reasons for an interrupt: 2048c2ecf20Sopenharmony_ci * uis bbisc lcdis 2058c2ecf20Sopenharmony_ci * 0100 0001 accelerator command completed 2068c2ecf20Sopenharmony_ci * 2000 0001 vsync start 2078c2ecf20Sopenharmony_ci * 2000 0002 display start 2088c2ecf20Sopenharmony_ci * 2000 0004 line number match(0x1ff mask???) 2098c2ecf20Sopenharmony_ci */ 2108c2ecf20Sopenharmony_cistatic irqreturn_t tmiofb_irq(int irq, void *__info) 2118c2ecf20Sopenharmony_ci{ 2128c2ecf20Sopenharmony_ci struct fb_info *info = __info; 2138c2ecf20Sopenharmony_ci struct tmiofb_par *par = info->par; 2148c2ecf20Sopenharmony_ci unsigned int bbisc = tmio_ioread16(par->lcr + LCR_BBISC); 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci tmio_iowrite16(bbisc, par->lcr + LCR_BBISC); 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_TMIO_ACCELL 2208c2ecf20Sopenharmony_ci /* 2218c2ecf20Sopenharmony_ci * We were in polling mode and now we got correct irq. 2228c2ecf20Sopenharmony_ci * Switch back to IRQ-based sync of command FIFO 2238c2ecf20Sopenharmony_ci */ 2248c2ecf20Sopenharmony_ci if (unlikely(par->use_polling && irq != -1)) { 2258c2ecf20Sopenharmony_ci printk(KERN_INFO "tmiofb: switching to waitq\n"); 2268c2ecf20Sopenharmony_ci par->use_polling = false; 2278c2ecf20Sopenharmony_ci } 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci if (bbisc & 1) 2308c2ecf20Sopenharmony_ci wake_up(&par->wait_acc); 2318c2ecf20Sopenharmony_ci#endif 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci return IRQ_HANDLED; 2348c2ecf20Sopenharmony_ci} 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci/*--------------------------------------------------------------------------*/ 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci/* 2418c2ecf20Sopenharmony_ci * Turns off the LCD controller and LCD host controller. 2428c2ecf20Sopenharmony_ci */ 2438c2ecf20Sopenharmony_cistatic int tmiofb_hw_stop(struct platform_device *dev) 2448c2ecf20Sopenharmony_ci{ 2458c2ecf20Sopenharmony_ci struct tmio_fb_data *data = dev_get_platdata(&dev->dev); 2468c2ecf20Sopenharmony_ci struct fb_info *info = platform_get_drvdata(dev); 2478c2ecf20Sopenharmony_ci struct tmiofb_par *par = info->par; 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci tmio_iowrite16(0, par->ccr + CCR_UGCC); 2508c2ecf20Sopenharmony_ci tmio_iowrite16(0, par->lcr + LCR_GM); 2518c2ecf20Sopenharmony_ci data->lcd_set_power(dev, 0); 2528c2ecf20Sopenharmony_ci tmio_iowrite16(0x0010, par->lcr + LCR_LCDCCRC); 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci return 0; 2558c2ecf20Sopenharmony_ci} 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci/* 2588c2ecf20Sopenharmony_ci * Initializes the LCD host controller. 2598c2ecf20Sopenharmony_ci */ 2608c2ecf20Sopenharmony_cistatic int tmiofb_hw_init(struct platform_device *dev) 2618c2ecf20Sopenharmony_ci{ 2628c2ecf20Sopenharmony_ci const struct mfd_cell *cell = mfd_get_cell(dev); 2638c2ecf20Sopenharmony_ci struct fb_info *info = platform_get_drvdata(dev); 2648c2ecf20Sopenharmony_ci struct tmiofb_par *par = info->par; 2658c2ecf20Sopenharmony_ci const struct resource *nlcr = &cell->resources[0]; 2668c2ecf20Sopenharmony_ci const struct resource *vram = &cell->resources[2]; 2678c2ecf20Sopenharmony_ci unsigned long base; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci if (nlcr == NULL || vram == NULL) 2708c2ecf20Sopenharmony_ci return -EINVAL; 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci base = nlcr->start; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci tmio_iowrite16(0x003a, par->ccr + CCR_UGCC); 2758c2ecf20Sopenharmony_ci tmio_iowrite16(0x003a, par->ccr + CCR_GCC); 2768c2ecf20Sopenharmony_ci tmio_iowrite16(0x3f00, par->ccr + CCR_USC); 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci msleep(2); /* wait for device to settle */ 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci tmio_iowrite16(0x0000, par->ccr + CCR_USC); 2818c2ecf20Sopenharmony_ci tmio_iowrite16(base >> 16, par->ccr + CCR_BASEH); 2828c2ecf20Sopenharmony_ci tmio_iowrite16(base, par->ccr + CCR_BASEL); 2838c2ecf20Sopenharmony_ci tmio_iowrite16(0x0002, par->ccr + CCR_CMD); /* base address enable */ 2848c2ecf20Sopenharmony_ci tmio_iowrite16(0x40a8, par->ccr + CCR_VRAMRTC); /* VRAMRC, VRAMTC */ 2858c2ecf20Sopenharmony_ci tmio_iowrite16(0x0018, par->ccr + CCR_VRAMSAC); /* VRAMSTS, VRAMAC */ 2868c2ecf20Sopenharmony_ci tmio_iowrite16(0x0002, par->ccr + CCR_VRAMBC); 2878c2ecf20Sopenharmony_ci msleep(2); /* wait for device to settle */ 2888c2ecf20Sopenharmony_ci tmio_iowrite16(0x000b, par->ccr + CCR_VRAMBC); 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci base = vram->start + info->screen_size; 2918c2ecf20Sopenharmony_ci tmio_iowrite16(base >> 16, par->lcr + LCR_CFSAH); 2928c2ecf20Sopenharmony_ci tmio_iowrite16(base, par->lcr + LCR_CFSAL); 2938c2ecf20Sopenharmony_ci tmio_iowrite16(TMIOFB_FIFO_SIZE - 1, par->lcr + LCR_CFS); 2948c2ecf20Sopenharmony_ci tmio_iowrite16(1, par->lcr + LCR_CFC); 2958c2ecf20Sopenharmony_ci tmio_iowrite16(1, par->lcr + LCR_BBIE); 2968c2ecf20Sopenharmony_ci tmio_iowrite16(0, par->lcr + LCR_CFWS); 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci return 0; 2998c2ecf20Sopenharmony_ci} 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci/* 3028c2ecf20Sopenharmony_ci * Sets the LCD controller's output resolution and pixel clock 3038c2ecf20Sopenharmony_ci */ 3048c2ecf20Sopenharmony_cistatic void tmiofb_hw_mode(struct platform_device *dev) 3058c2ecf20Sopenharmony_ci{ 3068c2ecf20Sopenharmony_ci struct tmio_fb_data *data = dev_get_platdata(&dev->dev); 3078c2ecf20Sopenharmony_ci struct fb_info *info = platform_get_drvdata(dev); 3088c2ecf20Sopenharmony_ci struct fb_videomode *mode = info->mode; 3098c2ecf20Sopenharmony_ci struct tmiofb_par *par = info->par; 3108c2ecf20Sopenharmony_ci unsigned int i; 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci tmio_iowrite16(0, par->lcr + LCR_GM); 3138c2ecf20Sopenharmony_ci data->lcd_set_power(dev, 0); 3148c2ecf20Sopenharmony_ci tmio_iowrite16(0x0010, par->lcr + LCR_LCDCCRC); 3158c2ecf20Sopenharmony_ci data->lcd_mode(dev, mode); 3168c2ecf20Sopenharmony_ci data->lcd_set_power(dev, 1); 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci tmio_iowrite16(info->fix.line_length, par->lcr + LCR_VHPN); 3198c2ecf20Sopenharmony_ci tmio_iowrite16(0, par->lcr + LCR_GDSAH); 3208c2ecf20Sopenharmony_ci tmio_iowrite16(0, par->lcr + LCR_GDSAL); 3218c2ecf20Sopenharmony_ci tmio_iowrite16(info->fix.line_length >> 16, par->lcr + LCR_VHPCH); 3228c2ecf20Sopenharmony_ci tmio_iowrite16(info->fix.line_length, par->lcr + LCR_VHPCL); 3238c2ecf20Sopenharmony_ci tmio_iowrite16(i = 0, par->lcr + LCR_HSS); 3248c2ecf20Sopenharmony_ci tmio_iowrite16(i += mode->hsync_len, par->lcr + LCR_HSE); 3258c2ecf20Sopenharmony_ci tmio_iowrite16(i += mode->left_margin, par->lcr + LCR_HDS); 3268c2ecf20Sopenharmony_ci tmio_iowrite16(i += mode->xres + mode->right_margin, par->lcr + LCR_HT); 3278c2ecf20Sopenharmony_ci tmio_iowrite16(mode->xres, par->lcr + LCR_HNP); 3288c2ecf20Sopenharmony_ci tmio_iowrite16(i = 0, par->lcr + LCR_VSS); 3298c2ecf20Sopenharmony_ci tmio_iowrite16(i += mode->vsync_len, par->lcr + LCR_VSE); 3308c2ecf20Sopenharmony_ci tmio_iowrite16(i += mode->upper_margin, par->lcr + LCR_VDS); 3318c2ecf20Sopenharmony_ci tmio_iowrite16(i += mode->yres, par->lcr + LCR_ILN); 3328c2ecf20Sopenharmony_ci tmio_iowrite16(i += mode->lower_margin, par->lcr + LCR_VT); 3338c2ecf20Sopenharmony_ci tmio_iowrite16(3, par->lcr + LCR_MISC); /* RGB565 mode */ 3348c2ecf20Sopenharmony_ci tmio_iowrite16(1, par->lcr + LCR_GM); /* VRAM enable */ 3358c2ecf20Sopenharmony_ci tmio_iowrite16(0x4007, par->lcr + LCR_LCDCC); 3368c2ecf20Sopenharmony_ci tmio_iowrite16(3, par->lcr + LCR_SP); /* sync polarity */ 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci tmio_iowrite16(0x0010, par->lcr + LCR_LCDCCRC); 3398c2ecf20Sopenharmony_ci msleep(5); /* wait for device to settle */ 3408c2ecf20Sopenharmony_ci tmio_iowrite16(0x0014, par->lcr + LCR_LCDCCRC); /* STOP_CKP */ 3418c2ecf20Sopenharmony_ci msleep(5); /* wait for device to settle */ 3428c2ecf20Sopenharmony_ci tmio_iowrite16(0x0015, par->lcr + LCR_LCDCCRC); /* STOP_CKP|SOFT_RESET*/ 3438c2ecf20Sopenharmony_ci tmio_iowrite16(0xfffa, par->lcr + LCR_VCS); 3448c2ecf20Sopenharmony_ci} 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci/*--------------------------------------------------------------------------*/ 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_TMIO_ACCELL 3498c2ecf20Sopenharmony_cistatic int __must_check 3508c2ecf20Sopenharmony_citmiofb_acc_wait(struct fb_info *info, unsigned int ccs) 3518c2ecf20Sopenharmony_ci{ 3528c2ecf20Sopenharmony_ci struct tmiofb_par *par = info->par; 3538c2ecf20Sopenharmony_ci /* 3548c2ecf20Sopenharmony_ci * This code can be called with interrupts disabled. 3558c2ecf20Sopenharmony_ci * So instead of relaying on irq to trigger the event, 3568c2ecf20Sopenharmony_ci * poll the state till the necessary command is executed. 3578c2ecf20Sopenharmony_ci */ 3588c2ecf20Sopenharmony_ci if (irqs_disabled() || par->use_polling) { 3598c2ecf20Sopenharmony_ci int i = 0; 3608c2ecf20Sopenharmony_ci while (tmio_ioread16(par->lcr + LCR_CCS) > ccs) { 3618c2ecf20Sopenharmony_ci udelay(1); 3628c2ecf20Sopenharmony_ci i++; 3638c2ecf20Sopenharmony_ci if (i > 10000) { 3648c2ecf20Sopenharmony_ci pr_err("tmiofb: timeout waiting for %d\n", 3658c2ecf20Sopenharmony_ci ccs); 3668c2ecf20Sopenharmony_ci return -ETIMEDOUT; 3678c2ecf20Sopenharmony_ci } 3688c2ecf20Sopenharmony_ci tmiofb_irq(-1, info); 3698c2ecf20Sopenharmony_ci } 3708c2ecf20Sopenharmony_ci } else { 3718c2ecf20Sopenharmony_ci if (!wait_event_interruptible_timeout(par->wait_acc, 3728c2ecf20Sopenharmony_ci tmio_ioread16(par->lcr + LCR_CCS) <= ccs, 3738c2ecf20Sopenharmony_ci 1000)) { 3748c2ecf20Sopenharmony_ci pr_err("tmiofb: timeout waiting for %d\n", ccs); 3758c2ecf20Sopenharmony_ci return -ETIMEDOUT; 3768c2ecf20Sopenharmony_ci } 3778c2ecf20Sopenharmony_ci } 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci return 0; 3808c2ecf20Sopenharmony_ci} 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_ci/* 3838c2ecf20Sopenharmony_ci * Writes an accelerator command to the accelerator's FIFO. 3848c2ecf20Sopenharmony_ci */ 3858c2ecf20Sopenharmony_cistatic int 3868c2ecf20Sopenharmony_citmiofb_acc_write(struct fb_info *info, const u32 *cmd, unsigned int count) 3878c2ecf20Sopenharmony_ci{ 3888c2ecf20Sopenharmony_ci struct tmiofb_par *par = info->par; 3898c2ecf20Sopenharmony_ci int ret; 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci ret = tmiofb_acc_wait(info, TMIOFB_FIFO_SIZE - count); 3928c2ecf20Sopenharmony_ci if (ret) 3938c2ecf20Sopenharmony_ci return ret; 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci for (; count; count--, cmd++) { 3968c2ecf20Sopenharmony_ci tmio_iowrite16(*cmd >> 16, par->lcr + LCR_CMDH); 3978c2ecf20Sopenharmony_ci tmio_iowrite16(*cmd, par->lcr + LCR_CMDL); 3988c2ecf20Sopenharmony_ci } 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ci return ret; 4018c2ecf20Sopenharmony_ci} 4028c2ecf20Sopenharmony_ci 4038c2ecf20Sopenharmony_ci/* 4048c2ecf20Sopenharmony_ci * Wait for the accelerator to finish its operations before writing 4058c2ecf20Sopenharmony_ci * to the framebuffer for consistent display output. 4068c2ecf20Sopenharmony_ci */ 4078c2ecf20Sopenharmony_cistatic int tmiofb_sync(struct fb_info *fbi) 4088c2ecf20Sopenharmony_ci{ 4098c2ecf20Sopenharmony_ci struct tmiofb_par *par = fbi->par; 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci int ret; 4128c2ecf20Sopenharmony_ci int i = 0; 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci ret = tmiofb_acc_wait(fbi, 0); 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci while (tmio_ioread16(par->lcr + LCR_BBES) & 2) { /* blit active */ 4178c2ecf20Sopenharmony_ci udelay(1); 4188c2ecf20Sopenharmony_ci i++ ; 4198c2ecf20Sopenharmony_ci if (i > 10000) { 4208c2ecf20Sopenharmony_ci printk(KERN_ERR "timeout waiting for blit to end!\n"); 4218c2ecf20Sopenharmony_ci return -ETIMEDOUT; 4228c2ecf20Sopenharmony_ci } 4238c2ecf20Sopenharmony_ci } 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci return ret; 4268c2ecf20Sopenharmony_ci} 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_cistatic void 4298c2ecf20Sopenharmony_citmiofb_fillrect(struct fb_info *fbi, const struct fb_fillrect *rect) 4308c2ecf20Sopenharmony_ci{ 4318c2ecf20Sopenharmony_ci const u32 cmd[] = { 4328c2ecf20Sopenharmony_ci TMIOFB_ACC_DSADR((rect->dy * fbi->mode->xres + rect->dx) * 2), 4338c2ecf20Sopenharmony_ci TMIOFB_ACC_DHPIX(rect->width - 1), 4348c2ecf20Sopenharmony_ci TMIOFB_ACC_DVPIX(rect->height - 1), 4358c2ecf20Sopenharmony_ci TMIOFB_ACC_FILL(rect->color), 4368c2ecf20Sopenharmony_ci TMIOFB_ACC_FLGO, 4378c2ecf20Sopenharmony_ci }; 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci if (fbi->state != FBINFO_STATE_RUNNING || 4408c2ecf20Sopenharmony_ci fbi->flags & FBINFO_HWACCEL_DISABLED) { 4418c2ecf20Sopenharmony_ci cfb_fillrect(fbi, rect); 4428c2ecf20Sopenharmony_ci return; 4438c2ecf20Sopenharmony_ci } 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci tmiofb_acc_write(fbi, cmd, ARRAY_SIZE(cmd)); 4468c2ecf20Sopenharmony_ci} 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_cistatic void 4498c2ecf20Sopenharmony_citmiofb_copyarea(struct fb_info *fbi, const struct fb_copyarea *area) 4508c2ecf20Sopenharmony_ci{ 4518c2ecf20Sopenharmony_ci const u32 cmd[] = { 4528c2ecf20Sopenharmony_ci TMIOFB_ACC_DSADR((area->dy * fbi->mode->xres + area->dx) * 2), 4538c2ecf20Sopenharmony_ci TMIOFB_ACC_DHPIX(area->width - 1), 4548c2ecf20Sopenharmony_ci TMIOFB_ACC_DVPIX(area->height - 1), 4558c2ecf20Sopenharmony_ci TMIOFB_ACC_SSADR((area->sy * fbi->mode->xres + area->sx) * 2), 4568c2ecf20Sopenharmony_ci TMIOFB_ACC_SCGO, 4578c2ecf20Sopenharmony_ci }; 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci if (fbi->state != FBINFO_STATE_RUNNING || 4608c2ecf20Sopenharmony_ci fbi->flags & FBINFO_HWACCEL_DISABLED) { 4618c2ecf20Sopenharmony_ci cfb_copyarea(fbi, area); 4628c2ecf20Sopenharmony_ci return; 4638c2ecf20Sopenharmony_ci } 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci tmiofb_acc_write(fbi, cmd, ARRAY_SIZE(cmd)); 4668c2ecf20Sopenharmony_ci} 4678c2ecf20Sopenharmony_ci#endif 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_cistatic void tmiofb_clearscreen(struct fb_info *info) 4708c2ecf20Sopenharmony_ci{ 4718c2ecf20Sopenharmony_ci const struct fb_fillrect rect = { 4728c2ecf20Sopenharmony_ci .dx = 0, 4738c2ecf20Sopenharmony_ci .dy = 0, 4748c2ecf20Sopenharmony_ci .width = info->mode->xres, 4758c2ecf20Sopenharmony_ci .height = info->mode->yres, 4768c2ecf20Sopenharmony_ci .color = 0, 4778c2ecf20Sopenharmony_ci .rop = ROP_COPY, 4788c2ecf20Sopenharmony_ci }; 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_ci info->fbops->fb_fillrect(info, &rect); 4818c2ecf20Sopenharmony_ci} 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_cistatic int tmiofb_vblank(struct fb_info *fbi, struct fb_vblank *vblank) 4848c2ecf20Sopenharmony_ci{ 4858c2ecf20Sopenharmony_ci struct tmiofb_par *par = fbi->par; 4868c2ecf20Sopenharmony_ci struct fb_videomode *mode = fbi->mode; 4878c2ecf20Sopenharmony_ci unsigned int vcount = tmio_ioread16(par->lcr + LCR_CDLN); 4888c2ecf20Sopenharmony_ci unsigned int vds = mode->vsync_len + mode->upper_margin; 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci vblank->vcount = vcount; 4918c2ecf20Sopenharmony_ci vblank->flags = FB_VBLANK_HAVE_VBLANK | FB_VBLANK_HAVE_VCOUNT 4928c2ecf20Sopenharmony_ci | FB_VBLANK_HAVE_VSYNC; 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci if (vcount < mode->vsync_len) 4958c2ecf20Sopenharmony_ci vblank->flags |= FB_VBLANK_VSYNCING; 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci if (vcount < vds || vcount > vds + mode->yres) 4988c2ecf20Sopenharmony_ci vblank->flags |= FB_VBLANK_VBLANKING; 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_ci return 0; 5018c2ecf20Sopenharmony_ci} 5028c2ecf20Sopenharmony_ci 5038c2ecf20Sopenharmony_ci 5048c2ecf20Sopenharmony_cistatic int tmiofb_ioctl(struct fb_info *fbi, 5058c2ecf20Sopenharmony_ci unsigned int cmd, unsigned long arg) 5068c2ecf20Sopenharmony_ci{ 5078c2ecf20Sopenharmony_ci switch (cmd) { 5088c2ecf20Sopenharmony_ci case FBIOGET_VBLANK: { 5098c2ecf20Sopenharmony_ci struct fb_vblank vblank = {0}; 5108c2ecf20Sopenharmony_ci void __user *argp = (void __user *) arg; 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_ci tmiofb_vblank(fbi, &vblank); 5138c2ecf20Sopenharmony_ci if (copy_to_user(argp, &vblank, sizeof vblank)) 5148c2ecf20Sopenharmony_ci return -EFAULT; 5158c2ecf20Sopenharmony_ci return 0; 5168c2ecf20Sopenharmony_ci } 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_TMIO_ACCELL 5198c2ecf20Sopenharmony_ci case FBIO_TMIO_ACC_SYNC: 5208c2ecf20Sopenharmony_ci tmiofb_sync(fbi); 5218c2ecf20Sopenharmony_ci return 0; 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci case FBIO_TMIO_ACC_WRITE: { 5248c2ecf20Sopenharmony_ci u32 __user *argp = (void __user *) arg; 5258c2ecf20Sopenharmony_ci u32 len; 5268c2ecf20Sopenharmony_ci u32 acc[16]; 5278c2ecf20Sopenharmony_ci 5288c2ecf20Sopenharmony_ci if (get_user(len, argp)) 5298c2ecf20Sopenharmony_ci return -EFAULT; 5308c2ecf20Sopenharmony_ci if (len > ARRAY_SIZE(acc)) 5318c2ecf20Sopenharmony_ci return -EINVAL; 5328c2ecf20Sopenharmony_ci if (copy_from_user(acc, argp + 1, sizeof(u32) * len)) 5338c2ecf20Sopenharmony_ci return -EFAULT; 5348c2ecf20Sopenharmony_ci 5358c2ecf20Sopenharmony_ci return tmiofb_acc_write(fbi, acc, len); 5368c2ecf20Sopenharmony_ci } 5378c2ecf20Sopenharmony_ci#endif 5388c2ecf20Sopenharmony_ci } 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci return -ENOTTY; 5418c2ecf20Sopenharmony_ci} 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci/*--------------------------------------------------------------------------*/ 5448c2ecf20Sopenharmony_ci 5458c2ecf20Sopenharmony_ci/* Select the smallest mode that allows the desired resolution to be 5468c2ecf20Sopenharmony_ci * displayed. If desired, the x and y parameters can be rounded up to 5478c2ecf20Sopenharmony_ci * match the selected mode. 5488c2ecf20Sopenharmony_ci */ 5498c2ecf20Sopenharmony_cistatic struct fb_videomode * 5508c2ecf20Sopenharmony_citmiofb_find_mode(struct fb_info *info, struct fb_var_screeninfo *var) 5518c2ecf20Sopenharmony_ci{ 5528c2ecf20Sopenharmony_ci struct tmio_fb_data *data = dev_get_platdata(info->device); 5538c2ecf20Sopenharmony_ci struct fb_videomode *best = NULL; 5548c2ecf20Sopenharmony_ci int i; 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci for (i = 0; i < data->num_modes; i++) { 5578c2ecf20Sopenharmony_ci struct fb_videomode *mode = data->modes + i; 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci if (mode->xres >= var->xres && mode->yres >= var->yres 5608c2ecf20Sopenharmony_ci && (!best || (mode->xres < best->xres 5618c2ecf20Sopenharmony_ci && mode->yres < best->yres))) 5628c2ecf20Sopenharmony_ci best = mode; 5638c2ecf20Sopenharmony_ci } 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci return best; 5668c2ecf20Sopenharmony_ci} 5678c2ecf20Sopenharmony_ci 5688c2ecf20Sopenharmony_cistatic int tmiofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 5698c2ecf20Sopenharmony_ci{ 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_ci struct fb_videomode *mode; 5728c2ecf20Sopenharmony_ci struct tmio_fb_data *data = dev_get_platdata(info->device); 5738c2ecf20Sopenharmony_ci 5748c2ecf20Sopenharmony_ci mode = tmiofb_find_mode(info, var); 5758c2ecf20Sopenharmony_ci if (!mode || var->bits_per_pixel > 16) 5768c2ecf20Sopenharmony_ci return -EINVAL; 5778c2ecf20Sopenharmony_ci 5788c2ecf20Sopenharmony_ci fb_videomode_to_var(var, mode); 5798c2ecf20Sopenharmony_ci 5808c2ecf20Sopenharmony_ci var->xres_virtual = mode->xres; 5818c2ecf20Sopenharmony_ci var->yres_virtual = info->screen_size / (mode->xres * 2); 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_ci if (var->yres_virtual < var->yres) 5848c2ecf20Sopenharmony_ci return -EINVAL; 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci var->xoffset = 0; 5878c2ecf20Sopenharmony_ci var->yoffset = 0; 5888c2ecf20Sopenharmony_ci var->bits_per_pixel = 16; 5898c2ecf20Sopenharmony_ci var->grayscale = 0; 5908c2ecf20Sopenharmony_ci var->red.offset = 11; 5918c2ecf20Sopenharmony_ci var->red.length = 5; 5928c2ecf20Sopenharmony_ci var->green.offset = 5; 5938c2ecf20Sopenharmony_ci var->green.length = 6; 5948c2ecf20Sopenharmony_ci var->blue.offset = 0; 5958c2ecf20Sopenharmony_ci var->blue.length = 5; 5968c2ecf20Sopenharmony_ci var->transp.offset = 0; 5978c2ecf20Sopenharmony_ci var->transp.length = 0; 5988c2ecf20Sopenharmony_ci var->nonstd = 0; 5998c2ecf20Sopenharmony_ci var->height = data->height; /* mm */ 6008c2ecf20Sopenharmony_ci var->width = data->width; /* mm */ 6018c2ecf20Sopenharmony_ci var->rotate = 0; 6028c2ecf20Sopenharmony_ci return 0; 6038c2ecf20Sopenharmony_ci} 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_cistatic int tmiofb_set_par(struct fb_info *info) 6068c2ecf20Sopenharmony_ci{ 6078c2ecf20Sopenharmony_ci struct fb_var_screeninfo *var = &info->var; 6088c2ecf20Sopenharmony_ci struct fb_videomode *mode; 6098c2ecf20Sopenharmony_ci 6108c2ecf20Sopenharmony_ci mode = tmiofb_find_mode(info, var); 6118c2ecf20Sopenharmony_ci if (!mode) 6128c2ecf20Sopenharmony_ci return -EINVAL; 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_ci info->mode = mode; 6158c2ecf20Sopenharmony_ci info->fix.line_length = info->mode->xres * 6168c2ecf20Sopenharmony_ci var->bits_per_pixel / 8; 6178c2ecf20Sopenharmony_ci 6188c2ecf20Sopenharmony_ci tmiofb_hw_mode(to_platform_device(info->device)); 6198c2ecf20Sopenharmony_ci tmiofb_clearscreen(info); 6208c2ecf20Sopenharmony_ci return 0; 6218c2ecf20Sopenharmony_ci} 6228c2ecf20Sopenharmony_ci 6238c2ecf20Sopenharmony_cistatic int tmiofb_setcolreg(unsigned regno, unsigned red, unsigned green, 6248c2ecf20Sopenharmony_ci unsigned blue, unsigned transp, 6258c2ecf20Sopenharmony_ci struct fb_info *info) 6268c2ecf20Sopenharmony_ci{ 6278c2ecf20Sopenharmony_ci struct tmiofb_par *par = info->par; 6288c2ecf20Sopenharmony_ci 6298c2ecf20Sopenharmony_ci if (regno < ARRAY_SIZE(par->pseudo_palette)) { 6308c2ecf20Sopenharmony_ci par->pseudo_palette[regno] = 6318c2ecf20Sopenharmony_ci ((red & 0xf800)) | 6328c2ecf20Sopenharmony_ci ((green & 0xfc00) >> 5) | 6338c2ecf20Sopenharmony_ci ((blue & 0xf800) >> 11); 6348c2ecf20Sopenharmony_ci return 0; 6358c2ecf20Sopenharmony_ci } 6368c2ecf20Sopenharmony_ci 6378c2ecf20Sopenharmony_ci return -EINVAL; 6388c2ecf20Sopenharmony_ci} 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_cistatic int tmiofb_blank(int blank, struct fb_info *info) 6418c2ecf20Sopenharmony_ci{ 6428c2ecf20Sopenharmony_ci /* 6438c2ecf20Sopenharmony_ci * everything is done in lcd/bl drivers. 6448c2ecf20Sopenharmony_ci * this is purely to make sysfs happy and work. 6458c2ecf20Sopenharmony_ci */ 6468c2ecf20Sopenharmony_ci return 0; 6478c2ecf20Sopenharmony_ci} 6488c2ecf20Sopenharmony_ci 6498c2ecf20Sopenharmony_cistatic const struct fb_ops tmiofb_ops = { 6508c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 6518c2ecf20Sopenharmony_ci 6528c2ecf20Sopenharmony_ci .fb_ioctl = tmiofb_ioctl, 6538c2ecf20Sopenharmony_ci .fb_check_var = tmiofb_check_var, 6548c2ecf20Sopenharmony_ci .fb_set_par = tmiofb_set_par, 6558c2ecf20Sopenharmony_ci .fb_setcolreg = tmiofb_setcolreg, 6568c2ecf20Sopenharmony_ci .fb_blank = tmiofb_blank, 6578c2ecf20Sopenharmony_ci .fb_imageblit = cfb_imageblit, 6588c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_TMIO_ACCELL 6598c2ecf20Sopenharmony_ci .fb_sync = tmiofb_sync, 6608c2ecf20Sopenharmony_ci .fb_fillrect = tmiofb_fillrect, 6618c2ecf20Sopenharmony_ci .fb_copyarea = tmiofb_copyarea, 6628c2ecf20Sopenharmony_ci#else 6638c2ecf20Sopenharmony_ci .fb_fillrect = cfb_fillrect, 6648c2ecf20Sopenharmony_ci .fb_copyarea = cfb_copyarea, 6658c2ecf20Sopenharmony_ci#endif 6668c2ecf20Sopenharmony_ci}; 6678c2ecf20Sopenharmony_ci 6688c2ecf20Sopenharmony_ci/*--------------------------------------------------------------------------*/ 6698c2ecf20Sopenharmony_ci 6708c2ecf20Sopenharmony_cistatic int tmiofb_probe(struct platform_device *dev) 6718c2ecf20Sopenharmony_ci{ 6728c2ecf20Sopenharmony_ci const struct mfd_cell *cell = mfd_get_cell(dev); 6738c2ecf20Sopenharmony_ci struct tmio_fb_data *data = dev_get_platdata(&dev->dev); 6748c2ecf20Sopenharmony_ci struct resource *ccr = platform_get_resource(dev, IORESOURCE_MEM, 1); 6758c2ecf20Sopenharmony_ci struct resource *lcr = platform_get_resource(dev, IORESOURCE_MEM, 0); 6768c2ecf20Sopenharmony_ci struct resource *vram = platform_get_resource(dev, IORESOURCE_MEM, 2); 6778c2ecf20Sopenharmony_ci int irq = platform_get_irq(dev, 0); 6788c2ecf20Sopenharmony_ci struct fb_info *info; 6798c2ecf20Sopenharmony_ci struct tmiofb_par *par; 6808c2ecf20Sopenharmony_ci int retval; 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci /* 6838c2ecf20Sopenharmony_ci * This is the only way ATM to disable the fb 6848c2ecf20Sopenharmony_ci */ 6858c2ecf20Sopenharmony_ci if (data == NULL) { 6868c2ecf20Sopenharmony_ci dev_err(&dev->dev, "NULL platform data!\n"); 6878c2ecf20Sopenharmony_ci return -EINVAL; 6888c2ecf20Sopenharmony_ci } 6898c2ecf20Sopenharmony_ci if (ccr == NULL || lcr == NULL || vram == NULL || irq < 0) { 6908c2ecf20Sopenharmony_ci dev_err(&dev->dev, "missing resources\n"); 6918c2ecf20Sopenharmony_ci return -EINVAL; 6928c2ecf20Sopenharmony_ci } 6938c2ecf20Sopenharmony_ci 6948c2ecf20Sopenharmony_ci info = framebuffer_alloc(sizeof(struct tmiofb_par), &dev->dev); 6958c2ecf20Sopenharmony_ci 6968c2ecf20Sopenharmony_ci if (!info) 6978c2ecf20Sopenharmony_ci return -ENOMEM; 6988c2ecf20Sopenharmony_ci 6998c2ecf20Sopenharmony_ci par = info->par; 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_TMIO_ACCELL 7028c2ecf20Sopenharmony_ci init_waitqueue_head(&par->wait_acc); 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_ci par->use_polling = true; 7058c2ecf20Sopenharmony_ci 7068c2ecf20Sopenharmony_ci info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA 7078c2ecf20Sopenharmony_ci | FBINFO_HWACCEL_FILLRECT; 7088c2ecf20Sopenharmony_ci#else 7098c2ecf20Sopenharmony_ci info->flags = FBINFO_DEFAULT; 7108c2ecf20Sopenharmony_ci#endif 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_ci info->fbops = &tmiofb_ops; 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ci strcpy(info->fix.id, "tmio-fb"); 7158c2ecf20Sopenharmony_ci info->fix.smem_start = vram->start; 7168c2ecf20Sopenharmony_ci info->fix.smem_len = resource_size(vram); 7178c2ecf20Sopenharmony_ci info->fix.type = FB_TYPE_PACKED_PIXELS; 7188c2ecf20Sopenharmony_ci info->fix.visual = FB_VISUAL_TRUECOLOR; 7198c2ecf20Sopenharmony_ci info->fix.mmio_start = lcr->start; 7208c2ecf20Sopenharmony_ci info->fix.mmio_len = resource_size(lcr); 7218c2ecf20Sopenharmony_ci info->fix.accel = FB_ACCEL_NONE; 7228c2ecf20Sopenharmony_ci info->screen_size = info->fix.smem_len - (4 * TMIOFB_FIFO_SIZE); 7238c2ecf20Sopenharmony_ci info->pseudo_palette = par->pseudo_palette; 7248c2ecf20Sopenharmony_ci 7258c2ecf20Sopenharmony_ci par->ccr = ioremap(ccr->start, resource_size(ccr)); 7268c2ecf20Sopenharmony_ci if (!par->ccr) { 7278c2ecf20Sopenharmony_ci retval = -ENOMEM; 7288c2ecf20Sopenharmony_ci goto err_ioremap_ccr; 7298c2ecf20Sopenharmony_ci } 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_ci par->lcr = ioremap(info->fix.mmio_start, info->fix.mmio_len); 7328c2ecf20Sopenharmony_ci if (!par->lcr) { 7338c2ecf20Sopenharmony_ci retval = -ENOMEM; 7348c2ecf20Sopenharmony_ci goto err_ioremap_lcr; 7358c2ecf20Sopenharmony_ci } 7368c2ecf20Sopenharmony_ci 7378c2ecf20Sopenharmony_ci info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len); 7388c2ecf20Sopenharmony_ci if (!info->screen_base) { 7398c2ecf20Sopenharmony_ci retval = -ENOMEM; 7408c2ecf20Sopenharmony_ci goto err_ioremap_vram; 7418c2ecf20Sopenharmony_ci } 7428c2ecf20Sopenharmony_ci 7438c2ecf20Sopenharmony_ci retval = request_irq(irq, &tmiofb_irq, 0, 7448c2ecf20Sopenharmony_ci dev_name(&dev->dev), info); 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci if (retval) 7478c2ecf20Sopenharmony_ci goto err_request_irq; 7488c2ecf20Sopenharmony_ci 7498c2ecf20Sopenharmony_ci platform_set_drvdata(dev, info); 7508c2ecf20Sopenharmony_ci 7518c2ecf20Sopenharmony_ci retval = fb_find_mode(&info->var, info, mode_option, 7528c2ecf20Sopenharmony_ci data->modes, data->num_modes, 7538c2ecf20Sopenharmony_ci data->modes, 16); 7548c2ecf20Sopenharmony_ci if (!retval) { 7558c2ecf20Sopenharmony_ci retval = -EINVAL; 7568c2ecf20Sopenharmony_ci goto err_find_mode; 7578c2ecf20Sopenharmony_ci } 7588c2ecf20Sopenharmony_ci 7598c2ecf20Sopenharmony_ci if (cell->enable) { 7608c2ecf20Sopenharmony_ci retval = cell->enable(dev); 7618c2ecf20Sopenharmony_ci if (retval) 7628c2ecf20Sopenharmony_ci goto err_enable; 7638c2ecf20Sopenharmony_ci } 7648c2ecf20Sopenharmony_ci 7658c2ecf20Sopenharmony_ci retval = tmiofb_hw_init(dev); 7668c2ecf20Sopenharmony_ci if (retval) 7678c2ecf20Sopenharmony_ci goto err_hw_init; 7688c2ecf20Sopenharmony_ci 7698c2ecf20Sopenharmony_ci fb_videomode_to_modelist(data->modes, data->num_modes, 7708c2ecf20Sopenharmony_ci &info->modelist); 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci retval = register_framebuffer(info); 7738c2ecf20Sopenharmony_ci if (retval < 0) 7748c2ecf20Sopenharmony_ci goto err_register_framebuffer; 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_ci fb_info(info, "%s frame buffer device\n", info->fix.id); 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_ci return 0; 7798c2ecf20Sopenharmony_ci 7808c2ecf20Sopenharmony_cierr_register_framebuffer: 7818c2ecf20Sopenharmony_ci/*err_set_par:*/ 7828c2ecf20Sopenharmony_ci tmiofb_hw_stop(dev); 7838c2ecf20Sopenharmony_cierr_hw_init: 7848c2ecf20Sopenharmony_ci if (cell->disable) 7858c2ecf20Sopenharmony_ci cell->disable(dev); 7868c2ecf20Sopenharmony_cierr_enable: 7878c2ecf20Sopenharmony_cierr_find_mode: 7888c2ecf20Sopenharmony_ci free_irq(irq, info); 7898c2ecf20Sopenharmony_cierr_request_irq: 7908c2ecf20Sopenharmony_ci iounmap(info->screen_base); 7918c2ecf20Sopenharmony_cierr_ioremap_vram: 7928c2ecf20Sopenharmony_ci iounmap(par->lcr); 7938c2ecf20Sopenharmony_cierr_ioremap_lcr: 7948c2ecf20Sopenharmony_ci iounmap(par->ccr); 7958c2ecf20Sopenharmony_cierr_ioremap_ccr: 7968c2ecf20Sopenharmony_ci framebuffer_release(info); 7978c2ecf20Sopenharmony_ci return retval; 7988c2ecf20Sopenharmony_ci} 7998c2ecf20Sopenharmony_ci 8008c2ecf20Sopenharmony_cistatic int tmiofb_remove(struct platform_device *dev) 8018c2ecf20Sopenharmony_ci{ 8028c2ecf20Sopenharmony_ci const struct mfd_cell *cell = mfd_get_cell(dev); 8038c2ecf20Sopenharmony_ci struct fb_info *info = platform_get_drvdata(dev); 8048c2ecf20Sopenharmony_ci int irq = platform_get_irq(dev, 0); 8058c2ecf20Sopenharmony_ci struct tmiofb_par *par; 8068c2ecf20Sopenharmony_ci 8078c2ecf20Sopenharmony_ci if (info) { 8088c2ecf20Sopenharmony_ci par = info->par; 8098c2ecf20Sopenharmony_ci unregister_framebuffer(info); 8108c2ecf20Sopenharmony_ci 8118c2ecf20Sopenharmony_ci tmiofb_hw_stop(dev); 8128c2ecf20Sopenharmony_ci 8138c2ecf20Sopenharmony_ci if (cell->disable) 8148c2ecf20Sopenharmony_ci cell->disable(dev); 8158c2ecf20Sopenharmony_ci 8168c2ecf20Sopenharmony_ci free_irq(irq, info); 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_ci iounmap(info->screen_base); 8198c2ecf20Sopenharmony_ci iounmap(par->lcr); 8208c2ecf20Sopenharmony_ci iounmap(par->ccr); 8218c2ecf20Sopenharmony_ci 8228c2ecf20Sopenharmony_ci framebuffer_release(info); 8238c2ecf20Sopenharmony_ci } 8248c2ecf20Sopenharmony_ci 8258c2ecf20Sopenharmony_ci return 0; 8268c2ecf20Sopenharmony_ci} 8278c2ecf20Sopenharmony_ci 8288c2ecf20Sopenharmony_ci#ifdef DEBUG 8298c2ecf20Sopenharmony_cistatic void tmiofb_dump_regs(struct platform_device *dev) 8308c2ecf20Sopenharmony_ci{ 8318c2ecf20Sopenharmony_ci struct fb_info *info = platform_get_drvdata(dev); 8328c2ecf20Sopenharmony_ci struct tmiofb_par *par = info->par; 8338c2ecf20Sopenharmony_ci 8348c2ecf20Sopenharmony_ci printk(KERN_DEBUG "lhccr:\n"); 8358c2ecf20Sopenharmony_ci#define CCR_PR(n) printk(KERN_DEBUG "\t" #n " = \t%04x\n",\ 8368c2ecf20Sopenharmony_ci tmio_ioread16(par->ccr + CCR_ ## n)); 8378c2ecf20Sopenharmony_ci CCR_PR(CMD); 8388c2ecf20Sopenharmony_ci CCR_PR(REVID); 8398c2ecf20Sopenharmony_ci CCR_PR(BASEL); 8408c2ecf20Sopenharmony_ci CCR_PR(BASEH); 8418c2ecf20Sopenharmony_ci CCR_PR(UGCC); 8428c2ecf20Sopenharmony_ci CCR_PR(GCC); 8438c2ecf20Sopenharmony_ci CCR_PR(USC); 8448c2ecf20Sopenharmony_ci CCR_PR(VRAMRTC); 8458c2ecf20Sopenharmony_ci CCR_PR(VRAMSAC); 8468c2ecf20Sopenharmony_ci CCR_PR(VRAMBC); 8478c2ecf20Sopenharmony_ci#undef CCR_PR 8488c2ecf20Sopenharmony_ci 8498c2ecf20Sopenharmony_ci printk(KERN_DEBUG "lcr: \n"); 8508c2ecf20Sopenharmony_ci#define LCR_PR(n) printk(KERN_DEBUG "\t" #n " = \t%04x\n",\ 8518c2ecf20Sopenharmony_ci tmio_ioread16(par->lcr + LCR_ ## n)); 8528c2ecf20Sopenharmony_ci LCR_PR(UIS); 8538c2ecf20Sopenharmony_ci LCR_PR(VHPN); 8548c2ecf20Sopenharmony_ci LCR_PR(CFSAL); 8558c2ecf20Sopenharmony_ci LCR_PR(CFSAH); 8568c2ecf20Sopenharmony_ci LCR_PR(CFS); 8578c2ecf20Sopenharmony_ci LCR_PR(CFWS); 8588c2ecf20Sopenharmony_ci LCR_PR(BBIE); 8598c2ecf20Sopenharmony_ci LCR_PR(BBISC); 8608c2ecf20Sopenharmony_ci LCR_PR(CCS); 8618c2ecf20Sopenharmony_ci LCR_PR(BBES); 8628c2ecf20Sopenharmony_ci LCR_PR(CMDL); 8638c2ecf20Sopenharmony_ci LCR_PR(CMDH); 8648c2ecf20Sopenharmony_ci LCR_PR(CFC); 8658c2ecf20Sopenharmony_ci LCR_PR(CCIFC); 8668c2ecf20Sopenharmony_ci LCR_PR(HWT); 8678c2ecf20Sopenharmony_ci LCR_PR(LCDCCRC); 8688c2ecf20Sopenharmony_ci LCR_PR(LCDCC); 8698c2ecf20Sopenharmony_ci LCR_PR(LCDCOPC); 8708c2ecf20Sopenharmony_ci LCR_PR(LCDIS); 8718c2ecf20Sopenharmony_ci LCR_PR(LCDIM); 8728c2ecf20Sopenharmony_ci LCR_PR(LCDIE); 8738c2ecf20Sopenharmony_ci LCR_PR(GDSAL); 8748c2ecf20Sopenharmony_ci LCR_PR(GDSAH); 8758c2ecf20Sopenharmony_ci LCR_PR(VHPCL); 8768c2ecf20Sopenharmony_ci LCR_PR(VHPCH); 8778c2ecf20Sopenharmony_ci LCR_PR(GM); 8788c2ecf20Sopenharmony_ci LCR_PR(HT); 8798c2ecf20Sopenharmony_ci LCR_PR(HDS); 8808c2ecf20Sopenharmony_ci LCR_PR(HSS); 8818c2ecf20Sopenharmony_ci LCR_PR(HSE); 8828c2ecf20Sopenharmony_ci LCR_PR(HNP); 8838c2ecf20Sopenharmony_ci LCR_PR(VT); 8848c2ecf20Sopenharmony_ci LCR_PR(VDS); 8858c2ecf20Sopenharmony_ci LCR_PR(VSS); 8868c2ecf20Sopenharmony_ci LCR_PR(VSE); 8878c2ecf20Sopenharmony_ci LCR_PR(CDLN); 8888c2ecf20Sopenharmony_ci LCR_PR(ILN); 8898c2ecf20Sopenharmony_ci LCR_PR(SP); 8908c2ecf20Sopenharmony_ci LCR_PR(MISC); 8918c2ecf20Sopenharmony_ci LCR_PR(VIHSS); 8928c2ecf20Sopenharmony_ci LCR_PR(VIVS); 8938c2ecf20Sopenharmony_ci LCR_PR(VIVE); 8948c2ecf20Sopenharmony_ci LCR_PR(VIVSS); 8958c2ecf20Sopenharmony_ci LCR_PR(VCCIS); 8968c2ecf20Sopenharmony_ci LCR_PR(VIDWSAL); 8978c2ecf20Sopenharmony_ci LCR_PR(VIDWSAH); 8988c2ecf20Sopenharmony_ci LCR_PR(VIDRSAL); 8998c2ecf20Sopenharmony_ci LCR_PR(VIDRSAH); 9008c2ecf20Sopenharmony_ci LCR_PR(VIPDDST); 9018c2ecf20Sopenharmony_ci LCR_PR(VIPDDET); 9028c2ecf20Sopenharmony_ci LCR_PR(VIE); 9038c2ecf20Sopenharmony_ci LCR_PR(VCS); 9048c2ecf20Sopenharmony_ci LCR_PR(VPHWC); 9058c2ecf20Sopenharmony_ci LCR_PR(VPHS); 9068c2ecf20Sopenharmony_ci LCR_PR(VPVWC); 9078c2ecf20Sopenharmony_ci LCR_PR(VPVS); 9088c2ecf20Sopenharmony_ci LCR_PR(PLHPIX); 9098c2ecf20Sopenharmony_ci LCR_PR(XS); 9108c2ecf20Sopenharmony_ci LCR_PR(XCKHW); 9118c2ecf20Sopenharmony_ci LCR_PR(STHS); 9128c2ecf20Sopenharmony_ci LCR_PR(VT2); 9138c2ecf20Sopenharmony_ci LCR_PR(YCKSW); 9148c2ecf20Sopenharmony_ci LCR_PR(YSTS); 9158c2ecf20Sopenharmony_ci LCR_PR(PPOLS); 9168c2ecf20Sopenharmony_ci LCR_PR(PRECW); 9178c2ecf20Sopenharmony_ci LCR_PR(VCLKHW); 9188c2ecf20Sopenharmony_ci LCR_PR(OC); 9198c2ecf20Sopenharmony_ci#undef LCR_PR 9208c2ecf20Sopenharmony_ci} 9218c2ecf20Sopenharmony_ci#endif 9228c2ecf20Sopenharmony_ci 9238c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 9248c2ecf20Sopenharmony_cistatic int tmiofb_suspend(struct platform_device *dev, pm_message_t state) 9258c2ecf20Sopenharmony_ci{ 9268c2ecf20Sopenharmony_ci struct fb_info *info = platform_get_drvdata(dev); 9278c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_TMIO_ACCELL 9288c2ecf20Sopenharmony_ci struct tmiofb_par *par = info->par; 9298c2ecf20Sopenharmony_ci#endif 9308c2ecf20Sopenharmony_ci const struct mfd_cell *cell = mfd_get_cell(dev); 9318c2ecf20Sopenharmony_ci int retval = 0; 9328c2ecf20Sopenharmony_ci 9338c2ecf20Sopenharmony_ci console_lock(); 9348c2ecf20Sopenharmony_ci 9358c2ecf20Sopenharmony_ci fb_set_suspend(info, 1); 9368c2ecf20Sopenharmony_ci 9378c2ecf20Sopenharmony_ci if (info->fbops->fb_sync) 9388c2ecf20Sopenharmony_ci info->fbops->fb_sync(info); 9398c2ecf20Sopenharmony_ci 9408c2ecf20Sopenharmony_ci 9418c2ecf20Sopenharmony_ci#ifdef CONFIG_FB_TMIO_ACCELL 9428c2ecf20Sopenharmony_ci /* 9438c2ecf20Sopenharmony_ci * The fb should be usable even if interrupts are disabled (and they are 9448c2ecf20Sopenharmony_ci * during suspend/resume). Switch temporary to forced polling. 9458c2ecf20Sopenharmony_ci */ 9468c2ecf20Sopenharmony_ci printk(KERN_INFO "tmiofb: switching to polling\n"); 9478c2ecf20Sopenharmony_ci par->use_polling = true; 9488c2ecf20Sopenharmony_ci#endif 9498c2ecf20Sopenharmony_ci tmiofb_hw_stop(dev); 9508c2ecf20Sopenharmony_ci 9518c2ecf20Sopenharmony_ci if (cell->suspend) 9528c2ecf20Sopenharmony_ci retval = cell->suspend(dev); 9538c2ecf20Sopenharmony_ci 9548c2ecf20Sopenharmony_ci console_unlock(); 9558c2ecf20Sopenharmony_ci 9568c2ecf20Sopenharmony_ci return retval; 9578c2ecf20Sopenharmony_ci} 9588c2ecf20Sopenharmony_ci 9598c2ecf20Sopenharmony_cistatic int tmiofb_resume(struct platform_device *dev) 9608c2ecf20Sopenharmony_ci{ 9618c2ecf20Sopenharmony_ci struct fb_info *info = platform_get_drvdata(dev); 9628c2ecf20Sopenharmony_ci const struct mfd_cell *cell = mfd_get_cell(dev); 9638c2ecf20Sopenharmony_ci int retval = 0; 9648c2ecf20Sopenharmony_ci 9658c2ecf20Sopenharmony_ci console_lock(); 9668c2ecf20Sopenharmony_ci 9678c2ecf20Sopenharmony_ci if (cell->resume) { 9688c2ecf20Sopenharmony_ci retval = cell->resume(dev); 9698c2ecf20Sopenharmony_ci if (retval) 9708c2ecf20Sopenharmony_ci goto out; 9718c2ecf20Sopenharmony_ci } 9728c2ecf20Sopenharmony_ci 9738c2ecf20Sopenharmony_ci tmiofb_irq(-1, info); 9748c2ecf20Sopenharmony_ci 9758c2ecf20Sopenharmony_ci tmiofb_hw_init(dev); 9768c2ecf20Sopenharmony_ci 9778c2ecf20Sopenharmony_ci tmiofb_hw_mode(dev); 9788c2ecf20Sopenharmony_ci 9798c2ecf20Sopenharmony_ci fb_set_suspend(info, 0); 9808c2ecf20Sopenharmony_ciout: 9818c2ecf20Sopenharmony_ci console_unlock(); 9828c2ecf20Sopenharmony_ci return retval; 9838c2ecf20Sopenharmony_ci} 9848c2ecf20Sopenharmony_ci#else 9858c2ecf20Sopenharmony_ci#define tmiofb_suspend NULL 9868c2ecf20Sopenharmony_ci#define tmiofb_resume NULL 9878c2ecf20Sopenharmony_ci#endif 9888c2ecf20Sopenharmony_ci 9898c2ecf20Sopenharmony_cistatic struct platform_driver tmiofb_driver = { 9908c2ecf20Sopenharmony_ci .driver.name = "tmio-fb", 9918c2ecf20Sopenharmony_ci .driver.owner = THIS_MODULE, 9928c2ecf20Sopenharmony_ci .probe = tmiofb_probe, 9938c2ecf20Sopenharmony_ci .remove = tmiofb_remove, 9948c2ecf20Sopenharmony_ci .suspend = tmiofb_suspend, 9958c2ecf20Sopenharmony_ci .resume = tmiofb_resume, 9968c2ecf20Sopenharmony_ci}; 9978c2ecf20Sopenharmony_ci 9988c2ecf20Sopenharmony_ci/*--------------------------------------------------------------------------*/ 9998c2ecf20Sopenharmony_ci 10008c2ecf20Sopenharmony_ci#ifndef MODULE 10018c2ecf20Sopenharmony_cistatic void __init tmiofb_setup(char *options) 10028c2ecf20Sopenharmony_ci{ 10038c2ecf20Sopenharmony_ci char *this_opt; 10048c2ecf20Sopenharmony_ci 10058c2ecf20Sopenharmony_ci if (!options || !*options) 10068c2ecf20Sopenharmony_ci return; 10078c2ecf20Sopenharmony_ci 10088c2ecf20Sopenharmony_ci while ((this_opt = strsep(&options, ",")) != NULL) { 10098c2ecf20Sopenharmony_ci if (!*this_opt) 10108c2ecf20Sopenharmony_ci continue; 10118c2ecf20Sopenharmony_ci /* 10128c2ecf20Sopenharmony_ci * FIXME 10138c2ecf20Sopenharmony_ci */ 10148c2ecf20Sopenharmony_ci } 10158c2ecf20Sopenharmony_ci} 10168c2ecf20Sopenharmony_ci#endif 10178c2ecf20Sopenharmony_ci 10188c2ecf20Sopenharmony_cistatic int __init tmiofb_init(void) 10198c2ecf20Sopenharmony_ci{ 10208c2ecf20Sopenharmony_ci#ifndef MODULE 10218c2ecf20Sopenharmony_ci char *option = NULL; 10228c2ecf20Sopenharmony_ci 10238c2ecf20Sopenharmony_ci if (fb_get_options("tmiofb", &option)) 10248c2ecf20Sopenharmony_ci return -ENODEV; 10258c2ecf20Sopenharmony_ci tmiofb_setup(option); 10268c2ecf20Sopenharmony_ci#endif 10278c2ecf20Sopenharmony_ci return platform_driver_register(&tmiofb_driver); 10288c2ecf20Sopenharmony_ci} 10298c2ecf20Sopenharmony_ci 10308c2ecf20Sopenharmony_cistatic void __exit tmiofb_cleanup(void) 10318c2ecf20Sopenharmony_ci{ 10328c2ecf20Sopenharmony_ci platform_driver_unregister(&tmiofb_driver); 10338c2ecf20Sopenharmony_ci} 10348c2ecf20Sopenharmony_ci 10358c2ecf20Sopenharmony_cimodule_init(tmiofb_init); 10368c2ecf20Sopenharmony_cimodule_exit(tmiofb_cleanup); 10378c2ecf20Sopenharmony_ci 10388c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("TMIO framebuffer driver"); 10398c2ecf20Sopenharmony_ciMODULE_AUTHOR("Chris Humbert, Dirk Opfer, Dmitry Baryshkov"); 10408c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 1041