This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PWM - Initialize default on Booting AM335x

Hi All ,

    I want to set the default values of following while booting :

-> request
-> period_freq
-> duty_percent
-> run
for ecap.2 ;

I am able to control PWM from user space there is no issue in that but my requirement to start PWM while Booting or Uncompressing the Kernel;

Just before The TI LOGO appear on the screen for LCD Back-light control;

for any suggestion I will be thankful to you !!!!!!!!!

  • Hi Praveen,

    1) Try to change the default values in board file & platform data structures and check will getting effect your requirements,

    2) Try to hard code the mentioned default values (first time (with some logic) only and able to change it from user space as usual)  in pwm driver file instead doing at user space located at

    /* LCD backlight platform Data */
    #define AM335X_BACKLIGHT_MAX_BRIGHTNESS        100
    #define AM335X_BACKLIGHT_DEFAULT_BRIGHTNESS    100
    #define AM335X_PWM_PERIOD_NANO_SECONDS        (5000 * 10)

    static struct platform_pwm_backlight_data am335x_backlight_data2 = {
        .pwm_id         = "ecap.2",
        .ch             = -1,
        .lth_brightness    = 21,
        .max_brightness = AM335X_BACKLIGHT_MAX_BRIGHTNESS,
        .dft_brightness = AM335X_BACKLIGHT_DEFAULT_BRIGHTNESS,
        .pwm_period_ns  = AM335X_PWM_PERIOD_NANO_SECONDS,
    };

    static struct platform_device am335x_backlight = {
        .name           = "pwm-backlight",
        .id             = -1,
        .dev        = {
            .platform_data = &am335x_backlight_data2,
        },
    };

  • Hi Titusrathinaraj ,

        Thank for your reply ;

       To control PWM from User Space  I have already did these changes ;

       but as you mention i have rechecked those parameters it set properly as u mention ; (Re - Compile kernel and downloaded to Evm)

    No luck regarding output ecap.2 it still not running;

    Just to check I have gone through :

    root@am335x-evm:/sys/class/pwm/ecap.2# cat request

    ecap.2 is free      

    ********************************************************************************************************

    Changes that I have did in board file:

    static struct pinmux_config ecap2_pin_mux[] = {
        {"mcasp0_ahclkr.ecap2_in_pwm2_out", OMAP_MUX_MODE4 | AM33XX_PIN_OUTPUT},
        {NULL, 0},
    };

    static void enable_ecap2(int evm_id, int profile)
    {
        backlight_enable = true;
        setup_pin_mux(ecap2_pin_mux);
    }

    /* Setup pwm-backlight */
    static struct platform_device am335x_backlight = {
        .name           = "pwm-backlight",
        .id             = -1,
        .dev        = {
            .platform_data = &am335x_backlight_data2,
        },
    };

    static struct pwmss_platform_data  pwm_pdata[3] = {
        {
            .version = PWM_VERSION_1,
        },
        {
            .version = PWM_VERSION_1,
        },
        {
            .version = PWM_VERSION_1,
        },
    };

    static int __init backlight_init(void)
    {
        int status = 0;

        if (backlight_enable) {
            int ecap_index = 0;

            switch (am335x_evm_get_id()) {
                ecap_index = 0;
                break;
            case CALIXTO_EVM:
                /*
                 * Invert polarity of PWM wave from ECAP to handle
                 * backlight intensity to pwm brightness
                 */
                ecap_index = 2;
                pwm_pdata[ecap_index].chan_attrib[0].inverse_pol = true;
                am335x_backlight.dev.platform_data =
                    &am335x_backlight_data2;
                break;
            default:
                pr_err("%s: Error on attempting to enable backlight,"
                    " not supported\n", __func__);
                return -EINVAL;
            }

            am33xx_register_ecap(ecap_index, &pwm_pdata[ecap_index]);
            platform_device_register(&am335x_backlight);
        }
        return status;
    }
    late_initcall(backlight_init);

    *************************************************************************

     

    --->>>  I have gone through the structure variable;
    where I found "int enable_gpio;" and other variable; Is any of them require to initialize pwm and run during kernel
    Uncompressing;
      struct platform_pwm_backlight_data {
              int pwm_id;
              unsigned int max_brightness;
              unsigned int dft_brightness;
              unsigned int lth_brightness;
              unsigned int pwm_period_ns;
              unsigned int *levels;
              int enable_gpio;
              unsigned long enable_gpio_flags;
              int (*init)(struct device *dev);
              int (*notify)(struct device *dev, int brightness);
              void (*notify_after)(struct device *dev, int brightness);
              void (*exit)(struct device *dev);
              int (*check_fb)(struct device *dev, struct fb_info *info);
      };


    Thanks for your support

     

  • Hi Titusrathinaraj ,

         Thanks for support;

         I have gone through setting that u have mention ; i have already did these setting afterwards I am able to control PWM from user space ;

    As u have mention i have performed again but no luck; it is not running after kernel uncompressing;

    Just to check pwm initialized or not --> CD to ecap.2 -->cat request

    ecap.2 is free ;

    it is not running ;checked on CRO but still not found any wave;

    /*PWM BACKLIGHT *//////////////////////////////////////////////////////////

    /* LCD backlight platform Data */
    #define AM335X_BACKLIGHT_MAX_BRIGHTNESS        100
    #define AM335X_BACKLIGHT_DEFAULT_BRIGHTNESS    50
    #define AM335X_PWM_PERIOD_NANO_SECONDS        (5000 * 10)

     

    static struct platform_pwm_backlight_data am335x_backlight_data2 = {
        .pwm_id         = "ecap.2",
        .ch             = -1,
        .lth_brightness    = 21,
        .max_brightness = AM335X_BACKLIGHT_MAX_BRIGHTNESS,
        .dft_brightness = AM335X_BACKLIGHT_DEFAULT_BRIGHTNESS,
        .pwm_period_ns  = AM335X_PWM_PERIOD_NANO_SECONDS,
    };


    /* Module pin mux for eCAP */
    static struct pinmux_config ecap0_pin_mux[] = {
        {"ecap0_in_pwm0_out.ecap0_in_pwm0_out",OMAP_MUX_MODE0 | AM33XX_PIN_OUTPUT},
        {NULL, 0},
    };

    /* Module pin mux for eCAP */
    static struct pinmux_config ecap2_pin_mux[] = {
            
            {"mcasp0_ahclkr.ecap2_in_pwm2_out", OMAP_MUX_MODE4 | AM33XX_PIN_OUTPUT},
        {NULL, 0},
    };

    static bool backlight_enable;

    static void enable_ecap0(int evm_id, int profile)
    {
        backlight_enable = true;
        setup_pin_mux(ecap0_pin_mux);
    }

    static void enable_ecap2(int evm_id, int profile)
    {
        backlight_enable = true;
        setup_pin_mux(ecap2_pin_mux);
    }

    /* Setup pwm-backlight */
    static struct platform_device am335x_backlight = {
        .name           = "pwm-backlight",
        .id             = -1,
        .dev        = {
            .platform_data = &am335x_backlight_data2,
        },
    };

    static struct pwmss_platform_data  pwm_pdata[3] = {
        {
            .version = PWM_VERSION_1,
        },
        {
            .version = PWM_VERSION_1,
        },
        {
            .version = PWM_VERSION_1,
        },
    };

    static int __init backlight_init(void)
    {
        int status = 0;

        if (backlight_enable) {
            int ecap_index = 0;

            switch (am335x_evm_get_id()) {
                ecap_index = 0;
                break;
            case CALIXTO_EVM:
                /*
                 * Invert polarity of PWM wave from ECAP to handle
                 * backlight intensity to pwm brightness
                 */
                ecap_index = 2;
                pwm_pdata[ecap_index].chan_attrib[0].inverse_pol = true;
                am335x_backlight.dev.platform_data =
                    &am335x_backlight_data2;
                break;
            default:
                pr_err("%s: Error on attempting to enable backlight,"
                    " not supported\n", __func__);
                return -EINVAL;
            }

            am33xx_register_ecap(ecap_index, &pwm_pdata[ecap_index]);
            platform_device_register(&am335x_backlight);
        }
        return status;
    }
    late_initcall(backlight_init);
    /*PWM BACKLIGHT *//////////////////////////////////////////////////////////

    Apart from that when I have gone through structure of platform_pwm_backlight_data i found one variable;

    enable_gpio is it required to enable to initialize and Run from kernel ;if Yes pls let me know ?

    struct platform_pwm_backlight_data {
              int pwm_id;
              unsigned int max_brightness;
              unsigned int dft_brightness;
              unsigned int lth_brightness;
              unsigned int pwm_period_ns;
              unsigned int *levels;
              int enable_gpio;
              unsigned long enable_gpio_flags;
              int (*init)(struct device *dev);
              int (*notify)(struct device *dev, int brightness);
              void (*notify_after)(struct device *dev, int brightness);
              void (*exit)(struct device *dev);
              int (*check_fb)(struct device *dev, struct fb_info *info);
     };

    Thanks for every support :

  • Hi Praveen ,

    Since you had already made changes to board file and driver file according to your requirement and able to control PWM module from user space why don't you write init script to start running the PWM module. In following example If you write a shell script with following lines and run your script at bootup ehrpwm0B module shall start with 1Khz period freq and 3% duty cycle.

    #!/bin/bash

    echo 1 > /sys/class/pwm/ehrpwm.0:1/request
    echo 1000 > /sys/class/pwm/ehrpwm.0:1/period_freq
    echo 3 > /sys/class/pwm/ehrpwm.0:1/duty_percent
    echo 1 > /sys/class/pwm/ehrpwm.0:1/run

    To run shell script at system bootup :

    1. You can either add your script to /etc/init.d directory and you shall create a link in your preferred run level directory.

    2. You can add a entry to crontab i.e. @bootup /path-to-your-shell-script/script-name.sh