From: Johannes Thumshirn <jth@kernel.org>
To: Mark Brown <broonie@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org
Subject: Re: [PATCH] spi: add ch341a usb2spi driver
Date: Mon, 8 Jul 2024 10:04:41 +0200 [thread overview]
Message-ID: <8a2467b9-4eb5-4ab4-a4c8-da37875fe4c9@kernel.org> (raw)
In-Reply-To: <aa3c79a0-ecbc-4f12-b540-6570350a7909@sirena.org.uk>
[-- Attachment #1.1.1: Type: text/plain, Size: 2273 bytes --]
On 05/07/2024 19:41, Mark Brown wrote:
>> +config SPI_CH341
>> + tristate "CH341 USB2SPI adapter"
>> + depends on SPI_MASTER && USB
>> + help
>> + Enables the SPI controller on the CH341a USB to serial chip
>> +
>> #
>> # Add new SPI master controllers in alphabetical order above this line
>> #
>
> Like the comment says please keep these files sorted (I appreciate
> there's some things been missed).
Oops. Fixed, sorry.
>
>> +++ b/drivers/spi/spi-ch341.c
>> @@ -0,0 +1,236 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * QiHeng Electronics ch341a USB-to-SPI adapter driver
>> + *
>> + * Copyright (C) 2024 Johannes Thumshirn <jth@kernel.org>
>
> Please make the entire comment block a C++ one so things look clearer.
I've never seen that in kernel code, but sure changed it.
>
>> +static void ch341_set_cs(struct spi_device *spi, bool is_high)
>> +{
>> + struct ch341_spi_dev *ch341 =
>> + spi_controller_get_devdata(spi->controller);
>> +
>> + memset(ch341->tx_buf, 0, CH341_PACKET_LENGTH);
>> + ch341->tx_buf[0] = CH341A_CMD_UIO_STREAM;
>> + ch341->tx_buf[1] = CH341A_CMD_UIO_STM_OUT | (is_high ? 0x36 : 0x37);
>> +
>> + if (is_high) {
>> + ch341->tx_buf[2] = CH341A_CMD_UIO_STM_DIR | 0x3f;
>> + ch341->tx_buf[3] = CH341A_CMD_UIO_STM_END;
>> + } else {
>> + ch341->tx_buf[2] = CH341A_CMD_UIO_STM_END;
>> + }
>> +
>> + (void)usb_bulk_msg(ch341->udev, ch341->write_pipe, ch341->tx_buf,
>> + (is_high ? 4 : 3), NULL, CH341_DEFAULT_TIMEOUT);
>
> The cast to void here is very suspicious, what's it doing?
Explicitly ignoring errors from usb_bulk_msg() as ->set_cs() can't
really handle error returns.
I've changed it to an error print.
>
>> +static int ch341_config_stream(struct ch341_spi_dev *ch341, int speed)
>> +{
>> + memset(ch341->tx_buf, 0, CH341_PACKET_LENGTH);
>> + ch341->tx_buf[0] = CH341A_CMD_I2C_STREAM;
>> + ch341->tx_buf[1] = CH341A_CMD_I2C_STM_SET | (speed & 0x7);
>> + ch341->tx_buf[2] = CH341A_CMD_I2C_STM_END;
>> +
>> + return usb_bulk_msg(ch341->udev, ch341->write_pipe, ch341->tx_buf, 3,
>> + NULL, CH341_DEFAULT_TIMEOUT);
>
> No validation of speed?
TBH I haven't found a command that reads the current settings of the device.
[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 23737 bytes --]
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
next prev parent reply other threads:[~2024-07-08 8:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-05 14:51 [PATCH] spi: add ch341a usb2spi driver Johannes Thumshirn
2024-07-05 17:41 ` Mark Brown
2024-07-08 8:04 ` Johannes Thumshirn [this message]
2024-07-08 11:32 ` Mark Brown
2024-07-08 11:55 ` Johannes Thumshirn
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=8a2467b9-4eb5-4ab4-a4c8-da37875fe4c9@kernel.org \
--to=jth@kernel.org \
--cc=broonie@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.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