📄 bts3c2410_c54xhpi.c
字号:
} */
return (len);
}
}
else if(intial==0)
{
//Jdebug("count1=%d\n",count);
number++;
if (count%2)
loop = len / 2;
else
loop = (count+1) / 2;
addtemp=add-1;
temp3=addtemp &0xff;
addtemp=add-1;
temp4=(addtemp>>8)&0xff;
if(number==2)
{
temp5=readb(RHPIC_L1);
temp6=readb(RHPIC_H1);
Jdebug("HPIC: = 0x%02x%02x\n",temp6,temp5);
//temp6=0x11;
//temp5=0x11;
temp6=temp6|(1<<4);
temp5=temp5|(1<<4);
writeb(temp5, WHPIC_L1);
writeb(temp6, WHPIC_H1);
udelay(10);
Jdebug("HPICtmp: = 0x%02x%02x\n",temp6,temp5);
Jdebug("HPIC: = 0x%02x%02x\n",readb(RHPIC_H1),readb(RHPIC_L1));
writeb(0x01, WHPIA_L1);
writeb(0x01, WHPIA_H1);
udelay(10);
//temp6=0x01;
//temp5=0x01;
temp6=temp6&~(1<<4);
temp5=temp5&~(1<<4);
udelay(10);
writeb(temp5, WHPIC_L1);
writeb(temp6, WHPIC_H1);
Jdebug("HPICtmp: = 0x%02x%02x\n",temp6,temp5);
Jdebug("HPIC: = 0x%02x%02x\n",readb(RHPIC_H1),readb(RHPIC_L1));
Jdebug("temp3=%x,temp4=%x\n",temp3,temp4);
writeb(temp3, WHPIA_L1);
writeb(temp4, WHPIA_H1);
}
else
{
Jdebug("HPIC: = 0x%02x%02x\n",readb(RHPIC_H1),readb(RHPIC_L1));
Jdebug("temp3=%x,temp4=%x\n",temp3,temp4);
writeb(temp3, WHPIA_L1);
writeb(temp4, WHPIA_H1);
}
Jdebug("get ready to write data from 0x8000.\n");
/*get ready to write data from 0x2000*/
for(i=0;i<loop;i++)
{
udelay(10);
writeb(pbuff[2*i], WHPIDI_L1);
writeb(pbuff[2*i+1], WHPIDI_H1);
//Jdebug("%x,%x",pbuff[2*i],pbuff[2*i+1]);
//udelay(50);
}
if(number==2)
{
temp5=readb(RHPIC_L1);
temp6=readb(RHPIC_H1);
Jdebug("HPIC: = 0x%02x%02x\n",temp6,temp5);
//temp6=0x11;
//temp5=0x11;
temp6=temp6|(1<<4);
temp5=temp5|(1<<4);
writeb(temp5, WHPIC_L1);
writeb(temp6, WHPIC_H1);
udelay(10);
Jdebug("HPICtmp: = 0x%02x%02x\n",temp6,temp5);
Jdebug("HPIC: = 0x%02x%02x\n",readb(RHPIC_H1),readb(RHPIC_L1));
writeb(0x00, WHPIA_L1);
writeb(0x00, WHPIA_H1);
udelay(10);
//temp6=0x01;
//temp5=0x01;
temp6=temp6&~(1<<4);
temp5=temp5&~(1<<4);
udelay(10);
writeb(temp5, WHPIC_L1);
writeb(temp6, WHPIC_H1);
}
if(number==3)
{
Jdebug("number==%d\n",number);
writeb(0x7d, WHPIA_L1);
writeb(0x00, WHPIA_H1);
udelay(1000);
writeb(0x01, WHPIDI_L1);
writeb(0x00, WHPIDI_H1);
udelay(1000);
Jdebug("A: = 0x%02x%02x\n",readb(RHPID_H1),readb(RHPID_L1));
writeb(0xf9, WHPIDI_L1);
writeb(0x93, WHPIDI_H1);
udelay(1000);
Jdebug("A: = 0x%02x%02x\n",readb(RHPID_H1),readb(RHPID_L1));
}
/* Jdebug("\n\n");
writeb(0xff, WHPIA_L1);
writeb(0x5f, WHPIA_H1);
for(i=0;i<loop;i++)
{
udelay(10);
bt1=readb(RHPIDI_L1);
bt2=readb(RHPIDI_H1);
Jdebug("%x,%x",bt1,bt2);
}*/
//Jdebug("count2=%d\n",count);
// writeb(0x7d, WHPIA_L1);
// writeb(0x00, WHPIA_H1);
//udelay(10);
// writeb(0x00, WHPIDI_L1);
// writeb(0x00, WHPIDI_H1);
// udelay(10);
//writeb(0x00, WHPIDI_L1);
// writeb(0x20, WHPIDI_H1);
// udelay(1000);
// udelay(10);
/* bt1=readb(WHPIDI_L1);
bt2=readb(WHPIDI_H1);
Jdebug("bt1=%x,bt2=%x\n",bt1,bt2);
Jdebug("dsp_hpi.write():send a INT to dsp.\n");
udelay(10);
writeb(0x7e, WHPIA_L1);
writeb(0x00, WHPIA_H1);
udelay(10);
writeb(0x00, WHPIDI_L1);
writeb(0x80, WHPIDI_H1);
udelay(10);
writeb(0x7e, WHPIA_L1);
writeb(0x00, WHPIA_H1);
udelay(10);
bt1=readb(WHPIDI_L1);
bt2=readb(WHPIDI_H1);
Jdebug("bt1=%x,bt2=%x\n",bt1,bt2);
udelay(10);
writeb(0xff, WHPIA_L1);
writeb(0x7f, WHPIA_H1);
udelay(10);
bt1=readb(WHPIDI_L1);
bt2=readb(WHPIDI_H1);*/
// Jdebug("bt1=%x,bt2=%x\n",bt1,bt2);
//writeb(0x05, WHPIC_L1);
//writeb(0x05, WHPIC_H1);
//Jdebug("(HPIC) = 0x%02x%02x\n",readb(RHPIC_H1),readb(RHPIC_L1));
//Jdebug("count3=%d\n",count);
return count;
}
}
static int dsp_hpi_write(struct file *file, const char *buffer, size_t count, loff_t *ppos)
{
int bbb=1;
unsigned char temp1, temp2;
int ret;
int use_buffer = 0;
int i;
unsigned char my_count = 0;
unsigned char count1 = 0;
unsigned char count2 = 0;
/* writeb(0x7f, WHPIA_L1);
writeb(0x00, WHPIA_H1);
writeb(0x2c,WHPID_L1);
writeb(0xf8,WHPID_H1);
udelay(10000);
writeb(0x7f, WHPIA_L1);
writeb(0x00, WHPIA_H1);
udelay(10000);
for( i=0;i<100;i++)
{
udelay(10000);
Jdebug("A: = 0x%02x%02x\n",readb(RHPID_H1),readb(RHPID_L1));
}
return 0;*/
if(count > (PAGE_SIZE << order))
return -EINVAL;
if(count > 2048)
{
Jdebug("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n");
while(1);
}
if (1 == buffer1_idle)
{
buffer1_idle = 0;
if (buf_flag == BIGBUFFER)
{
memset(buffer1, 0, (PAGE_SIZE << order));
// Jdebug("BIGBUFFER\n");
}
else
{
memset(buffer1, 0, BUFFERSIZE);
// Jdebug("SMALLBUFFER\n");
}
copy_from_user(buffer1, buffer, count);
use_buffer = BUFFER1;
}
else if (1 == buffer2_idle)
{
buffer2_idle = 0;
if (BIGBUFFER == buf_flag)
{
memset(buffer2, 0, (PAGE_SIZE << order));
// Jdebug("BIGBUFFER\n");
}
else
{
memset(buffer2, 0 , BUFFERSIZE);
//Jdebug("SMALLBUFFER\n");
}
copy_from_user(buffer2, buffer, count);
use_buffer = BUFFER2;
}
else
{
// printk(KERN_WARNING "dsp_hpi.write():buffer1 be over written.\n");
buffer1_idle = 0;
overflow_count++;
if (buf_flag == BIGBUFFER)
memset(buffer1, 0, (PAGE_SIZE << order));
else
memset(buffer1, 0, BUFFERSIZE);
copy_from_user(buffer1, buffer, count);
use_buffer = BUFFER1;
}
//bt
if(intial==1)
{
writeb(0xf0, WHPIA_L1);
writeb(0x5f, WHPIA_H1);
while(1)
{
udelay(50);
my_count++;
// 0x5ff0 check dsp's buffer busy or not
temp1 = readb(RHPID_L1);
temp2 = readb(RHPID_H1);
if(temp1 == 0 && temp2 == 0)
count1 ++;
else
count1 = 0;
/*check whether the data buffer is clear or not, to make sure avoiding overwritten!*/
if(count1 >= 5)//5
{
//Jdebug("dsp_hpi.write():dsp buffer is idle.\n");
break;
}
else if(my_count >= 100)
{
if (temp1==0xff && temp2==0xff)
{
//writeb(0x05, WHPIC_L1);
//writeb(0x05, WHPIC_H1);
//Jdebug("dsp_hpi.write():send a INT to dsp BTBTBTBT.\n");
udelay(100);
count2++;
}
my_count = 50;
// Jdebug("dsp_hpi.write():dsp buffer is busy.\n");
// return -EBUSY;
}
if (count2 > 10)
{
//Jdebug("dsp_hpi.write():Overwrite dsp buffer!!!\n");
break;
}
}
}
//Jdebug("count=%d\n",count);
if (use_buffer == BUFFER1)
{
// Jdebug("BUFFER1\n");
ret = do_write(buffer1,count);
buffer1_idle = 1;
return ret;
}
else
{
// Jdebug("BUFFER2\n");
ret = do_write(buffer2,count);
buffer2_idle = 1;
return ret;
}
}
static int dsp_hpi_open(struct inode *inode, struct file *file)
{
int i,j;
// Jdebug("BWSCON = 0x%x\n",BWSCON);
BWSCON &= ~(0x07 << 4); // BANK1
BWSCON |= (0x00 << 4); // set BANK1 to 8bit width
// Jdebug("new BWSCON = 0x%x\n",BWSCON);
// sometime need to set GPACON
HPI_BASE = ioremap(HPI_ADDR, 0x100);
// Jdebug("HPI_BASE = 0x%x\n", HPI_BASE);
if (check_mem_region(HPI_BASE, 0x10))
{
printk(KERN_INFO "dsp_hpi: can't get I/O port address 0x%x\n", HPI_BASE);
return (-1);
}
request_mem_region(HPI_BASE, 0x10, DEVICE_NAME);
WHPIC_L1 = HPI_BASE + 0x0;
WHPIC_H1 = HPI_BASE + 0x2;
RHPIC_L1 = HPI_BASE + 0x1;
RHPIC_H1 = HPI_BASE + 0x3;
WHPIDI_L1 = HPI_BASE + 0x4;
WHPIDI_H1 = HPI_BASE + 0x6;
RHPIDI_L1 = HPI_BASE + 0x5;
RHPIDI_H1 = HPI_BASE + 0x7;
WHPIA_L1 = HPI_BASE + 0x8;
WHPIA_H1 = HPI_BASE + 0xa;
RHPIA_L1 = HPI_BASE + 0x9;
RHPIA_H1 = HPI_BASE + 0xb;
WHPID_L1 = HPI_BASE + 0xc;
WHPID_H1 = HPI_BASE + 0xe;
RHPID_L1 = HPI_BASE + 0xd;
RHPID_H1 = HPI_BASE + 0xf;
Jdebug("(HPIC_L) = 0x%02x\n",readb(RHPIC_L1));
Jdebug("(HPIC_H) = 0x%02x\n",readb(RHPIC_H1));
writeb(0x09,WHPIC_L1);
writeb(0x09,WHPIC_H1);
Jdebug("new (HPIC_L) = 0x%02x\n",*RHPIC_L1);
Jdebug("new (HPIC_H) = 0x%02x\n",*RHPIC_H1);
Jdebug("checking HPIA=0x%x 0x%x\n",WHPIA_H1,WHPIA_L1);
writeb(0xf0, WHPIA_L1);
writeb(0x5f, WHPIA_H1);
// 0x5ff0 check dsp's buffer busy or not
writeb(0x00, WHPID_L1);
writeb(0x00, WHPID_H1);
Jdebug("checking (HPID)=0x%02x%02x\n",readb(RHPID_H1),readb(RHPID_L1));
buffer1 = (unsigned char *)kmalloc(BUFFERSIZE, GFP_KERNEL);
if(!buffer1)
{
printk("failed assigned small mem for buffer1 ! \n");
return -ENOMEM;
}
buffer2 = (unsigned char *)kmalloc(BUFFERSIZE, GFP_KERNEL);
if(!buffer2)
{
printk("failed assigned small mem for buffer2 ! \n");
return -ENOMEM;
}
buf_flag = SMALLBUFFER;
printk("dsp_hpi_open: assigned a small mem. \n");
open_count++;
Jdebug("dsp_hpi: open done!\n");
//GPGCON &=0;
GPGCON &=~(1<<23);
udelay(100);
Jdebug("%x\n",GPGCON);
GPGCON |= (1<<22);
udelay(100);
Jdebug("%x\n",GPGUP);
GPGUP |= (1<<11) ;
/* writeb(0xf5, WHPIA_L1);
writeb(0x5f, WHPIA_H1);
udelay(20);
writeb(0xFF, WHPID_L1);
writeb(0xFF, WHPID_H1);
while((0xff!=readb(RHPID_H1))&&(0xff!=readb(RHPID_L1)))
{
writeb(0xFF, WHPID_L1);
writeb(0xFF, WHPID_H1);
udelay(5);
} */
Jdebug("GPG init done!\n");
return 0;
}
static int dsp_hpi_release(struct inode *inode, struct file *file)
{
if (buf_flag == BIGBUFFER)
{
free_pages((unsigned char *)buffer1, order);
free_pages((unsigned char *)buffer2, order);
}
else if(buf_flag == SMALLBUFFER)
{
kfree(buffer1);
kfree(buffer2);
}
open_count = 0;
release_mem_region(HPI_BASE, 0x10);
iounmap(HPI_BASE);
Jdebug("dsp_hpi: release done!\n");
return 0;
}
static struct file_operations dsp_hpi_fops = {
owner: THIS_MODULE,
open: dsp_hpi_open,
read: dsp_hpi_read,
ioctl: dsp_hpi_ioctl,
write: dsp_hpi_write,
release: dsp_hpi_release,
};
#ifdef CONFIG_DEVFS_FS
static devfs_handle_t devfs_handle;
#endif
static int __init dsp_hpi_init(void)
{
int ret;
ready = 0;
ret = register_chrdev( DSP_MAJOR, DEVICE_NAME, &dsp_hpi_fops );
if(ret<0)
{
printk( DEVICE_NAME "can't register major number \n" );
return ret;
}
Jdebug("original INTMSK = 0x%x\n",S3C2410_INTMSK);
S3C2410_INTMSK &= ~(0x1 << 0);
Jdebug("new INTMSK = 0x%x\n",S3C2410_INTMSK);
init_waitqueue_head(&dsp_wait);
if(request_irq(IRQ_EINT0, &hpi_irq,0, DEVICE_NAME, NULL))
{
unregister_chrdev( DSP_MAJOR, DEVICE_NAME );
printk( DEVICE_NAME" can't request irq \n" );
return (-1);
}
Jdebug( DEVICE_NAME" assigned IRQ %d\n", IRQ_EINT0);
#ifdef CONFIG_DEVFS_FS
devfs_handle = devfs_register(NULL , DEVICE_NAME, DEVFS_FL_DEFAULT, DSP_MAJOR, 0, S_IFCHR | S_IRUSR | S_IWUSR, &dsp_hpi_fops, NULL );
#endif
Jdebug("dsp_hpi: initialize done!\n");
return 0;
}
static void __exit dsp_hpi_exit(void)
{
#ifdef CONFIG_DEVFS_FS
devfs_unregister(devfs_handle);
#endif
free_irq(IRQ_EINT0, hpi_irq);
unregister_chrdev(DSP_MAJOR, DEVICE_NAME);
Jdebug("dsp_hpi: exit() done!\n");
}
module_init(dsp_hpi_init);
module_exit(dsp_hpi_exit);
MODULE_LICENSE("GPL");
/**************************************************************
0x 5ff0 5ff1 5ff2
+----------+-------+-----------+----------------
|idle-flag |length | data-flag |
+----------+-------+-----------+--------------
***************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -