flush the uart inside a kernel module

I am writing a kernel module for our project. Inside the kernel module, I have to read and write the UART of BeagleBone Black (P9_24 and P9_26, uart1_txd and uart1_rxd). The uart is interfacing with out device. I used the “f_ser = filp_open("/dev/ttyO1",O_RDWR|O_NOCTTY|O_NONBLOCK, 0644);” to open it. I used the “f_ser ->f_op->unlocked_ioctl” with commands “TCGETS” and “TCSETS” to change baudrate. The problem is when I write something using vfs_write to our device and our device sent a response back and then I am expecting something read back by using vfs_read. But sometimes, the read back is not what I want (it looks some left over from previous command). I tried to use “f_ser ->f_op->unlocked_ioctl” with commands “TCIOFLUSH” to flush before the write but the function gives an error code -25, which is ENOTTY. Does anybody knows how to flush the uart inside a kernel module?

Thanks a lot.