18c2ecf20Sopenharmony_ci/* drivers/video/s1d13xxxfb.c 28c2ecf20Sopenharmony_ci * 38c2ecf20Sopenharmony_ci * (c) 2004 Simtec Electronics 48c2ecf20Sopenharmony_ci * (c) 2005 Thibaut VARENE <varenet@parisc-linux.org> 58c2ecf20Sopenharmony_ci * (c) 2009 Kristoffer Ericson <kristoffer.ericson@gmail.com> 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Driver for Epson S1D13xxx series framebuffer chips 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Adapted from 108c2ecf20Sopenharmony_ci * linux/drivers/video/skeletonfb.c 118c2ecf20Sopenharmony_ci * linux/drivers/video/epson1355fb.c 128c2ecf20Sopenharmony_ci * linux/drivers/video/epson/s1d13xxxfb.c (2.4 driver by Epson) 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * TODO: - handle dual screen display (CRT and LCD at the same time). 158c2ecf20Sopenharmony_ci * - check_var(), mode change, etc. 168c2ecf20Sopenharmony_ci * - probably not SMP safe :) 178c2ecf20Sopenharmony_ci * - support all bitblt operations on all cards 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 208c2ecf20Sopenharmony_ci * License. See the file COPYING in the main directory of this archive for 218c2ecf20Sopenharmony_ci * more details. 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#include <linux/module.h> 258c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 268c2ecf20Sopenharmony_ci#include <linux/delay.h> 278c2ecf20Sopenharmony_ci#include <linux/types.h> 288c2ecf20Sopenharmony_ci#include <linux/errno.h> 298c2ecf20Sopenharmony_ci#include <linux/mm.h> 308c2ecf20Sopenharmony_ci#include <linux/mman.h> 318c2ecf20Sopenharmony_ci#include <linux/fb.h> 328c2ecf20Sopenharmony_ci#include <linux/spinlock_types.h> 338c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 348c2ecf20Sopenharmony_ci#include <linux/slab.h> 358c2ecf20Sopenharmony_ci#include <linux/io.h> 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#include <video/s1d13xxxfb.h> 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define PFX "s1d13xxxfb: " 408c2ecf20Sopenharmony_ci#define BLIT "s1d13xxxfb_bitblt: " 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/* 438c2ecf20Sopenharmony_ci * set this to enable debugging on general functions 448c2ecf20Sopenharmony_ci */ 458c2ecf20Sopenharmony_ci#if 0 468c2ecf20Sopenharmony_ci#define dbg(fmt, args...) do { printk(KERN_INFO fmt, ## args); } while(0) 478c2ecf20Sopenharmony_ci#else 488c2ecf20Sopenharmony_ci#define dbg(fmt, args...) do { } while (0) 498c2ecf20Sopenharmony_ci#endif 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci/* 528c2ecf20Sopenharmony_ci * set this to enable debugging on 2D acceleration 538c2ecf20Sopenharmony_ci */ 548c2ecf20Sopenharmony_ci#if 0 558c2ecf20Sopenharmony_ci#define dbg_blit(fmt, args...) do { printk(KERN_INFO BLIT fmt, ## args); } while (0) 568c2ecf20Sopenharmony_ci#else 578c2ecf20Sopenharmony_ci#define dbg_blit(fmt, args...) do { } while (0) 588c2ecf20Sopenharmony_ci#endif 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* 618c2ecf20Sopenharmony_ci * we make sure only one bitblt operation is running 628c2ecf20Sopenharmony_ci */ 638c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(s1d13xxxfb_bitblt_lock); 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci/* 668c2ecf20Sopenharmony_ci * list of card production ids 678c2ecf20Sopenharmony_ci */ 688c2ecf20Sopenharmony_cistatic const int s1d13xxxfb_prod_ids[] = { 698c2ecf20Sopenharmony_ci S1D13505_PROD_ID, 708c2ecf20Sopenharmony_ci S1D13506_PROD_ID, 718c2ecf20Sopenharmony_ci S1D13806_PROD_ID, 728c2ecf20Sopenharmony_ci}; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci/* 758c2ecf20Sopenharmony_ci * List of card strings 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_cistatic const char *s1d13xxxfb_prod_names[] = { 788c2ecf20Sopenharmony_ci "S1D13505", 798c2ecf20Sopenharmony_ci "S1D13506", 808c2ecf20Sopenharmony_ci "S1D13806", 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci/* 848c2ecf20Sopenharmony_ci * here we define the default struct fb_fix_screeninfo 858c2ecf20Sopenharmony_ci */ 868c2ecf20Sopenharmony_cistatic const struct fb_fix_screeninfo s1d13xxxfb_fix = { 878c2ecf20Sopenharmony_ci .id = S1D_FBID, 888c2ecf20Sopenharmony_ci .type = FB_TYPE_PACKED_PIXELS, 898c2ecf20Sopenharmony_ci .visual = FB_VISUAL_PSEUDOCOLOR, 908c2ecf20Sopenharmony_ci .xpanstep = 0, 918c2ecf20Sopenharmony_ci .ypanstep = 1, 928c2ecf20Sopenharmony_ci .ywrapstep = 0, 938c2ecf20Sopenharmony_ci .accel = FB_ACCEL_NONE, 948c2ecf20Sopenharmony_ci}; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cistatic inline u8 978c2ecf20Sopenharmony_cis1d13xxxfb_readreg(struct s1d13xxxfb_par *par, u16 regno) 988c2ecf20Sopenharmony_ci{ 998c2ecf20Sopenharmony_ci return readb(par->regs + regno); 1008c2ecf20Sopenharmony_ci} 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cistatic inline void 1038c2ecf20Sopenharmony_cis1d13xxxfb_writereg(struct s1d13xxxfb_par *par, u16 regno, u8 value) 1048c2ecf20Sopenharmony_ci{ 1058c2ecf20Sopenharmony_ci writeb(value, par->regs + regno); 1068c2ecf20Sopenharmony_ci} 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistatic inline void 1098c2ecf20Sopenharmony_cis1d13xxxfb_runinit(struct s1d13xxxfb_par *par, 1108c2ecf20Sopenharmony_ci const struct s1d13xxxfb_regval *initregs, 1118c2ecf20Sopenharmony_ci const unsigned int size) 1128c2ecf20Sopenharmony_ci{ 1138c2ecf20Sopenharmony_ci int i; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci for (i = 0; i < size; i++) { 1168c2ecf20Sopenharmony_ci if ((initregs[i].addr == S1DREG_DELAYOFF) || 1178c2ecf20Sopenharmony_ci (initregs[i].addr == S1DREG_DELAYON)) 1188c2ecf20Sopenharmony_ci mdelay((int)initregs[i].value); 1198c2ecf20Sopenharmony_ci else { 1208c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(par, initregs[i].addr, initregs[i].value); 1218c2ecf20Sopenharmony_ci } 1228c2ecf20Sopenharmony_ci } 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci /* make sure the hardware can cope with us */ 1258c2ecf20Sopenharmony_ci mdelay(1); 1268c2ecf20Sopenharmony_ci} 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cistatic inline void 1298c2ecf20Sopenharmony_cilcd_enable(struct s1d13xxxfb_par *par, int enable) 1308c2ecf20Sopenharmony_ci{ 1318c2ecf20Sopenharmony_ci u8 mode = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE); 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci if (enable) 1348c2ecf20Sopenharmony_ci mode |= 0x01; 1358c2ecf20Sopenharmony_ci else 1368c2ecf20Sopenharmony_ci mode &= ~0x01; 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, mode); 1398c2ecf20Sopenharmony_ci} 1408c2ecf20Sopenharmony_ci 1418c2ecf20Sopenharmony_cistatic inline void 1428c2ecf20Sopenharmony_cicrt_enable(struct s1d13xxxfb_par *par, int enable) 1438c2ecf20Sopenharmony_ci{ 1448c2ecf20Sopenharmony_ci u8 mode = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE); 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci if (enable) 1478c2ecf20Sopenharmony_ci mode |= 0x02; 1488c2ecf20Sopenharmony_ci else 1498c2ecf20Sopenharmony_ci mode &= ~0x02; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, mode); 1528c2ecf20Sopenharmony_ci} 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci/************************************************************* 1568c2ecf20Sopenharmony_ci framebuffer control functions 1578c2ecf20Sopenharmony_ci *************************************************************/ 1588c2ecf20Sopenharmony_cistatic inline void 1598c2ecf20Sopenharmony_cis1d13xxxfb_setup_pseudocolour(struct fb_info *info) 1608c2ecf20Sopenharmony_ci{ 1618c2ecf20Sopenharmony_ci info->fix.visual = FB_VISUAL_PSEUDOCOLOR; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci info->var.red.length = 4; 1648c2ecf20Sopenharmony_ci info->var.green.length = 4; 1658c2ecf20Sopenharmony_ci info->var.blue.length = 4; 1668c2ecf20Sopenharmony_ci} 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_cistatic inline void 1698c2ecf20Sopenharmony_cis1d13xxxfb_setup_truecolour(struct fb_info *info) 1708c2ecf20Sopenharmony_ci{ 1718c2ecf20Sopenharmony_ci info->fix.visual = FB_VISUAL_TRUECOLOR; 1728c2ecf20Sopenharmony_ci info->var.bits_per_pixel = 16; 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci info->var.red.length = 5; 1758c2ecf20Sopenharmony_ci info->var.red.offset = 11; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci info->var.green.length = 6; 1788c2ecf20Sopenharmony_ci info->var.green.offset = 5; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci info->var.blue.length = 5; 1818c2ecf20Sopenharmony_ci info->var.blue.offset = 0; 1828c2ecf20Sopenharmony_ci} 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci/** 1858c2ecf20Sopenharmony_ci * s1d13xxxfb_set_par - Alters the hardware state. 1868c2ecf20Sopenharmony_ci * @info: frame buffer structure 1878c2ecf20Sopenharmony_ci * 1888c2ecf20Sopenharmony_ci * Using the fb_var_screeninfo in fb_info we set the depth of the 1898c2ecf20Sopenharmony_ci * framebuffer. This function alters the par AND the 1908c2ecf20Sopenharmony_ci * fb_fix_screeninfo stored in fb_info. It doesn't not alter var in 1918c2ecf20Sopenharmony_ci * fb_info since we are using that data. This means we depend on the 1928c2ecf20Sopenharmony_ci * data in var inside fb_info to be supported by the hardware. 1938c2ecf20Sopenharmony_ci * xxxfb_check_var is always called before xxxfb_set_par to ensure this. 1948c2ecf20Sopenharmony_ci * 1958c2ecf20Sopenharmony_ci * XXX TODO: write proper s1d13xxxfb_check_var(), without which that 1968c2ecf20Sopenharmony_ci * function is quite useless. 1978c2ecf20Sopenharmony_ci */ 1988c2ecf20Sopenharmony_cistatic int 1998c2ecf20Sopenharmony_cis1d13xxxfb_set_par(struct fb_info *info) 2008c2ecf20Sopenharmony_ci{ 2018c2ecf20Sopenharmony_ci struct s1d13xxxfb_par *s1dfb = info->par; 2028c2ecf20Sopenharmony_ci unsigned int val; 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci dbg("s1d13xxxfb_set_par: bpp=%d\n", info->var.bits_per_pixel); 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci if ((s1dfb->display & 0x01)) /* LCD */ 2078c2ecf20Sopenharmony_ci val = s1d13xxxfb_readreg(s1dfb, S1DREG_LCD_DISP_MODE); /* read colour control */ 2088c2ecf20Sopenharmony_ci else /* CRT */ 2098c2ecf20Sopenharmony_ci val = s1d13xxxfb_readreg(s1dfb, S1DREG_CRT_DISP_MODE); /* read colour control */ 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci val &= ~0x07; 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci switch (info->var.bits_per_pixel) { 2148c2ecf20Sopenharmony_ci case 4: 2158c2ecf20Sopenharmony_ci dbg("pseudo colour 4\n"); 2168c2ecf20Sopenharmony_ci s1d13xxxfb_setup_pseudocolour(info); 2178c2ecf20Sopenharmony_ci val |= 2; 2188c2ecf20Sopenharmony_ci break; 2198c2ecf20Sopenharmony_ci case 8: 2208c2ecf20Sopenharmony_ci dbg("pseudo colour 8\n"); 2218c2ecf20Sopenharmony_ci s1d13xxxfb_setup_pseudocolour(info); 2228c2ecf20Sopenharmony_ci val |= 3; 2238c2ecf20Sopenharmony_ci break; 2248c2ecf20Sopenharmony_ci case 16: 2258c2ecf20Sopenharmony_ci dbg("true colour\n"); 2268c2ecf20Sopenharmony_ci s1d13xxxfb_setup_truecolour(info); 2278c2ecf20Sopenharmony_ci val |= 5; 2288c2ecf20Sopenharmony_ci break; 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci default: 2318c2ecf20Sopenharmony_ci dbg("bpp not supported!\n"); 2328c2ecf20Sopenharmony_ci return -EINVAL; 2338c2ecf20Sopenharmony_ci } 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci dbg("writing %02x to display mode register\n", val); 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci if ((s1dfb->display & 0x01)) /* LCD */ 2388c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(s1dfb, S1DREG_LCD_DISP_MODE, val); 2398c2ecf20Sopenharmony_ci else /* CRT */ 2408c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(s1dfb, S1DREG_CRT_DISP_MODE, val); 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ci info->fix.line_length = info->var.xres * info->var.bits_per_pixel; 2438c2ecf20Sopenharmony_ci info->fix.line_length /= 8; 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci dbg("setting line_length to %d\n", info->fix.line_length); 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci dbg("done setup\n"); 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci return 0; 2508c2ecf20Sopenharmony_ci} 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci/** 2538c2ecf20Sopenharmony_ci * s1d13xxxfb_setcolreg - sets a color register. 2548c2ecf20Sopenharmony_ci * @regno: Which register in the CLUT we are programming 2558c2ecf20Sopenharmony_ci * @red: The red value which can be up to 16 bits wide 2568c2ecf20Sopenharmony_ci * @green: The green value which can be up to 16 bits wide 2578c2ecf20Sopenharmony_ci * @blue: The blue value which can be up to 16 bits wide. 2588c2ecf20Sopenharmony_ci * @transp: If supported the alpha value which can be up to 16 bits wide. 2598c2ecf20Sopenharmony_ci * @info: frame buffer info structure 2608c2ecf20Sopenharmony_ci * 2618c2ecf20Sopenharmony_ci * Returns negative errno on error, or zero on success. 2628c2ecf20Sopenharmony_ci */ 2638c2ecf20Sopenharmony_cistatic int 2648c2ecf20Sopenharmony_cis1d13xxxfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, 2658c2ecf20Sopenharmony_ci u_int transp, struct fb_info *info) 2668c2ecf20Sopenharmony_ci{ 2678c2ecf20Sopenharmony_ci struct s1d13xxxfb_par *s1dfb = info->par; 2688c2ecf20Sopenharmony_ci unsigned int pseudo_val; 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci if (regno >= S1D_PALETTE_SIZE) 2718c2ecf20Sopenharmony_ci return -EINVAL; 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci dbg("s1d13xxxfb_setcolreg: %d: rgb=%d,%d,%d, tr=%d\n", 2748c2ecf20Sopenharmony_ci regno, red, green, blue, transp); 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci if (info->var.grayscale) 2778c2ecf20Sopenharmony_ci red = green = blue = (19595*red + 38470*green + 7471*blue) >> 16; 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci switch (info->fix.visual) { 2808c2ecf20Sopenharmony_ci case FB_VISUAL_TRUECOLOR: 2818c2ecf20Sopenharmony_ci if (regno >= 16) 2828c2ecf20Sopenharmony_ci return -EINVAL; 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ci /* deal with creating pseudo-palette entries */ 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci pseudo_val = (red >> 11) << info->var.red.offset; 2878c2ecf20Sopenharmony_ci pseudo_val |= (green >> 10) << info->var.green.offset; 2888c2ecf20Sopenharmony_ci pseudo_val |= (blue >> 11) << info->var.blue.offset; 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci dbg("s1d13xxxfb_setcolreg: pseudo %d, val %08x\n", 2918c2ecf20Sopenharmony_ci regno, pseudo_val); 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci ((u32 *)info->pseudo_palette)[regno] = pseudo_val; 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci break; 2968c2ecf20Sopenharmony_ci case FB_VISUAL_PSEUDOCOLOR: 2978c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_ADDR, regno); 2988c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_DATA, red); 2998c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_DATA, green); 3008c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(s1dfb, S1DREG_LKUP_DATA, blue); 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci break; 3038c2ecf20Sopenharmony_ci default: 3048c2ecf20Sopenharmony_ci return -ENOSYS; 3058c2ecf20Sopenharmony_ci } 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_ci dbg("s1d13xxxfb_setcolreg: done\n"); 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci return 0; 3108c2ecf20Sopenharmony_ci} 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci/** 3138c2ecf20Sopenharmony_ci * s1d13xxxfb_blank - blanks the display. 3148c2ecf20Sopenharmony_ci * @blank_mode: the blank mode we want. 3158c2ecf20Sopenharmony_ci * @info: frame buffer structure that represents a single frame buffer 3168c2ecf20Sopenharmony_ci * 3178c2ecf20Sopenharmony_ci * Blank the screen if blank_mode != 0, else unblank. Return 0 if 3188c2ecf20Sopenharmony_ci * blanking succeeded, != 0 if un-/blanking failed due to e.g. a 3198c2ecf20Sopenharmony_ci * video mode which doesn't support it. Implements VESA suspend 3208c2ecf20Sopenharmony_ci * and powerdown modes on hardware that supports disabling hsync/vsync: 3218c2ecf20Sopenharmony_ci * blank_mode == 2: suspend vsync 3228c2ecf20Sopenharmony_ci * blank_mode == 3: suspend hsync 3238c2ecf20Sopenharmony_ci * blank_mode == 4: powerdown 3248c2ecf20Sopenharmony_ci * 3258c2ecf20Sopenharmony_ci * Returns negative errno on error, or zero on success. 3268c2ecf20Sopenharmony_ci */ 3278c2ecf20Sopenharmony_cistatic int 3288c2ecf20Sopenharmony_cis1d13xxxfb_blank(int blank_mode, struct fb_info *info) 3298c2ecf20Sopenharmony_ci{ 3308c2ecf20Sopenharmony_ci struct s1d13xxxfb_par *par = info->par; 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci dbg("s1d13xxxfb_blank: blank=%d, info=%p\n", blank_mode, info); 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci switch (blank_mode) { 3358c2ecf20Sopenharmony_ci case FB_BLANK_UNBLANK: 3368c2ecf20Sopenharmony_ci case FB_BLANK_NORMAL: 3378c2ecf20Sopenharmony_ci if ((par->display & 0x01) != 0) 3388c2ecf20Sopenharmony_ci lcd_enable(par, 1); 3398c2ecf20Sopenharmony_ci if ((par->display & 0x02) != 0) 3408c2ecf20Sopenharmony_ci crt_enable(par, 1); 3418c2ecf20Sopenharmony_ci break; 3428c2ecf20Sopenharmony_ci case FB_BLANK_VSYNC_SUSPEND: 3438c2ecf20Sopenharmony_ci case FB_BLANK_HSYNC_SUSPEND: 3448c2ecf20Sopenharmony_ci break; 3458c2ecf20Sopenharmony_ci case FB_BLANK_POWERDOWN: 3468c2ecf20Sopenharmony_ci lcd_enable(par, 0); 3478c2ecf20Sopenharmony_ci crt_enable(par, 0); 3488c2ecf20Sopenharmony_ci break; 3498c2ecf20Sopenharmony_ci default: 3508c2ecf20Sopenharmony_ci return -EINVAL; 3518c2ecf20Sopenharmony_ci } 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci /* let fbcon do a soft blank for us */ 3548c2ecf20Sopenharmony_ci return ((blank_mode == FB_BLANK_NORMAL) ? 1 : 0); 3558c2ecf20Sopenharmony_ci} 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci/** 3588c2ecf20Sopenharmony_ci * s1d13xxxfb_pan_display - Pans the display. 3598c2ecf20Sopenharmony_ci * @var: frame buffer variable screen structure 3608c2ecf20Sopenharmony_ci * @info: frame buffer structure that represents a single frame buffer 3618c2ecf20Sopenharmony_ci * 3628c2ecf20Sopenharmony_ci * Pan (or wrap, depending on the `vmode' field) the display using the 3638c2ecf20Sopenharmony_ci * `yoffset' field of the `var' structure (`xoffset' not yet supported). 3648c2ecf20Sopenharmony_ci * If the values don't fit, return -EINVAL. 3658c2ecf20Sopenharmony_ci * 3668c2ecf20Sopenharmony_ci * Returns negative errno on error, or zero on success. 3678c2ecf20Sopenharmony_ci */ 3688c2ecf20Sopenharmony_cistatic int 3698c2ecf20Sopenharmony_cis1d13xxxfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) 3708c2ecf20Sopenharmony_ci{ 3718c2ecf20Sopenharmony_ci struct s1d13xxxfb_par *par = info->par; 3728c2ecf20Sopenharmony_ci u32 start; 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci if (var->xoffset != 0) /* not yet ... */ 3758c2ecf20Sopenharmony_ci return -EINVAL; 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci if (var->yoffset + info->var.yres > info->var.yres_virtual) 3788c2ecf20Sopenharmony_ci return -EINVAL; 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci start = (info->fix.line_length >> 1) * var->yoffset; 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_ci if ((par->display & 0x01)) { 3838c2ecf20Sopenharmony_ci /* LCD */ 3848c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(par, S1DREG_LCD_DISP_START0, (start & 0xff)); 3858c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(par, S1DREG_LCD_DISP_START1, ((start >> 8) & 0xff)); 3868c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(par, S1DREG_LCD_DISP_START2, ((start >> 16) & 0x0f)); 3878c2ecf20Sopenharmony_ci } else { 3888c2ecf20Sopenharmony_ci /* CRT */ 3898c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(par, S1DREG_CRT_DISP_START0, (start & 0xff)); 3908c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(par, S1DREG_CRT_DISP_START1, ((start >> 8) & 0xff)); 3918c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(par, S1DREG_CRT_DISP_START2, ((start >> 16) & 0x0f)); 3928c2ecf20Sopenharmony_ci } 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ci return 0; 3958c2ecf20Sopenharmony_ci} 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci/************************************************************ 3988c2ecf20Sopenharmony_ci functions to handle bitblt acceleration 3998c2ecf20Sopenharmony_ci ************************************************************/ 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci/** 4028c2ecf20Sopenharmony_ci * bltbit_wait_bitclear - waits for change in register value 4038c2ecf20Sopenharmony_ci * @info : frambuffer structure 4048c2ecf20Sopenharmony_ci * @bit : value currently in register 4058c2ecf20Sopenharmony_ci * @timeout : ... 4068c2ecf20Sopenharmony_ci * 4078c2ecf20Sopenharmony_ci * waits until value changes FROM bit 4088c2ecf20Sopenharmony_ci * 4098c2ecf20Sopenharmony_ci */ 4108c2ecf20Sopenharmony_cistatic u8 4118c2ecf20Sopenharmony_cibltbit_wait_bitclear(struct fb_info *info, u8 bit, int timeout) 4128c2ecf20Sopenharmony_ci{ 4138c2ecf20Sopenharmony_ci while (s1d13xxxfb_readreg(info->par, S1DREG_BBLT_CTL0) & bit) { 4148c2ecf20Sopenharmony_ci udelay(10); 4158c2ecf20Sopenharmony_ci if (!--timeout) { 4168c2ecf20Sopenharmony_ci dbg_blit("wait_bitclear timeout\n"); 4178c2ecf20Sopenharmony_ci break; 4188c2ecf20Sopenharmony_ci } 4198c2ecf20Sopenharmony_ci } 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci return timeout; 4228c2ecf20Sopenharmony_ci} 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci/* 4258c2ecf20Sopenharmony_ci * s1d13xxxfb_bitblt_copyarea - accelerated copyarea function 4268c2ecf20Sopenharmony_ci * @info : framebuffer structure 4278c2ecf20Sopenharmony_ci * @area : fb_copyarea structure 4288c2ecf20Sopenharmony_ci * 4298c2ecf20Sopenharmony_ci * supports (atleast) S1D13506 4308c2ecf20Sopenharmony_ci * 4318c2ecf20Sopenharmony_ci */ 4328c2ecf20Sopenharmony_cistatic void 4338c2ecf20Sopenharmony_cis1d13xxxfb_bitblt_copyarea(struct fb_info *info, const struct fb_copyarea *area) 4348c2ecf20Sopenharmony_ci{ 4358c2ecf20Sopenharmony_ci u32 dst, src; 4368c2ecf20Sopenharmony_ci u32 stride; 4378c2ecf20Sopenharmony_ci u16 reverse = 0; 4388c2ecf20Sopenharmony_ci u16 sx = area->sx, sy = area->sy; 4398c2ecf20Sopenharmony_ci u16 dx = area->dx, dy = area->dy; 4408c2ecf20Sopenharmony_ci u16 width = area->width, height = area->height; 4418c2ecf20Sopenharmony_ci u16 bpp; 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci spin_lock(&s1d13xxxfb_bitblt_lock); 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci /* bytes per xres line */ 4468c2ecf20Sopenharmony_ci bpp = (info->var.bits_per_pixel >> 3); 4478c2ecf20Sopenharmony_ci stride = bpp * info->var.xres; 4488c2ecf20Sopenharmony_ci 4498c2ecf20Sopenharmony_ci /* reverse, calculate the last pixel in rectangle */ 4508c2ecf20Sopenharmony_ci if ((dy > sy) || ((dy == sy) && (dx >= sx))) { 4518c2ecf20Sopenharmony_ci dst = (((dy + height - 1) * stride) + (bpp * (dx + width - 1))); 4528c2ecf20Sopenharmony_ci src = (((sy + height - 1) * stride) + (bpp * (sx + width - 1))); 4538c2ecf20Sopenharmony_ci reverse = 1; 4548c2ecf20Sopenharmony_ci /* not reverse, calculate the first pixel in rectangle */ 4558c2ecf20Sopenharmony_ci } else { /* (y * xres) + (bpp * x) */ 4568c2ecf20Sopenharmony_ci dst = (dy * stride) + (bpp * dx); 4578c2ecf20Sopenharmony_ci src = (sy * stride) + (bpp * sx); 4588c2ecf20Sopenharmony_ci } 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_ci /* set source address */ 4618c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_SRC_START0, (src & 0xff)); 4628c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_SRC_START1, (src >> 8) & 0x00ff); 4638c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_SRC_START2, (src >> 16) & 0x00ff); 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci /* set destination address */ 4668c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START0, (dst & 0xff)); 4678c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START1, (dst >> 8) & 0x00ff); 4688c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START2, (dst >> 16) & 0x00ff); 4698c2ecf20Sopenharmony_ci 4708c2ecf20Sopenharmony_ci /* program height and width */ 4718c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH0, (width & 0xff) - 1); 4728c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH1, (width >> 8)); 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT0, (height & 0xff) - 1); 4758c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT1, (height >> 8)); 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci /* negative direction ROP */ 4788c2ecf20Sopenharmony_ci if (reverse == 1) { 4798c2ecf20Sopenharmony_ci dbg_blit("(copyarea) negative rop\n"); 4808c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_OP, 0x03); 4818c2ecf20Sopenharmony_ci } else /* positive direction ROP */ { 4828c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_OP, 0x02); 4838c2ecf20Sopenharmony_ci dbg_blit("(copyarea) positive rop\n"); 4848c2ecf20Sopenharmony_ci } 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci /* set for rectangel mode and not linear */ 4878c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x0); 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci /* setup the bpp 1 = 16bpp, 0 = 8bpp*/ 4908c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL1, (bpp >> 1)); 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci /* set words per xres */ 4938c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF0, (stride >> 1) & 0xff); 4948c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF1, (stride >> 9)); 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci dbg_blit("(copyarea) dx=%d, dy=%d\n", dx, dy); 4978c2ecf20Sopenharmony_ci dbg_blit("(copyarea) sx=%d, sy=%d\n", sx, sy); 4988c2ecf20Sopenharmony_ci dbg_blit("(copyarea) width=%d, height=%d\n", width - 1, height - 1); 4998c2ecf20Sopenharmony_ci dbg_blit("(copyarea) stride=%d\n", stride); 5008c2ecf20Sopenharmony_ci dbg_blit("(copyarea) bpp=%d=0x0%d, mem_offset1=%d, mem_offset2=%d\n", bpp, (bpp >> 1), 5018c2ecf20Sopenharmony_ci (stride >> 1) & 0xff, stride >> 9); 5028c2ecf20Sopenharmony_ci 5038c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CC_EXP, 0x0c); 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci /* initialize the engine */ 5068c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x80); 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_ci /* wait to complete */ 5098c2ecf20Sopenharmony_ci bltbit_wait_bitclear(info, 0x80, 8000); 5108c2ecf20Sopenharmony_ci 5118c2ecf20Sopenharmony_ci spin_unlock(&s1d13xxxfb_bitblt_lock); 5128c2ecf20Sopenharmony_ci} 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci/** 5158c2ecf20Sopenharmony_ci * 5168c2ecf20Sopenharmony_ci * s1d13xxxfb_bitblt_solidfill - accelerated solidfill function 5178c2ecf20Sopenharmony_ci * @info : framebuffer structure 5188c2ecf20Sopenharmony_ci * @rect : fb_fillrect structure 5198c2ecf20Sopenharmony_ci * 5208c2ecf20Sopenharmony_ci * supports (atleast 13506) 5218c2ecf20Sopenharmony_ci * 5228c2ecf20Sopenharmony_ci **/ 5238c2ecf20Sopenharmony_cistatic void 5248c2ecf20Sopenharmony_cis1d13xxxfb_bitblt_solidfill(struct fb_info *info, const struct fb_fillrect *rect) 5258c2ecf20Sopenharmony_ci{ 5268c2ecf20Sopenharmony_ci u32 screen_stride, dest; 5278c2ecf20Sopenharmony_ci u32 fg; 5288c2ecf20Sopenharmony_ci u16 bpp = (info->var.bits_per_pixel >> 3); 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_ci /* grab spinlock */ 5318c2ecf20Sopenharmony_ci spin_lock(&s1d13xxxfb_bitblt_lock); 5328c2ecf20Sopenharmony_ci 5338c2ecf20Sopenharmony_ci /* bytes per x width */ 5348c2ecf20Sopenharmony_ci screen_stride = (bpp * info->var.xres); 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ci /* bytes to starting point */ 5378c2ecf20Sopenharmony_ci dest = ((rect->dy * screen_stride) + (bpp * rect->dx)); 5388c2ecf20Sopenharmony_ci 5398c2ecf20Sopenharmony_ci dbg_blit("(solidfill) dx=%d, dy=%d, stride=%d, dest=%d\n" 5408c2ecf20Sopenharmony_ci "(solidfill) : rect_width=%d, rect_height=%d\n", 5418c2ecf20Sopenharmony_ci rect->dx, rect->dy, screen_stride, dest, 5428c2ecf20Sopenharmony_ci rect->width - 1, rect->height - 1); 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci dbg_blit("(solidfill) : xres=%d, yres=%d, bpp=%d\n", 5458c2ecf20Sopenharmony_ci info->var.xres, info->var.yres, 5468c2ecf20Sopenharmony_ci info->var.bits_per_pixel); 5478c2ecf20Sopenharmony_ci dbg_blit("(solidfill) : rop=%d\n", rect->rop); 5488c2ecf20Sopenharmony_ci 5498c2ecf20Sopenharmony_ci /* We split the destination into the three registers */ 5508c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START0, (dest & 0x00ff)); 5518c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START1, ((dest >> 8) & 0x00ff)); 5528c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_DST_START2, ((dest >> 16) & 0x00ff)); 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci /* give information regarding rectangel width */ 5558c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH0, ((rect->width) & 0x00ff) - 1); 5568c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_WIDTH1, (rect->width >> 8)); 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci /* give information regarding rectangel height */ 5598c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT0, ((rect->height) & 0x00ff) - 1); 5608c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_HEIGHT1, (rect->height >> 8)); 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci if (info->fix.visual == FB_VISUAL_TRUECOLOR || 5638c2ecf20Sopenharmony_ci info->fix.visual == FB_VISUAL_DIRECTCOLOR) { 5648c2ecf20Sopenharmony_ci fg = ((u32 *)info->pseudo_palette)[rect->color]; 5658c2ecf20Sopenharmony_ci dbg_blit("(solidfill) truecolor/directcolor\n"); 5668c2ecf20Sopenharmony_ci dbg_blit("(solidfill) pseudo_palette[%d] = %d\n", rect->color, fg); 5678c2ecf20Sopenharmony_ci } else { 5688c2ecf20Sopenharmony_ci fg = rect->color; 5698c2ecf20Sopenharmony_ci dbg_blit("(solidfill) color = %d\n", rect->color); 5708c2ecf20Sopenharmony_ci } 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci /* set foreground color */ 5738c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_FGC0, (fg & 0xff)); 5748c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_FGC1, (fg >> 8) & 0xff); 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_ci /* set rectangual region of memory (rectangle and not linear) */ 5778c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x0); 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_ci /* set operation mode SOLID_FILL */ 5808c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_OP, BBLT_SOLID_FILL); 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci /* set bits per pixel (1 = 16bpp, 0 = 8bpp) */ 5838c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL1, (info->var.bits_per_pixel >> 4)); 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci /* set the memory offset for the bblt in word sizes */ 5868c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF0, (screen_stride >> 1) & 0x00ff); 5878c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_MEM_OFF1, (screen_stride >> 9)); 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_ci /* and away we go.... */ 5908c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(info->par, S1DREG_BBLT_CTL0, 0x80); 5918c2ecf20Sopenharmony_ci 5928c2ecf20Sopenharmony_ci /* wait until its done */ 5938c2ecf20Sopenharmony_ci bltbit_wait_bitclear(info, 0x80, 8000); 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ci /* let others play */ 5968c2ecf20Sopenharmony_ci spin_unlock(&s1d13xxxfb_bitblt_lock); 5978c2ecf20Sopenharmony_ci} 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ci/* framebuffer information structures */ 6008c2ecf20Sopenharmony_cistatic struct fb_ops s1d13xxxfb_fbops = { 6018c2ecf20Sopenharmony_ci .owner = THIS_MODULE, 6028c2ecf20Sopenharmony_ci .fb_set_par = s1d13xxxfb_set_par, 6038c2ecf20Sopenharmony_ci .fb_setcolreg = s1d13xxxfb_setcolreg, 6048c2ecf20Sopenharmony_ci .fb_blank = s1d13xxxfb_blank, 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_ci .fb_pan_display = s1d13xxxfb_pan_display, 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci /* gets replaced at chip detection time */ 6098c2ecf20Sopenharmony_ci .fb_fillrect = cfb_fillrect, 6108c2ecf20Sopenharmony_ci .fb_copyarea = cfb_copyarea, 6118c2ecf20Sopenharmony_ci .fb_imageblit = cfb_imageblit, 6128c2ecf20Sopenharmony_ci}; 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_cistatic int s1d13xxxfb_width_tab[2][4] = { 6158c2ecf20Sopenharmony_ci {4, 8, 16, -1}, 6168c2ecf20Sopenharmony_ci {9, 12, 18, -1}, 6178c2ecf20Sopenharmony_ci}; 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ci/** 6208c2ecf20Sopenharmony_ci * s1d13xxxfb_fetch_hw_state - Configure the framebuffer according to 6218c2ecf20Sopenharmony_ci * hardware setup. 6228c2ecf20Sopenharmony_ci * @info: frame buffer structure 6238c2ecf20Sopenharmony_ci * 6248c2ecf20Sopenharmony_ci * We setup the framebuffer structures according to the current 6258c2ecf20Sopenharmony_ci * hardware setup. On some machines, the BIOS will have filled 6268c2ecf20Sopenharmony_ci * the chip registers with such info, on others, these values will 6278c2ecf20Sopenharmony_ci * have been written in some init procedure. In any case, the 6288c2ecf20Sopenharmony_ci * software values needs to match the hardware ones. This is what 6298c2ecf20Sopenharmony_ci * this function ensures. 6308c2ecf20Sopenharmony_ci * 6318c2ecf20Sopenharmony_ci * Note: some of the hardcoded values here might need some love to 6328c2ecf20Sopenharmony_ci * work on various chips, and might need to no longer be hardcoded. 6338c2ecf20Sopenharmony_ci */ 6348c2ecf20Sopenharmony_cistatic void s1d13xxxfb_fetch_hw_state(struct fb_info *info) 6358c2ecf20Sopenharmony_ci{ 6368c2ecf20Sopenharmony_ci struct fb_var_screeninfo *var = &info->var; 6378c2ecf20Sopenharmony_ci struct fb_fix_screeninfo *fix = &info->fix; 6388c2ecf20Sopenharmony_ci struct s1d13xxxfb_par *par = info->par; 6398c2ecf20Sopenharmony_ci u8 panel, display; 6408c2ecf20Sopenharmony_ci u16 offset; 6418c2ecf20Sopenharmony_ci u32 xres, yres; 6428c2ecf20Sopenharmony_ci u32 xres_virtual, yres_virtual; 6438c2ecf20Sopenharmony_ci int bpp, lcd_bpp; 6448c2ecf20Sopenharmony_ci int is_color, is_dual, is_tft; 6458c2ecf20Sopenharmony_ci int lcd_enabled, crt_enabled; 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci fix->type = FB_TYPE_PACKED_PIXELS; 6488c2ecf20Sopenharmony_ci 6498c2ecf20Sopenharmony_ci /* general info */ 6508c2ecf20Sopenharmony_ci par->display = s1d13xxxfb_readreg(par, S1DREG_COM_DISP_MODE); 6518c2ecf20Sopenharmony_ci crt_enabled = (par->display & 0x02) != 0; 6528c2ecf20Sopenharmony_ci lcd_enabled = (par->display & 0x01) != 0; 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_ci if (lcd_enabled && crt_enabled) 6558c2ecf20Sopenharmony_ci printk(KERN_WARNING PFX "Warning: LCD and CRT detected, using LCD\n"); 6568c2ecf20Sopenharmony_ci 6578c2ecf20Sopenharmony_ci if (lcd_enabled) 6588c2ecf20Sopenharmony_ci display = s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_MODE); 6598c2ecf20Sopenharmony_ci else /* CRT */ 6608c2ecf20Sopenharmony_ci display = s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_MODE); 6618c2ecf20Sopenharmony_ci 6628c2ecf20Sopenharmony_ci bpp = display & 0x07; 6638c2ecf20Sopenharmony_ci 6648c2ecf20Sopenharmony_ci switch (bpp) { 6658c2ecf20Sopenharmony_ci case 2: /* 4 bpp */ 6668c2ecf20Sopenharmony_ci case 3: /* 8 bpp */ 6678c2ecf20Sopenharmony_ci var->bits_per_pixel = 8; 6688c2ecf20Sopenharmony_ci var->red.offset = var->green.offset = var->blue.offset = 0; 6698c2ecf20Sopenharmony_ci var->red.length = var->green.length = var->blue.length = 8; 6708c2ecf20Sopenharmony_ci break; 6718c2ecf20Sopenharmony_ci case 5: /* 16 bpp */ 6728c2ecf20Sopenharmony_ci s1d13xxxfb_setup_truecolour(info); 6738c2ecf20Sopenharmony_ci break; 6748c2ecf20Sopenharmony_ci default: 6758c2ecf20Sopenharmony_ci dbg("bpp: %i\n", bpp); 6768c2ecf20Sopenharmony_ci } 6778c2ecf20Sopenharmony_ci fb_alloc_cmap(&info->cmap, 256, 0); 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_ci /* LCD info */ 6808c2ecf20Sopenharmony_ci panel = s1d13xxxfb_readreg(par, S1DREG_PANEL_TYPE); 6818c2ecf20Sopenharmony_ci is_color = (panel & 0x04) != 0; 6828c2ecf20Sopenharmony_ci is_dual = (panel & 0x02) != 0; 6838c2ecf20Sopenharmony_ci is_tft = (panel & 0x01) != 0; 6848c2ecf20Sopenharmony_ci lcd_bpp = s1d13xxxfb_width_tab[is_tft][(panel >> 4) & 3]; 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_ci if (lcd_enabled) { 6878c2ecf20Sopenharmony_ci xres = (s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_HWIDTH) + 1) * 8; 6888c2ecf20Sopenharmony_ci yres = (s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_VHEIGHT0) + 6898c2ecf20Sopenharmony_ci ((s1d13xxxfb_readreg(par, S1DREG_LCD_DISP_VHEIGHT1) & 0x03) << 8) + 1); 6908c2ecf20Sopenharmony_ci 6918c2ecf20Sopenharmony_ci offset = (s1d13xxxfb_readreg(par, S1DREG_LCD_MEM_OFF0) + 6928c2ecf20Sopenharmony_ci ((s1d13xxxfb_readreg(par, S1DREG_LCD_MEM_OFF1) & 0x7) << 8)); 6938c2ecf20Sopenharmony_ci } else { /* crt */ 6948c2ecf20Sopenharmony_ci xres = (s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_HWIDTH) + 1) * 8; 6958c2ecf20Sopenharmony_ci yres = (s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_VHEIGHT0) + 6968c2ecf20Sopenharmony_ci ((s1d13xxxfb_readreg(par, S1DREG_CRT_DISP_VHEIGHT1) & 0x03) << 8) + 1); 6978c2ecf20Sopenharmony_ci 6988c2ecf20Sopenharmony_ci offset = (s1d13xxxfb_readreg(par, S1DREG_CRT_MEM_OFF0) + 6998c2ecf20Sopenharmony_ci ((s1d13xxxfb_readreg(par, S1DREG_CRT_MEM_OFF1) & 0x7) << 8)); 7008c2ecf20Sopenharmony_ci } 7018c2ecf20Sopenharmony_ci xres_virtual = offset * 16 / var->bits_per_pixel; 7028c2ecf20Sopenharmony_ci yres_virtual = fix->smem_len / (offset * 2); 7038c2ecf20Sopenharmony_ci 7048c2ecf20Sopenharmony_ci var->xres = xres; 7058c2ecf20Sopenharmony_ci var->yres = yres; 7068c2ecf20Sopenharmony_ci var->xres_virtual = xres_virtual; 7078c2ecf20Sopenharmony_ci var->yres_virtual = yres_virtual; 7088c2ecf20Sopenharmony_ci var->xoffset = var->yoffset = 0; 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ci fix->line_length = offset * 2; 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_ci var->grayscale = !is_color; 7138c2ecf20Sopenharmony_ci 7148c2ecf20Sopenharmony_ci var->activate = FB_ACTIVATE_NOW; 7158c2ecf20Sopenharmony_ci 7168c2ecf20Sopenharmony_ci dbg(PFX "bpp=%d, lcd_bpp=%d, " 7178c2ecf20Sopenharmony_ci "crt_enabled=%d, lcd_enabled=%d\n", 7188c2ecf20Sopenharmony_ci var->bits_per_pixel, lcd_bpp, crt_enabled, lcd_enabled); 7198c2ecf20Sopenharmony_ci dbg(PFX "xres=%d, yres=%d, vxres=%d, vyres=%d " 7208c2ecf20Sopenharmony_ci "is_color=%d, is_dual=%d, is_tft=%d\n", 7218c2ecf20Sopenharmony_ci xres, yres, xres_virtual, yres_virtual, is_color, is_dual, is_tft); 7228c2ecf20Sopenharmony_ci} 7238c2ecf20Sopenharmony_ci 7248c2ecf20Sopenharmony_cistatic void __s1d13xxxfb_remove(struct platform_device *pdev) 7258c2ecf20Sopenharmony_ci{ 7268c2ecf20Sopenharmony_ci struct fb_info *info = platform_get_drvdata(pdev); 7278c2ecf20Sopenharmony_ci struct s1d13xxxfb_par *par = NULL; 7288c2ecf20Sopenharmony_ci 7298c2ecf20Sopenharmony_ci if (info) { 7308c2ecf20Sopenharmony_ci par = info->par; 7318c2ecf20Sopenharmony_ci if (par && par->regs) { 7328c2ecf20Sopenharmony_ci /* disable output & enable powersave */ 7338c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(par, S1DREG_COM_DISP_MODE, 0x00); 7348c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(par, S1DREG_PS_CNF, 0x11); 7358c2ecf20Sopenharmony_ci iounmap(par->regs); 7368c2ecf20Sopenharmony_ci } 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci fb_dealloc_cmap(&info->cmap); 7398c2ecf20Sopenharmony_ci 7408c2ecf20Sopenharmony_ci if (info->screen_base) 7418c2ecf20Sopenharmony_ci iounmap(info->screen_base); 7428c2ecf20Sopenharmony_ci 7438c2ecf20Sopenharmony_ci framebuffer_release(info); 7448c2ecf20Sopenharmony_ci } 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_ci release_mem_region(pdev->resource[0].start, 7478c2ecf20Sopenharmony_ci resource_size(&pdev->resource[0])); 7488c2ecf20Sopenharmony_ci release_mem_region(pdev->resource[1].start, 7498c2ecf20Sopenharmony_ci resource_size(&pdev->resource[1])); 7508c2ecf20Sopenharmony_ci} 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_cistatic int s1d13xxxfb_remove(struct platform_device *pdev) 7538c2ecf20Sopenharmony_ci{ 7548c2ecf20Sopenharmony_ci struct fb_info *info = platform_get_drvdata(pdev); 7558c2ecf20Sopenharmony_ci 7568c2ecf20Sopenharmony_ci unregister_framebuffer(info); 7578c2ecf20Sopenharmony_ci __s1d13xxxfb_remove(pdev); 7588c2ecf20Sopenharmony_ci return 0; 7598c2ecf20Sopenharmony_ci} 7608c2ecf20Sopenharmony_ci 7618c2ecf20Sopenharmony_cistatic int s1d13xxxfb_probe(struct platform_device *pdev) 7628c2ecf20Sopenharmony_ci{ 7638c2ecf20Sopenharmony_ci struct s1d13xxxfb_par *default_par; 7648c2ecf20Sopenharmony_ci struct fb_info *info; 7658c2ecf20Sopenharmony_ci struct s1d13xxxfb_pdata *pdata = NULL; 7668c2ecf20Sopenharmony_ci int ret = 0; 7678c2ecf20Sopenharmony_ci int i; 7688c2ecf20Sopenharmony_ci u8 revision, prod_id; 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_ci dbg("probe called: device is %p\n", pdev); 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci printk(KERN_INFO "Epson S1D13XXX FB Driver\n"); 7738c2ecf20Sopenharmony_ci 7748c2ecf20Sopenharmony_ci /* enable platform-dependent hardware glue, if any */ 7758c2ecf20Sopenharmony_ci if (dev_get_platdata(&pdev->dev)) 7768c2ecf20Sopenharmony_ci pdata = dev_get_platdata(&pdev->dev); 7778c2ecf20Sopenharmony_ci 7788c2ecf20Sopenharmony_ci if (pdata && pdata->platform_init_video) 7798c2ecf20Sopenharmony_ci pdata->platform_init_video(); 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_ci if (pdev->num_resources != 2) { 7828c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "invalid num_resources: %i\n", 7838c2ecf20Sopenharmony_ci pdev->num_resources); 7848c2ecf20Sopenharmony_ci ret = -ENODEV; 7858c2ecf20Sopenharmony_ci goto bail; 7868c2ecf20Sopenharmony_ci } 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_ci /* resource[0] is VRAM, resource[1] is registers */ 7898c2ecf20Sopenharmony_ci if (pdev->resource[0].flags != IORESOURCE_MEM 7908c2ecf20Sopenharmony_ci || pdev->resource[1].flags != IORESOURCE_MEM) { 7918c2ecf20Sopenharmony_ci dev_err(&pdev->dev, "invalid resource type\n"); 7928c2ecf20Sopenharmony_ci ret = -ENODEV; 7938c2ecf20Sopenharmony_ci goto bail; 7948c2ecf20Sopenharmony_ci } 7958c2ecf20Sopenharmony_ci 7968c2ecf20Sopenharmony_ci if (!request_mem_region(pdev->resource[0].start, 7978c2ecf20Sopenharmony_ci resource_size(&pdev->resource[0]), "s1d13xxxfb mem")) { 7988c2ecf20Sopenharmony_ci dev_dbg(&pdev->dev, "request_mem_region failed\n"); 7998c2ecf20Sopenharmony_ci ret = -EBUSY; 8008c2ecf20Sopenharmony_ci goto bail; 8018c2ecf20Sopenharmony_ci } 8028c2ecf20Sopenharmony_ci 8038c2ecf20Sopenharmony_ci if (!request_mem_region(pdev->resource[1].start, 8048c2ecf20Sopenharmony_ci resource_size(&pdev->resource[1]), "s1d13xxxfb regs")) { 8058c2ecf20Sopenharmony_ci dev_dbg(&pdev->dev, "request_mem_region failed\n"); 8068c2ecf20Sopenharmony_ci ret = -EBUSY; 8078c2ecf20Sopenharmony_ci goto bail; 8088c2ecf20Sopenharmony_ci } 8098c2ecf20Sopenharmony_ci 8108c2ecf20Sopenharmony_ci info = framebuffer_alloc(sizeof(struct s1d13xxxfb_par) + sizeof(u32) * 256, &pdev->dev); 8118c2ecf20Sopenharmony_ci if (!info) { 8128c2ecf20Sopenharmony_ci ret = -ENOMEM; 8138c2ecf20Sopenharmony_ci goto bail; 8148c2ecf20Sopenharmony_ci } 8158c2ecf20Sopenharmony_ci 8168c2ecf20Sopenharmony_ci platform_set_drvdata(pdev, info); 8178c2ecf20Sopenharmony_ci default_par = info->par; 8188c2ecf20Sopenharmony_ci default_par->regs = ioremap(pdev->resource[1].start, 8198c2ecf20Sopenharmony_ci resource_size(&pdev->resource[1])); 8208c2ecf20Sopenharmony_ci if (!default_par->regs) { 8218c2ecf20Sopenharmony_ci printk(KERN_ERR PFX "unable to map registers\n"); 8228c2ecf20Sopenharmony_ci ret = -ENOMEM; 8238c2ecf20Sopenharmony_ci goto bail; 8248c2ecf20Sopenharmony_ci } 8258c2ecf20Sopenharmony_ci info->pseudo_palette = default_par->pseudo_palette; 8268c2ecf20Sopenharmony_ci 8278c2ecf20Sopenharmony_ci info->screen_base = ioremap(pdev->resource[0].start, 8288c2ecf20Sopenharmony_ci resource_size(&pdev->resource[0])); 8298c2ecf20Sopenharmony_ci 8308c2ecf20Sopenharmony_ci if (!info->screen_base) { 8318c2ecf20Sopenharmony_ci printk(KERN_ERR PFX "unable to map framebuffer\n"); 8328c2ecf20Sopenharmony_ci ret = -ENOMEM; 8338c2ecf20Sopenharmony_ci goto bail; 8348c2ecf20Sopenharmony_ci } 8358c2ecf20Sopenharmony_ci 8368c2ecf20Sopenharmony_ci /* production id is top 6 bits */ 8378c2ecf20Sopenharmony_ci prod_id = s1d13xxxfb_readreg(default_par, S1DREG_REV_CODE) >> 2; 8388c2ecf20Sopenharmony_ci /* revision id is lower 2 bits */ 8398c2ecf20Sopenharmony_ci revision = s1d13xxxfb_readreg(default_par, S1DREG_REV_CODE) & 0x3; 8408c2ecf20Sopenharmony_ci ret = -ENODEV; 8418c2ecf20Sopenharmony_ci 8428c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(s1d13xxxfb_prod_ids); i++) { 8438c2ecf20Sopenharmony_ci if (prod_id == s1d13xxxfb_prod_ids[i]) { 8448c2ecf20Sopenharmony_ci /* looks like we got it in our list */ 8458c2ecf20Sopenharmony_ci default_par->prod_id = prod_id; 8468c2ecf20Sopenharmony_ci default_par->revision = revision; 8478c2ecf20Sopenharmony_ci ret = 0; 8488c2ecf20Sopenharmony_ci break; 8498c2ecf20Sopenharmony_ci } 8508c2ecf20Sopenharmony_ci } 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci if (!ret) { 8538c2ecf20Sopenharmony_ci printk(KERN_INFO PFX "chip production id %i = %s\n", 8548c2ecf20Sopenharmony_ci prod_id, s1d13xxxfb_prod_names[i]); 8558c2ecf20Sopenharmony_ci printk(KERN_INFO PFX "chip revision %i\n", revision); 8568c2ecf20Sopenharmony_ci } else { 8578c2ecf20Sopenharmony_ci printk(KERN_INFO PFX 8588c2ecf20Sopenharmony_ci "unknown chip production id %i, revision %i\n", 8598c2ecf20Sopenharmony_ci prod_id, revision); 8608c2ecf20Sopenharmony_ci printk(KERN_INFO PFX "please contact maintainer\n"); 8618c2ecf20Sopenharmony_ci goto bail; 8628c2ecf20Sopenharmony_ci } 8638c2ecf20Sopenharmony_ci 8648c2ecf20Sopenharmony_ci info->fix = s1d13xxxfb_fix; 8658c2ecf20Sopenharmony_ci info->fix.mmio_start = pdev->resource[1].start; 8668c2ecf20Sopenharmony_ci info->fix.mmio_len = resource_size(&pdev->resource[1]); 8678c2ecf20Sopenharmony_ci info->fix.smem_start = pdev->resource[0].start; 8688c2ecf20Sopenharmony_ci info->fix.smem_len = resource_size(&pdev->resource[0]); 8698c2ecf20Sopenharmony_ci 8708c2ecf20Sopenharmony_ci printk(KERN_INFO PFX "regs mapped at 0x%p, fb %d KiB mapped at 0x%p\n", 8718c2ecf20Sopenharmony_ci default_par->regs, info->fix.smem_len / 1024, info->screen_base); 8728c2ecf20Sopenharmony_ci 8738c2ecf20Sopenharmony_ci info->par = default_par; 8748c2ecf20Sopenharmony_ci info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; 8758c2ecf20Sopenharmony_ci info->fbops = &s1d13xxxfb_fbops; 8768c2ecf20Sopenharmony_ci 8778c2ecf20Sopenharmony_ci switch(prod_id) { 8788c2ecf20Sopenharmony_ci case S1D13506_PROD_ID: /* activate acceleration */ 8798c2ecf20Sopenharmony_ci s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill; 8808c2ecf20Sopenharmony_ci s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea; 8818c2ecf20Sopenharmony_ci info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN | 8828c2ecf20Sopenharmony_ci FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA; 8838c2ecf20Sopenharmony_ci break; 8848c2ecf20Sopenharmony_ci default: 8858c2ecf20Sopenharmony_ci break; 8868c2ecf20Sopenharmony_ci } 8878c2ecf20Sopenharmony_ci 8888c2ecf20Sopenharmony_ci /* perform "manual" chip initialization, if needed */ 8898c2ecf20Sopenharmony_ci if (pdata && pdata->initregs) 8908c2ecf20Sopenharmony_ci s1d13xxxfb_runinit(info->par, pdata->initregs, pdata->initregssize); 8918c2ecf20Sopenharmony_ci 8928c2ecf20Sopenharmony_ci s1d13xxxfb_fetch_hw_state(info); 8938c2ecf20Sopenharmony_ci 8948c2ecf20Sopenharmony_ci if (register_framebuffer(info) < 0) { 8958c2ecf20Sopenharmony_ci ret = -EINVAL; 8968c2ecf20Sopenharmony_ci goto bail; 8978c2ecf20Sopenharmony_ci } 8988c2ecf20Sopenharmony_ci 8998c2ecf20Sopenharmony_ci fb_info(info, "%s frame buffer device\n", info->fix.id); 9008c2ecf20Sopenharmony_ci 9018c2ecf20Sopenharmony_ci return 0; 9028c2ecf20Sopenharmony_ci 9038c2ecf20Sopenharmony_cibail: 9048c2ecf20Sopenharmony_ci __s1d13xxxfb_remove(pdev); 9058c2ecf20Sopenharmony_ci return ret; 9068c2ecf20Sopenharmony_ci 9078c2ecf20Sopenharmony_ci} 9088c2ecf20Sopenharmony_ci 9098c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 9108c2ecf20Sopenharmony_cistatic int s1d13xxxfb_suspend(struct platform_device *dev, pm_message_t state) 9118c2ecf20Sopenharmony_ci{ 9128c2ecf20Sopenharmony_ci struct fb_info *info = platform_get_drvdata(dev); 9138c2ecf20Sopenharmony_ci struct s1d13xxxfb_par *s1dfb = info->par; 9148c2ecf20Sopenharmony_ci struct s1d13xxxfb_pdata *pdata = NULL; 9158c2ecf20Sopenharmony_ci 9168c2ecf20Sopenharmony_ci /* disable display */ 9178c2ecf20Sopenharmony_ci lcd_enable(s1dfb, 0); 9188c2ecf20Sopenharmony_ci crt_enable(s1dfb, 0); 9198c2ecf20Sopenharmony_ci 9208c2ecf20Sopenharmony_ci if (dev_get_platdata(&dev->dev)) 9218c2ecf20Sopenharmony_ci pdata = dev_get_platdata(&dev->dev); 9228c2ecf20Sopenharmony_ci 9238c2ecf20Sopenharmony_ci#if 0 9248c2ecf20Sopenharmony_ci if (!s1dfb->disp_save) 9258c2ecf20Sopenharmony_ci s1dfb->disp_save = kmalloc(info->fix.smem_len, GFP_KERNEL); 9268c2ecf20Sopenharmony_ci 9278c2ecf20Sopenharmony_ci if (!s1dfb->disp_save) { 9288c2ecf20Sopenharmony_ci printk(KERN_ERR PFX "no memory to save screen\n"); 9298c2ecf20Sopenharmony_ci return -ENOMEM; 9308c2ecf20Sopenharmony_ci } 9318c2ecf20Sopenharmony_ci 9328c2ecf20Sopenharmony_ci memcpy_fromio(s1dfb->disp_save, info->screen_base, info->fix.smem_len); 9338c2ecf20Sopenharmony_ci#else 9348c2ecf20Sopenharmony_ci s1dfb->disp_save = NULL; 9358c2ecf20Sopenharmony_ci#endif 9368c2ecf20Sopenharmony_ci 9378c2ecf20Sopenharmony_ci if (!s1dfb->regs_save) 9388c2ecf20Sopenharmony_ci s1dfb->regs_save = kmalloc(info->fix.mmio_len, GFP_KERNEL); 9398c2ecf20Sopenharmony_ci 9408c2ecf20Sopenharmony_ci if (!s1dfb->regs_save) { 9418c2ecf20Sopenharmony_ci printk(KERN_ERR PFX "no memory to save registers"); 9428c2ecf20Sopenharmony_ci return -ENOMEM; 9438c2ecf20Sopenharmony_ci } 9448c2ecf20Sopenharmony_ci 9458c2ecf20Sopenharmony_ci /* backup all registers */ 9468c2ecf20Sopenharmony_ci memcpy_fromio(s1dfb->regs_save, s1dfb->regs, info->fix.mmio_len); 9478c2ecf20Sopenharmony_ci 9488c2ecf20Sopenharmony_ci /* now activate power save mode */ 9498c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(s1dfb, S1DREG_PS_CNF, 0x11); 9508c2ecf20Sopenharmony_ci 9518c2ecf20Sopenharmony_ci if (pdata && pdata->platform_suspend_video) 9528c2ecf20Sopenharmony_ci return pdata->platform_suspend_video(); 9538c2ecf20Sopenharmony_ci else 9548c2ecf20Sopenharmony_ci return 0; 9558c2ecf20Sopenharmony_ci} 9568c2ecf20Sopenharmony_ci 9578c2ecf20Sopenharmony_cistatic int s1d13xxxfb_resume(struct platform_device *dev) 9588c2ecf20Sopenharmony_ci{ 9598c2ecf20Sopenharmony_ci struct fb_info *info = platform_get_drvdata(dev); 9608c2ecf20Sopenharmony_ci struct s1d13xxxfb_par *s1dfb = info->par; 9618c2ecf20Sopenharmony_ci struct s1d13xxxfb_pdata *pdata = NULL; 9628c2ecf20Sopenharmony_ci 9638c2ecf20Sopenharmony_ci /* awaken the chip */ 9648c2ecf20Sopenharmony_ci s1d13xxxfb_writereg(s1dfb, S1DREG_PS_CNF, 0x10); 9658c2ecf20Sopenharmony_ci 9668c2ecf20Sopenharmony_ci /* do not let go until SDRAM "wakes up" */ 9678c2ecf20Sopenharmony_ci while ((s1d13xxxfb_readreg(s1dfb, S1DREG_PS_STATUS) & 0x01)) 9688c2ecf20Sopenharmony_ci udelay(10); 9698c2ecf20Sopenharmony_ci 9708c2ecf20Sopenharmony_ci if (dev_get_platdata(&dev->dev)) 9718c2ecf20Sopenharmony_ci pdata = dev_get_platdata(&dev->dev); 9728c2ecf20Sopenharmony_ci 9738c2ecf20Sopenharmony_ci if (s1dfb->regs_save) { 9748c2ecf20Sopenharmony_ci /* will write RO regs, *should* get away with it :) */ 9758c2ecf20Sopenharmony_ci memcpy_toio(s1dfb->regs, s1dfb->regs_save, info->fix.mmio_len); 9768c2ecf20Sopenharmony_ci kfree(s1dfb->regs_save); 9778c2ecf20Sopenharmony_ci } 9788c2ecf20Sopenharmony_ci 9798c2ecf20Sopenharmony_ci if (s1dfb->disp_save) { 9808c2ecf20Sopenharmony_ci memcpy_toio(info->screen_base, s1dfb->disp_save, 9818c2ecf20Sopenharmony_ci info->fix.smem_len); 9828c2ecf20Sopenharmony_ci kfree(s1dfb->disp_save); /* XXX kmalloc()'d when? */ 9838c2ecf20Sopenharmony_ci } 9848c2ecf20Sopenharmony_ci 9858c2ecf20Sopenharmony_ci if ((s1dfb->display & 0x01) != 0) 9868c2ecf20Sopenharmony_ci lcd_enable(s1dfb, 1); 9878c2ecf20Sopenharmony_ci if ((s1dfb->display & 0x02) != 0) 9888c2ecf20Sopenharmony_ci crt_enable(s1dfb, 1); 9898c2ecf20Sopenharmony_ci 9908c2ecf20Sopenharmony_ci if (pdata && pdata->platform_resume_video) 9918c2ecf20Sopenharmony_ci return pdata->platform_resume_video(); 9928c2ecf20Sopenharmony_ci else 9938c2ecf20Sopenharmony_ci return 0; 9948c2ecf20Sopenharmony_ci} 9958c2ecf20Sopenharmony_ci#endif /* CONFIG_PM */ 9968c2ecf20Sopenharmony_ci 9978c2ecf20Sopenharmony_cistatic struct platform_driver s1d13xxxfb_driver = { 9988c2ecf20Sopenharmony_ci .probe = s1d13xxxfb_probe, 9998c2ecf20Sopenharmony_ci .remove = s1d13xxxfb_remove, 10008c2ecf20Sopenharmony_ci#ifdef CONFIG_PM 10018c2ecf20Sopenharmony_ci .suspend = s1d13xxxfb_suspend, 10028c2ecf20Sopenharmony_ci .resume = s1d13xxxfb_resume, 10038c2ecf20Sopenharmony_ci#endif 10048c2ecf20Sopenharmony_ci .driver = { 10058c2ecf20Sopenharmony_ci .name = S1D_DEVICENAME, 10068c2ecf20Sopenharmony_ci }, 10078c2ecf20Sopenharmony_ci}; 10088c2ecf20Sopenharmony_ci 10098c2ecf20Sopenharmony_ci 10108c2ecf20Sopenharmony_cistatic int __init 10118c2ecf20Sopenharmony_cis1d13xxxfb_init(void) 10128c2ecf20Sopenharmony_ci{ 10138c2ecf20Sopenharmony_ci 10148c2ecf20Sopenharmony_ci#ifndef MODULE 10158c2ecf20Sopenharmony_ci if (fb_get_options("s1d13xxxfb", NULL)) 10168c2ecf20Sopenharmony_ci return -ENODEV; 10178c2ecf20Sopenharmony_ci#endif 10188c2ecf20Sopenharmony_ci 10198c2ecf20Sopenharmony_ci return platform_driver_register(&s1d13xxxfb_driver); 10208c2ecf20Sopenharmony_ci} 10218c2ecf20Sopenharmony_ci 10228c2ecf20Sopenharmony_ci 10238c2ecf20Sopenharmony_cistatic void __exit 10248c2ecf20Sopenharmony_cis1d13xxxfb_exit(void) 10258c2ecf20Sopenharmony_ci{ 10268c2ecf20Sopenharmony_ci platform_driver_unregister(&s1d13xxxfb_driver); 10278c2ecf20Sopenharmony_ci} 10288c2ecf20Sopenharmony_ci 10298c2ecf20Sopenharmony_cimodule_init(s1d13xxxfb_init); 10308c2ecf20Sopenharmony_cimodule_exit(s1d13xxxfb_exit); 10318c2ecf20Sopenharmony_ci 10328c2ecf20Sopenharmony_ci 10338c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL"); 10348c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Framebuffer driver for S1D13xxx devices"); 10358c2ecf20Sopenharmony_ciMODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>, Thibaut VARENE <varenet@parisc-linux.org>"); 1036