Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Help requested: Linux, PWMs, and LCD Backlights
PostPosted: Fri May 21, 2010 9:53 pm 
Offline

Joined: Tue May 12, 2009 7:21 pm
Posts: 16
Hi all,

I'm trying to use the AT91SAM9263's PWM for an LCD backlight control. Under the U-boot bootloader, I was able to get this working at a 75% duty cycle by writing directly to the AT91's registers. Under Linux, I was hoping to use the existing atmel-pwm-bl module; however, I'm running into issues and need your help.

Here's the code in my BSP:

Code:
/*
* Atmel Backlight PWM
*/
#if defined(CONFIG_BACKLIGHT_ATMEL_PWM) || defined(CONFIG_BACKLIGHT_ATMEL_PWM_MODULE)
static struct atmel_pwm_bl_platform_data cs_bl_data = {
        .pwm_channel            = AT91_PWM0,
        .pwm_frequency          = 10000,
        .pwm_compare_max        = 100,
        .pwm_duty_max           = 100,
        .pwm_duty_min           = 0,
        .pwm_active_low         = 1,
        .gpio_on                = -1,
        .on_active_low          = 0,
};

static struct platform_device cs_bl_dev = {
        .name           = "atmel-pwm-bl",
        .id             = 0,
        .dev = {
                .platform_data = &cs_bl_data,
        },
};

static void __init cs_add_device_backlight_pwm(void) {
        at91_add_device_pwm(1 << cs_bl_data.pwm_channel);
        platform_device_register(&cs_bl_dev);

#if 0
        at91_set_B_periph(AT91_PIN_PB7, 0);     /* PWM0 */
        at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9263_ID_PWMC);
#endif
}
#else
static void __init cs_add_device_backlight_pwm(void) {}
#endif


I then call cs_add_device_backlight_pwm() inside the board_init() function. I've also ensured that CONFIG_ATMEL_PWM and CONFIG_BACKLIGHT_ATMEL_PWM are set to 'y' in the .config file.

The PWM signal does not toggle, and no entry appears in /sys/class/backlight.

What am I missing? I'm sure it's painfully obvious, so I appreciate your help in slapping me over the head. :-)

Thanks in advance,
Chris


Top
 Profile  
 
 Post subject: Re: Help requested: Linux, PWMs, and LCD Backlights
PostPosted: Sat May 22, 2010 1:39 am 
Offline

Joined: Tue May 12, 2009 7:21 pm
Posts: 16
A little more info ...

I added debug messages to drivers/video/backlight/atmel-pwm-bl.c and discovered that the call to pwm_channel_alloc() inside atmel_pwm_bl_probe() is returning -ENODEV. This response is given by the following check:

Code:
if (!pwm || !(pwm->mask & 1 << index))
        return -ENODEV;


Still working to understand what is missing.

Chris


Top
 Profile  
 
 Post subject: Re: Help requested: Linux, PWMs, and LCD Backlights
PostPosted: Sat May 22, 2010 5:55 pm 
Offline

Joined: Tue May 12, 2009 7:21 pm
Posts: 16
Some more updates based on testing:

I noticed in the dmesg output that atmel-pwm-bl was being loaded before atmel_pwm. That prompted me to try restructuring the code to the following:

Code:
/*
* Atmel Backlight PWM
*/
#if defined(CONFIG_ATMEL_PWM) || defined(CONFIG_ATMEL_PWM_MODULE)
static void __init cs_add_device_pwm(void)
{
        at91_add_device_pwm(1 << AT91_PWM0);
}
#else
static void __init cs_add_device_pwm(void)
#endif

#if defined(CONFIG_BACKLIGHT_ATMEL_PWM) || defined(CONFIG_BACKLIGHT_ATMEL_PWM_MODULE)
static struct atmel_pwm_bl_platform_data cs_bl_data = {
        .pwm_channel            = AT91_PWM0,
        .pwm_frequency          = 10000,
        .pwm_compare_max        = 100,
        .pwm_duty_max           = 100,
        .pwm_duty_min           = 50,
        .pwm_active_low         = 0,
        .gpio_on                = -1,
        .on_active_low          = 0,
};

/* Defined in at91sam9263_devices.c */
extern struct platform_device at91sam9263_pwm0_device;

static struct platform_device cs_bl_dev = {
        .name           = "atmel-pwm-bl",
        .id             = -1,
        .dev = {
                .parent         = &at91sam9263_pwm0_device.dev,
                .platform_data  = &cs_bl_data,
        },
};

static void __init cs_add_device_backlight_pwm(void)
{
        platform_device_register(&cs_bl_dev);
}
#else
static void __init cs_add_device_backlight_pwm(void) {}
#endif


Especially note the parent dependency in the cs_bl_dev definition. My hope was that this would cause atmel_pwm to load before atmel-pwm-bl. Unfortunately, that hope was dashed.

I was able to get things working with the following:

[list=][*]CONFIG_ATMEL_PWM=y
[*]CONFIG_BACKLIGHT_ATMEL_PWM=m
[*]Load the kernel, atmel_pwm loads properly
[*]modprobe atmel-pwm-bl[/list]

Using this, I get the following dmesg output:

Code:
# dmesg | grep -i pwm
[    0.220000] registering platform atmel_pwm device
[    0.730000] atmel_pwm atmel_pwm: pwm registered, mask=0x00000001
[    0.730000] atmel_pwm driver loaded
[  277.450000] atmel-pwm-bl atmel-pwm-bl: atmel_pwm_bl_probe
[  277.450000] atmel-pwm-bl atmel-pwm-bl: Atmel PWM backlight driver (7760 Hz)
[  277.520000] backlight atmel-pwm-bl: backlight pwm registered


(I added these messages to the two drivers to help figure out the sequencing issue.)

So that leaves me with two questions:

[list=][*]Why is atmel-pwm-bl being loaded before atmel_pwm in the monolithic kernel, even with the parent dependency is setup?
[*]What can be done about it?[/list]

Chris


Top
 Profile  
 
 Post subject: Re: Help requested: Linux, PWMs, and LCD Backlights
PostPosted: Sat May 22, 2010 6:09 pm 
Offline

Joined: Tue May 12, 2009 7:21 pm
Posts: 16
It appears as though kbuild's Makefile structure may play a role in why atmel-pwm-bl is being loaded before atmel_pwm:

http://lxr.linux.no/#linux+v2.6.34/Docu ... efiles.txt#L147

Not sure how to fix it yet.

Chris


Top
 Profile  
 
 Post subject: Re: Help requested: Linux, PWMs, and LCD Backlights
PostPosted: Tue Jun 07, 2011 8:39 am 
Offline

Joined: Wed Apr 20, 2005 4:24 am
Posts: 4
Location: california
I had the same issue on a recent build. I was able to fix it by changing module_init() to subsys_initcall() in atmel_pwm.c


Top
 Profile  
 
 Post subject: Re: Help requested: Linux, PWMs, and LCD Backlights
PostPosted: Tue Oct 25, 2011 8:31 pm 
Offline

Joined: Tue Oct 25, 2011 8:28 pm
Posts: 1
Using najay's suggestion worked for me. Thanks a bunch for that. What is the difference between module_init() and sysinit_call()?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Bing [Bot] and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: