×

ADP8860背光LED Linux驱动器

消耗积分:3 | 格式:pdf | 大小:199.49KB | 2021-05-17

hxjq

分享资料个

This version (11 Feb 2016 21:13) was approved by Lars-Peter Clausen.The Previously approved version (18 Feb 2013 16:51) is available.Diff

ADP8860 Back-light LED Linux Driver

Supported Devices

Evaluation Boards

Description

Configuration

Software configurable features

Backlight:

Feature ADP8860 ADP8863 ADP8861
Ambient Light Sensor Support (ALS)
Three programmable ambient light sensing
zones for optimal backlight power savings
Configurable Fade On/Off times
Configurable Fade Law functions
Configurable ALS filter settings
Configurable Brightness/Intensity in 128 steps

LED:

Feature ADP8860 ADP8863 ADP8861
Up to 7 LEDs configurable
Configurable Fade On/Off times
LED Blink On/Off times
Configurable Fade Law functions
Configurable Brightness/Intensity in 128 steps from [0..255]

Source Code

Status

Source Mainlined?
git Yes

Files

Instructions / Theory of operation

Backlight control

With the ADP8860 driver installed, you will find sysfs files in the
/sys/class/backlight/adp8860_bl/
directory. You will be able to query and set the current screen
brightness:

brightness
get/set screen brightness (an integer between 0 and 126)
writing 127 will enable the Ambient Light Sensor.
actual_brightness
reading from this file will query the HW to get real brightness value.
max_brightness
the maximum brightness value.
bl_power
Current FB Power mode (0: full on, 1..3: power saving modes; 4: full off).

ADP8860 Specific Backlight controls

The ADP8860 features 3 individually programmable Ambient Light Sensing Zones:

l1_daylight_dim
Ambient Light Zone Daylight: Backlight DIM Intensity (an integer between 0 and 127, typically set to 0).
l1_daylight_max
Ambient Light Zone Daylight: Backlight Intensity (an integer between 0 and 127).
l2_office_dim
Ambient Light Zone Office: Backlight DIM Intensity (an integer between 0 and 127, typically set to 0)
l2_office_max
Ambient Light Zone Office: Backlight Intensity (an integer between 0 and 127)
l3_dark_dim
Ambient Light Zone Dark: Backlight DIM Intensity (an integer between 0 and 127, typically set to 0)
l3_dark_max
Ambient Light Zone Dark: Backlight Intensity (an integer between 0 and 127)
ambient_light_level
Get conversion value of the first light sensor. This value is updated every 80 ms
(when the light sensor is enabled). Returns integer between 0 (dark) and 8000 (max ambient brightness)
ambient_light_zone
Get/Set current Ambient Light Zone. Reading returns integer between 1..3
(1 = Daylight, 2 = office, 3 = dark). Writing a value between 1..3 forces the Backlight controller
to enter the corresponding Ambient Light Zone. Writing 0 returns to normal operation.

LED handling under Linux

LEDs not assigned to the Backlight are optionally exposed to the Linux LEDs Class.

The LED class allows control of LEDs from userspace. LEDs appear in /sys/class/leds/. The brightness file will set the brightness of the LED (taking a value 0-255). The LEDS class also introduces the optional concept of an LED trigger. A trigger is a kernel based source of led events, such as ide-disk or backlight control.
For more information read linux/Documentaion/leds-class.txt

brightness
get/set LED brightness (an integer between 0 and 255)
max_brightness
the maximum brightness value.

Example platform device initialization

For compile time configuration, it’s common Linux practice to keep board- and application-specific configuration out of the main driver file, instead putting it into the board support file.

For devices on custom boards, as typical of embedded and SoC-(system-on-chip) based hardware, Linux uses platform_data to point to board-specific structures describing devices and how they are connected to the SoC. This can include available ports, chip variants, preferred modes, default initialization, additional pin roles, and so on. This shrinks the board-support packages (BSPs) and minimizes board and application specific #ifdefs in drivers.

21 Oct 2010 16:10

platform_data: Platform data specific to the ADP8860 device.
Includes what LEDs are available, feature selections and default initialization.

#include 

Declaring I2C devices

Unlike PCI or USB devices, I2C devices are not enumerated at the hardware level. Instead, the software must know which devices are connected on each I2C bus segment, and what address these devices are using. For this reason, the kernel code must instantiate I2C devices explicitly. There are different ways to achieve this, depending on the context and requirements. However the most common method is to declare the I2C devices by bus number.

This method is appropriate when the I2C bus is a system bus, as in many embedded systems, wherein each I2C bus has a number which is known in advance. It is thus possible to pre-declare the I2C devices that inhabit this bus. This is done with an array of struct i2c_board_info, which is registered by calling i2c_register_board_info().

So, to enable such a driver one need only edit the board support file by adding an appropriate entry to i2c_board_info.

For more information see: Documentation/i2c/instantiating-devices

21 Oct 2010 16:10
static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
#if defined(CONFIG_BACKLIGHT_ADP8860) || defined(CONFIG_BACKLIGHT_ADP8860_MODULE)
	{
		I2C_BOARD_INFO("adp8860", 0x2A),
		.platform_data = (void *)&adp8860_pdata,
	},
#endif
}

Adding Linux driver support

Configure kernel with “make menuconfig” (alternatively use “make xconfig” or “make qconfig”)

The ADP8860 Backlight driver depends on I2C. It therefore requires selected I2C support to show up during kernel configuration.

Device Drivers  --->
	Graphics support  --->
		[*] Backlight & LCD device support  ---

ADP8860 Back-light LED Linux Driver

Supported Devices

Evaluation Boards

Description

Configuration

Software configurable features

Backlight:

Feature ADP8860 ADP8863 ADP8861
Ambient Light Sensor Support (ALS)
Three programmable ambient light sensing
zones for optimal backlight power savings
Configurable Fade On/Off times
Configurable Fade Law functions
Configurable ALS filter settings
Configurable Brightness/Intensity in 128 steps

LED:

Feature ADP8860 ADP8863 ADP8861
Up to 7 LEDs configurable
Configurable Fade On/Off times
LED Blink On/Off times
Configurable Fade Law functions
Configurable Brightness/Intensity in 128 steps from [0..255]

Source Code

Status

Source Mainlined?
git Yes

Files

Instructions / Theory of operation

Backlight control

With the ADP8860 driver installed, you will find sysfs files in the
/sys/class/backlight/adp8860_bl/
directory. You will be able to query and set the current screen
brightness:

brightness
get/set screen brightness (an integer between 0 and 126)
writing 127 will enable the Ambient Light Sensor.
actual_brightness
reading from this file will query the HW to get real brightness value.
max_brightness
the maximum brightness value.
bl_power
Current FB Power mode (0: full on, 1..3: power saving modes; 4: full off).

ADP8860 Specific Backlight controls

The ADP8860 features 3 individually programmable Ambient Light Sensing Zones:

l1_daylight_dim
Ambient Light Zone Daylight: Backlight DIM Intensity (an integer between 0 and 127, typically set to 0).
l1_daylight_max
Ambient Light Zone Daylight: Backlight Intensity (an integer between 0 and 127).
l2_office_dim
Ambient Light Zone Office: Backlight DIM Intensity (an integer between 0 and 127, typically set to 0)
l2_office_max
Ambient Light Zone Office: Backlight Intensity (an integer between 0 and 127)
l3_dark_dim
Ambient Light Zone Dark: Backlight DIM Intensity (an integer between 0 and 127, typically set to 0)
l3_dark_max
Ambient Light Zone Dark: Backlight Intensity (an integer between 0 and 127)
ambient_light_level
Get conversion value of the first light sensor. This value is updated every 80 ms
(when the light sensor is enabled). Returns integer between 0 (dark) and 8000 (max ambient brightness)
ambient_light_zone
Get/Set current Ambient Light Zone. Reading returns integer between 1..3
(1 = Daylight, 2 = office, 3 = dark). Writing a value between 1..3 forces the Backlight controller
to enter the corresponding Ambient Light Zone. Writing 0 returns to normal operation.

LED handling under Linux

LEDs not assigned to the Backlight are optionally exposed to the Linux LEDs Class.

The LED class allows control of LEDs from userspace. LEDs appear in /sys/class/leds/. The brightness file will set the brightness of the LED (taking a value 0-255). The LEDS class also introduces the optional concept of an LED trigger. A trigger is a kernel based source of led events, such as ide-disk or backlight control.
For more information read linux/Documentaion/leds-class.txt

brightness
get/set LED brightness (an integer between 0 and 255)
max_brightness
the maximum brightness value.

Example platform device initialization

For compile time configuration, it’s common Linux practice to keep board- and application-specific configuration out of the main driver file, instead putting it into the board support file.

For devices on custom boards, as typical of embedded and SoC-(system-on-chip) based hardware, Linux uses platform_data to point to board-specific structures describing devices and how they are connected to the SoC. This can include available ports, chip variants, preferred modes, default initialization, additional pin roles, and so on. This shrinks the board-support packages (BSPs) and minimizes board and application specific #ifdefs in drivers.

21 Oct 2010 16:10

platform_data: Platform data specific to the ADP8860 device.
Includes what LEDs are available, feature selections and default initialization.

#include 

Declaring I2C devices

Unlike PCI or USB devices, I2C devices are not enumerated at the hardware level. Instead, the software must know which devices are connected on each I2C bus segment, and what address these devices are using. For this reason, the kernel code must instantiate I2C devices explicitly. There are different ways to achieve this, depending on the context and requirements. However the most common method is to declare the I2C devices by bus number.

This method is appropriate when the I2C bus is a system bus, as in many embedded systems, wherein each I2C bus has a number which is known in advance. It is thus possible to pre-declare the I2C devices that inhabit this bus. This is done with an array of struct i2c_board_info, which is registered by calling i2c_register_board_info().

So, to enable such a driver one need only edit the board support file by adding an appropriate entry to i2c_board_info.

For more information see: Documentation/i2c/instantiating-devices

21 Oct 2010 16:10
static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
#if defined(CONFIG_BACKLIGHT_ADP8860) || defined(CONFIG_BACKLIGHT_ADP8860_MODULE)
	{
		I2C_BOARD_INFO("adp8860", 0x2A),
		.platform_data = (void *)&adp8860_pdata,
	},
#endif
}

Adding Linux driver support

Configure kernel with “make menuconfig” (alternatively use “make xconfig” or “make qconfig”)

The ADP8860 Backlight driver depends on I2C. It therefore requires selected I2C support to show up during kernel configuration.

Device Drivers  --->
	Graphics support  --->
		[*] Backlight & LCD device support  --->
			<*>   Lowlevel Backlight controls
			   Backlight Driver for ADP8860 using WLED

Hardware configuration

During test and driver development we used the ADP8860 Evaluation Mother/Daughter Board.

It can be easily wired to the Blackfin STAMP TWI/I2C header.

BF537-STAMP (P10) TWI/I2C header ADP886x Adaptor Board (J30)
PIN Function PIN/Function
5 SCL SCL
6 SDA SDA
20 GND GND

Leave J31 and J32 open (these jumpers connect the SCL and SDA to the cypress chip used as USB bridge). Then apply your own SCL, SDA, and GND to the big J30 connector on the left edge of the board.

The ADP8860 chip still needs Vin (to power the chip), Vddio (to pull nRST and nINT high), and Vboard (to power the ALS sensor on the daughter card). These are provided through the USB port and then get regulated down (Vin becomes 3.6V, Vddio is 2.7V, and Vboard is around 4 V). So even though you won't be using the USB to program the part, it would still be easiest to plug the board into a USB port just to power Vin, Vddio, and Vboard. Of course, if you want, you can power these supplies from a lab bench power supply. In that case, move LK1, 2, and 3 to the “EXT” position and apply the signals to J29.

Driver testing

Driver compiled as a module

ADP8860 driver is build as a module

root:/> modprobe adp8860_bl
adp8860_bl 0-002a: Rev.7 Backlight
Registered led device: adp8860-led7
root:/>

Example Backlight usage

root:/> cd sys/class/backlight/adp8860_bl/
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-adapter/i2c-0/0-002a/backlight/adp8860_bl> ls -l
-r--r--r--    1 root     root         4096 Jan  1 03:29 actual_brightness
-r--r--r--    1 root     root         4096 Jan  1 03:29 ambient_light_level
-rw-rw-r--    1 root     root         4096 Jan  1 03:29 ambient_light_zone
-rw-r--r--    1 root     root         4096 Jan  1 03:31 bl_power
-rw-r--r--    1 root     root         4096 Jan  1 04:55 brightness
lrwxrwxrwx    1 root     root            0 Jan  1 03:29 device -> ../../../0-002a
-rw-rw-r--    1 root     root         4096 Jan  1 03:29 l1_daylight_dim
-rw-rw-r--    1 root     root         4096 Jan  1 03:29 l1_daylight_max
-rw-rw-r--    1 root     root         4096 Jan  1 03:30 l2_office_dim
-rw-rw-r--    1 root     root         4096 Jan  1 03:29 l2_office_max
-rw-rw-r--    1 root     root         4096 Jan  1 03:31 l3_dark_dim
-rw-rw-r--    1 root     root         4096 Jan  1 03:29 l3_dark_max
-r--r--r--    1 root     root         4096 Jan  1 03:29 max_brightness
drwxr-xr-x    2 root     root            0 Jan  1 03:29 power
lrwxrwxrwx    1 root     root            0 Jan  1 03:29 subsystem -> ../../../../../../../../class/backlight
-rw-r--r--    1 root     root         4096 Jan  1 03:29 uevent
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-adapter/i2c-0/0-002a/backlight/adp8860_bl>

Set Backlight Intensity

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-adapter/i2c-0/0-002a/backlight/adp8860_bl> echo 42 > brightness

Query Backlight Intensity

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-adapter/i2c-0/0-002a/backlight/adp8860_bl> cat brightness
42

Enable Ambient Light Sensing Feature

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-adapter/i2c-0/0-002a/backlight/adp8860_bl> echo 127 > brightness

Query Ambient Light Level

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-adapter/i2c-0/0-002a/backlight/adp8860_bl> cat ambient_light_level
1276

Query Ambient Light Zone

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-adapter/i2c-0/0-002a/backlight/adp8860_bl> cat ambient_light_zone
2

Adjust Intensity for Ambient Light Zone 2 (office)

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-adapter/i2c-0/0-002a/backlight/adp8860_bl> echo 22 > l2_office_max
22

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-adapter/i2c-0/0-002a/backlight/adp8860_bl> cat l2_office_max
22

Example LED usage

root:/> cd /sys/class/leds/adp8860-led7/
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-adapter/i2c-0/0-002a/leds/adp8860-led7> ls -l
-rw-r--r--    1 root     root         4096 Jan  1 03:29 brightness
lrwxrwxrwx    1 root     root            0 Jan  1 03:29 device -> ../../../0-002a
-r--r--r--    1 root     root         4096 Jan  1 03:29 max_brightness
drwxr-xr-x    2 root     root            0 Jan  1 03:29 power
lrwxrwxrwx    1 root     root            0 Jan  1 03:29 subsystem -> ../../../../../../../../class/leds

Set Intensity

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-adapter/i2c-0/0-002a/leds/adp8860-led7>echo 99 > brightness

Turn LED OFF

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-adapter/i2c-0/0-002a/leds/adp8860-led7> echo 0 > brightness

Query Max Brightness

root:/sys/devices/platform/i2c-bfin-twi.0/i2c-adapter/i2c-0/0-002a/leds/adp8860-led7> cat max_brightness
255
root:/sys/devices/platform/i2c-bfin-twi.0/i2c-adapter/i2c-0/0-002a/leds/adp8860-led7>

More Information

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !

'+ '

'+ '

'+ ''+ '
'+ ''+ ''+ '
'+ ''+ '' ); $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code ==5){ $(pop_this).attr('href',"/login/index.html"); return false } if(data.code == 2){ //跳转到VIP升级页面 window.location.href="//m.lene-v.com/vip/index?aid=" + webid return false } //是会员 if (data.code > 0) { $('body').append(htmlSetNormalDownload); var getWidth=$("#poplayer").width(); $("#poplayer").css("margin-left","-"+getWidth/2+"px"); $('#tips').html(data.msg) $('.download_confirm').click(function(){ $('#dialog').remove(); }) } else { var down_url = $('#vipdownload').attr('data-url'); isBindAnalysisForm(pop_this, down_url, 1) } }); }); //是否开通VIP $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code == 2 || data.code ==5){ //跳转到VIP升级页面 $('#vipdownload>span').text("开通VIP 免费下载") return false }else{ // 待续费 if(data.code == 3) { vipExpiredInfo.ifVipExpired = true vipExpiredInfo.vipExpiredDate = data.data.endoftime } $('#vipdownload .icon-vip-tips').remove() $('#vipdownload>span').text("VIP免积分下载") } }); }).on("click",".download_cancel",function(){ $('#dialog').remove(); }) var setWeixinShare={};//定义默认的微信分享信息,页面如果要自定义分享,直接更改此变量即可 if(window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'){ var d={ title:'ADP8860背光LED Linux驱动器',//标题 desc:$('[name=description]').attr("content"), //描述 imgUrl:'https://'+location.host+'/static/images/ele-logo.png',// 分享图标,默认是logo link:'',//链接 type:'',// 分享类型,music、video或link,不填默认为link dataUrl:'',//如果type是music或video,则要提供数据链接,默认为空 success:'', // 用户确认分享后执行的回调函数 cancel:''// 用户取消分享后执行的回调函数 } setWeixinShare=$.extend(d,setWeixinShare); $.ajax({ url:"//www.lene-v.com/app/wechat/index.php?s=Home/ShareConfig/index", data:"share_url="+encodeURIComponent(location.href)+"&format=jsonp&domain=m", type:'get', dataType:'jsonp', success:function(res){ if(res.status!="successed"){ return false; } $.getScript('https://res.wx.qq.com/open/js/jweixin-1.0.0.js',function(result,status){ if(status!="success"){ return false; } var getWxCfg=res.data; wx.config({ //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId:getWxCfg.appId, // 必填,公众号的唯一标识 timestamp:getWxCfg.timestamp, // 必填,生成签名的时间戳 nonceStr:getWxCfg.nonceStr, // 必填,生成签名的随机串 signature:getWxCfg.signature,// 必填,签名,见附录1 jsApiList:['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function(){ //获取“分享到朋友圈”按钮点击状态及自定义分享内容接口 wx.onMenuShareTimeline({ title: setWeixinShare.title, // 分享标题 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享给朋友”按钮点击状态及自定义分享内容接口 wx.onMenuShareAppMessage({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 type: setWeixinShare.type, // 分享类型,music、video或link,不填默认为link dataUrl: setWeixinShare.dataUrl, // 如果type是music或video,则要提供数据链接,默认为空 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ”按钮点击状态及自定义分享内容接口 wx.onMenuShareQQ({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口 wx.onMenuShareWeibo({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口 wx.onMenuShareQZone({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); }); }); } }); } function openX_ad(posterid, htmlid, width, height) { if ($(htmlid).length > 0) { var randomnumber = Math.random(); var now_url = encodeURIComponent(window.location.href); var ga = document.createElement('iframe'); ga.src = 'https://www1.elecfans.com/www/delivery/myafr.php?target=_blank&cb=' + randomnumber + '&zoneid=' + posterid+'&prefer='+now_url; ga.width = width; ga.height = height; ga.frameBorder = 0; ga.scrolling = 'no'; var s = $(htmlid).append(ga); } } openX_ad(828, '#berry-300', 300, 250);