From 2d4406c2bcb60c011ad39cd396d77cd61078f573 Mon Sep 17 00:00:00 2001 From: surenyi Date: Wed, 23 Oct 2024 11:48:42 +0800 Subject: [PATCH] pinmux gpios, sm2130 add irq handler Signed-off-by: surenyi --- bspStubs.c | 20 +++++++++++++++++++- hwconf.c | 13 +++++++++++-- sysLib.c | 11 +++++++++++ vxbFtSpi.c | 39 ++++++++++++++++++++++----------------- vxbLfsLib.c | 14 +++++++------- vxbSm2130SpiDev.c | 15 +++++++++++++++ vxbSm2130SpiDev.h | 1 + 7 files changed, 86 insertions(+), 27 deletions(-) diff --git a/bspStubs.c b/bspStubs.c index 6eaadae..8f54cce 100644 --- a/bspStubs.c +++ b/bspStubs.c @@ -6,7 +6,10 @@ #include #include #include +#include + #include "config.h" +#include "vxbFtGpio.h" #if defined(INCLUDE_IPFTPS) #include #include @@ -18,7 +21,7 @@ /* externs */ extern int lfsLowRawWrite(unsigned long offset, const char *buffer, int size); - +extern void gpioIsrSetTest (UINT32 gpio, UINT32 pin); int bspLoadUserApp() { SEGMENT_ID seg; @@ -120,6 +123,21 @@ int bsp_ipftps_authenticate_nopasswd(Ipftps_session *session, char *password) } #endif +/* GPIO1_A4 */ +int bspSm1553bIrqConnect(void *data, void (*isr)(void *data)) +{ + VXB_DEVICE_ID pDev; + FT_GPIO_DRVCTRL * pCtrl; + + pDev = vxbInstByNameFind("ftGpio", 1); + if (pDev == NULL) { + return ERROR; + } + pCtrl = pDev->pDrvCtrl; + pCtrl->gpioISRSet(pDev, 4, isr, data); + return OK; +} + int mw(unsigned long addr, unsigned int val) { volatile unsigned int long *ptr = (volatile unsigned long *)(addr); diff --git a/hwconf.c b/hwconf.c index 697f6a1..63c4ac5 100644 --- a/hwconf.c +++ b/hwconf.c @@ -366,8 +366,8 @@ struct hcfResource i2cDev3Resources[] = { LOCAL UINT8 gpio0PortAModeTable[] = { /*pin of portA can be used as interrupt mode*/ /*portA-pinX: 0 1 2 3 4 5 6 7 */ - 0, 2, 0, 0, 0, 0, 0, 0 /* 0:GPIO_MODE_NOT_USED 1:GPIO_MODE_IN - 2:GPIO_MODE_OUT 3:GPIO_MODE_INT*/ + 0, 2, 0, 1, 0, 1, 1, 0 /* 0:GPIO_MODE_NOT_USED 1:GPIO_MODE_IN + 2:GPIO_MODE_OUT 3:GPIO_MODE_INT*/ /* GPIO0_A3, GPIO0_A5, GPIO0_A6 as uart irq */ }; /*This table is used to set the default pin mode of portB*/ LOCAL UINT8 gpio0PortBModeTable[] = { @@ -524,6 +524,14 @@ struct hcfResource lfsResources[] = { #define lfsResNum NELEMENTS(lfsResources) #endif +extern int bspSm1553bIrqConnect(void *data, void (*isr)(void *data)); + +struct hcfResource sm2130Resources[] = { + { "devName" , HCF_RES_STRING, {(void *)"/sm1553b"}}, + { "reqIsr" , HCF_RES_ADDR, {(void *)bspSm1553bIrqConnect}}, +}; +#define sm2130ResNum NELEMENTS(sm2130Resources) + const struct hcfDevice hcfDeviceList[] = { #ifdef DRV_ARM_GICV3 { "armGicDev", 0, VXB_BUSID_PLB, 0, armGICv3Num, armGICv3Resources}, @@ -586,6 +594,7 @@ const struct hcfDevice hcfDeviceList[] = { #ifdef DRV_FS_LITTLEFS { "lfs", 0, VXB_BUSID_PLB, 0, lfsResNum, lfsResources}, #endif +{ "SM2130", 0, VXB_BUSID_SPI, 0, sm2130ResNum, sm2130Resources}, }; const int hcfDeviceNum = NELEMENTS(hcfDeviceList); diff --git a/sysLib.c b/sysLib.c index 8dc2123..6baf35a 100644 --- a/sysLib.c +++ b/sysLib.c @@ -570,6 +570,17 @@ void sysHwInit(void) reg |= (0x1 << 8); writel(reg, PIN_DEMUX_BASE + REG218); + /* GPIO0_A3, GPIO0_A5, GPIO0_A6 + * + * sjtag_ntrst_pad: N gpio0_porta_3 uart_0_dsr_n + * tjtag_tdo_pad: N gpio0_porta_5 uart_0_rts_n + * tjtag_ntrst_pad: N gpio0_porta_6 uart_0_dtr_n + */ + reg = readl(PIN_DEMUX_BASE + REG200); + reg &= ~((0x3 << 12) | (0x3 << 8) | 0x3); + reg |= (1 << 12) | ( 1 << 8) | 1; + writel(reg, PIN_DEMUX_BASE + REG200); + #ifdef DRV_X100DC ftX100DcDevicePciRegister(); #endif diff --git a/vxbFtSpi.c b/vxbFtSpi.c index 613ad3d..cddfea7 100644 --- a/vxbFtSpi.c +++ b/vxbFtSpi.c @@ -240,23 +240,28 @@ LOCAL struct drvBusFuncs vxbFtSpiVxbFuncs = { vxbFtSpiInstConnect /* devConnect */ }; -LOCAL device_method_t vxbFtSpiDeviceMethods[] = { DEVMETHOD(vxbSpiControlGet, vxbFtSpiCtrlGet), - DEVMETHOD(busDevShow, vxbFtSpiShow), - DEVMETHOD(vxbDrvUnlink, vxbFtSpiInstUnlink), DEVMETHOD_END }; +/* clang-format off */ +LOCAL device_method_t vxbFtSpiDeviceMethods[] = { + DEVMETHOD(vxbSpiControlGet, vxbFtSpiCtrlGet), + DEVMETHOD(busDevShow, vxbFtSpiShow), + DEVMETHOD(vxbDrvUnlink, vxbFtSpiInstUnlink), + DEVMETHOD_END +}; LOCAL struct vxbPlbRegister vxbFtSpiDevRegistration = { { - NULL, /* pNext */ - VXB_DEVID_DEVICE, /* devID */ - VXB_BUSID_PLB, /* busID = PLB */ - VXB_VER_4_0_0, /* vxbVersion */ - FT_SPI_NAME, /* drvName */ - &vxbFtSpiVxbFuncs, /* pDrvBusFuncs */ - &vxbFtSpiDeviceMethods[0], /* pMethods */ - NULL, /* devProbe */ - NULL, /* pParamDefaults */ + NULL , /* pNext */ + VXB_DEVID_DEVICE , /* devID */ + VXB_BUSID_PLB , /* busID = PLB */ + VXB_VER_4_0_0 , /* vxbVersion */ + FT_SPI_NAME , /* drvName */ + &vxbFtSpiVxbFuncs , /* pDrvBusFuncs */ + &vxbFtSpiDeviceMethods[0] , /* pMethods */ + NULL , /* devProbe */ + NULL , /* pParamDefaults */ }, }; +/* clang-format on */ /* * vxbFtSpiRegister - register with the VxBus subsystem @@ -1048,14 +1053,14 @@ LOCAL STATUS vxbFtSpiTransfer(VXB_DEVICE_ID pDev, /* controller pDev */ } FSpimSetEnable(pDrvCtrl, FALSE); - - /* FSpimSetChipSelection(pDrvCtrl, TRUE); */ + + /* FSpimSetChipSelection(pDrvCtrl, TRUE); */ FSpimTransferPollFifo(pDrvCtrl, pPkg->txBuf, pPkg->rxBuf, max(pPkg->txLen, pPkg->rxLen)); -/* FSpimSetChipSelection(pDrvCtrl, FALSE); */ - - SPI_DBG(SPI_DBG_ERR," xfer : tx %d bytes, rx %d bytes\n", pPkg->txLen, pPkg->rxLen, 3, 4, 5, 6); + /* FSpimSetChipSelection(pDrvCtrl, FALSE); */ + + SPI_DBG(SPI_DBG_ERR, " xfer : tx %d bytes, rx %d bytes\n", pPkg->txLen, pPkg->rxLen, 3, 4, 5, 6); if (pDrvCtrl->initPhase >= 2) { semGive(pDrvCtrl->muxSem); diff --git a/vxbLfsLib.c b/vxbLfsLib.c index 2e9868b..60bf039 100644 --- a/vxbLfsLib.c +++ b/vxbLfsLib.c @@ -507,14 +507,14 @@ LOCAL void lfsDevShow(VXB_DEVICE_ID pDev, int verbose) printf(" with busInfo %p\n", pDev->u.pSubordinateBus); if (verbose) { - printf(" mountPoint: %s\n", pDrvCtrl->mountPoint); - printf(" flashName: %s\n", pDrvCtrl->flashDrvName); - printf(" mtd: %p\n", pDrvCtrl->mtd); - printf(" read_size: %d\n", pDrvCtrl->lfsConfig.read_size); - printf(" prog_size: %d\n", pDrvCtrl->lfsConfig.prog_size); - printf(" block_size: %d\n", pDrvCtrl->lfsConfig.block_size); + printf(" mountPoint: %s\n", pDrvCtrl->mountPoint); + printf(" flashName: %s\n", pDrvCtrl->flashDrvName); + printf(" mtd: %p\n", pDrvCtrl->mtd); + printf(" read_size: %d\n", pDrvCtrl->lfsConfig.read_size); + printf(" prog_size: %d\n", pDrvCtrl->lfsConfig.prog_size); + printf(" block_size: %d\n", pDrvCtrl->lfsConfig.block_size); if (pDrvCtrl->mtd) { - printf(" flashChip: %s\n", pDrvCtrl->mtd->chipName); + printf(" flashChip: %s\n", pDrvCtrl->mtd->chipName); } } } diff --git a/vxbSm2130SpiDev.c b/vxbSm2130SpiDev.c index 6a7bd37..acbc135 100644 --- a/vxbSm2130SpiDev.c +++ b/vxbSm2130SpiDev.c @@ -125,6 +125,9 @@ LOCAL void sm2130SpiDevInstInit(VXB_DEVICE_ID pDev) if (devResourceGet(pHcf, "devName", HCF_RES_STRING, (void *)&pDrvCtrl->devName) != OK) { pDrvCtrl->devName = pDrvCtrl->name; } + if (devResourceGet(pHcf, "reqIsr", HCF_RES_ADDR, (void *)&pDrvCtrl->reqIsr) != OK) { + pDrvCtrl->reqIsr = NULL; + } } pDrvCtrl->read = sm2130BusDevRead; @@ -243,6 +246,14 @@ LOCAL void sm2130SpiDevInstInit2(VXB_DEVICE_ID pDev) (*pFunc)(vxbDevParent(pDev), &pDrvCtrl->specialInfo); } +LOCAL void sm1553isr(void *data) +{ + SM2310_DEV_HANDLE *dev = data; + + logMsg("sm1553isr interrupt", 1, 2, 3, 4, 5, 6); + selWakeupAll(&dev->selList, SELREAD); +} + /* * sm2130SpiDevInstConnect - third level initialization routine of spi flash * @@ -284,6 +295,9 @@ LOCAL void sm2130SpiDevInstConnect(VXB_DEVICE_ID pDev) if (iosDevAdd(&dev->devHdr, pDrvCtrl->devName, sm2130_driver_node) == OK) { pDrvCtrl->devHandle = dev; dev->pDevCtrl = pDrvCtrl; + if (pDrvCtrl->reqIsr) { + pDrvCtrl->reqIsr(dev, sm1553isr); + } } else { #ifndef _VXBUS_BASIC_HWMEMLIB hwMemFree((char *)dev); @@ -351,6 +365,7 @@ LOCAL void sm2130SpiDevShow(VXB_DEVICE_ID pDev, int verbose) printf(" devName: %s\n", pDrvCtrl->devName); printf(" devHandle: %p\n", pDrvCtrl->devHandle); printf(" refCount: %d\n", pDrvCtrl->refcount); + printf(" reqIsr: %p\n", pDrvCtrl->reqIsr); } return; diff --git a/vxbSm2130SpiDev.h b/vxbSm2130SpiDev.h index 5ca1c27..445adc1 100644 --- a/vxbSm2130SpiDev.h +++ b/vxbSm2130SpiDev.h @@ -41,6 +41,7 @@ typedef struct _spi_1553b_drv_ctrl { int refcount; void *devHandle; + int (*reqIsr)(void *data, void (*isr)(void *data)); INT32 (*read)(VXB_DEVICE_ID pDev, UINT8 cmd); STATUS (*write)(VXB_DEVICE_ID pDev, UINT8 cmd, UINT16 var);