13 #ifdef CONFIG_SIR_BFIN_DMA
14 #define DMA_SIR_RX_XCNT 10
15 #define DMA_SIR_RX_YCNT (PAGE_SIZE / DMA_SIR_RX_XCNT)
16 #define DMA_SIR_RX_FLUSH_JIFS (HZ * 4 / 250)
20 static int max_rate = 57600;
22 static int max_rate = 115200;
25 static void turnaround_delay(
unsigned long last_jif,
int mtt)
29 mtt = mtt < 10000 ? 10000 : mtt;
58 #ifdef CONFIG_SIR_BFIN_DMA
66 #ifdef CONFIG_SIR_BFIN_DMA
93 static int bfin_sir_set_speed(
struct bfin_sir_port *port,
int speed)
97 unsigned short val, lsr,
lcr;
115 quot = (port->
clk + (8 * speed)) / (16 * speed);
120 }
while (!(lsr &
TEMT) && count--);
123 utime = 1000000 / speed + 1;
176 #ifdef CONFIG_SIR_BFIN_PIO
177 static void bfin_sir_tx_chars(
struct net_device *dev)
183 if (self->tx_buff.len != 0) {
184 chr = *(
self->tx_buff.data);
186 self->tx_buff.data++;
189 self->stats.tx_packets++;
190 self->stats.tx_bytes +=
self->tx_buff.data -
self->tx_buff.head;
191 if (self->newspeed) {
192 bfin_sir_set_speed(port, self->newspeed);
193 self->speed =
self->newspeed;
196 bfin_sir_stop_tx(port);
197 bfin_sir_enable_rx(port);
199 netif_wake_queue(dev);
203 static void bfin_sir_rx_chars(
struct net_device *dev)
209 UART_CLEAR_LSR(port);
221 spin_lock(&self->lock);
223 bfin_sir_rx_chars(dev);
224 spin_unlock(&self->lock);
229 static irqreturn_t bfin_sir_tx_int(
int irq,
void *dev_id)
235 spin_lock(&self->lock);
237 bfin_sir_tx_chars(dev);
238 spin_unlock(&self->lock);
244 #ifdef CONFIG_SIR_BFIN_DMA
245 static void bfin_sir_dma_tx_chars(
struct net_device *dev)
254 if (self->tx_buff.len == 0) {
255 self->stats.tx_packets++;
256 if (self->newspeed) {
257 bfin_sir_set_speed(port, self->newspeed);
258 self->speed =
self->newspeed;
261 bfin_sir_enable_rx(port);
263 netif_wake_queue(dev);
268 (
unsigned long)(self->tx_buff.data+self->tx_buff.len));
274 (
unsigned long)(self->tx_buff.data));
280 static irqreturn_t bfin_sir_dma_tx_int(
int irq,
void *dev_id)
286 spin_lock(&self->lock);
289 bfin_sir_stop_tx(port);
291 self->stats.tx_packets++;
292 self->stats.tx_bytes +=
self->tx_buff.len;
293 self->tx_buff.len = 0;
294 if (self->newspeed) {
295 bfin_sir_set_speed(port, self->newspeed);
296 self->speed =
self->newspeed;
299 bfin_sir_enable_rx(port);
301 netif_wake_queue(dev);
304 spin_unlock(&self->lock);
309 static void bfin_sir_dma_rx_chars(
struct net_device *dev)
315 UART_CLEAR_LSR(port);
317 for (i = port->rx_dma_buf.head; i < port->rx_dma_buf.tail; i++)
321 void bfin_sir_rx_dma_timeout(
struct net_device *dev)
329 x_pos = DMA_SIR_RX_XCNT - get_dma_curr_xcount(port->
rx_dma_channel);
330 if (x_pos == DMA_SIR_RX_XCNT)
333 pos = port->rx_dma_nrows * DMA_SIR_RX_XCNT + x_pos;
335 if (pos > port->rx_dma_buf.tail) {
336 port->rx_dma_buf.tail =
pos;
337 bfin_sir_dma_rx_chars(dev);
338 port->rx_dma_buf.head = port->rx_dma_buf.tail;
340 spin_unlock_irqrestore(&self->lock, flags);
343 static irqreturn_t bfin_sir_dma_rx_int(
int irq,
void *dev_id)
348 unsigned short irqstat;
350 spin_lock(&self->lock);
352 port->rx_dma_nrows++;
353 port->rx_dma_buf.tail = DMA_SIR_RX_XCNT * port->rx_dma_nrows;
354 bfin_sir_dma_rx_chars(dev);
355 if (port->rx_dma_nrows >= DMA_SIR_RX_YCNT) {
356 port->rx_dma_nrows = 0;
357 port->rx_dma_buf.tail = 0;
359 port->rx_dma_buf.head = port->rx_dma_buf.tail;
363 spin_unlock(&self->lock);
365 mod_timer(&port->rx_dma_timer, jiffies + DMA_SIR_RX_FLUSH_JIFS);
372 #ifdef CONFIG_SIR_BFIN_DMA
377 dev_warn(&dev->
dev,
"Unable to attach SIR RX DMA channel\n");
382 dev_warn(&dev->
dev,
"Unable to attach SIR TX DMA channel\n");
387 #ifdef CONFIG_SIR_BFIN_DMA
393 port->rx_dma_buf.head = 0;
394 port->rx_dma_buf.tail = 0;
395 port->rx_dma_nrows = 0;
405 set_dma_start_addr(port->
rx_dma_channel, (
unsigned long)port->rx_dma_buf.buf);
408 port->rx_dma_timer.data = (
unsigned long)(dev);
409 port->rx_dma_timer.function = (
void *)bfin_sir_rx_dma_timeout;
414 dev_warn(&dev->
dev,
"Unable to attach SIR RX interrupt\n");
419 dev_warn(&dev->
dev,
"Unable to attach SIR TX interrupt\n");
432 bfin_sir_stop_rx(port);
438 #ifdef CONFIG_SIR_BFIN_DMA
458 sir_port = platform_get_drvdata(pdev);
463 self = netdev_priv(dev);
466 bfin_sir_shutdown(self->sir_port, dev);
479 sir_port = platform_get_drvdata(pdev);
484 self = netdev_priv(dev);
485 port =
self->sir_port;
487 if (self->newspeed) {
488 self->speed =
self->newspeed;
491 bfin_sir_startup(port, dev);
492 bfin_sir_set_speed(port, 9600);
493 bfin_sir_enable_rx(port);
499 #define bfin_sir_suspend NULL
500 #define bfin_sir_resume NULL
511 while (bfin_sir_is_receiving(dev) && --tx_cnt)
512 turnaround_delay(dev->
last_rx, self->mtt);
514 bfin_sir_stop_rx(port);
529 #ifdef CONFIG_SIR_BFIN_DMA
530 bfin_sir_dma_tx_chars(dev);
532 bfin_sir_enable_tx(port);
539 int speed = irda_get_next_speed(skb);
541 netif_stop_queue(dev);
543 self->mtt = irda_get_mtt(skb);
545 if (speed != self->speed && speed != -1)
546 self->newspeed =
speed;
548 self->tx_buff.data =
self->tx_buff.head;
550 self->tx_buff.len = 0;
571 ret = bfin_sir_set_speed(port, rq->ifr_baudrate);
572 bfin_sir_enable_rx(port);
574 dev_warn(&dev->
dev,
"SIOCSBANDWIDTH: !netif_running\n");
589 rq->ifr_receiving = bfin_sir_is_receiving(dev);
607 static int bfin_sir_open(
struct net_device *dev)
618 err = bfin_sir_startup(port, dev);
622 bfin_sir_set_speed(port, 9600);
628 INIT_WORK(&self->work, bfin_sir_send_work);
634 bfin_sir_enable_rx(port);
636 netif_start_queue(dev);
642 bfin_sir_shutdown(port, dev);
647 static int bfin_sir_stop(
struct net_device *dev)
652 bfin_sir_shutdown(self->sir_port, dev);
655 dev_kfree_skb(self->rxskb);
665 netif_stop_queue(dev);
684 .ndo_open = bfin_sir_open,
685 .ndo_stop = bfin_sir_stop,
686 .ndo_start_xmit = bfin_sir_hard_xmit,
687 .ndo_do_ioctl = bfin_sir_ioctl,
688 .ndo_get_stats = bfin_sir_stats,
695 unsigned int baudrate_mask;
700 per[pdev->
id][3] == pdev->
id) {
705 dev_err(&pdev->
dev,
"Invalid pdev id, please check board file\n");
714 bfin_sir_init_ports(sir_port, pdev);
720 self = netdev_priv(dev);
721 self->dev = &pdev->
dev;
722 self->sir_port = sir_port;
751 dev_warn(&pdev->
dev,
"Invalid maximum baud rate, using 9600\n");
754 self->qos.baud_rate.bits &= baudrate_mask;
756 self->qos.min_turn_time.bits = 1;
763 kfree(self->tx_buff.head);
765 kfree(self->rx_buff.head);
773 platform_set_drvdata(pdev, sir_port);
784 sir_port = platform_get_drvdata(pdev);
788 self = netdev_priv(dev);
790 kfree(self->tx_buff.head);
791 kfree(self->rx_buff.head);
794 platform_set_drvdata(pdev,
NULL);
800 .probe = bfin_sir_probe,
812 MODULE_PARM_DESC(max_rate,
"Maximum baud rate (115200, 57600, 38400, 19200, 9600)");