1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * Video uclass and legacy implementation 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * Copyright (c) 2015 Google, Inc 5*4882a593Smuzhiyun * 6*4882a593Smuzhiyun * MPC823 Video Controller 7*4882a593Smuzhiyun * ======================= 8*4882a593Smuzhiyun * (C) 2000 by Paolo Scaffardi (arsenio@tin.it) 9*4882a593Smuzhiyun * AIRVENT SAM s.p.a - RIMINI(ITALY) 10*4882a593Smuzhiyun * 11*4882a593Smuzhiyun */ 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun #ifndef _VIDEO_H_ 14*4882a593Smuzhiyun #define _VIDEO_H_ 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun #ifdef CONFIG_DM_VIDEO 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun #include <stdio_dev.h> 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun struct video_uc_platdata { 21*4882a593Smuzhiyun uint align; 22*4882a593Smuzhiyun uint size; 23*4882a593Smuzhiyun ulong base; 24*4882a593Smuzhiyun }; 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun enum video_polarity { 27*4882a593Smuzhiyun VIDEO_ACTIVE_HIGH, /* Pins are active high */ 28*4882a593Smuzhiyun VIDEO_ACTIVE_LOW, /* Pins are active low */ 29*4882a593Smuzhiyun }; 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun /* 32*4882a593Smuzhiyun * Bits per pixel selector. Each value n is such that the bits-per-pixel is 33*4882a593Smuzhiyun * 2 ^ n 34*4882a593Smuzhiyun */ 35*4882a593Smuzhiyun enum video_log2_bpp { 36*4882a593Smuzhiyun VIDEO_BPP1 = 0, 37*4882a593Smuzhiyun VIDEO_BPP2, 38*4882a593Smuzhiyun VIDEO_BPP4, 39*4882a593Smuzhiyun VIDEO_BPP8, 40*4882a593Smuzhiyun VIDEO_BPP16, 41*4882a593Smuzhiyun VIDEO_BPP32, 42*4882a593Smuzhiyun }; 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun /* 45*4882a593Smuzhiyun * Convert enum video_log2_bpp to bytes and bits. Note we omit the outer 46*4882a593Smuzhiyun * brackets to allow multiplication by fractional pixels. 47*4882a593Smuzhiyun */ 48*4882a593Smuzhiyun #define VNBYTES(bpix) (1 << (bpix)) / 8 49*4882a593Smuzhiyun 50*4882a593Smuzhiyun #define VNBITS(bpix) (1 << (bpix)) 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun /** 53*4882a593Smuzhiyun * struct video_priv - Device information used by the video uclass 54*4882a593Smuzhiyun * 55*4882a593Smuzhiyun * @xsize: Number of pixel columns (e.g. 1366) 56*4882a593Smuzhiyun * @ysize: Number of pixels rows (e.g.. 768) 57*4882a593Smuzhiyun * @rot: Display rotation (0=none, 1=90 degrees clockwise, etc.) 58*4882a593Smuzhiyun * @bpix: Encoded bits per pixel 59*4882a593Smuzhiyun * @vidconsole_drv_name: Driver to use for the text console, NULL to 60*4882a593Smuzhiyun * select automatically 61*4882a593Smuzhiyun * @font_size: Font size in pixels (0 to use a default value) 62*4882a593Smuzhiyun * @fb: Frame buffer 63*4882a593Smuzhiyun * @fb_size: Frame buffer size 64*4882a593Smuzhiyun * @line_length: Length of each frame buffer line, in bytes 65*4882a593Smuzhiyun * @colour_fg: Foreground colour (pixel value) 66*4882a593Smuzhiyun * @colour_bg: Background colour (pixel value) 67*4882a593Smuzhiyun * @flush_dcache: true to enable flushing of the data cache after 68*4882a593Smuzhiyun * the LCD is updated 69*4882a593Smuzhiyun * @cmap: Colour map for 8-bit-per-pixel displays 70*4882a593Smuzhiyun */ 71*4882a593Smuzhiyun struct video_priv { 72*4882a593Smuzhiyun /* Things set up by the driver: */ 73*4882a593Smuzhiyun ushort xsize; 74*4882a593Smuzhiyun ushort ysize; 75*4882a593Smuzhiyun ushort rot; 76*4882a593Smuzhiyun enum video_log2_bpp bpix; 77*4882a593Smuzhiyun const char *vidconsole_drv_name; 78*4882a593Smuzhiyun int font_size; 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun /* 81*4882a593Smuzhiyun * Things that are private to the uclass: don't use these in the 82*4882a593Smuzhiyun * driver 83*4882a593Smuzhiyun */ 84*4882a593Smuzhiyun void *fb; 85*4882a593Smuzhiyun int fb_size; 86*4882a593Smuzhiyun int line_length; 87*4882a593Smuzhiyun int colour_fg; 88*4882a593Smuzhiyun int colour_bg; 89*4882a593Smuzhiyun bool flush_dcache; 90*4882a593Smuzhiyun ushort *cmap; 91*4882a593Smuzhiyun }; 92*4882a593Smuzhiyun 93*4882a593Smuzhiyun /* Placeholder - there are no video operations at present */ 94*4882a593Smuzhiyun struct video_ops { 95*4882a593Smuzhiyun }; 96*4882a593Smuzhiyun 97*4882a593Smuzhiyun #define video_get_ops(dev) ((struct video_ops *)(dev)->driver->ops) 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun /** 100*4882a593Smuzhiyun * video_reserve() - Reserve frame-buffer memory for video devices 101*4882a593Smuzhiyun * 102*4882a593Smuzhiyun * Note: This function is for internal use. 103*4882a593Smuzhiyun * 104*4882a593Smuzhiyun * This uses the uclass platdata's @size and @align members to figure out 105*4882a593Smuzhiyun * a size and position for each frame buffer as part of the pre-relocation 106*4882a593Smuzhiyun * process of determining the post-relocation memory layout. 107*4882a593Smuzhiyun * 108*4882a593Smuzhiyun * gd->video_top is set to the initial value of *@addrp and gd->video_bottom 109*4882a593Smuzhiyun * is set to the final value. 110*4882a593Smuzhiyun * 111*4882a593Smuzhiyun * @addrp: On entry, the top of available memory. On exit, the new top, 112*4882a593Smuzhiyun * after allocating the required memory. 113*4882a593Smuzhiyun * @return 0 114*4882a593Smuzhiyun */ 115*4882a593Smuzhiyun int video_reserve(ulong *addrp); 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun /** 118*4882a593Smuzhiyun * video_sync() - Sync a device's frame buffer with its hardware 119*4882a593Smuzhiyun * 120*4882a593Smuzhiyun * Some frame buffers are cached or have a secondary frame buffer. This 121*4882a593Smuzhiyun * function syncs these up so that the current contents of the U-Boot frame 122*4882a593Smuzhiyun * buffer are displayed to the user. 123*4882a593Smuzhiyun * 124*4882a593Smuzhiyun * @dev: Device to sync 125*4882a593Smuzhiyun */ 126*4882a593Smuzhiyun void video_sync(struct udevice *vid); 127*4882a593Smuzhiyun 128*4882a593Smuzhiyun /** 129*4882a593Smuzhiyun * video_sync_all() - Sync all devices' frame buffers with there hardware 130*4882a593Smuzhiyun * 131*4882a593Smuzhiyun * This calls video_sync() on all active video devices. 132*4882a593Smuzhiyun */ 133*4882a593Smuzhiyun void video_sync_all(void); 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun /** 136*4882a593Smuzhiyun * video_bmp_display() - Display a BMP file 137*4882a593Smuzhiyun * 138*4882a593Smuzhiyun * @dev: Device to display the bitmap on 139*4882a593Smuzhiyun * @bmp_image: Address of bitmap image to display 140*4882a593Smuzhiyun * @x: X position in pixels from the left 141*4882a593Smuzhiyun * @y: Y position in pixels from the top 142*4882a593Smuzhiyun * @align: true to adjust the coordinates to centre the image. If false 143*4882a593Smuzhiyun * the coordinates are used as is. If true: 144*4882a593Smuzhiyun * 145*4882a593Smuzhiyun * - if a coordinate is 0x7fff then the image will be centred in 146*4882a593Smuzhiyun * that direction 147*4882a593Smuzhiyun * - if a coordinate is -ve then it will be offset to the 148*4882a593Smuzhiyun * left/top of the centre by that many pixels 149*4882a593Smuzhiyun * - if a coordinate is positive it will be used unchnaged. 150*4882a593Smuzhiyun * @return 0 if OK, -ve on error 151*4882a593Smuzhiyun */ 152*4882a593Smuzhiyun int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y, 153*4882a593Smuzhiyun bool align); 154*4882a593Smuzhiyun 155*4882a593Smuzhiyun /** 156*4882a593Smuzhiyun * video_get_xsize() - Get the width of the display in pixels 157*4882a593Smuzhiyun * 158*4882a593Smuzhiyun * @dev: Device to check 159*4882a593Smuzhiyun * @return device frame buffer width in pixels 160*4882a593Smuzhiyun */ 161*4882a593Smuzhiyun int video_get_xsize(struct udevice *dev); 162*4882a593Smuzhiyun 163*4882a593Smuzhiyun /** 164*4882a593Smuzhiyun * video_get_ysize() - Get the height of the display in pixels 165*4882a593Smuzhiyun * 166*4882a593Smuzhiyun * @dev: Device to check 167*4882a593Smuzhiyun * @return device frame buffer height in pixels 168*4882a593Smuzhiyun */ 169*4882a593Smuzhiyun int video_get_ysize(struct udevice *dev); 170*4882a593Smuzhiyun 171*4882a593Smuzhiyun /** 172*4882a593Smuzhiyun * Set whether we need to flush the dcache when changing the image. This 173*4882a593Smuzhiyun * defaults to off. 174*4882a593Smuzhiyun * 175*4882a593Smuzhiyun * @param flush non-zero to flush cache after update, 0 to skip 176*4882a593Smuzhiyun */ 177*4882a593Smuzhiyun void video_set_flush_dcache(struct udevice *dev, bool flush); 178*4882a593Smuzhiyun 179*4882a593Smuzhiyun #endif /* CONFIG_DM_VIDEO */ 180*4882a593Smuzhiyun 181*4882a593Smuzhiyun #ifndef CONFIG_DM_VIDEO 182*4882a593Smuzhiyun 183*4882a593Smuzhiyun /* Video functions */ 184*4882a593Smuzhiyun 185*4882a593Smuzhiyun struct stdio_dev; 186*4882a593Smuzhiyun 187*4882a593Smuzhiyun int video_init(void *videobase); 188*4882a593Smuzhiyun void video_putc(struct stdio_dev *dev, const char c); 189*4882a593Smuzhiyun void video_puts(struct stdio_dev *dev, const char *s); 190*4882a593Smuzhiyun 191*4882a593Smuzhiyun /** 192*4882a593Smuzhiyun * Display a BMP format bitmap on the screen 193*4882a593Smuzhiyun * 194*4882a593Smuzhiyun * @param bmp_image Address of BMP image 195*4882a593Smuzhiyun * @param x X position to draw image 196*4882a593Smuzhiyun * @param y Y position to draw image 197*4882a593Smuzhiyun */ 198*4882a593Smuzhiyun int video_display_bitmap(ulong bmp_image, int x, int y); 199*4882a593Smuzhiyun 200*4882a593Smuzhiyun /** 201*4882a593Smuzhiyun * Get the width of the screen in pixels 202*4882a593Smuzhiyun * 203*4882a593Smuzhiyun * @return width of screen in pixels 204*4882a593Smuzhiyun */ 205*4882a593Smuzhiyun int video_get_pixel_width(void); 206*4882a593Smuzhiyun 207*4882a593Smuzhiyun /** 208*4882a593Smuzhiyun * Get the height of the screen in pixels 209*4882a593Smuzhiyun * 210*4882a593Smuzhiyun * @return height of screen in pixels 211*4882a593Smuzhiyun */ 212*4882a593Smuzhiyun int video_get_pixel_height(void); 213*4882a593Smuzhiyun 214*4882a593Smuzhiyun /** 215*4882a593Smuzhiyun * Get the number of text lines/rows on the screen 216*4882a593Smuzhiyun * 217*4882a593Smuzhiyun * @return number of rows 218*4882a593Smuzhiyun */ 219*4882a593Smuzhiyun int video_get_screen_rows(void); 220*4882a593Smuzhiyun 221*4882a593Smuzhiyun /** 222*4882a593Smuzhiyun * Get the number of text columns on the screen 223*4882a593Smuzhiyun * 224*4882a593Smuzhiyun * @return number of columns 225*4882a593Smuzhiyun */ 226*4882a593Smuzhiyun int video_get_screen_columns(void); 227*4882a593Smuzhiyun 228*4882a593Smuzhiyun /** 229*4882a593Smuzhiyun * Set the position of the text cursor 230*4882a593Smuzhiyun * 231*4882a593Smuzhiyun * @param col Column to place cursor (0 = left side) 232*4882a593Smuzhiyun * @param row Row to place cursor (0 = top line) 233*4882a593Smuzhiyun */ 234*4882a593Smuzhiyun void video_position_cursor(unsigned col, unsigned row); 235*4882a593Smuzhiyun 236*4882a593Smuzhiyun /* Clear the display */ 237*4882a593Smuzhiyun void video_clear(void); 238*4882a593Smuzhiyun 239*4882a593Smuzhiyun #if defined(CONFIG_FORMIKE) 240*4882a593Smuzhiyun int kwh043st20_f01_spi_startup(unsigned int bus, unsigned int cs, 241*4882a593Smuzhiyun unsigned int max_hz, unsigned int spi_mode); 242*4882a593Smuzhiyun #endif 243*4882a593Smuzhiyun #if defined(CONFIG_LG4573) 244*4882a593Smuzhiyun int lg4573_spi_startup(unsigned int bus, unsigned int cs, 245*4882a593Smuzhiyun unsigned int max_hz, unsigned int spi_mode); 246*4882a593Smuzhiyun #endif 247*4882a593Smuzhiyun 248*4882a593Smuzhiyun /* 249*4882a593Smuzhiyun * video_get_info_str() - obtain a board string: type, speed, etc. 250*4882a593Smuzhiyun * 251*4882a593Smuzhiyun * This is called if CONFIG_CONSOLE_EXTRA_INFO is enabled. 252*4882a593Smuzhiyun * 253*4882a593Smuzhiyun * line_number: location to place info string beside logo 254*4882a593Smuzhiyun * info: buffer for info string (empty if nothing to display on this 255*4882a593Smuzhiyun * line) 256*4882a593Smuzhiyun */ 257*4882a593Smuzhiyun void video_get_info_str(int line_number, char *info); 258*4882a593Smuzhiyun 259*4882a593Smuzhiyun #endif /* CONFIG_DM_VIDEO */ 260*4882a593Smuzhiyun 261*4882a593Smuzhiyun #endif 262