| |
| <html> |
| <head> |
| <meta http-equiv="content-type" content="text/html; charset=utf-8"/> |
| <title>Android - Porting Guide</title> |
| <script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=internal-codesite" type="text/javascript"></script> |
| <script src="http://code.google.com/js/jquery.js" type="text/javascript"></script> |
| <script type="text/javascript">var _tocPath_ = 'http://code.google.com/android/_toc.ezt';</script> |
| <script src="http://code.google.com/js/codesite.pack.01312008.js" type="text/javascript"></script> |
| <script language="JavaScript"> |
| function resizeHeight() { |
| if(document.getElementById && !(document.all)) { |
| height= document.getElementById('doxygen').contentDocument.body.scrollHeight + 20; |
| document.getElementById('doxygen').style.height = height; |
| } |
| else if(document.all) { |
| height= document.frames('doxygen').document.body.scrollHeight + 20; |
| document.all.doxygen.style.height = height; |
| } |
| } |
| </script> |
| <link href="http://code.google.com/css/codesite.pack.01312008.css" type="text/css" rel="stylesheet"> |
| </link> |
| |
| <!--[if IE]><link rel="stylesheet" type="text/css" href="/css/iehacks.css" /><![endif]--> |
| <script src="http://code.google.com/android/assets/search_autocomplete.js"></script> |
| <link rel="stylesheet" type="text/css" href="http://code.google.com/css/semantic_headers.css" /> |
| <link rel="stylesheet" type="text/css" href="http://code.google.com/android/assets/style.css" /> |
| <script> |
| jQuery(document).ready(function() { |
| jQuery("pre").addClass("prettyprint"); |
| }); |
| </script> |
| <style type="text/css"> |
| <!-- |
| h1,h2,h3 { |
| color: #000000; |
| } |
| --> |
| </style> |
| </head> |
| <body class="gc-documentation"> |
| <div id="gc-container"> |
| <a name="top"></a> |
| <div id="skipto"> </div> |
| <div id="langpref"> |
| <!--<a class="dropdown" href="/">English</a> <span>|</span> <a href="/more/">Site Directory</a> --> |
| |
| </div> |
| <div id="gc-header"> |
| <div id="logo"><a href="http://code.google.com/android/index.html"><img src="http://code.google.com/android/images/logo_android.gif" alt="Android"/></a></div> |
| <div id="search" style="inline"> |
| <div id="searchForm" class="searchForm" style="height: 44px;"> |
| <!--previously form was here--> |
| </div> |
| <!-- end searchForm --> |
| <noscript> |
| <style type="text/css"> |
| .searchForm { |
| display : none !important; |
| } |
| .searchForm2 { |
| display : inline !important; |
| } |
| </style> |
| </noscript> |
| |
| <div id="searchForm2" class="searchForm2" style="display:none"> |
| <form id="searchbox_001456098540849067467:6whlsytkdqg" action="http://www.google.com/cse"> |
| <input type="hidden" name="cx" value="001456098540849067467:6whlsytkdqg" /> |
| <input type="hidden" name="cof" value="FORID:0" /> |
| <input type="text" name="q" maxlength="2048" size="41" autocomplete="off" title="Google Code Search"/> |
| <input type="submit" name="sa" value="Search" title="Search"/> |
| <br/> |
| <div class="greytext">e.g. "ajax apis" or "open source"</div> |
| |
| </form> |
| </div> |
| <!-- end searchForm2 --> |
| </div> |
| <!-- end search --> |
| </div> |
| <!-- end gc-header --> |
| <div id="searchControl" class="search-control"></div> |
| <!--[if IE]><iframe id="backiFrame" name="backiFrame" src='/dummy.html' style="display:none"></iframe><![endif]--> |
| <div id="codesiteContent"> |
| <a name="gc-topnav-anchor"></a> |
| <div id="gc-topnav"> |
| |
| <h1>Android Platform Development Kit</h1> |
| <ul class="gc-topnav-tabs"> |
| <li id="sdk_link"> <a href="http://code.google.com/android/index.html" title="Android Software Development Kit">SDK</a> </li> |
| <li id="docs_link"> <a href="index.html" title="Official Android documentation">Docs</a> </li> |
| <li id="faq_link"> <a href="http://code.google.com/android/kb/index.html" title="Answers to frequently asked questions about Android">FAQ</a> </li> |
| |
| <li> <a href="http://android-developers.blogspot.com/" title="Official Android blog">Blog</a> </li> |
| <li> <a href="http://code.google.com/android/groups.html" title="Android developer forum">Group</a> </li> |
| <li> <a href="http://code.google.com/android/terms.html" title="Android terms of service">Terms</a> </li> |
| <li> <a href="mailto:android-pdk-feedback@google.com?subject=PDK%20Feedback&body=(filed%20from:%20display_drivers.html%20v0.6%20-%2025%20November%202008)%0D%0A%0D%0ASUMMARY:%0D%0A%0D%0A%0D%0A%0D%0ASTEPS%20TO%20REPRODUCE:%0D%0A%0D%0A%0D%0A%0D%0AADDITIONAL%20NOTES:">Report a Problem</a> </li> |
| |
| </ul> |
| </div> |
| <!-- end gc-topnav --> |
| <div class="g-section g-tpl-180"> |
| <a name="gc-toc"></a> |
| <div class="g-unit g-first" id="gc-toc"> |
| <ul> |
| <li> |
| <h1><a href="index.html">Documentation</a></h1> |
| <ul> |
| <li> <strong>Introduction</strong> |
| |
| <ul> |
| <li><a href="system_requirements.html">Device Requirements</a></li> |
| </ul> |
| </li> |
| <li> <strong>Dev Environment Setup</strong> |
| <ul> |
| <li><a href="build_system.html">Build System</a></li> |
| </ul> |
| </li> |
| <li> <strong>Basic Bring up</strong> |
| |
| <ul> |
| <li><a href="build_new_device.html">Building New Device</a></li> |
| <li><a href="bring_up.html">Bring up</a></li> |
| <li><a href="keymaps_keyboard_input.html">Keymaps and Keyboard</a></li> |
| <li><a href="display_drivers.html">Display Drivers</a></li> |
| </ul> |
| </li> |
| |
| <li> <strong>Multimedia</strong> |
| <ul> |
| <li><a href="audio_sub_system.html">Audio</a></li> |
| <li><a href="camera.html">Camera</a></li> |
| </ul> |
| </li> |
| <li> <strong>Power Management</strong> |
| |
| <ul> |
| <li><a href="power_management.html">Power Management</a></li> |
| </ul> |
| </li> |
| |
| <li> <strong>Networking</strong> |
| <ul> |
| <li><a href="wifi.html">Wi-Fi</a></li> |
| <li><a href="gps.html">GPS</a></li> |
| <li><a href="bluetooth.html">Bluetooth</a></li> |
| </ul> |
| </li> |
| |
| <li> <strong>Telephony</strong> |
| <ul> |
| <li><a href="telephony.html">Radio Interface Layer</a></li> |
| |
| </ul> |
| </li> |
| <li> <strong>Testing</strong> |
| <ul> |
| <li><a href="instrumentation_testing.html">Instrumentation Testing</a></li> |
| </ul> |
| |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </div> |
| <a name="gc-pagecontent"></a> |
| <div class="g-unit" id="gc-pagecontent"> |
| <div id="jd-content"> |
| <div class="jd-descr"> |
| |
| |
| <a name="androidDisplayDriversTitle"></a><h1>Display Drivers</h1> |
| |
| |
| |
| <a name="toc"/> |
| <div style="padding:10px"> |
| <a href="#androidDisplayDriverIntroduction">Introduction</a><br/> |
| <a href="#androidDisplayDriverFunctionality">Functionality</a><br/> |
| <a href="#androidDisplayDriversSourceTemplate">Implementing Your Own Driver (Driver Template)</a><br/> |
| <a href="#androidDisplayDriversTroubleshooting">Troubleshooting</a><br/></div></font></div> |
| |
| <a name="androidDisplayDriverIntroduction"></a><h2>Introduction</h2> |
| |
| <p>This section describes how the display driver functions and offers a functional template designed to help you build your own device-specific driver.</p> |
| <p>Android relies on the standard frame buffer device (<code>/dev/fb0</code> or <code>/dev/graphics/fb0</code>) and driver as described in the <code>linux/fb.h</code> kernel header file. For more information regarding the standard Linux frame buffer, please see <a href="http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.24.y.git;a=blob;f=Documentation/fb/framebuffer.txt">The Frame Buffer Device</a> at <a href="http://kernel.org">http://kernel.org</a>. |
| |
| |
| <a name="androidDisplayDriverFunctionality"></a><h2>Functionality</h2> |
| |
| <p>In Android, every window gets implemented with an underlying Surface object, an object that gets placed on the framebuffer by SurfaceFlinger, the system-wide screen composer. Each Surface is double-buffered. The back buffer is where drawing takes place and the front buffer is used for composition. </p> |
| <p> When <code>unlockCanvas()</code> is called, the back buffer is posted, which |
| means that it gets displayed and becomes available again. Android flips the front and back buffers, ensuring a minimal amount of buffer copying and that there is always a buffer for SurfaceFlinger to use for composition (which ensures that the screen never flickers or shows artifacts).</p> |
| <p>Android makes two requirements of the driver: a linear address space of mappable memory that it can write to directly and support for the rgb_565 pixel format. A typical frame display includes:</p> |
| <ul> |
| <li>accessing the driver by calling open on <code>/dev/fb0</code></li> |
| <li>using the <code>FBIOGET_FSCREENINFO</code> and <code>FBIOGET_VSCREENINFO</code> Input / Output Control (ioctl) calls to retrieve information about the screen</li> |
| <li>using <code>FBIOPUT_VSCREENINFO</code> ioctl to attempt to create a virtual display twice the size of the physical screen and to set the pixel format to rgb_565. If this succeeds, double buffering is accomplished with video memory. </li> |
| </ul> |
| <p>When a page flip is required, Android makes another <code>FBIOPUT_VSCREENINFO</code> ioctl call with a new y-offset pointing to the other buffer in video memory. This ioctl, in turn, invokes the driver's <code>.fb_pan_display</code> function in order to do the actual flip. If there isn't sufficient video memory, regular memory is used and is just copied into the video memory when it is time do the flip. After allocating the video memory and setting the pixel format, Android uses <code>mmap()</code> to map the memory into the process's address space. All writes to the frame buffer are done through this mmaped memory.</p> |
| <p>To maintain adequate performance, framebuffer memory should be cacheable. If you use write-back, flush the cache before the frame buffer is written from DMA to the LCD. If that isn't possible, you may use write-through. As a last resort, you can also use uncached memory with the write-bugger enabled, but performance will suffer.</p> |
| |
| |
| <a name="androidDisplayDriversSourceTemplate"></a><h2>Implementing Your Own Driver (Driver Template)</h2> |
| |
| <p>The following sample driver offers a functional example to help you build your own display driver. Modify <code>PGUIDE_FB...</code> macros as desired to match the requirements of your own device hardware.</p> |
| <pre class="prettyprint"> |
| /* |
| * pguidefb.c |
| * |
| * Copyright 2007, Google Inc. |
| * |
| * This program is free software; you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 2 as |
| * published by the Free Software Foundation. |
| */ |
| |
| |
| /* |
| * ANDROID PORTING GUIDE: FRAME BUFFER DRIVER TEMPLATE |
| * |
| * This template is designed to provide the minimum frame buffer |
| * functionality necessary for Android to display properly on a new |
| * device. The PGUIDE_FB macros are meant as pointers indicating |
| * where to implement the hardware specific code necessary for the new |
| * device. The existence of the macros is not meant to trivialize the |
| * work required, just as an indication of where the work needs to be |
| * done. |
| */ |
| |
| #include <linux/module.h> |
| #include <linux/kernel.h> |
| #include <linux/errno.h> |
| #include <linux/string.h> |
| #include <linux/slab.h> |
| #include <linux/delay.h> |
| #include <linux/mm.h> |
| #include <linux/fb.h> |
| #include <linux/init.h> |
| #include <linux/platform_device.h> |
| |
| |
| /* Android currently only uses rgb565 in the hardware framebuffer */ |
| #define ANDROID_BYTES_PER_PIXEL 2 |
| |
| /* Android will use double buffer in video if there is enough */ |
| #define ANDROID_NUMBER_OF_BUFFERS 2 |
| |
| /* Modify these macros to suit the hardware */ |
| |
| #define PGUIDE_FB_ROTATE |
| /* Do what is necessary to cause the rotation */ |
| |
| #define PGUIDE_FB_PAN |
| /* Do what is necessary to cause the panning */ |
| |
| #define PGUIDE_FB_PROBE_FIRST |
| /* Do any early hardware initialization */ |
| |
| #define PGUIDE_FB_PROBE_SECOND |
| /* Do any later hardware initialization */ |
| |
| #define PGUIDE_FB_WIDTH 320 |
| /* Return the width of the screen */ |
| |
| #define PGUIDE_FB_HEIGHT 240 |
| /* Return the heighth of the screen */ |
| |
| #define PGUIDE_FB_SCREEN_BASE 0 |
| /* Return the virtual address of the start of fb memory */ |
| |
| #define PGUIDE_FB_SMEM_START PGUIDE_FB_SCREEN_BASE |
| /* Return the physical address of the start of fb memory */ |
| |
| #define PGUIDE_FB_REMOVE |
| /* Do any hardware shutdown */ |
| |
| |
| |
| |
| |
| struct pguide_fb { |
| int rotation; |
| struct fb_info fb; |
| u32 cmap[16]; |
| }; |
| |
| static inline u32 convert_bitfield(int val, struct fb_bitfield *bf) |
| { |
| unsigned int mask = (1 << bf->length) - 1; |
| |
| return (val >> (16 - bf->length) & mask) << bf->offset; |
| } |
| |
| |
| /* set the software color map. Probably doesn't need modifying. */ |
| static int |
| pguide_fb_setcolreg(unsigned int regno, unsigned int red, unsigned int green, |
| unsigned int blue, unsigned int transp, struct fb_info *info) |
| { |
| struct pguide_fb *fb = container_of(info, struct pguide_fb, fb); |
| |
| if (regno < 16) { |
| fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) | |
| convert_bitfield(blue, &fb->fb.var.blue) | |
| convert_bitfield(green, &fb->fb.var.green) | |
| convert_bitfield(red, &fb->fb.var.red); |
| return 0; |
| } |
| else { |
| return 1; |
| } |
| } |
| |
| /* check var to see if supported by this device. Probably doesn't |
| * need modifying. |
| */ |
| static int pguide_fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) |
| { |
| if((var->rotate & 1) != (info->var.rotate & 1)) { |
| if((var->xres != info->var.yres) || |
| (var->yres != info->var.xres) || |
| (var->xres_virtual != info->var.yres) || |
| (var->yres_virtual > |
| info->var.xres * ANDROID_NUMBER_OF_BUFFERS) || |
| (var->yres_virtual < info->var.xres )) { |
| return -EINVAL; |
| } |
| } |
| else { |
| if((var->xres != info->var.xres) || |
| (var->yres != info->var.yres) || |
| (var->xres_virtual != info->var.xres) || |
| (var->yres_virtual > |
| info->var.yres * ANDROID_NUMBER_OF_BUFFERS) || |
| (var->yres_virtual < info->var.yres )) { |
| return -EINVAL; |
| } |
| } |
| if((var->xoffset != info->var.xoffset) || |
| (var->bits_per_pixel != info->var.bits_per_pixel) || |
| (var->grayscale != info->var.grayscale)) { |
| return -EINVAL; |
| } |
| return 0; |
| } |
| |
| |
| /* Handles screen rotation if device supports it. */ |
| static int pguide_fb_set_par(struct fb_info *info) |
| { |
| struct pguide_fb *fb = container_of(info, struct pguide_fb, fb); |
| if(fb->rotation != fb->fb.var.rotate) { |
| info->fix.line_length = |
| info->var.xres * ANDROID_BYTES_PER_PIXEL; |
| fb->rotation = fb->fb.var.rotate; |
| PGUIDE_FB_ROTATE; |
| } |
| return 0; |
| } |
| |
| |
| /* Pan the display if device supports it. */ |
| static int pguide_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) |
| { |
| struct pguide_fb *fb __attribute__ ((unused)) |
| = container_of(info, struct pguide_fb, fb); |
| |
| /* Set the frame buffer base to something like: |
| fb->fb.fix.smem_start + fb->fb.var.xres * |
| ANDROID_BYTES_PER_PIXEL * var->yoffset |
| */ |
| PGUIDE_FB_PAN; |
| |
| return 0; |
| } |
| |
| |
| static struct fb_ops pguide_fb_ops = { |
| .owner = THIS_MODULE, |
| .fb_check_var = pguide_fb_check_var, |
| .fb_set_par = pguide_fb_set_par, |
| .fb_setcolreg = pguide_fb_setcolreg, |
| .fb_pan_display = pguide_fb_pan_display, |
| |
| /* These are generic software based fb functions */ |
| .fb_fillrect = cfb_fillrect, |
| .fb_copyarea = cfb_copyarea, |
| .fb_imageblit = cfb_imageblit, |
| }; |
| |
| |
| static int pguide_fb_probe(struct platform_device *pdev) |
| { |
| int ret; |
| struct pguide_fb *fb; |
| size_t framesize; |
| uint32_t width, height; |
| |
| fb = kzalloc(sizeof(*fb), GFP_KERNEL); |
| if(fb == NULL) { |
| ret = -ENOMEM; |
| goto err_fb_alloc_failed; |
| } |
| platform_set_drvdata(pdev, fb); |
| |
| PGUIDE_FB_PROBE_FIRST; |
| width = PGUIDE_FB_WIDTH; |
| height = PGUIDE_FB_HEIGHT; |
| |
| |
| fb->fb.fbops = &pguide_fb_ops; |
| |
| /* These modes are the ones currently required by Android */ |
| |
| fb->fb.flags = FBINFO_FLAG_DEFAULT; |
| fb->fb.pseudo_palette = fb->cmap; |
| fb->fb.fix.type = FB_TYPE_PACKED_PIXELS; |
| fb->fb.fix.visual = FB_VISUAL_TRUECOLOR; |
| fb->fb.fix.line_length = width * ANDROID_BYTES_PER_PIXEL; |
| fb->fb.fix.accel = FB_ACCEL_NONE; |
| fb->fb.fix.ypanstep = 1; |
| |
| fb->fb.var.xres = width; |
| fb->fb.var.yres = height; |
| fb->fb.var.xres_virtual = width; |
| fb->fb.var.yres_virtual = height * ANDROID_NUMBER_OF_BUFFERS; |
| fb->fb.var.bits_per_pixel = 16; |
| fb->fb.var.activate = FB_ACTIVATE_NOW; |
| fb->fb.var.height = height; |
| fb->fb.var.width = width; |
| |
| fb->fb.var.red.offset = 11; |
| fb->fb.var.red.length = 5; |
| fb->fb.var.green.offset = 5; |
| fb->fb.var.green.length = 6; |
| fb->fb.var.blue.offset = 0; |
| fb->fb.var.blue.length = 5; |
| |
| framesize = width * height * |
| ANDROID_BYTES_PER_PIXEL * ANDROID_NUMBER_OF_BUFFERS; |
| fb->fb.screen_base = PGUIDE_FB_SCREEN_BASE; |
| fb->fb.fix.smem_start = PGUIDE_FB_SMEM_START; |
| fb->fb.fix.smem_len = framesize; |
| |
| ret = fb_set_var(&fb->fb, &fb->fb.var); |
| if(ret) |
| goto err_fb_set_var_failed; |
| |
| PGUIDE_FB_PROBE_SECOND; |
| |
| ret = register_framebuffer(&fb->fb); |
| if(ret) |
| goto err_register_framebuffer_failed; |
| |
| return 0; |
| |
| |
| err_register_framebuffer_failed: |
| err_fb_set_var_failed: |
| kfree(fb); |
| err_fb_alloc_failed: |
| return ret; |
| } |
| |
| static int pguide_fb_remove(struct platform_device *pdev) |
| { |
| struct pguide_fb *fb = platform_get_drvdata(pdev); |
| |
| PGUIDE_FB_REMOVE; |
| |
| kfree(fb); |
| return 0; |
| } |
| |
| |
| static struct platform_driver pguide_fb_driver = { |
| .probe = pguide_fb_probe, |
| .remove = pguide_fb_remove, |
| .driver = { |
| .name = "pguide_fb" |
| } |
| }; |
| |
| static int __init pguide_fb_init(void) |
| { |
| return platform_driver_register(&pguide_fb_driver); |
| } |
| |
| static void __exit pguide_fb_exit(void) |
| { |
| platform_driver_unregister(&pguide_fb_driver); |
| } |
| |
| module_init(pguide_fb_init); |
| module_exit(pguide_fb_exit); |
| |
| MODULE_LICENSE("GPL"); |
| </pre> |
| |
| |
| <a name="androidDisplayDriversTroubleshooting"></a><h2>Troubleshooting</h2> |
| |
| <p>Both of the following problems have a similar cause:</p> |
| <ul> |
| <li><strong>Number keys</strong>: In the dialer application, when a number key is pressed to dial a phone number, the number doesn't display on the screen until after the next number has been pressed. </li> |
| <li><strong>Arrow keys</strong>: When an arrow key is pressed, the desired icon doesn't get highlighted. For example, if you browse through icons in the Applications menu, you might notice that icons aren't highlighted as expected when you use the arrow key to navigate between options.</li> |
| </ul> |
| <p>Both problems are caused by an incorrect implementation of the frame buffer's page flipping. Key events are captured, but the graphical interface appears to drop every other frame. </p> |
| <p>Android relies on a double buffer to smoothly render page flips (please see <a href="androidDisplayDriverFunctionality">Functionality</a> for details). |
| |
| |
| <p><span class="lh2"><a name="androidFooter"></a></span> |
| |
| </div> |
| </div> |
| <!-- end gc-pagecontent --> |
| </div> |
| <!-- end gooey wrapper --> |
| </div> |
| <!-- end codesearchresults --> |
| <div id="gc-footer" dir="ltr"> |
| <div class="text"> ©2008 Google<!-- - <a href="/">Code Home</a> - <a href="http://www.google.com/accounts/TOS">Site Terms of Service</a> - <a href="http://www.google.com/privacy.html">Privacy Policy</a> - <a href="/more">Site Directory</a> --></div> |
| </div> |
| <!-- end gc-footer --> |
| </div> |
| <!-- end gc-containter --> |
| <script src="http://www.google-analytics.com/ga.js" type="text/javascript"> |
| </script> |
| <script type="text/javascript"> |
| try { |
| var pageTracker = _gat._getTracker("UA-18071-1"); |
| pageTracker._setAllowAnchor(true); |
| pageTracker._initData(); |
| pageTracker._trackPageview(); |
| } catch(e) {} |
| </script> |
| <div id="jd-build-id"> v0.6 - 25 November 2008</div> |
| </div></div></div></body> |
| </html> |
| |