Lines Matching refs:ljca_gpio
75 static int gpio_config(struct ljca_gpio_dev *ljca_gpio, u8 gpio_id, u8 config) in gpio_config() argument
77 struct gpio_packet *packet = (struct gpio_packet *)ljca_gpio->obuf; in gpio_config()
80 mutex_lock(&ljca_gpio->trans_lock); in gpio_config()
82 packet->item[0].value = config | ljca_gpio->connect_mode[gpio_id]; in gpio_config()
85 ret = ljca_transfer(ljca_gpio->gpio_info->ljca, LJCA_GPIO_CONFIG, packet, in gpio_config()
87 mutex_unlock(&ljca_gpio->trans_lock); in gpio_config()
91 static int ljca_gpio_read(struct ljca_gpio_dev *ljca_gpio, u8 gpio_id) in ljca_gpio_read() argument
93 struct gpio_packet *packet = (struct gpio_packet *)ljca_gpio->obuf; in ljca_gpio_read()
94 struct gpio_packet *ack_packet = (struct gpio_packet *)ljca_gpio->ibuf; in ljca_gpio_read()
98 mutex_lock(&ljca_gpio->trans_lock); in ljca_gpio_read()
101 ret = ljca_transfer(ljca_gpio->gpio_info->ljca, LJCA_GPIO_READ, packet, in ljca_gpio_read()
102 struct_size(packet, item, packet->num), ljca_gpio->ibuf, &ibuf_len); in ljca_gpio_read()
107 dev_err(&ljca_gpio->pdev->dev, "failed gpio_id:%u %u", gpio_id, ack_packet->num); in ljca_gpio_read()
112 mutex_unlock(&ljca_gpio->trans_lock); in ljca_gpio_read()
118 static int ljca_gpio_write(struct ljca_gpio_dev *ljca_gpio, u8 gpio_id, in ljca_gpio_write() argument
121 struct gpio_packet *packet = (struct gpio_packet *)ljca_gpio->obuf; in ljca_gpio_write()
124 mutex_lock(&ljca_gpio->trans_lock); in ljca_gpio_write()
129 ret = ljca_transfer(ljca_gpio->gpio_info->ljca, LJCA_GPIO_WRITE, packet, in ljca_gpio_write()
131 mutex_unlock(&ljca_gpio->trans_lock); in ljca_gpio_write()
137 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(chip); in ljca_gpio_get_value() local
139 return ljca_gpio_read(ljca_gpio, offset); in ljca_gpio_get_value()
145 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(chip); in ljca_gpio_set_value() local
148 ret = ljca_gpio_write(ljca_gpio, offset, val); in ljca_gpio_set_value()
156 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(chip); in ljca_gpio_direction_input() local
159 return gpio_config(ljca_gpio, offset, config); in ljca_gpio_direction_input()
165 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(chip); in ljca_gpio_direction_output() local
169 ret = gpio_config(ljca_gpio, offset, config); in ljca_gpio_direction_output()
180 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(chip); in ljca_gpio_set_config() local
182 ljca_gpio->connect_mode[offset] = 0; in ljca_gpio_set_config()
185 ljca_gpio->connect_mode[offset] |= LJCA_GPIO_CONF_PULLUP; in ljca_gpio_set_config()
188 ljca_gpio->connect_mode[offset] |= LJCA_GPIO_CONF_PULLDOWN; in ljca_gpio_set_config()
203 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(chip); in ljca_gpio_init_valid_mask() local
205 WARN_ON_ONCE(ngpios != ljca_gpio->gpio_info->num); in ljca_gpio_init_valid_mask()
206 bitmap_copy(valid_mask, ljca_gpio->gpio_info->valid_pin_map, ngpios); in ljca_gpio_init_valid_mask()
217 static int ljca_enable_irq(struct ljca_gpio_dev *ljca_gpio, int gpio_id, bool enable) in ljca_enable_irq() argument
219 struct gpio_packet *packet = (struct gpio_packet *)ljca_gpio->obuf; in ljca_enable_irq()
222 mutex_lock(&ljca_gpio->trans_lock); in ljca_enable_irq()
227 ret = ljca_transfer(ljca_gpio->gpio_info->ljca, in ljca_enable_irq()
230 mutex_unlock(&ljca_gpio->trans_lock); in ljca_enable_irq()
236 struct ljca_gpio_dev *ljca_gpio = container_of(work, struct ljca_gpio_dev, work); in ljca_gpio_async() local
240 for_each_set_bit(gpio_id, ljca_gpio->reenable_irqs, ljca_gpio->gc.ngpio) { in ljca_gpio_async()
241 clear_bit(gpio_id, ljca_gpio->reenable_irqs); in ljca_gpio_async()
242 unmasked = test_bit(gpio_id, ljca_gpio->unmasked_irqs); in ljca_gpio_async()
244 ljca_enable_irq(ljca_gpio, gpio_id, true); in ljca_gpio_async()
251 struct ljca_gpio_dev *ljca_gpio = context; in ljca_gpio_event_cb() local
259 irq = irq_find_mapping(ljca_gpio->gc.irq.domain, packet->item[i].index); in ljca_gpio_event_cb()
261 dev_err(ljca_gpio->gc.parent, "gpio_id %u does not mapped to IRQ yet\n", in ljca_gpio_event_cb()
266 generic_handle_domain_irq(ljca_gpio->gc.irq.domain, irq); in ljca_gpio_event_cb()
267 set_bit(packet->item[i].index, ljca_gpio->reenable_irqs); in ljca_gpio_event_cb()
270 schedule_work(&ljca_gpio->work); in ljca_gpio_event_cb()
276 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(gc); in ljca_irq_unmask() local
280 set_bit(gpio_id, ljca_gpio->unmasked_irqs); in ljca_irq_unmask()
286 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(gc); in ljca_irq_mask() local
289 clear_bit(gpio_id, ljca_gpio->unmasked_irqs); in ljca_irq_mask()
296 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(gc); in ljca_irq_set_type() local
299 ljca_gpio->connect_mode[gpio_id] = LJCA_GPIO_CONF_INTERRUPT; in ljca_irq_set_type()
302 ljca_gpio->connect_mode[gpio_id] |= (LJCA_GPIO_CONF_LEVEL | LJCA_GPIO_CONF_PULLUP); in ljca_irq_set_type()
305 ljca_gpio->connect_mode[gpio_id] |= (LJCA_GPIO_CONF_LEVEL | LJCA_GPIO_CONF_PULLDOWN); in ljca_irq_set_type()
310 ljca_gpio->connect_mode[gpio_id] |= (LJCA_GPIO_CONF_EDGE | LJCA_GPIO_CONF_PULLUP); in ljca_irq_set_type()
313 ljca_gpio->connect_mode[gpio_id] |= (LJCA_GPIO_CONF_EDGE | LJCA_GPIO_CONF_PULLDOWN); in ljca_irq_set_type()
325 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(gc); in ljca_irq_bus_lock() local
327 mutex_lock(&ljca_gpio->irq_lock); in ljca_irq_bus_lock()
333 struct ljca_gpio_dev *ljca_gpio = gpiochip_get_data(gc); in ljca_irq_bus_unlock() local
338 enabled = test_bit(gpio_id, ljca_gpio->enabled_irqs); in ljca_irq_bus_unlock()
339 unmasked = test_bit(gpio_id, ljca_gpio->unmasked_irqs); in ljca_irq_bus_unlock()
343 gpio_config(ljca_gpio, gpio_id, 0); in ljca_irq_bus_unlock()
344 ljca_enable_irq(ljca_gpio, gpio_id, true); in ljca_irq_bus_unlock()
345 set_bit(gpio_id, ljca_gpio->enabled_irqs); in ljca_irq_bus_unlock()
347 ljca_enable_irq(ljca_gpio, gpio_id, false); in ljca_irq_bus_unlock()
348 clear_bit(gpio_id, ljca_gpio->enabled_irqs); in ljca_irq_bus_unlock()
352 mutex_unlock(&ljca_gpio->irq_lock); in ljca_irq_bus_unlock()
368 struct ljca_gpio_dev *ljca_gpio; in ljca_gpio_probe() local
372 ljca_gpio = devm_kzalloc(&pdev->dev, sizeof(*ljca_gpio), GFP_KERNEL); in ljca_gpio_probe()
373 if (!ljca_gpio) in ljca_gpio_probe()
376 ljca_gpio->gpio_info = dev_get_platdata(&pdev->dev); in ljca_gpio_probe()
377 ljca_gpio->connect_mode = devm_kcalloc(&pdev->dev, ljca_gpio->gpio_info->num, in ljca_gpio_probe()
378 sizeof(*ljca_gpio->connect_mode), GFP_KERNEL); in ljca_gpio_probe()
379 if (!ljca_gpio->connect_mode) in ljca_gpio_probe()
382 mutex_init(&ljca_gpio->irq_lock); in ljca_gpio_probe()
383 mutex_init(&ljca_gpio->trans_lock); in ljca_gpio_probe()
384 ljca_gpio->pdev = pdev; in ljca_gpio_probe()
385 ljca_gpio->gc.direction_input = ljca_gpio_direction_input; in ljca_gpio_probe()
386 ljca_gpio->gc.direction_output = ljca_gpio_direction_output; in ljca_gpio_probe()
387 ljca_gpio->gc.get = ljca_gpio_get_value; in ljca_gpio_probe()
388 ljca_gpio->gc.set = ljca_gpio_set_value; in ljca_gpio_probe()
389 ljca_gpio->gc.set_config = ljca_gpio_set_config; in ljca_gpio_probe()
390 ljca_gpio->gc.init_valid_mask = ljca_gpio_init_valid_mask; in ljca_gpio_probe()
391 ljca_gpio->gc.can_sleep = true; in ljca_gpio_probe()
392 ljca_gpio->gc.parent = &pdev->dev; in ljca_gpio_probe()
394 ljca_gpio->gc.base = -1; in ljca_gpio_probe()
395 ljca_gpio->gc.ngpio = ljca_gpio->gpio_info->num; in ljca_gpio_probe()
396 ljca_gpio->gc.label = ACPI_COMPANION(&pdev->dev) ? in ljca_gpio_probe()
399 ljca_gpio->gc.owner = THIS_MODULE; in ljca_gpio_probe()
401 platform_set_drvdata(pdev, ljca_gpio); in ljca_gpio_probe()
402 ljca_register_event_cb(ljca_gpio->gpio_info->ljca, ljca_gpio_event_cb, ljca_gpio); in ljca_gpio_probe()
404 girq = &ljca_gpio->gc.irq; in ljca_gpio_probe()
413 INIT_WORK(&ljca_gpio->work, ljca_gpio_async); in ljca_gpio_probe()
414 ret = gpiochip_add_data(&ljca_gpio->gc, ljca_gpio); in ljca_gpio_probe()
416 ljca_unregister_event_cb(ljca_gpio->gpio_info->ljca); in ljca_gpio_probe()
417 mutex_destroy(&ljca_gpio->irq_lock); in ljca_gpio_probe()
418 mutex_destroy(&ljca_gpio->trans_lock); in ljca_gpio_probe()
426 struct ljca_gpio_dev *ljca_gpio = platform_get_drvdata(pdev); in ljca_gpio_remove() local
428 gpiochip_remove(&ljca_gpio->gc); in ljca_gpio_remove()
429 ljca_unregister_event_cb(ljca_gpio->gpio_info->ljca); in ljca_gpio_remove()
430 mutex_destroy(&ljca_gpio->irq_lock); in ljca_gpio_remove()
431 mutex_destroy(&ljca_gpio->trans_lock); in ljca_gpio_remove()