标题:
读写SPI FLASH--驱动部分(6)
[打印本页]
作者:
yuyang911220
时间:
2015-2-27 09:08
标题:
读写SPI FLASH--驱动部分(6)
/* fill pre opcode */
addr = base + SPI_PREOP;
val = readw((void *)(spi_char.mem_virt+SPI_PREOP));
SPI_DBG("before init, SPI_PREOOP=%08x/n", val);
val = SPI_WR_ENABLE | (SPI_WSR_ENABLE << 8);
writew(val, (void *)addr);
val = readw((void *)(spi_char.mem_virt+SPI_PREOP));
SPI_DBG("after init, SPI_PREOP=%08x/n", val);
/* disable Atomic Cycle Sequence */
val = readw((void *)(spi_char.mem_virt+SPI_CTRL));
val &= ~SPI_CTRL_ACS;
val &= ~SPI_CTRL_SPOP;
writew(val, (void*)(spi_char.mem_virt+SPI_CTRL));
}
loff_t spi_lseek(struct file *filp, loff_t off, int whence)
{
loff_t newpos;
switch (whence)
{
case 0: /* SEEK_SET */
newpos = off;
break;
case 1: /* SEEK_CUR */
newpos = spi_char.fp + off;
break;
case 2: /* SEEK_END */
newpos = spi_char.fp + off;
break;
default: /* cant't happen */
return (-EINVAL);
break;
}
if(newpos < 0 || newpos >= SPI_FLASH_SIZE)
{
return (-EINVAL);
}
spi_char.fp = newpos;
return (newpos);
}
// Linux file operations
struct file_operations file_ops =
{
.owner = THIS_MODULE,
.read = spi_read,
.write = spi_write,
.llseek = spi_lseek,
.open = spi_open,
.release = spi_release,
.ioctl = spi_ioctl,
};
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0