|
|
@ -31,6 +31,8 @@ typedef struct _Sm2310_DEV_HANDLE { |
|
|
|
SM2130_SPI_DEV *pDevCtrl; |
|
|
|
} SM2310_DEV_HANDLE; |
|
|
|
|
|
|
|
LOCAL int sm2130_driver_node = -1; |
|
|
|
|
|
|
|
/* locals */ |
|
|
|
LOCAL void sm2130SpiDevShow(VXB_DEVICE_ID pDev, int verbose); |
|
|
|
LOCAL INT32 sm2130BusDevRead(VXB_DEVICE_ID pDev, UINT8 cmd); |
|
|
@ -53,9 +55,9 @@ LOCAL struct drvBusFuncs sm2130SpiDevFuncs = { |
|
|
|
/* Publish the methods for the resources controlled with this file */ |
|
|
|
/* clang-format off */ |
|
|
|
LOCAL struct vxbDeviceMethod sm2130SpiDevMethods[] = { |
|
|
|
DEVMETHOD(busDevShow , sm2130SpiDevShow), |
|
|
|
DEVMETHOD(vxbDrvUnlink, sm2130SpiDevInstUnlink), |
|
|
|
{ 0, 0 } |
|
|
|
DEVMETHOD(busDevShow , sm2130SpiDevShow), |
|
|
|
DEVMETHOD(vxbDrvUnlink, sm2130SpiDevInstUnlink), |
|
|
|
{ 0, 0 } |
|
|
|
}; |
|
|
|
|
|
|
|
LOCAL struct vxbSpiRegister sm2130SpiDevRegister = { |
|
|
@ -114,13 +116,14 @@ LOCAL void sm2130SpiDevInstInit(VXB_DEVICE_ID pDev) |
|
|
|
pDrvCtrl->pDev = pDev; |
|
|
|
pDev->pDrvCtrl = pDrvCtrl; |
|
|
|
|
|
|
|
pDrvCtrl->drvNode = -1; |
|
|
|
pDrvCtrl->devHandle = NULL; |
|
|
|
pDrvCtrl->devName = SM2310_DEV_NAME; |
|
|
|
|
|
|
|
snprintf(pDrvCtrl->name, sizeof (pDrvCtrl->name), "%s/%d", SM2130_DEV_NAME, pDev->unitNumber); |
|
|
|
pDrvCtrl->devName = pDrvCtrl->name; |
|
|
|
pHcf = (struct hcfDevice *)hcfDeviceGet(pDev); |
|
|
|
if (pHcf) { |
|
|
|
if (devResourceGet(pHcf, "devName", HCF_RES_STRING, (void *)&pDrvCtrl->devName) != OK) { |
|
|
|
pDrvCtrl->devName = SM2310_DEV_NAME; |
|
|
|
pDrvCtrl->devName = pDrvCtrl->name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -130,35 +133,6 @@ LOCAL void sm2130SpiDevInstInit(VXB_DEVICE_ID pDev) |
|
|
|
vxbNextUnitGet(pDev); |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
* |
|
|
|
* sm2130SpiDevInstInit2 - first level initialization routine of spi flash device |
|
|
|
* |
|
|
|
* |
|
|
|
* RETURNS: N/A |
|
|
|
* |
|
|
|
* ERRNO: N/A |
|
|
|
*/ |
|
|
|
LOCAL void sm2130SpiDevInstInit2(VXB_DEVICE_ID pDev) |
|
|
|
{ |
|
|
|
SM2130_SPI_DEV *pDrvCtrl; |
|
|
|
FUNCPTR pFunc; |
|
|
|
|
|
|
|
/* Check for vaild parameter */ |
|
|
|
VXB_ASSERT_NONNULL_V(pDev); |
|
|
|
|
|
|
|
pDrvCtrl = (SM2130_SPI_DEV *)pDev->pDrvCtrl; |
|
|
|
|
|
|
|
/* Mutex semaphore is initialized and necessary at this point */ |
|
|
|
pDrvCtrl->muteSem = semMCreate(SPI_DEV_MUTEX_OPT); |
|
|
|
|
|
|
|
pFunc = vxbDevMethodGet(vxbDevParent(pDev), (VXB_METHOD_ID)vxbSpiSpecialGet_desc); |
|
|
|
|
|
|
|
/* Retrieve the SPI master special information */ |
|
|
|
if (pFunc != NULL) |
|
|
|
(*pFunc)(vxbDevParent(pDev), &pDrvCtrl->specialInfo); |
|
|
|
} |
|
|
|
|
|
|
|
/* {{{ device driver api */ |
|
|
|
LOCAL SM2310_DEV_HANDLE *drv1553bOpen(SM2310_DEV_HANDLE *dev, const char *name, int flags, int mode) |
|
|
|
{ |
|
|
@ -219,6 +193,35 @@ LOCAL int drv1553bIoctl(SM2310_DEV_HANDLE *dev, int cmd, _Vx_ioctl_arg_t arg) |
|
|
|
} |
|
|
|
/* }}} */ |
|
|
|
|
|
|
|
/*
|
|
|
|
* |
|
|
|
* sm2130SpiDevInstInit2 - first level initialization routine of spi flash device |
|
|
|
* |
|
|
|
* |
|
|
|
* RETURNS: N/A |
|
|
|
* |
|
|
|
* ERRNO: N/A |
|
|
|
*/ |
|
|
|
LOCAL void sm2130SpiDevInstInit2(VXB_DEVICE_ID pDev) |
|
|
|
{ |
|
|
|
SM2130_SPI_DEV *pDrvCtrl; |
|
|
|
FUNCPTR pFunc; |
|
|
|
|
|
|
|
/* Check for vaild parameter */ |
|
|
|
VXB_ASSERT_NONNULL_V(pDev); |
|
|
|
|
|
|
|
pDrvCtrl = (SM2130_SPI_DEV *)pDev->pDrvCtrl; |
|
|
|
|
|
|
|
/* Mutex semaphore is initialized and necessary at this point */ |
|
|
|
pDrvCtrl->muteSem = semMCreate(SPI_DEV_MUTEX_OPT); |
|
|
|
|
|
|
|
pFunc = vxbDevMethodGet(vxbDevParent(pDev), (VXB_METHOD_ID)vxbSpiSpecialGet_desc); |
|
|
|
|
|
|
|
/* Retrieve the SPI master special information */ |
|
|
|
if (pFunc != NULL) |
|
|
|
(*pFunc)(vxbDevParent(pDev), &pDrvCtrl->specialInfo); |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
* sm2130SpiDevInstConnect - third level initialization routine of spi flash |
|
|
|
* |
|
|
@ -238,10 +241,9 @@ LOCAL void sm2130SpiDevInstConnect(VXB_DEVICE_ID pDev) |
|
|
|
|
|
|
|
pDrvCtrl = (SM2130_SPI_DEV *)pDev->pDrvCtrl; |
|
|
|
|
|
|
|
(void)semTake(pDrvCtrl->muteSem, WAIT_FOREVER); |
|
|
|
if (pDrvCtrl->drvNode < 0) { |
|
|
|
if (sm2130_driver_node < 0) { |
|
|
|
/* clang-format off */ |
|
|
|
pDrvCtrl->drvNode = iosDrvInstall( |
|
|
|
sm2130_driver_node = iosDrvInstall( |
|
|
|
(DRV_CREATE_PTR)drv1553bOpen , |
|
|
|
(DRV_REMOVE_PTR)NULL , |
|
|
|
(DRV_OPEN_PTR)drv1553bOpen , |
|
|
@ -250,23 +252,25 @@ LOCAL void sm2130SpiDevInstConnect(VXB_DEVICE_ID pDev) |
|
|
|
(DRV_WRITE_PTR)NULL , |
|
|
|
(DRV_IOCTL_PTR)drv1553bIoctl); |
|
|
|
/* clang-format on */ |
|
|
|
if (pDrvCtrl->drvNode > 0) { |
|
|
|
dev = (SM2310_DEV_HANDLE *)hwMemAlloc(sizeof(SM2310_DEV_HANDLE)); |
|
|
|
if (dev) { |
|
|
|
pDrvCtrl->refcount = 0; |
|
|
|
selWakeupListInit(&dev->selList); |
|
|
|
if (iosDevAdd(&dev->devHdr, pDrvCtrl->devName, pDrvCtrl->drvNode) == OK) { |
|
|
|
pDrvCtrl->devHandle = dev; |
|
|
|
dev->pDevCtrl = pDrvCtrl; |
|
|
|
} else { |
|
|
|
} |
|
|
|
|
|
|
|
semTake(pDrvCtrl->muteSem, WAIT_FOREVER); |
|
|
|
if (sm2130_driver_node > 0) { |
|
|
|
dev = (SM2310_DEV_HANDLE *)hwMemAlloc(sizeof(SM2310_DEV_HANDLE)); |
|
|
|
if (dev) { |
|
|
|
pDrvCtrl->refcount = 0; |
|
|
|
selWakeupListInit(&dev->selList); |
|
|
|
if (iosDevAdd(&dev->devHdr, pDrvCtrl->devName, sm2130_driver_node) == OK) { |
|
|
|
pDrvCtrl->devHandle = dev; |
|
|
|
dev->pDevCtrl = pDrvCtrl; |
|
|
|
} else { |
|
|
|
#ifndef _VXBUS_BASIC_HWMEMLIB |
|
|
|
hwMemFree((char *)dev); |
|
|
|
hwMemFree((char *)dev); |
|
|
|
#endif /* _VXBUS_BASIC_HWMEMLIB */ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
(void)semGive(pDrvCtrl->muteSem); |
|
|
|
semGive(pDrvCtrl->muteSem); |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
@ -325,7 +329,6 @@ LOCAL void sm2130SpiDevShow(VXB_DEVICE_ID pDev, int verbose) |
|
|
|
printf(" speed: %u\n", pDrvCtrl->freq); |
|
|
|
printf(" devName: %s\n", pDrvCtrl->devName); |
|
|
|
printf(" devHandle: %p\n", pDrvCtrl->devHandle); |
|
|
|
printf(" drvNode: %d\n", pDrvCtrl->drvNode); |
|
|
|
printf(" refCount: %d\n", pDrvCtrl->refcount); |
|
|
|
} |
|
|
|
|
|
|
|