update to 1740446fb32

1.Fix spidev delay-usec cannot work
2.Fix spi transfer failed when use gpio cs
3.Support EC200N-CN 4G model
4.Fix alert/critical temperature to 75/105 for 2k300
5.Enable ch341,pl2303 for 2k300_defconfig
This commit is contained in:
maoxiaochuan
2025-07-29 09:02:13 +08:00
committed by loongson
parent 1601802e4a
commit 3904801f2b
12 changed files with 2024 additions and 784 deletions
@@ -766,10 +766,20 @@
interrupt-parent = <&icu>;
interrupts = <48>;
dma-mask = <0x0 0xffffffff>;
/* Use for most devices */
//loongson,dwc2-fix = <DWC2_LOONGSON_FIX_DMA>;
/* Use for 4G model*/
loongson,dwc2-fix = <DWC2_LOONGSON_FIX_DELAY>;
/* DWC2_LOONGSON_FIX_DMA:
Used for most devices, such as USB storage and USB touchscreens.
However, network devices may experience packet loss. */
loongson,dwc2-fix = <DWC2_LOONGSON_FIX_DMA>;
/* DWC2_LOONGSON_FIX_DELAY:
Deprecated. It causes USB to operate slowly.
However, the 4G model can still dial up. Maybe optimize later. */
//loongson,dwc2-fix = <DWC2_LOONGSON_FIX_DELAY>;
/* DWC2_LOONGSON_FIX_NONE:
Original. Some USB devices cannot initialize when first powered up.
However, network devices do not experience packet loss.
Therefore, if we confirm the use of a USB-network device, then select this configuration. */
//loongson,dwc2-fix = <DWC2_LOONGSON_FIX_NONE>;
//dr_mode = "peripheral";
/* Optional for that dr_mode = "host" or dr_mode = "peripheral" */
};
@@ -847,13 +857,13 @@
trips {
cpu_alert: cpu-alert {
temperature = <55000>;
temperature = <75000>;
hysteresis = <5000>;
type = "active";
};
cpu_crit: cpu-crit {
temperature = <125000>;
temperature = <105000>;
hysteresis = <5000>;
type = "critical";
};
@@ -270,3 +270,7 @@
loongson,sound-card-name = "ES8388";
};
&otg {
// PAI 板卡定死使用 wifi
loongson,dwc2-fix = <DWC2_LOONGSON_FIX_NONE>;
};
@@ -553,6 +553,8 @@ CONFIG_USB_ACM=y
CONFIG_USB_STORAGE=y
CONFIG_USB_DWC2=y
CONFIG_USB_SERIAL=y
CONFIG_USB_SERIAL_CH341=y
CONFIG_USB_SERIAL_PL2303=y
CONFIG_USB_SERIAL_OPTION=y
CONFIG_USB_GADGET=y
CONFIG_USB_ETH=y
+4
View File
@@ -361,6 +361,10 @@ static int max31865_probe(struct spi_device *spi)
data = iio_priv(indio_dev);
data->spi = spi;
data->filter_50hz = false;
if (of_property_read_bool(spi->dev.of_node, "filter_50hz"))
data->filter_50hz = true;
mutex_init(&data->lock);
indio_dev->info = &max31865_info;
+87 -15
View File
@@ -140,6 +140,11 @@ struct ls_spiio_priv {
u8 dsize;
struct gpio_desc **cs_gpios;
struct device *dev;
struct work_struct work;
struct workqueue_struct *work_queue;
struct list_head xfer_queue;
spinlock_t lock;
};
static int ls_spiio_idle_sr1(struct ls_spiio_priv* priv, u32 bit)
@@ -153,10 +158,14 @@ static int ls_spiio_idle_sr1(struct ls_spiio_priv* priv, u32 bit)
static int ls_spiio_active_cs(struct ls_spiio_priv* priv, int cs)
{
int active = 0;
unsigned int cr1_reg;
if (!priv->cs_gpios)
ls_spiio_write_reg(priv, REG_CR1, BIT_CR1_SSREV | BIT_CR1_SPE);
else
cr1_reg = ls_spiio_read_reg(priv, REG_CR1);
cr1_reg &= 0x1ff;
cr1_reg |= BIT_CR1_SSREV | BIT_CR1_SPE;
ls_spiio_write_reg(priv, REG_CR1, cr1_reg);
if (priv->cs_gpios)
gpiod_set_raw_value(priv->cs_gpios[cs], active);
return 0;
@@ -167,12 +176,19 @@ static int ls_spiio_clear_cs(struct ls_spiio_priv* priv)
struct spi_master* master = priv->master;
int clear = 1;
int i;
unsigned int cr1_reg;
if (!priv->cs_gpios)
ls_spiio_write_reg(priv, REG_CR1, BIT_CR1_SSREV);
else
cr1_reg = ls_spiio_read_reg(priv, REG_CR1);
cr1_reg &= 0x1ff;
cr1_reg |= BIT_CR1_SPE;
cr1_reg ^= BIT_CR1_SPE;
ls_spiio_write_reg(priv, REG_CR1, cr1_reg);
if (priv->cs_gpios) {
for (i = 0; i < master->num_chipselect; i++)
gpiod_set_raw_value(priv->cs_gpios[i], clear);
}
return 0;
}
@@ -360,6 +376,39 @@ static int __spi_setup(struct spi_device *spi)
return 0;
}
static void __spi_work(struct work_struct *work)
{
struct ls_spiio_priv* priv = container_of(work, struct ls_spiio_priv, work);
spin_lock(&priv->lock);
while (!list_empty(&priv->xfer_queue)) {
struct spi_message *m;
struct spi_device *spi;
struct spi_transfer *t = NULL;
m = container_of(priv->xfer_queue.next, struct spi_message, queue);
list_del_init(&m->queue);
spin_unlock(&priv->lock);
spi = m->spi;
ls_spiio_active_cs(priv, spi->chip_select);
list_for_each_entry(t, &m->transfers, transfer_list) {
/*setup spi clock*/
ls_spiio_set_clk_timing(priv, t->speed_hz, spi->mode);
m->actual_length += ls_spiio_xfer(priv,
(u8*)t->tx_buf, (u8*)t->rx_buf, t->len);
spi_delay_exec(&t->delay, t);
}
ls_spiio_clear_cs(priv);
m->complete(m->context);
spin_lock(&priv->lock);
}
spin_unlock(&priv->lock);
}
static int __spi_transfer(struct spi_device *spi, struct spi_message *m)
{
struct ls_spiio_priv* priv = spi_master_get_devdata(spi->master);
@@ -367,16 +416,34 @@ static int __spi_transfer(struct spi_device *spi, struct spi_message *m)
m->actual_length = 0;
m->status = 0;
ls_spiio_active_cs(priv, spi->chip_select);
list_for_each_entry(t, &m->transfers, transfer_list) {
/*setup spi clock*/
ls_spiio_set_clk_timing(priv, t->speed_hz, spi->mode);
m->actual_length += ls_spiio_xfer(priv,
(u8*)t->tx_buf, (u8*)t->rx_buf, t->len);
}
ls_spiio_clear_cs(priv);
if (list_empty(&m->transfers) || !m->complete)
return -EINVAL;
m->complete(m->context);
list_for_each_entry(t, &m->transfers, transfer_list) {
if (t->tx_buf == NULL && t->rx_buf == NULL && t->len) {
dev_err(&spi->dev,
"message rejected : "
"invalid transfer data buffers\n");
goto msg_rejected;
}
/*other things not check*/
}
spin_lock(&priv->lock);
list_add_tail(&m->queue, &priv->xfer_queue);
queue_work(priv->work_queue, &priv->work);
spin_unlock(&priv->lock);
return 0;
msg_rejected:
m->status = -EINVAL;
if (m->complete)
m->complete(m->context);
return -EINVAL;
return 0;
}
@@ -440,6 +507,11 @@ static int drv_ls_spiio_probe(struct platform_device *pdev)
ls_spiio_init(priv);
priv->work_queue = create_singlethread_workqueue(pdev->name);
INIT_WORK(&priv->work, __spi_work);
INIT_LIST_HEAD(&priv->xfer_queue);
spin_lock_init(&priv->lock);
ret = spi_register_master(master);
if (ret)
{
+2
View File
@@ -266,6 +266,8 @@ static void ls_spi_work(struct work_struct *work)
if (t->len)
m->actual_length +=
ls_spi_write_read(spi, t);
spi_delay_exec(&t->delay, t);
}
set_cs(ls_spi, spi, 1);
+54 -2
View File
@@ -16,6 +16,7 @@
#define LS2K_TSENSOR_CTRL_LO (0x8)
#define LS2K_TSENSOR_STATUS (0x10)
#define LS2K_TSENSOR_OUT (0x14)
#define LS2K_TSENSOR_CFG (0x18)
#define LS2K_MIN_TEMP -40
#define LS2K_MAX_TEMP 125
@@ -77,14 +78,65 @@ static int ls2k_tsensor_set(struct ls2k_thermal_data *data,
return 0;
}
static int warning_2k300_old_fuse_tip;
static int ls2k_thermal_get_temp(void *__data, int *temp)
{
struct ls2k_thermal_data *data = __data;
u32 reg_val;
int temp_val;
int old_fuse_2k300;
reg_val = readl(data->regs + LS2K_TSENSOR_OUT);
if (data->cpu_type == ID_2K300)
*temp = ((reg_val & 0x7ff) * 569) - 394700;
if (data->cpu_type == ID_2K300) {
int version;
int val_fix;
writel(0xff03, data->regs + LS2K_TSENSOR_CFG); // 0x18
reg_val = readl(data->regs + LS2K_TSENSOR_OUT);
reg_val &= 0x7ff;
version = readl(data->regs + 0x2AF0); // 0x16003ff0
version >>= 4;
version &= 1;
if(version)
val_fix = readl(data->regs + 0x2AF4) & 0xffff; // 0x16003ff4
else
val_fix = (readl(data->regs + 0x2AF0) >> 20) & 0xffff; // 0x16003ff0
if (val_fix & 0x8000)
val_fix = -(val_fix & 0x7fff);
else
val_fix = val_fix & 0x7fff;
reg_val += val_fix;
temp_val = reg_val * 570 - 394700;
/*
* fix old 2k300 use old fuse that will let kernel crash critical temperature
*/
old_fuse_2k300 = 0;
reg_val = temp_val;
if (temp_val < -55000) {
pr_info("look temp_val is %d\n", temp_val);
old_fuse_2k300 = 1;
temp_val = -55000;
}
else if (temp_val > 125000) {
pr_info("look temp_val is %d\n", temp_val);
old_fuse_2k300 = 1;
temp_val = 125000;
}
if (old_fuse_2k300)
{
if (!warning_2k300_old_fuse_tip) {
pr_err("%s this 2k300 use old fuse so thermal not right!(%d)\n", __func__, reg_val);
warning_2k300_old_fuse_tip = 1;
}
reg_val = readl(data->regs + LS2K_TSENSOR_OUT);
temp_val = ((reg_val & 0x7ff) * 569) - 394700;
}
*temp = temp_val;
}
else
*temp = ((reg_val & 0xff) - 100) * 1000;
+17
View File
@@ -517,6 +517,23 @@ struct dwc2_core_params {
bool change_speed_quirk;
/*
* DWC2_LOONGSON_FIX_NONE:
* Original. Some USB devices cannot initialize when first powered up.
* However, network devices do not experience packet loss.
* Therefore, if we confirm the use of a USB-network device, then select this configuration.
*
* DWC2_LOONGSON_FIX_DMA:
* Used for most devices, such as USB storage and USB touchscreens.
* However, network devices may experience packet loss.
*
* DWC2_LOONGSON_FIX_DELAY:
* Deprecated. It causes USB to operate slowly.
* However, the 4G model can still dial up. Maybe optimize later.
*
* DWC2_LOONGSON_FIX_DELAY_FULL:
* Deprecated.
*/
#define DWC2_LOONGSON_FIX_NONE 0
#define DWC2_LOONGSON_FIX_DMA 1
#define DWC2_LOONGSON_FIX_DELAY 2
+1665 -760
View File
File diff suppressed because it is too large Load Diff
+153
View File
@@ -0,0 +1,153 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
*
* Includes for ch341.c
*
*/
#ifndef _CH341_H
#define _CH341_H
/*
* Baud rate and default timeout
*/
#define DEFAULT_BAUD_RATE 9600
#define DEFAULT_TIMEOUT 2000
/*
* CMSPAR, some architectures can't have space and mark parity.
*/
#ifndef CMSPAR
#define CMSPAR 0
#endif
/*
* Major and minor numbers.
*/
#define CH341_TTY_MAJOR 169
#define CH341_TTY_MINORS 256
/*
* Requests.
*/
#define USB_RT_CH341 (USB_TYPE_CLASS | USB_RECIP_INTERFACE)
#define CMD_R 0x95
#define CMD_W 0x9A
#define CMD_C1 0xA1
#define CMD_C2 0xA4
#define CMD_C3 0x5F
#define CH341_CTO_O 0x10
#define CH341_CTO_D 0x20
#define CH341_CTO_R 0x40
#define CH341_CTI_C 0x01
#define CH341_CTI_DS 0x02
#define CH341_CTRL_RI 0x04
#define CH341_CTI_DC 0x08
#define CH341_CTI_ST 0x0f
#define CH341_CTT_M BIT(3)
#define CH341_CTT_F (BIT(2) | BIT(6))
#define CH341_CTT_P BIT(2)
#define CH341_CTT_O BIT(1)
#define CH341_L_ER 0x80
#define CH341_L_ET 0x40
#define CH341_L_PS 0x38
#define CH341_L_PM 0x28
#define CH341_L_PE 0x18
#define CH341_L_PO 0x08
#define CH341_L_SB 0x04
#define CH341_L_D8 0x03
#define CH341_L_D7 0x02
#define CH341_L_D6 0x01
#define CH341_L_D5 0x00
#define CH341_RB 0x05
#define CH341_RL 0x18
#define CH341_NB 0x01
#define CH341_NW 2
#define CH341_NR 4
struct ch341_wb {
unsigned char *buf;
dma_addr_t dmah;
int len;
int use;
struct urb *urb;
struct ch341 *instance;
};
struct ch341_rb {
int size;
unsigned char *base;
dma_addr_t dma;
int index;
struct ch341 *instance;
};
struct usb_ch341_line_coding {
__le32 dwDTERate;
__u8 bCharFormat;
#define USB_CH341_1_STOP_BITS 0
#define USB_CH341_1_5_STOP_BITS 1
#define USB_CH341_2_STOP_BITS 2
__u8 bParityType;
#define USB_CH341_NO_PARITY 0
#define USB_CH341_ODD_PARITY 1
#define USB_CH341_EVEN_PARITY 2
#define USB_CH341_MARK_PARITY 3
#define USB_CH341_SPACE_PARITY 4
__u8 bDataBits;
} __attribute__((packed));
struct ch341 {
struct usb_device *dev; /* the corresponding usb device */
struct usb_interface *data; /* data interface */
struct tty_port port; /* our tty port data */
struct urb *ctrlurb; /* urbs */
u8 *ctrl_buffer; /* buffers of urbs */
dma_addr_t ctrl_dma; /* dma handles of buffers */
struct ch341_wb wb[CH341_NW];
unsigned long read_urbs_free;
struct urb *read_urbs[CH341_NR];
struct ch341_rb read_buffers[CH341_NR];
int rx_buflimit;
int rx_endpoint;
spinlock_t read_lock;
int write_used; /* number of non-empty write buffers */
int transmitting;
spinlock_t write_lock;
struct mutex mutex;
bool disconnected;
struct usb_ch341_line_coding line; /* baudrate, data format */
struct work_struct work; /* used for line discipline waking up */
unsigned int ctrlin; /* input lines (CTS, DSR, DCD, RI) */
unsigned int ctrlout; /* output control lines (DTR, RTS) */
struct async_icount iocount; /* counters for control line changes */
struct async_icount oldcount; /* for comparison of counter */
wait_queue_head_t wioctl; /* for ioctl */
unsigned int writesize; /* max packet size */
unsigned int readsize, ctrlsize; /* buffer sizes for freeing */
unsigned int minor; /* ch341 minor number */
unsigned char clocal; /* termios CLOCAL */
unsigned int susp_count; /* number of suspended interfaces */
u8 bInterval;
struct usb_anchor delayed; /* used for a device about to be woken */
unsigned long quirks;
bool hardflow;
};
/* constants describing various quirks and errors */
#define NO_UNION_NORMAL BIT(0)
#define SINGLE_RX_URB BIT(1)
#define NO_CAP_LINE BIT(2)
#define NO_DATA_INTERFACE BIT(4)
#define IGNORE_DEVICE BIT(5)
#define QUIRK_CONTROL_LINE_STATE BIT(6)
#define CLEAR_HALT_CONDITIONS BIT(7)
#endif
+2
View File
@@ -250,6 +250,7 @@ static void option_instat_callback(struct urb *urb);
#define QUECTEL_PRODUCT_EP06 0x0306
#define QUECTEL_PRODUCT_EM12 0x0512
#define QUECTEL_PRODUCT_RM500Q 0x0800
#define QUECTEL_PRODUCT_EC200N_CN 0x6002
#define QUECTEL_PRODUCT_EC200A_CN 0x6005
#define QUECTEL_PRODUCT_EC200T 0x6026
#define QUECTEL_PRODUCT_EC200U_CN 0x0901
@@ -1120,6 +1121,7 @@ static const struct usb_device_id option_ids[] = {
{ USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RM500Q, 0xff, 0, 0) },
{ USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RM500Q, 0xff, 0xff, 0x10),
.driver_info = ZLP },
{ USB_DEVICE(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EC200N_CN) },
{ USB_DEVICE(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EC200A_CN) },
{ USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EC200T, 0xff, 0, 0) },
{ USB_DEVICE(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EC200U_CN) },
@@ -1,6 +1,23 @@
#ifndef __DT_DWC2_LOONGSON_FIX_H
#define __DT_DWC2_LOONGSON_FIX_H
/*
* DWC2_LOONGSON_FIX_NONE:
* Original. Some USB devices cannot initialize when first powered up.
* However, network devices do not experience packet loss.
* Therefore, if we confirm the use of a USB-network device, then select this configuration.
*
* DWC2_LOONGSON_FIX_DMA:
* Used for most devices, such as USB storage and USB touchscreens.
* However, network devices may experience packet loss.
*
* DWC2_LOONGSON_FIX_DELAY:
* Deprecated. It causes USB to operate slowly.
* However, the 4G model can still dial up. Maybe optimize later.
*
* DWC2_LOONGSON_FIX_DELAY_FULL:
* Deprecated.
*/
#define DWC2_LOONGSON_FIX_NONE 0
#define DWC2_LOONGSON_FIX_DMA 1
#define DWC2_LOONGSON_FIX_DELAY 2