21 #include <linux/module.h>
23 #include <linux/types.h>
25 #include <linux/errno.h>
26 #include <linux/netdevice.h>
27 #include <linux/slab.h>
28 #include <linux/rtnetlink.h>
40 #include <mach/hardware.h>
43 static int power_level = 3;
45 static int max_rate = 4000000;
78 static int sa1100_irda_set_speed(
struct sa1100_irda *,
int);
80 #define IS_FIR(si) ((si)->speed >= 4000000)
82 #define HPSIR_MAX_RXLEN 2047
105 static unsigned sa1100_irda_dma_xferred(
struct sa1100_buf *
buf)
129 dev_err(dev,
"unable to request DMA channel for %s\n",
134 ret = dmaengine_slave_config(buf->
chan, cfg);
136 dev_warn(dev,
"DMA slave_config for %s returned %d\n",
139 buf->
dev = buf->
chan->device->dev;
144 static void sa1100_irda_dma_start(
struct sa1100_buf *buf,
150 desc = dmaengine_prep_slave_sg(chan, &buf->
sg, 1, dir,
155 buf->
cookie = dmaengine_submit(desc);
156 dma_async_issue_pending(chan);
163 static int sa1100_irda_rx_alloc(
struct sa1100_irda *si)
178 skb_reserve(si->
dma_rx.skb, 1);
193 static void sa1100_irda_rx_dma_start(
struct sa1100_irda *si)
208 dmaengine_terminate_all(si->
dma_rx.chan);
214 static void sa1100_irda_check_speed(
struct sa1100_irda *si)
217 sa1100_irda_set_speed(si, si->
newspeed);
225 static void sa1100_irda_sirtxdma_irq(
void *
id)
231 dev_kfree_skb(si->
dma_tx.skb);
234 dev->
stats.tx_packets++;
249 sa1100_irda_check_speed(si);
252 netif_wake_queue(dev);
266 netif_wake_queue(dev);
267 dev->
stats.tx_dropped++;
299 dev->
stats.rx_errors++;
301 dev->
stats.rx_frame_errors++;
303 dev->
stats.rx_fifo_errors++;
342 static void sa1100_irda_firtxdma_irq(
void *
id)
367 sa1100_irda_check_speed(si);
373 sa1100_irda_rx_dma_start(si);
380 dev->
stats.tx_packets ++;
390 netif_wake_queue(dev);
396 int mtt = irda_get_mtt(skb);
402 netif_wake_queue(dev);
403 dev->
stats.tx_dropped++;
436 len = sa1100_irda_dma_xferred(&si->
dma_rx);
450 dev->
stats.rx_errors++;
452 dev->
stats.rx_crc_errors++;
454 dev->
stats.rx_frame_errors++;
471 skb_reset_mac_header(skb);
473 dev->
stats.rx_packets++;
479 sa1100_irda_rx_alloc(si);
500 dmaengine_pause(si->
dma_rx.chan);
508 dev->
stats.rx_errors++;
511 dev->
stats.rx_frame_errors++;
532 sa1100_irda_fir_error(si, dev);
537 sa1100_irda_rx_dma_start(si);
545 static int sa1100_irda_set_speed(
struct sa1100_irda *si,
int speed)
551 case 9600:
case 19200:
case 38400:
552 case 57600:
case 115200:
553 brd = 3686400 / (16 * speed) - 1;
557 dmaengine_terminate_all(si->
dma_rx.chan);
558 dmaengine_slave_config(si->
dma_tx.chan,
559 &sa1100_irda_sir_tx);
576 if (si->
pdata->set_speed)
577 si->
pdata->set_speed(si->
dev, speed);
580 si->
tx_start = sa1100_irda_sir_tx_start;
581 si->
irq = sa1100_irda_sir_irq;
589 dmaengine_slave_config(si->
dma_tx.chan,
590 &sa1100_irda_fir_tx);
599 si->
tx_start = sa1100_irda_fir_tx_start;
600 si->
irq = sa1100_irda_fir_irq;
602 if (si->
pdata->set_speed)
603 si->
pdata->set_speed(si->
dev, speed);
605 sa1100_irda_rx_alloc(si);
606 sa1100_irda_rx_dma_start(si);
633 if (si->
pdata->set_power)
634 ret = si->
pdata->set_power(si->
dev, state);
639 sa1100_set_power(
struct sa1100_irda *si,
unsigned int state)
643 ret = __sa1100_irda_set_power(si, state);
655 return si->
irq(dev, si);
661 int speed = irda_get_next_speed(skb);
668 if (speed != si->
speed && speed != -1)
673 sa1100_irda_check_speed(si);
678 netif_stop_queue(dev);
701 ret = sa1100_irda_set_speed(si,
704 printk(
"sa1100_irda_ioctl: SIOCSBANDWIDTH: !netif_running\n");
719 rq->ifr_receiving =
IS_FIR(si) ? 0
730 static int sa1100_irda_startup(
struct sa1100_irda *si)
737 if (si->
pdata->startup) {
765 ret = sa1100_irda_set_speed(si, si->
speed = 9600);
770 if (si->
pdata->shutdown)
777 static void sa1100_irda_shutdown(
struct sa1100_irda *si)
782 dmaengine_terminate_all(si->
dma_rx.chan);
783 dmaengine_terminate_all(si->
dma_tx.chan);
789 if (si->
pdata->shutdown)
793 static int sa1100_irda_start(
struct net_device *dev)
800 err = sa1100_irda_dma_request(si->
dev, &si->
dma_rx,
"Ser2ICPRc",
801 &sa1100_irda_fir_rx);
805 err = sa1100_irda_dma_request(si->
dev, &si->
dma_tx,
"Ser2ICPTr",
806 &sa1100_irda_sir_tx);
813 err = sa1100_irda_startup(si);
833 sa1100_set_power(si, power_level);
835 netif_start_queue(dev);
842 sa1100_irda_shutdown(si);
851 static int sa1100_irda_stop(
struct net_device *dev)
856 netif_stop_queue(dev);
859 sa1100_irda_shutdown(si);
894 sa1100_set_power(si, 0);
912 .ndo_open = sa1100_irda_start,
913 .ndo_stop = sa1100_irda_stop,
914 .ndo_start_xmit = sa1100_irda_hard_xmit,
915 .ndo_do_ioctl = sa1100_irda_ioctl,
922 unsigned int baudrate_mask;
925 if (!pdev->
dev.platform_data)
930 return irq < 0 ? irq : -
ENXIO;
950 si = netdev_priv(dev);
952 si->
pdata = pdev->
dev.platform_data;
960 err = sa1100_irda_init_iobuf(&si->
rx_buff, 14384);
979 case 4000000: baudrate_mask |=
IR_4000000 << 8;
981 case 57600: baudrate_mask |=
IR_57600;
982 case 38400: baudrate_mask |=
IR_38400;
983 case 19200: baudrate_mask |=
IR_19200;
986 si->
qos.baud_rate.bits &= baudrate_mask;
987 si->
qos.min_turn_time.bits = 7;
1005 platform_set_drvdata(pdev, dev);
1025 struct net_device *dev = platform_get_drvdata(pdev);
1048 struct net_device *dev = platform_get_drvdata(pdev);
1054 si = netdev_priv(dev);
1061 sa1100_irda_shutdown(si);
1062 __sa1100_irda_set_power(si, 0);
1073 struct net_device *dev = platform_get_drvdata(pdev);
1079 si = netdev_priv(dev);
1093 sa1100_irda_startup(si);
1094 __sa1100_irda_set_power(si, si->
power);
1106 #define sa1100_irda_suspend NULL
1107 #define sa1100_irda_resume NULL
1111 .probe = sa1100_irda_probe,
1112 .remove = sa1100_irda_remove,
1116 .name =
"sa11x0-ir",
1121 static int __init sa1100_irda_init(
void)
1126 if (power_level < 1)
1128 if (power_level > 3)
1134 static void __exit sa1100_irda_exit(
void)
1150 MODULE_PARM_DESC(max_rate,
"Maximum baud rate (4000000, 115200, 57600, 38400, 19200, 9600)");