Lines Matching refs:ljca_gpio

77 static int ljca_gpio_config(struct ljca_gpio_dev *ljca_gpio, u8 gpio_id,  in ljca_gpio_config()  argument
81 (struct ljca_gpio_packet *)ljca_gpio->obuf; in ljca_gpio_config()
84 mutex_lock(&ljca_gpio->trans_lock); in ljca_gpio_config()
86 packet->item[0].value = config | ljca_gpio->connect_mode[gpio_id]; in ljca_gpio_config()
89 ret = ljca_transfer(ljca_gpio->ljca, LJCA_GPIO_CONFIG, (u8 *)packet, in ljca_gpio_config()
91 mutex_unlock(&ljca_gpio->trans_lock); in ljca_gpio_config()
96 static int ljca_gpio_read(struct ljca_gpio_dev *ljca_gpio, u8 gpio_id) in ljca_gpio_read() argument
99 (struct ljca_gpio_packet *)ljca_gpio->ibuf; in ljca_gpio_read()
101 (struct ljca_gpio_packet *)ljca_gpio->obuf; in ljca_gpio_read()
104 mutex_lock(&ljca_gpio->trans_lock); in ljca_gpio_read()
107 ret = ljca_transfer(ljca_gpio->ljca, LJCA_GPIO_READ, (u8 *)packet, in ljca_gpio_read()
109 ljca_gpio->ibuf, LJCA_GPIO_BUF_SIZE); in ljca_gpio_read()
112 dev_err(&ljca_gpio->ljca->auxdev.dev, in ljca_gpio_read()
117 mutex_unlock(&ljca_gpio->trans_lock); in ljca_gpio_read()
122 static int ljca_gpio_write(struct ljca_gpio_dev *ljca_gpio, u8 gpio_id, int value) in ljca_gpio_write() argument
125 (struct ljca_gpio_packet *)ljca_gpio->obuf; in ljca_gpio_write()
128 mutex_lock(&ljca_gpio->trans_lock); in ljca_gpio_write()
133 ret = ljca_transfer(ljca_gpio->ljca, LJCA_GPIO_WRITE, (u8 *)packet, in ljca_gpio_write()
135 mutex_unlock(&ljca_gpio->trans_lock); in ljca_gpio_write()
142 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(chip); in ljca_gpio_get_value() local
144 return ljca_gpio_read(ljca_gpio, offset); in ljca_gpio_get_value()
150 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(chip); in ljca_gpio_set_value() local
153 ret = ljca_gpio_write(ljca_gpio, offset, val); in ljca_gpio_set_value()
162 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(chip); in ljca_gpio_direction_input() local
166 ret = ljca_gpio_config(ljca_gpio, offset, config); in ljca_gpio_direction_input()
170 clear_bit(offset, ljca_gpio->output_enabled); in ljca_gpio_direction_input()
178 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(chip); in ljca_gpio_direction_output() local
182 ret = ljca_gpio_config(ljca_gpio, offset, config); in ljca_gpio_direction_output()
187 set_bit(offset, ljca_gpio->output_enabled); in ljca_gpio_direction_output()
194 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(chip); in ljca_gpio_get_direction() local
196 if (test_bit(offset, ljca_gpio->output_enabled)) in ljca_gpio_get_direction()
205 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(chip); in ljca_gpio_set_config() local
207 ljca_gpio->connect_mode[offset] = 0; in ljca_gpio_set_config()
210 ljca_gpio->connect_mode[offset] |= LJCA_GPIO_CONF_PULLUP; in ljca_gpio_set_config()
213 ljca_gpio->connect_mode[offset] |= LJCA_GPIO_CONF_PULLDOWN; in ljca_gpio_set_config()
229 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(chip); in ljca_gpio_init_valid_mask() local
231 WARN_ON_ONCE(ngpios != ljca_gpio->gpio_info->num); in ljca_gpio_init_valid_mask()
232 bitmap_copy(valid_mask, ljca_gpio->gpio_info->valid_pin_map, ngpios); in ljca_gpio_init_valid_mask()
244 static int ljca_enable_irq(struct ljca_gpio_dev *ljca_gpio, int gpio_id, in ljca_enable_irq() argument
248 (struct ljca_gpio_packet *)ljca_gpio->obuf; in ljca_enable_irq()
251 mutex_lock(&ljca_gpio->trans_lock); in ljca_enable_irq()
256 ret = ljca_transfer(ljca_gpio->ljca, in ljca_enable_irq()
260 mutex_unlock(&ljca_gpio->trans_lock); in ljca_enable_irq()
267 struct ljca_gpio_dev *ljca_gpio = in ljca_gpio_async() local
271 for_each_set_bit(gpio_id, ljca_gpio->reenable_irqs, ljca_gpio->gc.ngpio) { in ljca_gpio_async()
272 clear_bit(gpio_id, ljca_gpio->reenable_irqs); in ljca_gpio_async()
273 unmasked = test_bit(gpio_id, ljca_gpio->unmasked_irqs); in ljca_gpio_async()
275 ljca_enable_irq(ljca_gpio, gpio_id, true); in ljca_gpio_async()
283 struct ljca_gpio_dev *ljca_gpio = context; in ljca_gpio_event_cb() local
290 irq = irq_find_mapping(ljca_gpio->gc.irq.domain, in ljca_gpio_event_cb()
293 dev_err(ljca_gpio->gc.parent, in ljca_gpio_event_cb()
299 generic_handle_domain_irq(ljca_gpio->gc.irq.domain, irq); in ljca_gpio_event_cb()
300 set_bit(packet->item[i].index, ljca_gpio->reenable_irqs); in ljca_gpio_event_cb()
303 schedule_work(&ljca_gpio->work); in ljca_gpio_event_cb()
309 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(gc); in ljca_irq_unmask() local
313 set_bit(gpio_id, ljca_gpio->unmasked_irqs); in ljca_irq_unmask()
319 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(gc); in ljca_irq_mask() local
322 clear_bit(gpio_id, ljca_gpio->unmasked_irqs); in ljca_irq_mask()
329 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(gc); in ljca_irq_set_type() local
332 ljca_gpio->connect_mode[gpio_id] = LJCA_GPIO_CONF_INTERRUPT; in ljca_irq_set_type()
335 ljca_gpio->connect_mode[gpio_id] |= in ljca_irq_set_type()
339 ljca_gpio->connect_mode[gpio_id] |= in ljca_irq_set_type()
345 ljca_gpio->connect_mode[gpio_id] |= in ljca_irq_set_type()
349 ljca_gpio->connect_mode[gpio_id] |= in ljca_irq_set_type()
362 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(gc); in ljca_irq_bus_lock() local
364 mutex_lock(&ljca_gpio->irq_lock); in ljca_irq_bus_lock()
370 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(gc); in ljca_irq_bus_unlock() local
374 enabled = test_bit(gpio_id, ljca_gpio->enabled_irqs); in ljca_irq_bus_unlock()
375 unmasked = test_bit(gpio_id, ljca_gpio->unmasked_irqs); in ljca_irq_bus_unlock()
379 ljca_gpio_config(ljca_gpio, gpio_id, 0); in ljca_irq_bus_unlock()
380 ljca_enable_irq(ljca_gpio, gpio_id, true); in ljca_irq_bus_unlock()
381 set_bit(gpio_id, ljca_gpio->enabled_irqs); in ljca_irq_bus_unlock()
383 ljca_enable_irq(ljca_gpio, gpio_id, false); in ljca_irq_bus_unlock()
384 clear_bit(gpio_id, ljca_gpio->enabled_irqs); in ljca_irq_bus_unlock()
388 mutex_unlock(&ljca_gpio->irq_lock); in ljca_irq_bus_unlock()
406 struct ljca_gpio_dev *ljca_gpio; in ljca_gpio_probe() local
410 ljca_gpio = devm_kzalloc(&auxdev->dev, sizeof(*ljca_gpio), GFP_KERNEL); in ljca_gpio_probe()
411 if (!ljca_gpio) in ljca_gpio_probe()
414 ljca_gpio->ljca = ljca; in ljca_gpio_probe()
415 ljca_gpio->gpio_info = dev_get_platdata(&auxdev->dev); in ljca_gpio_probe()
416 ljca_gpio->connect_mode = devm_kcalloc(&auxdev->dev, in ljca_gpio_probe()
417 ljca_gpio->gpio_info->num, in ljca_gpio_probe()
418 sizeof(*ljca_gpio->connect_mode), in ljca_gpio_probe()
420 if (!ljca_gpio->connect_mode) in ljca_gpio_probe()
423 mutex_init(&ljca_gpio->irq_lock); in ljca_gpio_probe()
424 mutex_init(&ljca_gpio->trans_lock); in ljca_gpio_probe()
425 ljca_gpio->gc.direction_input = ljca_gpio_direction_input; in ljca_gpio_probe()
426 ljca_gpio->gc.direction_output = ljca_gpio_direction_output; in ljca_gpio_probe()
427 ljca_gpio->gc.get_direction = ljca_gpio_get_direction; in ljca_gpio_probe()
428 ljca_gpio->gc.get = ljca_gpio_get_value; in ljca_gpio_probe()
429 ljca_gpio->gc.set = ljca_gpio_set_value; in ljca_gpio_probe()
430 ljca_gpio->gc.set_config = ljca_gpio_set_config; in ljca_gpio_probe()
431 ljca_gpio->gc.init_valid_mask = ljca_gpio_init_valid_mask; in ljca_gpio_probe()
432 ljca_gpio->gc.can_sleep = true; in ljca_gpio_probe()
433 ljca_gpio->gc.parent = &auxdev->dev; in ljca_gpio_probe()
435 ljca_gpio->gc.base = -1; in ljca_gpio_probe()
436 ljca_gpio->gc.ngpio = ljca_gpio->gpio_info->num; in ljca_gpio_probe()
437 ljca_gpio->gc.label = ACPI_COMPANION(&auxdev->dev) ? in ljca_gpio_probe()
440 ljca_gpio->gc.owner = THIS_MODULE; in ljca_gpio_probe()
442 auxiliary_set_drvdata(auxdev, ljca_gpio); in ljca_gpio_probe()
443 ljca_register_event_cb(ljca, ljca_gpio_event_cb, ljca_gpio); in ljca_gpio_probe()
445 girq = &ljca_gpio->gc.irq; in ljca_gpio_probe()
454 INIT_WORK(&ljca_gpio->work, ljca_gpio_async); in ljca_gpio_probe()
455 ret = gpiochip_add_data(&ljca_gpio->gc, ljca_gpio); in ljca_gpio_probe()
458 mutex_destroy(&ljca_gpio->irq_lock); in ljca_gpio_probe()
459 mutex_destroy(&ljca_gpio->trans_lock); in ljca_gpio_probe()
467 struct ljca_gpio_dev *ljca_gpio = auxiliary_get_drvdata(auxdev); in ljca_gpio_remove() local
469 gpiochip_remove(&ljca_gpio->gc); in ljca_gpio_remove()
470 ljca_unregister_event_cb(ljca_gpio->ljca); in ljca_gpio_remove()
471 cancel_work_sync(&ljca_gpio->work); in ljca_gpio_remove()
472 mutex_destroy(&ljca_gpio->irq_lock); in ljca_gpio_remove()
473 mutex_destroy(&ljca_gpio->trans_lock); in ljca_gpio_remove()