Lines Matching refs:lm
162 static int lm8323_write(struct lm8323_chip *lm, int len, ...) in lm8323_write() argument
171 dev_err(&lm->client->dev, "tried to send %d bytes\n", len); in lm8323_write()
185 ret = i2c_master_send(lm->client, data, len); in lm8323_write()
187 ret = i2c_master_send(lm->client, data, len); in lm8323_write()
189 dev_err(&lm->client->dev, "sent %d bytes of %d total\n", in lm8323_write()
199 static int lm8323_read(struct lm8323_chip *lm, u8 cmd, u8 *buf, int len) in lm8323_read() argument
207 ret = i2c_master_send(lm->client, &cmd, 1); in lm8323_read()
209 ret = i2c_master_send(lm->client, &cmd, 1); in lm8323_read()
211 dev_err(&lm->client->dev, "sending read cmd 0x%02x failed\n", in lm8323_read()
216 ret = i2c_master_recv(lm->client, buf, len); in lm8323_read()
218 dev_err(&lm->client->dev, "wanted %d bytes, got %d\n", in lm8323_read()
227 static void lm8323_set_active_time(struct lm8323_chip *lm, int time) in lm8323_set_active_time() argument
229 lm8323_write(lm, 2, LM8323_CMD_SET_ACTIVE, time >> 2); in lm8323_set_active_time()
246 static void process_keys(struct lm8323_chip *lm) in process_keys() argument
250 int old_keys_down = lm->keys_down; in process_keys()
258 ret = lm8323_read(lm, LM8323_CMD_READ_FIFO, key_fifo, LM8323_FIFO_LEN); in process_keys()
261 dev_err(&lm->client->dev, "Failed reading fifo \n"); in process_keys()
269 unsigned short keycode = lm->keymap[key]; in process_keys()
271 dev_vdbg(&lm->client->dev, "key 0x%02x %s\n", in process_keys()
274 if (lm->kp_enabled) { in process_keys()
275 input_event(lm->idev, EV_MSC, MSC_SCAN, key); in process_keys()
276 input_report_key(lm->idev, keycode, isdown); in process_keys()
277 input_sync(lm->idev); in process_keys()
281 lm->keys_down++; in process_keys()
283 lm->keys_down--; in process_keys()
291 if (!old_keys_down && lm->keys_down) in process_keys()
292 lm8323_set_active_time(lm, 0); in process_keys()
293 if (old_keys_down && !lm->keys_down) in process_keys()
294 lm8323_set_active_time(lm, lm->active_time); in process_keys()
297 static void lm8323_process_error(struct lm8323_chip *lm) in lm8323_process_error() argument
301 if (lm8323_read(lm, LM8323_CMD_READ_ERR, &error, 1) == 1) { in lm8323_process_error()
303 dev_vdbg(&lm->client->dev, "fifo overflow!\n"); in lm8323_process_error()
305 dev_vdbg(&lm->client->dev, in lm8323_process_error()
308 dev_vdbg(&lm->client->dev, in lm8323_process_error()
311 dev_vdbg(&lm->client->dev, "bad command parameter\n"); in lm8323_process_error()
315 static void lm8323_reset(struct lm8323_chip *lm) in lm8323_reset() argument
318 lm8323_write(lm, 2, LM8323_CMD_RESET, 0xAA); in lm8323_reset()
321 static int lm8323_configure(struct lm8323_chip *lm) in lm8323_configure() argument
323 int keysize = (lm->size_x << 4) | lm->size_y; in lm8323_configure()
325 int debounce = lm->debounce_time >> 2; in lm8323_configure()
326 int active = lm->active_time >> 2; in lm8323_configure()
335 lm8323_write(lm, 2, LM8323_CMD_WRITE_CFG, 0); in lm8323_configure()
336 lm8323_write(lm, 2, LM8323_CMD_WRITE_CLOCK, clock); in lm8323_configure()
337 lm8323_write(lm, 2, LM8323_CMD_SET_KEY_SIZE, keysize); in lm8323_configure()
338 lm8323_set_active_time(lm, lm->active_time); in lm8323_configure()
339 lm8323_write(lm, 2, LM8323_CMD_SET_DEBOUNCE, debounce); in lm8323_configure()
340 lm8323_write(lm, 3, LM8323_CMD_WRITE_PORT_STATE, 0xff, 0xff); in lm8323_configure()
341 lm8323_write(lm, 3, LM8323_CMD_WRITE_PORT_SEL, 0, 0); in lm8323_configure()
366 struct lm8323_chip *lm = _lm; in lm8323_irq() local
370 mutex_lock(&lm->lock); in lm8323_irq()
372 while ((lm8323_read(lm, LM8323_CMD_READ_INT, &ints, 1) == 1) && ints) { in lm8323_irq()
374 process_keys(lm); in lm8323_irq()
377 dev_vdbg(&lm->client->dev, "rotator fired\n"); in lm8323_irq()
380 dev_vdbg(&lm->client->dev, "error!\n"); in lm8323_irq()
381 lm8323_process_error(lm); in lm8323_irq()
384 dev_err(&lm->client->dev, "chip lost config; " in lm8323_irq()
386 lm8323_configure(lm); in lm8323_irq()
390 dev_vdbg(&lm->client->dev, in lm8323_irq()
392 pwm_done(&lm->pwm[i]); in lm8323_irq()
397 mutex_unlock(&lm->lock); in lm8323_irq()
405 static int lm8323_read_id(struct lm8323_chip *lm, u8 *buf) in lm8323_read_id() argument
409 bytes = lm8323_read(lm, LM8323_CMD_READ_ID, buf, 2); in lm8323_read_id()
501 struct lm8323_chip *lm = pwm->chip; in lm8323_pwm_set_brightness() local
513 mutex_lock(&lm->lock); in lm8323_pwm_set_brightness()
514 if (likely(!lm->pm_suspend)) in lm8323_pwm_set_brightness()
518 mutex_unlock(&lm->lock); in lm8323_pwm_set_brightness()
555 static int init_pwm(struct lm8323_chip *lm, int id, struct device *dev, in init_pwm() argument
562 pwm = &lm->pwm[id - 1]; in init_pwm()
572 pwm->chip = lm; in init_pwm()
593 struct lm8323_chip *lm = dev_get_drvdata(dev); in lm8323_show_disable() local
595 return sprintf(buf, "%u\n", !lm->kp_enabled); in lm8323_show_disable()
602 struct lm8323_chip *lm = dev_get_drvdata(dev); in lm8323_set_disable() local
610 mutex_lock(&lm->lock); in lm8323_set_disable()
611 lm->kp_enabled = !i; in lm8323_set_disable()
612 mutex_unlock(&lm->lock); in lm8323_set_disable()
623 struct lm8323_chip *lm; in lm8323_probe() local
646 lm = kzalloc(sizeof *lm, GFP_KERNEL); in lm8323_probe()
648 if (!lm || !idev) { in lm8323_probe()
653 lm->client = client; in lm8323_probe()
654 lm->idev = idev; in lm8323_probe()
655 mutex_init(&lm->lock); in lm8323_probe()
657 lm->size_x = pdata->size_x; in lm8323_probe()
658 lm->size_y = pdata->size_y; in lm8323_probe()
660 lm->size_x, lm->size_y); in lm8323_probe()
662 lm->debounce_time = pdata->debounce_time; in lm8323_probe()
663 lm->active_time = pdata->active_time; in lm8323_probe()
665 lm8323_reset(lm); in lm8323_probe()
670 while (lm8323_read(lm, LM8323_CMD_READ_INT, data, 1) == 1) { in lm8323_probe()
683 lm8323_configure(lm); in lm8323_probe()
686 if (lm8323_read_id(lm, data) != 0) { in lm8323_probe()
693 err = init_pwm(lm, pwm + 1, &client->dev, in lm8323_probe()
699 lm->kp_enabled = true; in lm8323_probe()
705 snprintf(lm->phys, sizeof(lm->phys), in lm8323_probe()
707 idev->phys = lm->phys; in lm8323_probe()
713 lm->keymap[i] = pdata->keymap[i]; in lm8323_probe()
727 IRQF_TRIGGER_LOW|IRQF_ONESHOT, "lm8323", lm); in lm8323_probe()
733 i2c_set_clientdata(client, lm); in lm8323_probe()
747 if (lm->pwm[pwm].enabled) in lm8323_probe()
748 led_classdev_unregister(&lm->pwm[pwm].cdev); in lm8323_probe()
751 kfree(lm); in lm8323_probe()
757 struct lm8323_chip *lm = i2c_get_clientdata(client); in lm8323_remove() local
761 free_irq(client->irq, lm); in lm8323_remove()
763 input_unregister_device(lm->idev); in lm8323_remove()
765 device_remove_file(&lm->client->dev, &dev_attr_disable_kp); in lm8323_remove()
768 if (lm->pwm[i].enabled) in lm8323_remove()
769 led_classdev_unregister(&lm->pwm[i].cdev); in lm8323_remove()
771 kfree(lm); in lm8323_remove()
784 struct lm8323_chip *lm = i2c_get_clientdata(client); in lm8323_suspend() local
790 mutex_lock(&lm->lock); in lm8323_suspend()
791 lm->pm_suspend = true; in lm8323_suspend()
792 mutex_unlock(&lm->lock); in lm8323_suspend()
795 if (lm->pwm[i].enabled) in lm8323_suspend()
796 led_classdev_suspend(&lm->pwm[i].cdev); in lm8323_suspend()
804 struct lm8323_chip *lm = i2c_get_clientdata(client); in lm8323_resume() local
807 mutex_lock(&lm->lock); in lm8323_resume()
808 lm->pm_suspend = false; in lm8323_resume()
809 mutex_unlock(&lm->lock); in lm8323_resume()
812 if (lm->pwm[i].enabled) in lm8323_resume()
813 led_classdev_resume(&lm->pwm[i].cdev); in lm8323_resume()