: new Blackfin on-chip SIR IrDA driver
PATCH 1/1 : new Blackfin on-chip SIR IrDA driver
From: Graff Yang <[email protected]>
--- drivers/net/irda/Kconfig | 45 +++ drivers/net/irda/Makefile | 1 + drivers/net/irda/bfin_sir.c | 806 +++++++++++++++++++++++++++++++++++++++++++ drivers/net/irda/bfin_sir.h | 147 ++++++++ 4 files changed, 999 insertions(+), 0 deletions(-) create mode 100644 drivers/net/irda/bfin_sir.c create mode 100644 drivers/net/irda/bfin_sir.h
drivers/net/irda/Kconfig +45 -0
@@ -17,6 +17,51 @@ config IRTTY_SIR If unsure, say Y. +config BFIN_SIR + tristate "Blackfin SIR on UART" + depends on BLACKFIN && IRDA + default n + help + Say Y here if your want to enable SIR function on Blackfin UART + devices. + + To activate this driver you can start irattach like: + "irattach irda0 -s" + + Saying M, it will be built as a module named bfin_sir. + + Note that you need to turn off one of the serial drivers for SIR + to use that UART. + +config BFIN_SIR3 + bool "Blackfin SIR on UART3" + depends on BFIN_SIR && !SERIAL_BFIN_UART3 && (BF54x) + +config BFIN_SIR1 + bool "Blackfin SIR on UART1" + depends on BFIN_SIR && !SERIAL_BFIN_UART1 && (!BF531 && !BF532 && !BF533 && !BF561) + +config BFIN_SIR0 + bool "Blackfin SIR on UART0" + depends on BFIN_SIR && !SERIAL_BFIN_UART0 + +config BFIN_SIR2 + bool "Blackfin SIR on UART2" + depends on BFIN_SIR && !SERIAL_BFIN_UART2 && (BF54x || BF538 || BF539) + +choice + prompt "SIR Mode" + depends on BFIN_SIR + default SIR_BFIN_DMA + +config SIR_BFIN_DMA + bool "DMA mode" + depends on !DMA_UNCACHED_NONE + +config SIR_BFIN_PIO + bool "PIO mode" +endchoice + comment "Dongle support" config DONGLE
drivers/net/irda/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_MCS_FIR) += mcs7780.o obj-$(CONFIG_AU1000_FIR) += au1k_ir.o # SIR drivers obj-$(CONFIG_IRTTY_SIR) += irtty-sir.o sir-dev.o +obj-$(CONFIG_BFIN_SIR) += bfin_sir.o # dongle drivers for SIR drivers obj-$(CONFIG_ESI_DONGLE) += esi-sir.o obj-$(CONFIG_TEKRAM_DONGLE) += tekram-sir.o
drivers/net/irda/bfin_sir.c new file +806 -0
806 lines not on this page · raw message
drivers/net/irda/bfin_sir.h new file +147 -0
147 lines not on this page · raw message
Signature · 1 line
1.6.1
drivers/net/irda/Kconfig config IRTTY_SIR · line 49
Quoted 8 lines · On Tue, Mar 10, 2009 at 03:29, <[email protected]> wrote:
drivers/net/irda/Kconfig +8
-0+config BFIN_SIR3 + bool "Blackfin SIR on UART3" +config BFIN_SIR1 + bool "Blackfin SIR on UART1" +config BFIN_SIR0 + bool "Blackfin SIR on UART0" +config BFIN_SIR2 + bool "Blackfin SIR on UART2"
looks like an odd order for things. or maybe you count to 3 differently from me :).
drivers/net/irda/bfin_sir.c line 99
Quoted 7 lines
drivers/net/irda/bfin_sir.c new file +7
-0+static int bfin_sir_set_speed (struct bfin_sir_port *port,int speed) +{ + int ret = -EINVAL; + unsigned int quot; + unsigned short val, lsr, lcr = 0; + + lcr = WLS(8);
the lcr init to 0 looks pretty pointless to me ...
Quoted 1 line
+ quot = (
port->clk+ (8 * speed)) / (16 * speed);
isnt the SIR affected by the same anomalies as the UART ? in other words, you just made that adjustment to the UART recently ...
Quoted 3 lines
+ do {
+ lsr =SIR_UART_GET_LSR(port);
+ } while (!(lsr & TEMT));
i'm pretty sure we determined that it is not the job of the kernel to make sure the line is clear before we go changing speeds. plus, we had a few bugs on the UART driver when polling for bits on a peripheral that wasnt enabled yet ...
Quoted 4 lines
+
SIR_UART_PUT_DLL(port, quot & 0xFF);
+SSYNC();
+SIR_UART_PUT_DLH(port, (quot >> 8) & 0xFF);
+SSYNC();
i'm pretty sure that first SSYNC is not needed
Quoted 1 line
+ /*printk(KERN_DEBUG "
bfin_sir: Set new speed %d\n", speed);*/
pr_debug() ?
drivers/net/irda/bfin_sir.c line 278
Quoted 8 lines
drivers/net/irda/bfin_sir.c new file +8
-0+static irqreturn_t bfin_sir_dma_tx_int (int irq,void *dev_id) +{ + struct net_device *dev = dev_id; + struct bfin_sir_self *self = netdev_priv(dev); + struct bfin_sir_port *port = self->sir_port; + + spin_lock(&self->lock); + if (!(get_dma_curr_irqstat(port->tx_dma_channel)&DMA_RUN)) {
really should be whitespace around that &
drivers/net/irda/bfin_sir.c line 356
Quoted 4 lines
drivers/net/irda/bfin_sir.c new file +4
-0+static irqreturn_t bfin_sir_dma_rx_int (int irq,void *dev_id) +{ +.... + mod_timer(&(port->rx_dma_timer), jiffies + DMA_SIR_RX_FLUSH_JIFS);
those paren are unnecessary
drivers/net/irda/bfin_sir.c line 368
Quoted 8 lines
drivers/net/irda/bfin_sir.c new file +8
-0+static int bfin_sir_startup (struct bfin_sir_port *port,struct net_device *dev) +{ +#ifdef CONFIG_SIR_BFIN_DMA + dma_addr_t dma_handle; +#endif /* CONFIG_SIR_BFIN_DMA */ + + if (request_dma(port->rx_dma_channel, "BFIN_UART_RX") < 0) { + printk(KERN_WARNING "bfin_sir: Unable to attach SIR RX DMA channel\n");
should be dev_warn(&dev->dev, ...) ? if so, i'd check all the places where printk() is used when a net_device is available ...
Quoted 4 lines
drivers/net/irda/bfin_sir.c new file +4
-0+static int __devinit bfin_sir_probe (struct platform_device *pdev) +{ + struct net_device *dev; + struct bfin_sir_self *self;
drivers/net/irda/bfin_sir.c line 688
Quoted 10 lines
drivers/net/irda/bfin_sir.c new file +10
-0+ unsigned int baudrate_mask; + struct bfin_sir_port *sir_port; + int err = 0; + + err = peripheral_request(per[pdev->id][0], DRIVER_NAME); + if (err) + return err; + err = peripheral_request(per[pdev->id][1], DRIVER_NAME); + if (err) + return err;
the first per list was just leaked ...
Quoted 1 line
+
sir_port=kmalloc(sizeof(struct bfin_sir_port), GFP_KERNEL);
sizeof(*sir_port)
Quoted 1 line
+ dev =
alloc_irdadev(sizeof(struct bfin_sir_self));
sizeof(*dev)
Quoted 4 lines
+
baudrate_mask=IR_9600;
+
+ switch (max_rate) {
+ case 115200:
Quoted 8 lines
+
baudrate_mask|=IR_115200;
+ case 57600:
+baudrate_mask|=IR_57600;
+ case 38400:
+baudrate_mask|=IR_38400;
+ case 19200:
+baudrate_mask|=IR_19200;
+ }
what if someone specified max_rate = 1231245 ?
drivers/net/irda/bfin_sir.c line 751
Quoted 10 lines
+ if (err) {
drivers/net/irda/bfin_sir.c new file +9
-0+err_mem_3: + kfree(self->tx_buff.head); +err_mem_2: + kfree(self->rx_buff.head); +err_mem_1: + free_netdev(dev); +err_mem_0: + kfree(sir_port); + }
the peripheral pins are leaked here as well
Quoted 2 lines
+ if (err == 0)
+platform_set_drvdata(pdev, sir_port);
considering you tested "if (err)" right before, an "} else" would make more sense
Quoted 1 line
+MODULE_AUTHOR("Graf.Yang <[email protected]>");
i think your name has no "." ? :)
drivers/net/irda/bfin_sir.h line 34
Quoted 8 lines
drivers/net/irda/bfin_sir.h new file +6
-0+#ifdef CONFIG_SIR_BFIN_DMA +struct dma_rx_buf { + char *buf; + int head; + int tail; + };
no indentation in closing brace
Quoted 6 lines
+static unsigned short per[][2] = {
+ {P_UART0_RX,P_UART0_TX},
+ {P_UART1_RX,P_UART1_TX},
+ {P_UART2_RX,P_UART2_TX},
+ {P_UART3_RX,P_UART3_TX},
+ };
no indentation in closing brace and really this should be const -mike
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 15 lines · graff yang
Quoted 14 lines · Mike Frysinger
Quoted 12 lines · On Tue, Mar 10, 2009 at 03:29, <[email protected]> wrote:
+
baudrate_mask=IR_9600;
+
+ switch (max_rate) {
+ case 115200:
+baudrate_mask|=IR_115200;
+ case 57600:
+baudrate_mask|=IR_57600;
+ case 38400:
+baudrate_mask|=IR_38400;
+ case 19200:
+baudrate_mask|=IR_19200;
+ }
Quoted 3 lines
Quoted 1 line
what if someone specified
max_rate= 1231245 ?The initial value of
baudrate_maskisIR_9600.
i meant in terms of the user being notified it's a bogus value. what if they did max_rate=576000 ? clearly they meant 57600, but they hit "0" too many times ...
-mike
Quoted 3 lines
i meant in terms of the user being notified it's a bogus value. what if they did max_rate=576000 ? clearly they meant 57600, but they hit "0" too many times ...
If a termios option is set which is not supported by the hardware the driver should put the value it actually used in the termios struct.
Alan
Quoted 6 lines · Alan Cox
Quoted 3 lines
i meant in terms of the user being notified it's a bogus value. what if they did max_rate=576000 ? clearly they meant 57600, but they hit "0" too many times ...
If a termios option is set which is not supported by the hardware the driver should put the value it actually used in the termios struct.
while true, that isnt what we're talking about here -mike
Quoted 44 lines · graff yang
On Tue, Mar 10, 2009 at 4:03 PM, Mike Frysinger <[email protected]> wrote:
On Tue, Mar 10, 2009 at 03:29, <[email protected]> wrote:
> +configBFIN_SIR3
> + bool "Blackfin SIR on UART3"> +config
BFIN_SIR1
> + bool "Blackfin SIR on UART1"> +config
BFIN_SIR0
> + bool "Blackfin SIR on UART0"> +config
BFIN_SIR2
> + bool "Blackfin SIR on UART2"looks like an odd order for things. or maybe you count to 3 differently from me :).
> +static int
bfin_sir_set_speed(struct bfin_sir_port *port, int speed)
> +{
> + int ret =-EINVAL;
> + unsigned int quot;
> + unsigned short val, lsr, lcr = 0;
> +
> + lcr = WLS(8);the lcr init to 0 looks pretty pointless to me ...
> + quot = (
port->clk+ (8 * speed)) / (16 *
speed);isnt the SIR affected by the same anomalies as the UART ? in other
words, you just made that adjustment to the UART recently ...SIR hasn't encounter such anomalies. Anyway, I will add it.
Quoted 8 lines
> + do {
> + lsr = SIR_UART_GET_LSR(port);
> + } while (!(lsr & TEMT));
i'm pretty sure we determined that it is not the job of the
kernel to
make sure the line is clear before we go changing speeds.But we should prevent changing speed when the byte is sending out.
Quoted 165 lines
plus, we had a few bugs on the UART driver when polling for bits on a peripheral that wasnt enabled yet ... > + SIR_UART_PUT_DLL(port, quot & 0xFF); > + SSYNC(); > + SIR_UART_PUT_DLH(port, (quot >> 8) & 0xFF); > + SSYNC(); i'm pretty sure that first SSYNC is not needed > + /*printk(KERN_DEBUG "bfin_sir: Set new speed %d\n", speed);*/ pr_debug() ? > +static irqreturn_t bfin_sir_dma_tx_int(int irq, void *dev_id) > +{ > + struct net_device *dev = dev_id; > + struct bfin_sir_self *self = netdev_priv(dev); > + struct bfin_sir_port *port = self->sir_port; > + > + spin_lock(&self->lock); > + if (!(get_dma_curr_irqstat(port->tx_dma_channel)&DMA_RUN)) { really should be whitespace around that & > +static irqreturn_t bfin_sir_dma_rx_int(int irq, void *dev_id) > +{ > +.... > + mod_timer(&(port->rx_dma_timer), jiffies + DMA_SIR_RX_FLUSH_JIFS); those paren are unnecessary > +static int bfin_sir_startup(struct bfin_sir_port *port, struct net_device *dev) > +{ > +#ifdef CONFIG_SIR_BFIN_DMA > + dma_addr_t dma_handle; > +#endif /* CONFIG_SIR_BFIN_DMA */ > + > + if (request_dma(port->rx_dma_channel, "BFIN_UART_RX") < 0) { > + printk(KERN_WARNING "bfin_sir: Unable to attach SIR RX DMA channel\n"); should be dev_warn(&dev->dev, ...) ? if so, i'd check all the places where printk() is used when a net_device is available ... > +static int __devinit bfin_sir_probe(struct platform_device *pdev) > +{ > + struct net_device *dev; > + struct bfin_sir_self *self; > + unsigned int baudrate_mask; > + struct bfin_sir_port *sir_port; > + int err = 0; > + > + err = peripheral_request(per[pdev->id][0], DRIVER_NAME); > + if (err) > + return err; > + err = peripheral_request(per[pdev->id][1], DRIVER_NAME); > + if (err) > + return err; the first per list was just leaked ... > + sir_port = kmalloc(sizeof(struct bfin_sir_port), GFP_KERNEL); sizeof(*sir_port) > + dev = alloc_irdadev(sizeof(struct bfin_sir_self)); sizeof(*dev) > + baudrate_mask = IR_9600; > + > + switch (max_rate) { > + case 115200: > + baudrate_mask |= IR_115200; > + case 57600: > + baudrate_mask |= IR_57600; > + case 38400: > + baudrate_mask |= IR_38400; > + case 19200: > + baudrate_mask |= IR_19200; > + } what if someone specified max_rate = 1231245 ?The initial value of
baudrate_maskisIR_9600.> + if (err) { > +err_mem_3: > + kfree(self->tx_buff.head); > +err_mem_2: > + kfree(self->rx_buff.head); > +err_mem_1: > + free_netdev(dev); > +err_mem_0: > + kfree(sir_port); > + } the peripheral pins are leaked here as well > + if (err == 0) > + platform_set_drvdata(pdev, sir_port); considering you tested "if (err)" right before, an "} else" would make more sense > +MODULE_AUTHOR("Graf.Yang <[email protected]>"); i think your name has no "." ? :)Thanks.
> --- /dev/null > +++ b/drivers/net/irda/bfin_sir.h > +#ifdef CONFIG_SIR_BFIN_DMA > +struct dma_rx_buf { > + char *buf; > + int head; > + int tail; > + }; no indentation in closing brace > +static unsigned short per[][2] = { > + {P_UART0_RX, P_UART0_TX}, > + {P_UART1_RX, P_UART1_TX}, > + {P_UART2_RX, P_UART2_TX}, > + {P_UART3_RX, P_UART3_TX}, > + }; no indentation in closing brace and really this should be const -mike
Quoted 8 lines · gyang
Quoted 7 lines · graff yang
Quoted 4 lines · Mike Frysinger
Quoted 3 lines · On Tue, Mar 10, 2009 at 03:29, <[email protected]> wrote:
+ do {
+ lsr =SIR_UART_GET_LSR(port);
+ } while (!(lsr & TEMT));
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
i'm pretty sure we determined that it is not the job of the kernel to
make sure the line is clear before we go changing speeds.But we should prevent changing speed when the byte is sending out.
no we shouldnt. if the user changes speeds while things are being transmitted, then they screwed up. this is why tcdrain/tcflush exist on the tty side of things.
-mike