Lines Matching refs:ucb
50 void ucb1x00_io_set_dir(struct ucb1x00 *ucb, unsigned int in, unsigned int out) in ucb1x00_io_set_dir() argument
54 spin_lock_irqsave(&ucb->io_lock, flags); in ucb1x00_io_set_dir()
55 ucb->io_dir |= out; in ucb1x00_io_set_dir()
56 ucb->io_dir &= ~in; in ucb1x00_io_set_dir()
58 ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir); in ucb1x00_io_set_dir()
59 spin_unlock_irqrestore(&ucb->io_lock, flags); in ucb1x00_io_set_dir()
78 void ucb1x00_io_write(struct ucb1x00 *ucb, unsigned int set, unsigned int clear) in ucb1x00_io_write() argument
82 spin_lock_irqsave(&ucb->io_lock, flags); in ucb1x00_io_write()
83 ucb->io_out |= set; in ucb1x00_io_write()
84 ucb->io_out &= ~clear; in ucb1x00_io_write()
86 ucb1x00_reg_write(ucb, UCB_IO_DATA, ucb->io_out); in ucb1x00_io_write()
87 spin_unlock_irqrestore(&ucb->io_lock, flags); in ucb1x00_io_write()
102 unsigned int ucb1x00_io_read(struct ucb1x00 *ucb) in ucb1x00_io_read() argument
104 return ucb1x00_reg_read(ucb, UCB_IO_DATA); in ucb1x00_io_read()
109 struct ucb1x00 *ucb = gpiochip_get_data(chip); in ucb1x00_gpio_set() local
112 spin_lock_irqsave(&ucb->io_lock, flags); in ucb1x00_gpio_set()
114 ucb->io_out |= 1 << offset; in ucb1x00_gpio_set()
116 ucb->io_out &= ~(1 << offset); in ucb1x00_gpio_set()
118 ucb1x00_enable(ucb); in ucb1x00_gpio_set()
119 ucb1x00_reg_write(ucb, UCB_IO_DATA, ucb->io_out); in ucb1x00_gpio_set()
120 ucb1x00_disable(ucb); in ucb1x00_gpio_set()
121 spin_unlock_irqrestore(&ucb->io_lock, flags); in ucb1x00_gpio_set()
126 struct ucb1x00 *ucb = gpiochip_get_data(chip); in ucb1x00_gpio_get() local
129 ucb1x00_enable(ucb); in ucb1x00_gpio_get()
130 val = ucb1x00_reg_read(ucb, UCB_IO_DATA); in ucb1x00_gpio_get()
131 ucb1x00_disable(ucb); in ucb1x00_gpio_get()
138 struct ucb1x00 *ucb = gpiochip_get_data(chip); in ucb1x00_gpio_direction_input() local
141 spin_lock_irqsave(&ucb->io_lock, flags); in ucb1x00_gpio_direction_input()
142 ucb->io_dir &= ~(1 << offset); in ucb1x00_gpio_direction_input()
143 ucb1x00_enable(ucb); in ucb1x00_gpio_direction_input()
144 ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir); in ucb1x00_gpio_direction_input()
145 ucb1x00_disable(ucb); in ucb1x00_gpio_direction_input()
146 spin_unlock_irqrestore(&ucb->io_lock, flags); in ucb1x00_gpio_direction_input()
154 struct ucb1x00 *ucb = gpiochip_get_data(chip); in ucb1x00_gpio_direction_output() local
158 spin_lock_irqsave(&ucb->io_lock, flags); in ucb1x00_gpio_direction_output()
159 old = ucb->io_out; in ucb1x00_gpio_direction_output()
161 ucb->io_out |= mask; in ucb1x00_gpio_direction_output()
163 ucb->io_out &= ~mask; in ucb1x00_gpio_direction_output()
165 ucb1x00_enable(ucb); in ucb1x00_gpio_direction_output()
166 if (old != ucb->io_out) in ucb1x00_gpio_direction_output()
167 ucb1x00_reg_write(ucb, UCB_IO_DATA, ucb->io_out); in ucb1x00_gpio_direction_output()
169 if (!(ucb->io_dir & mask)) { in ucb1x00_gpio_direction_output()
170 ucb->io_dir |= mask; in ucb1x00_gpio_direction_output()
171 ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir); in ucb1x00_gpio_direction_output()
173 ucb1x00_disable(ucb); in ucb1x00_gpio_direction_output()
174 spin_unlock_irqrestore(&ucb->io_lock, flags); in ucb1x00_gpio_direction_output()
181 struct ucb1x00 *ucb = gpiochip_get_data(chip); in ucb1x00_to_irq() local
183 return ucb->irq_base > 0 ? ucb->irq_base + offset : -ENXIO; in ucb1x00_to_irq()
211 void ucb1x00_adc_enable(struct ucb1x00 *ucb) in ucb1x00_adc_enable() argument
213 mutex_lock(&ucb->adc_mutex); in ucb1x00_adc_enable()
215 ucb->adc_cr |= UCB_ADC_ENA; in ucb1x00_adc_enable()
217 ucb1x00_enable(ucb); in ucb1x00_adc_enable()
218 ucb1x00_reg_write(ucb, UCB_ADC_CR, ucb->adc_cr); in ucb1x00_adc_enable()
237 unsigned int ucb1x00_adc_read(struct ucb1x00 *ucb, int adc_channel, int sync) in ucb1x00_adc_read() argument
244 ucb1x00_reg_write(ucb, UCB_ADC_CR, ucb->adc_cr | adc_channel); in ucb1x00_adc_read()
245 ucb1x00_reg_write(ucb, UCB_ADC_CR, ucb->adc_cr | adc_channel | UCB_ADC_START); in ucb1x00_adc_read()
248 val = ucb1x00_reg_read(ucb, UCB_ADC_DATA); in ucb1x00_adc_read()
265 void ucb1x00_adc_disable(struct ucb1x00 *ucb) in ucb1x00_adc_disable() argument
267 ucb->adc_cr &= ~UCB_ADC_ENA; in ucb1x00_adc_disable()
268 ucb1x00_reg_write(ucb, UCB_ADC_CR, ucb->adc_cr); in ucb1x00_adc_disable()
269 ucb1x00_disable(ucb); in ucb1x00_adc_disable()
271 mutex_unlock(&ucb->adc_mutex); in ucb1x00_adc_disable()
284 struct ucb1x00 *ucb = irq_desc_get_handler_data(desc); in ucb1x00_irq() local
287 ucb1x00_enable(ucb); in ucb1x00_irq()
288 isr = ucb1x00_reg_read(ucb, UCB_IE_STATUS); in ucb1x00_irq()
289 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, isr); in ucb1x00_irq()
290 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, 0); in ucb1x00_irq()
294 generic_handle_irq(ucb->irq_base + i); in ucb1x00_irq()
295 ucb1x00_disable(ucb); in ucb1x00_irq()
298 static void ucb1x00_irq_update(struct ucb1x00 *ucb, unsigned mask) in ucb1x00_irq_update() argument
300 ucb1x00_enable(ucb); in ucb1x00_irq_update()
301 if (ucb->irq_ris_enbl & mask) in ucb1x00_irq_update()
302 ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl & in ucb1x00_irq_update()
303 ucb->irq_mask); in ucb1x00_irq_update()
304 if (ucb->irq_fal_enbl & mask) in ucb1x00_irq_update()
305 ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl & in ucb1x00_irq_update()
306 ucb->irq_mask); in ucb1x00_irq_update()
307 ucb1x00_disable(ucb); in ucb1x00_irq_update()
316 struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data); in ucb1x00_irq_mask() local
317 unsigned mask = 1 << (data->irq - ucb->irq_base); in ucb1x00_irq_mask()
319 raw_spin_lock(&ucb->irq_lock); in ucb1x00_irq_mask()
320 ucb->irq_mask &= ~mask; in ucb1x00_irq_mask()
321 ucb1x00_irq_update(ucb, mask); in ucb1x00_irq_mask()
322 raw_spin_unlock(&ucb->irq_lock); in ucb1x00_irq_mask()
327 struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data); in ucb1x00_irq_unmask() local
328 unsigned mask = 1 << (data->irq - ucb->irq_base); in ucb1x00_irq_unmask()
330 raw_spin_lock(&ucb->irq_lock); in ucb1x00_irq_unmask()
331 ucb->irq_mask |= mask; in ucb1x00_irq_unmask()
332 ucb1x00_irq_update(ucb, mask); in ucb1x00_irq_unmask()
333 raw_spin_unlock(&ucb->irq_lock); in ucb1x00_irq_unmask()
338 struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data); in ucb1x00_irq_set_type() local
339 unsigned mask = 1 << (data->irq - ucb->irq_base); in ucb1x00_irq_set_type()
341 raw_spin_lock(&ucb->irq_lock); in ucb1x00_irq_set_type()
343 ucb->irq_ris_enbl |= mask; in ucb1x00_irq_set_type()
345 ucb->irq_ris_enbl &= ~mask; in ucb1x00_irq_set_type()
348 ucb->irq_fal_enbl |= mask; in ucb1x00_irq_set_type()
350 ucb->irq_fal_enbl &= ~mask; in ucb1x00_irq_set_type()
351 if (ucb->irq_mask & mask) { in ucb1x00_irq_set_type()
352 ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl & in ucb1x00_irq_set_type()
353 ucb->irq_mask); in ucb1x00_irq_set_type()
354 ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl & in ucb1x00_irq_set_type()
355 ucb->irq_mask); in ucb1x00_irq_set_type()
357 raw_spin_unlock(&ucb->irq_lock); in ucb1x00_irq_set_type()
364 struct ucb1x00 *ucb = irq_data_get_irq_chip_data(data); in ucb1x00_irq_set_wake() local
365 struct ucb1x00_plat_data *pdata = ucb->mcp->attached_device.platform_data; in ucb1x00_irq_set_wake()
366 unsigned mask = 1 << (data->irq - ucb->irq_base); in ucb1x00_irq_set_wake()
371 raw_spin_lock(&ucb->irq_lock); in ucb1x00_irq_set_wake()
373 ucb->irq_wake |= mask; in ucb1x00_irq_set_wake()
375 ucb->irq_wake &= ~mask; in ucb1x00_irq_set_wake()
376 raw_spin_unlock(&ucb->irq_lock); in ucb1x00_irq_set_wake()
390 static int ucb1x00_add_dev(struct ucb1x00 *ucb, struct ucb1x00_driver *drv) in ucb1x00_add_dev() argument
399 dev->ucb = ucb; in ucb1x00_add_dev()
408 list_add_tail(&dev->dev_node, &ucb->devs); in ucb1x00_add_dev()
441 static int ucb1x00_detect_irq(struct ucb1x00 *ucb) in ucb1x00_detect_irq() argument
450 ucb1x00_reg_write(ucb, UCB_IE_RIS, UCB_IE_ADC); in ucb1x00_detect_irq()
451 ucb1x00_reg_write(ucb, UCB_IE_FAL, UCB_IE_ADC); in ucb1x00_detect_irq()
452 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, 0xffff); in ucb1x00_detect_irq()
453 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, 0); in ucb1x00_detect_irq()
458 ucb1x00_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA); in ucb1x00_detect_irq()
459 ucb1x00_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA | UCB_ADC_START); in ucb1x00_detect_irq()
464 while ((ucb1x00_reg_read(ucb, UCB_ADC_DATA) & UCB_ADC_DAT_VAL) == 0); in ucb1x00_detect_irq()
465 ucb1x00_reg_write(ucb, UCB_ADC_CR, 0); in ucb1x00_detect_irq()
470 ucb1x00_reg_write(ucb, UCB_IE_RIS, 0); in ucb1x00_detect_irq()
471 ucb1x00_reg_write(ucb, UCB_IE_FAL, 0); in ucb1x00_detect_irq()
472 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, 0xffff); in ucb1x00_detect_irq()
473 ucb1x00_reg_write(ucb, UCB_IE_CLEAR, 0); in ucb1x00_detect_irq()
483 struct ucb1x00 *ucb = classdev_to_ucb1x00(dev); in ucb1x00_release() local
484 kfree(ucb); in ucb1x00_release()
496 struct ucb1x00 *ucb; in ucb1x00_probe() local
513 ucb = kzalloc(sizeof(struct ucb1x00), GFP_KERNEL); in ucb1x00_probe()
515 if (!ucb) in ucb1x00_probe()
518 device_initialize(&ucb->dev); in ucb1x00_probe()
519 ucb->dev.class = &ucb1x00_class; in ucb1x00_probe()
520 ucb->dev.parent = &mcp->attached_device; in ucb1x00_probe()
521 dev_set_name(&ucb->dev, "ucb1x00"); in ucb1x00_probe()
523 raw_spin_lock_init(&ucb->irq_lock); in ucb1x00_probe()
524 spin_lock_init(&ucb->io_lock); in ucb1x00_probe()
525 mutex_init(&ucb->adc_mutex); in ucb1x00_probe()
527 ucb->id = id; in ucb1x00_probe()
528 ucb->mcp = mcp; in ucb1x00_probe()
530 ret = device_add(&ucb->dev); in ucb1x00_probe()
534 ucb1x00_enable(ucb); in ucb1x00_probe()
535 ucb->irq = ucb1x00_detect_irq(ucb); in ucb1x00_probe()
536 ucb1x00_disable(ucb); in ucb1x00_probe()
537 if (!ucb->irq) { in ucb1x00_probe()
538 dev_err(&ucb->dev, "IRQ probe failed\n"); in ucb1x00_probe()
543 ucb->gpio.base = -1; in ucb1x00_probe()
545 ucb->irq_base = irq_alloc_descs(-1, irq_base, 16, -1); in ucb1x00_probe()
546 if (ucb->irq_base < 0) { in ucb1x00_probe()
547 dev_err(&ucb->dev, "unable to allocate 16 irqs: %d\n", in ucb1x00_probe()
548 ucb->irq_base); in ucb1x00_probe()
549 ret = ucb->irq_base; in ucb1x00_probe()
554 unsigned irq = ucb->irq_base + i; in ucb1x00_probe()
557 irq_set_chip_data(irq, ucb); in ucb1x00_probe()
561 irq_set_irq_type(ucb->irq, IRQ_TYPE_EDGE_RISING); in ucb1x00_probe()
562 irq_set_chained_handler_and_data(ucb->irq, ucb1x00_irq, ucb); in ucb1x00_probe()
565 ucb->gpio.label = dev_name(&ucb->dev); in ucb1x00_probe()
566 ucb->gpio.parent = &ucb->dev; in ucb1x00_probe()
567 ucb->gpio.owner = THIS_MODULE; in ucb1x00_probe()
568 ucb->gpio.base = pdata->gpio_base; in ucb1x00_probe()
569 ucb->gpio.ngpio = 10; in ucb1x00_probe()
570 ucb->gpio.set = ucb1x00_gpio_set; in ucb1x00_probe()
571 ucb->gpio.get = ucb1x00_gpio_get; in ucb1x00_probe()
572 ucb->gpio.direction_input = ucb1x00_gpio_direction_input; in ucb1x00_probe()
573 ucb->gpio.direction_output = ucb1x00_gpio_direction_output; in ucb1x00_probe()
574 ucb->gpio.to_irq = ucb1x00_to_irq; in ucb1x00_probe()
575 ret = gpiochip_add_data(&ucb->gpio, ucb); in ucb1x00_probe()
579 dev_info(&ucb->dev, "gpio_base not set so no gpiolib support"); in ucb1x00_probe()
581 mcp_set_drvdata(mcp, ucb); in ucb1x00_probe()
584 device_set_wakeup_capable(&ucb->dev, pdata->can_wakeup); in ucb1x00_probe()
586 INIT_LIST_HEAD(&ucb->devs); in ucb1x00_probe()
588 list_add_tail(&ucb->node, &ucb1x00_devices); in ucb1x00_probe()
590 ucb1x00_add_dev(ucb, drv); in ucb1x00_probe()
597 irq_set_chained_handler(ucb->irq, NULL); in ucb1x00_probe()
599 if (ucb->irq_base > 0) in ucb1x00_probe()
600 irq_free_descs(ucb->irq_base, 16); in ucb1x00_probe()
602 device_del(&ucb->dev); in ucb1x00_probe()
604 put_device(&ucb->dev); in ucb1x00_probe()
614 struct ucb1x00 *ucb = mcp_get_drvdata(mcp); in ucb1x00_remove() local
618 list_del(&ucb->node); in ucb1x00_remove()
619 list_for_each_safe(l, n, &ucb->devs) { in ucb1x00_remove()
625 if (ucb->gpio.base != -1) in ucb1x00_remove()
626 gpiochip_remove(&ucb->gpio); in ucb1x00_remove()
628 irq_set_chained_handler(ucb->irq, NULL); in ucb1x00_remove()
629 irq_free_descs(ucb->irq_base, 16); in ucb1x00_remove()
630 device_unregister(&ucb->dev); in ucb1x00_remove()
638 struct ucb1x00 *ucb; in ucb1x00_register_driver() local
643 list_for_each_entry(ucb, &ucb1x00_devices, node) { in ucb1x00_register_driver()
644 ucb1x00_add_dev(ucb, drv); in ucb1x00_register_driver()
667 struct ucb1x00 *ucb = dev_get_drvdata(dev); in ucb1x00_suspend() local
671 list_for_each_entry(udev, &ucb->devs, dev_node) { in ucb1x00_suspend()
677 if (ucb->irq_wake) { in ucb1x00_suspend()
680 raw_spin_lock_irqsave(&ucb->irq_lock, flags); in ucb1x00_suspend()
681 ucb1x00_enable(ucb); in ucb1x00_suspend()
682 ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl & in ucb1x00_suspend()
683 ucb->irq_wake); in ucb1x00_suspend()
684 ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl & in ucb1x00_suspend()
685 ucb->irq_wake); in ucb1x00_suspend()
686 ucb1x00_disable(ucb); in ucb1x00_suspend()
687 raw_spin_unlock_irqrestore(&ucb->irq_lock, flags); in ucb1x00_suspend()
689 enable_irq_wake(ucb->irq); in ucb1x00_suspend()
699 struct ucb1x00 *ucb = dev_get_drvdata(dev); in ucb1x00_resume() local
702 if (!ucb->irq_wake && pdata && pdata->reset) in ucb1x00_resume()
705 ucb1x00_enable(ucb); in ucb1x00_resume()
706 ucb1x00_reg_write(ucb, UCB_IO_DATA, ucb->io_out); in ucb1x00_resume()
707 ucb1x00_reg_write(ucb, UCB_IO_DIR, ucb->io_dir); in ucb1x00_resume()
709 if (ucb->irq_wake) { in ucb1x00_resume()
712 raw_spin_lock_irqsave(&ucb->irq_lock, flags); in ucb1x00_resume()
713 ucb1x00_reg_write(ucb, UCB_IE_RIS, ucb->irq_ris_enbl & in ucb1x00_resume()
714 ucb->irq_mask); in ucb1x00_resume()
715 ucb1x00_reg_write(ucb, UCB_IE_FAL, ucb->irq_fal_enbl & in ucb1x00_resume()
716 ucb->irq_mask); in ucb1x00_resume()
717 raw_spin_unlock_irqrestore(&ucb->irq_lock, flags); in ucb1x00_resume()
719 disable_irq_wake(ucb->irq); in ucb1x00_resume()
721 ucb1x00_disable(ucb); in ucb1x00_resume()
724 list_for_each_entry(udev, &ucb->devs, dev_node) { in ucb1x00_resume()