first let's look at the struct file_operation
{
.ioctl = fun_name,(if in linux-digilent ti is .unlocked_ioctl = fun_name)
}
function declare:
static int my_ioctl(unsigned int reg_num,unsigned int cmd,struct data *arg);
now we know, there is a struct named data
struct data{
int reg_num;
int reg_val;
};
there also has a function to init the struct data
struct data makedata(int x,int y)
{
struct data temp;
temp.reg_num = x;
temp.reg_val = y;
return temp;
}
static int my_ioctl(unsigned int reg_num,unsigned int cmd,struct data *arg){
struct data * p = arg ;
int tmp;
switch(cmd){
case 0:
prink("read_reg%d\n",p->reg_num);
tmp = ioread32(( (p->reg_num)*4 )+ aes_slave_reg0_addr); break;
case 1:
prink("write_reg%d\n",p->reg_num);
tmp =iowrite32(( (p->reg_num)*4 )+ aes_slave_reg0_addr,p->val);break;
default: return 0xff;
}
return tmp;
}