ONOFF button

Discussion in 'Kernels' started by arzej, Mar 10, 2014.

  1. arzej

    arzej New Member

    Joined:
    Jun 10, 2013
    Messages:
    5
    Likes Received:
    0
    ONOFF button doesn't work for me. It would be great to make it works. I am able to register pressing button as interrupt but I don'n know how to make udoo go sleep and after second press wakeup. Maybe someone already works on this task and could share his work?

    Here is my code:
    Code:
    #define	SNVS_LPSR_REG			0x4C	/* LP Status Register */
    #define	SNVS_LPCR_REG			0x38	/* LP Control Register */
    #define SNVS_LPSR_SPO			(0x1 << 18)
    #define SNVS_LPSR_EO			(0x1 << 17)
    #define SNVS_LPSR_MASK		0x0f000000
    #define SNVS_LPCR_TOP			(0x1 << 6)
    #define SNVS_LPCR_DEP_EN	(0x1 << 5)
    
    struct work_struct work_pm;
    int                irq = 36;
    void __iomem *mx6_snvs_base_pm = MX6_IO_ADDRESS(MX6Q_SNVS_BASE_ADDR);
    
    static void pwr_keys_work_func( struct work_struct *work )
    {
    	printk(" =======%s()\n", __func__ );
    	//enable_irq(irq);
    }
    
    static irqreturn_t snvs_pwrkey_interrupt(int irq, void *dev_id)
    {
    	u32 lp_status, lp_cr;
    	lp_status = __raw_readl( mx6_snvs_base_pm + SNVS_LPSR_REG );
    	lp_cr = __raw_readl( mx6_snvs_base_pm + SNVS_LPCR_REG );
    	printk(" =======%s()\n lpstatus 0x%x, lp_cr 0x%x \n",__func__, lp_status, lp_cr);
    	if (lp_cr & SNVS_LPCR_TOP)
    	{
    		printk(" power off the pmic request trigger");
    	}
    	if (lp_cr & SNVS_LPCR_DEP_EN)
    	{
    		printk(" set snvs as DUMP PMIC MODE\n");
    	}
    	else
    	{
    		printk(" Not DUMP PMIC MODE, EO will be ingnored!\n");
    	}
    	if (lp_status & SNVS_LPSR_SPO && !(lp_status & SNVS_LPSR_EO))
    	{
    		printk(" =======%s()\n 1 \n",__func__);
    	}
    	else
    	{
    		printk(" =======%s()\n 2 \n",__func__);
    	}
    	/* clear SPO/EO status */
    	__raw_writel( lp_status, mx6_snvs_base_pm + SNVS_LPSR_REG );
    	//disable_irq(irq);
    	schedule_work(&work_pm);
    	return IRQ_HANDLED;
    }
    
    void init_pwr_btn()
    {
      u32 lp_cr = 0;
      int ret = 0;
    
    	lp_cr = __raw_readl( mx6_snvs_base_pm + SNVS_LPCR_REG );
    	printk(" =======%s()\n lp_cr 0x%x \n",__func__, lp_cr);
    	lp_cr |= SNVS_LPCR_DEP_EN,
    	printk(" =======%s()\n lp_cr 0x%x \n",__func__, lp_cr);
    	__raw_writel( lp_cr, mx6_snvs_base_pm + SNVS_LPCR_REG );
    	INIT_WORK( &work_pm, pwr_keys_work_func );
    	ret = request_irq( irq, snvs_pwrkey_interrupt, IRQF_NO_SUSPEND, "imx_pm", NULL );
    	if(ret < 0)
    	{
    		printk("interrupt not available.\n");
    		irq = -1;
    	}
    	else
    	{
    		disable_irq( irq );
    	}
    	enable_irq( irq );
    }
    
    Here is thread on offcial freescale forum: https://freescale.hosted.jivesoftware.com/thread/308257
     

Share This Page