static int ricoh583_alarm_irq_enable(struct device *dev, unsigned int enabled) { struct ricoh583_rtc *rtc = dev_get_drvdata(dev); int ret; dev_info(dev, "%s: %d\n", __func__, enabled); if (enabled){ rtc->irq_en = true; ret = ricoh583_set_bits(dev->parent, rtc_ctrl1, 1 << 5); }else{ rtc->irq_en = false; ret = ricoh583_clr_bits(dev->parent, rtc_ctrl1, 1 << 5); } return ret; }
static __devinit int ricoh583_ac_detect_probe(struct platform_device *pdev) { struct ricoh583_ac_detect_info *info; struct ricoh583_ac_detect_platform_data *pdata; int ret; info = kzalloc(sizeof(struct ricoh583_ac_detect_info), GFP_KERNEL); if (!info) return -ENOMEM; info->dev = &pdev->dev; pdata = pdev->dev.platform_data; info->irq = pdata->irq; #if RICOH583_USB_CHARGER_DETECT info->usb_gpio = pdata->usb_gpio; info->usb_irq = gpio_to_irq(info->usb_gpio); #endif platform_set_drvdata(pdev, info); info->online = 0; g_info = info; ret = ricoh583_set_bits(info->dev->parent, RICOH583_PWRIRSL1_REG, 1 << 1);//both edge trigger if (ret){ goto out; } INIT_WORK(&info->work, ricoh583_ac_detect_irq_work); ret = request_threaded_irq(info->irq, NULL, ricoh583_ac_detect_irq, IRQF_ONESHOT, "ricoh583_ac_detect", info); if (ret < 0) { dev_err(&pdev->dev, "Can't get %d IRQ for ricoh583 charger detect: %d\n", info->irq, ret); goto out; } #if RICOH583_USB_CHARGER_DETECT INIT_DELAYED_WORK(&info->usb_work, ricoh583_usb_work); ret = gpio_request(info->usb_gpio, "usb_detect"); if (ret < 0){ dev_err(&pdev->dev, "%s: gpio %d request failed!\n", __func__, info->usb_gpio); goto irq; } gpio_direction_input(info->usb_gpio); int val = gpio_get_value(info->usb_gpio); gpio_free(info->usb_gpio); if (val){ info->usb_online = 0; ret = request_threaded_irq(info->usb_irq, NULL, ricoh583_usb_irq, IRQF_TRIGGER_FALLING, "usb_charger_detect", info); }else{ info->usb_online = 1; dev_info(g_info->dev, "USB charger is plugged!\n"); ricoh583_charger_plug(CHG_TYPE_USB); ret = request_threaded_irq(info->usb_irq, NULL, ricoh583_usb_irq, IRQF_TRIGGER_RISING, "usb_charger_detect", info); } if (ret < 0) { dev_err(&pdev->dev, "Can't get %d IRQ for ricoh583 usb charger detect: %d\n", info->usb_irq, ret); goto irq; } device_init_wakeup(info->dev, 1); enable_irq_wake(info->usb_irq); #endif dev_info(&pdev->dev, "%s is OK!\n", __func__); return 0; irq: free_irq(info->irq, info); out: kfree(info); return -1; }
static int __devinit ricoh583_pwrkey_probe(struct platform_device *pdev) { struct input_dev *pwr; int key_irq; int err; struct ricoh583_pwrkey *pwrkey; struct ricoh583_pwrkey_platform_data *pdata = pdev->dev.platform_data; uint8_t val; if (!pdata) { dev_err(&pdev->dev, "power key platform data not supplied\n"); return -EINVAL; } key_irq = pdata->irq; pwrkey = kzalloc(sizeof(*pwrkey), GFP_KERNEL); if (!pwrkey) return -ENOMEM; pwrkey->dev = &pdev->dev; pwrkey->pdata = pdata; pwrkey->pressed_first = false; pwrkey->delay = HZ / 1000 * pdata->delay_ms; g_pwrkey = pwrkey; pwr = input_allocate_device(); if (!pwr) { dev_dbg(&pdev->dev, "Can't allocate power button\n"); err = -ENOMEM; goto free_pwrkey; } input_set_capability(pwr, EV_KEY, KEY_POWER); pwr->name = "ricoh583_pwrkey"; pwr->phys = "ricoh583_pwrkey/input0"; pwr->dev.parent = &pdev->dev; #if RICOH583_ONKEY_TRIGGER_LEVEL init_timer(&pwrkey->timer); pwrkey->timer.function = ricoh583_pwrkey_timer; #endif mutex_init(&pwrkey->lock); err = input_register_device(pwr); if (err) { dev_dbg(&pdev->dev, "Can't register power key: %d\n", err); goto free_input_dev; } pwrkey->key_irq = key_irq; pwrkey->pwr = pwr; platform_set_drvdata(pdev, pwrkey); /* Check if power-key is pressed at boot up */ err = ricoh583_read(pwrkey->dev->parent, 0x1b, &val); if (err < 0) { dev_err(&pdev->dev, "Key-press status at boot failed rc=%d\n", err); goto unreg_input_dev; } val &= 0x1; if (val) { input_report_key(pwrkey->pwr, KEY_POWER, 1); dev_info(&pdev->dev, "the power key is pressed!\n"); input_sync(pwrkey->pwr); pwrkey->pressed_first = true; } #if !(RICOH583_ONKEY_TRIGGER_LEVEL) ricoh583_set_bits(pwrkey->dev->parent, 0x1c, 0x1); //trigger both edge #endif err = request_threaded_irq(key_irq, NULL, pwrkey_irq, IRQF_ONESHOT, "ricoh583_pwrkey", pwrkey); if (err < 0) { dev_err(&pdev->dev, "Can't get %d IRQ for pwrkey: %d\n", key_irq, err); goto unreg_input_dev; } #if RICOH583_ONKEY_OFF_IRQ err = request_threaded_irq(key_irq + RICOH583_IRQ_ONKEY_OFF, NULL, pwrkey_irq_off, IRQF_ONESHOT, "ricoh583_pwrkey_off", pwrkey); if (err < 0) { dev_err(&pdev->dev, "Can't get %d IRQ for pwrkey: %d\n", key_irq + RICOH583_IRQ_ONKEY_OFF, err); free_irq(key_irq, pwrkey); goto unreg_input_dev; } #endif pwrkey->workqueue = create_singlethread_workqueue("ricoh583_pwrkey"); INIT_WORK(&pwrkey->work, ricoh583_irq_work); printk("%s is OK!\n", __func__); return 0; unreg_input_dev: input_unregister_device(pwr); pwr = NULL; free_input_dev: input_free_device(pwr); free_pwrkey: kfree(pwrkey); return err; }