17 #include <linux/module.h>
18 #include <linux/netdevice.h>
23 #include <linux/slab.h>
32 #include <mach/regs-ost.h>
33 #include <mach/regs-uart.h>
35 #define FICP __REG(0x40800000)
36 #define ICCR0 __REG(0x40800000)
37 #define ICCR1 __REG(0x40800004)
38 #define ICCR2 __REG(0x40800008)
39 #define ICDR __REG(0x4080000c)
40 #define ICSR0 __REG(0x40800014)
41 #define ICSR1 __REG(0x40800018)
43 #define ICCR0_AME (1 << 7)
44 #define ICCR0_TIE (1 << 6)
45 #define ICCR0_RIE (1 << 5)
46 #define ICCR0_RXE (1 << 4)
47 #define ICCR0_TXE (1 << 3)
48 #define ICCR0_TUS (1 << 2)
49 #define ICCR0_LBM (1 << 1)
50 #define ICCR0_ITR (1 << 0)
52 #define ICCR2_RXP (1 << 3)
53 #define ICCR2_TXP (1 << 2)
54 #define ICCR2_TRIG (3 << 0)
55 #define ICCR2_TRIG_8 (0 << 0)
56 #define ICCR2_TRIG_16 (1 << 0)
57 #define ICCR2_TRIG_32 (2 << 0)
60 #define ICSR0_EOC (1 << 6)
62 #define ICSR0_FRE (1 << 5)
63 #define ICSR0_RFS (1 << 4)
64 #define ICSR0_TFS (1 << 3)
65 #define ICSR0_RAB (1 << 2)
66 #define ICSR0_TUR (1 << 1)
67 #define ICSR0_EIF (1 << 0)
69 #define ICSR1_ROR (1 << 6)
70 #define ICSR1_CRE (1 << 5)
71 #define ICSR1_EOF (1 << 4)
72 #define ICSR1_TNF (1 << 3)
73 #define ICSR1_RNE (1 << 2)
74 #define ICSR1_TBY (1 << 1)
75 #define ICSR1_RSY (1 << 0)
77 #define IrSR_RXPL_NEG_IS_ZERO (1<<4)
78 #define IrSR_RXPL_POS_IS_ZERO 0x0
79 #define IrSR_TXPL_NEG_IS_ZERO (1<<3)
80 #define IrSR_TXPL_POS_IS_ZERO 0x0
81 #define IrSR_XMODE_PULSE_1_6 (1<<2)
82 #define IrSR_XMODE_PULSE_3_16 0x0
83 #define IrSR_RCVEIR_IR_MODE (1<<1)
84 #define IrSR_RCVEIR_UART_MODE 0x0
85 #define IrSR_XMITIR_IR_MODE (1<<0)
86 #define IrSR_XMITIR_UART_MODE 0x0
88 #define IrSR_IR_RECEIVE_ON (\
89 IrSR_RXPL_NEG_IS_ZERO | \
90 IrSR_TXPL_POS_IS_ZERO | \
91 IrSR_XMODE_PULSE_3_16 | \
92 IrSR_RCVEIR_IR_MODE | \
93 IrSR_XMITIR_UART_MODE)
95 #define IrSR_IR_TRANSMIT_ON (\
96 IrSR_RXPL_NEG_IS_ZERO | \
97 IrSR_TXPL_POS_IS_ZERO | \
98 IrSR_XMODE_PULSE_3_16 | \
99 IrSR_RCVEIR_UART_MODE | \
131 static inline void pxa_irda_disable_clk(
struct pxa_irda *si)
134 clk_disable_unprepare(si->
cur_clk);
138 static inline void pxa_irda_enable_firclk(
struct pxa_irda *si)
141 clk_prepare_enable(si->
fir_clk);
144 static inline void pxa_irda_enable_sirclk(
struct pxa_irda *si)
147 clk_prepare_enable(si->
sir_clk);
151 #define IS_FIR(si) ((si)->speed >= 4000000)
152 #define IRDA_FRAME_SIZE_LIMIT 2047
154 inline static void pxa_irda_fir_dma_rx_start(
struct pxa_irda *si)
163 inline static void pxa_irda_fir_dma_tx_start(
struct pxa_irda *si)
175 static void pxa_irda_set_mode(
struct pxa_irda *si,
int mode)
177 if (si->
pdata->transceiver_mode)
178 si->
pdata->transceiver_mode(si->
dev, mode);
180 if (gpio_is_valid(si->
pdata->gpio_pwdown))
183 !si->
pdata->gpio_pwdown_inverted);
191 static int pxa_irda_set_speed(
struct pxa_irda *si,
int speed)
197 case 9600:
case 19200:
case 38400:
198 case 57600:
case 115200:
202 divisor = 14745600 / (16 * speed);
211 pxa_irda_disable_clk(si);
217 pxa_irda_enable_sirclk(si);
225 STDLL = divisor & 0xff;
226 STDLH = divisor >> 8;
242 pxa_irda_disable_clk(si);
251 pxa_irda_enable_firclk(si);
254 pxa_irda_fir_dma_rx_start(si);
271 struct pxa_irda *si = netdev_priv(dev);
276 switch (iir & 0x0F) {
283 dev->
stats.rx_errors++;
285 dev->
stats.rx_frame_errors++;
287 dev->
stats.rx_fifo_errors++;
289 dev->
stats.rx_bytes++;
303 dev->
stats.rx_bytes++;
316 dev->
stats.tx_packets++;
330 pxa_irda_set_speed(si, si->
newspeed);
339 netif_wake_queue(dev);
348 static void pxa_irda_fir_dma_rx_irq(
int channel,
void *data)
350 int dcsr =
DCSR(channel);
358 static void pxa_irda_fir_dma_tx_irq(
int channel,
void *data)
361 struct pxa_irda *si = netdev_priv(dev);
364 dcsr =
DCSR(channel);
368 dev->
stats.tx_packets++;
371 dev->
stats.tx_errors++;
385 pxa_irda_set_speed(si, si->
newspeed);
391 pxa_irda_fir_dma_rx_start(si);
399 netif_wake_queue(dev);
403 static void pxa_irda_fir_irq_eif(
struct pxa_irda *si,
struct net_device *dev,
int icsr0)
417 dev->
stats.rx_errors++;
420 dev->
stats.rx_crc_errors++;
424 dev->
stats.rx_over_errors++;
440 dev->
stats.rx_dropped++;
447 dev->
stats.rx_dropped++;
453 skb_copy_to_linear_data(skb, si->
dma_rx_buff, len);
458 skb_reset_mac_header(skb);
462 dev->
stats.rx_packets++;
468 static irqreturn_t pxa_irda_fir_irq(
int irq,
void *dev_id)
471 struct pxa_irda *si = netdev_priv(dev);
482 dev->
stats.rx_frame_errors++;
485 dev->
stats.rx_errors++;
490 if (icsr0 & ICSR0_EIF) {
492 pxa_irda_fir_irq_eif(si, dev, icsr0);
496 pxa_irda_fir_dma_rx_start(si);
510 struct pxa_irda *si = netdev_priv(dev);
511 int speed = irda_get_next_speed(skb);
518 if (speed != si->
speed && speed != -1)
527 pxa_irda_set_speed(si, speed);
533 netif_stop_queue(dev);
546 unsigned long mtt = irda_get_mtt(skb);
559 pxa_irda_fir_dma_tx_start(si);
570 struct pxa_irda *si = netdev_priv(dev);
581 if (netif_running(dev)) {
582 ret = pxa_irda_set_speed(si,
601 rq->ifr_receiving =
IS_FIR(si) ? 0
613 static void pxa_irda_startup(
struct pxa_irda *si)
635 pxa_irda_set_speed(si, 9600);
640 static void pxa_irda_shutdown(
struct pxa_irda *si)
658 pxa_irda_disable_clk(si);
666 pxa_irda_set_mode(si,
IR_OFF);
671 static int pxa_irda_start(
struct net_device *dev)
673 struct pxa_irda *si = netdev_priv(dev);
705 goto err_dma_rx_buff;
710 goto err_dma_tx_buff;
713 pxa_irda_startup(si);
728 netif_start_queue(dev);
735 pxa_irda_shutdown(si);
752 static int pxa_irda_stop(
struct net_device *dev)
754 struct pxa_irda *si = netdev_priv(dev);
756 netif_stop_queue(dev);
758 pxa_irda_shutdown(si);
783 struct net_device *dev = platform_get_drvdata(_dev);
786 if (dev && netif_running(dev)) {
787 si = netdev_priv(dev);
789 pxa_irda_shutdown(si);
797 struct net_device *dev = platform_get_drvdata(_dev);
800 if (dev && netif_running(dev)) {
801 si = netdev_priv(dev);
802 pxa_irda_startup(si);
804 netif_wake_queue(dev);
824 .ndo_open = pxa_irda_start,
825 .ndo_stop = pxa_irda_stop,
826 .ndo_start_xmit = pxa_irda_hard_xmit,
827 .ndo_do_ioctl = pxa_irda_ioctl,
834 unsigned int baudrate_mask;
837 if (!pdev->
dev.platform_data)
855 si = netdev_priv(dev);
857 si->
pdata = pdev->
dev.platform_data;
872 err = pxa_irda_init_iobuf(&si->
rx_buff, 14384);
875 err = pxa_irda_init_iobuf(&si->
tx_buff, 4000);
879 if (gpio_is_valid(si->
pdata->gpio_pwdown)) {
884 !si->
pdata->gpio_pwdown_inverted);
891 if (si->
pdata->startup) {
897 if (gpio_is_valid(si->
pdata->gpio_pwdown) && si->
pdata->startup)
898 dev_warn(si->
dev,
"gpio_pwdown and startup() both defined!\n");
910 si->
qos.baud_rate.bits &= baudrate_mask;
911 si->
qos.min_turn_time.bits = 7;
921 if (si->
pdata->shutdown)
944 struct net_device *dev = platform_get_drvdata(_dev);
947 struct pxa_irda *si = netdev_priv(dev);
949 if (gpio_is_valid(si->
pdata->gpio_pwdown))
951 if (si->
pdata->shutdown)
971 .probe = pxa_irda_probe,
972 .remove = pxa_irda_remove,
973 .suspend = pxa_irda_suspend,
974 .resume = pxa_irda_resume,