It appears that you're worried that serving different content to mobile users than to desktop users at the same URL, using user-agent detection, might be considered a form of cloaking, and thus penalized by Google.
According to the Google Webmaster Central Blog, this is not the case, provided that you do the mobile browser detection properly. Essentially, the important detail to realize is that Google's crawlers use different user-agent strings depending on whether they expect desktop or mobile content. For example, a typical user-agent string for normal Googlebot requests would be:
Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
whereas for requests from the mobile crawler, you'll see something like:
SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1
UP.Browser/126.96.36.199.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1;
or (for smartphone requests):
Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26
(KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25 (compatible;
As long as you make sure that you correctly detect the latter type of Googlebot requests (and not the former type) as mobile, and serve mobile content to them, everything should be fine. Basically, the important thing is that normal Googlebot requests need to receive desktop content, while mobile Googlebot requests need to receive mobile content.
Here's a nice diagram illustrating this, from the Google Webmaster Central Blog article I linked to above:
Also, to let Google's crawler know that there might be different content available for mobile browsers, you'll want to configure your web server to send the
Vary: User-Agent HTTP header for any pages that you're using user-agent detection for. You'll also want to make sure to avoid common pitfalls when detecting user-agents.