static void omap_pwm_led_power_on(struct omap_pwm_led *led) { pr_debug("%s%s: \n", PASS1,__func__); printk("!!!!!!!!!!%s the brightness is %d \n",__func__, led->brightness); if (led->powered){ printk("!!!!!!!!!!LED powered, returning \n"); return; } led->powered = 1; /* Select clock */ omap_dm_timer_enable(led->intensity_timer); omap_dm_timer_set_source(led->intensity_timer, OMAP_TIMER_SRC_SYS_CLK); omap_dm_timer_set_prescaler(led->intensity_timer, 0); /* Turn voltage on */ if (led->pdata->set_power != NULL) { printk("!!!!!!!!!!Turn voltage on \n"); led->pdata->set_power(led->pdata, 1); } /* Enable PWM timers */ if (led->blink_timer != NULL) { printk("!!!!!!!!!!Enable PWM timers \n"); omap_dm_timer_enable(led->blink_timer); omap_dm_timer_set_source(led->blink_timer, OMAP_TIMER_SRC_32_KHZ); omap_pwm_led_set_blink(led); } omap_dm_timer_set_load(led->intensity_timer, 1, 0xffffff00); }
// Initialize the kernel module static int __init gptimer_test_init(void) { int ret = 0; struct clk *gt_fclk; uint32_t gt_rate; printk("gptimer test: starting moudle init\n"); // request a timer (we are asking for ANY open timer, see dmtimer.c for details on how this works) timer_ptr = omap_dm_timer_request(); if(timer_ptr == NULL){ // oops, no timers available printk("gptimer test: No more gp timers available, bailing out\n"); return -1; } // set the clock source to system clock omap_dm_timer_set_source(timer_ptr, OMAP_TIMER_SRC_SYS_CLK); // set prescalar to 1:1 omap_dm_timer_set_prescaler(timer_ptr, 32); // figure out what IRQ our timer triggers timer_irq = omap_dm_timer_get_irq(timer_ptr); // install our IRQ handler for our timer ret = request_irq(timer_irq, timer_irq_handler, IRQF_DISABLED | IRQF_TIMER , "gptimer test", timer_irq_handler); if(ret){ printk("gptimer test: request_irq failed (on irq %d), bailing out\n", timer_irq); return ret; } // get clock rate in Hz gt_fclk = omap_dm_timer_get_fclk(timer_ptr); gt_rate = clk_get_rate(gt_fclk); // set preload, and autoreload // we set it to the clock rate in order to get 1 overflow every second omap_dm_timer_set_load(timer_ptr, 1, 0xFFFFFFFF - gt_rate); // setup timer to trigger our IRQ on the overflow event omap_dm_timer_set_int_enable(timer_ptr, OMAP_TIMER_INT_OVERFLOW); // start the timer! omap_dm_timer_start(timer_ptr); // done! printk("gptimer test: GP Timer initialized and started (%lu Hz, IRQ %d)\n", (long unsigned)gt_rate, timer_irq); // return sucsess return 0; }
static int __init pwm_start(void) { int ret = 0; struct clk *timer_fclk; uint32_t gt_rate; printk(KERN_INFO "Loading PWM Module... \n"); // request any timer timer_ptr = omap_dm_timer_request(); if(timer_ptr == NULL){ // no timers available printk("pwm module: No more gp timers available, bailing out\n"); return -1; } // set the clock source to the system clock ret = omap_dm_timer_set_source(timer_ptr, OMAP_TIMER_SRC_SYS_CLK); if(ret) { printk("pwm module: could not set source\n"); return -1; } // set prescalar to 1:1 omap_dm_timer_set_prescaler(timer_ptr, 0); // figure out what IRQ our timer triggers timer_irq = omap_dm_timer_get_irq(timer_ptr); // install our IRQ handler for our timer ret = request_irq(timer_irq, timer_irq_handler, IRQF_DISABLED | IRQF_TIMER , "pwm", timer_irq_handler); if(ret){ printk("pwm module: request_irq failed (on irq %d), bailing out\n", timer_irq); return ret; } // get clock rate in Hz and add it to struct timer_fclk = omap_dm_timer_get_fclk(timer_ptr); gt_rate = clk_get_rate(timer_fclk); pwm_data_ptr.timer_rate = gt_rate; // set preload, and autoreload // we set it to a default of 1kHz set_pwm_freq(1000); // setup timer to trigger IRQ on the overflow omap_dm_timer_set_int_enable(timer_ptr, OMAP_TIMER_INT_OVERFLOW); // start the timer omap_dm_timer_start(timer_ptr); // done! printk("pwm module: GP Timer initialized and started (%lu Hz, IRQ %d)\n", (long unsigned)gt_rate, timer_irq); // setup a GPIO pwm_setup_pin(38); pwm_data_ptr.pin = 38; set_pwm_dutycycle(1,150); // return success return 0; }