Ejemplo n.º 1
0
void __p2pm_do_poff(void)
{
    /* check GPIO port */
    if(!gpio_is_valid_port(param.gpio)){
        PWARNING("can't power-off in order to invalid gpio port=%d\n",param.gpio);
        return;
    }
    PEMERG("power-off by GPIO port = %d\n",param.gpio);
    gpio_set_value(param.gpio,param.pol?1:0);
}
Ejemplo n.º 2
0
/* initilazie */
static int init_key(struct msudev_keyev_ops *ops)
{
    int retval = 0;
    struct key_param *kp = (struct key_param *)ops->data;
    memset(kp,0,sizeof(struct key_param));

    /* get key mapping to gpio */
    {
        struct device_node *np;
        const u32 *prop;
        u32 len,i;
        

        np = of_find_compatible_node(NULL,devtype,compatible);
        if(!np){
            _ERR("NOT found a node : dev_type=\"%s\", compatible=\"%s\"\n",
                 devtype, compatible);
            retval = -EINVAL;
            goto fail;
        }

        prop = of_get_property(np,"key-map",&len);
        len /= sizeof(u32);
        if(!prop||len<3||(len%3)){
            _ERR("NOT found \"key-map\" property or too few cells in this property\n");
            retval = -EINVAL;
            goto fail;
        }

        kp->nr_map = len/3;
        kp->maps = (struct gpio_maps *)kzalloc(sizeof(struct gpio_maps) * kp->nr_map,
                                               GFP_KERNEL);
        if(NULL==kp->maps){
            _ERR("failed to allocate memory\n");
            retval=-ENOMEM;
            goto fail;
        }

        for(i=0;i<len;i+=3){
            struct gpio_maps *p = &kp->maps[i/3];
            p->keyno = prop[i];
            if(p->keyno >= (sizeof(kp->keymap)*8)){
                _ERR("invalid key number = %d\n", p->keyno);
                retval = -EINVAL;
                goto fail;
            }
            p->gpio = of_get_gpio(np,prop[i+1]);
            if(p->gpio<0){
                _ERR("NOT foud gpio port");
                retval=p->gpio;
                goto fail;
            }
            if(!gpio_is_valid_port(p->gpio)){
                _ERR("invalid gpio = %d\n",p->gpio);
                retval=-ENODEV;
                goto fail;
            }
            if(prop[i+2])
                p->flags |= FLAG_REVERSE;
            _INFO("key[%d] --> gpio[%d]%s\n",p->keyno,p->gpio,(p->flags&FLAG_REVERSE)?" : REVERSE":"");
        }

    }

    /* setup timer */
    setup_timer(&(kp->timer),timer_fn,(unsigned long)&key_param);
    kp->timer.expires = jiffies + timer_period;
    add_timer(&(kp->timer));

 fail:

    if(retval<0){

        /* deallocate memory */
        if(kp->maps){
            kfree(kp->maps);
            kp->maps=NULL;
            kp->nr_map = 0;
        }

    }

    /* complete */
    return retval;
}