1167c5898Swdenk /* 21acafc73SSimon Glass * Video uclass and legacy implementation 31acafc73SSimon Glass * 41acafc73SSimon Glass * Copyright (c) 2015 Google, Inc 51acafc73SSimon Glass * 61acafc73SSimon Glass * MPC823 Video Controller 71acafc73SSimon Glass * ======================= 81acafc73SSimon Glass * (C) 2000 by Paolo Scaffardi (arsenio@tin.it) 91acafc73SSimon Glass * AIRVENT SAM s.p.a - RIMINI(ITALY) 101acafc73SSimon Glass * 11167c5898Swdenk */ 12167c5898Swdenk 13167c5898Swdenk #ifndef _VIDEO_H_ 14167c5898Swdenk #define _VIDEO_H_ 15167c5898Swdenk 161acafc73SSimon Glass #ifdef CONFIG_DM_VIDEO 171acafc73SSimon Glass 181acafc73SSimon Glass #include <stdio_dev.h> 191acafc73SSimon Glass 201acafc73SSimon Glass struct video_uc_platdata { 211acafc73SSimon Glass uint align; 221acafc73SSimon Glass uint size; 231acafc73SSimon Glass ulong base; 241acafc73SSimon Glass }; 251acafc73SSimon Glass 2621c561b7SSimon Glass enum video_polarity { 2721c561b7SSimon Glass VIDEO_ACTIVE_HIGH, /* Pins are active high */ 2821c561b7SSimon Glass VIDEO_ACTIVE_LOW, /* Pins are active low */ 2921c561b7SSimon Glass }; 3021c561b7SSimon Glass 311acafc73SSimon Glass /* 321acafc73SSimon Glass * Bits per pixel selector. Each value n is such that the bits-per-pixel is 331acafc73SSimon Glass * 2 ^ n 341acafc73SSimon Glass */ 351acafc73SSimon Glass enum video_log2_bpp { 361acafc73SSimon Glass VIDEO_BPP1 = 0, 371acafc73SSimon Glass VIDEO_BPP2, 381acafc73SSimon Glass VIDEO_BPP4, 391acafc73SSimon Glass VIDEO_BPP8, 401acafc73SSimon Glass VIDEO_BPP16, 411acafc73SSimon Glass VIDEO_BPP32, 421acafc73SSimon Glass }; 431acafc73SSimon Glass 441acafc73SSimon Glass /* 451acafc73SSimon Glass * Convert enum video_log2_bpp to bytes and bits. Note we omit the outer 461acafc73SSimon Glass * brackets to allow multiplication by fractional pixels. 471acafc73SSimon Glass */ 481acafc73SSimon Glass #define VNBYTES(bpix) (1 << (bpix)) / 8 491acafc73SSimon Glass 501acafc73SSimon Glass #define VNBITS(bpix) (1 << (bpix)) 511acafc73SSimon Glass 521acafc73SSimon Glass /** 531acafc73SSimon Glass * struct video_priv - Device information used by the video uclass 541acafc73SSimon Glass * 551acafc73SSimon Glass * @xsize: Number of pixel columns (e.g. 1366) 561acafc73SSimon Glass * @ysize: Number of pixels rows (e.g.. 768) 578cdae1daSSimon Glass * @rot: Display rotation (0=none, 1=90 degrees clockwise, etc.) 588c466ed3SSimon Glass * @bpix: Encoded bits per pixel (enum video_log2_bpp) 59826f35f9SSimon Glass * @vidconsole_drv_name: Driver to use for the text console, NULL to 60826f35f9SSimon Glass * select automatically 61826f35f9SSimon Glass * @font_size: Font size in pixels (0 to use a default value) 621acafc73SSimon Glass * @fb: Frame buffer 631acafc73SSimon Glass * @fb_size: Frame buffer size 64*06696ebeSSimon Glass * @line_length: Length of each frame buffer line, in bytes. This can be 65*06696ebeSSimon Glass * set by the driver, but if not, the uclass will set it after 66*06696ebeSSimon Glass * probing 671acafc73SSimon Glass * @colour_fg: Foreground colour (pixel value) 681acafc73SSimon Glass * @colour_bg: Background colour (pixel value) 691acafc73SSimon Glass * @flush_dcache: true to enable flushing of the data cache after 701acafc73SSimon Glass * the LCD is updated 711acafc73SSimon Glass * @cmap: Colour map for 8-bit-per-pixel displays 729ffa4d12SHeinrich Schuchardt * @fg_col_idx: Foreground color code (bit 3 = bold, bit 0-2 = color) 731acafc73SSimon Glass */ 741acafc73SSimon Glass struct video_priv { 751acafc73SSimon Glass /* Things set up by the driver: */ 761acafc73SSimon Glass ushort xsize; 771acafc73SSimon Glass ushort ysize; 781acafc73SSimon Glass ushort rot; 791acafc73SSimon Glass enum video_log2_bpp bpix; 80826f35f9SSimon Glass const char *vidconsole_drv_name; 81826f35f9SSimon Glass int font_size; 821acafc73SSimon Glass 831acafc73SSimon Glass /* 841acafc73SSimon Glass * Things that are private to the uclass: don't use these in the 851acafc73SSimon Glass * driver 861acafc73SSimon Glass */ 871acafc73SSimon Glass void *fb; 881acafc73SSimon Glass int fb_size; 891acafc73SSimon Glass int line_length; 905c30fbb8SHeinrich Schuchardt u32 colour_fg; 915c30fbb8SHeinrich Schuchardt u32 colour_bg; 921acafc73SSimon Glass bool flush_dcache; 931acafc73SSimon Glass ushort *cmap; 949ffa4d12SHeinrich Schuchardt u8 fg_col_idx; 951acafc73SSimon Glass }; 961acafc73SSimon Glass 971acafc73SSimon Glass /* Placeholder - there are no video operations at present */ 981acafc73SSimon Glass struct video_ops { 991acafc73SSimon Glass }; 1001acafc73SSimon Glass 1011acafc73SSimon Glass #define video_get_ops(dev) ((struct video_ops *)(dev)->driver->ops) 1021acafc73SSimon Glass 1031acafc73SSimon Glass /** 1041acafc73SSimon Glass * video_reserve() - Reserve frame-buffer memory for video devices 1051acafc73SSimon Glass * 1061acafc73SSimon Glass * Note: This function is for internal use. 1071acafc73SSimon Glass * 1081acafc73SSimon Glass * This uses the uclass platdata's @size and @align members to figure out 1091acafc73SSimon Glass * a size and position for each frame buffer as part of the pre-relocation 1101acafc73SSimon Glass * process of determining the post-relocation memory layout. 1111acafc73SSimon Glass * 1121acafc73SSimon Glass * gd->video_top is set to the initial value of *@addrp and gd->video_bottom 1131acafc73SSimon Glass * is set to the final value. 1141acafc73SSimon Glass * 1151acafc73SSimon Glass * @addrp: On entry, the top of available memory. On exit, the new top, 1161acafc73SSimon Glass * after allocating the required memory. 1171acafc73SSimon Glass * @return 0 1181acafc73SSimon Glass */ 1191acafc73SSimon Glass int video_reserve(ulong *addrp); 1201acafc73SSimon Glass 1211acafc73SSimon Glass /** 122a085aa1fSRob Clark * video_clear() - Clear a device's frame buffer to background color. 123a085aa1fSRob Clark * 124a085aa1fSRob Clark * @dev: Device to clear 125c6ebd011SSimon Glass * @return 0 126a085aa1fSRob Clark */ 127c6ebd011SSimon Glass int video_clear(struct udevice *dev); 128a085aa1fSRob Clark 129a085aa1fSRob Clark /** 1301acafc73SSimon Glass * video_sync() - Sync a device's frame buffer with its hardware 1311acafc73SSimon Glass * 1321acafc73SSimon Glass * Some frame buffers are cached or have a secondary frame buffer. This 1331acafc73SSimon Glass * function syncs these up so that the current contents of the U-Boot frame 1341acafc73SSimon Glass * buffer are displayed to the user. 1351acafc73SSimon Glass * 1361acafc73SSimon Glass * @dev: Device to sync 13755d39911SSimon Glass * @force: True to force a sync even if there was one recently (this is 13855d39911SSimon Glass * very expensive on sandbox) 1391acafc73SSimon Glass */ 14055d39911SSimon Glass void video_sync(struct udevice *vid, bool force); 1411acafc73SSimon Glass 1421acafc73SSimon Glass /** 1431acafc73SSimon Glass * video_sync_all() - Sync all devices' frame buffers with there hardware 1441acafc73SSimon Glass * 1451acafc73SSimon Glass * This calls video_sync() on all active video devices. 1461acafc73SSimon Glass */ 1471acafc73SSimon Glass void video_sync_all(void); 1481acafc73SSimon Glass 1491acafc73SSimon Glass /** 1501acafc73SSimon Glass * video_bmp_display() - Display a BMP file 1511acafc73SSimon Glass * 1521acafc73SSimon Glass * @dev: Device to display the bitmap on 1531acafc73SSimon Glass * @bmp_image: Address of bitmap image to display 1541acafc73SSimon Glass * @x: X position in pixels from the left 1551acafc73SSimon Glass * @y: Y position in pixels from the top 1561acafc73SSimon Glass * @align: true to adjust the coordinates to centre the image. If false 1571acafc73SSimon Glass * the coordinates are used as is. If true: 1581acafc73SSimon Glass * 1591acafc73SSimon Glass * - if a coordinate is 0x7fff then the image will be centred in 1601acafc73SSimon Glass * that direction 1611acafc73SSimon Glass * - if a coordinate is -ve then it will be offset to the 1621acafc73SSimon Glass * left/top of the centre by that many pixels 1631acafc73SSimon Glass * - if a coordinate is positive it will be used unchnaged. 1641acafc73SSimon Glass * @return 0 if OK, -ve on error 1651acafc73SSimon Glass */ 1661acafc73SSimon Glass int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y, 1671acafc73SSimon Glass bool align); 1681acafc73SSimon Glass 1691acafc73SSimon Glass /** 1701acafc73SSimon Glass * video_get_xsize() - Get the width of the display in pixels 1711acafc73SSimon Glass * 1721acafc73SSimon Glass * @dev: Device to check 1731acafc73SSimon Glass * @return device frame buffer width in pixels 1741acafc73SSimon Glass */ 1751acafc73SSimon Glass int video_get_xsize(struct udevice *dev); 1761acafc73SSimon Glass 1771acafc73SSimon Glass /** 1781acafc73SSimon Glass * video_get_ysize() - Get the height of the display in pixels 1791acafc73SSimon Glass * 1801acafc73SSimon Glass * @dev: Device to check 1811acafc73SSimon Glass * @return device frame buffer height in pixels 1821acafc73SSimon Glass */ 1831acafc73SSimon Glass int video_get_ysize(struct udevice *dev); 1841acafc73SSimon Glass 18568dcdc99SSimon Glass /** 18668dcdc99SSimon Glass * Set whether we need to flush the dcache when changing the image. This 18768dcdc99SSimon Glass * defaults to off. 18868dcdc99SSimon Glass * 18968dcdc99SSimon Glass * @param flush non-zero to flush cache after update, 0 to skip 19068dcdc99SSimon Glass */ 19168dcdc99SSimon Glass void video_set_flush_dcache(struct udevice *dev, bool flush); 19268dcdc99SSimon Glass 1935c30fbb8SHeinrich Schuchardt /** 1945c30fbb8SHeinrich Schuchardt * Set default colors and attributes 1955c30fbb8SHeinrich Schuchardt * 196b9f210a3SSimon Glass * @dev: video device 197b9f210a3SSimon Glass * @invert true to invert colours 1985c30fbb8SHeinrich Schuchardt */ 199b9f210a3SSimon Glass void video_set_default_colors(struct udevice *dev, bool invert); 2005c30fbb8SHeinrich Schuchardt 2011acafc73SSimon Glass #endif /* CONFIG_DM_VIDEO */ 2021acafc73SSimon Glass 2031acafc73SSimon Glass #ifndef CONFIG_DM_VIDEO 2041acafc73SSimon Glass 205167c5898Swdenk /* Video functions */ 206167c5898Swdenk 207f674f7cfSStefan Reinauer /** 208f674f7cfSStefan Reinauer * Display a BMP format bitmap on the screen 209f674f7cfSStefan Reinauer * 210f674f7cfSStefan Reinauer * @param bmp_image Address of BMP image 211f674f7cfSStefan Reinauer * @param x X position to draw image 212f674f7cfSStefan Reinauer * @param y Y position to draw image 213f674f7cfSStefan Reinauer */ 214f674f7cfSStefan Reinauer int video_display_bitmap(ulong bmp_image, int x, int y); 215f674f7cfSStefan Reinauer 216f674f7cfSStefan Reinauer /** 217f674f7cfSStefan Reinauer * Get the width of the screen in pixels 218f674f7cfSStefan Reinauer * 219f674f7cfSStefan Reinauer * @return width of screen in pixels 220f674f7cfSStefan Reinauer */ 221f674f7cfSStefan Reinauer int video_get_pixel_width(void); 222f674f7cfSStefan Reinauer 223f674f7cfSStefan Reinauer /** 224f674f7cfSStefan Reinauer * Get the height of the screen in pixels 225f674f7cfSStefan Reinauer * 226f674f7cfSStefan Reinauer * @return height of screen in pixels 227f674f7cfSStefan Reinauer */ 228f674f7cfSStefan Reinauer int video_get_pixel_height(void); 229f674f7cfSStefan Reinauer 230f674f7cfSStefan Reinauer /** 231f674f7cfSStefan Reinauer * Get the number of text lines/rows on the screen 232f674f7cfSStefan Reinauer * 233f674f7cfSStefan Reinauer * @return number of rows 234f674f7cfSStefan Reinauer */ 235f674f7cfSStefan Reinauer int video_get_screen_rows(void); 236f674f7cfSStefan Reinauer 237f674f7cfSStefan Reinauer /** 238f674f7cfSStefan Reinauer * Get the number of text columns on the screen 239f674f7cfSStefan Reinauer * 240f674f7cfSStefan Reinauer * @return number of columns 241f674f7cfSStefan Reinauer */ 242f674f7cfSStefan Reinauer int video_get_screen_columns(void); 243f674f7cfSStefan Reinauer 244f674f7cfSStefan Reinauer /** 245f674f7cfSStefan Reinauer * Set the position of the text cursor 246f674f7cfSStefan Reinauer * 247f674f7cfSStefan Reinauer * @param col Column to place cursor (0 = left side) 248f674f7cfSStefan Reinauer * @param row Row to place cursor (0 = top line) 249f674f7cfSStefan Reinauer */ 250f674f7cfSStefan Reinauer void video_position_cursor(unsigned col, unsigned row); 251f674f7cfSStefan Reinauer 252f674f7cfSStefan Reinauer /* Clear the display */ 253f674f7cfSStefan Reinauer void video_clear(void); 254f674f7cfSStefan Reinauer 255b26354cfSHeiko Schocher #if defined(CONFIG_FORMIKE) 256b26354cfSHeiko Schocher int kwh043st20_f01_spi_startup(unsigned int bus, unsigned int cs, 257b26354cfSHeiko Schocher unsigned int max_hz, unsigned int spi_mode); 258b26354cfSHeiko Schocher #endif 259fc1a79d9SHeiko Schocher #if defined(CONFIG_LG4573) 260fc1a79d9SHeiko Schocher int lg4573_spi_startup(unsigned int bus, unsigned int cs, 261fc1a79d9SHeiko Schocher unsigned int max_hz, unsigned int spi_mode); 262fc1a79d9SHeiko Schocher #endif 2631acafc73SSimon Glass 2640a6eac84SSimon Glass /* 2650a6eac84SSimon Glass * video_get_info_str() - obtain a board string: type, speed, etc. 2660a6eac84SSimon Glass * 2670a6eac84SSimon Glass * This is called if CONFIG_CONSOLE_EXTRA_INFO is enabled. 2680a6eac84SSimon Glass * 2690a6eac84SSimon Glass * line_number: location to place info string beside logo 2700a6eac84SSimon Glass * info: buffer for info string (empty if nothing to display on this 2710a6eac84SSimon Glass * line) 2720a6eac84SSimon Glass */ 2730a6eac84SSimon Glass void video_get_info_str(int line_number, char *info); 2740a6eac84SSimon Glass 2758c466ed3SSimon Glass #endif /* !CONFIG_DM_VIDEO */ 2761acafc73SSimon Glass 277167c5898Swdenk #endif 278