ark1668e_display_cfg.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. #include <common.h>
  2. #include <dm.h>
  3. #include <display.h>
  4. #include "ark1668e_lcd.h"
  5. #define UPDATING_WIDTH 200
  6. #define UPDATING_HEIGHT 20
  7. #define PROGRESS_WIDTH 200
  8. #define PROGRESS_HEIGHT 32
  9. #define UPDATE_LOGO_WIDTH PROGRESS_WIDTH
  10. #define UPDATE_LOGO_HEIGHT (UPDATING_HEIGHT+PROGRESS_HEIGHT)
  11. #if 1
  12. //chinese
  13. #define UPDATING_POINT_COUNT 397
  14. static unsigned short updating[UPDATING_POINT_COUNT] =
  15. {
  16. 810, 821, 828, 840, 866, 878, 883, 894, 900, 1008, 1009, 1010, 1021, 1024, 1025, 1026,
  17. 1027, 1028, 1040, 1060, 1066, 1076, 1077, 1078, 1079, 1080, 1083, 1086, 1093, 1094, 1096, 1097,
  18. 1098, 1099, 1100, 1206, 1207, 1210, 1220, 1223, 1224, 1225, 1227, 1228, 1240, 1260, 1261, 1263,
  19. 1264, 1265, 1266, 1267, 1268, 1269, 1275, 1276, 1277, 1280, 1281, 1283, 1285, 1293, 1299, 1404,
  20. 1405, 1406, 1407, 1410, 1420, 1422, 1425, 1427, 1436, 1440, 1441, 1442, 1443, 1444, 1445, 1461,
  21. 1466, 1467, 1468, 1477, 1481, 1483, 1484, 1492, 1494, 1498, 1499, 1500, 1501, 1502, 1603, 1606,
  22. 1610, 1619, 1621, 1622, 1624, 1627, 1628, 1629, 1636, 1637, 1638, 1639, 1640, 1641, 1644, 1645,
  23. 1664, 1665, 1666, 1667, 1669, 1677, 1678, 1679, 1680, 1683, 1684, 1685, 1686, 1692, 1694, 1695,
  24. 1696, 1697, 1698, 1702, 1806, 1810, 1812, 1813, 1814, 1818, 1819, 1820, 1821, 1824, 1825, 1826,
  25. 1827, 1828, 1829, 1836, 1840, 1844, 1859, 1860, 1861, 1862, 1863, 1864, 1865, 1866, 1867, 1868,
  26. 1869, 1870, 1874, 1875, 1876, 1877, 1880, 1881, 1882, 1883, 1884, 1885, 1891, 1892, 1894, 1896,
  27. 1897, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2014, 2020, 2024, 2025, 2028,
  28. 2036, 2040, 2044, 2058, 2059, 2060, 2063, 2068, 2076, 2077, 2078, 2080, 2085, 2090, 2092, 2094,
  29. 2096, 2097, 2098, 2099, 2100, 2101, 2206, 2210, 2219, 2220, 2221, 2222, 2223, 2224, 2226, 2227,
  30. 2228, 2236, 2237, 2238, 2239, 2240, 2241, 2242, 2243, 2244, 2245, 2260, 2264, 2265, 2266, 2267,
  31. 2268, 2276, 2277, 2279, 2280, 2281, 2282, 2283, 2284, 2285, 2292, 2294, 2295, 2296, 2298, 2406,
  32. 2410, 2419, 2420, 2423, 2426, 2427, 2436, 2440, 2460, 2464, 2465, 2466, 2467, 2468, 2475, 2477,
  33. 2480, 2485, 2492, 2494, 2498, 2499, 2500, 2501, 2502, 2606, 2610, 2621, 2622, 2623, 2626, 2627,
  34. 2640, 2660, 2662, 2663, 2664, 2668, 2674, 2675, 2677, 2680, 2681, 2682, 2683, 2684, 2685, 2692,
  35. 2694, 2695, 2696, 2697, 2698, 2805, 2810, 2820, 2821, 2822, 2825, 2826, 2827, 2840, 2851, 2852,
  36. 2860, 2861, 2862, 2864, 2865, 2866, 2867, 2868, 2874, 2877, 2880, 2885, 2892, 2897, 2899, 3004,
  37. 3005, 3010, 3018, 3019, 3021, 3022, 3024, 3025, 3028, 3040, 3051, 3052, 3060, 3061, 3064, 3068,
  38. 3077, 3080, 3083, 3085, 3092, 3096, 3100, 3106, 3107, 3114, 3115, 3122, 3123, 3203, 3204, 3210,
  39. 3221, 3223, 3224, 3228, 3229, 3230, 3240, 3252, 3264, 3266, 3267, 3268, 3277, 3280, 3284, 3285,
  40. 3292, 3295, 3296, 3300, 3301, 3403, 3422, 3423, 3451, 3464, 3494, 3495, 3502,
  41. };
  42. #else
  43. //english
  44. #define UPDATING_POINT_COUNT 237
  45. static unsigned short updating[UPDATING_POINT_COUNT] =
  46. {
  47. 1021, 1022, 1023, 1044, 1045, 1222, 1223, 1235, 1236, 1422, 1423, 1435, 1436, 1601, 1602, 1603,
  48. 1605, 1606, 1607, 1609, 1610, 1611, 1612, 1613, 1614, 1619, 1620, 1621, 1622, 1623, 1627, 1628,
  49. 1629, 1630, 1633, 1634, 1635, 1636, 1637, 1638, 1642, 1643, 1644, 1645, 1649, 1650, 1652, 1653,
  50. 1654, 1659, 1660, 1661, 1662, 1663, 1802, 1803, 1806, 1807, 1810, 1811, 1814, 1815, 1818, 1819,
  51. 1822, 1823, 1826, 1827, 1830, 1831, 1835, 1836, 1844, 1845, 1850, 1851, 1852, 1854, 1855, 1858,
  52. 1859, 1861, 1862, 2002, 2003, 2006, 2007, 2010, 2011, 2014, 2015, 2018, 2019, 2022, 2023, 2028,
  53. 2029, 2030, 2031, 2035, 2036, 2044, 2045, 2050, 2054, 2055, 2058, 2059, 2061, 2062, 2202, 2203,
  54. 2206, 2207, 2210, 2211, 2214, 2215, 2218, 2219, 2222, 2223, 2227, 2228, 2230, 2231, 2235, 2236,
  55. 2244, 2245, 2250, 2254, 2255, 2259, 2260, 2261, 2402, 2403, 2406, 2407, 2410, 2411, 2414, 2415,
  56. 2418, 2419, 2422, 2423, 2426, 2427, 2430, 2431, 2435, 2436, 2444, 2445, 2450, 2454, 2455, 2458,
  57. 2459, 2466, 2467, 2468, 2474, 2475, 2476, 2482, 2483, 2484, 2603, 2604, 2605, 2606, 2607, 2608,
  58. 2610, 2611, 2612, 2613, 2614, 2619, 2620, 2621, 2622, 2623, 2624, 2627, 2628, 2629, 2630, 2631,
  59. 2632, 2636, 2637, 2638, 2642, 2643, 2644, 2645, 2646, 2647, 2649, 2650, 2651, 2652, 2654, 2655,
  60. 2656, 2658, 2659, 2660, 2661, 2662, 2666, 2667, 2668, 2674, 2675, 2676, 2682, 2683, 2684, 2810,
  61. 2811, 2858, 2859, 2862, 2863, 3009, 3010, 3011, 3012, 3059, 3060, 3061, 3062,
  62. };
  63. #endif
  64. #define UPDATELOGO_DISPLAY_ADDR 0x4E200000
  65. #define UPDATE_PWM_LED_BLINKING
  66. static int screen_width, screen_height;
  67. static struct udevice *g_dp;
  68. #ifdef UPDATE_PWM_LED_BLINKING
  69. #include <pwm.h>
  70. static void update_led_blinking(int start)
  71. {
  72. #define BACKLIGHT_PWM_PERIOD 500000000
  73. u32 pwm_id = 1;
  74. /* pad config */
  75. if(pwm_id < 4) {
  76. u32 val = rSYS_PAD_CTRL05;
  77. u32 offset = pwm_id * 3;
  78. val &= ~(0x7<<offset);
  79. val |= (0x1<<offset);
  80. rSYS_PAD_CTRL05 = val;
  81. }
  82. if(start) {
  83. u32 duty = BACKLIGHT_PWM_PERIOD / 2;
  84. pwm_config(pwm_id, duty, BACKLIGHT_PWM_PERIOD);
  85. pwm_enable(pwm_id);
  86. } else {
  87. pwm_disable(pwm_id);
  88. pwm_config(pwm_id, 0, BACKLIGHT_PWM_PERIOD);
  89. }
  90. }
  91. #endif
  92. static void updating_init(void)
  93. {
  94. int i;
  95. unsigned int *p = (unsigned int *)(UPDATELOGO_DISPLAY_ADDR);
  96. unsigned int color = 0xffffffff;
  97. int pos = 0;
  98. for (i = 0; i < UPDATING_WIDTH*UPDATING_HEIGHT; i++) {
  99. if (updating[pos] == i) {
  100. *p = color;
  101. pos++;
  102. }
  103. p++;
  104. }
  105. }
  106. static void update_progress_init(void)
  107. {
  108. int i, j;
  109. unsigned int *p = (unsigned int *)(UPDATELOGO_DISPLAY_ADDR + UPDATING_HEIGHT*PROGRESS_WIDTH*4);
  110. int height = UPDATE_LOGO_HEIGHT;
  111. unsigned int color = 0xffffffff;
  112. for (j = UPDATING_HEIGHT; j < height; j++) {
  113. for (i = 0; i < PROGRESS_WIDTH; i++) {
  114. if (j < (UPDATING_HEIGHT + 2) || j > (height -3) || \
  115. i < 2 || i > (PROGRESS_WIDTH -3)) {
  116. *p = color;
  117. }
  118. p++;
  119. }
  120. }
  121. }
  122. static void update_progress_set(int percent)
  123. {
  124. int i, j, end;;
  125. unsigned int *p = (unsigned int *)(UPDATELOGO_DISPLAY_ADDR + UPDATING_HEIGHT*PROGRESS_WIDTH*4);
  126. int height = UPDATE_LOGO_HEIGHT;
  127. unsigned int color = 0xff00ff00;
  128. if (percent < 0 || percent > 100) {
  129. printf("update progress percent=%d, error.",percent);
  130. return;
  131. }
  132. end = percent * (PROGRESS_WIDTH-3)/100;
  133. for (j = UPDATING_HEIGHT; j < height; j++) {
  134. for (i = 0; i < PROGRESS_WIDTH; i++) {
  135. if (j > (UPDATING_HEIGHT + 2) && j < (height -3) \
  136. && i > 2 && i < end) {
  137. *p = color;
  138. }
  139. p++;
  140. }
  141. }
  142. if (percent == 100) {
  143. udelay(500000);
  144. ark_osd_en_layer(OSD2_LAYER, 0);
  145. if (g_dp)
  146. display_disable(g_dp);
  147. } else if (percent >= 90) {
  148. udelay(200000);
  149. }
  150. }
  151. static void display_updatelogo(void)
  152. {
  153. int x, y;
  154. unsigned int width = UPDATE_LOGO_WIDTH;
  155. unsigned int height = UPDATE_LOGO_HEIGHT;
  156. memset((void *)UPDATELOGO_DISPLAY_ADDR, 0 , width * height * 4);
  157. updating_init();
  158. update_progress_init();
  159. ark_set_osd_image(OSD2_LAYER, DISP_RGB_888, width, height);
  160. ark_set_osd_addr(OSD2_LAYER, UPDATELOGO_DISPLAY_ADDR);
  161. x = (screen_width - width) / 2;
  162. y = (screen_height - height) / 2;
  163. ark_disp_set_osd_layer_position(OSD2_LAYER, x, y);
  164. }
  165. void ark_display_init(void)
  166. {
  167. struct udevice *dp;
  168. struct display_timing timing;
  169. int ret;
  170. ret = uclass_first_device(UCLASS_DISPLAY, &dp);
  171. if (ret) {
  172. printf("%s: Display device error %d\n", __func__, ret);
  173. return;
  174. }
  175. g_dp = dp;
  176. ret = display_read_timing(dp, &timing);
  177. if (ret) {
  178. printf("%s: Display read timing error %d\n", __func__, ret);
  179. return;
  180. }
  181. screen_width = timing.hactive.typ;
  182. screen_height = timing.vactive.typ;
  183. display_updatelogo();
  184. ret = display_enable(dp, 24, NULL);
  185. if (ret) {
  186. printf("%s: Display enable error %d\n", __func__, ret);
  187. return;
  188. }
  189. }
  190. int do_disconfig (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  191. {
  192. unsigned long percent = 0;
  193. int ret;
  194. if(argc < 2)
  195. return cmd_usage(cmdtp);
  196. ret = strict_strtoul(argv[1], 10, &percent);
  197. if (ret < 0) {
  198. printf("error format screen id\n");
  199. }
  200. if (percent > 100) {
  201. printf("Invalide param.\n");
  202. return cmd_usage(cmdtp);
  203. }
  204. if (percent == 0) {
  205. #ifdef UPDATE_PWM_LED_BLINKING
  206. update_led_blinking(1);
  207. #endif
  208. ark_display_init();
  209. } else {
  210. update_progress_set(percent);
  211. #ifdef UPDATE_PWM_LED_BLINKING
  212. if(percent == 100)
  213. update_led_blinking(0);
  214. #endif
  215. }
  216. return 0;
  217. }
  218. /***************************************************/
  219. U_BOOT_CMD(
  220. disconfig, CONFIG_SYS_MAXARGS, 0, do_disconfig,
  221. "config display",
  222. "disconfig percent\n"
  223. "percent(0:) \n"
  224. );