📄 pwm.c
字号:
/*********************************************************************************************************
** Function name: pwm_ioctl
** Descriptions: IO control function
** Input:inode: information of device
** filp: pointer of file
** cmd: command
** arg: additive parameter
** Output 0: OK
** other: not OK
** Created by: Chenmingji
** Created Date: 2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static int pwm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg){ unsigned long temp; if (_IOC_TYPE(cmd) != PWM_IOC_MAGIC) { return -ENOTTY; } if (_IOC_NR(cmd) >= PWM_MAXNR) { return -ENOTTY; }
switch(cmd) { case PWM_SET_CYC: if(arg<65535) { outl(arg,S3C44B0X_TCNTB2); outl((arg/2),S3C44B0X_TCMPB2);// temp = inl(S3C44B0X_TCON);// temp &= (~(0x0f<<12));// temp |= (0x01<<13);// outl(temp,S3C44B0X_TCON);// temp &= (~(0x0f<<12));// temp |= (0x09<<12);// outl(temp,S3C44B0X_TCON); } break; case PWM_GET_RUN_TIME: if (!access_ok(VERIFY_WRITE, (void *)arg, _IOC_SIZE(cmd))) { return -EFAULT; } put_user(RunTime, (u32 *)arg); break;/* case PWM_1_ENABLE:
outl(inl(PWMLER) | (1 << 9), PWMPCR);
outl(0x02 | (inl(PINSEL0) & ~0x03), PINSEL0);
break; case PWM_1_DISABLE: outl(inl(PWMPCR) & ~(1 << 9), PWMPCR);
outl((PinSel0Save & 0x03) | (inl(PINSEL0) & ~0x03), PINSEL0);
break; case PWM_1_SET_DUTY:
if (arg < inl(PWMMR0))
{
outl(arg, PWMMR1);
outl(inl(PWMLER) | (1 << 1), PWMLER); } break; */ case PWM_2_ENABLE:
temp = inl(S3C44B0X_PCONE); temp &= (~(0x03<<10)); temp |= (0x02<<10); outl(temp,S3C44B0X_PCONE); outl(inl(S3C44B0X_TCON)|0x0D000,S3C44B0X_TCON); break; case PWM_2_DISABLE: outl(inl(S3C44B0X_TCON)&(~(0x05<<12)),S3C44B0X_TCON); outl(PinSel0Save | (inl(S3C44B0X_PCONE) & (~(0x03<<10))), S3C44B0X_PCONE);
outl(PinSel1Save | (inl(S3C44B0X_PUPE) & (~(0x01<<5))), S3C44B0X_PUPE);
break; case PWM_2_SET_DUTY:
if (arg < inl(S3C44B0X_TCNTB2))
{ outl(arg,S3C44B0X_TCMPB2); } break;/* case PWM_3_ENABLE:
outl(inl(PWMPCR) & ~(1 << 3), PWMPCR);
outl(inl(PWMPCR) | (1 << 11), PWMPCR);
outl((0x02 << 2) | (inl(PINSEL0) & (~(0x03 << 2))), PINSEL0);
break; case PWM_3_DISABLE: outl(inl(PWMPCR) & ~(1 << 11), PWMPCR);
outl((PinSel0Save & (0x03 << 2)) | (inl(PINSEL0) & (~(0x03 << 2))), PINSEL0);
break; case PWM_3_SET_DUTY:
if (arg < inl(PWMMR0))
{
outl(arg, PWMMR3);
outl(inl(PWMLER) | (1 << 3), PWMLER); } break;
case PWM_4_ENABLE:
outl(inl(PWMPCR) & ~(1 << 4), PWMPCR);
outl(inl(PWMPCR) | (1 << 12), PWMPCR);
outl((0x02 << 16) | (inl(PINSEL0) & (~(0x03 << 16))), PINSEL0);
break; case PWM_4_DISABLE: outl(inl(PWMPCR) & ~(1 << 12), PWMPCR);
outl((PinSel0Save & (0x03 << 16)) | (inl(PINSEL0) & (~(0x03 << 16))), PINSEL0);
break; case PWM_4_SET_DUTY:
if (arg < inl(PWMMR0))
{
outl(arg, PWMMR4);
outl(inl(PWMLER) | (1 << 4), PWMLER); } break;
case PWM_5_ENABLE:
outl(inl(PWMPCR) & ~(1 << 5), PWMPCR);
outl(inl(PWMPCR) | (1 << 13), PWMPCR);
outl((0x01 << 10) | (inl(PINSEL1) & (~(0x03 << 10))), PINSEL1);
break; case PWM_5_DISABLE: outl(inl(PWMPCR) & ~(1 << 13), PWMPCR);
outl((PinSel1Save & (0x03 << 10)) | (inl(PINSEL1) & (~(0x03 << 10))), PINSEL1);
break; case PWM_5_SET_DUTY:
if (arg < inl(PWMMR0))
{
outl(arg, PWMMR5);
outl(inl(PWMLER) | (1 << 5), PWMLER); } break;
case PWM_6_ENABLE:
outl(inl(PWMPCR) & ~(1 << 6), PWMPCR);
outl(inl(PWMPCR) | (1 << 14), PWMPCR);
outl((0x02 << 18) | (inl(PINSEL0) & (~(0x03 << 18))), PINSEL0);
break; case PWM_6_DISABLE: outl(inl(PWMPCR) & ~(1 << 14), PWMPCR);
outl((PinSel0Save & (0x03 << 18)) | (inl(PINSEL0) & (~(0x03 << 18))), PINSEL0);
break; case PWM_6_SET_DUTY:
if (arg < inl(PWMMR0))
{
outl(arg, PWMMR6);
outl(inl(PWMLER) | (1 << 6), PWMLER); } break;
default: return -ENOTTY; break;*/ } return 0;}
/*********************************************************************************************************
** Function name: pwm_irq_handle
** Descriptions: The top-half interrupt handler
** Input:
** Output none
** Created by: Chenmingji
** Created Date: 2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
static void pwm_irq_handle(int irq, void *dev_id, struct pt_regs *regs){ outl((0x0B<<11),S3C44B0X_I_ISPC);
RunTime++;
}
/*********************************************************************************************************
** Function name: pwm_init
** Descriptions: init driver
** Input:none
** Output 0: OK
** other: not OK
** Created by: Chenmingji
** Created Date: 2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
int pwm_init(void){ int result;
result = register_chrdev(MAJOR_NR, DEVICE_NAME, &pwm_fops); if (result < 0) { printk(KERN_ERR DEVICE_NAME ": Unable to get major %d\n", MAJOR_NR ); return(result); }
if (MAJOR_NR == 0) { MAJOR_NR = result; /* dynamic */ }
printk(KERN_INFO DEVICE_NAME ": init OK\n"); return(0); }/*********************************************************************************************************
** Function name: pwm_cleanup
** Descriptions: exit driver
** Input:none
** Output none
** Created by: Chenmingji
** Created Date: 2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void pwm_cleanup(void){
unregister_chrdev(MAJOR_NR, DEVICE_NAME);}/*********************************************************************************************************** End Of File********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -