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 261acafc73SSimon Glass /* 271acafc73SSimon Glass * Bits per pixel selector. Each value n is such that the bits-per-pixel is 281acafc73SSimon Glass * 2 ^ n 291acafc73SSimon Glass */ 301acafc73SSimon Glass enum video_log2_bpp { 311acafc73SSimon Glass VIDEO_BPP1 = 0, 321acafc73SSimon Glass VIDEO_BPP2, 331acafc73SSimon Glass VIDEO_BPP4, 341acafc73SSimon Glass VIDEO_BPP8, 351acafc73SSimon Glass VIDEO_BPP16, 361acafc73SSimon Glass VIDEO_BPP32, 371acafc73SSimon Glass }; 381acafc73SSimon Glass 391acafc73SSimon Glass /* 401acafc73SSimon Glass * Convert enum video_log2_bpp to bytes and bits. Note we omit the outer 411acafc73SSimon Glass * brackets to allow multiplication by fractional pixels. 421acafc73SSimon Glass */ 431acafc73SSimon Glass #define VNBYTES(bpix) (1 << (bpix)) / 8 441acafc73SSimon Glass 451acafc73SSimon Glass #define VNBITS(bpix) (1 << (bpix)) 461acafc73SSimon Glass 471acafc73SSimon Glass /** 481acafc73SSimon Glass * struct video_priv - Device information used by the video uclass 491acafc73SSimon Glass * 501acafc73SSimon Glass * @xsize: Number of pixel columns (e.g. 1366) 511acafc73SSimon Glass * @ysize: Number of pixels rows (e.g.. 768) 521acafc73SSimon Glass * @tor: Display rotation (0=none, 1=90 degrees clockwise, etc.) 531acafc73SSimon Glass * @bpix: Encoded bits per pixel 541acafc73SSimon Glass * @fb: Frame buffer 551acafc73SSimon Glass * @fb_size: Frame buffer size 561acafc73SSimon Glass * @line_length: Length of each frame buffer line, in bytes 571acafc73SSimon Glass * @colour_fg: Foreground colour (pixel value) 581acafc73SSimon Glass * @colour_bg: Background colour (pixel value) 591acafc73SSimon Glass * @flush_dcache: true to enable flushing of the data cache after 601acafc73SSimon Glass * the LCD is updated 611acafc73SSimon Glass * @cmap: Colour map for 8-bit-per-pixel displays 621acafc73SSimon Glass */ 631acafc73SSimon Glass struct video_priv { 641acafc73SSimon Glass /* Things set up by the driver: */ 651acafc73SSimon Glass ushort xsize; 661acafc73SSimon Glass ushort ysize; 671acafc73SSimon Glass ushort rot; 681acafc73SSimon Glass enum video_log2_bpp bpix; 691acafc73SSimon Glass 701acafc73SSimon Glass /* 711acafc73SSimon Glass * Things that are private to the uclass: don't use these in the 721acafc73SSimon Glass * driver 731acafc73SSimon Glass */ 741acafc73SSimon Glass void *fb; 751acafc73SSimon Glass int fb_size; 761acafc73SSimon Glass int line_length; 771acafc73SSimon Glass int colour_fg; 781acafc73SSimon Glass int colour_bg; 791acafc73SSimon Glass bool flush_dcache; 801acafc73SSimon Glass ushort *cmap; 811acafc73SSimon Glass }; 821acafc73SSimon Glass 831acafc73SSimon Glass /* Placeholder - there are no video operations at present */ 841acafc73SSimon Glass struct video_ops { 851acafc73SSimon Glass }; 861acafc73SSimon Glass 871acafc73SSimon Glass #define video_get_ops(dev) ((struct video_ops *)(dev)->driver->ops) 881acafc73SSimon Glass 891acafc73SSimon Glass /** 901acafc73SSimon Glass * video_reserve() - Reserve frame-buffer memory for video devices 911acafc73SSimon Glass * 921acafc73SSimon Glass * Note: This function is for internal use. 931acafc73SSimon Glass * 941acafc73SSimon Glass * This uses the uclass platdata's @size and @align members to figure out 951acafc73SSimon Glass * a size and position for each frame buffer as part of the pre-relocation 961acafc73SSimon Glass * process of determining the post-relocation memory layout. 971acafc73SSimon Glass * 981acafc73SSimon Glass * gd->video_top is set to the initial value of *@addrp and gd->video_bottom 991acafc73SSimon Glass * is set to the final value. 1001acafc73SSimon Glass * 1011acafc73SSimon Glass * @addrp: On entry, the top of available memory. On exit, the new top, 1021acafc73SSimon Glass * after allocating the required memory. 1031acafc73SSimon Glass * @return 0 1041acafc73SSimon Glass */ 1051acafc73SSimon Glass int video_reserve(ulong *addrp); 1061acafc73SSimon Glass 1071acafc73SSimon Glass /** 1081acafc73SSimon Glass * video_sync() - Sync a device's frame buffer with its hardware 1091acafc73SSimon Glass * 1101acafc73SSimon Glass * Some frame buffers are cached or have a secondary frame buffer. This 1111acafc73SSimon Glass * function syncs these up so that the current contents of the U-Boot frame 1121acafc73SSimon Glass * buffer are displayed to the user. 1131acafc73SSimon Glass * 1141acafc73SSimon Glass * @dev: Device to sync 1151acafc73SSimon Glass */ 1161acafc73SSimon Glass void video_sync(struct udevice *vid); 1171acafc73SSimon Glass 1181acafc73SSimon Glass /** 1191acafc73SSimon Glass * video_sync_all() - Sync all devices' frame buffers with there hardware 1201acafc73SSimon Glass * 1211acafc73SSimon Glass * This calls video_sync() on all active video devices. 1221acafc73SSimon Glass */ 1231acafc73SSimon Glass void video_sync_all(void); 1241acafc73SSimon Glass 1251acafc73SSimon Glass /** 1261acafc73SSimon Glass * video_bmp_display() - Display a BMP file 1271acafc73SSimon Glass * 1281acafc73SSimon Glass * @dev: Device to display the bitmap on 1291acafc73SSimon Glass * @bmp_image: Address of bitmap image to display 1301acafc73SSimon Glass * @x: X position in pixels from the left 1311acafc73SSimon Glass * @y: Y position in pixels from the top 1321acafc73SSimon Glass * @align: true to adjust the coordinates to centre the image. If false 1331acafc73SSimon Glass * the coordinates are used as is. If true: 1341acafc73SSimon Glass * 1351acafc73SSimon Glass * - if a coordinate is 0x7fff then the image will be centred in 1361acafc73SSimon Glass * that direction 1371acafc73SSimon Glass * - if a coordinate is -ve then it will be offset to the 1381acafc73SSimon Glass * left/top of the centre by that many pixels 1391acafc73SSimon Glass * - if a coordinate is positive it will be used unchnaged. 1401acafc73SSimon Glass * @return 0 if OK, -ve on error 1411acafc73SSimon Glass */ 1421acafc73SSimon Glass int video_bmp_display(struct udevice *dev, ulong bmp_image, int x, int y, 1431acafc73SSimon Glass bool align); 1441acafc73SSimon Glass 1451acafc73SSimon Glass /** 1461acafc73SSimon Glass * video_get_xsize() - Get the width of the display in pixels 1471acafc73SSimon Glass * 1481acafc73SSimon Glass * @dev: Device to check 1491acafc73SSimon Glass * @return device frame buffer width in pixels 1501acafc73SSimon Glass */ 1511acafc73SSimon Glass int video_get_xsize(struct udevice *dev); 1521acafc73SSimon Glass 1531acafc73SSimon Glass /** 1541acafc73SSimon Glass * video_get_ysize() - Get the height of the display in pixels 1551acafc73SSimon Glass * 1561acafc73SSimon Glass * @dev: Device to check 1571acafc73SSimon Glass * @return device frame buffer height in pixels 1581acafc73SSimon Glass */ 1591acafc73SSimon Glass int video_get_ysize(struct udevice *dev); 1601acafc73SSimon Glass 161*68dcdc99SSimon Glass /** 162*68dcdc99SSimon Glass * Set whether we need to flush the dcache when changing the image. This 163*68dcdc99SSimon Glass * defaults to off. 164*68dcdc99SSimon Glass * 165*68dcdc99SSimon Glass * @param flush non-zero to flush cache after update, 0 to skip 166*68dcdc99SSimon Glass */ 167*68dcdc99SSimon Glass void video_set_flush_dcache(struct udevice *dev, bool flush); 168*68dcdc99SSimon Glass 1691acafc73SSimon Glass #endif /* CONFIG_DM_VIDEO */ 1701acafc73SSimon Glass 1711acafc73SSimon Glass #ifndef CONFIG_DM_VIDEO 1721acafc73SSimon Glass 173167c5898Swdenk /* Video functions */ 174167c5898Swdenk 175709ea543SSimon Glass struct stdio_dev; 176709ea543SSimon Glass 177167c5898Swdenk int video_init(void *videobase); 178709ea543SSimon Glass void video_putc(struct stdio_dev *dev, const char c); 179709ea543SSimon Glass void video_puts(struct stdio_dev *dev, const char *s); 180167c5898Swdenk 181f674f7cfSStefan Reinauer /** 182f674f7cfSStefan Reinauer * Display a BMP format bitmap on the screen 183f674f7cfSStefan Reinauer * 184f674f7cfSStefan Reinauer * @param bmp_image Address of BMP image 185f674f7cfSStefan Reinauer * @param x X position to draw image 186f674f7cfSStefan Reinauer * @param y Y position to draw image 187f674f7cfSStefan Reinauer */ 188f674f7cfSStefan Reinauer int video_display_bitmap(ulong bmp_image, int x, int y); 189f674f7cfSStefan Reinauer 190f674f7cfSStefan Reinauer /** 191f674f7cfSStefan Reinauer * Get the width of the screen in pixels 192f674f7cfSStefan Reinauer * 193f674f7cfSStefan Reinauer * @return width of screen in pixels 194f674f7cfSStefan Reinauer */ 195f674f7cfSStefan Reinauer int video_get_pixel_width(void); 196f674f7cfSStefan Reinauer 197f674f7cfSStefan Reinauer /** 198f674f7cfSStefan Reinauer * Get the height of the screen in pixels 199f674f7cfSStefan Reinauer * 200f674f7cfSStefan Reinauer * @return height of screen in pixels 201f674f7cfSStefan Reinauer */ 202f674f7cfSStefan Reinauer int video_get_pixel_height(void); 203f674f7cfSStefan Reinauer 204f674f7cfSStefan Reinauer /** 205f674f7cfSStefan Reinauer * Get the number of text lines/rows on the screen 206f674f7cfSStefan Reinauer * 207f674f7cfSStefan Reinauer * @return number of rows 208f674f7cfSStefan Reinauer */ 209f674f7cfSStefan Reinauer int video_get_screen_rows(void); 210f674f7cfSStefan Reinauer 211f674f7cfSStefan Reinauer /** 212f674f7cfSStefan Reinauer * Get the number of text columns on the screen 213f674f7cfSStefan Reinauer * 214f674f7cfSStefan Reinauer * @return number of columns 215f674f7cfSStefan Reinauer */ 216f674f7cfSStefan Reinauer int video_get_screen_columns(void); 217f674f7cfSStefan Reinauer 218f674f7cfSStefan Reinauer /** 219f674f7cfSStefan Reinauer * Set the position of the text cursor 220f674f7cfSStefan Reinauer * 221f674f7cfSStefan Reinauer * @param col Column to place cursor (0 = left side) 222f674f7cfSStefan Reinauer * @param row Row to place cursor (0 = top line) 223f674f7cfSStefan Reinauer */ 224f674f7cfSStefan Reinauer void video_position_cursor(unsigned col, unsigned row); 225f674f7cfSStefan Reinauer 226f674f7cfSStefan Reinauer /* Clear the display */ 227f674f7cfSStefan Reinauer void video_clear(void); 228f674f7cfSStefan Reinauer 229b26354cfSHeiko Schocher #if defined(CONFIG_FORMIKE) 230b26354cfSHeiko Schocher int kwh043st20_f01_spi_startup(unsigned int bus, unsigned int cs, 231b26354cfSHeiko Schocher unsigned int max_hz, unsigned int spi_mode); 232b26354cfSHeiko Schocher #endif 233fc1a79d9SHeiko Schocher #if defined(CONFIG_LG4573) 234fc1a79d9SHeiko Schocher int lg4573_spi_startup(unsigned int bus, unsigned int cs, 235fc1a79d9SHeiko Schocher unsigned int max_hz, unsigned int spi_mode); 236fc1a79d9SHeiko Schocher #endif 2371acafc73SSimon Glass 2381acafc73SSimon Glass #endif /* CONFIG_DM_VIDEO */ 2391acafc73SSimon Glass 240167c5898Swdenk #endif 241