On Fri, Jul 05, 2024 at 04:51:37PM +0200, Johannes Thumshirn wrote: > --- a/drivers/spi/Kconfig > +++ b/drivers/spi/Kconfig > @@ -1198,6 +1198,12 @@ config SPI_AMD > help > Enables SPI controller driver for AMD SoC. > > +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). > +++ 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@xxxxxxxxxx> Please make the entire comment block a C++ one so things look clearer. > +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? > +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?
Attachment:
signature.asc
Description: PGP signature