public inbox for linux-serial@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: Max Filippov <jcmvbkbc@gmail.com>,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	devicetree@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>
Subject: Re: [PATCH 4/4] drivers/tty/serial: add ESP32S3 ACM device driver
Date: Thu, 14 Sep 2023 09:16:04 +0200	[thread overview]
Message-ID: <6f95d492-2f5e-42e8-acdd-210d6a03b14c@kernel.org> (raw)
In-Reply-To: <20230913211449.668796-5-jcmvbkbc@gmail.com>

On 13. 09. 23, 23:14, Max Filippov wrote:
> Add driver for the ACM  controller of the Espressif ESP32S3 Soc.
> Hardware specification is available at the following URL:
> 
>    https://www.espressif.com/sites/default/files/documentation/esp32-s3_technical_reference_manual_en.pdf
>    (Chapter 33 USB Serial/JTAG Controller)
...

> +static void esp32s3_acm_put_char_sync(struct uart_port *port, unsigned char c)
> +{
> +	while (!esp32s3_acm_tx_fifo_free(port))
> +		cpu_relax();

No limits...

> +	esp32s3_acm_put_char(port, c);
> +	esp32s3_acm_push(port);
> +}
> +
> +static void esp32s3_acm_transmit_buffer(struct uart_port *port)
> +{

tx helper.

> +	struct circ_buf *xmit = &port->state->xmit;
> +	u32 tx_fifo_used = esp32s3_acm_tx_fifo_cnt(port);
> +
> +	if (esp32s3_acm_tx_fifo_free(port)) {
> +		while (!uart_circ_empty(xmit) && tx_fifo_used < ESP32S3_ACM_TX_FIFO_SIZE) {
> +			esp32s3_acm_put_char(port, xmit->buf[xmit->tail]);
> +			xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
> +			port->icount.tx++;
> +			++tx_fifo_used;
> +		}
> +	}
> +
> +	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
> +		uart_write_wakeup(port);
> +
> +	if (uart_circ_empty(xmit)) {
> +		esp32s3_acm_stop_tx(port);
> +	} else {
> +		u32 int_ena;
> +
> +		int_ena = esp32s3_acm_read(port, USB_SERIAL_JTAG_INT_ENA_REG);
> +		esp32s3_acm_write(port, USB_SERIAL_JTAG_INT_ENA_REG,
> +				  int_ena | USB_SERIAL_JTAG_SERIAL_IN_EMPTY_INT_ENA_MASK);
> +	}
> +
> +	if (tx_fifo_used > 0 && tx_fifo_used < ESP32S3_ACM_TX_FIFO_SIZE)
> +		esp32s3_acm_write(port, USB_SERIAL_JTAG_EP1_CONF_REG,
> +				  USB_SERIAL_JTAG_WR_DONE_MASK);
> +}


> +static irqreturn_t esp32s3_acm_int(int irq, void *dev_id)
> +{
> +	struct uart_port *port = dev_id;
> +	u32 status;
> +
> +	status = esp32s3_acm_read(port, USB_SERIAL_JTAG_INT_ST_REG);
> +	esp32s3_acm_write(port, USB_SERIAL_JTAG_INT_CLR_REG, status);
> +
> +	if (status & USB_SERIAL_JTAG_SERIAL_OUT_RECV_PKT_INT_ST_MASK)
> +		esp32s3_acm_rxint(port);
> +	if (status & USB_SERIAL_JTAG_SERIAL_IN_EMPTY_INT_ST_MASK)
> +		esp32s3_acm_txint(port);
> +
> +	return IRQ_HANDLED;

IRQ_STATUS()

> +}

> +static int esp32s3_acm_startup(struct uart_port *port)
> +{
> +	int ret = 0;
> +
> +	esp32s3_acm_write(port, USB_SERIAL_JTAG_INT_ENA_REG,
> +			  USB_SERIAL_JTAG_SERIAL_OUT_RECV_PKT_INT_ENA_MASK);
> +	ret = devm_request_irq(port->dev, port->irq, esp32s3_acm_int, 0,
> +			       DRIVER_NAME, port);
> +	return ret;

No need for ret. Or not, you don't handle the failure properly again 
(disable ints). And the order appears to be switched too.


> +static void
> +esp32s3_acm_console_write(struct console *co, const char *s, unsigned int count)
> +{
> +	struct uart_port *port = esp32s3_acm_ports[co->index];
> +	unsigned long flags;
> +	int locked = 1;

bool? ANd in the otrher driver too.

> +
> +	if (port->sysrq)
> +		locked = 0;
> +	else if (oops_in_progress)
> +		locked = spin_trylock_irqsave(&port->lock, flags);
> +	else
> +		spin_lock_irqsave(&port->lock, flags);
> +
> +	esp32s3_acm_string_write(port, s, count);
> +
> +	if (locked)
> +		spin_unlock_irqrestore(&port->lock, flags);
> +}


> +#ifdef CONFIG_CONSOLE_POLL
> +static int esp32s3_acm_earlycon_read(struct console *con, char *s, unsigned int n)
> +{
> +	struct earlycon_device *dev = con->data;
> +	int num_read = 0;

num looks like should be unsigned?

> +
> +	while (num_read < n) {
> +		int c = esp32s3_acm_poll_get_char(&dev->port);
> +
> +		if (c == NO_POLL_CHAR)
> +			break;
> +		s[num_read++] = c;
> +	}
> +	return num_read;
> +}
> +#endif


> +static int esp32s3_acm_probe(struct platform_device *pdev)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	struct uart_port *port;
> +	struct resource *res;
> +	int ret;
> +
> +	port = devm_kzalloc(&pdev->dev, sizeof(*port), GFP_KERNEL);
> +	if (!port)
> +		return -ENOMEM;
> +
> +	ret = of_alias_get_id(np, "serial");
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret);
> +		return ret;
> +	}
> +	if (ret >= UART_NR) {
> +		dev_err(&pdev->dev, "driver limited to %d serial ports\n",
> +			UART_NR);
> +		return -ENOMEM;
> +	}
> +
> +	port->line = ret;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	if (!res)
> +		return -ENODEV;
> +
> +	port->mapbase = res->start;
> +	port->membase = devm_ioremap_resource(&pdev->dev, res);
> +	if (IS_ERR(port->membase))
> +		return PTR_ERR(port->membase);
> +
> +	port->dev = &pdev->dev;
> +	port->type = PORT_ESP32ACM;
> +	port->iotype = UPIO_MEM;
> +	port->irq = platform_get_irq(pdev, 0);
> +	port->ops = &esp32s3_acm_pops;
> +	port->flags = UPF_BOOT_AUTOCONF;
> +	port->has_sysrq = 1;
> +	port->fifosize = ESP32S3_ACM_TX_FIFO_SIZE;
> +
> +	esp32s3_acm_ports[port->line] = port;
> +
> +	platform_set_drvdata(pdev, port);
> +
> +	ret = uart_add_one_port(&esp32s3_acm_reg, port);
> +	return ret;

return imm.

> +}

regards,
-- 
js
suse labs


  reply	other threads:[~2023-09-14  7:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-13 21:14 [PATCH 0/4] serial: add drivers for the ESP32xx serial devices Max Filippov
2023-09-13 21:14 ` [PATCH 1/4] dt-bindings: serial: document esp32-uart bindings Max Filippov
2023-09-14  5:54   ` Krzysztof Kozlowski
2023-09-14 20:00     ` Max Filippov
2023-09-14  5:55   ` Krzysztof Kozlowski
2023-09-14 14:48     ` Conor Dooley
2023-09-14 20:02       ` Max Filippov
2023-09-13 21:14 ` [PATCH 2/4] drivers/tty/serial: add driver for the ESP32 UART Max Filippov
2023-09-14  7:06   ` Jiri Slaby
2023-09-15  9:04     ` Max Filippov
2023-09-14 13:07   ` Ilpo Järvinen
2023-09-15 22:33     ` Max Filippov
2023-09-18  9:07       ` Ilpo Järvinen
2023-09-13 21:14 ` [PATCH 3/4] dt-bindings: serial: document esp32s3-acm bindings Max Filippov
2023-09-14  5:57   ` Krzysztof Kozlowski
2023-09-14 20:47     ` Max Filippov
2023-09-15  6:50       ` Krzysztof Kozlowski
2023-09-13 21:14 ` [PATCH 4/4] drivers/tty/serial: add ESP32S3 ACM device driver Max Filippov
2023-09-14  7:16   ` Jiri Slaby [this message]
2023-09-15 23:54     ` Max Filippov
2023-09-14 13:14   ` Ilpo Järvinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6f95d492-2f5e-42e8-acdd-210d6a03b14c@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jcmvbkbc@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox