Lines Matching +full:ast2500 +full:- +full:vuart

1 // SPDX-License-Identifier: GPL-2.0+
3 * Serial Port driver for Aspeed VUART device
48 * The VUART is basically two UART 'front ends' connected by their FIFO
59 * to the host on the Host <-> BMC LPC bus. It could be different on a
66 struct aspeed_vuart *vuart = dev_get_drvdata(dev); in lpc_address_show() local
69 addr = (readb(vuart->regs + ASPEED_VUART_ADDRH) << 8) | in lpc_address_show()
70 (readb(vuart->regs + ASPEED_VUART_ADDRL)); in lpc_address_show()
72 return snprintf(buf, PAGE_SIZE - 1, "0x%x\n", addr); in lpc_address_show()
79 struct aspeed_vuart *vuart = dev_get_drvdata(dev); in lpc_address_store() local
87 writeb(val >> 8, vuart->regs + ASPEED_VUART_ADDRH); in lpc_address_store()
88 writeb(val >> 0, vuart->regs + ASPEED_VUART_ADDRL); in lpc_address_store()
98 struct aspeed_vuart *vuart = dev_get_drvdata(dev); in sirq_show() local
101 reg = readb(vuart->regs + ASPEED_VUART_GCRB); in sirq_show()
105 return snprintf(buf, PAGE_SIZE - 1, "%u\n", reg); in sirq_show()
111 struct aspeed_vuart *vuart = dev_get_drvdata(dev); in sirq_store() local
123 reg = readb(vuart->regs + ASPEED_VUART_GCRB); in sirq_store()
126 writeb(reg, vuart->regs + ASPEED_VUART_GCRB); in sirq_store()
136 struct aspeed_vuart *vuart = dev_get_drvdata(dev); in sirq_polarity_show() local
139 reg = readb(vuart->regs + ASPEED_VUART_GCRA); in sirq_polarity_show()
142 return snprintf(buf, PAGE_SIZE - 1, "%u\n", reg ? 1 : 0); in sirq_polarity_show()
145 static void aspeed_vuart_set_sirq_polarity(struct aspeed_vuart *vuart, in aspeed_vuart_set_sirq_polarity() argument
148 u8 reg = readb(vuart->regs + ASPEED_VUART_GCRA); in aspeed_vuart_set_sirq_polarity()
155 writeb(reg, vuart->regs + ASPEED_VUART_GCRA); in aspeed_vuart_set_sirq_polarity()
162 struct aspeed_vuart *vuart = dev_get_drvdata(dev); in sirq_polarity_store() local
170 aspeed_vuart_set_sirq_polarity(vuart, val != 0); in sirq_polarity_store()
188 static void aspeed_vuart_set_enabled(struct aspeed_vuart *vuart, bool enabled) in aspeed_vuart_set_enabled() argument
190 u8 reg = readb(vuart->regs + ASPEED_VUART_GCRA); in aspeed_vuart_set_enabled()
197 writeb(reg, vuart->regs + ASPEED_VUART_GCRA); in aspeed_vuart_set_enabled()
200 static void aspeed_vuart_set_host_tx_discard(struct aspeed_vuart *vuart, in aspeed_vuart_set_host_tx_discard() argument
205 reg = readb(vuart->regs + ASPEED_VUART_GCRA); in aspeed_vuart_set_host_tx_discard()
213 writeb(reg, vuart->regs + ASPEED_VUART_GCRA); in aspeed_vuart_set_host_tx_discard()
219 struct aspeed_vuart *vuart = uart_8250_port->port.private_data; in aspeed_vuart_startup() local
226 aspeed_vuart_set_host_tx_discard(vuart, false); in aspeed_vuart_startup()
234 struct aspeed_vuart *vuart = uart_8250_port->port.private_data; in aspeed_vuart_shutdown() local
236 aspeed_vuart_set_host_tx_discard(vuart, true); in aspeed_vuart_shutdown()
246 up->ier &= ~irqs; in __aspeed_vuart_set_throttle()
248 up->ier |= irqs; in __aspeed_vuart_set_throttle()
249 serial_out(up, UART_IER, up->ier); in __aspeed_vuart_set_throttle()
256 spin_lock_irqsave(&port->lock, flags); in aspeed_vuart_set_throttle()
258 spin_unlock_irqrestore(&port->lock, flags); in aspeed_vuart_set_throttle()
273 struct aspeed_vuart *vuart = from_timer(vuart, timer, unthrottle_timer); in aspeed_vuart_unthrottle_exp() local
274 struct uart_8250_port *up = vuart->port; in aspeed_vuart_unthrottle_exp()
276 if (!tty_buffer_space_avail(&up->port.state->port)) { in aspeed_vuart_unthrottle_exp()
277 mod_timer(&vuart->unthrottle_timer, in aspeed_vuart_unthrottle_exp()
282 aspeed_vuart_unthrottle(&up->port); in aspeed_vuart_unthrottle_exp()
286 * Custom interrupt handler to manage finer-grained flow control. Although we
287 * have throttle/unthrottle callbacks, we've seen that the VUART device can
308 spin_lock_irqsave(&port->lock, flags); in aspeed_vuart_handle_irq()
313 space = tty_buffer_space_avail(&port->state->port); in aspeed_vuart_handle_irq()
317 struct aspeed_vuart *vuart = port->private_data; in aspeed_vuart_handle_irq() local
320 if (!timer_pending(&vuart->unthrottle_timer)) { in aspeed_vuart_handle_irq()
321 vuart->port = up; in aspeed_vuart_handle_irq()
322 mod_timer(&vuart->unthrottle_timer, in aspeed_vuart_handle_irq()
332 if (--count == 0) in aspeed_vuart_handle_irq()
336 tty_flip_buffer_push(&port->state->port); in aspeed_vuart_handle_irq()
350 struct aspeed_vuart *vuart, struct device_node *syscon_np, in aspeed_vuart_auto_configure_sirq_polarity() argument
358 dev_warn(vuart->dev, in aspeed_vuart_auto_configure_sirq_polarity()
359 "could not get regmap for aspeed,sirq-polarity-sense\n"); in aspeed_vuart_auto_configure_sirq_polarity()
363 dev_warn(vuart->dev, "could not read hw strap table\n"); in aspeed_vuart_auto_configure_sirq_polarity()
367 aspeed_vuart_set_sirq_polarity(vuart, (value & reg_mask) == 0); in aspeed_vuart_auto_configure_sirq_polarity()
374 struct aspeed_vuart *vuart; in aspeed_vuart_probe() local
380 np = pdev->dev.of_node; in aspeed_vuart_probe()
382 vuart = devm_kzalloc(&pdev->dev, sizeof(*vuart), GFP_KERNEL); in aspeed_vuart_probe()
383 if (!vuart) in aspeed_vuart_probe()
384 return -ENOMEM; in aspeed_vuart_probe()
386 vuart->dev = &pdev->dev; in aspeed_vuart_probe()
387 timer_setup(&vuart->unthrottle_timer, aspeed_vuart_unthrottle_exp, 0); in aspeed_vuart_probe()
390 vuart->regs = devm_ioremap_resource(&pdev->dev, res); in aspeed_vuart_probe()
391 if (IS_ERR(vuart->regs)) in aspeed_vuart_probe()
392 return PTR_ERR(vuart->regs); in aspeed_vuart_probe()
395 port.port.private_data = vuart; in aspeed_vuart_probe()
396 port.port.membase = vuart->regs; in aspeed_vuart_probe()
397 port.port.mapbase = res->start; in aspeed_vuart_probe()
404 port.port.dev = &pdev->dev; in aspeed_vuart_probe()
407 rc = sysfs_create_group(&vuart->dev->kobj, &aspeed_vuart_attr_group); in aspeed_vuart_probe()
411 if (of_property_read_u32(np, "clock-frequency", &clk)) { in aspeed_vuart_probe()
412 vuart->clk = devm_clk_get(&pdev->dev, NULL); in aspeed_vuart_probe()
413 if (IS_ERR(vuart->clk)) { in aspeed_vuart_probe()
414 dev_warn(&pdev->dev, in aspeed_vuart_probe()
415 "clk or clock-frequency not defined\n"); in aspeed_vuart_probe()
416 rc = PTR_ERR(vuart->clk); in aspeed_vuart_probe()
420 rc = clk_prepare_enable(vuart->clk); in aspeed_vuart_probe()
424 clk = clk_get_rate(vuart->clk); in aspeed_vuart_probe()
427 /* If current-speed was set, then try not to change it. */ in aspeed_vuart_probe()
428 if (of_property_read_u32(np, "current-speed", &prop) == 0) in aspeed_vuart_probe()
432 if (of_property_read_u32(np, "reg-offset", &prop) == 0) in aspeed_vuart_probe()
436 if (of_property_read_u32(np, "reg-shift", &prop) == 0) in aspeed_vuart_probe()
440 if (of_property_read_u32(np, "fifo-size", &prop) == 0) in aspeed_vuart_probe()
456 if (of_property_read_bool(np, "no-loopback-test")) in aspeed_vuart_probe()
462 if (of_property_read_bool(np, "auto-flow-control")) in aspeed_vuart_probe()
469 vuart->line = rc; in aspeed_vuart_probe()
472 np, "aspeed,sirq-polarity-sense", 2, 0, in aspeed_vuart_probe()
475 dev_dbg(&pdev->dev, in aspeed_vuart_probe()
476 "aspeed,sirq-polarity-sense property not found\n"); in aspeed_vuart_probe()
479 vuart, sirq_polarity_sense_args.np, in aspeed_vuart_probe()
485 aspeed_vuart_set_enabled(vuart, true); in aspeed_vuart_probe()
486 aspeed_vuart_set_host_tx_discard(vuart, true); in aspeed_vuart_probe()
487 platform_set_drvdata(pdev, vuart); in aspeed_vuart_probe()
492 clk_disable_unprepare(vuart->clk); in aspeed_vuart_probe()
495 sysfs_remove_group(&vuart->dev->kobj, &aspeed_vuart_attr_group); in aspeed_vuart_probe()
501 struct aspeed_vuart *vuart = platform_get_drvdata(pdev); in aspeed_vuart_remove() local
503 del_timer_sync(&vuart->unthrottle_timer); in aspeed_vuart_remove()
504 aspeed_vuart_set_enabled(vuart, false); in aspeed_vuart_remove()
505 serial8250_unregister_port(vuart->line); in aspeed_vuart_remove()
506 sysfs_remove_group(&vuart->dev->kobj, &aspeed_vuart_attr_group); in aspeed_vuart_remove()
507 clk_disable_unprepare(vuart->clk); in aspeed_vuart_remove()
513 { .compatible = "aspeed,ast2400-vuart" },
514 { .compatible = "aspeed,ast2500-vuart" },
520 .name = "aspeed-vuart",
531 MODULE_DESCRIPTION("Driver for Aspeed VUART device");